akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

struct UnionFind{
    vector<int> Size,Parent;

    UnionFind(int n){
        Size.resize(n,0);
        Parent.resize(n,0);
        rep(i,0,n){
            makeTree(i);
        }
    }

    void makeTree(int x){
        Parent.at(x)=x;
        Size.at(x)=1;
    }

    void unite(int x,int y){
        x=findRoot(x);
        y=findRoot(y);
        if(x==y) return;

        if(Size.at(x)>=Size.at(y)){
            Parent.at(y)=x;
            Size.at(x)+=Size.at(y);
        }else{
            Parent.at(x)=y;
            Size.at(y)+=Size.at(x);
        }
    }

    int findRoot(int x){
        if(x!=Parent.at(x)) Parent.at(x)=findRoot(Parent.at(x));
        return Parent.at(x);
    }

    int getSize(int x){
        return Size.at(findRoot(x));
    }

    bool sameTree(int x,int y){
        return findRoot(x)==findRoot(y);
    }
};

int main(){
    int N,M,K; cin>>N>>M>>K;
    UnionFind G(N);
    vector<set<int>> F(N);
    rep(m,0,M){
        int a,b; cin>>a>>b;
        G.unite(a-1,b-1);
        F.at(a-1).insert(b-1);
        F.at(b-1).insert(a-1);
    }
    vector<set<int>> Block(N);
    rep(k,0,K){
        int c,d; cin>>c>>d;
        Block.at(c-1).insert(d-1);
        Block.at(d-1).insert(c-1);
    }

    rep(i,0,N){
        int ans=G.getSize(i)-F.at(i).size()-1;
        for(auto b:Block.at(i)){
            if(G.sameTree(i,b)) ans--;
        }
        cout<<ans<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 29696
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M,X,Y;
	int x[101],y[101];
	scan(N);scan(M);scan(X);scan(Y);
	int xmax=X,ymin=Y;
	rep(i,N){
		scan(x[i]);
		xmax=max(xmax,x[i]);
	}
	rep(i,M){
		scan(y[i]);
		ymin=min(ymin,y[i]);
	}
	if(xmax>=ymin) prin("War");
	else prin("No War");
	return 0;
}


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

int f(int x){
  if(x==0) return 0;
  int p=0;
  rep(bit,24){
    if(x>>bit&1){
      p++;
    }
  }
  return f(x%p)+1;
}

int main(){
  int n;
  cin>>n;
  string x;
  cin>>x;
  int count=0;
  rep(i,n) if(x[i]=='1') count++;
  vector<vector<int>> res(n,vector<int>(2));
  int p=1,q=1;
  vector<int> t(2);
  rep(i,n){
    res[n-1-i][0]=p;    
    p=p*2%(count+1);   
  }
  rep(i,n) if(x[i]=='1') t[0]=(t[0]+res[i][0])%(count+1);    
 
  if(count-1){
    rep(i,n){
      res[n-1-i][1]=q;
      q=q*2%(count-1);
    }
    rep(i,n) if(x[i]=='1') t[1]=(t[1]+res[i][1])%(count-1);
  }
  
  rep(i,n){
    int j=x[i]-'0';
    int y;
    if(j==0){
      y=(t[j]+res[i][j])%(count+1);
      cout<<f(y)+1<<endl;
    }
    if(j==1){
      if(count-1){
        y=(t[j]-res[i][j]+count-1)%(count-1);
        cout<<f(y)+1<<endl;
      }
      else cout<<0<<endl;
    }    
  }
}


Measured memory_bytes: 14432
#include<iostream>

using namespace std;

int main(){

	int a, b; 

	char op;

	while(1){

	 	cin >> a >> op >> b;

		if ( op == '?') break;

		if ( op	== '+'){

			cout << a + b << endl;

			}

		else if ( op == '-'){

			cout << a - b << endl;

			}

		else if ( op == '*'){

			cout << a * b << endl;

			}

		else if ( op == '/'){

			cout << a / b << endl;

			}

	}

	return 0;

}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var S = Console.ReadLine();
        var set = new HashSet<char>();
        set.Add(S[0]);
        set.Add(S[1]);
        set.Add(S[2]);

        Console.WriteLine(set.Count == 1 ? "No" : "Yes");
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> p;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;

int main(){
    ll x,y;cin>>x>>y;
    int ans=0;
    for(ll i=x;i<=y;i*=2) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
import sys
r=lambda:sys.stdin.readline().strip()
while 1:
 n=int(r())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=r().split()
  d[k]=v
 a=''
 for _ in[0]*int(r()):
  e=r()
  a+=d[e]if e in d else e
 print(a)


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

int main(){
    while(true){
        string card, tmp;
        int m, h;
        cin >> card;
        if(card == "-") break;
        cin >> m;
        for(int i=0; i < m; i++){
            cin >> h;
            tmp = card.substr(0, h);
            card = card.erase(0, h) + tmp;
        }
        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

int n, k;
ll ans = 0;

int main() {
    cin >> n >> k;
    for (int x = k; x < n; x++) {
        int t = n-x;
        for (int b = x+1; b <= n;) {
            int nxt = 0;
            if (t/b) nxt = t/(t/b);
            else nxt = n;
            ans += 1ll*(nxt-b+1)*((t/b)+(x>0));
            b = nxt+1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#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 a[n+2];
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	
	int prefix_sum[n+2];
	prefix_sum[0] = 0;
	
	for(int i = 1; i <= n; i++){
		prefix_sum[i] = prefix_sum[i-1] + a[i];
 	}
 	
 	map<int,int> m;
 	int ans = 0;
 	int cur = 1-k;
 	m[0] = 1;
 	for(int i = 1; i <= n; i++){
		int val = (prefix_sum[i]-i+k) % k;
		if(cur >= 0){
			m[(prefix_sum[cur]-cur+k)%k]--;
		}
		ans += m[val];
		m[val]++;
		cur++;
	}
	
	cout << ans << endl;
	

	return 0;
}



Measured memory_bytes: 15872
n = int(input())
x = list(map(int, input().split()))

a = len(x)
b = sorted(x)
fa = b[int((a/2)-1)]
se = b[int(a/2)]

for i in range(n):
    if x[i] <= fa:
        print(se)
    else:
        print(fa)

Measured memory_bytes: 25228
N, Y = map(int, input().split())

exist = False
for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if 10000*x+5000*y+1000*z == Y:
            exist = True
            print(x, y, z)
            break
    else:
        continue
    break

if not exist: print('-1 -1 -1')

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

int main(){

	long long int N;
	long long int A,B;

	cin>>N>>A>>B;
	long long int diff=B-A;
	if(diff%2==0)
	{
		cout<<diff/2<<endl;
	}
	else
	{
		long long int S1,E1;
		S1=A-1;
		E1=N-B;
		if(S1>E1)
		{
			cout<<E1+1+(B-A-1)/2<<endl;
		}
		else
		{
			cout<<S1+1+(B-A-1)/2<<endl;
		}
	}



	return 0;
}

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

char c[1005];
int ans=0;

int main(void){
	scanf("%s",c);
	int l=strlen(c);
	for(int i=0;i<l;i++){
		for(int j=0;j<l;j++){
			bool tmp=0;
			for(int k=i;k<=j;k++)
			if(c[k]!='A'&&c[k]!='T'&&c[k]!='C'&&c[k]!='G'){
				tmp=1;
				break;
			}
			if(tmp==0)ans=max(ans,j-i+1);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- as_.(i) + acc.(i)
  done;
  let dp = Array.make_matrix n n 0 in
  for w = 1 to n - 1 do
    for l = 0 to n - w - 1 do
      dp.(l).(l + w) <- ( + ) (acc.(l + w + 1) - acc.(l)) @@
        Array.fold_left min max_int @@
        Array.init w @@ fun i -> dp.(l).(l + i) + dp.(l + i + 1).(l + w)
    done
  done;
  Printf.printf "%d\n" dp.(0).(n - 1)



Measured memory_bytes: 10368
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + MOD_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a*MOD_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

ll solve() {
    ll n, d;
    cin >> n >> d;
    ll cnt = 0;
    d = d * d;
    for (ll i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)

Measured memory_bytes: 6112
/*
By Tianyi Chen. All rights reserved.
Date: 2016-12-04
*/
#include<bits/stdc++.h>
using namespace std;
int n,x,a[100001];int64_t ans;
int main() {
 ios::sync_with_stdio(0);
 cin>>n>>x;
 for(int i=0;i<n;++i)cin>>a[i];
 for(int i=1;i<n;++i) {
  if (a[i]+a[i-1]>x) {
   int t=a[i]+a[i-1]-x;
   a[i]-=t;
   if (a[i]<0)a[i]=0;
   ans+=t;
  }
 }
 cout<<ans;
}

Measured memory_bytes: 640
import java.util.*;


public class Main {
	static class pair{
		int x,y;
		pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	static Queue<pair> q = new LinkedList<pair>();
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(),W = sc.nextInt(),N = sc.nextInt();
		String temp_in;
		char[][] field = new char[H+2][W+2];
		pair start = null;
		for(int i=0;i<W+2;i++){
			field[0][i] = 'X';
			field[H+1][i] = 'X';
		}
		for(int i=0;i<H+2;i++){
			field[i][0] = 'X';
			field[i][W+1] = 'X';
		}
		int[][] dis = new int[H+2][W+2];
		int[][] check = new int[H+2][W+2];
		for(int i=1;i<H+1;i++){
			temp_in = sc.next();
			for(int j=1;j<W+1;j++){
				field[i][j] = temp_in.charAt(j-1);
				if(field[i][j] == 'S') {
					start = new pair(i,j);
				}
				dis[i][j] = -1;
				check[i][j] = 0;
			}
		}
		q.add(start);
		check[start.x][start.y] = 1;
		int[] dx = {1,0,-1,0};
		int[] dy = {0,1,0,-1};
		int level = 1, counter =0;
		while(!q.isEmpty()){
			pair p = q.poll();
			//System.out.println("size:"+q.size()+" level:"+level);
			int x = p.x, y = p.y;
			if(dis[x][y]==-1) dis[x][y] =0;
			
			String v_buf = String.valueOf(field[x][y]);
			if(Character.isDigit(field[x][y])&&Integer.parseInt(v_buf)<=level){
				//System.out.println(v);
				field[x][y] = '.';
				
				counter +=dis[x][y];
				if(level ==N) break;
				q.removeAll(q);
				for(int i=1;i<H+1;i++){
					for(int j=1;j<W+1;j++){
						dis[i][j] = -1;
						check[i][j] = 0;
 					}
				}
				pair new_p = new pair(x,y);
				check[x][y] = 1;
				q.add(new_p);
				level++;
			}else{
				for(int c=0;c<4;c++){
					if(field[x+dx[c]][y+dy[c]]!='X' && check[x+dx[c]][y+dy[c]]==0){
						dis[x+dx[c]][y+dy[c]]=dis[x][y]+1;
						pair temp_p = new pair(x+dx[c],y+dy[c]);
						q.add(temp_p);
						check[x+dx[c]][y+dy[c]] = 1;
					}
				}
			}
		}
		System.out.println(counter);
	}
}

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

int main()
{
	int n;
    cin >> n;
    int arr[n];
    int cnt = 0;
    for(int i=0;i<n;i++) {cin >> arr[i];
                          if(i%2==0 && arr[i] %2==1) {cnt++;}
                         }
    cout << cnt << endl;
    
    
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll to = 0;
    rep(i, n)
    {
        cin >> a[i];
        to += a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    vector<ll> b(n);
    rep(i, n)
    {
        cin >> b[i];
    }
    sort(b.begin(), b.end());
    if (to <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    ll l = 0;
    ll r = 0;
    rep(i, n)
    {
        r = max(r, a[i] * b[i]);
    }

    while (r - l > 1)
    {
        ll mid = (l + r) / 2;
        ll now = 0;
        rep(i, n)
        {
            if (a[i] * b[i] > mid)
            {
                now += (a[i] * b[i] - mid - 1) / b[i] + 1;
            }
        }
        if (k >= now)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 6372
/*
	@・ω・@ <だれだろうね
*/

/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<long long>;
using pll = pair<long long, long long>;
template<class T> using pr = pair<T, T>;
template<class T> using vec = vector<T>;

#define debug(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t",n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define str(n)	(n.toString())

#define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(ll i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(ll i=(n); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = math_P(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T mod_pow(T x, T n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) { (ret *= x) %= p; } (x *= x) %= p; n >>= 1; } return ret; }

/*****/

ll K, N;
vecll A;

void Main()
{
	cin >> K >> N;
	A.resize(N);
	rep(i, N)	cin >> A[i];

	ll max = K - *(A.end() - 1) + A[0];
	rep(i, N - 1)
	{
		chmax(max, A[i + 1] - A[i]);
	}

	cout << (K - max);
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);

	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/

	Main();
	cout << /**/ endl /*/ flush /**/;

	return 0;
}


Measured memory_bytes: 1792
s=list(input())
s=set(s)
s=list(s)
s.sort()
k=0
for i in range(26):
    if ord(s[i])-97!=i:
        if i==0:
            print("a")
            k=1
            break
        print(chr(ord(s[i-1])+1))
        break
    if i==25:
        print("None")
        k=1
        break
    if i==len(s)-1:
        print(chr(ord(s[-1])+1))
        break

Measured memory_bytes: 3956
n, k  = map(int,input().split())
p = list(map(int,input().split()))
t = sum(p[0:k])
s = t
for i in range(1,n-k+1):
  t = t - p[i-1] + p[i+k-1]
  s = max(s,t)
print((s+k)/2)

Measured memory_bytes: 71792
x,k,d = map(int,input().split())
#print(x,k,d)
x=abs(x)
a = x//d
b = x%d

if k <= a:
    print(abs(x-k*d))

else:
    tmp = k-a
    if tmp%2 == 0:
        print(x-a*d)
    else:
        print(abs(x-(a+1)*d))

Measured memory_bytes: 9192
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
import math

def main():
    n = II()
    print(2*n*math.pi)

if __name__ == '__main__':
    main()


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

int main(){
int n;
int count=0;
int ans=0;
cin>>n;
for(int i=1;i<=n;i++){
    count=0;
if(i%2==0)continue;
for(int  j=1;j<=i;j++){
    if(j%2==0)continue;
    if(i%j==0)count++;
}
if(count==8)ans++;
}
cout<<ans;

}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct node {
    int key;
    bool confirmed;
    node *left;
    node *right;
    node *parent;

    node *reconstruction() {
        if (parent->confirmed) return this->parent;
        node *pNode = parent->reconstruction();
        parent->parent = this;
        if (this == parent->right) {
            parent->right = nullptr;
            left = parent;
            pNode->right = this;
        } else {
            parent->left = nullptr;
            right = parent;
            pNode->left = this;
        }
        parent = pNode;
        return pNode;
    }
};

queue<node *> postOrder;

void walkPostOrder(node *cur) {
    if (cur == nullptr) return;
    walkPostOrder(cur->left);
    walkPostOrder(cur->right);
    postOrder.push(cur);
}

int main() {
    int n;
    cin >> n;
    vector<node *> preOrder(n);
    vector<node> inOrder(n + 1);
    inOrder[0].confirmed = true;
    for (int i = 0; i < n; ++i) {
        int key;
        cin >> key;
        preOrder[i] = &inOrder[key];
    }
    int key, pre;
    pre = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> key;
        inOrder[key].key = key;
        inOrder[key].parent = &inOrder[pre];
        inOrder[pre].right = &inOrder[key];
        pre = key;
    }
    for (int i = 0; i < n; ++i) {
        preOrder[i]->reconstruction();
        preOrder[i]->confirmed = true;
    }
    walkPostOrder(preOrder[0]);
    while (postOrder.size() > 1) {
        cout << postOrder.front()->key << ' ';
        postOrder.pop();
    }
    if (!postOrder.empty()) cout << postOrder.front()->key;
    cout << endl;
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll H, W;
    cin >> H >> W;
    ll dp[H+5][W+5];
    ll i, j;
    char a[H+5][W+5];
    
    for(i=1; i<=H; i++) {
        for(j=1; j<=W; j++) {
            cin >> a[i][j];
        }
    }
    
    memset(dp, 0, sizeof(dp));
    dp[1][1]=1;
    
    for(i=1; i<=H; i++) {
        for(j=1; j<=W; j++) {
            if(a[i-1][j]!='#') {
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=MOD;
            }
            
            if(a[i][j-1]!='#') {
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=MOD;
            }
            
        }
    }
    
    pr(dp[H][W]);
}


Measured memory_bytes: 9088
import sys
from collections import deque

def main():
  input = sys.stdin.readline
  n, m = map(int, input().split())
  roads0 = [[] for _ in range(n)]
  roads1 = [[] for _ in range(n)]
  roads2 = [[] for _ in range(n)]
  
  for i in range(m):
    u, v = map(int, input().split())
    roads0[u-1].append(v-1)
    roads1[u-1].append(v-1)
    roads2[u-1].append(v-1)
  

  s, t = map(int, input().split())
  not_yet = deque([])
  already = [[False]*3 for _ in range(n)]
  dist = [[0]*3 for _ in range(n)]
  for v in roads0[s-1]:
    not_yet.append((v, 1))
    dist[v][1] = 1
    already[v][1] = True
  already[s-1][0] = True
  while not_yet:
    key = not_yet.popleft()
    k1, k2 = key[0], key[1]
    if k2 == 0:
      for v in roads1[k1]:
        if already[v][1]:
          continue
        dist[v][1] = dist[k1][0]+1
        already[v][1] = True
        not_yet.append((v, 1))
    elif k2 == 1:
      for v in roads2[k1]:
        if already[v][2]:
          continue
        dist[v][2] = dist[k1][1]+1
        already[v][2] = True
        not_yet.append((v, 2))
    else:
      for v in roads0[k1]:
        if already[v][0]:
          continue
        dist[v][0] = dist[k1][2]+1
        already[v][0] = True
        not_yet.append((v, 0))
  if already[t-1][0]:
    print(dist[t-1][0]//3)
  else:
    print(-1)
  
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 78292
class Dice():

    def __init__(self, label):
        self.label = label

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def rotate(self):
        self.change([1, 4, 2, 5, 3, 6])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num

    def is_same_dice(self, another_dice):
        for i in range(6):
            if i % 2 == 0:
                self.north()
            else:
                self.west()
            for j in range(4):
                self.rotate()
                if self.label == another_dice:
                    return True
        return False


def main():
    f = [int(x) for x in input().split()]
    s = [int(x) for x in input().split()]

    if Dice(f).is_same_dice(s):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 7788
A, B, C = map(int, input().split())

if A == C or B == C:
    print('Yes')
elif A < B:
    if A <= C and C <= B:
        print('Yes')
    else:
        print('No')
else:
    if B <= C and C <= A:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 38384
#include <iostream>
#define REP(val,times) for(int val = 0;val < times;val++)
using namespace std;

int main(){
    string  str[3];
    REP(i,3)
        cin >> str[i];
    cout << str[0][0] << str[1][0] << str[2][0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAX_N 100

int A[MAX_N];
int main(int argc, char *argv[])
{
  int N;
  scanf("%d",&N);
  for(int i = 0;i <N;i++){
    cin >>A[i];
  }
  for(int i = N-1;i >= 0;i--){
    cout <<A[i];
    if(i != 0)
      cout <<" ";
    if(i == 0)
      cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
N = int(input())
Pn = list(map(int,input().split(' ')))

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] < Pn[i] < Pn[i+1] ) or ( Pn[i+1] < Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0;true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}
int main() {
	string a, b;
	cin >> a >> b;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end(), greater<char>());
	if (a < b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {
	int r,d,x,old=0;
	cin>>r>>d>>x;
	old=x;

	for (int i = 1; i <= 10; i++) {
		x=r*old-d;
		cout<<x<<"\n";
		old=x;
	}


	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
main = do
  [n,m,l]<-map (read::String->Int) . words <$> getLine
  a <-  map (map (read::String->Int) .words) <$> (replicateM n getLine)
  b <-  map (map (read::String->Int) .words) <$> (replicateM m getLine)
  putStr $ unlines $ map (unwords . map show) $ mult a b

mult :: Num a => [[a]] -> [[a]] -> [[a]]
mult a b = [map (sum . zipWith (*) r) $ transpose b | r <- a]

Measured memory_bytes: 12280
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

ans = 0

if m - n*2 >= 0:
    ans += n
    m -= n*2
    ans += m//4
    print(ans)
    exit()
else:
    if m % 2 == 0:
        print(m//2)
        exit()
    else:
        print((m-1)//2)
        exit()


Measured memory_bytes: 61980
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	cin >> H >> W;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	vector<vector<int>>dis(H, vector<int>(W, MOD));
	dis[0][0] = 0;
	int white = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.')white++;
		}
	}
	queue<pair<int, int>>Q;
	Q.push({ 0,0 });
	int dir[] = { 1,0,-1,0,1 };
	while (!Q.empty()) {
		int cy = Q.front().first;
		int cx = Q.front().second;
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i];
			int nx = cx + dir[i + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (s[ny][nx] == '#')continue;
			if (dis[ny][nx] > dis[cy][cx] + 1) {
				dis[ny][nx] = dis[cy][cx] + 1;
				Q.push({ ny,nx });
			}
		}
	}
	if (dis.back().back() == MOD) {
		cout << -1 << endl;
		return 0;
	}
	cout << white - dis.back().back() - 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int n, m, a;
	int sum = 0;
	cin >> n;
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> a;
		sum += a;
	}

	if (sum <= n) {
		cout << n - sum << endl;
	} else {
		cout << "-1" << endl;
	}
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    string n;
    cin >> n;
    ll check = 0;
    rep(i,0,n.size()){
        check += int(n[i])-int('0');
    }
    if(check%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3748
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

ll f(ll b, ll n) {
	if (b > n) return n;
	return f(b, n / b) + (n % b);
}
ll xa[3];
ll xr[3];
ll xb[3];
bool use1[3];
ll Cb(ll n, vector<ll> vec,int de);
ll Ca(ll n,vector<ll> vec,int de) {

	if (de == 0) {
		ll res = Cb(n, vec,1);

		for (size_t i = 0; i < 3; i++)
		{
			if (use1[i]) continue;
			use1[i] = true;
			vec[i] = n / xa[i];

			ll val = Ca(n - (vec[i] * xa[i]), vec, 0);
			val = max(val, Cb(n - (vec[i] * xa[i]), vec,1));
			res = max(res, val);
			vec[i] = 0;
			use1[i] = false;
		}
		return res;
	}
	else if(de == 1){
		ll res = 0;
		for (int i = 0;i < 3;i++)
		{
			res += vec[i] * xa[i];
		}
		return res;
	}

}
bool use2[3];
ll Cb(ll n,vector<ll> vec,int de) {

	ll res = 0;

	for (size_t i = 0; i < 3; i++)
	{
		if (use2[i]) continue;
		use2[i] = true;
		ll tmp = vec[i];

		vec[i] = n / xb[i];
		ll val = Cb(n - (vec[i] * xb[i]), vec, de);
		val = max(val, Ca(n - (vec[i] * xb[i]), vec, (de == 2 ? 0 : de)));
		ll val2 = tmp * xb[i];
		vec[i] = 0;
		val = max(val, val2 + Cb(n, vec, de));
		res = max(res, val);
		use2[i] = false;
	}
	return res;

}
void solv() {

	int n, x;
	cin >> n >> x;
	ll v[110];
	for (size_t i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	ll d = 0;
	int c = 1;
	for (size_t i = 0; i < n; i++)
	{
		d += v[i];
		if (d > x) break;
		c++;
	}
	cout << c << endl;
}

int main() {
//	COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string n; cin >> n;
	for (int i = 0; i < 3; i++) {
		if (n[i] == '1') { n[i] = '9'; }
		else { n[i] = '1'; }
	}
	cout << n << endl;
	return 0;
}

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

#define N 100000

int n;
int a[N];

map<int, int> m;

int main()
{
	int ans = 0;

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

	sort( a, a + n );
	for( int i = 0; i < n; i++ ) {
		m[a[i]]++;
	}
	int sz = m.size();
	int last = -1;
	for( int i = 0; i < n; i++ ) {
		int mm = m[a[i]];
		int aa = a[i];
		if( aa == last ) {
			continue;
		}
		if( mm > 0 ) {
			if( mm < aa ) {
				ans += mm;
			}
			else if( mm > aa ) {
				ans += mm - aa;
			}
		}
		last = aa;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  long A[N];
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  int count=0;
  bool flag=false;
  while(1) {
    for (int i=0; i<N; i++) {
      if (A[i]%2) {
        flag=true;
        break;
      }
      else A[i] /= 2;
    }
    if (flag) break;
    count++;
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool isRightTriangle(int a, int b, int c)
{
	return (a * a == b * b + c * c);
}

int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		vector<int> triangle;
		for (int j = 0; j < 3; j++){
			int edge;
			scanf("%d", &edge);
			triangle.push_back(edge);
		}
		sort(triangle.begin(), triangle.end());
		puts(isRightTriangle(triangle[2], triangle[1], triangle[0]) ? "YES" : "NO");
	}
	return (0);
}

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

int	main()
{
	int n;
	cin >> n;
	vector<int>	S_vec(n);
	for (int i = 0; i < n; ++i)
		cin >> S_vec.at(i);
	int	q;
	cin >> q;
	int	cnt = 0;
	int	t;
	for (int i = 0; i < q; ++i) {
		cin >> t;
		auto it = lower_bound(S_vec.begin(), S_vec.end(), t);
		if (it != S_vec.end() && *it == t)
			++cnt;
	}
	cout << cnt << endl;
}


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

using namespace std;

int n, m;
int a;

int main(void)
{
	scanf("%d %d", &n, &m);
	
	for(int i = 0 ; i < m ; i++)
	{
		scanf("%d", &a);
		n -= a;
	}
	
	printf("%d", n < 0 ? -1 : n);
	return 0;
}

Measured memory_bytes: 3836
import sys
def input(): return sys.stdin.readline().strip()

def main():
    x=int(input())
    a=1
    for i in range(2,x+1):
        j=2
        while True:
            k=i**j
            if k>x:
                break
            if k>a:
                a=k
            j+=1
    print(a)

main()

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <sstream>

using namespace std;

int a[128];
char b[1001];

int s2i(string s) {
  int ret = 0;

  int N = s.size();
  for(int i=0; i<N; i++) {
    if(isdigit(s[i])) {
      int temp = s[i]-'0';
      i++;
      ret += temp * a[s[i]];
    }
    else {
      ret += a[s[i]];
    }
  }
  
  return ret;
}

string i2s(int x) {
  string ret;
  stringstream ss; ss << x;
  
  string s = ss.str();
  int N = s.size();
  
  for(int i=0; i<N; i++) {
    if(s[i] == '1') ret += b[(int)pow(10, N-i-1)];
    else if(s[i] == '0') {}
    else {
      ret += s[i];
      ret += b[(int)pow(10, N-i-1)];
    }
  }
  
  return ret;
}

int main() {
  int n;

  a['m'] = 1000;
  a['c'] = 100;
  a['x'] = 10;
  a['i'] = 1;
  
  b[1000] = 'm';
  b[100] = 'c';
  b[10] = 'x';
  b[1] = 'i';
  
  cin >> n;
  for(int i=0; i<n; i++) {
    string s, t; cin >> s >> t;
    cout << i2s(s2i(s) + s2i(t)) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1264
from collections import Counter

N, *A = map(int, open(0).read().split())
ctr = Counter(A)
total = sum(v * (v - 1) // 2 for v in ctr.values())
for v in A:
    c = ctr[v]
    print(total - (c * (c - 1) // 2) + max(0, (c - 1) * (c - 2) // 2))


Measured memory_bytes: 92056
a, b = map(int, input().split())
if a > b and (a+b)%2 == 0:
    ans = (a+b)/2
    print(int(ans))
#ans = -(a*a-b*b)/(2*(b-a))
elif b > a and (a+b)%2 == 0:
    ans = (b+a)/2
    print(int(ans))
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::cout << (N / 100 == N % 10 ? "Yes" : "No") << std::endl;

  return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    s += t[t.size()-1];
    if(s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, m, A[100][100], b[100], c[100];
    for(int i=0; i<100; i++){
        b[i] = 0;
        c[i] = 0;
        for(int j=0; j<100; j++){
            A[i][j] = 0;
        }
    }
    scanf("%d %d", &n, &m);
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            scanf("%d", &A[i][j]);
        }
    }
    for(int i=0; i<m; i++){
        scanf("%d", &b[i]);
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            c[i] += + A[i][j] * b[j];
        }
    }
    for(int i=0; i<n; i++){
        printf("%d\n", c[i]);
    }
    return 0;
}



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

const int N = 705;

vector <int> G[N];
int a[N][N], dp[N], rec[N];
int color[N];
int B, W;
queue <int> q;

bool bfs(int x){
	int u, v;
	B = W = 0;
	q.push(x);
	color[x] = 1;
	while (!q.empty()){
		u = q.front(); q.pop();
		if (color[u] == 1) B++;
		else W++;
		for (int i = 0; i < (int)G[u].size(); i++){
			v = G[u][i];
			if (color[v] == color[u]) return false;
			else if (color[v] == -1){
				q.push(v);
				color[v] = 3 - color[u];
			}
		}
	}
	return true;
}

int main(){
	int n, m, u, v, cnt, ans;
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (i == j) a[i][j] = 0;
			else a[i][j] = 1;
		}
	}
	for (int i = 1; i <= m; i++){
		scanf("%d %d",&u,&v);
		a[u][v] = 0;
		a[v][u] = 0;
	}
	cnt = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (a[i][j]){
				G[i].push_back(j);
				if (i < j) cnt++;
			}
		}
	}
	memset(color, -1, sizeof(color));
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	for (int i = 1; i <= n; i++){
		if (color[i] == -1){
			if (!bfs(i)){
				printf("-1\n");
				return 0;
			}
			memset(rec, 0, sizeof(rec));
			for (int j = 0; j <= n; j++){
				if (j + B <= n) rec[j + B] |= dp[j];
				if (j + W <= n) rec[j + W] |= dp[j];
			}
			for (int j = 0; j <= n; j++) dp[j] = rec[j];
		}
	}
	ans = 1e9;
	for (int i = 0; i <= n; i++){
		if (dp[i]) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
int n,m,head[100100],cnt=0,parent[100100],dfn[100100],low[100100],vis[100100],tag=0,book[100100],count=0;
struct node{
    int to,next;
}e[100000*2+100];//无向?
void addedge(int u,int v){
    cnt++,e[cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
}
void dfs(int current,int previous){//?置 dfn[] low[] 
    int next,b;//next点 b? 
    vis[current]=1;
    //parent[current]=previous;//1 此句?除 
    tag++;
    dfn[current]=low[current]=tag;
    for(b=head[current];b;b=e[b].next){
        next=e[b].to;
        if(vis[next]==0){
            parent[next]=current;//1 添加此句 
            dfs(next,current);
            low[current]=low[current]>low[next]?low[next]:low[current];
        }else if(next!=previous){
            low[current]=low[current]>dfn[next]?dfn[next]:low[current];
        }
    }
} 
void art_point(){
    int i,p,p_num=0;
    for(i=0;i<n;i++){
        p=parent[i];
        if(p==0)p_num++;
        else if(p>0&&dfn[p]<=low[i])book[p]=1;
    }
    if(p_num>1)book[0]=1;
}
int main(){
    int i,u,v;
    memset(vis,0,sizeof(vis));
    memset(head,0,sizeof(head));
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        addedge(u,v);
        addedge(v,u);
    }
    parent[0]=-1;
    dfs(0,-1);
    art_point();
    for(i=0;i<n;i++)
        if(book[i])
            printf("%d\n",i);
    return 0;
} 


Measured memory_bytes: 3860
n, m, l = gets.split.map(&:to_i)
mat1 = []
mat2 = []
(1..n).each { |_x| mat1 << gets.split.map(&:to_i) }
(1..m).each { |_x| mat2 << gets.split.map(&:to_i) }

ans = []
(0..n - 1).each do |rx|
  v = []
  (0..l - 1).each do |cx|
    sum = 0
    (0..m - 1).each do |mx|
      sum += mat1[rx][mx] * mat2[mx][cx]
    end
    v << sum
  end
  ans << v
end

ans.each { |row| puts row.join(' ') }

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

int main(){
    int R, C, K;
    std::cin >> R >> C >> K;
    std::vector< std::vector< int > > RCV(R, std::vector< int >(C, 0));
    for(int i=0; i<K; i++){
        int tmpr, tmpc, tmpv;
        std::cin >> tmpr >> tmpc >> tmpv;
        RCV[tmpr-1][tmpc-1] = tmpv;
    }
    
    std::vector< std::vector< std::vector< long long > > > dp(R+1, std::vector< std::vector< long long > >(C+1, std::vector< long long >(4, 0)));
    
    for(int i=1; i<=R; i++){
        for(int j=1; j<=C; j++){
            for(int k=0; k<4; k++){
                if(k == 0){
                    dp[i][j][k] = std::max(dp[i-1][j][0], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][1], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][2], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][3], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i][j-1][k], dp[i][j][k]);
                }else if(k == 1){
                    dp[i][j][k] = std::max(dp[i-1][j][0] + RCV[i-1][j-1], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][1] + RCV[i-1][j-1], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][2] + RCV[i-1][j-1], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i-1][j][3] + RCV[i-1][j-1], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i][j-1][k], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i][j-1][k-1] + RCV[i-1][j-1], dp[i][j][k]);
                }else{
                    dp[i][j][k] = std::max(dp[i][j-1][k], dp[i][j][k]);
                    dp[i][j][k] = std::max(dp[i][j-1][k-1] + RCV[i-1][j-1], dp[i][j][k]);
                }
            }
        }
    }
    
    std::cout << std::max(dp[R][C][3], std::max(dp[R][C][2], std::max(dp[R][C][1], dp[R][C][0]) ) ) << std::endl;
    
    
    return 0;
    
}


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

using namespace std;

int n;
bool tvojamama[100010];
vector<int> s;

int main() {
    memset(tvojamama, false, sizeof tvojamama);
    scanf("%d", &n);


    for (int i = 2; i <= 55555; i++) {
        if (tvojamama[i]) continue;
        s.emplace_back(i);
        for (int j = i; j <= 55555; j += i)
            tvojamama[j] = true;
    }
    int ptr = 0;
    for (int i = 0; i < n;) {
        if (s[ptr] % 5 == 1) {
            printf("%d ", s[ptr]);
            i++;
        }
        ptr++;
    }
    return 0;
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll maxbit(ll i) {
	for(int j=0x8000; j>0; j=j>>1) {
		if (j & i) return j;
	}
	return 0;
}
ll index(ll x) {
	ll ret = 0;
	while(x) {
		ret++;
		x = x >> 1;
	}
	return ret;
}
int main() {
	ll		b,i,j,k,n,m,x,y,xx,ans = 0;
	string	s;

	cin >> n >> m >> x;
	vector<ll> c(n+1);
	vector<vector<ll>> a(n+1 , vector<ll>(m+1) );
	for(i=1;i<=n;i++) {
		cin >> c[i];
		for(j=1;j<=m;j++) {
			cin >> a[i][j];
		}
	}
	b = 1 << n;

	vector<vector<ll>>	dp2(b , vector<ll>(m+1, INFL));
	for(j=1;j<=m;j++) {
		dp2[0][j] = 0;
	}
	for(i=1;i<b;i++) {
		for(j=1;j<=m;j++) {
			xx = maxbit(i);
			y = index(xx);
			dp2[i][j] = dp2[i & ~xx][j] + a[y][j];
		}
	}
	ans = INFL;
	for(i=1;i<b;i++) {
		int f = 1;
		for(j=1;j<=m;j++) {
			if (dp2[i][j]<x) f = 0;
		}
		//cout << "DBG : " << i << ' ' << f << endl;
		if (f) {
			ll ii = i;
			ll tmp = 0;
			ll x = 1;
			while(ii) {
				if (ii & 1) tmp+=c[x];
				ii = ii >> 1;
				x++;
			}
			ans = min(ans , tmp);
			//cout << "DBG :: " << ans << ' ' << tmp << endl;
		}
	}
	/*
	for(i=0;i<b;i++) {
		cout << "DBG ";
		for(j=1;j<=m;j++) cout << dp2[i][j] << ' ';
		cout << endl;
	}*/
	if (ans == INFL) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4160