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

/* 値を入れ替える関数 */
void swap (long long *x, long long *y) {
    long long temp;    // 値を一時保存する変数
    
    temp = *x;
    *x = *y;
    *y = temp;
}

/***
 * pivotを決め、
 * 全データをpivotを境目に振り分け、
 * pivotの添え字を返す
 ***/
int partition (long long array[], int left, int right,long long A[]) {
    int i, j, pivot;
    i = left;
    j = right + 1;
    pivot = left;   // 先頭要素をpivotとする
    
    do {
        do { i++; } while (array[i] < array[pivot]);
        do { j--; } while (array[pivot] < array[j]);
        // pivotより小さいものを左へ、大きいものを右へ
        if (i < j) {
            swap(&array[i], &array[j]);
            swap(&A[i],&A[j]);
        }
    } while (i < j);
    
    swap(&array[pivot], &array[j]);   //pivotを更新
    swap(&A[pivot],&A[j]);
    
    return j;
}

/* クイックソート */
void quick_sort (long long array[], int left, int right,long long A[]) {
    int pivot;
    
    if (left < right) {
        pivot = partition(array, left, right,A);
        quick_sort(array, left, pivot-1,A);   // pivotを境に再帰的にクイックソート
        quick_sort(array, pivot+1, right,A);
    }
}

