akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

class Solver {
public:
	static void solve() {
		int n;
		cin >> n;

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

		bool*** dp = new bool** [55];
		for (int i = 0; i < 55; i++) {
			dp[i] = new bool* [1000];
			for (int j = 0; j < 1000; j++) {
				dp[i][j] = new bool[1000];
				for (int k = 0; k < 1000; k++) {
					dp[i][j][k] = false;
				}
			}
		}

		dp[0][ts[0]][0] = true;
		dp[0][0][ts[0]] = true;
		dp[0][0][0] = true;
		for (int i = 0; i + 1 < n; i++) {
			for (int j = 0; j < 1000; j++) {
				for (int k = 0; k < 1000; k++) {
					if (!dp[i][j][k])continue;

					if (j + ts[i+1] < 1000)dp[i + 1][j + ts[i+1]][k] = true;
					if (k + ts[i+1] < 1000)dp[i + 1][j][k + ts[i+1]] = true;
					dp[i + 1][j][k] = true;
				}
			}
		}

		int res = 1e9;
		for (int i = 0; i < 1000; i++) {
			for (int j = 0; j < 1000; j++) {
				if (!dp[n - 1][i][j])continue;

				int tmp = max(max(i, j), sum - i - j);
				res = min(res, tmp);
				//cout << i << ' ' << j << ' ' << sum - i - j << endl;
			}
		}

		cout << res << endl;
	}
};

int main() {
	Solver::solve();
	return 0;
}


Measured memory_bytes: 57676
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int p, a=0, b = 99999999;
  for(int i=0;i<n;i++){
    scanf("%d",&p);
    if(p<b){
      b=p;
      a++;
    }
  }
  printf("%d",a);
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */

#include <iostream>
#include <fstream>

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

class AWeatherPrediction {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        if(s[0]=='S'){
            out << "Cloudy" << endl;
        }else if(s[0]=='C'){
            out << "Rainy" << endl;
        }else{
            out << "Sunny" << endl;
        }
	}
};


