akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t h,w;
    cin >> h >> w;
    vector<string> s(h);
    vector<string> res(h);
    rep(i,h) cin >> s.at(i);
    string s_;
    rep(i,w) s_.push_back('#');
    rep(i,h) res.at(i) = s_;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s.at(i).at(j) == '.'){
                int64_t num = 0;
                // 上の列
                if(i>0){
                    if(j>0) num += s.at(i-1).at(j-1)=='#';
                    num += s.at(i-1).at(j)=='#';
                    if(j<w-1) num += s.at(i-1).at(j+1)=='#';
                }
                // 同じ列
                {
                    if(j>0) num += s.at(i).at(j-1)=='#';
                    if(j<w-1) num += s.at(i).at(j+1)=='#';
                }
                // 下の列
                if(i<h-1){
                    if(j>0) num += s.at(i+1).at(j-1)=='#';
                    num += s.at(i+1).at(j)=='#';
                    if(j<w-1) num += s.at(i+1).at(j+1)=='#';
                }
                res.at(i).at(j) = num+48;
            }
        }
    }
    rep(i,h){
        cout << res.at(i) << endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int dp[10];


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

	fill_n(dp, 10, -INF);
	dp[0] = 0;
	int n;
	cin >> n;
	rep(i,n) {
		int s;
		cin >> s;
		int nxt[10];
		fill_n(nxt, 10, -INF);
		rep(j,10) {
			nxt[j] = max(nxt[j], dp[j]);
			nxt[(j + s) % 10] = max(nxt[(j + s) % 10], dp[j] + s);
		}
		copy(nxt, nxt +10, dp);
	}
	cout << max(0,*max_element(dp+1, dp + 10)) << endl;

	return 0;
}

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

