akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)



//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g;}E;
typedef struct graph{
	ll vcnt,ecnt;
	E  e[200010];//適宜変える
	ll id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	rep(i,0,n-1){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
	}
	g.vcnt=n;
	g.ecnt=2*n-2;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//一応番兵
}

ll ue[100010],sita[100010];
int flag[100010];
int q[100010],qcnt;
int vq[100010];
void toposo(ll r){
	//トポソ
	flag[r]=2-ue[r]%2;
	q[qcnt]=r;
	vq[r]=qcnt;
	qcnt++;
	rep(i,0,g.vcnt){
		ll v=q[i];
		rep(j,g.id[v],g.id[v+1])if(!flag[g.e[j].g]){
			ll vv=g.e[j].g;
			flag[vv]=3-flag[v];
			q[qcnt]=vv;
			vq[vv]=qcnt;
			qcnt++;
			if(ue[vv]==sita[vv]&&ue[vv]%2!=flag[vv]%2){
				//ついでにパリティのチェック
				puts("No");
				exit(0);
			}
		}
	}
}

int main(){
	readgraph();
	rep(i,0,g.vcnt){
		sita[i]=-INF;
		ue[i]=INF;
	}
	
	ll k;
	scanf("%lld",&k);
	ll r;
	rep(i,0,k){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		a--;
		sita[a]=ue[a]=b;
		r=a;
	}
	toposo(r);

	//葉からチェック
	for(ll i=g.vcnt-1;i>=0;i--){
		ll v=q[i];
		rep(j,g.id[v],g.id[v+1]){
			ll vv=g.e[j].g;
			if(vq[v]>vq[vv]){
				ue[vv]=min(ue[vv],ue[v]+1);
				sita[vv]=max(sita[vv],sita[v]-1);
			}
		}
	}

	//根からチェック
	rep(i,0,g.vcnt){
		ll v=q[i];
		rep(j,g.id[v],g.id[v+1]){
			ll vv=g.e[j].g;
			if(vq[v]<vq[vv]){
				ue[vv]=min(ue[vv],ue[v]+1);
				sita[vv]=max(sita[vv],sita[v]-1);
			}
		}
	}
	
	//候補が空でないかチェック
	rep(i,0,g.vcnt)if(ue[i]<sita[i]){
		puts("No");
		return 0;
	}
	
	puts("Yes");
	rep(i,0,g.vcnt)printf("%lld\n",sita[i]);
}

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

int main() { 	
  int  N;
  	cin >> N;
    vector<int> P(N);
  int p,m;
  cin >>P.at(0);
  cin >>P.at(1); 
  p=0;
  
for(int i=2;i<N;i++){
    cin >>P.at(i); 
  if(P.at(i-2)<=P.at(i-1)&&P.at(i)>=P.at(i-1)){
	p++;
  }else if(P.at(i-2)>=P.at(i-1) && P.at(i)<=P.at(i-1)){
    p++;
  }
   
}
  
cout << p<<endl;
  
  
}

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