int main() {
	AWeatherPrediction solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int x[200000] = {},y[200000] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(x,x+n);
    for(int i = 0; i < n; ++i){
        if(y[i] <= x[n/2 - 1]){
            cout << x[n / 2] << endl;
        }else{
            cout << x[n/2-1] << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void){
  int N,A,ans[200000],i;
  scanf("%d",&N);
  ans[0]=0;
  for(i=1;i<N;i++){
    ans[i]=0;
    scanf("%d",&A);
    ans[A-1]+=1;
  }
  for(i=0;i<N;i++){
    printf("%d\n",ans[i]);
  }
}

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

int main() {
  int X,Y;
  cin>>X>>Y;
  bool can=true;
  if(Y%2==1) can=false;
  if(Y<2*X||Y>4*X) can=false;
  
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

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

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

int main(){

	map<string,lint> ans;

	int n;
	cin >> n;
	rep(i,n){
		char s[11];
		scanf("%s",s);
		vector<char> moji;
		rep(j,10){
			moji.push_back(s[j]);
		}
		sort(moji.begin(),moji.end());
		string ss="";
		for(int j =0;j<moji.size();j++){
			ss += moji[j];
		}
		ans[ss] += 1;
	}

	lint lans = 0;

	
	map<string,lint>::iterator itr = ans.begin();
	for(map<string,lint>::iterator k = itr; k != ans.end(); k++){
		if(k->second >1){
			lans += (lint)((k->second)*(k->second-1)/2);
		}
	}

	printf("%lld",lans);

	return 0;
}



Measured memory_bytes: 12800
//17
#include<iostream>
#include<algorithm>

using namespace std;

char g[12][6];
bool ps[12][6];
bool c[12][6];

void cr(int y,int x,char p){
  if(!c[y][x]&&g[y][x]==p){
    c[y][x]=true;
    for(int i=0;i<4;i++){
      int dx[]={1,0,-1,0};
      int dy[]={0,1,0,-1};
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(0<=nx&&nx<6&&0<=ny&&ny<12){
	cr(ny,nx,p);
      }
    }
  }
}

int cn(int y,int x,char p){
  if(p=='O'||p=='.'||p!=g[y][x]||ps[y][x]){
    return 0;
  }else{
    ps[y][x]=true;
    int c=0;
    for(int i=0;i<4;i++){
      int dx[]={1,0,-1,0};
      int dy[]={0,1,0,-1};
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(0<=nx&&nx<6&&0<=ny&&ny<12){
	c+=cn(ny,nx,p);
      }
    }
    return c+1;
  }
}

int main(){
  int t;
  cin>>t;
  while(t--){
    for(int y=0;y<12;y++){
      cin>>g[y];
    }
    for(int i=0;;i++){
      fill(ps[0],ps[12],false);
      fill(c[0],c[12],false);
      bool co=false;
      for(int y=0;y<12;y++){
	for(int x=0;x<6;x++){
	  if(cn(y,x,g[y][x])>=4){
	    cr(y,x,g[y][x]);
	    co=true;
	  }
	}
      }
      if(!co){
	cout<<i<<endl;
	break;
      }
      for(int y=0;y<12;y++){
	for(int x=0;x<6;x++){
	  if(c[y][x]){
	    g[y][x]='.';
	    for(int i=0;i<4;i++){
	      int dx[]={0,1,0,-1};
	      int dy[]={1,0,-1,0};
	      int nx=x+dx[i];
	      int ny=y+dy[i];
	      if(g[ny][nx]=='O'){
		g[ny][nx]='.';
	      }
	    }
	  }
	}
      }
      for(int j=0;j<11;j++){
	for(int y=0;y<11;y++){
	  for(int x=0;x<6;x++){
	    if(g[y][x]!='.'&&g[y+1][x]=='.'){
	      swap(g[y][x],g[y+1][x]);
	    }
	  }
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

vector<int> w,s,hist;
vector<string> name;
int n,tmpn,tmpm;
int used,ret[10];
string str;
double gmin = 1e+10;

inline double calc_g(){
	double p=0;
	double q=0;
	for(int i=0;i<n;i++){
		p += (i+1) * w[hist[n-1-i]];
		q += w[hist[i]];
		
	}
	return p/q;
}

void solve(int num, int weight){
	if(num == n){
		double g = calc_g();
		if(gmin > g){
			gmin = g;
			for(int i=0;i<n;i++){
				ret[i] = hist[i];
			}
		}
		return;
	}

	for(int i=0;i<n;i++){
		if((used & (1 << i)) == 0){
			if(s[i] >= weight){
				//ツ鳴「ツ使ツ用ツづつゥツづつ重ツづ敖づ可妥渉つヲツづァツづェツつスツづァツ静渉づアツづづ敖づゥ
				used |= 1 << i;
				hist.push_back(i);
				solve(num+1, weight+w[i]);
				hist.pop_back();
				used ^= 1 << i;
			}
		}
	}
}

int main(void){
	while(cin >> n && n){
		w.clear();
		s.clear();
		hist.clear();
		name.clear();
		memset(ret, 0, sizeof(ret));
		used = 0;
		gmin = 1e+10;
		for(int i=0;i<n;i++){
			cin >> str >> tmpn >> tmpm;
			name.push_back(str);
			w.push_back(tmpn);
			s.push_back(tmpm);
		}
		solve(0,0);
		for(int i=0;i<n;i++){
			cout << name[ret[n-i-1]] << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define sp " "
typedef long long ll;
#define len(x) x.length()
#define vsort(x) sort(x.begin(), x.end();
using namespace std;
ll inf=2e18;

int main()

{

    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("bruh.txt","r",stdin);
    int n;
    cin >>n;
    int arr[n];
    for(int i=0;i<n;i++)cin >>arr[i];
    sort(arr, arr+n);
    int mid=(arr[0]+arr[n-1])/2;
    int mx=1e9; int ans;
    for(int k=0;k<=100;k++){
            ans=0;
            mid=k;
    for(int i=0;i<n;i++){
        ans+=(arr[i]-mid)*(arr[i]-mid);
    }
    mx=min(ans,mx);
    }
    cout<<mx<<nl;
}


Measured memory_bytes: 256
# やるだけ（ソートしたものをもっていればいいのと、2つえらぶさんすう）
d = {}
for _ in range(int(input())):
    s = "".join(sorted(list(input())))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
ans = 0
for v in d.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 22264
/*Unknown_Ghost*/
/*AGC033C Removing Coins*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define LL long long
#define MAXN 200000
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,D,pos;
vector<int> G[MAXN+5];
void dfs(int x,int fa,int dis){
    if(dis>D){
        D=dis;pos=x;
    }
    for(int i=0;i<G[x].size();i++){
        int nxt=G[x][i];
        if(nxt==fa)continue;
        dfs(nxt,x,dis+1);
    }
}
int main()
{
    n=read();
    for(int i=1;i<n;i++){
        int u=read(),v=read();
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,0,1);
    D=0;
    dfs(pos,0,1);
    printf("%s",(D%3==2)?"Second":"First");
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> s(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#'){
        row[i] = true;
        col[j] = true;
      }
    }
  }
  rep(i,h){
    if(row[i]){
      rep(j,w){
        if(col[j]){
          cout << s[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
  vector<string> word;
  uint u;
  cin >> u;
  string s;
  cin >> s;
  word.push_back(s);
  for (auto i = 1; i < u; i++) {
    cin >> s;
    if (find(cbegin(word), cend(word), s) != cend(word)) {
      cout << "No" << endl;
      break;
    }
    word.push_back(s);
    if (word[i - 1].back() != word[i].front()) {
      cout << "No" << endl;
      break;
    }
    if (i == u - 1) {
      cout << "Yes" << endl;
    }
  }
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p.at(i);
  
  int cnta = 0, ans = 0, cntb = 0;
  for(auto k : p){
    if(k <= a) cnta++;
    else if(k <= b) ans++;
    else cntb++;
  }
  
  ans = min(ans, min(cnta, cntb));
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main()
{
	long long S, C;
	long long ans = 0;
	cin >> S >> C;
	
	if (S * 2 <= C)
	{
		if (C - S * 2 >= 4)
		{
			S += (C - S * 2) / 4;
		}

		ans += S;
	}
	else
	{
		ans += C / 2;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n,a,b = list(map(int,input().split()))
num_sum = 0
for ni in range(n+1):
    d1 = ni%10
    d2 = (ni//10)%10
    d3 = (ni//100)%10
    d4 = (ni//1000)%10
    d5 = (ni//10000)%10
    digit_sum = d1 + d2 + d3 + d4 + d5
    if digit_sum >= a and digit_sum <= b: num_sum += ni
print(num_sum)

Measured memory_bytes: 3060
mod = 10**9+7
 
n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]
 
dp = [-1 for __ in range(1 << n)]
dp[0] = 1
 
 
def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]
 
 
print(dfs(2**n-1, 0))

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

int main()
{
	int n;
	cin>>n;
	string s[n];
	int t[n];
	
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		cin>>t[i];
	}
	string x;
	cin>>x;
	
	int c=0;
	for(int i=0;i<n;i++)
	{
		if(x==s[i])
		{
			c=i;
			break;
		}
	}
	int sum =0;
	for(int i=c+1;i<n;i++)
	{
		sum+=t[i];
	}
	
cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r; cin >> r;
    cout << 3*r*r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
   ll n,a,b;
   cin>>a>>b>>n;
   ll m=min(b-1,n);
   cout<<(a*m)/b;


}


int main(){
   ll t=1;
   //cin>>t;
   while(t--){
    solve();
    cout<<endl;
   }
}


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

    int N,i,count = 0;
    cin >> N;
    int L[2*N];
    for(i = 0; i < 2 * N; i++){
        cin >> L[i];
    }

    sort(L,L+2*N);

    for(i = 0; i < 2 * N; i=i+2){
        if(L[i] <= L[i+1]){
            count += L[i];
        }else{
            count += L[i+1];
        }
    }

    cout << count << endl;
    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);
  
  for (int i = 0; i < m; i++) {
    int a,b;
    cin >> a >> b;
    vec.at(a-1) += 1;
    vec.at(b-1) += 1;
  }
  
  for (int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,d,i,j,k;
    vector<int>v;
    cin>>a;
    for(i=0;i<a;i++){
        cin>>b;
        c+=b;
        v.push_back(b);
    }
    sort(v.begin(),v.end());
    j=0;
    for(i=0;i<a;i++){

        if(c%10!=0){
            cout<<c<<endl;
            return 0;
        }
        else{
            c=c-v[i]+j;
        }
        j=v[i];
    }
    cout<<"0"<<endl;



    return 0;
}


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

int main() {
  int e, c, sum, num, n;
  sum = num = n = 0;
  while(scanf("%d,%d", &e, &c) != EOF) {
    ++n;
    sum += e*c;
    num += c;
  }
  printf("%d\n%d\n", sum, (int)((double)num/n+0.5));
  return 0;
}

Measured memory_bytes: 1184
#define M 100
char m[M][M],s[M][M][M],r[M],*z;
cmp(char *p,char *q){
  int r=0;
  for(;*p=='0';p++);
  for(;*q=='0';q++);
  if(r=strlen(p)-strlen(q))return r;
  return strcmp(p,q);
}
main(w,h,i,j,k,l){
	for(;scanf("%d%d",&w,&h),w;puts(z)){
		memset(s,0,sizeof(s));
		memset(r,0,sizeof(r));
		for(j=1;j<=h;j++)scanf("%s",m[j]+1);
		for(i=1;i<=w;i++)
			for(j=1;j<=h;j++){
				if(!isdigit(m[j][i]))continue;
				if(cmp(s[j][i-1],s[j-1][i])>0)strcpy(s[j][i],s[j][i-1]),s[j][i][strlen(s[j][i])]=m[j][i];
				else strcpy(s[j][i],s[j-1][i]),s[j][i][strlen(s[j][i])]=m[j][i];
				if(cmp(s[j][i],r)>0)strcpy(r,s[j][i]);
			}
		for(z=r;*z=='0';z++);
	}
return 0;}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <deque>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

deque<pi>vec, a, b, c;
int N, M, P, Q, R;

int cnt(int p, int q, int r){
  if(p > r) return 0;
  if(r >= q) return q-p+1;
  return r-p+1;
}

int countR(int p, int q, int r){
  int n = 1, vp, res = 0;
  for(vp=0;vp<vec.size();vp++){
    int f = vec[vp].F, l = vec[vp].S;
    int c = l-f+1;
    if(n <= p){
      if(n+c < p){
      }
      else if(n + c > q){
	res += cnt(f+p-n, f+q-n, r);
      }else{
	res += cnt(f+p-n, l, r);
      }
      n += c;
    }else if(n <= q){
      if(n+c<=q){
	res += cnt(f, l, r);
      }else{
	res += cnt(f, f+q-n, r);
      }
      n += c;
    }
  }
  return res;
}


int main(){
  while(1){
    cin >> N;
    if(!N) break;
    cin >> M >> P >> Q >> R;
    vec.clear();
    vec.push_back(MP(1,N));
    int x, y;
    rep(i, M){
      cin >> x >> y;
      a.clear(); b.clear();
      int p=1;
      while(p<=x){
	int f = vec[0].F, s = vec[0].S;
	if(p+s-f<=x){
	  a.push_back(MP(f,s));
	  p += s-f+1;
	  vec.pop_front();
	}else if(p+s-f>x){
	  a.push_back(MP(f, f+x-p));
	  vec[0].F = f+x-p+1;
	  p = x+1;
	}
      }
      while(p<=y){
	int f = vec[0].F, s = vec[0].S;
	if(p+s-f<=y){
	  b.push_back(MP(f, s));
	  p += s-f+1;
	  vec.pop_front();
	}else if(p+s-f>y){
	  b.push_back(MP(f, f+y-p));
	  vec[0].F = f+y-p+1;
	  p = y+1;
	}
      }

      vec.insert(vec.end(), b.begin(), b.end());
      vec.insert(vec.end(), a.begin(), a.end());

    }


    /*    rep(i, vec.size()){
      for(int j=vec[i].F;j<=vec[i].S;j++) cout << j << endl;;
      }*/
    cout << countR(P, Q, R) << endl;
  }
  return 0;
}

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

int main(){
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  for(int i=0; i<A; i++){
    cin >> a.at(i);
  }
  for(int i=0; i<B; i++){
    cin >> b.at(i);
  }
  for(int i=0; i<M; i++){
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    x.at(i)--; y.at(i)--;
  }
  int ans = a.at(0) + b.at(0);
  for(int i=0; i<M; i++){
    ans = min(ans,a.at(x.at(i))+b.at(y.at(i))-c.at(i));
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ans = min(ans,a.at(0)+b.at(0));
  cout << ans << endl;
}

Measured memory_bytes: 2176
import java.util.Scanner;

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

		double weight;
		while ((scan.hasNext())){
			weight = scan.nextDouble();
			System.out.println(kaikyu(weight));
		}
	}

	private static String kaikyu(double weight){
		String kaikyu = null;
		if(weight <= 48.0){
			kaikyu = "light fly";
		}else if(weight > 48.0 && 51.0 >= weight){
			kaikyu = "fly";
		}else if(weight > 51.0 && 54.0 >= weight){
			kaikyu = "bantam";
		}else if(weight > 54.0 && 57.0 >= weight){
			kaikyu = "feather";
		}else if(weight > 57.0 && 60.0 >= weight){
			kaikyu = "light";
		}else if(weight > 60.0 && 64.0 >= weight){
			kaikyu = "light welter";
		}else if(weight > 64.0 && 69.0 >= weight){
			kaikyu = "welter";
		}else if(weight > 69.0 && 75.0 >= weight){
			kaikyu = "light middle";
		}else if(weight > 75.0 && 81.0 >= weight){
			kaikyu = "middle";
		}else if(weight > 81.0 && 91.0 >= weight){
			kaikyu = "light heavy";
		}else if(91.0 < weight){
			kaikyu = "heavy";
		}

		return kaikyu;
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n,x,t, ans = 0;
	bool flag = false;
	string s;

	cin >> n >> x >> t;

	ans = (n / x)*t;

	if (n%x != 0) {
		ans += t;
	}

	cout << ans;
}

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

char s[10005],t[10005];
int main(int argc, char * argv[]) 
{
	cin>>s>>t;
	int lens = strlen(s);
	int lent = strlen(t);
	int ans = 10000;
	for(int i=0;(i+lent-1)<lens;i++){
		int sum = 0;
		for(int j=0;j<lent;j++)
			if(s[i+j]!=t[j]) 
				sum++;
		ans = min(ans,sum);
	}
	cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3636
mod = 10**9+7

def Pow(a, n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

N, K = map(int, input().split())
li = [0] * (K+1)
for i in range(K, 0, -1): 
    li[i] = Pow((K//i), N)
    for j in range(2,K//i+1):
        li[i] = (li[i] - li[i*j])%mod
ans = 0
for i in range(1, K+1):
    ans = (ans + i*li[i])%mod
print(ans)

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

int main(){
  while(1){
  int n,m;
  int sumt=0,sumh=0;
  int t[101],h[101];
  cin>>n>>m;
  if(n+m==0) break;
  for(int i=0;i<n;i++){
    cin>>t[i];
    sumt+=t[i];
  }
  int  stt=sumt;
  
  for(int i=0;i<m;i++){
    cin>>h[i];
    sumh+=h[i];
  }
  int sth=sumh;
  int g;
  int anst=0,ansh=0;
  int f=0,min=10000;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      sumt-=t[i];
      sumh-=h[j];
      sumt+=h[j];
      sumh+=t[i];
      
      if(sumt==sumh){
	f=1;
	if(t[i]+h[j]<min){
	  min=t[i]+h[i];
	  anst=t[i];
	    ansh=h[j];
      }
      }
      else if(sumt!=sumh){
	sumt=stt;
	sumh=sth;
      }

    }
  }
 
  if(f==1) cout<<anst<<" "<<ansh<<endl;
  else cout<<"-1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
for e in iter(input,'0'):
 a=[list(map(int,input().split()))for _ in[0]*int(e)]
 b=[list(map(int,input().split()))for _ in[0]*int(input())]
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if[u+x,v+y]not in b:break
  else:print(x,y)


Measured memory_bytes: 5976
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a, b := nextInt(), nextInt()
	s := next()

	for i := 0; i < a+b+1; i++ {
		c := s[i]

		if i == a {
			if c != '-' {
				fmt.Println("No")
				return
			}
		} else {
			x, err := strconv.Atoi(string(c))
			if err != nil {
				fmt.Println("No")
				return
			}
			if x < 0 || x > 9 {
				fmt.Println("No")
				return
			}
		}
	}

	fmt.Println("Yes")
}


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

void dfs(int now, int bef, ll cost, vector<ll> &path, const vector<vector<pair<int, ll>>> &T) {
  path[now] = cost;
  for (auto node: T[now]) {
    if (node.first == bef) continue;
    dfs(node.first, now, cost + node.second, path, T);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, ll>>> T(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    T[a].push_back({b, c});
    T[b].push_back({a, c});
  }
  int q, k;
  cin >> q >> k;
  vector<ll> path(n + 1);
  dfs(k, -1, 0LL, path, T);
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    cout << path[x] + path[y] << endl;
  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    ll ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
                {
                    if (min(l[i] + l[j], min(l[j] + l[k], l[k] + l[i])) > max(l[i], max(l[j], l[k])))
                        ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	int K;
	cin >> S >> K;

	int64_t result = 0;
	if( S.size() == 1 ) {
		result = K/2;
	}
	else if( count( S.begin(), S.end(), S[0] ) == S.size() ) {
		result = S.size() * K / 2;
	}
	else {
		int a = 0;
		for( int i = 0; i < S.size()-1; ++i ) {
			if( S[i] == S[i+1] ) {
				a += 1;
				i += 1;
			}
		}

		S += S;

		int b = 0;
		for( int i = 0; i < S.size()-1; ++i ) {
			if( S[i] == S[i+1] ) {
				b += 1;
				i += 1;
			}
		}

		result = a + (b-a) * (int64_t)(K-1);
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  ll x[105];
  ll sum = 0;
  ll sum2 = 0;
  for(ll i=0;i<n;i++){
    ll a; cin >> a;
    x[i] = a;
    sum += a;
    sum2 += a*a;
  }
  sort(x,x+n);
  ll mi = x[0];
  ll mx = x[n-1];
  ll ans = 1000000007;
  for(ll p=mi;p<=mx;p++){
    ans = min(ans, sum2 + n * p*p - 2 * p * sum);
  }
  cout << ans << endl;
  return 0;
}

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

const long mod = 1000'000'007;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    // 0-index
    --k;

    vector<ll> dp(w, 0);
    dp[0] = 1;
    for(int i = 1; i <= h; i++){
        vector<ll> dpNext(w, 0);
        for(int j = 0; j < (1 << (w-1)); ++j){
            bitset<8> bs(j);
            bool ng = false;
            for(int m = 0; m < w - 2; ++m){
                if(bs[m] == 1 && bs[m + 1] == 1){
                    ng = true;
                }
            }

            if(ng){
                continue;
            }

            // mは縦棒を表す
            for(int m = 0; m < w; ++m){
                // mの左側に横棒
                if(m > 0 && bs[m - 1]){
                    (dpNext[m] += dp[m - 1]) %= mod;
                }
                // mの右側に横棒
                else if(m < w - 1 && bs[m]){
                    (dpNext[m] += dp[m + 1]) %= mod;
                }
                // mに接触している横棒なし
                else{
                    (dpNext[m] += dp[m]) %= mod;
                }
            }
        }

        dpNext.swap(dp);
    }

    cout << dp[k] << endl;

    return 0;
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-17 21:36:06
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=100010;
int n,m,d[N],u[N],v[N],f[N];
int getf(int u){ return u==f[u]?u:f[u]=getf(f[u]); }
int main()
{
	n=read(); m=read();
	fr(i,1,m){ u[i]=read(); v[i]=read(); d[u[i]]++; d[v[i]]++; }
	fr(i,1,n) if(d[i]&1){ printf("No\n"); return 0; }
	fr(i,1,n) if(d[i]>=6){ printf("Yes\n"); return 0; }
	int cnt=0;
	fr(i,1,n) if(d[i]>=4) cnt++;
	if(cnt<2) printf("No\n");
	else if(cnt>2) printf("Yes\n");
	else
	{
		int x=0,y=0;
		fr(i,1,n) if(d[i]>=4) (x?y:x)=i;
		fr(i,1,n) if(i!=x) f[i]=i;
		fr(i,1,m) if(u[i]!=x&&v[i]!=x) f[getf(u[i])]=getf(v[i]);
		fr(i,1,n) if(i!=x&&getf(i)!=getf(y)){ printf("Yes\n"); return 0; }
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1664
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m;
ll k;
string s;
int xs[200000];

int main() {
	cin >> s;
	string notX;
	REP(i,s.size())if(s[i]!='x')
		notX += s[i];
	REP(i,notX.size()/2)if(notX[i]!=notX[notX.size()-1-i]){
		cout << -1 << endl;
		return 0;
	}
	int c=0;
	REP(i,s.size()){
		if(s[i]!='x')c++;
		else{
			xs[c]++;
		}
	}
	int ans=0;
	REP(i, (notX.size()+1)/2){
		ans += abs(xs[i] - xs[notX.size()+1-1-i]);
	}
	cout << ans;
	cout << endl;
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vi l(n);
    int sum=0;
    REP(i,n) {
        cin>>l[i];
        sum += l[i];
    }
    sort(ALL(l));

    string ans = (sum > l[n-1]*2) ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}

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

ran = []
for i in range(n):
    s, t, x = map(int, input().split())
    ran.append((s-x, t-x-1, x))
ran.sort(key=lambda a: a[2])

qu = []
convert = {}
for i in range(q):
    que = int(input())
    convert[que] = i
    qu.append(que)
qu.sort()

memo = [-1] * q

ans = [-1] * q

for i in range(n):
    x = ran[i][2]
    l = ran[i][0]
    r = ran[i][1]
    ql = bisect.bisect_left(qu, l)
    qr = bisect.bisect_right(qu, r)
    if ql >= qr:
        continue
    while ql < qr:
        if memo[ql] >= 0:
            ql = memo[ql]
        else:
            memo[ql] = qr
            ans[convert[qu[ql]]] = x
            ql += 1

for i in ans:
    print(i)

Measured memory_bytes: 125024
s = input()
s_list = []
for i in range(1 << (len(s) - 1)):
  s_ = ''
  for j in range(len(s) - 1):
    s_ += s[j:j+1]
    if (i >> j) % 2 == 1:
      s_ += '+'
  s_ += s[-1]
  s_list += [s_]

res = 0
for s_ in s_list:
  res += sum(map(int, s_.split('+')))
print(res)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> num(3);
  for (auto i : a) {
    if (i % 4 == 0) {
      num[2]++;
    } else if (i % 2 == 0) {
      num[1]++;
    } else {
      num[0]++;
    }
  }

  bool ok = (num[2] >= num[0] || num[2] == num[0] - 1 && num[1] == 0);
  cout << (ok ? "Yes" : "No") << '\n';

  return 0;
}


Measured memory_bytes: 3772
#include <iostream>
using namespace std;
int main(void){
    long long mod=1000000007;
    long long H,W,K,i;
    cin >> H >> W >> K;
    if(W==1){
        cout << 1 << endl;
        return 0;
    }
    long long N[W+2],M[W+2],pattern[10];
    for(i=0;i<W+2;i++){
        N[i]=0;
    }
    N[1]=1;
    pattern[0]=1;
    pattern[1]=1;
    for(i=2;i<10;i++){
        pattern[i]=pattern[i-1]+pattern[i-2];
    }
    for(i=0;i<H;i++){
        long long j;
        M[1]=N[1]*pattern[W-1]+N[2]*pattern[W-2];
        for(j=2;j<W;j++){
            M[j]=N[j-1]*pattern[j-2]*pattern[W-j] + N[j]*pattern[j-1]*pattern[W-j] + N[j+1]*pattern[j-1]*pattern[W-j-1];
        }
        M[W]=N[W]*pattern[W-1]+N[W-1]*pattern[W-2];
        for(j=1;j<W+1;j++){
            N[j]=M[j]%mod;
        }
    }
    cout << N[K] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c, s, e) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N = 3e5 + 5;
const long long INF = 1e18 + 37;

#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif


void solve(){
    int n;
    cin >> n;
    int a[n] , sum = 0;
    for(int i=0 ; i<n; i++){
        cin >> a[i];
        sum+=a[i];
    }
    sort(a , a+n, greater<>());
    int ans = 0;
    vector<int> c,w;
    for(int i=0 ; i<(n+1)/2 ; i++){
        c.pb(a[i]);
        if(i>0){
            ans+=a[i-1];
        }
    }
    for(int i=(n+1)/2; i<n; i++){
        w.pb(a[i]);
    }
    for(int i=0 ; i<w.size(); i++){
        if(i+1 < (n+1)/2){
            ans+=c[i+1];
        }
        else{
            ans+=c[i];
        }
    }
    cout << ans;
}


signed main() {
    FAST
    int tc = 1;
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}

Measured memory_bytes: 7148
n = gets.to_i
a = gets.split.map(&:to_i)
count = 0
(0..(n-1)).each do |i|
  if i == 0 || a[i] == 0
    next
  else
    if a[i] == a[i-1]
      a[i] = 0
      count += 1
    end
  end
end

p count



Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
  int num[101];
  int k;
  for(k=1;k<=100;k++){
    num[k]=0; //????????´??°??????????????°
  }
  while(scanf("%d",&k)!=EOF){
    num[k]++;
  }
  int freq;//?????????
  int maxnum=0;//????????????????????°
  for(k=100;k>=1;k--){
    if(maxnum <= num[k]){
      maxnum = num[k];
      freq = k;
    }
  }
  for(k=1;k<=100;k++){
    if(num[k] == num[freq]){
      printf("%d\n",k);
    }
  }
  return 0;
}

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

int main(){
	int a,taro=0,hanako=0;
	string s1,s2;
	
	cin>>a;
	
	for(int i=0;i<a;i++){
		cin>>s1>>s2;
		if(s1==s2){
			taro++;
			hanako++;
		}else if(s1>s2){
			taro+=3;
		}else if(s1<s2){
			hanako+=3;
		}
	}
	cout<<taro<<" "<<hanako<<endl;
	return 0;
}
	
	

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

int main() {
	long int n;
	cin >> n;
	long int p = n;
	long int t = n+1;
	vector<long int> a;
	vector<long int> b;
	while(t--) {
	    long int x;
	    cin >> x;
	    a.push_back(x);
	}
	
	while(p--) {
	    long int y;
	    cin >> y;
	    b.push_back(y);
	}
	
	long long int ans=0;
	for(long int i = 0; i < n; i++) {
	    if(a[i]>=b[i]) {
	        ans += b[i];
	    }
	    if(a[i]<b[i]) {
	        ans += a[i];
	        if(a[i+1]>(b[i]-a[i])) {
	            a[i+1] -= b[i]-a[i];
	            ans += b[i]-a[i];
	        }
	        else {
	            ans += a[i+1];
	            a[i+1] = 0;
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;

    long t;
    long min = 1000000;
    long max = -1000000;
    long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> t;
        if (min >= t) min = t;
        if (max <= t) max = t;
        sum += t;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
  int N;
  vector<double> vec;
  double sum = 0;
  double A;
  
  cin >> N;
  
  for (int i=0;i<N;i++){
  cin >> A;
  vec.push_back(A);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int i=0;i<N;i++){
	if (i==0){
      sum+=vec[0];
    }
    sum = (sum + vec[i])/2;
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxn = 100010;
int N, K;
int A[maxn];

template <unsigned Mod> struct Modular {
  using M = Modular;
  unsigned v;
  Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= mdpow(r, Mod - 2); }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
  friend M mdpow(M b, unsigned exp) {
    Modular res(1);
    while(exp) {
      if (exp & 1) {
        res *= b;
        if ((res.v += Mod) >= Mod) res.v -= Mod;
      }
      b *= b;
      exp >>= 1;
    }
    return res;
  }
};

constexpr long long mod = 1e9 + 7;
using Mint = Modular<mod>;

vector<Mint> fact, inv_fact, minv;
void prep(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1;
  inv_fact[n] = 1 / fact[n];
  // cout << inv_fact[n].v << endl;
  for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}

Mint binom(int n, int k) {
  if (k < 0 || k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}

int main() {
  fastio;
  cin >> N >> K;
  prep(N);
  // rep(i, N) cout << inv_fact[i].v << endl;
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  sort(A, A + N);
  Mint res(0);
  Mint choose;

  for (int i = 0; i < N; i++) {
    choose = binom(i, K-1);
    Mint val(A[i]);
    res += (val * choose);
  }

  for (int i = 0; i < N; i++) {
    Mint val(A[i]);
    choose = binom(N - i - 1, K-1);
    res -= (val * choose);
  }
  cout << res.v << endl;
}


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

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;++i){
        bool f=false;
        if(i%3==0) f=true;
        int x=i;
        while(x>0){
            if(x%10==3) f=true;
            x/=10;
        }
        if(f) cout << ' ' << i;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    long long  a[n];
    for (int i=0; i<n; i++){
        long long x;
        cin >> x;
        a[i]=x-i-1;
    }
    sort(a,a+n);
    long long med;
    if (n%2==0){
        med=(a[n/2]+a[n/2-1])/2;
    }
    else {
        med=a[n/2];
    }
    long long ans=0;
    for (int i=0; i<n; i++){
        ans+=abs(a[i]-med);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    ll K; cin >> K;
        vector<vector<ll>> DP(11, vector<ll>(11));
        ll cnt = 0;

        for(int i = 1; i < 11; i++) {
            for(int j = 0; j < 10; j++){
                if(i == 1) {
                    DP[i][j] = 1;
                    if(j != 0)cnt += DP[i][j];
                }
                else {
                    if(j == 0) DP[i][j] = DP[i-1][j] + DP[i-1][j+1]; 
                    else {
                        DP[i][j] = DP[i-1][j-1] + DP[i-1][j] + DP[i-1][j+1];
                        cnt += DP[i][j]; 
                    }
                }
                
                if(cnt >= K){
                    ll cnt2 = cnt - DP[i][j];
                    string tag = "";

                    tag += (char)(j+48);
                    ll cnt3 = K - cnt2;
                    if(i == 1) {cout << tag << endl; return 0;}


                    while(i > 1){
                        if(j == 0){
                            if(0 <= cnt3 && cnt3 <= DP[i-1][j]){
                                tag += to_string(j);
                            }
                            else {
                                cnt3 -= DP[i-1][j];
                                tag += to_string(j+1);
                                j = j+1;
                            }
                        }
                        else if(j == 9){
                            if(0 <= cnt3 && cnt3 <= DP[i-1][j-1]){
                                tag += to_string(j-1);
                                j = j-1;
                            }
                            else {
                                cnt3 -= DP[i-1][j-1];
                                tag += to_string(j);
                            }
                        }
                        else{
                            if( 0 <= cnt3 && cnt3 <= DP[i-1][j-1]){
                                tag += to_string(j-1);
                                j--;
                            }
                            else if( DP[i-1][j-1] < cnt3 && cnt3 <=  DP[i-1][j-1] + DP[i-1][j]){
                                cnt3 -= DP[i-1][j-1];
                                tag += to_string(j);
                            }
                            else{
                                cnt3 -= DP[i-1][j-1] + DP[i-1][j];
                                tag += to_string(j+1);
                                j = j+1;
                            }
                            
                        }
                        i--;
                        if(i == 1) {cout <<  tag << endl;return 0;}

                    }
                }
            }
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    ll ans = ((N-M) * 100 + 1900 * M) * pow(2,M);
    print(ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+9, INF = 0x3f3f3f3f;

int main( void ) {
    ios::sync_with_stdio( false );
    int n, q;
    list< int > ls;
    string s;
    cin >> n;
    for( int i = 0; i < n; ++i ) {
        cin >> s;
        if( s == "deleteFirst" ) ls.pop_front();
        else if( s == "deleteLast" ) ls.pop_back();
        else {
            cin >> q;
            if( s[0] == 'i' ) ls.push_front( q );
            else {
                for( list<int>::iterator it = ls.begin(); it != ls.end(); ++it ) {
                    if( *it == q ) {
                        ls.erase( it );
                        break;
                    }
                }
            }
        }
    }
    list<int>::iterator it = ls.begin();
    cout << *it;
    it++;
    for( ; it != ls.end(); ++it ) {
        cout << ' ' << *it;
    }
    cout << '\n';
    return 0;
}



Measured memory_bytes: 34476
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long X=1000000000+7;  

int main() {
  int n;
  cin>>n;
  bool exist=true;
  if(n%2==0){
    int even[50009];
    rep(i,50009) even[i]=0;
    rep(i,n){
      int a;
      cin>>a;
      if(a%2==0 || a>=n || even[a/2]>1){
        exist=false;
        break;
      }
      even[a/2]++;
    }
  }
  else{
    int odd[50009];
    rep(i,50009) odd[i]=0;
    rep(i,n){
      int a;
      cin>>a;
      if(a%2==1 || a>=n || odd[a/2]>1){
        exist=false;
        break;
      }
      if(a==0 && odd[a/2]!=0){
        exist=false;
        break;
      }
      odd[a/2]++;
    }
  }
  
  if(!exist) cout<<0<<endl;
  else{
    long long ans=1;
    rep(i,n/2)
      ans=(ans*2)%X;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 384