akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int a[5][5];
  int N,i,j;
  int b[12];

  for(i=0;i<3;i++){
    scanf("%d %d %d\n",&a[i][0],&a[i][1],&a[i][2] );
  }
  scanf("%d\n",&N );
  for(i=0;i<N;i++){
    scanf("%d\n",&b[i] );
    for(j=0;j<3;j++){
      if(a[j][0] == b[i]){
        a[j][0] = 0;
      }
      if(a[j][1] == b[i]){
        a[j][1] = 0;
      }
      if(a[j][2] == b[i]){
        a[j][2] = 0;
      }
    }
  }
  for(i=0;i<3;i++){
    if(a[i][0] + a[i][1] + a[i][2] == 0){
      printf("Yes");
      exit(0);
    }
    if(a[0][i] + a[1][i] + a[2][i] == 0){
      printf("Yes");
      exit(0);
    }
  }
  if((a[1][1] + a[2][2] + a[0][0] == 0)||(a[0][2] +a[1][1] + a[2][0] == 0)){
    printf("Yes");
    exit(0);
  }
  printf("No" );
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s,ans="";
	cin>>s;
	int i;
	for(i=0;i<s.length();i++){
		if(s[i]=='B'){
			if(ans.length()>0)ans=ans.substr(0,ans.length()-1);
		}
		else ans+=s[i];
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
		
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll a[210],bs[210];
int main(){
    int t; cin >> t;
    while(t){
        t--;
        int i,j,n,sz = 0;
        cin >> n;
        for(i=0;i<n;i++){
            cin >> a[i];
        }
        string s; cin >> s;
        for(i=n - 1;i>=0;i--){
            if(s[i]=='1'){
                for(j=0;j<sz;j++){
                    a[i] = min(a[i],a[i]^bs[j]);
                }
                if(a[i]!=0){
                    cout << 1 << endl;
                    break;
                }
            }else{
                for(j=0;j<sz;j++){
                    a[i] = min(a[i],a[i]^bs[j]);
                }
                if(a[i]!=0){
                    bs[sz] = a[i];
                    sz++;
                }
            }
            if(i==0){
                cout << 0 << endl;
            }
        }
    }
}

Measured memory_bytes: 3556
#include <iostream>
using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;
    
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j <= N - i; ++j){
            int k = N - i - j;
            int sum = 10000*i + 5000*j + 1000*k;
            if(sum == Y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
vi g[125252];

set<pii> S;
bool used[125252];
int dep[125252];
bool isin(int a, int b){
    return S.count(pii(a,b)) || S.count(pii(b,a));
}
void dfs(int p, int bef, int d){
    used[p] = true;
    dep[p] = d;
    for(int to : g[p])if(to != bef){
        if(!used[to]){
            dfs(to,p,d+1);
        }
    }
    vi tos;
    for(int to : g[p])if(dep[to] > dep[p]){
        if(!isin(p,to))tos.push_back(to);
    }
    for(int to : g[p])if(dep[to] < dep[p]){
        if(!isin(p,to))tos.push_back(to);
    }
    if(tos.size()%2==1)tos.pop_back();
    for(int to : tos){
        S.insert(pii(p,to));
    }
}

int main(){
    scanf("%d%d",&n,&m);
    REP(i,m){
        int a,b;
        scanf("%d%d",&a,&b);
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(m%2==1){
        puts("-1");
        return 0;
    }
    assert(n>=3);
    dfs(0,-1,0);
    for(pii P : S){
        printf("%d %d\n",P.first+1, P.second+1);
    }
    return 0;
}


Measured memory_bytes: 25088
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const N = input[0][0]
  const M = input[0][1]

  const enq = input.slice(1)
  const votebox = [...Array(M + 1)].map(v => 0)
  enq.forEach(item => {
    for (let i = 1; i < item.length; i++) {
      votebox[item[i]]++
    }
  })
  const ans = votebox.filter(num => {
    return num === N
  })
  console.log(ans.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22964
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Zp {
	const int p = 998244353;
	ll r;
	void set(ll x) {
		while (x < 0) x += p;
		r = x % p;
	}

public:
	Zp(ll x) { set(x); }
	Zp() { set(0); }

	Zp operator-() const { return Zp(-r); }
	Zp &operator=(ll y) {
		set(y);
		return *this;
	}
	Zp &operator=(const Zp &y) { return *this = y.r; }

	Zp &operator+=(ll y) {
		set(r + y);
		return *this;
	}
	Zp &operator-=(ll y) { return *this += -y; }
	Zp &operator*=(ll y) {
		set(r * y);
		return *this;
	}
	Zp &operator/=(ll y) { return *this *= inv(y); }
	Zp operator+(ll y) const { return Zp(r + y); }
	Zp operator-(ll y) const { return *this + (-y); }
	Zp operator*(ll y) const { return Zp(r * y); }
	Zp operator/(ll y) const { return *this * inv(y); }

	Zp &operator+=(const Zp &y) { return *this += y.r; }
	Zp &operator-=(const Zp &y) { return *this -= y.r; }
	Zp &operator*=(const Zp &y) { return *this *= y.r; }
	Zp &operator/=(const Zp &y) { return *this /= y.r; }
	Zp operator+(const Zp &y) const { return *this + y.r; }
	Zp operator-(const Zp &y) const { return *this - y.r; }
	Zp operator*(const Zp &y) const { return *this * y.r; }
	Zp operator/(const Zp &y) const { return *this / y.r; }

	Zp pow(int n) const {
		if (n == 0) return 1;
		if (n % 2) return *this * pow(n - 1);
		Zp tmp = pow(n / 2);
		return tmp * tmp;
	}
	Zp inv(int x) const { return Zp(x).pow(p - 2); }
	Zp inv() const { return inv(r); }

	ll get() const { return r; }

	friend istream &operator>>(istream &istr, Zp &x) {
		istr >> x.r;
		x.set(x.r);
		return istr;
	}
	friend ostream &operator<<(ostream &ostr, const Zp &x) {
		ostr << x.r;
		return ostr;
	}
};
class Comb {
	vector<Zp> fact, ifact;

public:
	Comb(int N) : fact(N + 1), ifact(N + 1) {
		fact[0] = 1;
		REP(i, N)
		fact[i + 1] = fact[i] * (i + 1);
		ifact[N] = fact[N].inv();
		REPR(i, N)
		ifact[i] = ifact[i + 1] * (i + 1);
	}
	Zp operator()(int n, int k) const {
		return fact[n] * ifact[n - k] * ifact[k];
	}
	Zp f(int k) const { return fact[k]; }
	Zp invf(int k) const { return ifact[k]; }
};

Zp dp[3005][3005];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A > C || B > D) {
		cout << 0 << endl;
		return 0;
	}
	dp[A][B] = 1;
	FOR(i, A, C) {
		dp[i + 1][B] = dp[i][B] * B;
	}
	FOR(j, B, D) {
		dp[A][j + 1] = dp[A][j] * A;
	}
	FOR(i, A, C) {
		FOR(j, B, D) {
			dp[i + 1][j + 1] += dp[i + 1][j] * (i + 1);
			dp[i + 1][j + 1] += dp[i][j + 1] * (j + 1);
			dp[i + 1][j + 1] -= dp[i][j] * i * j;
		}
	}

	cout << dp[C][D] << endl;

	return 0;
}


Measured memory_bytes: 144760
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 1; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int N, K;
  cin >> N >> K;
  vector<int> slist(N,0);
  for (int i = 0; i<K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j<d; j++) {
      int a;
      cin >> a;
      a--;
      slist.at(a)++;
    }
  }
  int ans=0;
  for (int i = 0; i < N; i++) {
    if (slist.at(i)==0) ans++;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int64 mpow(int64 mm, int64 xx)
{
	if(xx == 0)
	{
		return 1;
	}
	int64 tmp = mpow(mm, xx / 2);
	tmp *= tmp;
	tmp %= mod;
	if(xx % 2 == 1)
	{
		tmp *= mm;
		tmp %= mod;
	}
	return tmp;
}

int main()
{
	int64 aa, bb, cc;
	cin >> aa >> bb >> cc;
	cc -= (aa - bb);
	cout << max((int64)0, cc) << endl;
	return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,t[100000],x[100000],y[100000],i,nx = 0,ny = 0,nt = 0;

    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d",&t[i],&x[i],&y[i]);
    }

    for (i = 0; i < n; i++)
    {
        if(abs(x[i] - nx + y[i] - ny) <= t[i] - nt && abs(x[i] - nx + y[i] - ny) % 2 == (t[i] - nt) % 2)
        {
            nx = x[i];
            ny = y[i];
            nt = t[i];
        }
        else
        {
            break;
        }
    }
    
    if(i == n)printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;

ll N, K;

	
ll gcd(ll a, ll b) {
	if (!b) return a;
	return gcd(b, a % b);
}
int main(){
    cin >> N >> K;

    vector<ll> tst;
    ll N2 = N % K;
    ll N3 = K - (N % K);
    tst.push_back(N);
    tst.push_back(N3);
    tst.push_back(N2);
    sort(tst.begin(), tst.end());
    cout << tst[0];
    return 0;
}

Measured memory_bytes: 256
import sys
import bisect

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
L = [int(x) for x in input().split()]
L.sort()

ans=0
for i in range(0, N-1):
	for j in range(1, N-1):
		if i>=j:
			continue
		ans += bisect.bisect_left(L, L[i]+L[j], lo=j+1)-1-j
print(ans)

Measured memory_bytes: 45020
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
using namespace std;



int main(){
  string S;
  getline(cin, S);
  int calc[100001];
  memset(calc, 0, sizeof(calc));
  bool isRmode = true;
  long cnt = 0;
  long Rpos=-1;
  long Lpos = -1;
  for(long x=0; x < S.length(); x++)
  {
    if(S[x] == 'R')
    {
      if(isRmode)
      {
        // R文字数カウント
        cnt++;
      }
      else
      {
        // Lモードの時なので計算してRモードに戻す
        calc[Lpos] += cnt / 2 + cnt % 2;
        calc[Rpos] += cnt / 2;
        isRmode = true;
        cnt = 1;
      }
    }
    else
    {
      if(isRmode)
      {
        // カウントしたこれまでの場所に割り当てする
        Rpos = x - 1;
        Lpos = x;
        calc[Rpos] += cnt / 2 + cnt % 2;
        calc[Lpos] += cnt / 2;
        
        isRmode = false;
        cnt = 1;
      }
      else
      {
        cnt++;
      }
    }
    
  }
  
  // 最後の計算
  // Lモードの時なので計算してRモードに戻す
  calc[Lpos] += cnt / 2 + cnt % 2;
  calc[Rpos] += cnt / 2;
  
  for(long x = 0; x < S.length() - 1; x++)
  {
    cout << calc[x] << " ";
  }
  cout << calc[S.length() - 1] << endl; 
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
bool a[1000001]; 
int main ()
{
	int k;
	cin>>k;
	int res=0;
	for(int i=1;;i++)
	{
		res=(res*10+7)%k;
		if(res==0)
		{
			cout<<i;
			return 0;
		}
		else
		{
			if(a[res])
			{
				cout<<-1;
				return 0;
			}
			a[res]=1;
		}
	}
	
} 
 

Measured memory_bytes: 4584
import bisect


if __name__ == '__main__':
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    answer = 0
    for b in B:
        answer += (bisect.bisect_left(A, b)) * (N - bisect.bisect_right(C, b))
    print(answer)

Measured memory_bytes: 23156
///*
#include<iostream>
#include<string>
using namespace std;

int main() {

	string input;
	string left, right;
	bool YYMM = false, MMYY = false;

	cin >> input;
	left = input.substr(0, 2);
	right = input.substr(2, 2);
	//cout << left << " " << right << endl;

	if (right > "00" && right < "13")YYMM = true;

	if (left > "00" && left < "13")MMYY = true;

	if (YYMM && MMYY) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (!YYMM && !MMYY) {
		cout << "NA" << endl;
	}else if(YYMM){
		cout << "YYMM" << endl;
	}
	else {
		cout << "MMYY" << endl;
	}

	return 0;
}
//*/

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define  long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const double INF=1e9+7;
LL Find[100005];
LL find(int x) {return Find[x]==x?x:Find[x]=find(Find[x]);}
LL a[100005],b[100005],vis[100005],ans[100005];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        Find[i]=i;
    for(int i=1;i<=n;i++)
        vis[i]=1;
    for(int i=1;i<=m;i++)
    {
        scanf("%lld%lld",&a[i],&b[i]);
    }
    ans[m]=1LL*n*(n-1)/2;
    //printf("%d\n",a[m]);
    LL sum=0;
    for(int i=m;i>=1;i--)
    {
        LL fx=find(a[i]);
        LL fy=find(b[i]);
        if(fx!=fy)
        {
             Find[fy]=fx;
             sum-=vis[fx]*(vis[fx]-1)/2+vis[fy]*(vis[fy]-1)/2;
             vis[fx]+=vis[fy];
             sum+=vis[fx]*(vis[fx]-1)/2;
        }
        //printf("%d %d %d \n",fx,vis[fx],sum);
        ans[i-1]=ans[m]-sum;
    }
    for(int i=1;i<=m;i++)
        printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  struct edge { int to, w; };
  vector< vector<edge> > G(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    G[a].push_back(edge{b, c});
    G[b].push_back(edge{a, c});
  }
  int q, k; cin >> q >> k;
  k--;
  vector<lint> d(n, -1);
  queue<int> que;
  d[k] = 0;
  que.push(k);
  while (not que.empty()) {
    int v = que.front(); que.pop();
    for (auto&& e : G[v]) {
      if (d[e.to] == -1) {
        d[e.to] = d[v] + e.w;
        que.push(e.to);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int x, y; cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] << '\n';
  }
  return 0;
}

Measured memory_bytes: 8820
#include <iostream>

using namespace std;

int main() {
  int H, N;
  cin >> H;
  cin >> N;
  int a;
  for(int i = 0; i < N; i++) {
    cin >> a;
    H -= a;
  }

  if(H <= 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;

int main(){
  int64_t X,K,D;
  cin>>X>>K>>D;
  if(K<abs(X/D)){
    cout<<abs(X)-K*D;
  }
  else if((K-abs(X/D))%2==0){
    cout<<abs(X-(X/D)*D);
  }
  else{
    cout<<abs(abs(X)-(abs(X/D)+1)*D);
  }
}

Measured memory_bytes: 3636
a, b, k = map(int, input().split())

for i in range(k):
    if i % 2 == 0:
        if a % 2 != 0:
            a -= 1
        b += a//2
        a //= 2
    else:
        if b % 2 != 0:
            b -= 1
        a += b//2
        b //= 2
print(a, b)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

ll mergecount(vector<int> &a) {
    ll count = 0;
    int n = a.size();
    if (n > 1) {
        vector<int> b(a.begin(), a.begin() + n/2);
        vector<int> c(a.begin() + n/2, a.end());
        count += mergecount(b);
        count += mergecount(c);
        for (int i = 0, j = 0, k = 0; i < n; ++i)
        if (k == c.size())       a[i] = b[j++];
        else if (j == b.size())  a[i] = c[k++];
        else if (b[j] <= c[k])   a[i] = b[j++];
        else                   { a[i] = c[k++]; count += n/2 - j; }
    }
    return count;
}

int main() {
    ll n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int l = 1, r = 1001001001;
    while(l + 1 < r){
        int m = (l + r) / 2;
        vector<int> b(n);
        rep(i,n){
            if(a[i] >= m) b[i] = 1;
            else b[i] = -1;
        }
        vector<int> sum(n+1);
        sum[0] = 0;
        srep(i,1,n+1){
            sum[i] = sum[i-1] + b[i-1];
        }
        ll k = mergecount(sum);
        if(k <= (n+1)*n/2/2) l = m;
        else r = m;
    }

    cout << l << endl;
    return 0;
}
 
 


Measured memory_bytes: 5236
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

template<class U,class T>ostream& operator<<(ostream& out, pair<U,T> & P){
    return out << "[" << P.first << ", " << P.second << "]";
}
template<class T>ostream& operator<<(ostream& out, vector<T> & V){
    if(!V.empty())out << "[";
    for(int i = 0; i < sz(V); i++)out << V[i] << (i+1==sz(V)?"]":", ");
    return out;
}

int main(){
    ios_base::sync_with_stdio(false);
    double h, a;
    cin >> h >> a;
    cout << int(ceil(h/a)) << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int h,w,n,ans=0;cin>>h>>w>>n;
  while(n>0){
	  if(h>w){
      n-=h;
      ans++;
	  }else{
      n-=w;
      ans++;
	  }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//Optimise Yourself
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n,a,b,x,c1,c2,c3;
    cin >> n >> a >> b;
    c1 = c2 = c3 = 0;
    while(n--){
        cin >> x ;
        if(x<=a) c1++;
        else if(x>b) c3++;
        else c2++;
    }
    cout << min(c1,min(c2,c3));
    return 0;
}

Measured memory_bytes: 256
s = input()
k = int(input())


def enumerate_substring(k, s):
    s_list = list(s)
    for i in range(1, k + 1):
        for j in range(len(s)):
            if j + i < len(s):
                s_list.append(s[j:j + i + 1])
    s_list = list(set(s_list))
    s_list.sort()
    return s_list


s_list = enumerate_substring(k, s)
print(s_list[k - 1])

Measured memory_bytes: 5416
import sys

#a^n mod p を求める
def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res

input = sys.stdin.readline

n = int(input())
p = 1000000007
n_10 = power_func(10,n,p)
n_9 = power_func(9,n,p) * 2 % p

n_8 = power_func(8,n,p)

if n_10 - n_9 + n_8 < 0:
    print(n_10 - n_9 + n_8 + p)
else:
    print(n_10 - n_9 + n_8)

Measured memory_bytes: 9208
package main

import (
	"fmt"
)

func main() {
	var N, A, B int
	res := 0

	fmt.Scan(&N, &A, &B)
	set := (N / (A + B)) * A
	rem := (N % (A + B))
	if rem > A {
		rem = A
	}
	res = set + rem
	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var a, b, c, x, ans int
	fmt.Scan(&a, &b, &c, &x)

	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if 500*i + 100*j + 50*k == x {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    int n;cin>>n;
    deque<int> q;

    for(int i=0;i<n;i++){
        int x;cin>>x;
        if(i&1){
            q.push_front(x);
        }else{
            q.push_back(x);
        }
    }
    if(n&1){
        while(!q.empty()){
            int t=q.back();
            q.pop_back();
            cout<<t<<" ";
        }
    }else{
        while(!q.empty()){
            int t=q.front();
            q.pop_front();
            cout<<t<<" ";
        }
    }
}


Measured memory_bytes: 4492
import Control.Monad
import Data.Function
import Data.List
import Text.Read
import Text.ParserCombinators.ReadPrec

import qualified Data.ByteString.Char8 as B

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

main :: IO ()
main = do
  (_, k) <- getPair <$> readLn :: IO (Int, Int)
  ps <- map read . words <$> getLine
  print $ solve k ps

solve :: Int -> [Int] -> Int
solve k = sum . take k . sort


Measured memory_bytes: 5192
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

int n;
int d[10000], p[10000];
int c[10000];
priority_queue<pair<int, int> > q;
vector<pair<int, int> > v[10000];


void prim(){
  d[0] = 0;
  p[0] = -1;

  q.push(make_pair(0, 0));

  while(q.empty() == 0){
    int u;
    pair<int, int> f = q.top();
    q.pop();
    u = f.second;

    c[u] = 2;

    if(d[u] < f.first * (-1)) continue;

    for(int i = 0; i < v[u].size(); i++){
      int a = v[u][i].first;
      if(c[a] != 2){
        if(v[u][i].second + d[u] < d[a]){
          d[a] = v[u][i].second + d[u];
          p[a] = u;
          c[a] = 1;
          q.push(make_pair(d[a] * (-1), a));
        }

      }
    }
  }
}

int main(){

  cin >> n;

  for(int i = 0; i < n; i++){
    c[i] = 0;
    d[i] = 1000000;
    int id, k, x;
    cin >> id >> k;

    for(int j = 0; j < k; j++){
      int x, y;
      cin >> x >> y;
      v[id].push_back(make_pair(x, y));
    }
  }

  prim();

  for(int i = 0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 7764
#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  vector<ll> su(n+1);
  for(int i=0;i<n;++i) {
    cin >> a[i];
    su[i+1] = su[i] + a[i];
  }
  //printv(su);

  map<ll, ll> mp;
  ll ans = 0;
  mp[0]++;
  for(int i=1;i<min(n+1, k);++i) {
    ans += mp[(su[i]-i) % k];
    //cout << ans << endl;
    mp[(su[i]-i) % k]++;
  }

  for(int i=k;i<n+1;++i) {
    mp[(su[i-k]-(i-k)) % k]--;
    ans += mp[(su[i]-i) % k];
    //cout << ans << endl;
    mp[(su[i]-i) % k]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    string s;cin>>s;
    bool ok=0;
    for(char c:s){
        ok|=(c=='7');
    }
    cout<<(ok?"Yes":"No");
}






Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll H;
    cin >> H;
    int cnt = 0;
    while (H > 0) {
        H /= 2;
        ++cnt;
    }
    cout << (1LL << cnt) - 1 << endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lowbit(_A) ((_A) & (-(_A)))

int n;
int cnt;
int fr[166666];
int ne[333333];
int to[333333];

void add(int a, int b){
	ne[++cnt] = fr[a], fr[a] = cnt, to[cnt] = b;
	ne[++cnt] = fr[b], fr[b] = cnt, to[cnt] = a;
}

void dfs(int S, int T, int s, int cnt){
	if(cnt == n - 1){add(S, T); return;}
	for(int i = 0; i < n; i++){
		if(s & (1 << i)) continue;
		if((S & (1 << i)) != (T & (1 << i))){
			for(int j = 0, tmp, tmp2; j < n; j++){
				if((s & (1 << j)) || j == i) continue;
				else{
					if(S & (1 << j)) tmp = S & ((1 << n) - 1 - (1 << j));
					else tmp = S | (1 << j);
					dfs(S, tmp, s | (1 << i), cnt + 1);
					if(S & (1 << i)) tmp2 = tmp & (((1 << n) - 1 - (1 << i)));
					else tmp2 = tmp | (1 << i);
					dfs(tmp2, T, s | (1 << i), cnt + 1);
					add(tmp, tmp2);
					break;
				}
			}
			break;
		}
	}
}

int A, B;
int na, nb;

void out(int a, int f){
	printf("%d ", a);
	for(int i = fr[a]; i; i = ne[i])
		if(to[i] != f) out(to[i], a);
}

int main(){
	scanf("%d", &n);
	scanf("%d %d", &A, &B);
	int tmp = A;
	while(tmp) tmp -= lowbit(tmp), na++;
	tmp = B;
	while(tmp) tmp -= lowbit(tmp), nb++;
	if(na % 2 == nb % 2) return !printf("NO\n");
	dfs(A, B, 0, 0);
	puts("YES");
	out(A, -2);
	printf("\n");
	return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define MAX 100
int is[MAX];
int main(void) {
	string s, t;
	int n;
	int i = 0;
	cin >> n >> s >> t;
	for (int j = 0; j <n; ++j) {
		i = 0;
		while (s[j + i] == t[i] && i < n)
		{
			++i;
		}
		if (j + i == n) {
			cout << n + n - i << endl;
			return 0;
		}
	}
	cout << n + n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n,w;
	cin>>n>>w;
	vector<pair<long long,long long>> hoge(n);
	for(long long i=0;i<n;i++){
		cin>>hoge.at(i).first>>hoge.at(i).second;
	}

	vector<vector<long long>> dp(n+1,vector<long long>(w+1,-1));
	dp.at(0).at(0)=0;

	long long ans=0;

	for(long long i=0;i<n;i++){
		for(long long j=0;j<=w;j++){
			dp.at(i+1).at(j)=dp.at(i).at(j);

			if(j-hoge.at(i).second>=0){
				dp.at(i+1).at(j)=max(dp.at(i+1).at(j),dp.at(i).at(j-hoge.at(i).second)+hoge.at(i).first);
			}

			ans=max(ans,dp.at(i+1).at(j));
		}
	}

	cout<<ans<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}



Measured memory_bytes: 10800
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define ll long long
#define cases ll t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)


int main(){
    fast;
    ll i,j,n,m,r,u,v,k,x,y;
    ll ans=0;
    cin>>n>>k;
    vector<bool> chk(n+1,false);
    for(i=0;i<k;i++){
        cin>>j;
        while(j--){
            cin>>x;
            chk[x]=true;
        }
    }
    ans=count(chk.begin(),chk.end(),false)-1;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3604
n,m = gets.chomp.split(' ').map(&:to_i)
i = 0
students = []
while i < n
  a,b = gets.chomp.split(' ').map(&:to_i)
  students << [a,b]
  i += 1
end

position = []
i = 0
while i < m
  x,y = gets.chomp.split(' ').map(&:to_i)
  position << [x,y]
  i += 1
end

# p students,position

# 計算
ans = []
i = 0
while i < students.size
  j = 0
  # 基準値
  min = (students[i][0] - position[0][0]).abs + (students[i][1] - position[0][1]).abs
  min_p = 1
  # p "基準値:min/#{min}, min_p/#{min_p}"
  while j < position.size
    d = (students[i][0] - position[j][0]).abs + (students[i][1] - position[j][1]).abs
    if d < min
      min = d
      min_p = j+1
    end
    j += 1
  end
  p min_p
  i += 1
end

Measured memory_bytes: 14300
#include<iostream>
#include<cstring>
using namespace std;
long long s[2009];
const int mod=1e9+7; 
int main(){
    memset(s,0,sizeof(s));
    long long ans=1;
    int a;
    cin>>a;
    for(int i=1;i<=a;i++)
    s[i]=1;
    s[0]=0;
    s[1]=0;
    s[2]=0;
    for(int i=3;i<=a;i++){
        for(int j=3;i+j<=a;j++){
            s[i+j]+=s[i];
            s[i+j]%=mod;
        }
    }
    cout<<s[a]++;
    system("pause");

}

Measured memory_bytes: 3096
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

N=int(input().rstrip())
a=[int(i) for i in input().split()]
l=max(a)+1
cnt=[0]*l
for i in a:
    for j in range(i,l,i):cnt[j]+=1

ans=0
for i in a:
    if cnt[i]==1:
        ans+=1
print(ans)

Measured memory_bytes: 31476
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var str = Console.ReadLine();
            for (var i = 0; i < str.Length; i++)
                Console.Write("x");
        }
    }
}


Measured memory_bytes: 13140
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, T, inputs):
    routes = list(map(string_to_int, inputs))
    min_cost = -1
    for r in routes:
        if r[1] <= T and (min_cost == -1 or r[0] < min_cost):
            min_cost = r[0]
    if min_cost == -1:
        return "TLE"
    return str(min_cost)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, T] = string_to_int(input())
    ret = solve(N, T, inputs(N))
    print(ret)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int K,A,B;cin>>K>>A>>B;
  
  string x="NG";
  
  for(int i=A;i<=B;i++){
    if(i%K==0){
      x="OK";
      break;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

char s[100005],t[100005];
int ss[100005],st[100005];

int main(){
	scanf("%s%s",s,t);
	for(int i=0;s[i];++i){
		if(s[i]=='A')ss[i+1]=ss[i]+2;
		else ss[i+1]=ss[i]+1;
	}
	for(int i=0;t[i];++i){
		if(t[i]=='A')st[i+1]=st[i]+2;
		else st[i+1]=st[i]+1;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);a--;c--;
		if((ss[b]-ss[a])%3==(st[d]-st[c])%3)puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1536
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
r = int(sys.stdin.readline())
print(int(r**2))




Measured memory_bytes: 23496
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>

#define INT(X) \
  ( *( (const int *)(X) ) )

static int
compare (
  const void * a,
  const void * b
  )
{
  return ( INT( b ) - INT( a ) );
}

static uint64_t
factorial (
  uint64_t n
  )
{
  uint64_t res = 1;
  uint64_t i;

  for ( i = 2; i <= n; ++i )
  {
    res *= i;
  }

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int h[ CHAR_MAX + 1 ] = { 0 };
  int64_t res = 0, dv = 1;
  int dl = 0;
  int i, j;

  for ( ; ; )
  {
    const char ch = getchar ( );

    if ( ch == '\n' ) break ;

    ++h[ ch ];
  }

  qsort ( h, CHAR_MAX + 1, sizeof ( int ), compare );
  for ( i = 0; i <= CHAR_MAX; ++i )
  {
    if ( !( h[ i ] ) ) break ;
    if ( h[ i ] % 2 )
    {
      if ( dl )
      {
        puts ( "0" );
        goto CONTT;
      }

      --h[ i ];
      ++dl;
    }

    h[ i ] /= 2;
    res += h[ i ];
    dv *= factorial ( h[ i ] );
  }

  printf ( "%llu\n", factorial ( res ) / dv );
CONTT: ;

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

int main(){
	int n,a,b,c,d;
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);

	vector<vector<mint>> dp(2,vector<mint>(n+1));
	dp[0][0]=1;
	for(int x=a;x<=b;x++){
		dp[1]=dp[0];
		for(int y=c;y<=d;y++){
			mint p=pow(fact_inverse(x),y);
			for(int w=n;w>=y*x;w--){
				dp[1][w]+=dp[0][w-y*x]*p*fact_inverse(y);
			}
		}
		dp[0]=dp[1];
	}
	cout<<fact(n)*dp[0][n]<<'\n';

	return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    s = input()
    t = input()

    s = list(s)
    s.sort()
    s2 = ""
    for moji in s:
        s2 += moji

    t = list(t)
    t.sort(reverse=True)
    t2 = ""
    for moji in t:
        t2 += moji
    
    if s2 < t2:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

int i,j,n,max[3],dummy;

for(i=0;i<3;i++){
max[i]=0;
}

for(i=0;i<10;i++){

  scanf("%d",&n);

for(j=0;j<3;j++){
 if(n>max[j]){
   dummy=max[j];
   max[j]=n;
   n=dummy;
  }
 }
}

for(i=0;i<3;i++){
printf("%d\n",max[i]);
}

}

Measured memory_bytes: 1028
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
typedef long long ll;

const int MOD = 1000000007;

ll fac[100000+10];
ll facinv[100000+10];

ll mypow(ll x, ll n) {
  if(n == 0) return 1;
  if(n % 2 == 0) return mypow(x*x%MOD, n/2);
  return mypow(x*x%MOD, n/2) * x % MOD;
}

inline ll cmb(int n, int k) {
  if(k < 0 || n < k) return 0;
  return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
}
inline ll perm(int n, int k) {
  if(k < 0 || n < k) return 0;
  return fac[n] * facinv[n-k] % MOD;
}

vector<int> g[100000+5];
int K;

ll go(int p, int u) {
  ll res;
  if(p == -1) {
    res = perm(K, (int)g[u].size()+1);
  } else {
    res = perm(K-2, (int)g[u].size()-1);
  }
  for(int v : g[u]) {
    if(v != p) {
      res = res * go(u, v) % MOD;
    }
  }
  return res;
}

int main(void) {
  fac[0] = 1;
  REP(i, 100000) {
    fac[i+1] = fac[i] * (i+1) % MOD;
  }
  facinv[100000] = mypow(fac[100000], MOD-2);
  for(int i = 99999; i >= 0; --i) {
    facinv[i] = facinv[i+1] * (i+1) % MOD;
  }
  int n;
  scanf("%d%d", &n, &K);
  REP(i, n-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cout << go(-1, 0) << endl;
  
  return 0;
}


Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	char a,b;
	cin>>a>>b;
	switch(a){
		case 'H':
			switch(b){
			case 'H':
				cout<<'H'<<endl;
				break;
			case 'D':
				cout<<'D'<<endl;
				break;
			}
			break;
		case 'D':
			switch(b){
			case 'H':
				cout<<'D'<<endl;
				break;
			case 'D':
				cout<<'H'<<endl;
				break;
			}
			break;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
def lcm(m, n):
    return m // gcd(m, n) * n
def solve():
    N = int(readline())
    if N == 0:
        return False

    pp = [13, 17, 19, 23]
    E = [[0]*i for i in range(25)]
    Q = []
    for i in range(N):
        d, t, *qs = map(int, readline().split())
        qs = qs[t:] + qs[:t]
        Ed = E[d]
        for i in range(d):
            Ed[i] += qs[i]
    L = 13860
    V = [0]*L
    for i in range(1, 25):
        if i in pp:
            continue
        if i <= 12:
            Ei = E[i]; Ej = E[2*i]
            for j in range(2*i):
                Ej[j] += Ei[j % i]
        else:
            Ei = E[i]
            if i == 16:
                for j in range(8):
                    Ei[j] = max(Ei[j+8], Ei[j])
                Ej = E[24]
                for j in range(24):
                    Ej[j] += Ei[j % 8]
            elif i == 24:
                for j in range(12):
                    Ei[j] = max(Ei[j+12], Ei[j])
                for j in range(L):
                    V[j] += Ei[j % 12]
            else:
                for j in range(L):
                    V[j] += Ei[j % i]
    ans = max(V)
    for i in pp:
        ans += max(E[i])
    write("%d\n" % ans)
    return True
while solve():
    ...


Measured memory_bytes: 5984
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

h,w=LI()
h,w,g,sg=GGI(h,w,search=['S','G'])
dp=[1e6]*(h*w)
dp[w+1]=g[w+1]

for j in range(h*w-w):
  for d in (1,w):
    dp[j+d]=min(dp[j]+1 if (g[j],g[j+d])==(0,1) else dp[j],dp[j+d])

print(dp[(h-2)*w+w-2])


Measured memory_bytes: 41708
/* ALDS1_5_C: Koch Curve */
/* 20181119 */

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <math.h>

#define rad M_PI / 3

typedef struct {
	double x;
	double y;
} Point;

void cochCurve(Point start_p, Point end_p, int n);
Point rotatePoint(Point p1, Point p3);
void printPoint(Point p);

int main(void){
	int n;
	Point start_p = {0, 0}, end_p = {100, 0};
	scanf("%d", &n);

	printPoint(start_p);
	cochCurve(start_p, end_p, n);
	printPoint(end_p);

	return  0;
}

void cochCurve(Point start_p, Point end_p, int n){
	if(n == 0) return ;

	Point p1 = {start_p.x + (end_p.x - start_p.x) / 3, start_p.y + (end_p.y - start_p.y) / 3};
	Point p3 = {start_p.x + 2 * (end_p.x - start_p.x) / 3, start_p.y + 2 * (end_p.y - start_p.y) / 3};
	Point p2 = rotatePoint(p1, p3);
	
	cochCurve(start_p, p1, n - 1);
	printPoint(p1);
	cochCurve(p1, p2, n-1);
	printPoint(p2);
	cochCurve(p2, p3, n-1);
	printPoint(p3);
	cochCurve(p3, end_p, n - 1);
}

Point rotatePoint(Point p1, Point p3){
	double x = p3.x - p1.x;
	double y = p3.y - p1.y;
	Point p2 = {p1.x + (x * cos(rad)- y * sin(rad)), p1.y +(x * sin(rad) + y * cos(rad))};

	return p2;
}

void printPoint(Point p){
	printf("%lf %lf\n", p.x, p.y);
}


Measured memory_bytes: 1916
#include<iostream>
using namespace std;

int main(){
  int i,n;
  cin>>n;
  long long a[n+1],b[n],sum=0;
  for(i=0;i<n+1;i++) cin>>a[i];
  for(i=0;i<n;i++) cin>>b[i];
  
  for(i=0;i<n;i++){
    if(b[i]>=a[i]){
      sum+=a[i];
      b[i]=b[i]-a[i];
      a[i+1]-=b[i];
      if(a[i+1]<=0){
        sum+=(b[i]+a[i+1]);
        a[i+1]=0;
      }
      else sum+=b[i];
    }
    else sum+=b[i];
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define N 100

void main(){
  int m, n, a[N], cnt=0;
  long int sum_vote=0;
  scanf("%d %d", &n, &m);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum_vote += a[i]; 
  }
  
  float threshold = 0.25/m;
  for(int i=0; i<n; i++){
    float vote = a[i]*1.0/sum_vote;
//    printf("%d %f %f\n",i,vote,threshold);
    if(vote>=threshold)
      cnt++;
  }
  
  if(cnt>=m)
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 1732