akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# input
s = input()
t = input()
ls = len(s)
lt = len(t)
ans = 0
# calc
for i in range(ls, lt-1, -1):
    temp = s[i-lt:i]
    # print(temp)
    counter = 0
    for j in range(lt-1, -1, -1):
        if t[j] == temp[j] or temp[j] == '?':
            counter += 1
            # print(j)
            # print(temp[j])
    if counter == lt:
        ans = i
        break
# output
if ans == 0:
    print('UNRESTORABLE')
else:
    print((s[:ans-lt]+t+s[ans:]).replace('?', 'a'))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;

int main(){
	ll a,b,c,m;
	cin >> a >> b >> c;
	m = max({a,b,c});
	if(m==a){
		cout << "A" << endl;
	}else if(m==b){
		cout << "B" << endl;
	}else if(m==c){
		cout << "C" << endl;
	}
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define ll long long
#define MOD 1000000007

ll N, K, s[60], dp[60][2];
int main() {
	cin >> N >> K;
	REP(i, N) {
		ll a; cin >> a;
		REP(j, 50) if (a & (1ll << j))s[j]++;
	}
	reverse(s, s + 50);
	REP(i, 50) {
		if (K & (1ll << 50 - i - 1)) {
			dp[i + 1][0] = dp[i][0] * 2 + N - s[i];
			dp[i + 1][1] = dp[i][0] * 2 + s[i];
		}
		else dp[i + 1][0] = dp[i][0] * 2 + s[i];
		if(dp[i][1] > 0)dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] * 2 + max(N - s[i], s[i]));
	}
	cout << max(dp[50][0], dp[50][1]) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;

int N;
ll a[105];

int broken[105];
ll dfs(int v) {
    if (v >= min(35, N)) {
        ll ret = 0;
        for (int j = v; j <= N; ++j) {
            if (j % 2 == 0 && j / 2 >= v) continue;
            if (broken[j] == 0) {
                if (2*j > N || broken[2*j] > 0) {
                    ret += max(0LL, a[j]);
                } else {
                    ret += max(0LL, max(a[j], a[j]+a[2*j]));
                }
            }
        }
        return ret;
    }

    if (broken[v] > 0) return dfs(v+1);

    // nope
    ll ans = a[v] + dfs(v+1);

    // break
    for (int w = v; w <= N; w += v) {
        broken[w]++;
    }
    ans = max(ans, dfs(v+1));
    for (int w = v; w <= N; w += v) {
        broken[w]--;
    }

    return ans;
}

int main() {
    fill(broken, broken+105, 0);
    cin >> N;
    for (int j = 1; j <= N; ++j) cin >> a[j];
    cout << dfs(1) << endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define INF 100000

using namespace std;

void dijkstra(int);
vector<int>get_path(int);

int V,prev[1001];
double cost[1001][1001],d[1001];
bool used[1001];

int main(void){

  int b[1001],m,s,g;
  double x[1001],y[1001];

  while(cin >> V,V){
    for(int i=0;i<V;i++)
      cin >> b[i] >> x[i] >> y[i];
    
    for(int i=0;i<=V;i++)
      for(int j=0;j<=V;j++)
	cost[i][j]=INF;

    for(int i=0;i<V;i++){
      for(int j=0;j<V;j++){
	if(i!=j){
	  double a=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
	  if(50.>=a)cost[b[i]][b[j]]=cost[b[j]][b[i]]=a;
	}
      }
    }
    
    cin >> m;
    for(int i=0;i<m;i++){
      cin>> s >> g;
      
	dijkstra(s);

	if(used[g]){

	  vector<int>p=get_path(g);

	  for(int j=0;j<p.size();j++){
	    cout << p[j];

	    if(j<p.size()-1)cout <<" ";
	    else cout << endl;
	  }
	}
	else cout << "NA" << endl; 
    }
  }
  
  return 0;
}

void dijkstra(int s){
  fill(d,d+V+1,INF);
  fill(used,used+V+1,false);
  fill(prev,prev+V+1,-1);
  d[s]=0;

  while(true){
    int v=-1;
    for(int u=1;u<=V;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }

    if(v==-1 || d[v]==INF)break;
    used[v]=true;

    for(int u=1;u<=V;u++){
      if(d[u]>d[v]+cost[v][u]){
	d[u]=d[v]+cost[v][u];
	prev[u]=v;
      }
    }
  }
}

vector<int>get_path(int t){
  vector<int>path;
  for(;t!=-1;t=prev[t])path.push_back(t);
  reverse(path.begin(),path.end());
  return path;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<String> list=new ArrayList<String>();
		//int[] array = new int[1000000000*2];
		int n = sc.nextInt();
		int k = sc.nextInt();
		final String base36 = Integer.toString(n, k);
		List<String> list=new ArrayList<String>(Arrays.asList(base36.split("")));
		System.out.println(list.size());
	}
}

