akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, x;
    cin >> n >> x;
    int m, min_m = 1001;
    rep(i,n) {
        cin >> m;
        min_m = min(m, min_m);
        x -= m;
    }
    cout << n + x / min_m << endl;
}

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

int main(){
  string A,B,E;
  int C,D;
  cin >> A >> B >> C >> D >> E;
  if(E==A){
    C--;
  }
  else{
    D--;
  }
  cout << C <<" " << D<< endl;
}

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

typedef long long ll;

const int MAXN = 505;
const ll INF = 1e18;

int N;
ll a[MAXN][MAXN];
ll dp[MAXN][MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			if (j != i)
				scanf("%lld", a[i] + j);
}

ll rectangle(int x1, int x2, int y1, int y2) {
	return a[x2][y2] + a[x1 - 1][y1 - 1] - a[x1 - 1][y2] - a[x2][y1 - 1];
}

ll rec(int l, int r) {
	ll &ref = dp[l][r];
	if (ref != INF)
		return ref;
	if (l == 1)
		return ref = rectangle(l, r, l, r);
	for (int i = 1; i < l; i++)
		ref = min(ref, rec(i, l - 1) + rectangle(l, r, i, r));
	return ref;
}

ll solve() {
	for (int i = 0; i <= N; i++)
		for (int j = 0; j <= N; j++)
			dp[i][j] = INF;
			
	ll sum = 0;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j < i; j++) {
			sum += a[i][j];
			a[i][j] = -a[i][j];
		}
		
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			a[i][j] += a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
	
	ll best = INF;
	for (int i = 1; i <= N; i++)
		best = min(best, rec(i, N));
	
	return sum + best;
}

int main() {
	load();
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll n,m,z,ne;;
   cin>>n>>m;
   
   if(m%2==0){
      z=m,ne=1+m;
   }else{
      z=m+1,ne=m+2;
   }
   bool f[101010]={},f2[101010]={};//f2kyori
   if(n%2==1){
      REP(i,1,m+1){

      cout<<i<<" "<<n-i+1<<endl;
      }
   }
   else{
      int i=1;
      while(z>i){
         cout<<i%n<<" "<<(z)%n<<endl;
         i++;z--;
      }
      
      z=ne;
      i=ne;
      z=ne+m-(m%2);
      while(z>i){
         cout<<i%n<<" "<<(z)%n<<endl;
         i++;z--;
      }
      // REP(i,1,n*2+1){
      //    if(f[i%n]==0&&f[(i+z)%n]==0){
      //       if(i%n<(i+z)%n){
      //          cout<<i%n<<" "<<(i+z)%n<<endl;;
      //       }else{
      //          cout<<(i+z)%n<<" "<<(i)%n<<endl;;
      //       }
            
      //       f[i%n]=f[(i+z)%n]=1;
      //       z--;
            
      //    }
      //    if(z==0)return 0;
      // }
   }
   
}


Measured memory_bytes: 3640
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
using namespace std;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, A, B;
	cin >> N >> A >> B;

	int sum, ans;

	ans = 0;
	rep2(x, 1, N + 1)
	{
		sum = 0;
		int y = x;
		while (0 < y)
		{
			sum = sum + (y % 10);
			y = y / 10;
		}
		if (A <= sum && sum <= B)
		{
			ans += x;
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
//#define EPS 0.000000001
using namespace std;

#define EPS 0.0000001
#define NUM 120005

struct Info{

	bool operator<(const struct Info &arg) const{
		return angle < arg.angle;
	}
	ll x,y,z;
	double angle;
};


int N;
Info info[NUM];


double calc_angle(Info A,Info B){

	double bunshi = A.x*B.x+A.y*B.y+A.z*B.z;
	double bunbo = sqrt(A.x*A.x+A.y*A.y+A.z*A.z)*sqrt(B.x*B.x+B.y*B.y+B.z*B.z);

	return acos(bunshi/bunbo);
}

bool compare(Info A,Info B){

	if(A.x != B.x){

		return A.x < B.x;

	}else if(A.y != B.y){

		return A.y < B.y;

	}else if(A.z != B.z){

		return A.z < B.z;
	}
	return -1;
}

bool isSame(Info A,Info B){

	return A.x == B.x && A.y == B.y && A.z == B.z;
}

void func(){


	Info base;
	base.x = 1;
	base.y = 1;
	base.z = 1;

	for(int i = 0; i < N; i++){

		info[i].angle = calc_angle(base,info[i]);
	}

	sort(info,info+N);

	Info ans_L,ans_R;

	double minimum = acos(0);
	double tmp_angle;

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			if(fabs(info[i].angle - info[k].angle) > minimum) break;

			tmp_angle = calc_angle(info[i],info[k]);
			if(tmp_angle < EPS)continue;

			if(tmp_angle+EPS < minimum){
				minimum = tmp_angle;

				if(compare(info[i],info[k])){

					ans_L = info[i];
					ans_R = info[k];

				}else{

					ans_L = info[k];
					ans_R = info[i];
				}

			}else if(fabs(tmp_angle-minimum) < EPS){

				if(compare(info[i],info[k])){

					if((compare(info[i],ans_L) == true) || (isSame(info[i],ans_L) && compare(info[k],ans_R) == true)){

						ans_L = info[i];
						ans_R = info[k];
					}

				}else{

					if((compare(info[k],ans_L) == true) || (isSame(info[k],ans_L) && compare(info[i],ans_R) == true)){

						ans_L = info[k];
						ans_R = info[i];
					}
				}
			}
		}
	}

	printf("%lld %lld %lld %lld %lld %lld\n",ans_L.x,ans_L.y,ans_L.z,ans_R.x,ans_R.y,ans_R.z);
}

