akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)
 
ll ceili(ll a, ll b)
{
	if(a%b==0LL) return ll(a/b);
	return 1 + ll(a/b);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

    string s;
    cin>>s;

    int d=0;

    for(int i=0; i<len(s); i++)
    {
    	d += (int)s[i] - (int)'0';
    }

    cout << ((d%9 == 0) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3788
#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;

#define n_MAX (int)(2*10e5)
pair<long long, long long> J[n_MAX];

int main(){
    int N;
    scanf("%d", &N);
    long long a, b;
    for(int i = 0; i < N; i++){
        scanf("%lld %lld", &a, &b);
        J[i] = make_pair(b, a);
    }

    sort(J, J+N);

    long long A_sum[N];
    A_sum[0] = J[0].second;
    for(int i = 1; i < N; i++){
        A_sum[i] = J[i].second + A_sum[i-1];
    }

    bool f = true;
    for(int i = 0; i < N; i++){
        if(A_sum[i] > J[i].first){
            f = false;
            break;
        }
    }

    if(f){
        printf("Yes\n");
    }else{
        printf("No\n");
    }


    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 200
int S[N],n,top=0;
int main()
{
char x[100];
while(scanf("%s",x) != EOF)
  {
  if(x[0]=='+' && top != 1)
    {
    S[top-1] = S[top] + S[top-1];
    top--;
    }
  else if(x[0]=='*' && top != 1)
    {
    S[top-1] = S[top] * S[top-1];
    top--;
    }
  else if(x[0]=='-' && top != 1)
    {
    S[top-1] = S[top-1] - S[top];
    top--;
    }
  else
    {
    top++;
    S[top]=atoi(x);
    }
  }
printf("%d\n",S[top]);
return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner

import scala.collection.mutable.ListBuffer
import scala.util.control.Breaks

object Main {
  def main (args: Array[String]) = {
        val in = new Scanner(System.in)
        var list = new ListBuffer[String]

        val brk = new Breaks
        brk.breakable {
          while (true) {
            val first = in.nextInt
            val second = in.nextInt
            if (0 != first || 0 != second) {
              val great = Math.max(first, second)
              val less = Math.min(first, second)
              list += less + " " + great
            } else brk.break()
          }
        }

        list.foreach(println(_))
  }
}

Measured memory_bytes: 54228
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int H, W;
string S[10];
bool K[10][10];
bool dfs(int a, int b) {
    if (a == H - 1 && b == W - 1) return K[a][b] = true;
    if (a + 1 < H && S[a + 1][b] == '#' && dfs(a + 1, b)) return K[a][b] = true;
    if (b + 1 < W && S[a][b + 1] == '#' && dfs(a, b + 1)) return K[a][b] = true;
    return K[a][b] = false;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> W;
    rep(i, H) cin >> S[i];
    if(dfs(0, 0)) {
        rep(i, H) {
            rep(j, W) {
                if(S[i][j] == '#' && !K[i][j]) {
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
	int D; cin >> D; 
	int C[30] = {}; 
	for(int i = 1; i <= 26; i++) cin >> C[i]; 
	int S[370][30] = {}; 
	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= 26; j++){
			cin >> S[i][j]; 
		}
	}
	int ans[370] = {}; 
	int L[30] = {}; 
	for(int i = 1; i < D; i+= 2){
		int E[700] = {}; 
		for(int j = 1; j <= 676; j++){
			int p = (j - 1) % 26 + 1; // i日目
			int q = (j - 1) / 26 + 1; // i+1日目
			int M[30] = {}; 
			for(int k = 1; k <= 26; k++){
				M[k] = L[k]; 
			}
			E[j] += S[i][p] + C[p] * (i - M[p]) * 13; 
			M[p] = i; 
			E[j] += S[i+1][q] + C[q] * (i + 1 - M[q]) * 13;
		}
		int a = 0; int mx = -1145141919; 
		for(int j = 1; j <= 676; j++){
			if(E[j] > mx){
				a = j; mx = E[j]; 
			}
		}
		ans[i] = (a-1) % 26 + 1; ans[i+1] = (a-1) / 26 + 1; 
		L[(a-1) % 26 + 1] = i; L[(a-1) / 26 + 1] = i + 1; 
	}
	for(int i = D; i <= D; i++){
		int E[30] = {}; 
		for(int j = 1; j <= 26; j++){
			E[j] = S[i][j] + C[j] * (i - L[j]); 
		}
		int a = 0; int mx = -1145141919; 
		for(int j = 1; j <= 26; j++){
			if(E[j] > mx){
				a = j; mx = E[j]; 
			}
		}
		ans[i] = a; L[a] = i; 
	}
	for(int i = 1; i <= D; i++) cout << ans[i] << endl; 
}

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

class Rect
{
public:
  int pos, height;
  Rect(int _pos, int _height)
    :pos(_pos), height(_height) {}
};

int main()
{
  int H, W;
  while (cin >> H >> W) {
    if ((H|W) == 0)
      break;

    vector<string> rec(H);
    for (int i = 0; i < H; ++i)
      cin >> rec[i];

    vector<vector<int> > dp(H, vector<int>(W+1, 0));
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
	if (rec[i][j] == '*')
	  continue;
	if (i == 0)
	  dp[i][j] = 1;
	else
	  dp[i][j] = dp[i-1][j]+1;
      }
    }

    int ans = 0;
    for (int i = 0; i < H; ++i) {
      stack<Rect> stk;
      for (int j = 0; j <= W; ++j) {
	if (stk.empty()) {
	  stk.push(Rect(j, dp[i][j]));
	} else {
	  if (stk.top().height < dp[i][j]) {
	    stk.push(Rect(j, dp[i][j]));
	  } else if (stk.top().height > dp[i][j]) {
	    int pos = j;
	    while (!stk.empty() && stk.top().height > dp[i][j]) {
	      const Rect rec = stk.top();
	      stk.pop();
	      ans = max(ans, rec.height * (j-rec.pos));
	      pos = rec.pos;
	    }
	    stk.push(Rect(pos, dp[i][j]));
	  }
	}
      }
    }

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

Measured memory_bytes: 0
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
 
const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
 
ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll a;
ll b;
int main(){
	migmig;
	cin >> a >>b;
	if (a * b <= 0){
		cout << "Zero";
	}else{
		if (a > 0 ){
			cout << "Positive";	
		}else{
			if((abs(b-a)+1)%2 == 0){
				cout<<"Positive";
			}else cout<<"Negative";
		}
	}
}
 

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
using namespace std;
int N;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,1,-1};
main()
{
	while(cin>>N,N)
	{
		string start="";
		for(int i=0;i<N;i++)
		{
			string input;cin>>input;start+=input;
		}
		map<string,int>M;
		M[start]=0;
		queue<string>P;
		P.push(start);
		int ans=-1;
		while(!P.empty())
		{
			string now=P.front();P.pop();
			int cost=M[now];
			int sx,sy;
			int cnt=0;
			for(int i=0;i<N*N;i++)
			{
				if(now[i]=='@')sx=i/N,sy=i%N;
				if(now[i]=='#')cnt++;
			}
			if(cnt==0)
			{
				ans=cost;
				break;
			}
			for(int r=0;r<8;r++)
			{
				int tx=sx+dx[r],ty=sy+dy[r];
				if(tx<0||ty<0||tx>=N||ty>=N||now[tx*N+ty]=='#')continue;
				string tmp=now;
				tmp[sx*N+sy]='.';
				tmp[tx*N+ty]='@';
				string nxt=tmp;
				for(int x=0;x<N;x++)for(int y=0;y<N;y++)
				{
					if(nxt[x*N+y]=='@')continue;
					int cnt=0;
					for(int r=0;r<8;r++)
					{
						int xx=x+dx[r],yy=y+dy[r];
						if(0<=xx&&xx<N&&0<=yy&&yy<N&&tmp[xx*N+yy]!='.')cnt++;
					}
					if(tmp[x*N+y]=='#'?2<=cnt&&cnt<=3:cnt==3)nxt[x*N+y]='#';
					else nxt[x*N+y]='.';
				}
				if(M.find(nxt)==M.end())
				{
					M[nxt]=cost+1;
					P.push(nxt);
				}
			}
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 7184
#include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
    cin >> a >> b;
    reverse(a.begin(), a.end());
    if (a == b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define inf (ll)1e9

#define debugone(x) cout << #x << " " << x << "\n"; cout.flush();
#define debugtwo(x) cout << #x << "-------------" << "\n";for(auto &it: x) cout << it << " ";cout << "\n"; cout.flush();
#define debugthree(x, i, j) cout << #x << "------------" << "\n";cout << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cout << x[k] << " ";cout << "\n"; cout.flush();



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
		
	string s;
	cin >> s;
	int cnt0 = 0;
	int cnt1 = 0;
	for(int i=0; i<(int)s.length(); i++){

		if(i%2 == 0 && s[i] == '1') cnt0++;

		if(i%2 == 1 && s[i] == '0') cnt0++;
	}


	for(int i=0; i<(int)s.length(); i++){

		if(i%2 == 0 && s[i] == '0') cnt1++;

		if(i%2 == 1 && s[i] == '1') cnt1++;
	}


	cout << min(cnt1, cnt0) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
    
    int x=1;
    int y=1;
    
    while(1){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            printf("%d %d\n", y ,x);
        }else{
            printf("%d %d\n", x ,y);
        }
        
    }
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli uf[100001], size[100001];
lli n, m;
using P = pair<lli, lli>;
P e[100001];

lli root(lli i) { return i == uf[i] ? i : uf[i] = root(uf[i]); }
void unite(lli i, lli j) {
  lli ri = root(i), rj = root(j);
  lli a = max(ri, rj), b = min(ri, rj);
  uf[b] = a;
  size[a] += size[b];
  size[b] = 0;
}
bool same(lli i, lli j) { return root(i) == root(j); }

int main() {
  cin >> n >> m;
  for (lli i=0; i<m; ++i) {
    cin >> e[i].first >> e[i].second;
  }

  for (lli i=1; i<=n; ++i) {
    uf[i] = i;
    size[i] = 1;
  }

  lli scr = n*(n-1)/2;
  vector<lli> res;
  res.push_back(scr);
  for (lli i=m-1; i>0; --i) {
    lli u = e[i].first, v = e[i].second;
    
    if (!same(u, v)) {
      lli su = size[root(u)], sv = size[root(v)];
      scr -= su * sv;

      unite(u, v);
    }

    res.push_back(scr);
  }

  while (!res.empty()) {
    cout << res.back() << '\n';
    res.pop_back();
  }
  return 0;
}


Measured memory_bytes: 5364
n, m = map(int, input().split())
a = [None] * n
for i in range(n):
    a[i] = tuple(map(int, input().split()))
b = [None] * m
for i in range(m):
    b[i] = tuple(map(int, input().split()))
for x, y in a:
    z = None
    k = None
    for i in range(m):
        c, d = b[i]
        d = abs(x - c) + abs(y - d)
        if z is None or d < z:
            z = d
            k = i
    print(k + 1)


Measured memory_bytes: 3064
n = int(input())

ans = 0

for i in range(1,n):
    for j in range(i, n):
        if n - i*j < 0:
            break

        if n - i*j > 0 and i == j:
            ans += 1
        elif n - i*j >0 and i != j:
            ans += 2

print(ans)


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

int main() {
	int k, s, res = 0;
	cin >> k >> s;
	for (int x = 0;x <= k;x++) {
		for (int y = 0;y <= k;y++) {
			int z = s - x - y;
			if (0 <= z && z <= k)res++;
		}
	}
	cout << res << endl;
}

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

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

	int time[n];

	for(int i = 0; i < n; ++i){
		scanf("%d", &time[i]);
	}

	cin >> m;

	int drink[m][2];

	for(int i = 0; i < m; ++i){
		scanf("%d%d", &drink[i][0], &drink[i][1]);
	}

	int add = 0;

	for(int i = 0; i < n; ++i){
		add += time[i];
	}

	for(int i = 0; i < m; ++i){
		cout << add + drink[i][1] - time[drink[i][0] - 1] << "\n";
	}	

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define MOD          1000000007 //10^9 + 7
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    // while(cin>>n){}
    cin>>n>>k;
    ans=k*pow((k-1),n-1);
    cout<<ans<<endl;
    return 0;
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main(){

  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  SORT(v);

  int ans = 0;
  rep(i, n){
    if(abs(v[n-1] - 2 * ans) > abs(v[n-1] - 2 * v[i])) ans = v[i];
  }

  cout << v[n-1] << " " << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll com(ll N,ll R){
    if(R<0 || R>N) return 0;
    if(R==1) return N;
    else if(R==2) return N*(N-1)/2;
    else return N*(N-1)*(N-2)/6;
}

ll pow(ll N,ll k){
    ll res=1;
    rep(i,k) res*=N;
    return res; 
}

string S;
int N,K;

ll solve(int i,int k,int smaller){
    if(i==N){
        if(k==0) return 1;
        else return 0;
    }
    if(k==0) return 1;

    if(smaller) return com(N-i,k)*pow(9,k);
    else{
        if(S[i]=='0') return solve(i+1,k,false);
        else{
            ll zero=solve(i+1,k,true);
            ll aida=solve(i+1,k-1,true)*(S[i]-'1');
            ll icchi=solve(i+1,k-1,false);
            return zero+aida+icchi;
        }
    }
}

int main(){
    cin>>S>>K;
    N=S.size();
    cout<<solve(0,K,false)<<endl;
}

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

using namespace std;
int main(){
    int t;
    scanf("%d",&t);
    if(t%10==7||(t/10)%10==7||(t/100)%10==7)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (1) {
		ll h, w; cin >> h >> w;
		if (h == 0 && w == 0) break;
		rep(i, h) {
			rep(j, w) {
				if ((i+j)%2==0)	cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3180
def examA():
    S = SI()
    F = "FESTIVAL"
    ans = S[:-(len(F))]
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 3440
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 1000;
const int MAXW = 10000;

int val[MAXN],weight[MAXN];
int dp[MAXN][MAXW];
// dp[i][w] .. i番目までを重さwで行った時の最大の価値
// dp[i+1][w] =
//   max(dp[i][w-weight[i+1]] + val[i+1] , dp[i][w])
int main(){
  int N,W,casenum = 1;
  while(scanf("%d",&W) && W != 0){
    //input
    fill(*dp,*(dp+MAXN),0);
    scanf("%d",&N);
    for(int i = 0;i < N;i++){
      scanf("%d,%d",val+i,weight+i);
    }
    ///
    
    ///solve
    for(int i = 0; i < N;i++){
      for(int w = 0;w < W+1;w++){
        int use = (w - weight[i] >= 0
                   ? dp[i][w - weight[i]] + val[i]
                   : 0);
        int unuse = dp[i][w];
        dp[i+1][w] = max(use,unuse);
      }
    }
    
    //
    printf("Case %d:\n",casenum);
    for(int w = 0;w <= W;w++){
      if(dp[N][w] == dp[N][W]){
        printf("%d\n%d\n",dp[N][w],w);
        break;
      }
    }
    casenum++;
  }
}

Measured memory_bytes: 40240
#include<iostream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;
 
typedef long long int ll;

const ll INF=(ll)1e18;

int A,B,C,D,E,F;

int main(){
    cin >> A >> B >> C >> D >> E >> F;

    double lim = (double)E / (100+E);

    double m = 0.0;
    int ans_sw = 0;
    int ans_s = 0;
    REP(i,31){
        REP(j,31){
            if(i == 0 && j == 0)continue;

            if((i*A+j*B)*100 > F)break;


            REP(k,3000){
                REP(l,3000){
                    if(k*C+l*D+100*i*A+100*j*B > F)break;

                    double tmp = (double)(k*C+l*D) / (k*C+l*D+(i*A+j*B)*100);
                    if(lim < tmp)continue;

                    if(m<tmp){
                        m = tmp;
                        ans_sw = k*C+l*D+(i*A+j*B)*100;
                        ans_s = k*C+l*D;
                    }
                }
            }
        }
    }
    if(ans_sw > 0){
        cout << ans_sw << " " << ans_s << endl;
    }else{
        cout << A*100 << " " << 0 << endl;
    }
}



Measured memory_bytes: 768
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n;

main(){
	cin>>n;
	int a[n];rep(i,n)cin>>a[i];sort(a,a+n);
	int sum=0;
	rep(i,n-1)sum+=a[i];
	if(sum>a[n-1])dump("Yes");
	else dump("No");
}


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

int main() {
  int N;
  cin >> N;
  long long int a[3 * N];
  for (int i = 0; i < 3 * N; i++) cin >> a[i];
  sort(a, a + 3 * N, greater<long long>());
  long long int sum = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 1) sum += a[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.util.ArrayList;

public class Main{
	public static void main(String[] args){

		// 値取得
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		ArrayList<String> strodd = new ArrayList<>();
		ArrayList<String> streve = new ArrayList<>();

		// System.out.println(str);
	 	// 奇数・偶数文字切り分け
		for(int i=1;i<=str.length();i++){

			if( i % 2 == 0){
				//偶数
				streve.add(str.substring(i-1,i));

			}else{
				// 奇数
				strodd.add(str.substring(i-1,i));
				// System.out.println(strodd.get(i-1));				
			}
		}

		
		boolean abc = true;
		boolean abd = true;
		for(int k = 0;k<strodd.size();k++ ){
			// System.out.println(strodd.get(k));
			if(!(strodd.get(k).contains("R") || strodd.get(k).contains("U") || strodd.get(k).contains("D"))){
				abc = false;
			}
		}

		for(int l = 0;l<streve.size();l++ ){
			// System.out.println(streve.get(l));
			if(!(streve.get(l).contains("L") || streve.get(l).contains("U") || streve.get(l).contains("D"))){
				abd = false;
			}
		}


		if(abc && abd){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
int INF = 10000000;
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> p(M), q(M), c(M);
	for (int i = 0; i < M; i++){
		cin >> p[i] >> q[i] >> c[i];
		p[i]--;
		q[i]--;
	}
	vector<int> cv = c;
	sort(cv.begin(), cv.end());
	cv.erase(unique(cv.begin(), cv.end()), cv.end());
	int cnt = cv.size();
	map<int, int> mp;
	for (int i = 0; i < cnt; i++){
		mp[cv[i]] = i;
	}
	for (int i = 0; i < M; i++){
		c[i] = mp[c[i]];
	}
	vector<vector<int>> edges(cnt);
	for (int i = 0; i < M; i++){
		edges[c[i]].push_back(i);
	}
	vector<vector<int>> E(N);
	for (int i = 0; i < cnt; i++){
		vector<int> v_id;
		for (int j : edges[i]){
			v_id.push_back(p[j]);
			v_id.push_back(q[j]);
		}
		sort(v_id.begin(), v_id.end());
		v_id.erase(unique(v_id.begin(), v_id.end()), v_id.end());
		int v_cnt = v_id.size();
		map<int, int> mp2;
		for (int j = 0; j < v_cnt; j++){
			mp2[v_id[j]] = j;
		}
		vector<vector<int>> E2(v_cnt);
		for (int j : edges[i]){
			E2[mp2[p[j]]].push_back(mp2[q[j]]);
			E2[mp2[q[j]]].push_back(mp2[p[j]]);
		}
		vector<bool> used(v_cnt, false);
		for (int j = 0; j < v_cnt; j++){
			if (!used[j]){
				used[j] = true;
				vector<int> cc;
				cc.push_back(j);
				queue<int> Q;
				Q.push(j);
				while (!Q.empty()){
					int v = Q.front();
					Q.pop();
					for (int w : E2[v]){
						if (!used[w]){
							used[w] = true;
							cc.push_back(w);
							Q.push(w);
						}
					}
				}
				int V = E.size();
				E.push_back(vector<int>());
				for (int v : cc){
					E[v_id[v]].push_back(V);
					E[V].push_back(v_id[v]);
				}
			}
		}
	}
	int V = E.size();
	vector<int> d(V, INF);
	d[0] = 0;
	queue<int> Q;
	Q.push(0);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (d[w] == INF){
				d[w] = d[v] + 1;
				Q.push(w);
			}
		}
	}
	if (d[N - 1] == INF){
		cout << -1 << endl;
	} else {
		cout << d[N - 1] / 2 << endl;
	}
}

Measured memory_bytes: 43432
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


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

    int absmin=10000,sum=0,MIN=0;

    rep2(i,1,n){
        sum+=l+i-1;
        if(absmin>abs(l+i-1)){
            absmin=abs(l+i-1);
            MIN=l+i-1;
        }
    }

    cout<<sum-MIN<<endl;
}






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

int main() {
	int L;
	cin >> L;
	vector<tuple<int,int, int>>Ans;
	int N = 2;
	int pow = 1;
	Ans.push_back(make_tuple(N-1,N,0)); 
	Ans.push_back(make_tuple(N - 1, N, pow));
	while (pow*4 -1 < L ) {
		pow *= 2;
		N++;
		Ans.push_back(make_tuple(N - 1, N, 0));
		Ans.push_back(make_tuple(N - 1, N, pow));
	}
	L--;
	int now = pow * 2 - 1;
	while (L != now) {
		int num = now + 1;
		int powsub = 1;
		int count = 0;
		while ((powsub * 2 - 1) + num <= L) {
			powsub *= 2;
			count++;
		}
		Ans.push_back(make_tuple(1 + count,N, num));
		now = num + powsub - 1; 
	}
	cout << N<<" "<<Ans.size()<<endl;
	for (int n = 0;n<Ans.size();++n) {
		cout << get<0>(Ans[n]) << " "<<get<1>(Ans[n]) << " "<<get<2>(Ans[n]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,m,i,ans=0;
    cin >> n >> m;
    vector<int> x(m);
    for(i=0;i<m;i++) cin >> x.at(i);
    if(n>=m){
        cout << "0" << endl;
        return 0;
    }
    sort(x.begin(),x.end());
    vector<int> dis(m-1);
    for(i=0;i<m-1;i++) dis.at(i) = x.at(i+1)-x.at(i);
    sort(dis.begin(),dis.end());
    for(i=0;i<n-1;i++){
        ans += dis.at(m-2-i);
    }
    cout << x.at(m-1)-x.at(0)-ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	int arr[N];
	for(int i = 0; i < N; i++) {
		int index;
		cin >> index;
		arr[index - 1] = i;
	}
	for(int i =0; i < N; i++) cout << arr[i] + 1 << " ";

	return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        for(int i = 0; i < 26; i++){
            if(str.indexOf(String.valueOf((char)('a' + i))) == -1){
                System.out.println((char)('a' + i));
                return;
            }
        }
        System.out.println("None");
    }
}


Measured memory_bytes: 23892
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		String nn = sc.next();
		char[] n = new StringBuilder(nn).reverse().append(0).toString().toCharArray();

		int[][] dp = new int[n.length + 1][2];
		for (int i = 0; i < dp.length; i++) {
			Arrays.fill(dp[i], 100000000);
		}
		dp[0][0] = 0;
		for (int i = 0; i < n.length; i++) {
			for (int j = 0; j < 2; j++) {
				int x = Integer.parseInt(String.valueOf(n[i]));
				x += j;
				for (int a = 0; a < 10; a++) {
					int b = a - x;
					if (b < 0) {
						b += 10;
						dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][j] + a + b);
					} else {
						dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][j] + a + b);
					}
				}
			}
		}

		System.out.println(dp[n.length][0]);
	}
}


Measured memory_bytes: 105352
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		for(int i=0; i<N;i++) {
			X[i]=sc.nextInt();
		}
		int[] Y = X.clone();
		Arrays.sort(Y);
		int k = Y[N/2-1];
		int g = Y[N/2];
		for(int i=0;i<N;i++) {
			if(X[i]<=k) {
				System.out.println(g);
			}else{
				System.out.println(k);
			}
		}
	}
}

Measured memory_bytes: 87812
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n, m, t;
	cin >> n >> m >> t;
	vector<string> d(n);
	for (int i = 0; i < n; i++)
		cin >> d[i];

	int ans = 0;

	for (int k = 0; k < (1 << n); k++) {
		for (int l = 0; l < (1 << m); l++) {
			int o = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					int b1 = ((k >> i) & 1);
					int b2 = ((l >> j) & 1);
					if (!b1 && !b2 && d[i][j] == '#')
						o++;
				}
			}
			if (o == t)
				ans++;
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int cnt = 0;
		for (int i=0; i<N; i++) {
			int num = sc.nextInt();
			if (num<A || B<=num) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}

}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

int H, W;

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

  while(cin >> W >> H,W){
  int N;
  cin >> N;
  vector<pair<PII,PII>> ps(N);
  {
	set<int> xs, ys;
	REP(i,N){
	  cin >> ps[i].FF >> ps[i].SS;
	  
	  FOR(d,-1,1){
		if(0 <= ps[i].FF.FF+d && ps[i].FF.FF+d <= W)
		  xs.insert(ps[i].FF.FF + d);
		if(0 <= ps[i].FF.SS+d && ps[i].FF.SS+d <= H)
		  ys.insert(ps[i].FF.SS + d);
	  }
	  FOR(d,0,2){
		if(0 <= ps[i].SS.FF+d && ps[i].SS.FF+d <= W)
		  xs.insert(ps[i].SS.FF + d);
		if(0 <= ps[i].SS.SS+d && ps[i].SS.SS+d <= H)
		  ys.insert(ps[i].SS.SS + d);
	  }
	}
	
	xs.insert(0);
	xs.insert(W-1);
	xs.insert(W);
	ys.insert(0);
	ys.insert(H-1);
	ys.insert(H);
	
  
	map<int,int> xs2ix, ys2ix;
	int it = 0;
	for(int x: xs){
	  xs2ix[x] = it++;
	}
	it = 0;
	for(int y: ys){
	  ys2ix[y] = it++;
	}

	W = SZ(xs);
	H = SZ(ys);
	for(auto& p: ps){
	  p.FF.FF = xs2ix[p.FF.FF];
	  p.SS.FF = xs2ix[p.SS.FF];
	  p.FF.SS = ys2ix[p.FF.SS];
	  p.SS.SS = ys2ix[p.SS.SS];
	}
  }

  vector<vector<short>> acc(H+1, vector<short>(W+1));
  for(auto& p: ps){
	acc[p.FF.SS][p.FF.FF]++;
	acc[p.SS.SS][p.SS.FF]++;
	acc[p.FF.SS][p.SS.FF]--;
	acc[p.SS.SS][p.FF.FF]--;
  }

  REP(y,H+1) REP(x,W+1){
	acc[y][x] += (y>0? acc[y-1][x]: 0) + (x>0? acc[y][x-1]: 0) - (y>0&&x>0?acc[y-1][x-1]: 0);
  }

  int ans = 0;
  REP(y,H-1) REP(x,W-1){
	if(!acc[y][x]){
	  ++ans;

	  queue<PII> q;
	  q.push(MP(x,y));
	  while(!q.empty()){
		PII p = q.front();
		q.pop();
		REP(d,4){
		  PII np(p.FF + dx[d], p.SS + dy[d]);
		  if(np.FF < 0 || W-1 <= np.FF || np.SS < 0 || H-1 <= np.SS) continue;
		  if(!acc[np.SS][np.FF]){
			acc[np.SS][np.FF] = 1;
			q.push(np);
		  }
		}
	  }
	}
  }
  cout << ans << endl;
}

  return 0;
}



Measured memory_bytes: 4924
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


def resolve():
    n, k = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    div = make_divisors(sum(A))
    res = 1
    for x in div:
        B = sorted([a % x for a in A])
        M, P = [0], [0]
        for i in range(n):
            M.append(M[-1] + B[i])
            P.append(P[-1] + x - B[i])
        M.pop(0)
        P.pop(0)
        for i in range(n - 1):
            m = M[i]
            p = P[n - 1] - P[i]
            if m <= k and p <= k and m % x == p % x:
                res = max(res, x)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9472
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	/** 奇数文字の一覧 */
	private static final List<Character> EVEN_LIST = Arrays.asList('R', 'U', 'D');
	/** 偶数文字の一覧 */
	private static final List<Character> ODD_LIST = Arrays.asList('L', 'U', 'D');

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			boolean result = true;
			for (int i = 0; i < s.length; i++) {
				if (1 == (i & 1)) {
					// 0-indexのため、偶数文字
					if (!ODD_LIST.contains(s[i])) {
						result = false;
						break;
					}
				} else {
					if (!EVEN_LIST.contains(s[i])) {
						result = false;
						break;
					}
				}
			}
			System.out.println(result ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s >> t){
        ll t_start = -1;
        rep(i, s.size() - t.size() + 1){
            bool flag = true;
            rep(j, t.size()){
                if((s[i + j] != t[j]) && (s[i + j] != '?')){
                    flag = false;
                    break;
                }
            }
            if(flag){
                t_start = i;
            }
        }
        if(t_start == -1){
            print("UNRESTORABLE");
            continue;
        }
        rep(i, s.size()){
            if((i >= t_start) && (i < t_start + t.size())){
                out(t[i - t_start]);
            }else{
                out(((s[i] == '?') ? 'a' : s[i]));
            }
        }
        out('\n');
    }
}

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

typedef long long ll;

ll N, M;
vector<vector<pair<ll, ll>>> Out;
vector<ll> Pos;
const ll INF = 1ll << 60;

void dfs(ll v, ll pos) {
  Pos[v] = pos;
  for (auto wd : Out[v]) {
    ll w = wd.first, d = wd.second;
    if (Pos[w] == INF) dfs(w, pos + d);
  }
}
bool check() {
  for (ll v = 0; v < N; ++v) {
    for (auto wd : Out[v]) {
      ll w = wd.first, d = wd.second;
      if (Pos[w] != Pos[v] + d) return false;
    }
  }
  return true;
}
int main() {
  cin >> N >> M;
  Out.resize(N);
  for (ll i = 0; i < M; ++i) {
    ll l, r, d;
    cin >> l >> r >> d;
    --l;
    --r;
    Out[l].push_back(make_pair(r, d));
    Out[r].push_back(make_pair(l, -d));
  }
  Pos.resize(N, INF);
  for (ll v = 0; v < N; ++v) {
    if (Pos[v] == INF) dfs(v, 0);
  }
  cout << (check() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 200000
#define EPS 1e-9

int n;
lli c[20][20];

int main(void){
    cin >> n;
    lli ans = 0;
    rep(i, 20) rep(j, 20) c[i][j] = 0;
    rep(i, n){
        string x;
        lli y;
        cin >> x;
        if(x.find(".") == string::npos) y = stoll(x)*(lli)1e9;
        else{
            int k = x.find(".");
            string s, t;
            s = x.substr(0, k);
            t = x.substr(k+1);
            while(t.size() < 9) t+="0";
            s+=t;
            y = stoll(s);
        }
        lli a, b;
        a = b = 0;
        while(y%2 == 0) y/=2, a++;
        while(y%5 == 0) y/=5, b++;
        a = min(a, 19LL);
        b = min(b, 19LL);
        for(int i = 0; i <= 19; i++){
            for(int j = 0; j <= 19; j++){
                if(i+a >= 18 && j+b >= 18){
                    ans+=c[i][j];
                }
            }
        }
        c[a][b]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <numeric>

using namespace std;

using ll = long long;


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

    vector<ll> A;
    for (auto i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    ll arai = accumulate(A.begin(), A.end(), 0LL);
    ll sunuke = A[0];
    arai -= A[0];
    ll ans = abs(sunuke - arai);
    // cout << "sunuke: " << sunuke << ", arai: " << arai << endl;
    for (auto it = A.begin() + 1; it != A.end() - 1; ++it) {
        sunuke += *it;
        arai -= *it;
        ans = min(ans, abs(sunuke - arai));
        // cout << "sunuke: " << sunuke << ", arai: " << arai << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(LL x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(LL x){write(x);putchar('\n');}
int A,B;
int main()
{
	int T=read();while(T--)
	{
		A=read();B=read();
		if(A>B)swap(A,B);
		if(A==B||A+1==B){pr2(2*A-2);continue;}
		LL C=(LL)sqrt((long double)A*B-1),ans=2*C;
		if(C*(C+1)>=1LL*A*B)ans-=2;
		else ans-=1;
		pr2(ans);
	}
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
//#include<string>

using namespace std;

int main(){
  string S;
  int mn=999,n,i=0;
  cin>>S;
  while(i <=S.size()-3){
    n=(S[i]-'0')*100+(S[i+1]-'0')*10+S[i+2]-'0';
    mn=min(mn,abs(753-n));
    i++;
  }
  cout<<mn<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int num;
  bool flag;

  int n;
  cin >> n;

  // priority_queue<pair<int, int>> q;
  auto compare = [](pair<int, int> l, pair<int, int> r) { return l.second >= r.second; };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(compare)> q(compare);

  for (int i = 0; i < n; ++i)
  {
    int a, b;
    cin >> a >> b;
    // q.emplace(b, a);
    q.emplace(a, b);
  }

  flag = true;
  num = 0;
  while (!q.empty())
  {
    pair<int, int> p = q.top();
    q.pop();
    int a = p.first;
    int b = p.second;

    num += a;
    if (num > b)
      flag = false;
    if (!flag)
      break;
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
}


Measured memory_bytes: 6512
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn sort(i: i32, j: i32, k: i32) -> (i32, i32, i32) {
    if i <= j {
        if j <= k {
            (i, j, k)
        } else {
            if i <= k {
                (i, k, j)
            } else {
                (k, i, j)
            }
        }
    } else {
        if i <= k {
            (j, i, k)
        } else {
            if j <= k {
                (j, k, i)
            } else {
                (k, j, i)
            }
        }
    }
}

fn is_member(a: (i32, i32, i32), v: &Vec<(i32, i32, i32)>) -> bool {
    for x in v {
        if a.0 == x.0 && a.1 == x.1 && a.2 == x.2 {
            return true;
        }
    }
    false
}

fn main() {
    loop {
        let z = read_parameters::<i32>().unwrap();
        let (n, x) = (z[0], z[1]);

        if n == 0 && x == 0 {
            return;
        }

        let mut ans = Vec::new();
        for i in 1..n + 1 {
            for j in i + 1..n + 1 {
                let k = x - (i + j);
                if k >= 1 && k <= n && k != i && k != j {
                    let a = sort(i, j, k);
                    if !is_member(a, &ans) {
                        ans.push(a)
                    }
                }
            }
        }
        println!("{}", ans.len());
    }
}



Measured memory_bytes: 5044
#include <cstdio>
#include <cctype>

int main(){
	int i=0, a[26]={0};
	char ch;
	
	while( scanf("%c", &ch) != EOF ){
		if( isupper(ch) ) 
			ch = tolower(ch);
	
		if('a'<=ch && ch<='z') 
			++a[ ch-'a' ];
	
		++i;
	}

	for(int x=0; x<26; ++x)
		printf("%c : %d\n", 'a'+x, a[x]);

	return 0;
}



Measured memory_bytes: 2604
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <functional>

using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; const int INF=1e9; const ll LINF=1e18;
template<typename T> void caut(T a, T b, T c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T> void caut(T a, T b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}

const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main(){
  int n; cin>>n;
  ll an = 1;
  ll b[n]={}; bool ng=false;
  for(int i=0;i<n;i++) {
    ll a; cin>>a; b[a]++;
    if (i==0&&a!=0) ng=true;
    else if (i!=0&&a==0) ng=true;
  }
  for(int i=0;i<n-1;i++) {
    an *= mod_pow(b[i], b[i+1]);
    an %= M;
  }
  if (ng) an=0;
  cout<<an<<endl;
}


Measured memory_bytes: 1024