Measured memory_bytes: 23252
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 110000
#define LL long long
using namespace std;
struct node{int y,nex;}a[2*N];
int fir[N],len,n,m,cnt,u,v,o,num,f[N],g[N],c[N],A[N];
LL ans;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		if(c[y]==0)
		{
			c[y]=-c[x];
			dfs(y,x);
		}
		else
		{
			u=x;v=y;
			if(c[x]==c[y]) o=1;
			else o=0;
		}
	}
}
void dp(int x,int fa)
{
	f[x]=c[x];
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa || (x==u && y==v) || (x==v && y==u)) continue;
		dp(y,x);
		f[x]+=f[y];
		g[x]+=g[y];
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	c[1]=1;
	dfs(1,0);
	if(m==n-1)
	{
		dp(1,0);
		if(f[1]) {printf("-1\n");return 0;}
		for(int i=1;i<=n;i++) ans+=abs(f[i]);
		printf("%lld\n",ans);
	}
	else if(o==1)
	{
		dp(1,0);
		if(f[1]%2) {printf("-1\n");return 0;}
		int t=f[1];
		c[u]-=t/2;c[v]-=t/2;ans=abs(t/2);
		dp(1,0);
		for(int i=1;i<=n;i++) ans+=abs(f[i]);
		printf("%lld\n",ans);
	}
	else
	{
		g[u]++;g[v]--;
		dp(1,0);
		if(f[1]) {printf("-1\n");return 0;}
		for(int i=1;i<=n;i++)
			if(g[i]==0) ans+=abs(f[i]);
			else if(g[i]==1) A[++num]=-f[i];
			else A[++num]=f[i];
		A[++num]=0;
		sort(A+1,A+num+1);
		int t=A[(num+1)/2];
		for(int i=1;i<=num;i++) ans+=abs(t-A[i]);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 8448
S = gets.chomp.split("").map(&:to_i)
tmp = []
abs = []
S.each do |s|
  tmp << s
  if tmp.length == 3
    abs << (753 - (tmp[0] * 100 + tmp[1] * 10 + tmp[2])).abs
    tmp.shift
  end
end
puts abs.min

Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
	int j,t,jt;
	
	scanf("%d %d %d", &j, &t, &jt);
	
	if (jt == 1) printf("Open\n");
	
	else if (j == 0 || t == 0) printf("Close\n");
	
	else if (j == 1 && t == 1) printf("Open\n");
	
	return (0);
}

Measured memory_bytes: 584
# -*- coding: utf-8 -*-

s = input()

# ああ､これだと全部aのケースとかもYesになっちゃうからダメ｡
# if 'a' in s and 'a' in s and 'c' in s:
#     print('Yes')
# else:
#     print('No')


if s.count('a') and s.count('b') and s.count('c'):
    print('Yes')
else:
    print('No')

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

struct Dataset{
	int year;
	int month;
	int day;
};