int main(){

	ll num_1,num_2,S,W;

	while(true){

		scanf("%lld %lld %lld %lld",&num_1,&num_2,&S,&W);
		if(num_1 == 0 && num_2 == 0 && S == 0 && W == 0)break;

		for(int i = 0; i < num_1; i++){

			scanf("%lld %lld %lld",&info[i].x,&info[i].y,&info[i].z);
		}

		ll g = S;

		for(int i = 0; i < num_2; i++){
			info[i+num_1].x = (g/7)    %100 + 1;
			info[i+num_1].y = (g/700)  %100 + 1;
			info[i+num_1].z = (g/70000)%100 + 1;
			if( g%2 == 0 ) { g = (g/2); }
			else           { g = (g/2) ^ W; }
		}

		N = num_1+num_2;

		func();
	}

	return 0;
}



Measured memory_bytes: 6756
import numpy as np

MOD = 10 ** 9 + 7

l_matrix = np.zeros((32, 32), np.uint64)
for i in range(16):
    l_matrix[i+16][i] = 1
    l_matrix[i][i+16] = 1
for i in range(15):
    l_matrix[i+1][i] = 1
for i in range(5, 15):
    l_matrix[i+1][i+16] = 1
    
doubling = [l_matrix] #doubling[i] = (l_matrix) ** (2 ** i) % MOD
for _ in range(30):
    doubling.append(doubling[-1] @ doubling[-1] % MOD)

T = int(input())
for _ in range(T):
    N = int(input())
    N += 10
    dp = np.zeros(32, np.uint64)
    dp[0] = 1
    for i, c in enumerate(reversed(format(N, 'b'))):
        if c == '1':
            dp = doubling[i] @ dp
            dp %= MOD
    print(int((dp[15] + dp[31]) % MOD))
    #print(dp)


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ct1 = 0;
		int ct2 = 0;
		for(auto it:s)
		{
			if(it=='W')
			++ct1;
			else
			++ct2;
		}
		int ct3  =0;
		for(int i=ct2;i<n;++i)
		{
			if(s[i]=='R')
			++ct3;
		}
		cout<<min({ct1,ct2,ct3});
    }
    return 0;
}


Measured memory_bytes: 3744
n = int(input())
a = list(map(int, input().split()))

tmp = 1
cnt = 0

for i in range(n):
    if a[i] == tmp:
        cnt += 1
        tmp += 1
        
        
if cnt == 0:
    ans = -1
else:
    ans = n-cnt
    
print(ans)

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

int main() {
	int n,m;
	cin>>n>>m;
	int temp=n*m;
	if(temp%2==0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes";
	}


	return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def f(x):
    cnt = 0
    while x%2==0:
        cnt += 1
        x //= 2
    return cnt

n,m = inpl()
a = inpl()
g = f(a[0])
xx = a[0]

for i in range(1,n):
    if g != f(a[i]):
        print(0)
        quit()
    xx = xx*a[i]//fractions.gcd(xx,a[i])
if xx//2 > m:
    print(0)
else:
    print((m*2-xx)//(xx*2)+1)



Measured memory_bytes: 85352
#include <stdio.h>
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  
  if(a < b)
  {
    printf("a < b\n");
  }
  else if(a > b)
  {
    printf("a > b\n");
  }
  else if(a == b)
  {
    printf("a == b\n");
  }
  
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int x,y,b,p;
		cin>>x>>y>>b>>p;
		int count1=0;
		int count2=0;
		count1=x*b+y*p;
		if(b<5)
			b=5;
		if(p<2)
			p=2;
		count2=x*b+y*p;
		count2=count2*0.8;
		if(count2<count1)
			cout<<count2<<endl;
		else
			cout<<count1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  cout << n*n << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
void printmap();
void draw(int x,int y);
int w,h,c[51][51];

int main(){
	int i,j;
	int count;


	scanf("%d %d",&w,&h);


	while((w!=0)&&(h!=0)){
		count=0;
	
		for(j=0;j<h;j++){
			for(i=0;i<w;i++){
				scanf("%d",&c[j][i]);
			}
		}
		//printf("\n");
		
		for(i=0;i<w;i++){
			c[h][i]=0;
		}
		for(i=0;i<h;i++){
			c[i][w]=0;
		}

		for(i=0;i<w;i++){
			for(j=0;j<h;j++){
				if(c[j][i]==1){
					count++;
					//printf("count up count=%d\n",count);
					draw(j,i);
					//printmap();
				}
			}
		}

		printf("%d\n",count);
		scanf("%d %d",&w,&h);
	}
	return 0;
}

void draw(int x,int y){
	//printf("delete %d %d\n",x,y);
	int i,j;
	c[x][y]=0;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			if(c[x-1+i][y-1+j]==1){
				draw(x-1+i,y-1+j);
			}
		}
	}


}