main(){
  int n,m,ans=0;
  vector<int>v;
  cin>>n>>m;
  int a[n];
  r(i,n)cin>>a[i];
  r(i,n-1)v.push_back(a[i+1]-a[i]-1);
  sort(v.begin(),v.end(),greater<int>());
  r(i,min((int)v.size(),m-1))ans+=v[i];
  cout<<a[n-1]-a[0]-ans+1<<endl;
}


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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   ll n;
   cin >> n;
   string ans = "";
   while(n){
      n--;
      ans += char('a' + n % 26);
      n /= 26;
   }
   reverse(ans.begin() , ans.end());
   cout << ans;
   return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
	ll n; cin>>n;
	ll a[n],d=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i+1!=a[i]) d++;
	}
	if(d<3) cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b and b==c){
    if(a%2==0) cout<<-1<<endl;
    else cout<<0<<endl;
    return 0;
  }
  int ans=0;
  while(a%2==0 and b%2==0 and c%2==0){
    ans++;
    int temp_a=a;
    int temp_b=b;
    int temp_c=c;
    a=(temp_b+temp_c)/2;
    b=(temp_c+temp_a)/2;
    c=(temp_a+temp_b)/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int check(vector<string> a, vector<string> b, int x, int y){
    int flag = 0, m = b.size(); int cnt = 0;
    for (int i=0; i<m; i++){
        for (int j=0; j<m; j++){
            if (a[x+i][y+j]!=b[i][j]){
                flag = 1;
                break;
            }
        }
        if (flag == 1)break;
    }
    if (flag == 1)return 0;
    return 1;
}
int main()
{
    int n, m;
    cin>>n>>m;
    vector<string> a(n), b(m);
    for (int i=0; i<n; i++)cin>>a[i];
    for (int i=0; i<m; i++)cin>>b[i];
    int flag = 0;
    for (int i=0; i<=n-m; i++){
        for (int j=0; j<=n-m; j++){
            int x = check(a, b, i, j);
            if (x == 1){
                flag = 1;
                break;
            }
        }
        if (flag == 1)break;
    }
    if (flag == 0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

/**
 * Search
 */
public class Main {

    int n;
    int[] a;
    int q;
    int[] m;

    public void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        q = sc.nextInt();
        m = new int[q];
        for (int i = 0; i < q; i++) {
            m[i] = sc.nextInt();
            System.out.println((this.search(0, 0, m[i]) ? "yes" : "no"));
        }

    }

    boolean search(int num, int cnt, int _m) {
        if (num > _m) {
            return false;
        } else if (num == _m) {
            // System.out.println("yes");
            return true;
        } else if (cnt == n) {
            // System.out.println("no");
            return false;
        }
        return (search(num, cnt + 1, _m) || search(num + a[cnt], cnt + 1, _m));
    }

    public static void main(String[] args) {
        (new Main()).run();
    }
}


Measured memory_bytes: 26964
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int M=50;
const int N=1010;
int x[N],y[N];
int abs(int x)
{
	return x>0?x:-x;
}
int t;
int d[M];
char ans[N][M];
int n;
void gao(int k)
{
	t++;
	d[t]=k;
	for(int i=1;i<=n;i++)
		if(abs(x[i])>abs(y[i]))
		{
			if(x[i]>0)
			{
				x[i]-=k;
				ans[i][t]='R';
			}
			else
			{
				x[i]+=k;
				ans[i][t]='L';
			}
		}
		else
		{
			if(y[i]>0)
			{
				y[i]-=k;
				ans[i][t]='U';
			}
			else
			{
				y[i]+=k;
				ans[i][t]='D';
			}
		}
}
int main()
{
	open2("d");
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=30;i>=0;i--)
		gao(1<<i);
	if(x[1]||y[1])
		gao(1);
	for(int i=1;i<=n;i++)
		if(x[i]||y[i])
		{
			printf("-1\n");
			return 0;
		}
	printf("%d\n",t);
	for(int i=1;i<=t;i++)
		printf("%d ",d[i]);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%s\n",ans[i]+1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
int ke (int n){
    n--;
    if(n == 1 )return 0;
    int ans = 1;
    while (0 < n){
        ans *= n;
        n--;
    }
    return ans ;

}
int main(){
    int a,b,c;

    cin >> a >> b >> c;

    cout << c <<" " << a << " " << b <<endl;
}





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

int main() {
 int s,b,c;
 cin>>s>>b;

  if(s>=b){
	  c=s;
  s=s-1;}


else if(b>=s){
	  c=b;
  b=b-1;}



  if(s>=b){
	  cout<<c+s;}

  if(b>s){
	cout<<c+b;}


	return 0;
}


Measured memory_bytes: 3596
#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() {
    int h,k;
    cin >> h >> k;
    vector<ll> s(h);
    rep(i,h) {
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());
    ll ans=0;
    for(int i=k; i<h; i++) ans+=s[i];
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int n;
P dat[(1 << 21) - 1];

void init()
{
    for(int i = 0; i < (1 << 20); ++i) dat[(1 << 20) + i - 1].second = i;
}

void update(int i, int x)
{
    i += (1<< 20) - 1;
    dat[i].first += x;
    while(i > 0){
        i = (i - 1) / 2;
        P p;
        if(dat[i*2+1].first == dat[i*2+2].first){
            p = dat[i*2+1];
        } else {
            p = max(dat[i*2+1], dat[i*2+2]);
        }
        dat[i] = p;
    }
}

int main()
{
    init();
    int a,v,q;
    cin >> n >> q;
    for(int i = 0; i < q; ++i){
        cin  >> a >> v;
        update(a-1, v);
        cout << dat[0].second + 1 << ' ' << dat[0].first << endl;
    }
}

Measured memory_bytes: 17548
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;

int _;

//========================================================================

//========================================================================
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",1000-((n%1000)==0?1000:n%1000));
    return 0;
}


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

int main() {
  int r , g , b ;
  cin >> r >> g >> b ;
  
  if ((10*g + b)%4 == 0 ){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

ll gcd(ll a, ll b) {
    if(a < b)
        return gcd(b, a);
    if(b == 0) {
        return a;
    }
    if(a == b)
        return a;
    return gcd(b, a%b);
}
int main(){
    long long a,b; cin >> a >> b;
    ll x = gcd(a,b);
    ll y = x;
    ll ans = 1;
    vector<ll> v;

    for(ll i = 2; i*i<=x+1;i++){
        bool flag = false;
        while(y%i ==0) {
            y /= i;
            flag = true;
        }
        if(flag){
            ans++;
            v.push_back(i);
        }
    }
    if(y != 1) {
        cout << ans+1 << endl;
    } else {
        cout << ans << endl;
    }
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int ans = 0;
    if (N == 1) {
        cout << M << endl;
        return 0;
    }
    for (int i = 1; i <= M / N; ++i) {
        if (M % i == 0) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
}

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

int main() {
  long long n,a,b,c,d,e;
  cin >>n>>a>>b>>c>>d>>e;
  long long k=min({a,b,c,d,e});
  cout<<(n/k)+(n%k!=0)+4<<endl;
  }

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
struct Card{
  char word;
  char num;
};

int judge(struct Card *,struct Card *,int );

int main(){
  struct Card C1[N], C2[N];
  struct Card tmp;
  int i, j;
  int min_j;
  int n;

  scanf("%d", &n);
  for (i=0; i<n; i++ ) {
    scanf(" %c %c", &C1[i].word,&C1[i].num);
  }  

  for(i=0;i<n;i++){
    C2[i]=C1[i];
  }
  
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(C1[j].num < C1[j-1].num){
	tmp=C1[j];
	C1[j]=C1[j-1];
	C1[j-1]=tmp;
      }
    }
  }

   for(i=0; i<=n-1; i++){
    min_j=i;
    for(j=i; j<=n-1; j++){
      if(C2[j].num < C2[min_j].num){
	min_j=j;
      }
    }
      tmp=C2[i];
      C2[i]=C2[min_j];
      C2[min_j]=tmp;
   }
   
   for ( i = 0; i < n; i++ ){
     if ( i >= 1 ) printf(" ");
     printf("%c%c", C1[i].word,C1[i].num);
   }
   printf("\n"); 
   printf("Stable\n");
   
   for ( i = 0; i < n; i++ ){
     if ( i >= 1 ) printf(" ");
     printf("%c%c", C2[i].word,C2[i].num);
   }
   printf("\n");

   if ( judge(C1, C2, n) == 1 ){
     printf("Stable\n");
   }
   else {
     printf("Not stable\n");
   }
   return 0;   

}
int judge(struct Card C1[] ,struct Card C2[],int n){

  int i;
  
  for(i=0;i<n;i++){
    if(C1[i].word != C2[i].word){
      return 0;
    }
  }
    return 1;
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  
  vector<int> v;
  char cur = s.front();
  int cnt = 0;
  if (s[0] == '0') v.push_back(0);
  for (auto& x : s) {
    if (x == cur) ++cnt;
    else {
      v.push_back(cnt);
      cur = '0' + '1' - cur;
      cnt = 1;
    }
  }
  v.push_back(cnt);
  if (cur == '0') v.push_back(0);
  
  if (!k) {
    cout << *max_element(v.begin(), v.end()) << endl;
    return 0;
  }
  
  if (v.size() / 2 <= k) {
    cout << n << endl;
    return 0;
  }
  
  vector<int> a;
  a.push_back(0);
  for (auto& x : v) a.push_back(x + a.back());
  
  //for (auto& x : v) cout << x << endl;
  
  int ans = 0;
  for (int i = 1; i + k * 2 < a.size(); i += 2) {
    ans = max(ans, a[i + k * 2] - a[i - 1]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1528
# ABC121D - XOR World
def xor_sum(x):
    """
    Return 0 ^ 1 ^ ... ^ x - 1 ^ x
    """
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0


def main():
    a, b = list(map(int, input().rstrip().split()))
    print(xor_sum(a - 1) ^ xor_sum(b))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int remaining = N % 500;
		System.out.println(A >= remaining ? "Yes" : "No");
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int N = 2e5 + 10;
int n, a[N], v[N];

int c[N];
inline int lowbit(int x) { return x & -x; }
void Add(int x, int val) {
  for (; x <= n; x += lowbit(x))
    c[x] += val;
}
int Query(int x) {
  int res = 0;
  for (; x; x -= lowbit(x))
    res += c[x];
  return res;
}

int main(void) {
  read(n);
  for (int i = 1; i <= n; ++i)
    read(a[i]), v[i] = a[i];
  sort(v + 1, v + 1 + n);
  int m = unique(v + 1, v + 1 + n) - v - 1;
  for (int i = 1; i <= n; ++i)
    a[i] = lower_bound(v + 1, v + 1 + m, a[i]) - v;
  
  for (int i = 1; i <= n; ++i) Add(a[i], 1);
  for (int i = 1; i <= n; ++i) {
    if (i > 1) Add(a[i - 1], 1);
    Add(a[i], -1);
    int l = 1, r = m, res = 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (Query(mid) >= n / 2) res = mid, r = mid - 1;
      else l = mid + 1;
    }
    printf("%d\n", v[res]);
  }

  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 1e9+7;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

const int N=2e5+10;

int n,k;
ll a[N];
ll mp[N];

inline bool cmp(ll x,ll y){
	return abs(x)<abs(y);
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	cin>>n>>k;
  	for(int i=1;i<=n;++i)
	{
  		cin>>a[i];
  		if(a[i]>=0) 
		  mp[1]++;
  		else 
		  mp[2]++; 
  	}
  	
  	int l=1,r=n;
  	
  	ll ans=1;
  	
  	if(mp[1]==0 && k%2==1)
	  {
  		sort(a+1,a+1+n,cmp);
  		for(int i=1;i<=k;++i)
		{
  			ans=a[i]*ans%mod;
  		}
  	}
  	else
	{
  		sort(a+1,a+1+n,greater<int>());
  		while(k>0)
		  {
  			if(k%2==1) 
			  ans=ans*a[l++]%mod,k--;
  			else if(k>=2)
			  {
  				if(a[l]*a[l+1]>=a[r]*a[r-1])
				  {
  					ans=ans*a[l]%mod*a[l+1]%mod;
  					l+=2;
  					k-=2;
  				}
  				else
				  {
  					ans=ans*a[r-1]%mod*a[r]%mod;
  					r-=2;
  					k-=2;
  				}
  			} 
  		}
  	}

  	cout<<(ans%mod+mod)%mod<<endl;
	
	return 0;
}


Measured memory_bytes: 5184
#include <stdio.h>
#include <ctype.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int res = 0;

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

    if ( isdigit ( ch ) )
    {
      res += ch - '0';
    }
    else
    {
      if ( res == 0 ) break ;

      printf ( "%d\n", res );
      res = 0;
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var z = Read();
		int h = z[0], w = z[1];
		var a = new int[h].Select(_ => Console.ReadLine()).ToArray();

		int sv = h + w, ev = sv + 1;
		var s = (i: 0, j: 0);
		var t = (i: 0, j: 0);

		var dag = new List<long[]>();
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (a[i][j] == 'o')
				{
					dag.Add(new[] { i, h + j, 1L });
					dag.Add(new[] { h + j, i, 1L });
				}
				else if (a[i][j] == 'S')
				{
					s = (i, j);
					dag.Add(new[] { sv, i, 1L << 60 });
					dag.Add(new[] { sv, h + j, 1L << 60 });
				}
				else if (a[i][j] == 'T')
				{
					t = (i, j);
					dag.Add(new[] { i, ev, 1L << 60 });
					dag.Add(new[] { h + j, ev, 1L << 60 });
				}

		Console.WriteLine(s.i == t.i || s.j == t.j ? -1 : MaxFlow(ev, sv, ev, dag.ToArray()));
	}

	static long MaxFlow(int n, int sv, int ev, long[][] dag)
	{
		var map = Array.ConvertAll(new int[n + 1], _ => new List<long[]>());
		foreach (var e in dag)
		{
			map[e[0]].Add(new[] { e[0], e[1], e[2], map[e[1]].Count });
			map[e[1]].Add(new[] { e[1], e[0], 0, map[e[0]].Count - 1 });
		}

		long Bfs()
		{
			var from = new long[n + 1][];
			var minFlow = new long[n + 1];
			Array.Fill(minFlow, long.MaxValue);
			var q = new Queue<long>();
			q.Enqueue(sv);

			while (q.TryDequeue(out var v))
			{
				if (v == ev) break;
				foreach (var e in map[v])
				{
					if (from[e[1]] != null || e[2] == 0) continue;
					from[e[1]] = e;
					minFlow[e[1]] = Math.Min(minFlow[v], e[2]);
					q.Enqueue(e[1]);
				}
			}

			if (from[ev] == null) return 0;
			for (long v = ev; v != sv; v = from[v][0])
			{
				var e = from[v];
				e[2] -= minFlow[ev];
				map[e[1]][(int)e[3]][2] += minFlow[ev];
			}
			return minFlow[ev];
		}

		long M = 0, t;
		while ((t = Bfs()) > 0) M += t;
		return M;
	}
}


Measured memory_bytes: 27200
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))

d.sort()
t.sort()

cnt=0
 
for i in range(n):
    if d[i]==t[cnt]:
        cnt+=1
    elif d[i]<t[cnt]:
        pass
    else:
        print('NO')
        exit()
    
    if cnt==m:
        print('YES')
        exit()

Measured memory_bytes: 35324
/*
氏名 : 杉谷　裕貴,学籍番号 : 190441066
概要 : n人の学生の得点から標準偏差を求めるプログラム
*/
#include<math.h>/*標準関数の宣言*/
#include<stdio.h>

int main(void)
{
	int n, i;/*変数の宣言と初期化*/
	double sum, st_deviation;/*実数の宣言*/
	int s[1000];/*配列の宣言*/

	while (1)
	{
		scanf("%d", &n);/*学生の人数の入力*/

		if (n == 0) break;

		else
		{
			sum = 0, st_deviation = 0;
			for (i = 0; i < n; i++)/*n回繰り返す*/
			{
				scanf("%d", &s[i]);/*個々の点数の入力*/
				sum += s[i];/*得点の合計の計算*/
			}

			sum = sum / n;/*平均点の計算*/
			for (i = 0; i < n; i++)/*n回繰り返す*/
			{
				st_deviation += pow(s[i] - sum,2.0);/*分散を出す前までの計算*/
			}

			st_deviation = st_deviation / n;/*分散の計算*/

			printf("%.8f\n", sqrt(st_deviation));/*標準偏差の表示*/
		}
	}

	return 0;
}


Measured memory_bytes: 2140
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

map<ll,ll>mm;
ll mx1=-1,mx2=-1;
ll a[200005];
int main(){
	ll n;
	sfl(n);
	for(ll i=1;i<=n;i++){
		sfl(a[i]);
		mm[a[i]]++;
		if(a[i]>mx1){
			mx2=mx1;
			mx1=a[i];
		}
		else{
			mx2=max(mx2,a[i]);
		}

	}
	for(ll i=1;i<=n;i++){
		if(a[i]==mx1){
			if(mm[a[i]]>1){
				cout << mx1 << endl;
			}
			else{
				cout << mx2 << endl;
			}
		}
		else{
			cout << mx1 << endl;
		}
	}
}



Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void app() {
  int d;
  cin>>d;

  int n=26;
  vector<int> c(n);
  rep(j,n){
    cin>>c[j];
  }
  vector<vector<int>> s(d,vector<int>(n));
  rep(i,d) rep(j,n) cin>>s[i][j];

  vector<int> lastd(n,-1);
  rep(i,d){
    int bj=0,bdscore=-1e9;
    rep(j,n){
      int dscore=s[i][j]-c[j]*(i-lastd[j]);
      if(chmax(bdscore,dscore)){
        bj=j;
      }
    }
    cout<<bj+1<<endl;
    lastd[bj]=i;
  }

}

int main(){app();return 0;}


Measured memory_bytes: 3684
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/

map<int,int> mp;
int a[MAX_N];
main(){
    fast();per(0);
    //get_fact();
    int n;cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],mp[a[i]]++;
    int ans=0;
    for(pii i:mp){
        int num=i.F,cnt=i.S;
        if(num>cnt)
            ans+=cnt;
        else if(num<cnt)
            ans+=cnt-num;

    }
    cout<<ans;
}


Measured memory_bytes: 5120
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(int, N);

  vector<int> a(N);
  rep(i, N) {
    IN(a[i]);
  }

  bool up = false;
  bool down = false;
  i64 res = 1;
  for (int i = 1; i < N; ++i) {

    if (!up && !down) {
      if (a[i] == a[i-1]) continue;
      else if (a[i] > a[i-1]) up = true;
      else down = true;
    }

    else if (up && a[i] < a[i-1]) {
      ++res;
      up = false;
    }

    else if (down && a[i] > a[i-1]) {
      ++res;
      down = false;
    }
  }

  OUTL(res);

  return 0;
}