int main(){
	int n;
	cin>>n;
	struct Dataset *D;
	D = new struct Dataset[n];
	for(int i=0; i<n; i++){
		cin>>D[i].year>>D[i].month>>D[i].day;
	}
	int pre = (999*((19*5)+(20*5)))+(5*(999/3))+1;
	for(int i=0; i<n; i++){
		int sum=0;
		if(D[i].year%3==0){
			sum += ((D[i].year-1)*((19*5)+(20*5)))+(5*((D[i].year-1)/3))+((D[i].month-1)*20)+D[i].day;
		}
		else{
			sum += ((D[i].year-1)*((19*5)+(20*5)))+(5*((D[i].year-1)/3))+((D[i].month-1)*19)+((D[i].month)/2)+D[i].day;
		}

		int ans = pre - sum;

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main() {
	int num, choice;
	cin >> num >> choice;
	vector<int> vec(num);
	for (int n = 0; n < num; n++) {
		cin >> vec[n];
	}
	sort(vec.begin(), vec.end());
	int min_diff = INT_MAX;
	for (int n = 0; n + choice-1 < num; n++) {
		min_diff = min(vec[n + choice-1] - vec[n],min_diff);
	}
	cout << min_diff << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;



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

  if (k < 10){
    cout << k << endl;
    return 0;
  }

  queue<ll> q;
  rep(i, 9) q.push(i+1);
  int cnt = 9;
  while (cnt < k){
    ll v = q.front(); q.pop();
    int r = v % 10;
    v *= 10;
    for(int d=-1;d<=1;d++){
      ll nr = r + d;
      if (nr < 0 or nr > 9) continue;
      nr = nr + v;
      q.push(nr);
      cnt++;
      if (cnt == k) cout << nr << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        String X=sc.next();
        char[] x=X.toCharArray();
        long ans=0;
        long c=0;
        for(int i=0;i<X.length();i++){
              if(x[i]=='T'){
              c--;
              if(c<0){
              ans++;
              c=0;
               }
               }else{
               c++;
               }
        }
        System.out.println(ans+c);
    }
}


Measured memory_bytes: 25936
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String ans="";
		//int c=0;
		
		String s=br.readLine();
		int n=s.length();
		int x=s.charAt(n-1)-'0';
		
		if(x==2 || x==4 || x==5 || x==7 || x==9)
			ans="hon";
		else if(x==0|| x==1 ||x==6 ||x==8)
			ans="pon";
		else
			ans="bon";
		
		out.println(ans);
		
	}
	
	
}




Measured memory_bytes: 32532
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"APPROVED"<<endl;else cout<<"DENIED"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  int n;cin>>n;
  int i=0;
  int a;
  rep(j,n){
    cin>>a;
    if(a%2==0){
      if(a%3!=0&&a%5!=0){
        i++;
      }
    }
  }
  
  Ans(i==0);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c=0;
    cin>>a;
    b=a;
    while(b>0){
        c=c+b%10;
        b=b/10;
    }
    if(a%c==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    ll ans = 0;
    repi(i, 1, n + 1) {
        if(i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3596
h,n=map(int,input().split())
inf=100000000000
dp=[inf]*(h+1)
dp[h]=0
for i in range(n):
    a,b=map(int,input().split())
    for j in range(h,-1,-1):
        dp[max(j-a,0)]=min(dp[max(j-a,0)],dp[j]+b)
print(dp[0])

Measured memory_bytes: 74912
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 1000000 + 9;
int n;
vector<pair<ll,pair<ll,ll>>>a,b,c,d;
 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        ll x,y;
        forr(i,1,n)
        {
            cin>>x>>y;
            a.push_back({x+y,{x,y}});
            b.push_back({x-y,{x,y}});
            c.push_back({-x+y,{x,y}});
            d.push_back({-x-y,{x,y}});
        }

        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        sort(d.begin(),d.end());



        ll ans = abs(a[0].S.F-a[n-1].S.F) + abs(a[0].S.S-a[n-1].S.S);
        ans = max(ans,abs(b[0].S.F-b[n-1].S.F) + abs(b[0].S.S-b[n-1].S.S));
        ans = max(ans,abs(c[0].S.F-c[n-1].S.F) + abs(c[0].S.S-c[n-1].S.S));
        ans = max(ans,abs(d[0].S.F-d[n-1].S.F) + abs(d[0].S.S-d[n-1].S.S));

        cout<<ans<<endl;




return 0;
}


Measured memory_bytes: 22124
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
const int K = 14;

long long a[2002], x;
long long what[2002];
long long st[K][2002], n;

void PreCalc()
{
	for(int i = 0; i < n; i++) st[0][i] = a[i];

	for(int j = 1; j <= K; j++)
		for(int i = 0; i + (1 << j) <= n; i++)
			st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
}

long long Get(int l, int r)
{
	int Length = r - l + 1;
	int k = log2(Length);
	return min(st[k][l], st[k][r - (1 << k) + 1]);
}

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> x;
	for(int i = 0; i < n; i++) cin >> a[i];
	PreCalc();
	for(int k = 1; k <= n; k++)
	{
		long long cur = 0;
		for(int i = 0; i < n; i++)
		{
			if(i + k - 1 >= n) cur += min(Get(i, n - 1), Get(0, (i + k - 1) % n));
			else cur += Get(i, i + k - 1);
		}
		what[k] = cur + x * (k - 1);
	}
	cout << *min_element(what + 1, what + n + 1);
}


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

const int MAXN = 1e5 + 5;
vector<int> sons[MAXN];
int dist[MAXN], pars[MAXN], vist[MAXN];
queue<int> q;

int prop(int s) {
    if(vist[s])
        return dist[s];
    vist[s] = 1;
    for(auto v : sons[s])
        dist[s] = max(dist[s], 1 + prop(v));
    return dist[s];
}

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        sons[x].push_back(y);
        pars[y]++;
    }
    for(int i = 1; i <= n; i++) {
        if(pars[i] == 0)
            prop(i);
    }
    int mx = 0;
    for(int i = 1; i <= n; i++)
        mx = max(mx, dist[i]);
    cout << mx << endl;
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
using namespace std;

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

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

	int N; cin >> N;
	vector<int> a(N,0);
	rep (j, N) cin >> a[j];
	sort(ALL(a), greater<int>());
	
	int check = N - 1;
	rep (i, N-1){
		if(a[i+1] < i+2){
			check = i;
			break;
		} // end if
	} // end rep

	int h = a[check] - check - 1;
	int w = 0;
	for (int i = check + 1; i < N; ++i){
		if (check + 1 != a[i]) break;
		++w;
	} // end for
	if (h % 2 != 0 || w % 2 != 0){
		cout << "First" << endl;
	}else{
		cout << "Second" << endl;
	} // end if

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()


int main() {
	ll n, ans = 0, Min = INF;
	cin >> n;
	for (int i = 0;i < n;i++) {
		ll a, b;
		cin >> a >> b;
		if (a > b)Min = min(Min, b);
		ans += a;
	}
	if (Min == INF)ans = 0;
	else ans -= Min;
	cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    H, W=input().split()
    H=int(H)
    W=int(W)
    a=''
    b=''
    for w in range(W):
        if (w+2)%2==0:
            a+='#'
            b+='.'
        else :
            a+='.'
            b+='#'
    for i in range(H):
        if (i+2)%2==0:
            print(a)
        else :
            print(b)
    if H==0:
        break
    print("")


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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

using ll = long long;

int main() {
    IN(int, n);
    IN(int, m);
    vector<int> a(n,0);
    int k;
    REP(i, m){
        cin >> k;
        a[k-1]++;
        cin >> k;
        a[k-1]++;
    }
    REP(i, n){
        cout << a[i] << endl;
    }
    return 0;
}


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

ll n;
const ll mod = 1000000007;
map<ll,ll> pf;

void prime_factor(ll n){
  for(int i=2;i*i<=n;i++){
    while(n%i==0){
      pf[i]++;
      n/=i;
    }
  }
  if(n!=1)pf[n]++;
}
int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    prime_factor(i);
  }
  ll res=1;
  for(auto v:pf){
    res=res*(v.second+1)%mod;
  }

  cout<<res<<endl;

}