void printmap(){
	int i,j;
	for(j=0;j<h;j++){
		for(i=0;i<w;i++){
			printf("%d ",c[j][i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<double> x(n), y(n), d(4);

    for (auto &xi: x) cin >> xi;
    for (auto &yi: y) cin >> yi;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n; j++)
            d[i] += pow(abs(x[j] - y[j]), i + 1);
        d[i] = pow(d[i], 1.0 / (i + 1));
    }

    d[3] = DBL_MIN;
    for (int i = 0; i < n; i++)
        d[3] = max(d[3], abs(x[i] - y[i]));

    cout << fixed << setprecision(8);
    for (auto &di: d)
        cout << di << endl;

    return 0;
}


Measured memory_bytes: 3424
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector< vector<int> > S(N);
  for(int i = 0; i < N; ++i){
    int t, d;
    cin >> t >> d;
    --t;
    S[t].push_back(d);
  }
  for(int i = 0; i < N; ++i) sort(S[i].rbegin(), S[i].rend());
  sort(S.rbegin(), S.rend());
  long long ans = 0, s = 0, t = 0;
  priority_queue<int> pq;
  for(int i = 0; i < min(N,K); ++i){
    if(S[i].empty()) continue;
    s += S[i][0];
    while(i+1+pq.size() > K){
      s += pq.top();
      pq.pop();
    }
    ans = max(ans, s+t+(long long)(i+1)*(i+1));
    for(int j = 1; j < (int)S[i].size(); ++j){
      t += S[i][j];
      pq.push(-S[i][j]);
      if((int)pq.size() > K-i-1) t += pq.top(), pq.pop();
      ans = max(ans, s+t+(i+1)*(i+1));
    }
    //cerr << ans << endl;
  }
  cout << ans << endl;
}


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


int main() {
    int n; cin >> n;
    vector<tuple<string,int,int>> v(n,tuple<string,int,int> ("",0,0));
    rep(i,n){
        cin >> get<0>(v.at(i)) >> get<1>(v.at(i));
        get<2>(v.at(i))=i+1;
        get<1>(v.at(i))*=(-1);
    }
    sort(v.begin(),v.end());
    rep(i,n){
        cout << get<2>(v.at(i)) << endl;
    }
    
}

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

#define max  100000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}


int main(void){
    int q, i, flag=0;
    char s[max], t[max];

    scanf("%s%s", s, t);
    
    q=strlen(s);
    
    for (i=0; i<q; i++) {
        if (s[i]==t[i]) {
            flag++;
        }
    }
    
    if (flag==q&&strlen(t)==q+1) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 1744
#include <iostream>

using namespace std;

int main() {
    int N;
    int a[10010];
    int bin_cnt[10010];

    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];

    for(int i = 0; i < N; i++) {
        int temp = a[i];
        int cnt = 0;

        while(1) {
            if(temp % 2 == 0) {
                temp = temp / 2;
                cnt++;
            } else {
                bin_cnt[i] = cnt;
                break;
            }
        }
    }

    int val = 0;
    for(int i = 0; i < N; i++) {
        val += bin_cnt[i];
    }

    cout << val << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll income[1010011];
vector<ll>adj[1010011];
map<ll,ll>m;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll num;
    ll cur=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(i!=j)
            {
                ll mini=min(i,j);
                ll maxi=max(i,j);
                m[mini*10000+maxi]=cur;
                cur++;
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ll num1;
        cin>>num1;
        ll i1=m[min(i,num1)*10000+max(i,num1)];
        for(ll j=2;j<n;j++)
        {
           cin>>num;
           ll mini=min(i,num);
           ll maxi=max(i,num);
           ll i2=m[min(i,num)*10000+max(i,num)];
           //cout<<i1<<" "<<i2<<endl;
           adj[i1].push_back(i2);
           income[i2]+=1;
           //cout<<i2<<" "<<income[i2]<<endl;
           i1=i2;
        }
    }
    //cout<<income[1]<<" "<<income[2]<<" "<<income[3]<<endl;
    //for(ll i=1;i<cur;i++)
    //    cout<<income[i]<<" "<<i<<endl;;
    vector<ll>v;
    ll ans=1;
    for(ll i=1;i<cur;i++)
    {
        if(income[i]==0)
        {
            v.push_back(i);
        }

    }
    //cout<<v.size()<<endl;
    if(v.size()==0)
    {
        cout<<"-1";
        return 0;
    }
    while(1)
    {
        vector<ll>v1;
        ll flag=0;
        for(ll i=0;i<v.size();i++)
        {
            for(ll j:adj[v[i]])
            {
                income[j]-=1;
                if(income[j]==0)
                {
                    v1.push_back(j);
                    flag=1;
                }
            }
        }
        if(flag==1)
        {
            ans++;
            v.clear();
            for(ll i=0;i<v1.size();i++)
            {
                v.push_back(v1[i]);
            }
        }
        else{
            break;
        }
    }
    for(ll i=1;i<cur;i++)
    {
        if(income[i]>0)
        {
            cout<<"-1";
            return 0;
        }
    }
    cout<<ans;
	return 0;
}

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

int N;
int main()
{
    cin >> N;
    long long sum = 0;
    long long minb = -1;

    for (int i = 0; i < N; i++)
    {
        long long a, b;
        cin >> a >> b;
        sum += b;
        if (a > b && (b < minb || minb < 0)) minb = b;
    }
    if (minb >= 0) cout << sum - minb << "\n";
    else cout << 0 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a[3][3];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a[0][0] >> a[0][1] >> a[1][1];
	a[2][1] = a[1][1]*2-a[0][1];
	llint S = a[0][1] + a[1][1] + a[2][1];
	
	a[2][2] = S-a[0][0]-a[1][1];
	a[0][2] = S-a[0][0]-a[0][1];
	a[1][2] = S-a[0][2]-a[2][2];
	a[1][0] = S-a[1][1]-a[1][2];
	a[2][0] = S-a[2][2]-a[2][1];
	
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,v) VL v(n);rep(i,n)cin>>v[i]
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>)
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl
#define debgp(a) cout<<#a<<" "<<a.fi<<" "<<a,se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(const auto&y:a){for(const auto&x:y)cout<<x<<" ";cout<<endl;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define PQ priority_queue
typedef long long ll;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T gcd(T a,T b){return (b==0?a:gcd(b,a%b));}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*a;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h,w,n;
  cin>>h>>w>>n;
  cinv(n,a);

  V<VL> ans(h,VL(w));
  int x=0,y=0,idx=0,use=0;
  bool xFlag=true;
  rep(i,h*w){
    //cout<<"yx "<<y<<" "<<x<<endl;
    ans[y][x]=idx+1;
    use++;
    if(use==a[idx]){
      use=0;
      idx++;
    }
    if(xFlag)x++;
    else x--;
    if(x==w||x==-1){
      if(x==w)x--;
      else x++;
      y++;
      xFlag=(!xFlag);
    }
  }
  for(auto y:ans){
    for(auto x:y){
      cout<<x<<" ";
    }
    cout<<endl;
  }
 //cout<<"end"<<endl;
  
  return 0;
}