Measured memory_bytes: 640
def main():
    A11, A12, A13 = map(int, input().split())
    A21, A22, A23 = map(int, input().split())
    A31, A32, A33 = map(int, input().split())
    N = int(input())
    #N, *b_list = map(int, open(0).read().split())
    b_list = []
    for i in range(1,N+1) :
        bi = int(input())
        b_list.append(bi)
    if A11 in b_list and A12 in b_list and A13 in b_list :
        print ("Yes")
    elif A21 in b_list and A22 in b_list and A23 in b_list :
        print("Yes")
    elif A31 in b_list and A32 in b_list and A33 in b_list :
        print("Yes")
    elif A11 in b_list and A21 in b_list and A31 in b_list :
        print("Yes")
    elif A12 in b_list and A22 in b_list and A32 in b_list :
        print("Yes")
    elif A13 in b_list and A23 in b_list and A33 in b_list :
        print("Yes")
    elif A11 in b_list and A22 in b_list and A33 in b_list :
        print("Yes")
    elif A13 in b_list and A22 in b_list and A31 in b_list :
        print("Yes")
    else :
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>

main(){
	int a[4][14],n,i,j;
	
	scanf("%d",&n);
	
	for(i=0;i<4;i++){
		for(j=0;j<14;j++){
			a[i][j]=0;
		}
	}
	
	scanf("%*c");
	for(i=0;i<n;i++){
		char b;
		int c;
		
		scanf("%c %d\n",&b,&c);
		
		if(b=='S'){
			a[0][c]=1;
		}
		else if(b=='H'){
			a[1][c]=1;
		}
		else if(b=='C'){
			a[2][c]=1;
		}
		else if(b=='D'){
			a[3][c]=1;
		}
	}
	
	char pattern[4] = {'S','H','C','D'};
	
	for(i=0;i<4;i++){
		for(j=1;j<14;j++){
			if(a[i][j]==0){
				printf("%c %d\n",pattern[i],j);
			}
		}
	}
	
	return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int mx = max(max(A, B), C);

  if (mx == A) {
    for (int i = 0; i < K; i++) A *= 2;
  } else if (mx == B) {
    for (int i = 0; i < K; i++) B *= 2;
  } else {
    for (int i = 0; i < K; i++) C *= 2;
  }

  cout << A + B + C << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

//----------------------------------------------------------------------
void solve() {

	ll n;
	cin >> n;
	vector<string> vec(n);
	rep(i,n) cin >> vec[i];

	map<string,ll> MAP;
	rep(i,n) MAP[vec[i]]++;

	ll _max = 0;
	for (auto itr = MAP.begin(); itr != MAP.end(); itr++) {
		_max = max((*itr).second, _max);
	}

	debug("-");

	for (auto itr = MAP.begin(); itr != MAP.end(); itr++) {
		auto p = *itr;
		if (p.second == _max) cout << p.first << endl;
	}


}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 25172
def graph()
  n = gets.to_i
  a = []
  b = []
  for k in 0..n-1
    b[k] = []
    for l in 0..n-1
      b[k][l] = 0
    end
  end
  for i in 0..n-1
    a[i] = gets.split(' ').map(&:to_i)
    if a[i][1] > 0
      for j in 2..a[i][1]+1
        c = a[i][j] - 1
        b[i][c] = 1
      end
    end
    puts b[i].join(' ')
  end
end

graph()

Measured memory_bytes: 6984
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] H = new int[N];
		for(int i=0; i<N; i++) {
			H[i] = sc.nextInt();
		}
		
		Arrays.sort(H);

		long ans = 0;
		for(int i=0; i<Math.max(0, N-K); i++)
			ans += H[i];

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 90260
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]
    black_cnt = 0
    for y in range(H):
        for x in range(W):
            if grid[y][x] == '#': black_cnt += 1

    q = deque([(0,0,0)])
    visited = [[False]*W for _ in range(H)]
    visited[0][0] = True
    while q:
        y,x,step = q.popleft()
        if y == H-1 and x == W-1:
            print(H*W-(step+1)-black_cnt)
            return 0
        for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
            ny = y+dy
            nx = x+dx
            if 0<=ny<H and 0<=nx<W and not visited[ny][nx] and grid[ny][nx] == '.':
                q.append((ny,nx,step+1))
                visited[ny][nx] = True

    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12200