Measured memory_bytes: 256
n=int(input())
c=0
for i in range(2,int(n**0.5)+1):
    d=n
    while d%i==0:
        d//=i
    if n%i==0 and (d-1)%i==0:
        c+=1
for i in range(2,int((n-1)**0.5)+1):
    if (n-1)%i==0:
        if n-1==i**2:
            c+=1
        else:
            c+=2
if n<3:
    print(1)
else:
    print(c+2)

Measured memory_bytes: 3188
import numpy as np
from itertools import combinations

def mark_to_binary(x):
    if x == '.':
        return 0
    elif x == '#':
        return 1
    

H,W,K = map(int,input().split())

image = np.zeros((H,W),dtype='int')

score = 0

for i in range(H):
    row = list(map(mark_to_binary,list(input())))
    image[i] = row
    
for num_row_del in range(H+1):
    for row_idxes in combinations(range(H),num_row_del):
        for num_col_del in range(W+1):
            for col_idxes in combinations(range(W),num_col_del):
                image_del = image.copy()
                image_del[row_idxes,:] = 0
                image_del[:,col_idxes] = 0
                
                if image_del.sum() == K:
                    score += 1
print(score)

Measured memory_bytes: 27216
#include <cstdio>

int main() {
	int n;
	int card[52] = { 0 };

	scanf(" %d", &n);
	for (int i = 0; i < n; ++i) {
		char c;
		int a;
		scanf(" %c %d", &c, &a);

		if (c == 'S') card[a - 1] = 1;
		else if (c == 'H') card[a - 1 + 13] = 1;
		else if (c == 'C') card[a - 1 + 26] = 1;
		else if (c == 'D') card[a - 1 + 39] = 1;
	}

	for (int i = 0; i < 52; ++i) {
		if (card[i] == 0) {
			if (i < 13) printf("S ");
			else if (i < 26) printf("H ");
			else if (i < 39) printf("C ");
			else if (i < 52) printf("D ");

			printf("%d\n", i % 13 + 1);
		}
	}

	return 0;
}


Measured memory_bytes: 2660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,c = 0,a;
  cin >> N;
  int P[N];
  for(int i = 0; i < N; i++){
    cin >> P[i];
  }
  a = P[0];
  for(int j = 0; j < N; j++){
    if(P[j] <= a){
      c++;
      a = P[j];
    }
  }
    cout << c << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
#define Foreach(i,arr) For(i,0,arrlen(arr))
#define Arrin(arr) Foreach(i,arr){cin>>arr[i];}
#define Arrin2(arr1,arr2) Foreach(i,arr1){cin>>arr1[i]>>arr2[i];}
#define Arrin3(arr1,arr2,arr3) Foreach(i,arr1){cin>>arr1[i]>>arr2[i]>>arr3[i];}
	