Measured memory_bytes: 512
import sys
import math
from collections import deque
import copy

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

SUM = 0

for i in range(1, K + 1):
    p = 0
    t = []
    for l in range(10 ** 9):
        t.append(T[i + K * l - 1])
        if (i + K * (l + 1) -1 ) >= N:
            break
    dp = [[-1, -1, -1] for _ in range(len(t) + 1)]
    dp[0] = [0, 0, 0]
    for l in range(1, len(t) + 1):
        if t[l - 1] == "r":
            dp[l][0] = max(dp[l - 1][1], dp[l - 1][2])
            dp[l][1] = max(dp[l - 1][0], dp[l - 1][2])
            dp[l][2] = max(dp[l - 1][0], dp[l - 1][1]) + P
        elif t[l - 1] == "s":
            dp[l][0] = max(dp[l - 1][1], dp[l - 1][2]) + R
            dp[l][1] = max(dp[l - 1][0], dp[l - 1][2])
            dp[l][2] = max(dp[l - 1][0], dp[l - 1][1])
        else:
            dp[l][0] = max(dp[l - 1][1], dp[l - 1][2])
            dp[l][1] = max(dp[l - 1][0], dp[l - 1][2]) + S
            dp[l][2] = max(dp[l - 1][0], dp[l - 1][1])
    SUM += max(dp[len(t)])
print(SUM)


