akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	static int[][] list;
	static int[] check;
    
	public static void main(String[] args){
    	 Scanner sc= new Scanner(System.in);
    	 int n =sc.nextInt();
    	 list =new int[n][2];
    	 check = new int[n];
    	 for(int i=0;i<n;i++){
    		 list[i][0]=sc.nextInt();
    	 }
    	 for(int i=0;i<n;i++){
    		 check[i]=sc.nextInt();
    		 for(int j=0;j<n;j++){
    			 if(check[i]==list[j][0]){
    				 list[j][1]=i;
    			 }
    		 }
    	 }
    	 mpost(0,n,list);
    	 
     }
     
     static int reg=0;
     
     static void mpost(int a,int b,int[][] list){
    	if(a>=b){
    		return;
    	}else{
    	 int num=list[reg][0];
    	 int id=list[reg][1];
    	 reg++;
    	 mpost(a,id,list);
    	 mpost(id+1,b,list);
    	 System.out.print(num);
    	 System.out.print(num==list[0][0]?"\n":" ");
    	}
     }
}


Measured memory_bytes: 26284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string T;
  cin >> T;
  for (int i = 0; i < T.size(); i++) {
    if (i % 2 == 0){
      if (T.at(i) != 'h'){
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if (T.at(i) != 'i'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  if (T.at(T.size()-1) == 'h'){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}
  

    
 
  
 
  

Measured memory_bytes: 3540
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadText();
            switch (N.Last())
            {
                case '2':
                case '4':
                case '5':
                case '7':
                case '9':
                    return "hon";
                case '0':
                case '1':
                case '6':
                case '8':
                    return "pon";
                case '3':
                    return "bon";
                default:
                    break;
            }

            return null;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 26260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;

int main() {
  int N;
  cin>>N;
  
  vector<int> w(N);
  for(int i=0;i<N;++i){
    cin>>w[i];
  }
  
  int ans=10000;
  
  for(int i=1;i<N;++i){
    int sum1=0;
    int sum2=0;
    
    for(int j=0;j<i;++j){
      sum1+=w[j];
    }
    
    for(int j=i;j<N;++j){
      sum2+=w[j];
    }
    
    int z=abs(sum1-sum2);
    ans=min(ans,z);
    
    sum1=0;
    sum2=0;
    
  }
  
  cout<<ans<<endl;
  
}


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

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int M , N;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  double sum = 0;
  int count = 0;
  double m = 4 * M;
  rep(i, N) sum += A[i];

  rep(i, N){
    count += (sum/m <= A[i]);
  }

  if (count >= M)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  
  return 0;
}




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



int main(){
    string s, t;    cin >> s >> t;
    int sn=s.size(), tn=t.size();
    string ans="UNRESTORABLE";
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());

    for(int i=0; i<=sn-tn; i++){
        bool flag=true;
        for(int j=0; j<tn; j++){
            if(s[i+j]==t[j] || s[i+j]=='?') continue;
            flag = false; break;
        }
 
        if(flag){
            ans = "";
            for(int k=0; k<sn; k++){
                if(i==k){
                    ans += t; k+=tn-1;
                }else if(s[k]=='?') ans += 'a';
                else ans += s[k];
            }
            reverse(ans.begin(), ans.end());
            break;
        }
    }
    
    cout << ans << endl;
}




Measured memory_bytes: 256
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
#print()


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#define INF (LLONG_MAX>>2)
using namespace std;

typedef long long ll;

class edge{
public:
  int to;
  int weight;
  edge(int to, int weight){
    this->to = to;
    this->weight = weight;
  }
};

ll minimumSpannTree(int, vector<edge>*);

int main(){
  int n; cin >> n;
  vector<edge> graph[n+1];

  pair<int, int> xp[n+1], yp[n+1]; //(頂点番号・座標)のpair
  int x, y;
  for(int i=1; i<=n; i++){
    cin >> x >> y;
    xp[i] = make_pair(x, i);
    yp[i] = make_pair(y, i);
  }

  //隣り合う頂点同士を探すためにソート
  sort(xp+1, xp+n+1); sort(yp+1, yp+n+1);

  //グラフ作成
  for(int i=1; i<n; i++){
    int s=xp[i].second, t=xp[i+1].second;
    int weight = abs(xp[i].first-xp[i+1].first);
    graph[s].push_back(edge(t, weight));
    graph[t].push_back(edge(s, weight));

    s=yp[i].second, t=yp[i+1].second;
    weight = abs(yp[i].first-yp[i+1].first);
    graph[s].push_back(edge(t, weight));
    graph[t].push_back(edge(s, weight));
  }

  ll ans = minimumSpannTree(n, graph);

  cout << ans << endl;

  return 0;
}

ll minimumSpannTree(int n, vector<edge>* graph){
  ll minDis[n+1];
  bool added[n+1];
  for(int i=1; i<=n; i++){
    minDis[i] = INF;
    added[i] = false;
  }

  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
  pq.push(make_pair(0, 1));//とりあえず頂点1をプッシュ
  minDis[1] = 0;

  ll res = 0;
  while(!pq.empty()){
    pair<ll, int> nowP = pq.top(); pq.pop(); //先頭要素をポップ
    ll nowDis = nowP.first; int nowNode = nowP.second;
    if(added[nowNode]) continue;

    added[nowNode] = true;
    res += nowDis;

    for(int i=0; i<graph[nowNode].size(); i++){
      edge e = graph[nowNode][i];
      if(e.weight < minDis[e.to]){
        minDis[e.to] = e.weight;
        pq.push(make_pair(minDis[e.to], e.to));
      }
    }
  }

  return res;
}


Measured memory_bytes: 12404
N = int(input())
S = str(input())
alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
answer = ''
for i in range(len(S)):
    num = alpha.index(S[i])+N
    if num > 25:
        num -= 26
    answer += alpha[num]
print(answer)

Measured memory_bytes: 73484
// B.

#include <sstream>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<int> ans;
	set<int> s;
	LL sum = 0;
	for (int i = 2; i <= 30000; ++i) {
		if ((i % 2) == 0 || (i % 3) == 0) {
			ans.push_back(i);
			sum += i;
			if (ans.size() >= n) {
				break;
			}
			s.insert(i);
		}
	}
	for (int i = 2; i <= 30000; ++i) {
		auto ok = [&] {
			for (int i = 0; i < n; ++i) {
				if (gcd(ans[i], sum - ans[i]) == 1) {
					return false;
				}
			}
			return true;
		};
		if (s.find(i) == s.end()) {
			sum -= ans[n - 1];
			ans[n - 1] = i;
			sum += i;
			if (ok()) {
				break;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << (i ? " " : "") << ans[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<map>
#include<cmath>
#define int long long
#define double long double
using namespace std;
int X1,Y1,X2,Y2,n,m,xp[200005],bit[200005];
map<int,int>mp;
double ans;
struct sd{int x,y;bool operator < (const sd &fu) const {return x<fu.x;};}p[200005],w[200005];
inline void add(int v,int r) {for(v;v<=200004;v+=v&-v) bit[v]=max(bit[v],r);}
inline int ask(int v) {int rt=0;for(;v;v-=v&-v) rt=max(rt,bit[v]);return rt;}
signed main()
{
	scanf("%lld%lld%lld%lld%lld",&X1,&Y1,&X2,&Y2,&n);X1++;Y1++;X2++;Y2++;
	for(int i=1;i<=n;++i) {scanf("%lld%lld",&p[i].x,&p[i].y);p[i].x++;p[i].y++;xp[i]=p[i].y;}
	sort(xp+1,xp+1+n);
	for(int i=1;i<=n;++i) mp[xp[i]]=i;
	for(int i=1;i<=n;++i) if(((X1<=p[i].x&&X2>=p[i].x)||(X1>=p[i].x&&X2<=p[i].x))&&((Y1<=p[i].y&&p[i].y<=Y2)||(Y2<=p[i].y&&p[i].y<=Y1))) w[++m]=p[i];
	if(m==1&&(X1==X2||Y1==Y2)) cout<<setprecision(50)<<(double)(abs(X1-X2+Y1-Y2))*100.0-20.0+M_PI*10.0;
	else {
		sort(w+1,w+1+m);
		ans=(double)(abs(X1-X2)+abs(Y2-Y1))*100.0;
		if((X1>=X2&&Y1<=Y2)||(X1<=X2&&Y1>=Y2)) {
			if(w[m].x!=max(X1,X2)||m!=abs(X2-X1)+1) goto lp1;
			for(int i=m-1;i>0;--i) if(w[i].x!=max(X1,X2)-(m-i)||w[i].y<w[i+1].y) goto lp1;
			ans+=M_PI*5;
			lp1:;
			if(m!=abs(Y2-Y1)+1) goto lp3;
			for(int i=m-1;i>0;--i) if(w[i].y<w[i+1].y) goto lp3;
			ans+=M_PI*5;
			lp3:;
			for(int i=m;i;--i) add(mp[w[i].y],ask(mp[w[i].y])+1);
		}
		else {
			if(w[1].x!=min(X1,X2)||m!=abs(X2-X1)+1) goto lp2;
			for(int i=2;i<=m;++i) if(w[i].x!=min(X1,X2)+i-1||w[i].y<w[i-1].y)  goto lp2;
			ans+=M_PI*5;
			lp2:;
			if(m!=abs(Y2-Y1)+1) goto lp4;
			for(int i=2;i<=m;++i) if(w[i].y<w[i-1].y) goto lp4;
			ans+=M_PI*5;
			lp4:;
			for(int i=1;i<=m;++i) add(mp[w[i].y],ask(mp[w[i].y])+1);
		}
		cout<<setprecision(50)<<ans-20.0*(double)ask(200000)+M_PI*(double)ask(200000)/2.0*10.0;
	}
	return 0;
}

Measured memory_bytes: 22144
#include <iostream>

using namespace std;

int main() {
    int N;
    int A[200];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    int cnt = 0;

    while (true) {
        bool flag = false;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 0) {
                continue;
            } else {
                flag = true;
            }
        }

        if (!flag) {
            cnt++;
            for (int i = 0; i < N; i++) {
                A[i] = A[i] / 2;
            }
        } else {
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int x[] = new int[3];
            x[0] = Integer.parseInt(in.next());
            x[1] = Integer.parseInt(in.next());
            x[2] = Integer.parseInt(in.next());

            Arrays.sort(x);

            // 出力
            out.println(x[2] * 10 + x[1] + x[0]);

        }

    }
}



Measured memory_bytes: 22996
import collections
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    s = collections.Counter(s)
    ans = 0
    for i in s.values():
        ans += (i*(i-1))//2
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 19732
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	 const int N =1e5+5;
    
     int mod= 1e9+7,INF=1e17;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
     
     int cv[N],sod,se;
     
     void solve(){
         
       int n;
       cin>>n;
       vi v(n+1,0),wyn(n,0),val(n+1,0);
       
       rep(i,1,n+1)
         cin>>v[i];
       
       rep(i,1,n+1){
		  if(i==2)
		   cv[i]=sod;
		 if(i>2)
			   cv[i]+=se-sod;
		  if(i&1)
		   sod+=v[i];
		  else
		   se+=v[i];	   
	   }
	   
	   
	   //~ rep(i,1,n+1)
	     //~ cout<<cv[i]<<" "; 
	     //~ cout<<endl;
	     
	   int x1=(v[n]-cv[n])/2;
	   //~ cout<<x1<<endl;
	   val[1]=x1;
	   val[2]=cv[2]-x1;
	   rep(i,3,n+1){
		   if(i&1)
		    val[i]=cv[i]+x1;
		}
		
		rep(i,1,n+1){
			 if(!(i&1)){				 
				 val[i]=v[i]-val[i+1];
			 }
		}
		
	  rep(i,1,n+1)
	     cout<<2*val[i]<<" "; 
			    
			  
	 }
	
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
vector <ll> BIT(4*N+5,0);
void update(ll ptr,ll idx,ll start,ll end,ll val)
{
	if(start==end)
	{
		BIT[ptr] = max(BIT[ptr],val);
		return;
	}
	ll mid = (start + end)/2;
	if(idx>=start && idx<=mid)
		update(2*ptr,idx,start,mid,val);
	else
		update(2*ptr+1,idx,mid+1,end,val);
	BIT[ptr] = max(BIT[ptr*2] , BIT[ptr*2+1]);
	return;
}

ll query(ll ptr,ll start,ll end,ll l,ll r)
{
	if(start>r || l>end || start>end)
		return 0;
	if(start>=l && end<=r)
		return BIT[ptr];
	ll mid = (start + end)/2;
	return max(query(2*ptr,start,mid,l,r),query(2*ptr+1,mid+1,end,l,r));
}	

int main()
{
    IO
	clock_t begin = clock();
    ll n;
    cin>>n;
    ll h[n+1],v[n+1];
    for(ll i=1;i<=n;i++)
    	cin>>h[i];
    for(ll i=1;i<=n;i++)
    	cin>>v[i];
    for(ll i=1;i<=n;i++)
    	update(1,i,1,n,0);
    vector <ll> dp(n+5,0);
    for(ll i=n;i>=1;i--)
    {
    	ll ans = query(1,1,n,h[i],n);
    	// cout<<ans<<endl;
    	dp[i] = v[i] + ans;
    	update(1,h[i],1,n,dp[i]);
    }
    ll ma = 0;
    for(ll i=1;i<=n;i++)
    	ma = max(ma,dp[i]);
    cout<<ma<<endl;
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 14348
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


class uf {
private:
	int par[100003], r[100003] = {}, size[100003];

public:
	int init(int n) {
		int i;
		for (i = 0; i < n; i++) {
			par[i] = i;
			size[i] = 1;
		}
	}

	int root(int a) {
		if (par[a] == a) return a;
		return par[a] = root(par[a]);
	}

	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (r[a] > r[b]) {
			par[b] = a;
			r[a]++;
			size[a] += size[b];
		}
		else {
			par[a] = b;
			r[b]++;
			size[b] += size[a];
		}
	}

	int show_size(int a) {
		return size[a];
	}
};

int main(void) {
	int n, m, k, i, j, l, a, b, c, d, t, frn[100003] = {};
	vector<int> bl[100003];

	uf fr;

	cin >> n >> m >> k;

	fr.init(n);

	for (i = 0; i < m; i++) {
		cin >> a >> b;
		fr.unite(a - 1, b - 1);
		frn[a - 1]++;
		frn[b - 1]++;
	}

	for (i = 0; i < k; i++) {
		cin >> c >> d;
		bl[c - 1].push_back(d - 1);
		bl[d - 1].push_back(c - 1);
	}

	for (i = 0; i < n; i++) {
		t = 0;
		for (j = 0; j < bl[i].size(); j++) {
			if (fr.root(i) == fr.root(bl[i][j])) {
				t++;
			}
		}
		cout << fr.show_size(fr.root(i)) - frn[i] - t - 1 << ' ';
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 7552
n = int(input())
st, sx, sy = 0, 0, 0

is_reach = True

for i in range(0, n):
    gt, gx, gy = list(map(int, input().split()))
    t = gt - sy
    dist = abs(gx - sx) + abs(gy - sy)

    if not(t >= dist and (t - dist) % 2 == 0):
        is_reach = False
        break


if is_reach:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Heap{
  using val_t=int32_t;
  const greater<val_t> comp;
  size_t n;
  vector<val_t> vec;
  Heap(): comp(), n(0), vec(1){}
  explicit Heap(size_t x): comp(), n(x), vec(x+1){}
  void max_heapify(size_t i){
    size_t largest=i;
    if(i*2 <= Heap::n) largest=(Heap::comp(Heap::vec[i*2],Heap::vec[largest]) ? i*2 : largest);
    if(i*2+1 <= Heap::n) largest=(Heap::comp(Heap::vec[i*2+1],Heap::vec[largest]) ? i*2+1 : largest);
    if(largest != i){
      swap(Heap::vec[largest], Heap::vec[i]);
      Heap::max_heapify(largest);
    }
  }
  void build_max_heap(){
    for(size_t i=Heap::n/2; i>=1; --i) Heap::max_heapify(i);
  }
  val_t extract_max(){
    val_t maxi=Heap::vec[1];
    swap(Heap::vec[1], Heap::vec[n]);
    --Heap::n; Heap::vec.pop_back();
    Heap::max_heapify(1);
    return maxi;
  }
  void max_heapify_rev(size_t i){
    if(i>1){
      if(Heap::comp(Heap::vec[i],Heap::vec[i/2])){
        swap(Heap::vec[i], Heap::vec[i/2]);
        Heap::max_heapify_rev(i/2);
      }
    }
  }
  void insert(val_t x){
    ++Heap::n; Heap::vec.push_back(x);
    max_heapify_rev(Heap::n);
  }
};
int32_t main(){
  // size_t n; cin>>n;
  // Heap h(n);
  // for(size_t i=1; i<=n; ++i) cin>>h.vec[i];
  // h.build_max_heap();
  // for(size_t i=1; i<=n; ++i) cout<<' '<<h.vec[i];
  // cout<<'\n';
  string cmd; int32_t x; Heap h;
  for(;;){
    cin>>cmd;
    switch(cmd[2]){
      case 's': cin>>x; h.insert(x); break;
      case 't': cout<<h.extract_max()<<'\n'; break;
      default: return 0;
    }
  }
}


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


void solve(long long N, std::string s, std::string t){
  for(long long i = 0; i < N; i++) {
    if(equal(s.begin()+i, s.end(), t.begin())) {
      cout << N+i << endl;
      return;
    }
  }

  cout << (N*2) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::string s;
  std::cin >> s;
  std::string t;
  std::cin >> t;
    solve(N, s, t);
    return 0;
}


Measured memory_bytes: 256
H = int(input())

A = []
count = 0

while(H>0):
  count += 1
  A.append(H)
  H = H//2

ans = 0
temp = 1
for i in range(count):
  if(i==0):
    ans += temp
  else:
    temp = temp*2
    ans += temp
    
print(ans)

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

using namespace std;

const int N = 1e5 + 7;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

const double pi = acos(-1);

int main() {
    double r; cin >> r;
    cout << setprecision(10) << (2.0 * pi * r) << endl;

    return 0;
}

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

using namespace std;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;

int N;
ll A[2<<18+5];

set<pair<int, int>> DP[2<<18+5];

set<pair<int, int>> f(int bs) {
	if (bs == 0) return {{A[0], 0}};
	if (DP[bs].size()) return DP[bs];
	set<pair<int, int>> ans = {{A[bs],bs}};
	FO(i, N) if (bs&(1<<i)) {
		auto s = f(bs&(~(1<<i)));
		// int a = s.begin()->first, b = s.rbegin()->first;
		// cout << bs << " " << (bs&(~(1<<i))) << " " << a << " " << b << endl;
		ans.insert(s.begin(), s.end());
		while (ans.size() > 2) ans.erase(ans.begin());
		// combine(ans, p);
	}
	// int a = ans.begin()->first, b = ans.rbegin()->first;
	// cout << bs << " = " << a << " " << b << endl;
	return DP[bs] = ans;
}


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

	cin >> N;
	FO(i, 1<<N) {
		DP[i].clear();
		cin >> A[i];
	}

	int ans = 0;
	for (int k = 1; k < (1<<N); ++k) {
		auto s = f(k);
		int a = s.begin()->first, b = s.rbegin()->first;
		ans = max(ans, a+b);
		cout << ans << "\n";
	}
	
}

Measured memory_bytes: 818304
num = list(map(int, input().split()))
a = num[0]
b = num[1]
c = num[2]

if a+b <= a+c:
	if a+b  <= b+c:
		print(a+b)
	else:
		print(b+c)
elif a+c <= b+c:
	print(a+c)
else:
	print(b+c)
	


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

const long long MINUS_INF = -1LL << 60;

struct UnionFind {
    vector<long long> par; // 親ノード
    vector<long long> rank; // ランク
    vector<long long> root_size; //ノードが根のときに、何個の子要素を持っているのか。(自分を含む)
                            //親じゃない場合は-1を出力

    UnionFind(long long n = 1) {
        init(n);
    }

    void init(long long n = 1) {
        par.resize(n); rank.resize(n); root_size.resize(n);
        for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0, root_size[i] = 1;
    }

    long long root(long long x) {
        if (par[x] == x) {
            return x;
        }
        else {
            long long r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(long long x, long long y) {
        return root(x) == root(y);
    }

    //yをxにマージ
    bool merge(long long x, long long y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        root_size[x] += root_size[y];
        root_size[y] = -1;
        return true;
    }

    long long size(long long x){
        x = root(x);
        return root_size[x];
    }
};

int main(){
    int N; cin >> N;
    long long K; cin >> K;


    vector<long long> C(N+1);
    vector<long long> P(N+1);
    for(int i=1; i<=N; ++i){
        cin >> P[i];
    }

    for(int i=1; i<=N; ++i){
        cin >> C[i];
    }

    UnionFind uf = UnionFind(N+1);

    //cycle_root, cycle_point.
    map<int, long long> m;


    for(int i=1; i<=N; ++i){
        uf.merge(i, P[i]);
    }

    for(int i=1; i<=N; ++i){
        uf.root(i);
        m[uf.root(i)] += C[P[i]];
    }



    long long ans = MINUS_INF;

    //最初に始める点
    for(int i=1; i<=N; ++i){

        //何回歩けるか
        long long rest_K = K;
        long long tmp_ans = 0;

        //サイクルが負なら一周のみ
        if(m[uf.root(i)] <= 0){
            long long cnt = min(rest_K, uf.root_size[uf.root(i)]);
            int t = P[i];
            for(int _=0; _< cnt; ++_){
                tmp_ans += C[t];
                ans = max(ans, tmp_ans);
                t = P[t];
            }
        }else{
        //正なら最後の一種になるまで動く
            long long cycle_size = uf.root_size[uf.root(i)];
            long long cycle_cnt = rest_K / cycle_size;
            long long rest = rest_K % cycle_size;

            if(rest == 0){
                cycle_cnt -= 1;
            }

            tmp_ans = cycle_cnt * m[uf.root(i)];
            ans = max(ans, tmp_ans);
            rest_K -= cycle_cnt * cycle_size;

            int t = P[i];
            while(rest_K){
                tmp_ans += C[t];
                ans = max(ans, tmp_ans);
                t = P[t];
                rest_K--;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
  int a,b,c;
  cin >>a >>b >>c;

  vector<int>n(100,0);
  for(int i=0; i<a; i++){
    if(a%(i+1)==0 && b%(i+1)==0){
      n[i]=-(i+1);
    }
  }
  
  sort(n.begin(),n.end());
  cout <<-n[c-1] <<endl;
}

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  bool ok = true;
  if (n % 2 == 1)
    ok = false;
  else
  {
    for (int i = 0; i < n / 2; i++)
    {
      if (s[i] != s[(n / 2) + i])
      {
        ok = false;
        break;
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

const int INF = 1e7;

struct node {
	pii rn;
	bool orig;

	node() {
		rn = pii(-INF,INF);
		orig = false;
	}
};

vector<node> V;
vector<vector<int> > E;
bool vis[100100];

pii dfs(int u, int pre, int parity) {
	vis[u] = true;
	if(V[u].orig) {
		if(parity == V[u].rn.fi % 2)
			return V[u].rn;
		return pii(1,-1);
	}
	pii res = V[pre].rn;
	res.fi--; res.se++;
	rep(i,E[u].size()) {
		int v;
		v = E[u][i];
		if(v == pre) continue;
		pii tmp;
		tmp = dfs(v,u, !parity);
		res.fi = max(res.fi, tmp.fi-1);
		res.se = min(res.se, tmp.se+1);
	}
	if(res.fi > res.se || (res.fi == res.se && res.fi % 2 != parity))
			res = pii(1,-1);
	return V[u].rn = res;
}

bool solve(int u, int pre) {
	if(V[u].orig) {
		//cout << "abs:" << (V[u].rn.fi) << "," << (V[pre].rn.fi) << endl;
		return abs(V[u].rn.fi - V[pre].rn.fi) == 1;
	}
	if(V[u].rn.fi <= V[pre].rn.fi+1 && V[pre].rn.fi+1 <= V[u].rn.se) {
		V[u].rn.fi = V[u].rn.se = V[pre].rn.fi+1;
	}
	else if(V[u].rn.fi <= V[pre].rn.fi-1 && V[pre].rn.fi-1 <= V[u].rn.se) {
		V[u].rn.fi = V[u].rn.se = V[pre].rn.fi-1;
	}
	else {
		//cout << u << endl;
		return false;
	}
	rep(i,E[u].size()) {
		if(E[u][i] == pre) continue;
		if(!solve(E[u][i], u)) {
			//cout <<"*"<< u << endl;
			return false;
		}
	}
	return true;
}

int main() {
	int N;
	cin >> N;
	V.resize(N);
	E.resize(N);
	rep(i,N-1) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		E[A].push_back(B);
		E[B].push_back(A);
	}
	int K;
	cin >> K;
	vector<pii> cost;
	rep(i,K) {
		int v, p;
		cin >> v >> p;
		v--;
		cost.push_back(pii(v,p));
		V[v].rn = pii(p,p);
		V[v].orig = true;
	}

	bool ok = true;
	rep(i,cost.size()) {
		rep(j,E[cost[i].fi].size()) {
			int v;
			v = E[cost[i].fi][j];
			if(!vis[v]) {
				pii tmp;
				tmp = dfs(v,cost[i].fi, !(cost[i].se % 2));
				if(tmp.fi > tmp.se) {
					ok = false;
				}
				else {
					if(!solve(v,cost[i].fi)) {
						ok = false;
					}
				}
			}
		}
	}
	if(ok) {
		cout << "Yes" << endl;
		rep(i,N) {
			cout << V[i].rn.fi << endl;
		}
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 12160
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
i = n
while i > 0:
    if s[i-7:i] == 'dreamer' and i-7 >= 0:
        i -= 7
    elif s[i-6:i] == 'eraser' and i-6 >= 0:
        i -= 6
    elif s[i-5:i] == 'dream' and i-5 >= 0:
        i -= 5
    elif s[i-5:i] == 'erase' and i-5 >= 0:
        i -= 5
    else:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 41452
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int test = 1;
    // cin >> test;
    while(test--) {
        long long  x,k,d;
        cin >> x >> k >> d;
        x = abs(x);
        if(x/d>=k) {
            cout << (x-k*d) << endl;
        }
        else {
            long long first = x%d;
            long long second = d-x%d;
            k = k-x/d;
            if(k%2) {
                cout << second << endl;
            }
            else {
                cout << first << endl;
            }
        }
    }
}

Measured memory_bytes: 3608
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
 
n=int(input())
arr=list(map(int,input().split()))
tmp=gcd(arr[0],arr[1])
for i in range(1,n):
  tmp=gcd(tmp,arr[i])
print(tmp)

Measured memory_bytes: 14224
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

ll fast_pow(ll a, ll n){
    if(n == 0) return 1;
    //べき数nが奇数, aを前にだして, a^n-1の気持ちに
    if(n % 2 == 1){
        return a * fast_pow(a, n - 1) % MOD;
    }else{
        //べき数nが偶数のとき，べき数を半分にして, aをまとめる. べき数を半分にする
        return fast_pow(a * a % MOD, n / 2) % MOD;
    }
}


int main() {

    ll N, K;
    cin >> N >> K;

    ll ans = fast_pow(K-1, N-1) * K;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const ll MAX_N = 1e7;
ll _par[MAX_N];//親                                                                                    
ll _rank[MAX_N];//木の深さ                                                                             

//n要素で初期化 parは親の要素の番号                                                                     
void init(ll n){
  for(ll i=0; i<n; i++){
    _par[i] = i;
    _rank[i]=0;
  }
}

//木の根を求める                                                                                        
int find(ll x){
  if(_par[x]==x){
    return x;
  }
  else{
    return _par[x] = find(_par[x]);
  }
}

//xとyの属する集合の併合                                                                                
void unite(ll x, ll y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if (_rank[x] < _rank[y]){
    _par[x] = y;
  }else{
    _par[y]=x;
    if(_rank[x] == _rank[y])_rank[x]++;
  }
}

//xとyが同じ集合に属するか否か                                                                          
bool same(ll x, ll y){
  return find(x) == find(y);
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,M;
  cin >> N >> M;
  ll A[M],B[M];
  ll a,b;
  rep(i,M){
    cin >> a >> b;
    A[i]=a-1; B[i]=b-1;
  }
  init(N);
  ll ans[M];
  ans[M-1] = N*(N-1)/2;
  
  ll count[N];
  rep(i,N) count[i]=1LL;
  for(int i=M-1; i>0; i--){
    //    cout << ans[i] << endl;
    if(same(A[i],B[i])){
      ans[i-1]=ans[i];
    }
    else{
      int ca = count[find(A[i])];
      int cb = count[find(B[i])];
      ans[i-1]=ans[i]-ca*cb;
      //      cout << count[A[i]] << " " << count[B[i]] << endl;
      count[find(A[i])]+=count[find(B[i])];
      count[find(B[i])]=count[find(A[i])];
      //      count[A[i]]+=count[B[i]];
      //      count[B[i]]= count[A[i]];
      //      cout << count[A[i]] << " " << count[B[i]] << endl;
      //ans[i-1]=ans[i]-count[A[i]]*count[B[i]];
      //      count[A[i]]+=count[B[i]];
      //      count[B[i]]= count[A[i]];
    }    
    unite(A[i],B[i]);   
  }
  rep(i,M) cout << ans[i] << endl;
  
  return 0;
    

}


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

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=22e4,M=N<<1,K=M<<1;

inline int read()
{
	int o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+(ch^48);
	return o;
}

int ne[K],la[M],lb[K],c[K],bb[N][2];
int dep[M];
int y[M];

int fa[N],re[N];
int gs[N];
int ke[M];
int be[N],en[N];
int n,m,S,T,oo;
int d[M];

inline int get(int o)
{return (fa[o]==o)?(o):(fa[o]=get(fa[o]));}

inline void llb(int a,int b,int cc)
{ne[++oo]=la[a]; la[a]=oo; lb[oo]=b; c[oo]=cc;}

inline void bfs()
{
	fo(i,1,T)dep[i]=-1;
	dep[S]=0;
	int l=0,r=1;
	d[r]=S;
	while(l<r){
		int o=d[++l];
		for(int y=la[o];y;y=ne[y])
		if(c[y]==1&&dep[lb[y]]==-1){
			dep[lb[y]]=dep[o]+1;
			d[++r]=lb[y];
		}
	}
	fo(i,1,T)y[i]=la[i];
}

inline int flow(int o)
{
	if(o==T)return 1;
	for(;y[o];y[o]=ne[y[o]])
	if(dep[lb[y[o]]]==dep[o]+1&&c[y[o]])
	if(flow(lb[y[o]])){
		c[y[o]]=0;
		c[y[o]^1]=1;
		return 1;
	}
	dep[o]=-1;
	return 0;
}

inline void dg(int o)
{
	for(int y=la[o];y;y=ne[y])
	if(!fa[lb[y]]){
		fa[lb[y]]=o;
		bb[re[lb[y]]][0]=o;
		bb[re[lb[y]]][1]=lb[y];
		++oo;
		dg(lb[y]);
	}
}

int main()
{
	scanf("%d",&n);
	fo(i,1,n)fa[i]=i;
	fo(i,1,n-1){
		gs[i]=read();
		be[i]=oo+1; 
		fo(l,1,gs[i]){
			ke[++oo]=read();
			if(l!=1)
			if(get(ke[oo-1])!=get(ke[oo]))fa[fa[ke[oo]]]=fa[ke[oo-1]];
		}
		en[i]=oo;
	}
	int kk=get(1);
	fo(i,2,n)if(get(i)!=kk){
		puts("-1");
		return 0;
	}
	
	S=n*2,T=S^1,oo=1;
	fo(i,1,n)llb(S,i,1),llb(i,S,0);
	fo(i,1,n-1)fo(l,be[i],en[i])llb(ke[l],n+i,1),llb(n+i,ke[l],0);
	fo(i,1,n-1)llb(n+i,T,1),llb(T,n+i,0);
	
	int ans=0;
	while(true){
		bfs();
		if(dep[T]==-1)break;
		else while(flow(S))++ans;
	}
	
	if(ans!=n-1){
		puts("-1");
		return 0;
	}
	
	int root=0;
	fo(i,1,n)fa[i]=0;
	fo(i,1,n){
		int ok=0;
		for(int y=la[i];y;y=ne[y])
		if(c[y]==0&&lb[y]!=S){
			re[i]=lb[y]-n;
			ok=1; break;
		}
		if(!ok)root=i;
	}
	
	oo=0;
	fo(i,1,n)la[i]=fa[i]=0;
	fo(i,1,n)if(root!=i)
	fo(l,be[re[i]],en[re[i]])if(ke[l]!=i)llb(ke[l],i,0);
	fa[root]=-1;
	oo=0;
	dg(root);
	if(oo!=n-1)puts("-1");
	else fo(i,1,n-1)printf("%d %d\n",bb[i][0],bb[i][1]);
}

Measured memory_bytes: 26368
#include <cstdio>
#include <algorithm>
#define FOR(i, l, r) for(int i = l;  i <= r; ++i)

using namespace std;

const int N = 200010;
int ans, n, k, x, sum[N];
bool cmp(int a, int b) {return a > b;}

int main()
{
    scanf("%d%d", &n, &k);
    FOR(i, 1, n)
    {
        scanf("%d", &x);
        ++sum[x];
    }
    sort(sum + 1, sum + N, cmp);
    FOR(i, k + 1, N - 1) ans += sum[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll> 
#define vv vector<v>
#define p pair<ll,ll>
#define mid (start+end)/2
#define fi first
#define se second	
int main() {
	int n;
	cin>>n;
	v a(n+10,0),b(n+1,0);
	for (int i=1; i<=n+1; i++)
		cin>>a[i];
	for (int i=1; i<=n;i++)
		cin>>b[i];
	ll ans=0;
	for (int i=1; i<=n; i++)
	{
		ll temp=min(a[i],b[i]);
		a[i]-=temp;
		b[i]-=temp;
		ll temp2=min(a[i+1],b[i]);
		a[i+1]-=temp2;
		b[i]-=temp2;
		ans+=temp2+temp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
$cnt = 0
def insertion_sort(arr, n, g)
  (g...n).each {|i|
    v = arr[i]
    j = i - g
    while j >= 0 && arr[j] > v
      arr[j + g] = arr[j]
      j = j - g
      $cnt += 1
    end
    arr[j + g] = v
  }
end

def shell_sort(arr, n)
  $cnt = 0

  g = []
  interval = 1
  while interval <= n
    g << interval
    interval = 3 * interval + 1
  end
  g.reverse!
  m = g.size
  puts m
  puts g.join(" ")
  (0...m).each {|i|
    insertion_sort(arr, n, g[i])
  }
end

n = gets.to_i
arr = n.times.map{gets.to_i}
shell_sort(arr, n)
puts $cnt
puts arr


Measured memory_bytes: 16776
#include<stdio.h>

int main(){
  int W,H,N;
  int i;
  int X[1001]={};
  int Y[1001]={};
  int ans=0;
  int dx,dy;

  scanf("%d%d%d",&W,&H,&N);
  for(i=0;i<N;i++)
    scanf("%d%d", &X[i],&Y[i]);

  for(i=1;i<N;i++){
    dx=X[i]-X[i-1];
    dy=Y[i]-Y[i-1];
    if(dx>=0&&dy>=0){
      if(dx>dy) ans+=dx;
      else ans+=dy;
    }
    else if(dx<=0&&dy<=0){
      if(-dx>-dy) ans += (-dx);
      else ans += (-dy);
    }
    else if(dx>0&&dy<0) ans+= (dx-dy);
    else ans+= (dy-dx);
  }
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 604
N,Y=(int(x) for x in input().split())
# YY現在の金額
# n:使える枚数
F=0
Y=Y/1000
for i in range(N+1):
    for j in range(N+1-i):
        if (Y-10*i-5*j)==(N-i-j):
            print(i,j,N-i-j)
            F=1
        else:
            continue
    if F==1:break
    

else:
    print("-1 -1 -1")

Measured memory_bytes: 3064
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

A,B,C = imn()

ans = min(A+B+1, C)
ans+= B
print(ans)

Measured memory_bytes: 5680
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

string T[4] = {
	"dream","dreamer","erase","eraser"
};


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

	string S;
	cin >> S;

	bool flg = true;

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++)
	{
		reverse(T[i].begin(), T[i].end());
	}

	int num = (int)S.size();
	int X = 0;

	while (1) {
		bool can = false;

		if (X == num) {
			break;
		}

		for (int i = 0; i < 4; i++)
		{
			string tmp = S.substr(X, T[i].size());
			if (tmp == T[i]) {
				can = true;
				X += (int)T[i].size();
				break;
			}
		}

		if (can == false) {
			flg = false;
			break;
		}
	}

	if (flg) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <string.h>

using namespace std;

int w, h;
bool b[20][20];
bool ok[20][20];

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

void dfs(int x, int y){
	for(int i=0;i<4;i++){
		if(0<=x+dx[i]&&x+dx[i]<w&&0<=y+dy[i]&&y+dy[i]<h){
			if(!b[y+dy[i]][x+dx[i]]) continue;
			if(ok[y+dy[i]][x+dx[i]]) continue;
			ok[y+dy[i]][x+dx[i]] = true;
			dfs(x+dx[i],y+dy[i]);
		}
	}
}

int main(){
	while(cin >> w >> h){
		if(!w) break;
		int x, y;
		string s;
		memset(b,false,sizeof(b));
		for(int i=0;i<h;i++){
			cin >> s;
			for(int j=0;j<w;j++){
				b[i][j] = (s[j] !='#');
				if(s[j]=='@') x = j, y = i;
			}
		}
		memset(ok,false,sizeof(ok));
		ok[y][x] = true;
		dfs(x,y);
		int count = 0;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				count += ok[i][j];
		cout << count << endl;
	}
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int t1=h1*60+m1,t2=h2*60+m2;
    cout<<t2-t1-k<<endl;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int cost[2500*30][52];
int cnt = 0;
int N;
int A[52][51];
vector<int>G[2500*30];
void connect(int x,int y,int num){
  int p = x;
  for(int i=0;i<num-1;i++){
    G[p].push_back( cnt );
    G[cnt].push_back( p );
    p = cnt++;
  }
  G[p].push_back( y );
  G[y].push_back( p );
}

void update(int id){
  queue<int> q;
  q.push( id );
  cost[id][id] = 0;
  while( !q.empty() ){
    int p = q.front();  q.pop();
    for(int i=0;i<(int)G[p].size();i++){
      int to = G[p][i];
      if( cost[to][id] == -1 ) {
        cost[to][id] = cost[p][id]+1;
        //         cout <<"cost " <<  to << " "<<id<< " "<< cost[to][id] << endl;
        q.push( to );
      }
    }
  }
}

int check(int x,int y){
  int c = A[x][0];
  int pc = cost[y][0];
  int comp = c - pc;
  //  cout << "check " << x << " "<< y << endl;
  // cout << c << " "<< pc << " " << comp << endl;
  if( pc < 0 || comp < 1 ) return 0;
  for(int i=1;i<x;i++){
    c = A[x][i];
    pc = cost[y][i];
    //cout << i << " : " << c << " "<< pc << " " << c - pc << endl;
    if( comp != c - pc ) return 0;
  }
  return comp;
}

void solve(){
  connect(0,1,A[0][1]);
  for(int i=2;i<N;i++){
    memset(cost,-1,sizeof(cost));
    for(int j=0;j<i;j++) update(j);
    for(int j=N;j<cnt;j++){
      int sc = check(i,j);
      if( sc ) {
        connect(i,j,sc);
        break;
      }
    }
  }
}

int main(){
  while(cin >> N&&N){
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        cin >> A[i][j];      
    cnt = N;
    solve();
    vector<int> ans;

    /* 
    cout << "debug " << endl;
    for(int i=0;i<cnt;i++){
      cout << "node : " << i << endl;
      for(int j=0;j<(int)G[i].size();j++){
        cout << " - > " << G[i][j] << endl;
      }
    }
    */

    for(int i=0;i<N;i++) G[i].clear();
    for(int i=N;i<cnt;i++){
      ans.push_back(G[i].size());
      G[i].clear();
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++){
      if( i ) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }

}

Measured memory_bytes: 18260
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  // 5, 9, 13
  int dx1[] = {-1,0,0,0,1};
  int dy1[] = {0,-1,0,1,0};
  int dx2[] = {-1,-1,-1,0,0,0,1,1,1};
  int dy2[] = {-1,0,1,-1,0,1,-1,0,1};
  int dx3[] = {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2};
  int dy3[] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
  vector<int> dx[3];
  vector<int> dy[3];
  dx[0].assign(dx1,dx1+5);
  dx[1].assign(dx2,dx2+9);
  dx[2].assign(dx3,dx3+13);
  dy[0].assign(dy1,dy1+5);
  dy[1].assign(dy2,dy2+9);
  dy[2].assign(dy3,dy3+13);
  
  int x, y, s;
  int ans1 = 100;
  int ans2 = 0;
  int ma[10][10];
  memset(ma,0,sizeof(ma));
  while(scanf("%d,%d,%d", &x,&y,&s)==3) {
    s--;
    REP(i,dx[s].size()) {
      int xx = x + dx[s][i];
      int yy = y + dy[s][i];
      if (xx<0||10<=xx||yy<0||10<=yy) continue;
      if (ma[xx][yy]==0) ans1--;
      ma[xx][yy]++;
      ans2 = max(ma[xx][yy], ans2);
    }

  }
  cout << ans1 << endl;
  cout << ans2 << endl;
}

Measured memory_bytes: 0