akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fastmap mp.reserve(1024);mp.max_load_factor(0.25);
#define fastset st.reserve(1024);st.max_load_factor(0.25);
ll int mpw(ll int a,ll int b,ll int m)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%m;
		}
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}
 
ll int pw(ll int a,ll int b)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans*=a;
		}
		a*=a;
		b>>=1;
	}
	return ans;
}
 
ll int mn(ll int a,ll int b)
{
	if(a<=b)
	{
		return a;
	}
	return b;
}
 
ll int mx(ll int a,ll int b)
{
	if(a>=b)
	{
		return a;
	}
	return b;
}
 
int main()
{
	fio
	cout.precision(13);
	int n;
	cin>>n;
	vector<vector<double>>D(n,vector<double>(n+1,0.0));
	vector<double>nm(n);
	for(int i=0;i<n;++i)
	{
		cin>>nm[i];
	}
	D[0][0]=1-nm[0];
	D[0][1]=nm[0];
	for(int i=1;i<n;++i)
	{
		D[i][0]=D[i-1][0]*(1-nm[i]);
		for(int j=1;j<=n;++j)
		{
			D[i][j]=nm[i]*D[i-1][j-1]+(1-nm[i])*D[i-1][j];
		}
	}
	double ans=0.0;
	for(int i=(n+1)/2;i<=n;++i)
	{
		ans+=D[n-1][i];
	}
	cout<<fixed<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 74244
#include <iostream>
using namespace std;
 
int main() { 
    char a, b;
    cin >> a >> b;
    if(a == 'H') {
        cout << b << '\n';
    } else {
        if(b == 'H') {
            cout << 'D' << '\n';
        } else {
            cout << 'H' << '\n';
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll D = 1000000007;

int main(){
  int n;
  cin >> n;
  string S[n];

  int cnt[n][26];
  for(int i=0;i<n;i++){
    for(int j=0;j<26;j++){
      cnt[i][j] = 0;
    }
  }

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

  for(int i=0;i<n;i++){
    int l = S[i].size();
    for(int j=0;j<l;j++){
      int check = S[i][j] - 'a';
      cnt[i][check]++;
    }
  }

  int common[26];
  for(int j=0;j<26;j++) common[j] = 100;

  for(int j=0;j<26;j++){
    for(int i=0;i<n;i++){
      common[j] = min(common[j], cnt[i][j]);
    }
  }

  for(int j=0;j<26;j++){
    char ch = 'a' + j;
    for(int k=0;k<common[j];k++){
      cout << ch;
    }
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

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

		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if (x > 0 && x < w && y > 0 && y < h) {
			if (x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

Measured memory_bytes: 17360
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

void swap(ll& a, ll& b){
    ll t;
    t = a;
    a = b;
    b = t;
}
int main() {
    

    ll n;
    cin >> n;
    unordered_map<ll, ll> abcList;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        abcList[tmp]++;
    }
    if(abcList.size() > 3){
        cout << "No" << endl;
        return 0;
    }else if(abcList.size() == 3){
        bool flag = true;
        auto itr = abcList.begin();
        ll num1 = itr -> second;
        while(itr != abcList.end()){
            if(num1 != itr -> second){
                flag = false;
                break;
            }
            itr++;
        }
        if(!flag){
            cout << "No" << endl;
            return 0;
        }else{
            itr = abcList.begin();
            unsigned long long number1 = itr -> first;
            itr++;
            unsigned long long number2 = itr -> first;
            itr++;
            unsigned long long number3 = itr -> first;
            if(number1 == (number2 ^ number3)){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }else if(abcList.size() == 2){
        ll num1 = 0;
        ll number1 = 0;
        ll num2 = 0;
        ll number2 = 0;
        auto itr = abcList.begin();
        num1 = itr -> second;
        number1 = itr -> first;
        itr++;
        num2 = itr -> second;
        number2 = itr -> first;
        if(num2 < num1){
            swap(num1, num2);
            swap(number1, number2);
        }
        if(number1 != 0){
            cout << "No" << endl;
            return 0;
        }else{
            if(num1*2 == num2){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }else if(abcList.size() == 1){
        auto itr = abcList.begin();
        if(itr -> first == 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }



}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    cin>>N;
    cout<<(N+1)/2<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int P=924844033;
const int MAXN=2010;

template<typename T1,typename T2>
	void Inc(T1 &a,T2 b){a+=b;if(a>=P) a-=P;}

template<typename T1,typename T2>
	void Dec(T1 &a,T2 b){a-=b;if(a<0) a+=P;}

template<typename T1,typename T2>
	T1 Add(T1 a,T2 b){a+=b;return a>=P?a-P:a;}

template<typename T1,typename T2>
	T1 Sub(T1 a,T2 b){a-=b;return a<0?a+P:a;}

int n,k;
int f[2][MAXN][2];
ll fac[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	int lst=0;
	f[0][0][1]=1;fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P;
	for(int r=1;r<=2*k;r++)
	{
		int tot=0,ed;
		for(int j=r;j<=n;j+=2*k)
			++tot,ed=j;
		if(!tot)
			break;
		for(int _=1;_<=tot;_++)
		{
			memset(f[!lst],0,sizeof f[!lst]);
			for(int j=0;j<=n;j++)
			{
				//f[lst][j][0]
				Inc(f[!lst][j+1][0],f[lst][j][0]);
				Inc(f[!lst][j+1][1],f[lst][j][0]);
				Inc(f[!lst][j][0],f[lst][j][0]);
				//f[lst][j][1]
				Inc(f[!lst][j+1][1],f[lst][j][1]);
				Inc(f[!lst][j][0],f[lst][j][1]);
			}
			lst^=1;
		}
		if(ed+k>n)
			for(int i=0;i<=n;i++)
				f[lst][i][1]=0;
		int fl=r+1<=k;
		for(int i=0;i<=n;i++)
			f[lst][i][fl]=Add(f[lst][i][0],f[lst][i][1]),
			f[lst][i][fl^1]=0;
	}
	ll Ans=0;
	for(int i=0;i<=n;i++)
		if(i&1)
			Dec(Ans,Add(f[lst][i][0],f[lst][i][1])*fac[n-i]%P);
		else
			Inc(Ans,Add(f[lst][i][0],f[lst][i][1])*fac[n-i]%P);
	printf("%lld\n",Ans);
}


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

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii> > vvii;

int main(){
    
    string x;
    cin >> x;
    if((x[0] == x[1] and x[1] == x[2]) or (x[1] == x[2] and x[2] == x[3])){
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

  int ans = 0;
  while (n != 0) {
    n /= k;
    ans++;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=INT_MAX;
  string s;
  cin >>n >>s;
  int wcount[n+1];
  wcount[0]=0;
  for(int i=0;i<n;i++){
    if(s[i]=='.')wcount[i+1]=wcount[i]+1;
    else wcount[i+1]=wcount[i];
  }
  for(int i=0;i<n+1;i++){
    ans=min(ans,i-wcount[i]+wcount[n]-wcount[i]);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 1412
#include<iostream>
#include<queue>
using namespace std;
char a[22][22];
int n,m;
struct pos{
	int x;
	int y;
	int step;
};
pos make_pos(int a,int b,int c){
	pos ret;
	ret.x=a;
	ret.y=b;
	ret.step=c;
	return ret;
}
int bfs(int sx,int sy,int ex,int ey){
	bool vis[n+2][m+2];
	for(int i=0;i<=n+1;++i)
		for(int j=0;j<=m+1;++j)
			if(a[i][j]=='#')
				vis[i][j]=true;
			else
				vis[i][j]=false;
	queue<pos>q;
	q.push(make_pos(sx,sy,0));
	vis[sx][sy]=true;
	int move[2][4]={{0,0,-1,1},{-1,1,0,0}};
	while(!q.empty()){
		pos fr=q.front();
		q.pop();
		if(fr.x==ex&&fr.y==ey)
			return fr.step;
		pos newpo;
		for(int i=0;i<4;++i){
			int nx=fr.x+move[0][i];
			int ny=fr.y+move[1][i];
			if(vis[nx][ny])
				continue;
			vis[nx][ny]=true;
			newpo=make_pos(nx,ny,fr.step+1);
			q.push(newpo);
		}
	}
	return 0;
}
int main(){
	for(int i=0;i<22;++i)
		for(int j=0;j<22;++j)
			a[i][j]='#';
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>a[i][j];
	int maxv=0;
	for(int i1=1;i1<=n;++i1)
		for(int j1=1;j1<=m;++j1){
			if(a[i1][j1]=='#')
				continue;
			for(int i2=1;i2<=n;++i2)
				for(int j2=1;j2<=m;++j2){
					if(a[i2][j2]=='#')
						continue;
					if(i1==i2&&j1==j2)
						continue;
					maxv=max(maxv,bfs(i1,j1,i2,j2));
				}
		}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int x, y;
    cin >> x >> y;

    int ans = 0, disp = x;
    disp = x;
    if(abs(y) <= abs(x)){
        if(disp > 0){
            ans++;
            disp = disp*-1;
        }
        // cout << "disp:" << disp << endl;
        if(y <= 0){
            ans += (y - disp);
        }else{
            ans += (-1*y - disp) + 1;
        }
    }else{
        if(disp == 0){
            if(y > 0)
                ans += y - disp;
            else
                ans += -1*y - disp + 1;
        }else{
            if(disp < 0){
                disp = disp*-1;
                ans++;
            }
            if(y > 0)
                ans += y - disp;
            else
                ans += -1*y - disp + 1;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split(" "))
sunuke = [0 for num in range(N)]
for i in range(K):
    d = int(input())
    sweets = list(map(int,input().split(" ")))
    for sweet in sweets:
        if sunuke[sweet-1] == 0:
            sunuke[sweet-1] = 1
trick = sunuke.count(0)
print(trick)


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

int main(){
    while(true){
        string str[2];
        cin>>str[0];
        if(str[0]==".")return 0;
        cin>>str[1];
        bool flag=false;
        vector<vector<ll>> mozi(2,vector<ll>());
        vector<vector<ll>> soto(2,vector<ll>());
        rep(nnn,2){
            rep(i,str[nnn].size()){
                if(str[nnn][i]=='"'){
                    if(flag){
                        flag=false;
                        soto[nnn].push_back(0);
                    }else{
                        flag=true;
                        mozi[nnn].push_back(0);
                    }
                }else{
                    if(flag){
                        mozi[nnn][mozi[nnn].size()-1]+=str[nnn][i];
                    }else{
                        if(soto[nnn].size()==0)soto[nnn].push_back(0);
                        soto[nnn][soto[nnn].size()-1]+=str[nnn][i];
                    }
                }
            }
        }
        ll wn=0;
        if(mozi[0].size()!=mozi[1].size() || soto[0].size()!=soto[1].size()){
            cout<<"DIFFERENT"<<endl;
            continue;
        }
        bool f=false;
        rep(i,soto[0].size()){
            if(soto[0][i]!=soto[1][i]){
                cout<<"DIFFERENT"<<endl;
                f=true;
                break;
            }
        }
        if(f){
            continue;
        }
        rep(i,mozi[0].size()){
            if(mozi[0][i]!=mozi[1][i]){
                wn++;
            }
        }
        if(wn==0){
            cout<<"IDENTICAL"<<endl;
        }else if(wn==1){
            cout<<"CLOSE"<<endl;
        }else{
            cout<<"DIFFERENT"<<endl;
        }
    }
}



Measured memory_bytes: 3152
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	int a, b, c;
  cin>>a>>b>>c;
	cout << yn(a + b >= c) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main()
{
	string s;
	cin>>s;
	int x = 0;
	ll n = s.size();
	for(int i = 0;i<n;i++)
	{
		x += (s[i] - '0')%9;
		x%=9;
	}
	cout<<(x?"No":"Yes")<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;

int main(void){
    int roop,upper,lower;
    cin >> roop >> upper >> lower;
    int total = 0;
    array<int,4> A;
    int b=0;
    for(int i=1;i <= roop;i++){
        b = i/10000;
        A[0] = i/1000-b*10;
        A[1] = i/100 - A[0]*10 - b*100;
        A[2] = i/10 - A[0] * 100 - A[1] * 10 - b*1000;
        A[3] = i%10;
        if(b+A[0]+A[1]+A[2]+A[3] >= upper && b+A[0]+A[1]+A[2]+A[3] <= lower){
            total += i;
        }
    }
    cout << total << endl;
}


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

int main(){
	int n, m;
	string str;
	map<string, int> ma;

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

	cin >> m;
	for( int i = 0; i < m; ++i ){
		cin >> str;
		ma[str]--;
	}

	int tot = 0;
	for( auto it = ma.begin(); it != ma.end(); ++it ){

		tot = max(it->second, tot);
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, u, v; cin >> n >> u >> v; u--; v--;
	vector<vector<int>> to(n);
	for(int i = 0; i < n - 1; i++){
		int x, y; cin >> x >> y; x--; y--;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	function<void(int,int,vector<int>&)> dfs = [&](int u, int p, vector<int> &d){
		for(int v : to[u]){
			if(v == p) continue;
			d[v] = d[u] + 1;
			dfs(v, u, d);
		}
	};
	vector<int> du(n, 0), dv(n, 0);
	dfs(u, -1, du);
	dfs(v, -1, dv);
	int ans = du[v] / 2;
	for(int i = 0; i < n; i++){
		if(du[i] < dv[i]){
			ans = max(ans, dv[i] - 1);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 14208
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> dx(n);
  rep(i, n) {
    int a;
    cin >> a;
    dx[i] = abs(x - a);
  }
  if (n == 1) {
    cout << dx[0] << endl;
    return 0;
  }
  ll ans = __gcd(dx[0], dx[1]);
  rep(i, n) {
    ans = __gcd(ans, dx[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> B(M);
  for (int i = 0; i < M; i++) cin >> B.at(i);

  int C = *max_element(A.begin(), A.end());
  int D = *min_element(B.begin(), B.end());

  if (X < C && C < D && D < Y) cout << "No War" << endl;
  else cout << "War" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  string str;
  while(cin >> str){
    if(str == "0") break;

    int dp[80001][11];
    memset(dp,0,sizeof(dp));

    int res = 0;
    for(int i=0;i<str.size();i++){
      int num = str[i] - '0';
      for(int j=0;j<=10;j++){
	dp[i+1][(j*10+num)%11] = dp[i][j];
      }
      if(num > 0) dp[i+1][num]++;
      res += dp[i+1][0];
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 4768
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const MAX: usize = 55555;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut sieve = vec![true; MAX+1];
    sieve[1] = false;
    for i in 2..MAX+1 {
        if !sieve[i] {
            continue;
        }
        let mut n = 2*i;
        while n <= MAX {
            sieve[n] = false;
            n += i;
        }
    }
    let mut ans = Vec::new();
    for i in 1..MAX+1 {
        if sieve[i] && i % 5 == 1 {
            ans.push(i);
        }
    }
    for &a in &ans[..N] {
        println!("{}", a);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,x;
	cin >> n;
	for(int i=2;i<=n;i++){
		cin >> x;
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		cout << a[i] << endl;
	}
	return 0;
}


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

int n;
int a[1000][1000];
int t[1000];

int main()
{
	while (scanf("%d", &n), n){
		memset(a, 0, sizeof(a));
		
		for (int i = 0; i < n; i++){
			int hh, mm, id;
			char str[2];
			scanf("%*s %d:%d %s %d", &hh, &mm, str, &id);
			t[i] = hh * 60 + mm;
			
			if (str[0] == 'I') a[id][i]++;
			else a[id][i]--;
		}
		
		for (int i = 0; i < 1000; i++){
			for (int j = 0; j + 1 < n; j++){
				a[i][j + 1] += a[i][j];
			}
		}
		
		int res = 0;
		for (int i = 1; i < 1000; i++){
			int sum = 0;
			for (int j = 0; j + 1 < n; j++){
				if (a[0][j] && a[i][j]){
					sum += t[j + 1] - t[j];
				}
			}
			res = max(res, sum);
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

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

int main()
{
	int a=0,w=0,t=0,r=0;

	int n;
	cin>>n;
	string b;

	for (int i = 0; i < n; i++)
	{
		cin>>b;

		if (b== "AC")
			a+=1;
		if (b== "WA")
			w+=1;
		if(b== "TLE")
			t+=1;
		if(b=="RE")
			r+=1;

	}

	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

vector<int> adj[N];
int mark[N];
int nim[N];

void dfs(int v, int p)
{
	for (auto u : adj[v])
		if (u != p)
		{
			dfs(u, v);
			nim[v] ^= nim[u] + 1;
		}
}

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

	int n;
	cin >> n;
	for (int i=1; i<n; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	dfs(0, -1);
	cout << (nim[0] ? "Alice" : "Bob") << "\n";

	return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e3+10;
int a[N],b[N];
int a1[N];
void debug_a(int a[],int n)
{
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
}
void debug_v(vector<int>&v)
{
    for(auto it:v)
    {
        cout<<it<<" ";
    }
    cout<<endl;
}
int32_t main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]>a[j])
            {
                b[i]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i!=j)
            {
                if(a[i]>a[j])
                {
                    a1[i]++;
                }
            }
        }
    }
    //debug_a(b,n);
    for(int i=1;i<=n;i++)
    {
        int k=m*(m-1)/2;
        k%=MOD;
        ans+=a1[i]*k;
        ans%=MOD;
        ans+=b[i]*m;
        ans%=MOD;
    }
    //cout<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
s=list(input())
t=list(input())

a=list("abcdefghijklmnopqrstuvwxyz")

rs=dict()
rt=dict()
for i in range(26):
    rs[a[i]]=-1
    rt[a[i]]=-1

yn=""
for i in range(len(s)):
    if rs[s[i]]==-1:
        rs[s[i]]=t[i]
    else:
        if rs[s[i]]!=t[i]:
            yn="No"
            break
    if rt[t[i]]==-1:
        rt[t[i]]=s[i]
    else:
        if rt[t[i]]!=s[i]:
            yn="No"
            break
        
if yn=="No":
    print("No")
else:
    print("Yes")
        

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

int main() {
    int sh, sm, ss, gh, gm, gs;
    while (cin >> sh >> sm >> ss >> gh >> gm >> gs) {
        int stime = sh * 3600 + sm * 60 + ss;
        int gtime = gh * 3600 + gm * 60 + gs;
        int atime = gtime - stime;
        cout << atime / 3600 << " ";
        atime %= 3600;
        cout << atime / 60 << " ";
        atime %= 60;
        cout << atime << endl;
    }

    return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////

int main() {
    int n;
    I(n);
    char ar[n+2];
    SC("%s", ar + 1);
    int la = n;
    int fi = 1;
    int cnt = 0;
    while( fi < la) {
        if(ar[la] == 'R'){
            while(ar[fi] != 'W' && fi < la){
                fi++;
            }
            if(ar[fi] == 'W'){
                swap(ar[fi], ar[la]);
                cnt++;
            }
        }else la--;
    }
    cout<<cnt<<Endl;
}

Measured memory_bytes: 3904
#A問題
N = int(input())
S = list(str(N))
Slen = len(S)
s = int(S[0])
ans = 0
if N == (s+1)*(10**(Slen-1))-1:
    for ss in S:
        ans+=int(ss)
else:
    for i in range(Slen):
        if i == 0:
            ans+=(int(S[0])-1)
        else:
            ans+=9
            
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];






int main()
{

	int n;
	cin >> n;

	vector<pair<int,int>> factor;
	int num;
	for (int i = 1; i <= n; i++) {
		num = i;

		for (int j = 0; j < factor.size(); j++) {

			while (num % factor[j].first == 0) {
				factor[j].second++;
				num /= factor[j].first;
			}

		}

		if (num != 1) {
			pair<int, int> wk = make_pair(num, 1);
			factor.push_back(wk);
		}
	}

	long long int ans = 1;
	for (int i = 0; i < factor.size(); i++) {
		ans = ans * (long long int)(factor[i].second + 1) % MOD;
	}

	cout << ans << endl;
	
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 998244353;

int N;
vector<pair<int,int>> XD;
vector<vector<int>> to;

LL count(int index)
{
    if (to[index].empty()) {
        return 2;
    }
    LL ret = 1;
    for (int child: to[index]) {
        ret = (ret * count(child)) % MOD;
    }
    ++ret;
    return ret;
}

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

    cin >> N;
    XD.resize(N);
    to.resize(N);

    rep(i, N) {
        cin >> XD[i].first >> XD[i].second;
        XD[i].second += XD[i].first;
    }
    sort(XD.begin(), XD.end());

    set<pair<int,int>> s; //! {x, index} of the root of each tree
    for (int i = N-1; 0 <= i; --i) {
        while (!s.empty() && s.begin()->first < XD[i].second) {
            to[i].push_back(s.begin()->second);
            s.erase(s.begin());
        }
        s.emplace(XD[i].first, i);
    }

    LL ans = 1;
    for (auto r: s) {
        ans = (ans * count(r.second)) % MOD;
    }
    cout << ans << endl;


    return 0;
}


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

#define MAX 500000

int A[MAX];
int n;

int left(int i) {
    return (i*2);
}

int right(int i) {
    return (i*2+1);
}
 
void maxHeapify(int *A, int i) {
    int l = left(i);
    int r = right(i);
    int largest;

    if(l<=n && A[l]>A[i]) {
        largest = l;
    }
    else {
        largest = i;
    }
    //printf("largest = %d\n", largest);
    if(r<=n && A[r]>A[largest]) {
        largest = r;
    }

    if(largest!=i) {
        //printf("swaping!\n");
        swap(A[i], A[largest]);
        maxHeapify(A, largest);
    }
}

void buildMaxHeap(int *A) {
    for(int i=n/2; i>0; i--) {
        maxHeapify(A, i);
    }
}

int main() {
    cin >> n;
    for(int i=1; i<n+1; i++) {
        cin >> A[i];
    }

    buildMaxHeap(A);

    cout << " ";
    for(int i=1; i<n+1; i++) {
        cout << A[i];
        if(i==n) {
            cout << endl;
        }
        else {
            cout << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 5044
def traveling(n, m):
    t = range(1, len(m))
    for i in t:
        xdif = abs(m[i][1]-m[i-1][1])
        ydif = abs(m[i][2]-m[i-1][2])
        tdif = m[i][0]-m[i-1][0]
        dif = xdif+ydif
        if tdif < dif:
            return 'No'
        elif (tdif > dif) and (((tdif - dif) % 2) != 0):
            return 'No'
    return 'Yes'
N = int(input())
deer = [list(map(int, input().split())) for i in range(N)]
deer.insert(0, [0,0,0])
print(traveling(N, deer))

Measured memory_bytes: 27380
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    vector<pair<ll, char>> v(m);
    rep(i, m) {
        ll s; char c; cin >> s >> c; s--;
        v[i] = {s, c};
    }

    for (ll i = (n != 1 ? (ll)pow(10, n - 1) : 0); i < (ll)pow(10, n); i++) {
        string j = to_string(i);
        bool isok = true;
        rep(k, m) {
            if (j[v[k].first] != v[k].second) {
                isok = false;
                break;
            }
        }
        if (isok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

// bool comp(const pair<ll,ll>& light, const pair<ll,ll>& right){
//     if(light.second != right.second){
//         return light.second > right.second;
//     }else{
//         return light.first > right.first;
//     }
// }

int main() {
    ll n,m;
    std::cin >> n>>m;
    vector<pair<ll,ll>> baito(n);
    vector<vector<ll>> hi(m);
    for (int i = 0; i < n; i++) {
        // A日後に、報酬B
        std::cin >> baito[i].first >> baito[i].second;
        if(m-baito[i].first>=0){
            hi[m-baito[i].first].push_back(baito[i].second);
        }
    }
    priority_queue<ll> kouho;
    
    ll result = 0;
    for (int i = m-1; i >= 0; i--) {
        for (auto e : hi[i]) {
            kouho.push(e);
        }
        if(!kouho.empty()){
            result += kouho.top();
            kouho.pop();
        }
    }
    std::cout << result << std::endl;
}
 

Measured memory_bytes: 7168
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: "List[int]"):
    A.sort(key=lambda x: x[1])
    current = 0
    for volume, deadend in A:
        current += volume
        if current > deadend:
            print(NO)
            return
    print(YES)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [tuple()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = (int(next(tokens)), int(next(tokens)))
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59740
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());

            int[] Vs = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] Cs = ReadLine().Split(' ').Select(int.Parse).ToArray();

            int ans = 0;

            for (int i = 0; i < N; i++)
            {
                if (Vs[i] > Cs[i])
                {
                    ans += Vs[i] - Cs[i];
                }
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,s,dp[2*100001][2];

ll solve(ll arr[],int idx,int prev)
{
  if(idx>=n) return 0;
  if(dp[idx][prev]!=-(1e9 +7)) return dp[idx][prev];
  if(prev==0)
  {
    return dp[idx][prev]=max(arr[idx]+solve(arr,idx+2,0),arr[idx+1]+solve(arr,idx+2,1));
  }
  else
  {
    return dp[idx][prev]=arr[idx+1]+solve(arr,idx+2,1);
  }
}

int main()
{

    cin>>n;
    cout<<fixed<<setprecision(20)<<2.0*3.14159*n;
}

Measured memory_bytes: 3780
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
    
    

    public static void main(String[] args)throws Exception{

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer>[] ary = new List[n];
        for(int i=0; i<n; i++){
            ary[i] = new ArrayList<Integer>();
        }

        for(int i=0; i<m; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();

            ary[a-1].add(b-1);
            ary[b-1].add(a-1);
        }

        Deque<Map<String,Integer>> que = new ArrayDeque<>();
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        Map<String,Integer> map = new HashMap<>();
        map.put("from", 0);
        map.put("number", 0);
        que.add(map);

        while(!que.isEmpty()){
            Map<String,Integer> map2 = que.removeFirst();
            int from = map2.get("from");
            int number = map2.get("number");

            if(ans[number] == -1){
                ans[number] = from;

                for(int i=0; i<ary[number].size(); i++){
                    int temp = ary[number].get(i);
                    Map<String,Integer> map3 = new HashMap<>();
                    map3.put("from", number);
                    map3.put("number", temp);
                    que.add(map3);
                }
            }
        }
        System.out.println("Yes");
        for(int i=1; i<n; i++){
            System.out.println((ans[i] + 1));
        }
    }
}

Measured memory_bytes: 168244
#include <cmath>
#include <iostream>
using namespace std;
int n, a[261], b[261];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		int mi, mj, mk; double v = 1e+300;
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 16; j++) {
				for (int k = 0; k < 16; k++) {
					int c[261] = { 0 }; b[0] = i;
					for (int l = 1; l <= n; l++) b[l] = (j * b[l - 1] + k) % 256;
					for (int l = 0; l < n; l++) c[(a[l] + b[l + 1]) % 256]++;
					double res = 0;
					for (int l = 0; l < 256; l++) {
						if (c[l]) res -= c[l] * log(1.0 * c[l] / n);
					}
					if (v - 1e-9 > res) v = res, mi = i, mj = j, mk = k;
				}
			}
		}
		cout << mi << ' ' << mj << ' ' << mk << endl;
	}
}

Measured memory_bytes: 3240
import java.util.*;

public class Main {


    static long mod = 1000000007;

    static long[] fac;
    static long[] finv;
    static long[] inv;

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int max = n+1;
        fac = new long[max];
        finv = new long[max];
        inv = new long[max];

        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[(int)mod%i] * (mod / i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }


        long res = 0;

        long[] a = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);

        for(int i=0; i<n; i++) {
            res += mod - c(n-i-1, k-1) * a[i];
            res %= mod;
            res += c(i, k-1) * a[i];
            res %= mod;
        }
        System.out.println(res);
    }

    static long c(int n, int k) {
        if(n < k) return 0;
        if(n < 0 || k< 0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
    }


}




Measured memory_bytes: 62308
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
	public static void main(String[] args) throws Exception
	{

		Scanner sc=new Scanner(System.in);
		long t=sc.nextLong();
		
		List<Long> li=new ArrayList<Long>();
		List<Long> li1=new ArrayList<Long>();
		Map<Long,Long> mp=new HashMap<>();
		long sum=0;
		for(int i=0;i<t;i++)
		{
			 li.add(sc.nextLong());
			 sum=sum+li.get(i);
			 
		}
		
		map1(li,mp);
		long q=sc.nextLong();;
		for(int i=0;i<q;i++)
		{
			long b=sc.nextLong();
			long c=sc.nextLong();
			long x=0;
			long y=0;
			long z=0;
			if(mp.containsKey(b))
			{
			     x=mp.get(b);
			     y=b*x;
			     z=c*x;
			     sum=sum-y+z;
			     if(mp.containsKey(c))
			     {
			    	 mp.remove(b);
			    	 mp.put(c,mp.get(c)+x);
			     }
			     else
			     {
				mp.remove(b);
				mp.put(c,x);
			     }
			
			}
			li1.add(sum);
		}
		for(int i=0;i<li1.size();i++)
		{
			System.out.println(li1.get(i));
		}
		
	}
	public static void map1(List<Long> li,Map<Long,Long> mp)
	{
		for(int i=0;i<li.size();i++)
		{
			if(mp.containsKey(li.get(i)))
			{
				mp.put(li.get(i),mp.get(li.get(i))+1l);
			}
			else
			{
				mp.put(li.get(i),1l);
			}
		}

   }
}


Measured memory_bytes: 70232
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
from queue import deque
q = deque([a[0]])
ans = 0
for num in a[1:]:
    ans += q.popleft()
    q.append(num)
    q.append(num)
print(ans)

Measured memory_bytes: 94144
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,t;
ll a[100000];
int main(){
	cin >> n >> t;
	REP(i,n) {
		cin >> a[i];
	}

	ll maxi = 0,mini = a[0];
	FOR(i,1,n) {
		maxi = max(maxi,a[i] - mini);
		if(a[i] < mini) 
			mini = a[i];
	}

	mini = 0;ll ans = 0;
	FOR(i,1,n) {
		if(a[i] - a[mini] == maxi) {
			ans ++;
		}
		if(a[i] < a[mini]) {
			mini = i;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int n; cin >> n;
    map<int, int> mapp;
    ll sum = 0;
    FOR(i, 0, n) {
        int a; cin >> a;
        mapp[a]++;
        sum += a;
    }
    int q; cin >> q;
    vector<int> b(q), c(q);
    FOR(i, 0, q) {
        int b, c; cin >> b >> c;
        int count = mapp[b];
        count *= (c-b);
        sum += count;
        mapp[c] += mapp[b];
        mapp[b] = 0;
        cout << sum << endl;
    }
}

signed main() {
    solve();
    return 0;
}

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

const int N = 105;
int a[N];

bool check(int x, int y, int z) {
    if (x == y) return 0;
    if (x == z) return 0;
    if (y == z) return 0;
    return x+y > z && x+z > y && y+z > x;
}

void solve() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; i <= n; i++) scanf("%d", a+i);
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            for (int k = j+1; k <= n; k++) {
                ans += check(a[i], a[j], a[k]);
            }
        }
    }
    printf("%d\n", ans);
}

int main() {
    int T = 1;
    // scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}


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

int GCD(int a,int b){
    int tmp;
    
    if(!(a >= b)){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    
    
    for(;;){
        if(!b) break;
        a %= b;
        tmp = a;
        a = b;
        b = tmp;
    }
    
    return a;
}

int main(){
    int a,b;
    
    while(cin >> a >> b){
    cout << GCD(a,b) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main() {
	int a, b, i, cnt;
	scanf("%d%d", &a, &b);
	cnt = 0;
	for (i = a; i <= b; i++) {
		if (i/10000%10 == i/1%10 && i/1000%10 == i/10%10) cnt++;
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 128