int main(){
	int N,K;
	cin >> N >> K;
	
	double sump=0;
	For(i,1,N+1){ // サイコロの目がi
		int times=max((int)ceil(log2((double)K/i)),0);
		sump+=(double)pow(0.5,times);
		//cout << i << ":" << times << ":" << (double)pow(0.5,times)<< endl;
	}
	printf("%1.12f",sump/N);
	//cout << (double)sump/N;
}

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

int n,cnt;
string str, tmp;

int main(){
	while(cin >> n){
		if(n == 0) break;
		cin >> str;
		for(int i = 0; i < n; i++){
			cnt = 0;
			tmp.clear();
			if(str.size() == 1){
				tmp.push_back('1');
				tmp.push_back(str[0]);
				str = tmp;
				continue;
			}
			for(int j = 0; j < str.size(); j++){
				if(j == 0){
					cnt++;
					continue;
				}
				if(str[j] != str[j-1]){
					stringstream ss;
					ss << cnt;
					tmp += ss.str();
					tmp.push_back(str[j-1]);
					cnt = 1;
				} else{
					cnt++;
				}
				if(j == str.size()-1){
					stringstream ss;
					ss << cnt;
					tmp += ss.str();
					tmp.push_back(str[j]);
				}
			}
			str = tmp;
		}
		cout << str << endl;
	}
}

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

struct xy{
  int x;
  int y;
  xy(int xx,int yy):x(xx),y(yy){}
};

struct Aset{
  xy ld,ru;
  bool flg;
  Aset():ld(100,100),ru(0,0),flg(false){}
  void set(xy t){
    ld.x = min(ld.x,t.x);
    ld.y = min(ld.y,t.y);
    ru.x = max(ru.x,t.x);
    ru.y = max(ru.y,t.y);
    flg = true;
  }
};

int nlist[26][26];

bool acs[26];

bool dfs(int p){
  if(acs[p]) return true;
  acs[p]=true;
  for(int i=0;i<26;i++){
    if(nlist[p][i] && dfs(i)) return true;
  }
  acs[p]=false;
  return false;
}

int main(){
  int n;
  cin>>n;
  while(n--){
    int H,W;
    cin>>H>>W;
    for(int i=0;i<26;i++){
      for(int j=0;j<26;j++){
	nlist[i][j]=0;
      }
      acs[i]=0;
    }

    Aset aset[26];
    vector<vector<char> > v(H,vector<char>(W));
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>v[i][j];
	if(v[i][j] != '.'){
	  aset[v[i][j]-'A'].set(xy(j,i));
	}
      }
    }
    bool check = false;
    for(int i=0;i<26;i++){
      if(!aset[i].flg) continue;
      for(int j=aset[i].ld.y;j<=aset[i].ru.y;j++){
	for(int k=aset[i].ld.x;k<=aset[i].ru.x;k++){
	  if(v[j][k] == '.'){
	    check = true;
	    for(int t=0;t<26;t++) nlist[i][t]=0;
	    break;
	  }
	  if(i+'A' != v[j][k]){
	    nlist[i][v[j][k]-'A']=1;
	  }
	}

	if(check) break;
      }
    }
    if(!check)
      for(int i=0;i<26;i++) check |= dfs(i);
 
    if(check) cout<<"SUSPICIOUS"<<endl;
    else cout<<"SAFE"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  
 
inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}
ll a[100005];

int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
    	sum+=(i*(n/i)*(n/i+1))/2;
    }
    cout<<sum<<endl;
    return 0; 
}