int main()
{
  int L,R,d,result=0;
  cin >> L >> R >> d;
  for(int i=L;i<=R;i++){
    if(i%d==0){
      result += 1;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int k, x; cin >> k >> x;
    for (int i = x-k+1; i < x+k; ++i) {
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
open Printf
open Scanf

let id x = x
let tuple x y = (x, y)

let print_array w a =
  Array.iter (fun a' ->
              Array.iteri (fun i x ->
                           if i = w-1 then printf "%d\n" x
                           else printf "%d " x)
                          a') a
             
let () =
  let h, w = scanf "%d %d " tuple in
  let a = Array.make_matrix h w 0 in
  let n = scanf "%d " id in
  let rec read x ls =
    if x = 0 then (List.rev ls)
    else let d = scanf "%d " id in read (x-1) (d :: ls) in
  let cs = read n [] in
  let rec replicate x y =
    if x = 0 then []
    else y :: replicate (x-1) y in
  let rec c_ex c = function
      [] -> []
    | h :: t -> replicate h c :: c_ex (c+1) t in
  let cs' = List.concat (c_ex 1 cs) in
  let rec loop i j di cs =
    if i = h then ()
    else if di = 0 && j = w then loop (i+1) (j-1) 1 cs
    else if di = 1 && j = (-1) then loop (i+1) 0 0 cs
    else begin
        a.(i).(j) <- (List.hd cs);
        if di = 0 then loop i (j+1) 0 (List.tl cs) else loop i (j-1) 1 (List.tl cs)
      end
  in
  loop 0 0 0 cs'; print_array w a


Measured memory_bytes: 5120
#include<iostream>
using namespace std;
int main()
{
   int n;
   cin>>n;
   string a,b;
   cin>>a;
   cin>>b;

   string p = "";
   for(int i=0;i<a.size();i++)
   {
       p = p+a[i];
       p = p+b[i];
   }
   cout<<p;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s = {a, b, c};
    if (s.size() == 2)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
int d[n];
int cnt =1;
for(int i =0;i<n;i++)
{
    cin>>d[i];
}
sort(d,d+n);
for(int i =1;i<n;i++)
{
    if(d[i]!=d[i-1]) cnt++;
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
	
	int R;
	scanf("%d",&R);
	if(R<1200){
		printf("ABC\n");
	}
	else if(R>=1200 && R<2800){
		printf("ARC\n");
	}
	else if(R>=2800){
		printf("AGC\n");
	}
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  for(int i=1; i<=9;i++)for(int j=1;j<=9;j++){
    if(i*j==n){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
s_set = list(set(s))
t_set = list(set(t))

for j in range(len(s_set)):
    tmp = []
    for k in range(len(s)):
        if s_set[j] == s[k]:
            tmp.append(t[k])
    if len(set(tmp)) > 1:
        print('No')
        exit()

for p in range(len(t_set)):
    tmp = []
    for q in range(len(t)):
        if t_set[p] == t[q]:
            tmp.append(s[q])
    if len(set(tmp)) > 1:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 7472
#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 a,b;
    cin >> a >> b;
    if(a<=9&&b<=9)cout << a*b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i < n-2; i++) {
    if(s.substr(i,3)=="ABC")
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <climits>
using namespace std;

int dp[100001];
vector<list<int>> graph(100001);

int longest_path(int src) {
    if (dp[src] != -1) {
        return dp[src];
    }
    int length = 0;
    for (int child : graph[src]) {
        length = max(length, 1 + longest_path(child));
    }
    return dp[src] = length;
}

int main() {
    int n, m, x, y;
    cin >> n >> m;
    int path = 0;
    while (m--) {
        cin >> x >> y;
        graph[x].push_back(y);
    }
   
    for (int i = 0; i <= n; i++) {
        dp[i] = -1;
    }
    for (int i = 1; i <= n; ++i) {
        path = max(path, longest_path(i));
    }
    cout << path << endl;
    return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long n;int m,q,a[1<<17];
bool f[7][1<<18];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void bfs(int x,int y,long _n)
{
	queue<pair<int,int> >P;
	f[x][y]=true;
	P.push(make_pair(x,y));
	while(!P.empty())
	{
		pair<int,int>p=P.front();P.pop();
		for(int r=0;r<4;r++)
		{
			int tx=p.first+dx[r],ty=p.second+dy[r];
			if(tx<0||ty<0||tx>=7||ty>=_n||f[tx][ty])continue;
			f[tx][ty]=true;
			P.push(make_pair(tx,ty));
		}
	}
}
main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i];
	}
	if(n<=100000)
	{
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<n;j++)
			{
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long ans=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(!f[i][j])
				{
					ans++;
					bfs(i,j,n);
				}
			}
		}
		cout<<ans<<endl;
	}
	else if(m%7==0)
	{
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m/7*2;j++)
			{
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long count1=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m/7*2;j++)
			{
				if(!f[i][j])
				{
					count1++;
					bfs(i,j,m/7*2);
				}
			}
		}
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m/7*3;j++)
			{
				f[i][j]=false;
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long count2=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m/7*3;j++)
			{
				if(!f[i][j])
				{
					count2++;
					bfs(i,j,m/7*3);
				}
			}
		}
		long kousa=count2-count1;
		long syokou=count1-kousa*2;
		cout<<syokou+kousa*(n/(m/7))<<endl;
	}
	else
	{
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m;j++)
			{
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long count1=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(!f[i][j])
				{
					count1++;
					bfs(i,j,m);
				}
			}
		}
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<2*m;j++)
			{
				f[i][j]=false;
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long count2=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<2*m;j++)
			{
				if(!f[i][j])
				{
					count2++;
					bfs(i,j,2*m);
				}
			}
		}
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<n-n/m*m+m;j++)
			{
				f[i][j]=false;
				int b=(j*7+i)%m;
				if(upper_bound(a,a+q,b)!=lower_bound(a,a+q,b))f[i][j]=true;
			}
		}
		long count3=0;
		for(int i=0;i<7;i++)
		{
			for(int j=0;j<n-n/m*m+m;j++)
			{
				if(!f[i][j])
				{
					count3++;
					bfs(i,j,n-n/m*m+m);
				}
			}
		}
		long kousa=count2-count1;
		long syokou=count1-kousa;
		long amari=count3-syokou-kousa;
		cout<<syokou+kousa*n/m+amari<<endl;
	}
}


Measured memory_bytes: 1664
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
S = sr()
if len(S) <= K:
    answer = S
else:
    answer = S[:K] + '...'

print(answer)