int main(void){
    int i,j,k;
    int index;
    unsigned int N;
    long long A[200000],B[200000],temp;
   
    scanf("%d",&N);
    for(i = 0;i < N-1;i++){
        scanf("%lld %lld\n",&A[i],&B[i]);
    }
    scanf("%lld %lld",&A[i],&B[i]);
    
    //ソート処理
    /*
    for(i = 0;i < N;i++){
        index = i;
        for(j = i+1;j < N;j++){
            if(B[j] < B[index]){
                index = j;
            }
        }
        temp = B[index];
        B[index] = B[i];
        B[i] = temp;
        temp = A[index];
        A[index] = A[i];
        A[i] = temp;
    }
     */
    
    quick_sort(B,0,N-1,A);
    
    //判定処理
    if(A[0] > B[0]){
        printf("No\n");
        return 0;
    }
    for(i = 1;i < N;i++){
        A[i] += A[i - 1];
        if(A[i] > B[i]){
            printf("No\n");
            return 0;
        }
    }
 
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 3328
def pow_r(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2)


x = int(input())
for a in range(-100, 1000):
    for b in range(-100, 1000):
        if x == (pow_r(a, 5)) - (pow_r(b, 5)):
            print(a, b)
            exit()



Measured memory_bytes: 68952
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

typedef long long lint;

using namespace std;

void test_case() {
    int n, q;
    lint sum = 0;
    cin >> n;
    map<int, int> mp;
    for(int x, i = 0; i < n; ++i) {
        cin >> x;
        mp[x]++;
        sum += x;
    }
    cin >> q;
    int b, c, cnt;
    while(q--) {
        cin >> b >> c;
        sum  = sum + (c-b)*mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int tests = 1;
    //cin >> tests;
    for(int test = 0; test < tests; ++test) {
        test_case();
    }
    return 0;
}


Measured memory_bytes: 8072
#include<stdio.h>

int main(void){

    int A,B,C,K;
    int count=0;

    scanf("%d %d %d",&A,&B,&C);
    scanf("%d",&K);

    while(B<=A){
        B *= 2;
        count++;
    }
    while(C<=B){
        C *= 2;
        count++;
    }

    if(count<=K){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<map>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<utility>
#include<string.h>
#include<string>
#define n 200000
#define loop(a, b) for(int i=a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
bool visit[n + 50];
lli arr[n + 50], a, b, c, d, e;
string str1, str2;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
}

////////////////////////////////////////

void solve()
{
	cin >> a;
	a--;
	lli ans = a * (a + 1) * 1ll;
	ans = (lli)ans / 2;	
	cout << ans << '\n';
}
int main()
{
	int times = 1;
//	cin >> times;
	loop(0, times - 1)
	{
		solve();
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 6400
#include<iostream>
#include<vector>
#include<queue>
#include<tuple>
#include<set>
#include<functional>
using namespace std;

const char Water = '#';
const char Earth = '.';
const char Tower = '&';

const vector<vector<int>> Next = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
enum {COST, Y, X};
typedef tuple<int, int, int> Node;

int bfs(const vector<string>& field) {
    int h = field.size();
    int w = field[0].size();

    set<tuple<int, int>> visited;
    priority_queue<Node, vector<Node>, greater<Node>> q;
    q.push(Node(0, 0, 0));
    while(!q.empty()) {
        int y = get<Y>(q.top());
        int x = get<X>(q.top());
        int cost = get<COST>(q.top());
        q.pop();
        if(field[y][x] == Tower) return cost;
        if(visited.count(tuple<int, int>(y, x))) continue;
        visited.insert(tuple<int, int>(y, x));
        for(const auto& d: Next) {
            int ny = y + d[0];
            int nx = x + d[1];
            int ncost = cost;
            if(ny < 0 || h <= ny) continue;
            if(nx < 0 || w <= nx) continue;
            if(field[y][x] == Water && field[ny][nx] != Water) ++ncost;
            q.push(Node(ncost, ny, nx));
        }
    }
    return 0;
}

int main() {
    int n, m;
    while(cin >> n >> m, n | m) {
        vector<string> field(m + 2);
        for(int i = 1; i <= m; ++i) {
            string s;
            cin >> s;
            field[i] = Earth + s + Earth;
        }
        for(int j = 0; j < n + 2; ++j) {
            field[0] += Earth;
            field[m + 1] += Earth;
        }
        cout << bfs(field) << endl;
    }
}

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

using namespace std;

#define ll  long long
#define X   first
#define Y   second

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb      emplace_back
#define endl    "\n"

const ll    inf = 1e18;
const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

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

    int n;  cin >> n;
    int k;  cin >> k;
    int S;  cin >> S;

    for(int i = 0 ; i < k ; ++i)    cout << S << " ";
    for(int i = k ; i < n ; ++i)    cout << (S + 1) % 1000000000 << " ";
}

Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>

using namespace std;

int mountain[10];

int main()
{
	for(int i= 0;i<10;i++)
	{
		scanf("%d",&mountain[i]);
	}
	sort(mountain,mountain+10);
	for(int i= 0;i<3;i++)
	{
		printf("%d\n",mountain[9-i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  cout<<fixed<<setprecision(10);
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0; i<N; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  for(int i=1; i<N; ++i){
    v[i] = (v[i-1]+v[i])/2.0;
  }
  cout << v[N-1] << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	long long int n;
	long long int count = 0;
	long long int maxi = -1;

	cin >> n;
	vector<long long int>a(n);
	FOR(i, 0, n - 1) {
		cin >> a[i];
		count += a[i];
	}
	count -= n;
	/*FOR(m, 0, 100001) {
		count = 0;
		FOR(i, 0, n - 1) {
			count += m % a[i];
		}
		if (count > maxi) {
			maxi = count;
		}
	}*/

	cout << count << endl;
	//cout << maxi << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 205
struct node {
	int x,y;
}red[MAXN],blue[MAXN];
int N;
vector<int> bag[MAXN];
bool vis[MAXN];
int matched[MAXN];
bool un(int u) {
	for(int i=0;i<int(bag[u].size());i++)
		if(!vis[bag[u][i]]) {
			int v=bag[u][i];
			vis[v]=1;
			if(!matched[v]||un(matched[v])){
				matched[u]=v;
				matched[v]=u;
				return 1;
			}
		}
	return 0;
}
int result() {
	int ans=0;
	for(int i=1;i<=2*N;i++){
		if(!matched[i]) {
			memset(vis,0,sizeof vis);
			ans+=un(i);
		}
	}
	return ans;
}
int main() {
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&red[i].x,&red[i].y);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&blue[i].x,&blue[i].y);
	
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			if(red[i].x<blue[j].x&&red[i].y<blue[j].y){
				bag[i].push_back(j+N);
				bag[j+N].push_back(i);
			}
	int ans=result();
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int N,M; cin >> N >> M;
        if (N+M==0) break;
        vector<pll> A(N);
        rep(i,N) cin >> A[i].second >> A[i].first;
        sort(all(A)); reverse(all(A));
        ll ans = 0;
        rep(i,N) {
            if (A[i].second > M) {
                ans += (A[i].second-M)*A[i].first;
                M = 0;
            } else {
                M -= A[i].second;
            }
        }

        cout << ans << ln;
    }
}


Measured memory_bytes: 3344
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    int k;
    int s=0;
    cin>>n>>k;
    vector<int> a(200000,0);
    for(int i=0;i<n;i++){
        int j;
        cin>>j;
        if(a[j-1]==0)s++;
        a[j-1]++;
    }
    vector<int> b;
    for(int i=0;i<200000;i++){
        if(a[i]!=0){
            b.push_back(a[i]);
        }
    }
    sort(b.begin(),b.end());
    int ans=0;
    int i=0;
    while(1){
        if(s<=k)break;
        ans+=b[i];
        s--;
        i++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2168
using System;

namespace ABC_075_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int A = int.Parse(word[0]);
            int B = int.Parse(word[1]);
            int C = int.Parse(word[2]);
            if (A == B && A != C)
            {
                Console.WriteLine(C);
            }
            else if (A != B && A == C)
            {
                Console.WriteLine(B);
            }
            else if (B == C && B != A)
            {
                Console.WriteLine(A);
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
  int main(){
      int A;
      int B;
      int X;
      cin >> A >> B >> X;
      if(A <= X ){
          if(B > X - A){
            cout << "YES" << endl;
          }
          else if (X - A > B){
              cout << "NO" << endl;
          }
         } 
         else{cout << "NO" << endl;}
  }
 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n,k,d,D[10];
    int i,j;
    scanf("%d %d",&n,&k);
    for (i = 0; i < k; i++)
    {
        scanf("%d",&d);
        D[d] = 1;
    }
    char ans[10];
    int len;
    while (1)
    {
        snprintf(ans,10,"%d",n);
        len = strlen(ans);
        for (i = 0; i < len; i++)
        {
            if(D[ans[i] - '0'] == 1)break;
        }
        if(i == len)break;
        n++;
    }
    
    printf("%d",n);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll N;
    cin >> N;

    ll ans = 0;

    for (ll i=1;(i+1)*i<N;++i)
    {
        if ((N % i) == 0) { ans += (N / i) - 1; }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int k,x,i;
  cin>>k>>x;
  for(i=x-(k-1);i<=x+(k-1);i++)
  {
    if(i!=x+(k-1))
    cout<<i<<" ";
    if(i==x+(k-1))
      cout<<i;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int leijia(int i,char s[],int sum)
{
    if(s[i+1]=='B')
    {
    	i++;
    	if(s[i+1]=='C')
    	{
    		i+=2;
    	    sum++;
		}
	}
	return sum;
}
int main()
{
    int n,sum=0;
    cin>>n;
    char s[n+1];
    for(int i=0;i<n;i++)
	cin>>s[i];
	for(int i=0;i<n;i++)
    if(s[i]=='A') sum=leijia(i,s,sum);
    cout<<sum;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int bfs(int n, int cnt, int next, int s) {
        if (cnt == n && s == 0) return 1;
        else if (cnt == n || s < 0) return 0;

        int count = 0;
        for (int i = next; i <= 9; ++i) {
            count += bfs(n, cnt + 1, i + 1,s - i);
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int n = scanner.nextInt(), s = scanner.nextInt();
            if (n == 0 && s == 0) break;

            System.out.println(bfs(n, 0, 0, s));
        }
    }
}


Measured memory_bytes: 26384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  if(N==26){
    if(S=="zyxwvutsrqponmlkjihgfedcba") S="-1";
    else{
      REP(o,2,N){
        int i=N-o;
        int memo=-1;
        char X;
        rep(j,i+1,N){
          if(S[i]<S[j]){
            if(memo==-1||X>S[j]){
              memo=j;
              X=S[j];
            }
          }
        }
        if(memo!=-1){
          swap(S[i],S[memo]);
          S=S.substr(0,i+1);
          break;
        }
      }
    }
  }
  else{
    vector<bool> F(26,1);
    rep(i,0,N) F[S[i]-'a']=0;
    rep(i,0,26){
      if(F[i]){
        S+=i+'a';
        break;
      }
    }
  }
  cout<<S<<endl;
  }


Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))


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

int main(){
  long long int n,a,b,ab,c,ans;
  cin >> n >> a >> b;
  ab = n/(a+b);
  c = n%(a+b);
  ans = a*ab;
  if(c>a)
    ans += a;
  else
    ans+=c;
    
  cout << ans;
  return 0;  
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n;
    cin>>n;
    int a[n],c=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if(a[i]!=i+1)
        c++;

    }
    if(c<=2)
    {
        cout<<"YES"<<endl;

    }
    else
        cout<<"NO"<<endl;



}
//Alhamdulillah







Measured memory_bytes: 3656
//Chocolate

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int N,D,X;cin>>N>>D>>X;
    vector<int> A(N);
    rep(i,0,N)cin >> A[i];
    rep(i,0,N){
        int cc=0;
        while(true){
            if(cc*A[i]+1<=D)X++;
            else break;
            cc++;
        }
    }
    cout << X << endl;
    return 0;
}

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

int main(){
  long long n;
  cin >> n;
  int ans=10;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      int p=n/i;
      int count=0;
      while(p){
        p/=10;
        count++;
      }
      ans=min(ans,count);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3680
//最短路径问题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int b=tx-sx,a=ty-sy;
    int x=0,y=0,i=2;
    //既要去也要返回
    while(i>0)
    {
        while(x<a)
        {
            cout<<'U';
            x++;
        }
        while(y<b)
        {
            cout<<'R';
            y++;
        }
       i==2?cout<<"":cout<<"RDRD";
        while(x>0)
        {
            cout<<'D';
            x--;
        }
        while(y>0)
        {
            cout<<'L';
            y--;
        }
        cout<<"LU";
        i--;
    }
    return 0;
}


Measured memory_bytes: 256
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  auto n = readln.chomp.to!(char[]);

  auto dp = new long[][][][](n.length + 1, 2, 1000, 2);
  dp[0][0][0][0] = 1;
  foreach (i; 0 .. (n.length)) {
    foreach (l; 0 .. 2) {
      foreach (k; 0 .. 1000) {
        foreach (ok; 0 .. 2) {
          auto x = k / 100, y = (k / 10) % 10, z = k % 10;
          auto d = l ? 9 : (n[i] - '0');
          for (int digit = 0; digit <= d; digit++) {
            auto less = l || (digit < d);
            auto okok = ok || (x == 5 && y == 1 && digit == 3);
            dp[i + 1][less][y * 100 + z * 10 + digit][okok] += dp[i][l][k][ok];
          }
        }
      }
    }
  }
  long s = 0;
  foreach (j; 0 .. 2) {
    foreach (k; 0 .. 1000) {
      s += dp[n.length][j][k][1];
    }
  }
  writeln(s);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}



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

int main() {
  int N;
  cin >> N;
  vector<int> H(30);
  for(int i=0;i<N;i++)cin >> H[i];
  int cnt=1; int M=H[0];
  for(int i=1;i<N;i++){
    if(H[i]>=M){cnt++; M=H[i];}
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,W,w[101],v[101],dp[101][10001]={0};
	cin>>n>>W;
	for(int i=0;i<n;i++)cin>>v[i]>>w[i];
	for(int i=n-1;i>=0;i--)for(int j=0;j<=W;j++)
	{
		if(j<w[i])dp[i][j]=dp[i+1][j];
		else dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
	}
	cout<<dp[0][W]<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
    string s; cin>>s;
    int N = s.size();
    ll ans = 0;
    ll stock = 0;
    REP(i,N-1){
        if(s[i]=='A'){
            ++stock;
        }else if(s.substr(i,2)=="BC"){
            ans += stock;
            ++i;
        }else{
            stock = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int main(){
int n,p[101],a[101],cnt=0;
memset(a,0,sizeof(a));
cin >> n;
for(int i=0;i<n;i++){
cin >> p[i];
}
for(int j=0;j<n;j++){
for(int i=0;i<p[j];i++){
a[i]++;
}
}
for(int i=0;i<=100;i++){
if(a[i] < i+1){
cout << i << endl;
break;
}
}
return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2104
S = input()

abc = list("abcdefghijklmnopqrstuvwxyz")
# ord('a') = 97
n = len(abc)
check = [0] * n
for s in S:
    check[ord(s) - 97] = 1

if S == ''.join(abc[::-1]):
    print(-1)
    exit()

if sum(check) != n:
    for i in range(n):
        if check[i] == 0:
            S += abc[i]
            break
    print(S)
else:
    check = [0] * n
    for i in range(0, n):
        check[ord(S[::-1][i]) - 97] = 1
        if S[::-1][i] > S[::-1][i + 1]:
            c = 24 - i
            break
    # print(c)
    # print(check)
    # print(S[c])
    ans = S[:c]
    for i in range(ord(S[c]) - 97, n):
        if check[i] == 1:
            ans += abc[i]
            break
    print(ans)


Measured memory_bytes: 3064
def main():
  H, N = map(int, input().split())
  
  sum = 0
  
  A = list(map(int, input().split()))
  
  for a in A:
    sum += a
  
  if(sum >= H):
    print('Yes')
  else:
    print('No')
  
  return 0

if __name__ == "__main__":
  main()

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

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	string s;
	cin >> s;
	string res = "";
	for (char c : s) {
		if (c == 'B') {
			if (!res.empty()) {
				res.erase(res.end() - 1);
			}
		} else {
			res += c;
		}
	}
	cout << res << '\n';

	return 0;
}



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

int main() {
    int n;cin>>n;
    string str;
    if(n==25)str="Christmas";
    if(n==24)str="Christmas Eve";
    if(n==23)str="Christmas Eve Eve";
    if(n==22)str="Christmas Eve Eve Eve";
    cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)


int main() {
    int x,y;
    cin >> x >> y;
    cout << x + y/2 << endl;
}

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

int main(){
	int H,W,i,j;
	for(;;){
		cin>>H>>W;
		if(H==0&&W==0)break;
		for(j=0;j<H;j++){
			for(i=0;i<W;i++){
				cout<<"#";
			}
			cout<<endl;
		}
	cout<<endl;
	}
}



Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	int[] A;
	boolean[] flags;
	int AMAX = 1000001;
	Deque<Integer> uncheck;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = Integer.parseInt(tokens[i]);
		}
		Arrays.sort(A);
		flags = new boolean[AMAX + 1];
		Arrays.fill(flags, true);
		uncheck = new ArrayDeque<>();
		for (int i = 0; i < N; ++i) {
			uncheck.add(i);
		}
	}

	void check(int[] array, int target) {
		Deque<Integer> temp = new ArrayDeque<>();
		if (target + 1 < N && array[target] == array[target + 1]) {
			flags[target] = false;
		}
		uncheck.poll();
		while (!uncheck.isEmpty()) {
			int i = uncheck.poll();
			if (array[i] % array[target] == 0) {
				flags[i] = false;
			} else {
				temp.add(i);
			}
		}
		uncheck = temp;
	}

	void calc() {
		int count = 0;
		while (!uncheck.isEmpty()) {
			int target = uncheck.poll();
			if (!flags[A[target]]) {
				continue;
			} else if (target + 1 < N && A[target] == A[target + 1]) {
				flags[A[target]] = false;
			} else {
				++count;
				flags[A[target]] = false;
			}
			for (int val = A[target] * 2; val <= AMAX; val += A[target]) {
				flags[val] = false;
			}
		}
		System.out.println(count);
	}

	void showResult() {
	}
}

Measured memory_bytes: 64704
//                                                   ¯\_(ツ)_/¯
  #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=3e7+5,MOD=998244353;

using namespace std;

int n,W;
ll dp[105][100005];
ll ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


	scanf("%d %d",&n,&W);

	for(int i=0,we,gain;i<n;i++){

		scanf("%d %d",&we,&gain);
		if(i==0)
			for(int j=we;j<=W;j++)dp[0][j]=gain;
		else
			for(int j=1;j<=W;j++){
				if(j>=we)
					dp[i][j]=max(dp[i-1][j],gain+dp[i-1][j-we]);
				else
					dp[i][j]=dp[i-1][j];

			}
	}

	printf("%lld\n",dp[n-1][W]);

	

}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int INF=1e18;

int dist(int a,int b,int c){
    return abs(b-a)+abs(c-b);
}

signed main()
{
    int A,B,Q; 
    cin>>A>>B>>Q;
    vint s(A+2),t(B+2);
    REP(i,A) cin>>s[i+1];
    REP(i,B) cin>>t[i+1];

    s[0]=-INF; s[A+1]=INF;
    t[0]=-INF; t[B+1]=INF;

    while(Q--){
        int x; cin>>x;
        int sR,sL,tR,tL;
        sR=*lower_bound(ALL(s),x);
        sL=*(upper_bound(ALL(s),x)-1);
        tR=*lower_bound(ALL(t),x);
        tL=*(upper_bound(ALL(t),x)-1);

        int ans=INF;
        REP(i,2) REP(j,2){
            int a=(i==0? sR:sL);
            int b=(j==0? tR:tL);
            ans=min(ans,dist(x,a,b));
            ans=min(ans,dist(x,b,a));
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 2944
# # Binary Indexed Tree (Fenwick Tree)
# class BIT:
#     def __init__(self, n):
#         self.n = n
#         self.data = [0]*(n+1)
#         self.el = [0]*(n+1)
#     def sum(self, i):
#         s = 0
#         while i > 0:
#             s += self.data[i]
#             i -= i & -i
#         return s
#     def add(self, i, x):
#         # assert i > 0
#         self.el[i] += x
#         while i <= self.n:
#             self.data[i] += x
#             i += i & -i
#     def get(self, i, j=None):
#         if j is None:
#             return self.el[i]
#         return self.sum(j) - self.sum(i)

# N = int(input())
# P = [int(i) for i in input().split()]

# res = 0
# bit = BIT(200010)
# for i, p in enumerate(P):
#     bit.add(p, 1)
#     res += 1 if bit.sum(p) <= 1 else 0
#     # print(bit.sum(p))

# print(res)
INF = 10**18

N = int(input())
P = [int(i) for i in input().split()]

minp = INF
res = 0
for p in P:
    if p < minp:
        minp = p
        res += 1
print(res)

Measured memory_bytes: 24744
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b] <- readInts
  print $ solve a b

solve a b = max (max (a + (a - 1)) (b + (b - 1))) (a + b)

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<stack>
using namespace std;

#define len 1e5+1
#define maxwt 1e15

int main(){
    string s; cin>>s; int st=0;

    int a,b; a=(s[0]-48)*10+s[1]-48; b=(s[2]-48)*10+s[3]-48;
    int sa=-1,sb=-1;
    if(0<a && a<=12) sa=0;
    if(0<b && b<=12) sb=0;
    if(sa==-1 && sb==-1) cout<<"NA"<<endl;
    else if(sa==0 && sb==0) cout<<"AMBIGUOUS"<<endl;
    else if(sa==0) cout<<"MMYY"<<endl;
    else cout<<"YYMM"<<endl;
}








Measured memory_bytes: 256
n,k = gets.chomp.split(" ").map(&:to_i)
p_arr = gets.chomp.split(" ").map(&:to_i)

expect = [0]
tmp_sum = 0
(1..200000).each do |i|
  tmp_sum += i
  expect << (tmp_sum) / i.to_f
end

tmp_arr = p_arr[0..(k-1)]
sum = 0
tmp_arr.each do |a|
  sum += expect[a]
end
max = sum
(k..p_arr.length-1).each do |i|
  p = tmp_arr.shift
  tmp_arr.push(p_arr[i])
  sum = sum - expect[p] + expect[p_arr[i]]
  max = sum if max < sum
end

puts max


Measured memory_bytes: 18444
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
 
 
int main()
{
	float R;
	const double PI=3.14159265358979323846;
 
	cin >> R;
 
	cout << fixed << setprecision(10) << 2 * PI * R; 
 
	return 0;
	
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  ll N;
  cin>>N;
  ll i=1;
  ll ans=0;
  while(i<N){
    if(N%i==0) if((N-i)%i==0&&(N-i)/i>i) ans+=(N-i)/i;
    if((N-i)/i<=i) break;
    i++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int,input().split())

from fractions import gcd
a = gcd(n,m)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

t = factorization(a) 

if (n == 1) or (m == 1):
    print(1)
else:
    print(len(t)+1)

Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-6
using namespace std;
typedef long long ll;
const ll mod = 998244353;
//const double pi = acos(-1);
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,h,w,k,tot;
int num[5];
int R[10],C[10],r,c,ans;
bool visr[10],visc[10];
bool vis[10][10];
char ch[10][10];
bool check(){
	int i,j;
	for(i=1;i<=r;i++){
		for(j=1;j<=w;j++){
			if(vis[R[i]][j]) continue;
			vis[R[i]][j]=1;
			if(ch[R[i]][j]=='#') tot--;
		}
	}
	for(j=1;j<=c;j++){
		for(i=1;i<=h;i++){
			if(vis[i][C[j]])continue;
			vis[i][C[j]]=1;
			if(ch[i][C[j]]=='#') tot--;
		}
	}
	bool flag=0;
	if(tot==k) flag=1;
	for(i=1;i<=r;i++){
		for(j=1;j<=w;j++){
			if(!vis[R[i]][j]) continue;
			vis[R[i]][j]=0;
			if(ch[R[i]][j]=='#') tot++;
		}
	}
	for(j=1;j<=c;j++){
		for(i=1;i<=h;i++){
			if(!vis[i][C[j]])continue;
			vis[i][C[j]]=0;
			if(ch[i][C[j]]=='#') tot++;
		}
	}
	return flag;
}
void solve2(int now,int las,int y){
	if(now==y) {
		if(check()) ans++;
		return ;
	}
	int i;
	for(i=las+1;i<=w;i++){
		if(!visc[i]){
			visc[i]=1;C[++c]=i;
			solve2(now+1,i,y);
			visc[i]=0;c--;
		}
	}
	
}
void solve1(int now,int las,int x,int y){
	if(now==x) {
		solve2(0,0,y);
		return ;
	}
	int i;
	for(i=las+1;i<=h;i++){
		if(!visr[i]){
			visr[i]=1;R[++r]=i;
			solve1(now+1,i,x,y);
			visr[i]=0;r--;
		}
	}
}
int main(){
    int i,j;
    h=read(),w=read(),k=read();
    for(i=1;i<=h;i++){
    	scanf("%s",ch[i]+1);
    	for(j=1;j<=w;j++){
    		if(ch[i][j]=='#') tot++;
    	}
	} 
    for(i=0;i<=h;i++){
    	for(j=0;j<=w;j++){
    		solve1(0,0,i,j);
    	}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ull n,x,y,min=9999999999999;
    cin>>n;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            x=i;
            y=n/i;
            x-=1;
            y-=1;
            if((x+y)<min)
                min=x+y;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 3660
// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define sz(a) (int)(a.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    string str;
    cin>>str;
    int n = str.size();
    if(str[0] == str[n-1]) {
        if(n%2) cout<<"Second";
        else cout<<"First";
    }
    else {
        if(n%2) cout<<"First";
        else cout<<"Second";
    }

    return 0;
}   

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;

  vector<string>words(n);
  char word_last;
  int same = 0;

  int word_long = 0;

  for(int i=0;i<n;i++){
    cin >> words[i];
  }

  word_long = words[0].length();
  word_last = words[0][word_long-1];



  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      if(words[i] == words[j])
        same = 1;
    }
    if(same == 1)
      break;
    else if(word_last != words[i][0]){
      same = 1;
      //cout << "same = 1" << endl;
      break;
    }
    else{
      word_long = words[i].length();
      word_last = words[i][word_long-1];
      //cout << "word_last = " << word_last << endl;
    }
  }

  if(same == 1)
    cout << "No" << endl;
  else
    cout << "Yes" <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>

#include <cassert>
#include <climits>

#include <string.h>

#include <vector>
#include <map>
#include <stack>
#include <deque>

int n, m;
int q;

std::vector< std::vector<int> > connection;
std::vector<int> color;

void breadthFirstSearch(int first, int id)
{
    std::deque<int> dq;
    assert(color[first] == -1);

    dq.push_back(first);
    color[first] = id;

    while (! dq.empty())
    {
        int current = dq.front();
        dq.pop_front();

        for (std::vector<int>::iterator it = connection[current].begin(); it != connection[current].end(); ++it)
        {
            if (color[(*it)] > -1)
            {
                continue;
            }

            dq.push_back(*it);
            color[(*it)] = id;
        }
    }
}

int main()
{
    std::cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        std::vector<int> line;
        connection.push_back(line);

        color.push_back(-1);
    }

    for (int i = 0; i < m; ++i)
    {
        int a, b;
        std::cin >> a >> b;

        connection[a].push_back(b);
        connection[b].push_back(a);
    }

    int id = 0;
    for (int i = 0; i < n; ++i)
    {
        if (color[i] == -1)
        {
            breadthFirstSearch(i, id++);
        }
    }

    std::cin >> q;
    for (int i = 0; i < q; ++i)
    {
        int a, b;
        std::cin >> a >> b;
        std::string ans = (color[a] == color[b]) ? "yes" : "no";
        std::cout << ans << std::endl;
    }

    return 0;
}






Measured memory_bytes: 8760
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX = 30;

typedef struct Edge
{
  int d, c;
};

class State
{
public:
  int nc, pc, nv;
  double nt;

  State() {}
  State(int a, int b, int c, double d)
    :nc(a), pc(b), nv(c), nt(d) {}

  inline void set(int a, int b, int c, double d)
  {
    nc = a;
    pc = b;
    nv = c;
    nt = d;
  }

  bool operator <(const State& rhs) const
  {
    return this->nt > rhs.nt;
  }

};

int main()
{
  int n, m, s, g;
  Edge cost[MAX][MAX];
  double time[MAX][MAX][MAX+1];
  bool visited[MAX][MAX][MAX+1];

  while (scanf("%d %d", &n, &m) != EOF) {
    if (n == 0 && m == 0)
      break;

    scanf("%d %d", &s, &g);
    --s;
    --g;

    for (int i = 0; i < MAX; ++i) {
      for (int j = 0; j < MAX; ++j)
	cost[i][j].d = cost[i][j].c = -1;
    }

    for (int i = 0; i < m; ++i) {
      int x, y, d, c;
      scanf("%d %d %d %d", &x, &y, &d, &c);
      --x;
      --y;
      cost[x][y].d = cost[y][x].d = d;
      cost[x][y].c = cost[y][x].c = c;
    }

    for (int i = 0; i < MAX; ++i) {
      for (int j = 0; j < MAX; ++j) {
	for (int k = 0; k < MAX+1; ++k) {
	  time[i][j][k] = 999999999.0;
	  visited[i][j][k] = false;
	}
      }
    }
    time[s][s][0] = 0.0;

    
    double ans = -1.0;
    priority_queue<State> que;
    State st(s, s, 0, 0.0), q;
    que.push(st);

    while (!que.empty()) {
      st = que.top();
      que.pop();

      if (st.nc == g && st.nv == 1) {
	ans = st.nt;
	break;
      }

      visited[st.nc][st.pc][st.nv] = true;
      for (int i = 0; i < n; ++i) {
	if (i == st.nc || i == st.pc || cost[st.nc][i].d == -1)
	  continue;
	for (int j = st.nv-1; j < st.nv+2; ++j) {
	  if (j > 0 && cost[st.nc][i].c >= j) {
	    double tmp = st.nt + cost[st.nc][i].d / (double)j;
	    if (time[i][st.nc][j] > tmp) {
	      time[i][st.nc][j] = tmp;
	      q.set(i, st.nc, j, tmp);
	      que.push(q);
	    }
	  }
	}
      }

    }

    if (ans == -1.0)
      printf("unreachable\n");
    else
      printf("%.5f\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1568
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(s.hasNext()){
			String now=s.next();
			for(int i=0;i<now.length();i++){
				if(now.charAt(i)=='@'){
					for(int j=0;j<(int)(now.charAt(i+1)-'0');j++){
						System.out.print(""+now.charAt(i+2));
					}
					i+=2;
				}else System.out.print(""+now.charAt(i));
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
n = gets.to_i
points = n.times.map{ gets.strip.split(' ').map(&:to_i) }

dist = points[0][1] + points[0][2]
_t = 0
_x = 0
_y = 0

points.each do |p|
        t, x, y = p
        dt = t - _t
        dist = (x - _x).abs + (y - _y).abs
        if dt >= dist && dt.odd? == dist.odd?
                _t = t
                _x = x
                _y = y
        else
                puts 'No'
                exit
        end
end

puts 'Yes'

Measured memory_bytes: 9468
#include <iostream>

using namespace std;

int main()
{
    char c[2][3] = {};

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    cout << (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0] ? "YES" : "NO") << endl; 
    return 0;
}

Measured memory_bytes: 888
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = sorted(LI())
    i = n // 2 - 1

    return a[i+1] - a[i]


print(main())



Measured memory_bytes: 16092
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int dp[100][10];

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

	int N, K, C; cin >> N >> K >> C;
	string S; cin >> S;
	vector<pair<int, int>> v1, v2;
	{
		int k = 0;
		int t = 0;
		while (k < N) {
			if (S[k] == 'o') { v1.push_back({ k, t }); k += C; t++; }
			k++;
		}
		k = N - 1;
		t = 0;
		while (k >= 0) {
			if (S[k] == 'o') { v2.push_back({ k, K - 1 - t }); k -= C; t++; }
			k--;
		}
		if (v1.back().second != K - 1 || v2.back().second != 0) { return 0; }
		int n = v1.size();
		for (int i = 0; i < n; i++) {
			if (v1[i] == v2[n - 1 - i]) {
				cout << v1[i].first + 1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define l long long
using namespace std;l q,x,y,f[99]={0,1},m=1e9+7;main(){cin>>q;rep(i,97)f[i+2]=f[i]+f[i+1];rep(i,q){cin>>x>>y;if(x>y)swap(x,y);if(y<=2){cout<<1<<" "<<(y==1?1:x==1?2:4)<<" ";continue;}rep(j,99){if(x<f[j]||y<f[j+1]){l a=x==1?2:1;rep(k,j-2){l n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];if(n<=x&&m<=y)a+=(y-m)/n+1;}if(f[j]<=x){a++;rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);}cout<<j-2<<" "<<a%m<<" ";break;}}}}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int ans = 0;
  for(int i = l; i<=r; i++){
    if(i % d == 0){
      ans++;
    }
  }cout << ans << endl;
}
  

Measured memory_bytes: 3524
H = int(input())

flag = 0
dp = []
dp.append([H,1])

for i in range(1,H):
    tmp0 = dp[i-1][0]//2
    tmp1 = dp[i-1][1]*2
    dp.append([tmp0,tmp1])
    if dp[i][0]==1:
        break

l = len(dp)
p = [dp[i][1] for i in range(l)]
ans = sum(p)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int ans;
int N;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    while(N--) {
        string s;
        cin >> s;
        if(s == "E869120") ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3228