Measured memory_bytes: 3592
#include<iostream>
#define ll long long
using namespace std;
int main()
{
	int n,num[200005];
	ll up,down,mm;
	while(scanf("%d",&n)!=EOF)
	{
		cin>>num[0];
		up=num[0];
		down=0;
		for(int i=1;i<n;i++)
		{
			cin>>num[i];
			down+=num[i];
		}
		mm=up>down?up-down:down-up;
		for(int i=1;i<n-1;i++)
		{
			up+=num[i];
			down-=num[i];
			ll tmp=up>down?up-down:down-up;
			if(mm>tmp)
			mm=tmp;
			
		}
		cout<<mm<<endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
using namespace std;

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

int h, point;
int f[11][6];

bool check() {
	bool res = false;
	for(int y=h-1; y>=0; y--) {
		for(int x=2; x<5; x++) {
			if(f[y][x]!=0 && f[y][x-2]==f[y][x] && f[y][x-1]==f[y][x]) {
				res = true;
				int dx=1;
				while(x+dx<5 && f[y][x]==f[y][x+dx]) dx++;
				point += f[y][x] * (3+dx-1);
				for(int ex=x-2; ex<x+dx; ex++) {
					f[y][ex] = 0;
				}
			}
		}
	}
	return res;
}

void fall() {
	int py[5] = {};
	rep(y, h) {
		rep(x, 5) {
			f[py[x]][x] = f[y][x];
			if(f[y][x]>0) {
				py[x]++;
			}
		}
	}
	rep(x, 5) {
		for(int y=py[x]; y<h; y++) {
			f[y][x] = 0;
		}
	}
}

int main() {
	while(cin >> h, h) {
		point = 0;
		memset( f, 0, sizeof(f) );
		rep(y, h) {
			rep(x, 5) {
				int k;
				cin >> k;
				f[h-y-1][x] = k;
			}
		}
		while(check()) {
			fall();
		}
		cout << point << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
package main

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

var N int
var ans int = 9999999999999

func main() {
	fmt.Scan(&N)
	reader := bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		reader.Scan()
		a[i], _ = strconv.Atoi(reader.Text())
	}

	m := make([]int, N+1)
	for i := 1; i <= N; i++ {
		m[i] = m[i-1] + a[i-1]
	}

	for i := 0; i < N-1; i++ {
		x := m[i+1]
		y := m[N] - m[i+1]
		ans = min(ans, abs(x-y))
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] > a[j][0]
}


Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());

            if (input == 1) { Console.WriteLine(input);return; }

            var MaxCounter = 0;
            var result = 0;
           

                for (int i = 1; i<= input; i++)
            {
                var counter = 0;
                var x = i;
                while (x % 2 == 0)
                {
                    x = x / 2;
                    counter++;
                }
                if (MaxCounter < counter)
                {
                    MaxCounter = counter;
                    result = i;
                }

            }
            Console.WriteLine(result);
        }

    }
}