Measured memory_bytes: 9172
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    int dp[n+1][m+1];
    for(int i=0;i<=m;i++)
    {
        dp[0][i]=0;
    }
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans="";
    int i=n,j=m;
    while(i>0 && j>0)
    {
        if(a[i-1]==b[j-1])
        {
            ans+=a[i-1];
            i--;j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 38800
#include<stdio.h>

int main(void)
{
	char S[10];
	scanf("%s", &S);
	if(S[0] == 'S'){printf("Cloudy\n");}
	if(S[0] == 'C'){printf("Rainy\n");}
	if(S[0] == 'R'){printf("Sunny\n");}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end());
#define MAX(vec) *max_element(vec.begin(), vec.end());
#define IN(n,m)  (!(m.find(n) == m.end()))
#define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }

using namespace std;
typedef pair<long,long> pr;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef map<pair<long,long>,long> mp;

class Union_Find {
private:
    vector<unsigned> par;    // par[x] : x の親ノード
    vector<unsigned> rank;   // rank[x] : 木の高さ
    size_t sz;             // 集合の個数
public:   
    // コンストラクタ : 空
    Union_Find() : sz(0) { }

    // コンストラクタ : 1 要素の集合 n 個
    Union_Find(size_t n) :
        par(n, -1), rank(n, 0), sz(n) {
        for (size_t i = 0; i < n; i++) par[i] = i;
    }

    size_t size() { return sz; }

    // 集合の追加 : 1 個
    void add_node() {
        par.push_back(par.size());
        rank.push_back(0);
        sz++;
    }
    // 集合の追加 : n 個
    void add_node(size_t n) {
        for (size_t i = 0; i < n; i++) add_node();
    }

    // x が属する集合の代表元を返す
    size_t find(size_t x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    // x が属する集合と y が属する集合をマージする
    void unite(size_t x, size_t 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]++;
        }
        sz--;
    }
    // x と y が同じ集合に属しているか？
    bool same(size_t x, size_t y) {
        return find(x) == find(y);
    }
    
    void dump_par(void){
        dump1d_arr(par);
    }

    void dump_rank(void){
        dump1d_arr(rank);
    }
};
int main(void){
    long N,K,L;
    long p,q;
    mp group;
    cin >> N >> K >> L;
    Union_Find uf(N);
    Union_Find uf2(N);
    vector<pr> par(N);
    REP(i,K){
        cin >> p >> q;
        uf.unite(p-1,q-1);
    }
    REP(i,L){
        cin >> p >> q;
        uf2.unite(p-1,q-1);
    }

    REP(i,N){
        par[i] = pr ((long)uf.find(i),(long)uf2.find(i));
        group[par[i]]++;  
    }

    REP(i,N){
        cout << group[par[i]] << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 105;

int n, m;
int a[maxn][maxn];
int dis[maxn][maxn][2];
char s[maxn][maxn];

inline void umin(int &x, int y){
	x = min(x, y);
	return;
}

int main(){
	scanf("%d%d", &n, &m);
	FOR(i, 0, n){
		scanf("%s", s[i]);
		FOR(j, 0, m)
			a[i][j] = (s[i][j] == '#');
	}
	memset(dis, 0x3f, sizeof(dis));
	dis[0][0][a[0][0]] = 0;
	FOR(i, 0, n) FOR(j, 0, m) FOR(o, 0, 2) if(a[i][j] == o){
		if(i){
			umin(dis[i][j][o], dis[i - 1][j][o]);
			umin(dis[i][j][o], dis[i - 1][j][o ^ 1] + (!o));
		}
		if(j){
			umin(dis[i][j][o], dis[i][j - 1][o]);
			umin(dis[i][j][o], dis[i][j - 1][o ^ 1] + (!o));
		}
	}
	printf("%d\n", min(dis[n - 1][m - 1][0], dis[n - 1][m - 1][1] + 1));
	return 0;
}


Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
r=[0]*9
for a in A:
  for i in range(8,-1,-1):
    if a >= 400*i:
      r[i]+=1
      break
ans=0
for i in range(8):
  if r[i]>0: ans+=1
if ans==0: print(1, r[8])
else: print(ans, ans+r[8])


Measured memory_bytes: 3060
# coding: utf-8
# Your code here!
n=int(input())

s=list(input())
for i in range(len(s)):
    if ord(s[i])+n>90:
        print(chr(ord(s[i])+n-26),end="")
    else:
        print(chr(ord(s[i])+n),end="")
    


Measured memory_bytes: 75632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

signed main() {
  string s, t;
  cin >> s;
  cin >> t;
  set<char> sset, tset;
  for (char schar : s) sset.insert(schar);
  for (char tchar : t) tset.insert(tchar);
  for (char c : tset) {
    auto it = sset.find(c);
    if (it == sset.end()) {
      cout << -1 << endl;
      exit(0);
    }
  }

  vector<vector<int>> alph_pos;
  rep(i,26) {
    vector<int> v;
    alph_pos.push_back(v);
  }
  rep(pos,s.size()) {
    alph_pos[s[pos] - 'a'].push_back(pos);
  }

  vector<vector<int>> next_table;
  rep(pos,s.size()) {
    vector<int> next_pos;
    rep(alph,26) {
      const auto& candidates = alph_pos[alph];
      if (candidates.empty()) {
        next_pos.push_back(-1);
        continue;
      }
      auto it = upper_bound(all(candidates), pos);
      if (it == candidates.end()) it = candidates.begin();
      int next = *it;
      if (next > pos) {
        next_pos.push_back(next - pos);
      } else {
        next_pos.push_back(s.size() - (pos - next));
      }
    }
    next_table.push_back(next_pos);
  }

  long ans = -1;
  rep(i,t.size()) {
    int alph = t[i] - 'a';
    int current = (ans + s.size()) % s.size();
    int distance = next_table[current][alph];
    ans += distance;
  }
  cout << (ans + 1) << endl;
}


Measured memory_bytes: 14768
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#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(){
    cin.tie(0);
    ll a,ans;
    cin >> a;

    if(a==100000){
        ans=9+900+90000; 
    } else if(10000<=a && a<100000){
        ans=9+900+a-9999;
    } else if(1000<=a && a<10000){
        ans=9+900;
    } else if(100<=a && a<1000){
        ans=9+a-99;
    } else if(10<=a && a<100){
        ans=9;
    } else if(a<10){
        ans=a;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n , A , B , C , arr[10] , INF = 1e9;
int calc(int i , int a , int b , int c){
    if(i == n){
        if(a && b && c)
            return abs(a - A) + abs(b - B) + abs(c - C);
        return INF;
    }
    int ret = calc(i + 1 , a , b , c);
    ret = min(ret , calc(i + 1 , a + arr[i] , b , c) + ((a != 0) ? 10 : 0 ));
    ret = min(ret , calc(i + 1 , a , b + arr[i] , c) + ((b != 0) ? 10 : 0));
    ret = min(ret , calc(i + 1 , a , b , c + arr[i])  + ((c != 0) ? 10 : 0));
    return ret;
}
int main(){
    cin >> n >> A >> B >> C;
    for(int i = 0 ; i < n ; i++)
            cin >> arr[i];
    cout<<calc(0 , 0 , 0 , 0);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int x,y,z;cin>>x>>y>>z;
    int res=0; x-=z;
    res += x/(y+z);
    cout<<res<<endl;
}


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

list<int> n, m, result, X;
int x;
int nminus = 0, mminus = 0;
int nO = 0, mO = 0;

void input(){
    string N, M;
    cin >> N >> M;
    if (N[0] == '-') nminus = 1;
    if (M[0] == '-') mminus = 1;
    for(int i = nminus; i < N.length(); i++) n.push_front(N[i] - '0');
    if (N[nminus] == '0') nO = 1;
    for(int i = mminus; i < M.length(); i++) m.push_front(M[i] - '0');
    if (M[mminus] == '0') mO = 1;
}

void computemult(list<int> *n, list<int> *m) {
    if ((*m).empty()) {
        while(!(X.empty())){
            x = x + *(X.begin());
            result.push_front(x % 10);
            x = x / 10;
            X.pop_front();
        }
        if (x != 0)  result.push_front(x);
        return;
    }
    list<int>::iterator itn = (*n).begin();
    list<int>::iterator itX = X.begin();
    int M = *((*m).begin());
    while(itn != (*n).end()) {
        x = M * *itn + *itX + x;
        *itX = x % 10;
        x = x / 10;
        itn++; itX++;
    }
    if (x != 0) *itX = x;
    x = 0;
    result.push_front(*(X.begin()));
    X.pop_front();
    (*m).pop_front();
    computemult(n, m);
    return;
}

int main(void){
    input();
    if (nO + mO > 0) {
        cout << 0 << endl;
        return 0;
    }
    X.resize(n.size() + m.size() + 1, 0);
    if(nminus != mminus) cout << "-";
    computemult(&n, &m);
    while(*(result.begin()) == 0) result.pop_front();
    while(!(result.empty())){
        cout << *(result.begin());
        result.pop_front();
    }
    cout << endl;
    return 0;
}



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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n,k;cin>>n>>k;

  if (n%k) {
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	string s,t;
	int flag=0;
	cin >> s;
	cin >> t;
	s = s+s;
	for(int i=0;i<s.size()-t.size();i++){
		flag = 1;
		for(int j=0;j<t.size();j++){
			if(t[j]!=s[i+j]){
					flag = 0;
					break;
			}
		}
		if(flag==1){
				cout << "Yes\n";
				return 0;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n;cin>>n;
    int ans=0;
    char gri[605][605];
    rep(i,0,n)rep(j,0,n){
        cin>>gri[i][j];
        gri[i][j+n]=gri[i][j];
        gri[i+n][j]=gri[i][j];
        gri[i+n][j+n]=gri[i][j];
    }
    rep(k,0,n){
        bool ch=true;
        rep(i,0,n){
            rep(j,0,n){
                if(gri[i][j+k]!=gri[j][i+k])ch=false;
            }
        }
        if(ch)ans+=n;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
#define first F
#define second S
typedef long long ll;

int main(){
	int n; cin>>n;
	n-=1;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	ll rta = arr[0] + arr[n-1];
	for(int i=n-1; i>0; i--){
		rta+=min(arr[i], arr[i-1]);
	}
	cout<<rta<<endl;
}


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

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

	vector<double> pr(n + 1);
	pr[0] = 0;
	for (int i = 1; i < n + 1; ++i) {
		double p;
		cin >> p;
		pr[i] = pr[i - 1] + (p + 1) / 2;
	}

	double m = 0;
	for (int i = 1; i <= n - k + 1; ++i) {
		m = max(m, pr[i + k - 1] - pr[i - 1]);
	}

	cout << fixed << setprecision(6) << m;
	
	return 0;
}
	

Measured memory_bytes: 1792
#include <stdio.h>
#define abs(a) ((a)>(0)?(a):-(a))
int gcd(int *sub,int n){
  int a,b,c;
  if(n>1)a=gcd(sub,n-1);
  else a=sub[0];
  b=sub[n];
  if (a<b) {
    a+=b; b=a-b; a-=b;
  }
  while (b!=0) {
    c=a%b; a=b; b=c;
  }
  return a;
}
int main(){
  int n,i,X;
  scanf("%d%d",&n,&X);
  int x[n],sub[n];
  for(i=0;i<n;i++)scanf("%d",&x[i]);
  for(i=0;i<n;i++)sub[i]=abs(x[i]-X);
  printf("%d",gcd(sub,n-1));
}

Measured memory_bytes: 4096
#include <stdio.h>

int main(void){
        int i, j, k, h[10000], w[10000], sum=0;
        for(k=0;k<10000;k++){
                scanf("%d %d", &h[k], &w[k]);
                if(h[k]==0 && w[k]==0)
                        break;
                sum++;
        }
        for(k=0;k<sum;k++){
                for(i=0;i<h[k];i++){
                        for(j=0;j<w[k];j++){
                                if((i+j)%2==0)
                                        putchar('#');
                                else
                                        putchar('.');
                        }
                        putchar('\n');
                }
                putchar('\n');
        }
        return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using namespace std; using INT = int64_t; using II = pair<INT, INT>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;

signed main() {
  string s; cin >> s;
  int a = 0, b = 0;
  for (char c: s) {
    if (c == '0') {
      a++;
    } else {
      b++;
    }
  }
  cout << 2 * min(a, b) << endl;
}


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

typedef long long ll ;


int main() {
    int N;
    cin>>N;
    vector<int> C(N);
    vector<int> S(N);
    vector<int> F(N);

    for(int i=0;i<(N-1);i++){
        cin>>C.at(i)>>S.at(i)>>F.at(i);
    }


    for(int i=0;i<(N-1);i++){
        int T;
        for(int j=i;j<(N-1);j++){
            if(j==i){
                T = S.at(j) + C.at(j);
            }else{
                int num=0,co=0;
                while(T>co){
                    co = num*F.at(j) + S.at(j);
                    num++;
                }
                T = co;
                T += C[j];
            }

        }
        cout<<T<<endl;
    }
    cout<<'0'<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
#include <stdio.h>

using namespace std;

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

//10^9 + 7
const ll MOD = 1000000007;

int main() {
	string S;
	cin >> S;

	ll Q;
	cin >> Q;

	long T, F;
	string C;
	bool isRev = false;

	rep(i, Q) {
		cin >> T;
		
		if (T == 1) {
			//反転
			//reverse(S.begin(), S.end());
			isRev = !isRev;
		}
		else {
			cin >> F >> C;
			//追加
			if (F == 1) {

				//先頭にcを追加
				if (isRev) {
					S.append(C);
				}
				else {
					S.insert(0, C);
				}
				
			}
			else {
				// 末尾にcを追加

				if (isRev) {
					S.insert(0, C);
				}
				else {
					S.append(C);
				}
			}
		}
	}

	if (isRev) {
		reverse(S.begin(), S.end());
	}

	cout << S << endl;
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

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

  while(1) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if (a <= 0) {
      cout << "No" << endl;
      break;
    }    
  }
  
  return 0;
}


Measured memory_bytes: 3632
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    D=LI()
    if( 0 in D):
        print(0)
    elif( N >= 24):
        print(0)
    elif( N>= 12):
        C=Counter(D)
        for c in C.values():
            if(c>=3):
                print(0)
                return
        print(1)
    else:
        ans = 0
        for mask in range(1<<N):
            times = [0,24]
            for i in range(N):
                if(mask >> i & 1):
                    times.append(24-D[i])
                else:
                    times.append(D[i])
            times.sort()
            sub = [times[i+1] - times[i] for i in range(len(times)-1)]
            ans = max(ans ,min(sub))
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5392
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9


def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10

    return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import random

class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if way==0:
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c


lst=["W","S","E","N"]
u,s,e,w,n,d=map(int,input().split())
N=int(input())
dice=Dice(u,w,s,e,n,d)
for i in range(N):
    top,front=map(int,input().split())
    while True:
        if dice.u==top and dice.w==front:
            break
        else:
            dice.rot(random.choice(lst))
    print(dice.s)


Measured memory_bytes: 8188
#include <bits/stdc++.h>
#include <functional>
#include <iomanip>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>

using ll = long long;
ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
double dis(int x1, int x2, int y1, int y2) {
    return sqrt((double)abs(x1-x2)*(double)abs(x1-x2)+(double)abs(y1-y2)*(double)abs(y1-y2));
}

bool solve() {
    int k,x; cin >> k >> x;
    int start = x-k+1;
    chmax(start,-1000000ll);
    int end = x+k-1;
    chmin(end,1000000ll);
    FOR (i,start,end+1) {
        cout << i << " ";
    }
    cout << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int main(void){
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	ll ans=b-a+1LL;
	ans-=b/c;
	ans+=(a-1)/c;
	ans-=b/d;
	ans+=(a-1)/d;
	ll g=gcd(c,d);
	g=c*d/g;
	ans+=b/g;
	ans-=(a-1)/g;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
int a,b,c;cin >> a >> b >> c;
int ans = a;
if(a==b)ans = c;
if(a== c)ans= b;
cout << ans << endl;
}


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

int main() {
  int n, q;
  cin>>n>>q;
  string s;
  cin>>s;

  char t[q], d[q];
  for (int i=0; i<q; i++) {
    cin>>t[i]>>d[i];
  }
  int cnt = 0;
  int l = -1, r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int cur = mid;
    bool ok = false;
    for (int i=0; i<q; i++) {
      if (s[cur] == t[i]) {
        if (d[i] == 'L') {
          --cur;
        } else {
          ++cur;
        }
      }
      if (cur == n) {
        ok = true;
        break;
      } else if (cur == -1) {
        break;
      }
    }
    if (ok) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cnt += n - l - 1;
  l = -1;
  r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    int cur = mid;
    bool ok = false;
    for (int i=0; i<q; i++) {
      if (s[cur] == t[i]) {
        if (d[i] == 'L') {
          --cur;
        } else {
          ++cur;
        }
      }
      if (cur == n) {
        break;
      } else if (cur == -1) {
        ok = true;
        break;
      }
    }
    if (ok) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cnt += l + 1;
  cout<<n - cnt<<endl;
}

Measured memory_bytes: 900
#include <iostream>

using namespace std;

long long dp[100005][3];

int main()
{
    int n;
    cin >> n;
    cin >> dp[1][0] >> dp[1][1] >> dp[1][2];

    int a, b, c;
    for(int i = 2; i <= n; ++i)
    {
        cin >> a >> b >> c;

        dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c + max(dp[i - 1][1], dp[i - 1][0]);
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

ll X, Y, Z, A, B, C, N;
ll cnt_x[1000], cnt_y[1000], cnt_z[1000], res[1000];

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

    cin >> X >> Y >> Z >> A >> B >> C >> N;
    for (int i = 0; i < X; i++)
    {
        int diff = abs(i - A) % N;
        cnt_x[diff]++;
    }
    for (int i = 0; i < Y; i++)
    {
        int diff = abs(i - B) % N;
        cnt_y[diff]++;
    }
    for (int i = 0; i < Z; i++)
    {
        int diff = abs(i - C) % N;
        cnt_z[diff]++;
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            for (int k = 0; k < N; k++)
            {
                int idx = i + j + k;
                if (idx >= 2 * N)
                    idx -= 2 * N;
                else if (idx >= N)
                    idx -= N;
                res[idx] += cnt_x[i] * cnt_y[j] * cnt_z[k];
            }
        }
    }
    for (int i = 0; i < N; i++)
    {
        cout << res[i] << " \n"[i == N - 1];
    }
}



Measured memory_bytes: 3228
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double a,b,h,m;
	double PI=3.14159265358979;
	cin>>a>>b>>h>>m;
	double theta1=((h+(m/60.0))/12.0)*2.0*PI;
	double theta2=(m/60.0)*2.0*PI;

	double ans=pow(abs(a*a+b*b-2.0*a*b*cos(abs(theta1-theta2))),0.5);
	printf("%.11lf",ans);
}

Measured memory_bytes: 4356
def main():
    c11, c12, c13 = map(int, input().split())
    c21, c22, c23 = map(int, input().split())
    c31, c32, c33 = map(int, input().split())

    r1max = max([c11, c12, c13])
    r2max = max([c21, c22, c23])
    r3max = max([c31, c32, c33])
    c1max = max([c11, c21, c31])
    c2max = max([c12, c22, c32])
    c3max = max([c13, c23, c33])
    for a1 in range(0, r1max + 1):
        for a2 in range(0, r2max + 1):
            for a3 in range(0, r3max + 1):
                m = max([a1, a2, a3])
                for b1 in range(0, c1max - m + 1):
                    if a1 + b1 == c11 and a2 + b1 == c21 and a3 + b1 == c31:
                        for b2 in range(0, c2max - m + 1):
                            if a1 + b2 == c12 and a2 + b2 == c22 and a3 + b2 == c32:
                                for b3 in range(0, c3max - m + 1):
                                    if a1 + b3 == c13 and a2 + b3 == c23 and a3 + b3 == c33:
                                        print('Yes')
                                        return

    print('No')
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[100005];

int32_t main()
{
	IO_OP;
	
	int n, s = 0;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i];
		if(i&1) s -= a[i];
		else s += a[i];
	}
	s /= 2;
	cout << s*2 << " ";
	for(int i=0;i<n-1;i++) {
		cout << (a[i] - s) * 2 << " ";
		s = a[i] - s;
	}
	
}



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

int main() {
    int Sprime; cin >> Sprime;
    int S = Sprime / 100 , T = Sprime - S * 100;
    
    if (S <= 12 && S > 0) {
        if (T <= 12 && T > 0) {
            cout << "AMBIGUOUS" << endl;
        }
        else {
            cout << "MMYY" << endl;
        }
    }
    else {
        if (T <= 12 && T > 0) {
            cout << "YYMM" << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	char c;
	std::cin >> c;
	std::cout << char(c + 1) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define INF 1e+9
using namespace std;

int a[3000];
vector<int> G[3000];

bool dfs(int v){
	bool flag = false;
	for(int to : G[v]){
		if(a[to] < a[v]){
			if(!dfs(to)) flag = true;
		}
	}
	return flag;
}

int main(){
	int n;
	vector<int> ans;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n - 1;i++){
		int x,y;
		cin >> x >> y; x--;y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(int i = 0;i < n;i++){
		if(dfs(i)) ans.push_back(i + 1);
	}
	for(int i = 0;i < ans.size();i++) cout << (i ? " " : "") << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp;
    long solve(int i, long n, long s) {
        if (i == S.length) {
            return n + s;
        } else {
            return solve(i+1, S[i]-'0', n+s) + solve(i+1, n*10+S[i]-'0', s);
        }
    }
    writeln(solve(1, S[0]-'0', 0));
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, Integer> odMap = new HashMap<>();
		HashMap<Integer, Integer> evMap = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (i % 2 == 0) {
		        if (evMap.containsKey(x)) {
		            evMap.put(x, evMap.get(x) + 1);
		        } else {
		            evMap.put(x, 1);
		        }
		    } else {
		        if (odMap.containsKey(x)) {
		            odMap.put(x, odMap.get(x) + 1);
		        } else {
		            odMap.put(x, 1);
		        }
		    }
		}
		int oddMax = 0;
		int oddMaxNum = 0;
		int oddNext = 0;
		int oddNextNum = 0;
		for (Map.Entry<Integer, Integer> entry : odMap.entrySet()) {
		    if (oddMax < entry.getValue()) {
		        oddNext = oddMax;
		        oddNextNum = oddMaxNum;
		        oddMax = entry.getValue();
		        oddMaxNum = entry.getKey();
		    } else if (oddNext < entry.getValue()) {
		        oddNext = entry.getValue();
		        oddNextNum = entry.getKey();
		    }
		}
		int evMax = 0;
		int evMaxNum = 0;
		int evNext = 0;
		int evNextNum = 0;
		for (Map.Entry<Integer, Integer> entry : evMap.entrySet()) {
		    if (evMax < entry.getValue()) {
		        evNext = evMax;
		        evNextNum = evMaxNum;
		        evMax = entry.getValue();
		        evMaxNum = entry.getKey();
		    } else if (evNext < entry.getValue()) {
		        evNext = entry.getValue();
		        evNextNum = entry.getKey();
		    }
		}
		int fixed;
		if (oddMaxNum == evMaxNum) {
		    fixed = Math.max(evMax + oddNext, evNext + oddMax);
		} else {
		    fixed = evMax + oddMax;
		}
		System.out.println(n - fixed);
	}
}


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

using namespace std;

long long int euclid(long long int x, long long int y){
  long long int t;
  t = max(x,y);
  x = min(x,y);
  y = t;
  long long int r = x % y;
  long long int tmp = y;
  
  while(r != 0){
    tmp = r;
    r = y % r;
    y = tmp;
  }
  return tmp;
}

int mylog2(long long int n){
  int cnt = 0;
  while(n != 0){
    if(n % 2 != 0) break;
    n /= 2;
    cnt++;
  }
  return cnt;
}

int main(){
  int N;
  cin >> N;
  vector<long long int> V(N);
  for(int i = 0; i < N; i++){
    cin >> V[i];
  }
  long long int tmp = euclid(V[0], V[1]);
  //cout << tmp << " ";
  for(int i = 1; i < N-1; i++){
    tmp = euclid(tmp, V[i+1]);
    //cout << tmp << " ";
  }
  if(N == 1){
    cout << mylog2(V[0]);
  }else{
    cout << mylog2(tmp);
  }
}


Measured memory_bytes: 256