Measured memory_bytes: 18336
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,t,q,u,w,y,r;
int ret=0;
int a[100],b[100],c[100],d[100],v[100];
void dfs(int i,int x){
    v[i]=x;
    if(i==n){
        int ans=0;
        for(int j=0;j<q;j++)
            if(v[b[j]]-v[a[j]]==c[j]) ans+=d[j];
        ret=max(ret,ans);
        return;
    }
    for(int j=x;j<=m;j++)
        dfs(i+1,j);
}
int main()
{
    cin>>n>>m>>q;
    for(int i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    for(int i=1;i<=m;i++)
        dfs(1,i);
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 3632
# coding: utf-8
import itertools
import math
# 人の数
N = int(input())
zahyo = []
for _ in range(N):
    zahyo.append(tuple(map(int, input().split(" "))))


def distance(zahyo1, zahyo2):
    return math.sqrt(pow(zahyo1[0] - zahyo2[0], 2) + pow(zahyo1[1] - zahyo2[1], 2))

dis = 0
for jyun in itertools.permutations(range(N)):
    for i in range(N-1):
       dis += distance(zahyo[jyun[i]], zahyo[jyun[i+1]])
print(dis / math.factorial(N))




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

using ll = long long;

using namespace std;

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) {
            continue;
        }
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int main(void) {
    ll N;
    cin >> N;
    auto pf = prime_factorize(N);
    ll res = 0;
    for (auto p : pf) {
        ll e = p.second;
        ll tmp = 0;
        ll cur = 1;
        while (e >= cur) {
            e -= cur++, ++tmp;
        }
        res += tmp;
    }
    cout << res << endl;
}


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

int main() {
   int N, M;
   cin >> N >> M;
   vector<int> H(N);
   vector<int> ans(N);
   vector<int> A(M), B(M);
   rep(i, N) {
      cin >> H[i];
   }
   rep(i, M) {
      cin >> A[i] >> B[i];
      if(H[A[i] - 1] > ans[B[i] - 1]) {
         ans[B[i] - 1] = H[A[i] - 1];
      }
      if(H[B[i] - 1] > ans[A[i] - 1]) {
         ans[A[i] - 1] = H[B[i] - 1];
      }
   }
   int sunuke = 0;
   rep(i, N) {
      if(H[i] > ans[i]) {
         sunuke++;
      }
   }
   cout << sunuke << endl;
   return 0;
}

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

int main(){
	int a, b, c, G, R, L, tmp, r;
	while(cin >> a >> b){
		R = a; L = b;
		if(b > a){
			tmp = a;
			a = b; 
			b = tmp;
		}
		while(1){
			r = a % b;
			if(r == 0) break;
			a = b;
			b = r;
		}

		G = b;
		R = R / G;
		L = L / G;

		cout << G << " "  << R*L*G << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define umap unordered_map
#define uset unordered_set
#define mod 1000000007
#define imax INT_MAX
#define imin INT_MIN
#define exp 1e9
#define sz(x) (int((x).size()))
#define int long long


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   string s,t;
   cin>>s>>t;
   vector<vector<int>>dp(s.size()+1,vector<int>(t.size()+1,0));
   for(int i=1;i<=s.size();i++)
   {
       for(int j=1;j<=t.size();j++)
       {
          if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
          else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
   }
   int i=s.size(),j=t.size();
   vector<char>ans;
   while(i>0 && j>0)
   {
       if(s[i-1]==t[j-1])
       {
         ans.push_back(s[i-1]);
         i--;
         j--;
         continue;
       }
       if(dp[i-1][j]>dp[i][j-1])
       {
           i--;
       }
       else
        j--;

   }
   reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        cout<<ans[i];

    return 0;
}


Measured memory_bytes: 73636
#include <stdio.h>

int main(void)
{
	int num[20], b[20], c[20], 
	n, i, j, bh, ch, flag;
	
	scanf("%d", &n);
	while (n != 0){
		n--;
		for (i = 0; i < 10; i++){
			b[i] = 0;
			c[i] = 0;
		}
		for (i = 0; i < 10; i++)scanf("%d", &num[i]);
		bh = 0;
		ch = 0;
		flag = 0;
		for (i = 0; i < 10; i++){
			if (!(num[i] < b[bh])){
				if (!(bh == 0));
				b[bh] = num[i];
			//	printf("b = %d\n", b[bh]);
			}
			else if (!(num[i] < c[ch])){
				if (!(ch == 0));
				c[ch] = num[i];
			//	printf("c = %d\n", c[ch]);
			}
			else {
				puts("NO");
				flag = 1;
				break;
			}
		}
		if (flag == 0)puts("YES");
	}
	
	return (0);
}

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

int main() {
  vector<int> data(3);
  for(int i=0; i<3; i++) {
    cin >> data[i];
  }
  sort(data.begin(), data.end());
  
  if(data[2] == data[0]+data[1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int p, q;
    while ( cin >> p >> q ) {
        map <int, int> M;
        int t = 0;
        int r = p % q;
        while ( r > 0 ) {
            r *= 10;
            if ( M.count( r ) ) {
                cout << endl;
                for ( int i = 0; i < t; ++ i ) {
                    if ( i >= M[r] && i <= t - 1 ) {
                        cout << "^";
                    } else {
                        cout << " ";
                    }
                }
                break;
            }
            M[r] = t;
            cout << r / q;
            r %= q;
            t ++;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int x[100],y[100];
	int n;
	cin >> n;
	REP(i,n) cin >> x[i];
	REP(i,n) cin >> y[i];
	long double sum = 0;
	REP(i,n) sum += abs(x[i]-y[i]);
	cout << sum << endl;
	sum = 0;
	REP(i,n) sum += (x[i]-y[i])*(x[i]-y[i]);
	cout << setprecision(20) << fixed << sqrt(sum) << endl;
	sum = 0;
	REP(i,n) sum += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
	cout << cbrt(sum) << endl;
	long double ans4 = -9999;
	REP(i,n) ans4 = max(ans4,(long double)abs(x[i]-y[i]));
	cout << ans4 << endl;
}

Measured memory_bytes: 1264
#include <iostream>

using namespace std;

int main(){

	int A[5];
	int B[5];

	while(cin >> A[0] >> A[1] >> A[2] >> A[3] >> B[0] >> B[1] >> B[2] >> B[3]){

		int hit = 0 , blow = 0;

		if(A[0] == 0 || A[1] == 0 || A[2] == 0 || A[3] == 0 ||
			B[0] == 0 || B[1] == 0 || B[2] == 0 || B[3] == 0) break;

		for(int i = 0; i < 4; i++){
			if(A[i] == B[i]){
					hit++;
				}
			for(int j = 0; j < 4; j++){

				if(A[i] ==  B[j] && A[i] != B[i]){
					blow++;
				}
			}
		}

		cout << hit << " " << blow << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>

using namespace std;

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

  int sw[n];
  int se[n];
  int nw=0;
  int ne=0;
  int ans = n;
  char temp;
  int debug=0;
  for (int i=0; i<n; ++i) 
    se[i] = sw[i] = 0;

  for (int i=0; i<n; ++i) {
    cin >> temp;
    if (i==0) {
      if (temp == 'W') sw[i] = 1, se[i] = 0;
      else se[i] = 1, sw[i] = 0;
    } else {
      if (temp == 'W') {
        sw[i] = sw[i-1] + 1;
        se[i] = se[i-1];
      } else {
        se[i] = se[i-1] + 1;
        sw[i] = sw[i-1];
      }
    }
  }

  for (int i=0; i<n; ++i) {
    // cout << "SE: " << se[i] << " SW: " <<sw[i] << endl;
    if (i == 0) {
      nw = 0;
      ne = se[n-1] - se[i];
    } else {
      nw = sw[i-1];
      ne = se[n-1] -se[i];
    }
    if (ans-(ne+nw)>=0)
      ans = ne + nw;
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
print(N+N**2+N**3)


Measured memory_bytes: 65212
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

int kotae[200];


signed main(){
    int n,k;
    cin >> n >> k;
    REP(i,k){
        int d1;
        cin >> d1;
        REP(j,d1){
            int a1;
            cin >> a1;
            kotae[a1] ++;
        }
    }
    int ans = 0;
    REP(i,n){
        if(kotae[i+1]==0) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
n, m = map(int,input().split())

aList = []
for i in range(n):
  aList.append(input())

bList = []
for j in range(m):
  bList.append(input())

for k in range(n-(m-1)):
  aIMatch = aList[k].find(bList[0])
  aICount = aList[k].count(bList[0])
  for ct in range(aICount):
 # if aIMatch >= 0:
    sucFlag = True 
    for l in range(1,m):
      aNMatch = aList[k+l].find(bList[l],aIMatch)
      if not(aNMatch >= 0 and aIMatch == aNMatch):
        sucFlag = False
        break
    if sucFlag:
      print("Yes")
      exit(0)
    aIMatch = aList[k].find(bList[0],aIMatch+1)

print("No")



Measured memory_bytes: 3064
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
x,y=map(int,input().split())
if((x in a and y in a)or(x in b and y in b)or(x in c and y in c)):
    print("Yes")
else:
    print("No")

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

int main()
{
    int A[4][13]{0}, n, y;
    // for (int i = 0; i < 4; ++i){
    //     for (int j = 0; j < 13; ++j){
    //         A[i][j] = 0;
    //     }
    // }
    char s;
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> s >> y;
        if (s == 'S') A[0][y-1] = 1;
        if (s == 'H') A[1][y-1] = 1;
        if (s == 'C') A[2][y-1] = 1;
        if (s == 'D') A[3][y-1] = 1;
    }
    
    for (int i = 0; i < 4; ++i){
        for (int j = 0; j < 13; ++j){
            if (i == 0 && A[i][j] != 1) cout << "S " << j+1 << endl;
            if (i == 1 && A[i][j] != 1) cout << "H " << j+1 << endl;
            if (i == 2 && A[i][j] != 1) cout << "C " << j+1 << endl;
            if (i == 3 && A[i][j] != 1) cout << "D " << j+1 << endl;
        }
    }

    return 0;
}


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

const int INF = 1e9;

int main(){
  #ifdef LOCAL
	freopen("input.txt","r",stdin);
 // freopen("out.txt","w",stdout);
	#endif
  int n , k;
  cin >> n >> k;
  vector<int>dp(n, INF);
  vector<int>ar(n);
  for(int i=0;i<n;i++)cin >> ar[i];
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=k+i;j++){
      if(j<n)
        dp[j]=min(dp[j], dp[i]+abs(ar[i]-ar[j]));
    }
  }
  cout << dp[n-1];

  return 0;
}



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

constexpr int kN = int(2E5 + 10);
typedef long long int ll;

ll a[kN];
int x[kN], y[kN], val[60][60];
double d[kN];

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n, sz;
	ll ans = 0;
	string s;
	bool flag;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		sz = int(s.size());
		flag = false;
		for (int j = 0; j < sz; j++) {
			if (s[j] == '.') {
				for (int k = j + 1; k < sz; k++) a[i] = a[i] * 10 + s[k] - '0';
				for (int k = 0; k < 10 - sz + j; k++) a[i] *= 10;
				flag = true;
				break;
			}
			else a[i] = a[i] * 10 + s[j] - '0';
		}
		if (!flag) for (int j = 0; j < 9; j++) a[i] *= 10;
	}
	for (int i = 1; i <= n; i++) {
		while (a[i] % 2 == 0) {
			a[i] >>= 1;
			x[i]++;
		}
		while (a[i] % 5 == 0) {
			a[i] /= 5;
			y[i]++;
		}
	}
	for (int i = 1; i <= n; i++) val[59 - x[i]][59 - y[i]]++;
	for (int i = 1; i < 60; i++) val[0][i] += val[0][i - 1];
	for (int i = 1; i < 60; i++) val[i][0] += val[i - 1][0];
	for (int i = 1; i < 60; i++) for (int j = 1; j < 60; j++) 
		val[i][j] += val[i - 1][j] + val[i][j - 1] - val[i - 1][j - 1];
	
	for (int i = 1; i <= n; i++) {
		if (x[i] >= 9 && y[i] >= 9) ans--;
		ans += val[min(59, 59 - (18 - x[i]))][min(59, 59 - (18 - y[i]))];
	}
	cout << ans / 2 << '\n';
}


Measured memory_bytes: 6704
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)
typedef long long ll;
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a[4];
	memset(a,0,sizeof(a));
	for(int i=1;i<=3;i++)cin>>a[i];
	sort(a+1,a+4);
	if(a[2]==a[3])cout<<a[1];
	else if(a[1]==a[3])cout<<a[2];
	else cout<<a[3];
	
	
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
int ans;
ll n;
int w;
int j;
void f(int i, ll tmp,  int three, int five, int seven) {
  if(i == j) {
    if(n >= tmp && three > 0 && five > 0 && seven > 0) {
      ans++;
      //   cout << tmp << endl;
    }
    return;
  }
  f(i+1,tmp * 10 + 7,three,five,seven+1);
  f(i+1,tmp * 10 + 5,three,five+1,seven);
  f(i+1,tmp * 10 + 3,three+1,five,seven);
   
  return;
}

int main() {
 
  cin >> n;
  int tmp = n;
  while(tmp > 0) {
    tmp /= 10;
    w++;
  }

  for(int i = 3; i <= w; i++) {
    j = i;
  f(0,0,0,0,0);
  }
  
  cout << ans << endl;
}
  
  


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endN "\n"

bool solve(){
  ll a,b;cin>>a>>b;
  if(a>=13)cout<<b<<endl;
  else if(a>=6)cout<<b/2<<endl;
  else cout<<0<<endl;
  return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
  // ll Q;cin>>Q;
	// while(Q--)solve();
  solve();
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <map> 
#include <set>
#include <ctime> 
#include <queue> 

#define LL long long

using namespace std;

int n;
char str[19] = "9999999999";

char read()
{
	char ret = 0;
	while(ret!='Y' && ret!='N')
		ret=getchar();
	return ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("test_out.txt", "w", stdout);
	#endif
	int cur = 0;
	bool only_one_1 = false;
	while(1)
	{
		int l = 0, r = 9, mid;
		while(l<r)
		{
			mid = l+r>>1;
			if(mid==0 && cur==0) { l = 1; break; }
			if(mid!=-1)	str[cur] = mid+'0';
			else	str[cur] = 0;
			printf("? %s\n", str);
			fflush(stdout);
			char ans = read();
			if(ans=='Y')
				r = mid;
			else
				l = mid+1;
		}
		if(l==1 && cur==0)	only_one_1 = true;
		if(cur!=0 && l!=0)	only_one_1 = false;
		str[cur] = l+'0';
		if(cur==9)	break;
		cur++;
	}
	while(1)
	{
		if(str[cur] != '0')
		{
			str[cur+1] = 0;
			printf("! %s\n", str);
			break;
		}
		LL x = 0;
		for(int i = 0; i < cur; i++)
			x+=str[i]-'0', x*=10;
		x--;
		cout<<"? "<<x<<endl;
		fflush(stdout);
		char ans = read();
		if(!only_one_1)
			if(ans == 'Y')
			{
				str[cur] = '0'; str[cur+1] = 0;
				printf("! %s\n", str);
				break;
			}else
				cur--;
		else
			if(ans == 'N')
			{
				str[cur] = '0'; str[cur+1] = 0;
				printf("! %s\n", str);
				break;
			}else
				cur--;
	}
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int a[222222];
int main(){
  int n; 
  cin>>n; 
  multiset<int>mst;
  for(int i=0;i<n;i++){
    cin>>a[i];
    mst.insert(a[i]);
  }
  for(int i=0;i<n;i++){
  	mst.erase(mst.find(a[i])) ;
    cout<<*(mst.rbegin())<<endl;
    mst.insert(a[i]);
  }
  return 0; 
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//ori
#define MOD 1000000007
 
int main() {
  int N, ans=1;
  cin >> N;
  vector<LL> a(N);
  FOR(i,2,N+1) {
    LL b=i;
    
    for(int j = 2; j*j <= b; j++) {
      while(b%j == 0) {
        b /= j;
        a.at(j-1)++;
      }
    }
    if(b>1) a.at(b-1)++;
  }
  
  FOR(i,1,N){
    ans = ans*(a.at(i)+1)%MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<set>
#include<functional>
#include<queue>
#define int long long
using namespace std;

int x[100005];
int d[20][100005];
signed main() {
	int n; scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &x[i]);
	}
	int l; scanf("%lld", &l);
	x[n] = 1ll << 38;
	for (int i = 0; i < n; i++) {
		int S = i, G = n + 1;//(S,G]
		while (G - S > 1) {
			int K = (S + G) / 2;
			if (x[K] - x[i] <= l) {
				S = K;
			}
			else {
				G = K;
			}
		}
		d[0][i] = S;
	}
	for (int i = 0; i < 18; i++) {
		for (int j = 0; j < n; j++) {
			d[i + 1][j] = d[i][d[i][j]];
		}
	}
	int Q; scanf("%lld", &Q);
	for (int i = 0; i < Q; i++) {
		int x, y; scanf("%lld%lld", &x, &y);
		x--; y--;
		if (x > y)swap(x, y);
		int ans = 1;
		for (int j = 18; j >= 0; j--) {
			if (d[j][x] < y) {
				x = d[j][x];
				ans += 1ll << j;
			}
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 17280
#include<stdio.h>
int matrix[101][101];
int level[101];
int queue[101];

int main()
{
    int n,i,j,u,v,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            matrix[u][v]=1;
        }
    }

    for(i=1;i<=n;i++)
     level[i]=-1;
    int qHead=0,qTail=0;
    queue[qTail++]=1;
    level[1]=0;
    while(qHead!=qTail){
     int v=queue[qHead++];
     for(i=1;i<=n;i++){
      if(level[i]==-1 && matrix[v][i]==1){
       level[i]=level[v]+1;
       queue[qTail++]=i;
      }
     }
    }

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



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

using namespace std;

const long long int mod = 1e9+7;
class Matrix{
	public:
		int size;
		vector<vector<int> > a;
		Matrix(int n){
			this->size = n;
			this->a.resize(n,vector<int>(n));
		}
	Matrix operator*( Matrix const  & other){
		Matrix temp(size);
		for(int i = 0; i < size; i++){
			for(int j = 0; j < size; j++){
				for(int k = 0; k < size; k++){
					temp.a[i][k] += 1ll*a[i][j] * other.a[j][k] % mod; 
					temp.a[i][k]%=mod;
				}
			}
		}
		return temp;
	}	
};

int n;

Matrix power(Matrix a, long long k){
	if(k==0){
		Matrix I(n);
		for(int i = 0; i < n; i++) I.a[i][i] = 1;
		return I;
	}
	Matrix q = power(a,k>>1);
	q = q * q;
	if(k&1) q = q * a;
	return q;
}

int main(){
	cin >> n;
	long long k; cin >> k;
	Matrix r(n);
	for(int i = 0; i < n; i++){
		for(int j = 0;j < n; j++){
			cin >> r.a[i][j];
		}
	}
///	Matrix R = r*r;
//	for(int i = 0; i < n; i++){
//		for(int j = 0; j < n; j++){
//			cout << R.a[i][j] << " ";
//		}
//		cout << "\n";
//	}
//	return 0;
	r = power(r,k);
	long long res = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			res += r.a[i][j];
			res %= mod;
		}
	}	
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(998244353)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF (int)2e18
#define EPS 1e-9
#define int long long
#define MAX 100009
int fun(int arr[][3], int n){
	/*if(n == 0) return 0;
	int maxi = 0LL;
	for(int i = 0; i < 3; i++){
		if(last != i) maxi = max(maxi, arr[n-1][i] + fun(arr, n-1, i));
	}
	return maxi;*/
	/*dp[i][j] = maximum possible happiness upto i days, 
	with type j as last day; j = {0, 1, 2}*/
	int dp[n][3];
	for(int i = 0; i < 3; i++) dp[0][i] = arr[0][i];

	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			dp[i][j] = 0;
			for(int k = 0; k < 3; k++){
				if(k == j) continue;
				dp[i][j] = max(dp[i][j], dp[i-1][k] + arr[i][j]);
			}
		}
	}
	return max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	int T=1;
	//cin >> T;
	FOR1(i, T)
	{
		//cout << "Case #" << i << ": \n";
		int n; cin >> n;
		int arr[n][3];
		FOR(i, n){
			cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
		}
		cout << fun(arr, n);
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define  p5         100005
#define  p6         1000007
#define  PI         acos(-1)
#define  M          1000000007
#define  sc         scanf
#define  ss         second
#define  ff         first
#define  pf         printf
#define  scin(x)    sc("%d",&x)
#define  scin2(x,y) sc("%d%d",&x,&y)
#define  READ(f)    freopen(f, "r", stdin)
#define  WRITE(f)   freopen(f, "w", stdout)
#define  ll         long long
#define  pp         pair < int, int>
#define  pq         priority_queue
#define  pb         push_back
#define OK          pf("Yes\n")
#define _OK         pf("No\n")
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,i,j,k;
    string st;
    cin>>st;
    if(st=="SAT")
        cout<<1<<endl;
    else if(st=="FRI")
        cout<<2<<endl;
    else if(st=="THU")
        cout<<3<<endl;
    else if(st=="WED")
        cout<<4<<endl;
    else if(st=="TUE")
        cout<<5<<endl;
    else if(st=="MON")
        cout<<6<<endl;
    else if(st=="SUN")
        cout<<7<<endl;
    return 0;
}
//https://github.com/me-shaon/bangla-programming-resources


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

int main(){
    string s;
    cin >> s;
    if(s[0] == 'S'){
        cout << "Cloudy" << endl;
    }
    else if(s[0] == 'C'){
        cout << "Rainy" << endl;

    }
    else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x-r<0){
		cout<<"No"<<endl;
	}
	else if(w<x+r){
		cout<<"No"<<endl;
	}
	else if(y-r<0){
		cout<<"No"<<endl;
	}
	else if(h<y+r){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}



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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int mx = 0;
	int cnt  =0;
	
	for(int i = 0;i<n;i++)
	{

		if(s[i]==')')cnt++;
		else cnt--;
		mx = max(mx,cnt);
	}
	
	for(int i =0 ;i<mx;i++)cout<<'(';
	cout<<s;
	cnt = 0;
	mx = 0;
	for(int i = n-1;i>=0;i--)
	{
		if(s[i]=='(')cnt++;
		else cnt--;
		mx = max(mx,cnt);
	}
	for(int i =0 ;i<mx;i++)cout<<')';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
fun main() {
    val numK = readLine()!!.toInt()
    val gcdList = mutableListOf<Int>()

    for(i in 1 .. numK ){
        for(j in 1 .. numK){
            for(k in 1 .. numK){
                gcdList.add(gcd(i, gcd(j, k)))
            }
        }
    }


    println(gcdList.sum())
}

fun gcd(a :Int, b :Int): Int{
    if(a < b) return gcd(b , a)
    if(b == 0) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 113328