Measured memory_bytes: 13140
import java.util.*;
import java.lang.*;

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

        String S = scan.next();
        scan.close();

        int ans = 1000;
        int s;

        for (int i = 0; i < S.length() - 2; i++) {
            s = Math.abs(Integer.parseInt(S.substring(i, i + 3)) - 753);
            if (s < ans) {
                ans = s;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
while True:
 
    H,W =[int(i) for i in input().split()]
 
    if H == W == 0:
        break
 
    for h in range(H):
        for w in range(W):
            if (h+w) % 2 ==0:
                print('#', end='')
            else :
                print('.' ,end='')
        print()
    print()

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std ;
int main(){
    string s ;
    cin >> s ;
    int len = s.length() ;
    bool flag = true ;
    for( int i = 1 ; i < len ; i++ )
        if ( s[i] != '9' ) flag = false ;
    int ans = s[0] - 48 + 9 * ( len - 1 ) ;
    if ( !flag ) ans-- ;
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;

int main() {
  ll X;
  cin >> X;
  ll m;
  for (ll i=1; i<1000; i++) {
    if (i*i*i*i>X) {
      m=i-1;
    }
  }
  ll A, B, fin=0;
  for (ll b=-m; b<=1000; b++) {
    for (ll a=b; a<=1000; a++) {
      if (a*a*a*a*a-b*b*b*b*b==X) {
        A=a;
        B=b;
        fin=1;
        break;
      }
    }
    if (fin==1) {break;}
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n){
		cnt++;
		n /= k;
	}
	cout << cnt;
	
	return 0;
}



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

int main() {
    int n, m; scanf("%d%d", &n, &m);
    int ret = 1000;
    vector<int> v(n+1, 0), t(n+1, 0);


    for (int i = 0; i < m; i++) {
        int s, c;
        scanf("%d%d", &s, &c);
        if (n!=1 && s==1 && c==0) ret = -1;
        if (t[s]==1 && v[s]!=c) ret = -1;
        t[s] = 1;
        v[s] = c;
    }
    if (ret == 1000) {
        if (t[1]==0) {
            ret = (n==1) ? 0 : 1;
        }
        else {
            ret = v[1];
        }
        for (int i = 2; i <= n; i++) {
            ret *= 10;
            ret += (t[i]==0) ? 0 : v[i];
        }
    }

    printf("%d\n", ret);
    return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;


int main(){
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        ll n; cin >> n;
        vector<ll> a(n);
        map<ll,ll> mp;
        ll now = 0;
        rep(i,n){
                cin >> a[i];
                now += a[i];
                mp[a[i]]++;
        }

        ll q; cin >> q;
        vector<ll> b(q), c(q);

        rep(i,q){
                cin >> b[i] >> c[i];
                ll x = mp[b[i]];
                mp[b[i]] = 0;
                mp[c[i]] += x;
                now += (c[i] - b[i]) * x;
                cout << now << endl;
        }

        return 0;
}


Measured memory_bytes: 11532
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    while(x && y){
        x%=y;
        if(x==0)break;
        y%=x;
    }
    return x+y;
}
int seg(int l,int r,int n,int nl,int nr,vector<int>&t){
    if(l>=nr || r<=nl)return 0;//範囲がノードから外れている
    else if(l<=nl && r>=nr)return t[n];//範囲がノードを包含している
    else{
        int mid=(nl+nr)/2;
        return gcd(seg(l,r,n*2,nl,mid,t),seg(l,r,n*2+1,mid,nr,t));
    }
}
int main(){
    int n;
    cin>>n;
    int N;
    for(int i=1;i<n*2;i*=2)N=i;
    int a[n];
    vector<int>t(N*2,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
        t[i+N]=a[i];
    }
    for(int i=N-1;i>=1;i--){
        t[i]=gcd(t[i*2],t[i*2+1]);
    }
    int m=0;
    for(int i=0;i<n;i++){
        m=max(m,gcd(seg(0,i,1,0,N,t),seg(i+1,n,1,0,N,t)));
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;



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

	int n, k;
	cin >> n >> k;
	
	int x = 1;

	for (int i = 1; i <= n; ++i) {
		if (x * 2 <= x + k) x *= 2;
		else x += k;
	}

	cout << x;

	//system("pause");

	return 0;
}

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

 
int main() {
  int N;
  cin >> N;
  set<int> d={};
  for(int i = 0; i <N; i++){
    int n;
    cin >> n;
    d.insert(n);
  }

  cout << d.size() << endl;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
        token = lines[0].split()
        n = int(token[0])
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        token = lines[0].split()
        n = int(token[0])

    a = [int(i) for i in lines[1].split(" ")]

    return (n, a)


def solve(n, a):

    b = a.copy()
    b.sort()

    if a == b:
        return "YES"

    result = "NO"
    for i in range(0, n):
        for j in range(i+1, n):
            if a[i] > a[j]:
                c = a.copy()
                c[i], c[j] = c[j], c[i]
                if b == c:
                    result = "YES"
                    break

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()
	

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




    int main()
    {
        int n;
        string s;
        std::cin >> n >> s;
        int num = s.size();
        if(num%2 != 0) std::cout << "No" << "\n";
        else{
            num = num/2;
            for (int i = 0; i < num; ++i)
            {
                if (s[i] != s[i+num])
                {
                    std::cout << "No" << "\n";
                    return 0;
                }
            }
            std::cout << "Yes" << "\n";
        }
        
        return 0;
    }


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
#define read(n) scanf("%lld",&n)
#define f(i,a,b) for(int i=a;i<=b;++i)
#define N 100005
ll num[N];
int main()
{
	ll n,q,sum=0;
	read(n);
	f(i,1,n)
	{
		ll x;
		read(x);
		++num[x];
		sum+=x;
	}
	read(q);
	f(i,1,q)
	{
		ll x,y;
		read(x);read(y);
		sum+=(y-x)*(num[x]);
		num[y]+=num[x];
		num[x]=0;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4436
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

int main(){

	int n,a;
	vector<int>v;
	cin >> n;
	rep(i,n){
		cin >> a;

		v.push_back(a);
	}

	sort(v.begin(),v.end());

	int p,q;
    vector<int>s;
    if(n==3) q=3;
    else q=4;
	rep(i,q){
	   rep(j,q){
		    if(i!=j){
			if(v[j]/10000!=0){ p=100000*v[i]+v[j]; s.push_back(p);}
			else if(v[j]/1000!=0){ p=10000*v[i]+v[j]; s.push_back(p);}
			else if(v[j]/100!=0){ p=1000*v[i]+v[j]; s.push_back(p);}
			else if(v[j]/10!=0){ p=100*v[i]+v[j]; s.push_back(p);}
			else{ p=10*v[i]+v[j]; s.push_back(p);}

			}
	      }
		}

	sort(s.begin(),s.end());

	cout << s[2] << endl;

	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
//#define ll long long
//#define INF LONG_MAX
//#define int long long
using namespace std;

int main() {
  int a, b, c, ans;
  cin >> a >> b >> c;
  if (a != b) {
    if (a == c) {
      ans = b;
    } else {
      ans = a;
    }    
  } else {
    ans = c;
  }

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


Measured memory_bytes: 256
import itertools
 
n, m = map(int, input().split())
AB = []
for i in range(m):
    AB.append(list(map(int, input().split())))
ct = 0
N_lis = [(i + 2) for i in range(n - 1)]
Pat = itertools.permutations(N_lis)
for one_case in Pat:
    tmp = 1
    all_flag = True
    for j in one_case:
        flag = False
        for k in range(m):
            if AB[k][0] == tmp:
                if AB[k][1] == j:
                    tmp = j
                    flag = True
                    break
            elif AB[k][1] == tmp:
                if AB[k][0] == j:
                    tmp = j
                    flag = True
                    break
        if not flag:
            all_flag = False
            break
    if all_flag:
        ct += 1
print(ct)

Measured memory_bytes: 43504
s=input()
t="abcdefghijklmnopqrstuvwxyz"
if s==t[::-1]:print(-1);exit()
if len(s)<26:
  for i in t:
    if not i in s:print(s+i);exit()
else:
  for i in range(25):
    if s[-i-2]<s[-1-i]:
      t=s[:-i-2]
      a=sorted(list(s[-2-i:]))
      print(t+a[a.index(s[-2-i])+1]);exit()

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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int m, d;
    cin >> m >> d;
    
    int cnt = 0;
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= d; j++){
            string s = to_string(j);
            if(s.length() != 2)continue;
            int d1 = s[1] - '0';
            int d10 = s[0] - '0';
            if(i == d1 * d10 && d1 >= 2 && d10 >= 2){
                cnt ++;
            }
            
        }
    }
    
    cout << cnt << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long	
const int maxi=1e5+5;

vector<int> adj[maxi];
int n,m;
vector<int> dist(maxi,0);
vector<bool> vis(maxi,0);

void dfs(int s)
{
	vis[s]=true;
	
	for(auto u:adj[s])
	{
		if(!vis[u])
		dfs(u);

		dist[s]=max(dist[s],dist[u]+1);
	}
}

int main()
{
	cin>>n>>m;
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		adj[x].push_back(y);
	}
	
	for(int i=1;i<=n;i++)
	{
		if(adj[i].size()>0&& vis[i]==0)
		dfs(i);
	}
	int ans=-1;
	for(int i=1;i<=n;i++)
	ans=max(ans,dist[i]);
	
	cout<<ans;
		
}


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

using namespace std;
typedef long long LL;

int main(){
	string S;
	cin >> S;
	if(S[0]=='7'||S[1]=='7'||S[2]=='7') cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int INF=1e9;

int main(){
	int h,w;
	while(cin>>h>>w && h){
		int tai=h*h+w*w;
		int ansh=h,answ,tmptai=INF;
		bool flg=0;
		for(int i=1;i<151;i++){
			for(int j=i+1;j<151;j++){
				int nowtai=i*i+j*j;
				if(nowtai==tai){
					if(i>h){
						ansh=i;answ=j;flg=1;break;
					}
				}
				if(tai<nowtai && nowtai<=tmptai){
					if(nowtai==tmptai){
						if(i<ansh){
							ansh=i;answ=j;tmptai=nowtai;
						}
					}
					else{
						ansh=i;answ=j;tmptai=nowtai;
					}
				}
			}
			if(flg) break;
		}
		cout<<ansh<<" "<<answ<<endl;
	}

	return 0;
}



Measured memory_bytes: 3092
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int K = 19;
const int KM = 1 << (K - 1);
ll dat[1 << K];
ll laz[1 << K];
ll zero = 2e18;

void eval(int A, int l, int r) {
	if (laz[A] == zero) return;
	if (A * 2 < 1 << K) {
		laz[A * 2] = min(laz[A * 2], laz[A]);
		laz[A * 2 + 1] = min(laz[A * 2 + 1], laz[A]);
	}
	dat[A] = min(dat[A], laz[A]);
	laz[A] = zero;
}

ll update(int L, int R, ll X, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return dat[A];
	if (L <= l && r <= R) {
		laz[A] = min(laz[A], X);
		return min(dat[A], laz[A]);
	}
	dat[A] = min(update(L, R, X, A * 2, l, (l + r) / 2), update(L, R, X, A * 2 + 1, (l + r) / 2, r));
	return dat[A];
}

void add(int L, int R, ll X) {
	update(L, R, X, 1, 0, KM);
}

ll check(int L, int R, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return zero;
	if (L <= l && r <= R) return dat[A];
	return min(check(L, R, A * 2, l, (l + r) / 2), check(L, R, A * 2 + 1, (l + r) / 2, r));
}

ll query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

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


	int N, M;
	cin >> N >> M;

	rep(i, 1 << K) {
		dat[i] = zero;
		laz[i] = zero;
	}

	tuple<int, int, int> LRC[100000];
	rep(i, M) {
		int l, r, c;
		cin >> l >> r >> c;
		LRC[i] = tie(l, r, c);
	}
	sort(LRC, LRC + M);

	add(1, 2, 0);
	rep(i, M) {
		ll k = query(get<0>(LRC[i]), get<0>(LRC[i]) + 1) + get<2>(LRC[i]);
		add(get<0>(LRC[i]) + 1, get<1>(LRC[i]) + 1, k);
	}

	ll kotae = query(N, N + 1);
	if (kotae != zero) co(query(N, N + 1));
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 9728