import math
x = input()
xs = x.split(" ")
A = int(xs[0])
B = int(xs[1])
H = int(xs[2])
M = int(xs[3])

Hangle = M/2 + H*30
Mangle = M*6



if (Hangle > Mangle):
    angleBetween = Hangle - Mangle
else:
    angleBetween = Mangle - Hangle



if (360 - angleBetween) < angleBetween:
    angleBetween = 360 - angleBetween

angleBetween = angleBetween * math.pi
angleBetween = angleBetween/180

output = (A*A) + (B*B) - (2*A*B*math.cos(angleBetween))
output = math.sqrt(output)
print(output)


Measured memory_bytes: 62332
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a, b, m := nextInt(), nextInt(), nextInt()

	ap := nextInts(a)
	bp := nextInts(b)

	result := 10000000000
	for i := 0; i < m; i++ {
		x, y, c := nextInt(), nextInt(), nextInt()
		s := ap[x-1] + bp[y-1] - c
		if result > s {
			result = s
		}
	}
	sort.Sort(sort.IntSlice(ap))
	sort.Sort(sort.IntSlice(bp))
	if result > ap[0]+bp[0] {
		result = ap[0] + bp[0]
	}
	fmt.Println(result)
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


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

int main(){
    int x;
    cin >> x;
    if(x >= 30 ){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t N, R=1000000007;
  cin >> N;
  vector<int64_t> A(N);
  long long S=0, ans=0;
  for (int64_t i=0; i<N; i++) {
    cin >> A[i];
    S=S+A[i];
    S=S%R;
  }
  for (int64_t i=0; i<N; i++) {
    S=S-A[i];
    if (S<0) {
      S=S+R;
    }
    ans=ans+A[i]*S;
    ans=ans%R;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
char c[1001][1001];
long long n,m,ans;
int main()
{
	cin>>n>>m;
	ans=m/n;
	n=0;
	while(ans)
	{
		ans/=2;
		n++;
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
char s[1000][1000];
int a[10000];
int vis[10000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%s%d",&s[i],&a[i]);
    }

    int l=1;
    int r=2;
    memset(vis,0,sizeof(vis));
    for(int j=1; j<=n; j++)
    {
        for(int i=1; i<=n-1; i++)
        {
            if(strcmp(s[l],s[r])==0&&!vis[l]&&!vis[r])
            {
                if(a[l]>a[r])
                    r++;
                else
                {
                    l=r;
                    r++;
                }
            }
            else if(strcmp(s[l],s[r])<0&&!vis[l]&&!vis[r])
            {
                r++;

            }
            else if(strcmp(s[l],s[r])>0&&!vis[l]&&!vis[r])
            {
                l=r;
                r++;

            }
            if(vis[l]==1&&!vis[r])
            {
                l=r;
                r++;
            }
            else if(vis[l]==1&&vis[r]==1)
            {
                for(int i=3; i<=n; i++)
                {
                    if(vis[i]==0)
                    {
                        l=i;
                        r=2;
                    }
                }
            }
            else if(vis[l]==0&&vis[r]==1)
                r++;
            if(l==r)
                r++;
            if(r==n+1)
                break;
        }
        vis[l]=1;
        printf("%d\n",l);
        l=1;
        r=2;

    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n, a , b;
    cin >> n >> a >> b;
    if (a > b ){
        cout << 0 << endl;
        return 0;
    }
    if (n > 2) {
        cout << (n - 2) * (b - a) + 1 << endl;
    }else{
        if ( a != b) {
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI N,M;

LLI dp[101000];
LLI dp2[101000];

LLI rec(vector<vector<int>> &tree, int cur){
  dp[cur] = 1;

  for(auto next : tree[cur]){
    (dp[cur] *= (rec(tree,next)+1)%M) %= M;
  }

  return dp[cur];
}

LLI rec2(vector<vector<int>> &tree, int cur, LLI val){
  int c = tree[cur].size();
  
  vector<LLI> left(c+1,1);
  REP(i,c) (left[i+1] = left[i] * (dp[tree[cur][i]]+1)%M) %= M;
  
  LLI right = 1;

  REV(i,tree[cur].size()-1,0){
    int next = tree[cur][i];
    dp2[next] = (val*left[i]%M*right%M+1)%M;

    (right *= (dp[tree[cur][i]]+1)%M) %= M;
    rec2(tree, next, dp2[next]);
  }
  
  return dp2[cur];
}

void remove_parent_edge(vector<vector<int>> &tree, int cur, int par){
  auto it = find(ALL(tree[cur]),par);
  if(it != tree[cur].end()) tree[cur].erase(it);
  for(auto next : tree[cur]){
    remove_parent_edge(tree,next,cur);
  }
}


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

  cin >> N >> M;
  vector<vector<int>> tree(N);
  REP(i,N-1){
    int x,y; cin >> x >> y;
    --x, --y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }

  remove_parent_edge(tree,0,-1);

  rec(tree, 0);
  rec2(tree, 0, dp2[0]=1);

  REP(i,N){
    LLI ans = (dp2[i]*dp[i])%M;
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 17280
// atcoder/abc132/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> v(n);
    cin >> v;

    map<int, int> cnt;
    each (i, v) ++cnt[i];

    int x = -1;
    int y = -1;
    int sum = 0;
    each (i, cnt) {
      sum += i.second;
      if (x != -1) {
        y = i.first;
        break;
      }
      if (sum * 2 == n) {
        x = i.first;
      }
    }
    // cout << endl;
    // cout << x << ' ' << y << endl;
    cout << y - x << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
import sys
input = sys.stdin.readline
from collections import Counter


def read():
    S = input().strip()
    return S,


def solve(S):
    C = Counter(S) + Counter("abc")
    V = list(sorted(C.values()))
    if V[-1] - V[0] <= 1:
        return "YES"
    else:
        return "NO"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 9352
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}
int main(){
  ll n;cin>>n;
  vl vec=divisor(n);
  vl vec2=divisor(n-1);
  ll count=0;
  rep(i,vec.size()){
    if(vec[i]==1)continue;
    ll x=n;
    while(x>1){
      if(x%vec[i]==0)x/=vec[i];
      else x%=vec[i];
      if(x<vec[i])break;
    }
    if(x==1)count++;
  }
  rep(i,vec2.size()){
    if(vec2[i]==1)continue;
    ll x=n;
    while(x>1){
      if(x%vec2[i]==0)x/=vec2[i];
      else x%=vec2[i];
      if(x<vec2[i])break;
    }
    if(x==1)count++;
  }
  cout<<count<<endl;
}
      
  
  
    
    


Measured memory_bytes: 384