akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)


int main() {
  double r;
  cin >> r;

  double pi = 3.141592653589;
  double len = 2*r*pi;
  double area = r*r*pi;

  cout << fixed << setprecision(15) << area << " ";
  cout << fixed << setprecision(15) << len << endl;

}


Measured memory_bytes: 3232
X, Y = map(int,input().split(' '))
MOD = 10**9 + 7

if (X+Y) % 3 == 0:
    Z = int((X+Y)/3)
    A = X - Z
    B = Y - Z
    fact = [1] * (Z+1)
    fact_inv = [1] * (Z+1)

    if A >= 0 and A <= Z and A + B == Z:
        for i in range(1,Z+1):
            fact[i] = (fact[i-1] * i)%MOD
        for i in range(1,max(A,B)+1):
            fact_inv[i] = pow(fact[i], MOD-2,MOD)

        ans = (((fact[Z] * fact_inv[Z-A]) % MOD ) * fact_inv[A]) % MOD
        print(ans)
    else:
        print(0)


else:
    print(0)

Measured memory_bytes: 45156
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const uint64_t MOD = 1e+9 + 7;

uint64_t sum(uint64_t L, uint64_t R)
{
  uint64_t P = R + L, Q = (R - L) + 1;

  uint64_t S = 0;
  if ((P % 2) == 0) {
    S = ((P / 2) * Q) % MOD;
  } else { // (Q % 2) == 0
    S = (P * (Q / 2)) % MOD;
  }
  return S;
}

uint64_t calc(uint64_t N, uint64_t x)
{
  uint64_t L = sum(0, x - 1);
  uint64_t R = sum(N - (x - 1), N);
  return (((R + MOD) - L) + 1) % MOD;
}

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  uint64_t S = 0;
  for (uint64_t x = K; x <= N + 1; ++x) {
    S = (calc(N, x) + S) % MOD;
  }
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int MOD = 1e9 + 7;

signed main(){

  string k; cin >> k;
  int d; cin >> d;

  static int dp[100001][101][2];
  dp[0][0][0] = 1;
  for(int i = 0; i < k.size(); i++){
    for(int j = 0; j < d; j++){
      int D = (int)(k[i]-'0');
      for(int l = 0; l < 10; l++){
        if(l < D){
          dp[i+1][(j+l)%d][1] += (dp[i][j][0] + dp[i][j][1]);
        }
        if(l == D){
          dp[i+1][(j+l)%d][0] += dp[i][j][0];
          dp[i+1][(j+l)%d][1] += dp[i][j][1];
        }
        if(l > D){
          dp[i+1][(j+l)%d][1] += dp[i][j][1];
        }
        dp[i+1][(j+l)%d][0] %= MOD;
        dp[i+1][(j+l)%d][1] %= MOD;
      }
    }
  }
  cout << (dp[k.size()][0][0] + dp[k.size()][0][1] - 1 + MOD) % MOD  << endl;

  return 0;
}


Measured memory_bytes: 16640
#入力はn, mの2行
#0 0が入力の終わりなのでwhile Trueのif
#for(1, n)は太郎、for(n+1, n+m)は花子、sum+=でそれぞれ合計を出す
#交換するとき(差/2)を小さい方から出したxに足すと大きい方から出す数に等しい
#ソートして同じi番目で差がsa/2だったら答え
#見つからんのやったらprint(-1)
while True:
    n, m = map(int, input().split())
    
    if n == 0 and m == 0:
        break
    
    else:
        taro = []
        hana = []
        
        for i in range(n):
            taro.append(int(input()))
        for i in range(m):
            hana.append(int(input()))
        
        taro.sort
        hana.sort
            
        sum_t = sum(taro)
        sum_h = sum(hana)

        sa = sum_t - sum_h #taroが多かったら正
        
        f = 0
        
        for i in range(n):
            if f == 1:
                break
            for j in range(m):
                if taro[i] == hana[j] + sa/2:
                    print(taro[i],hana[j])
                    f = 1
                    break
        
        if f == 0:
            print(-1)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef struct{
  string name;
  int time;
}P;

int main(){
  int n,t;
  queue<P>que;    //キュー♂♂♂♂♂♂♂♂♂♂
  string name;
  int time;
  cin >> n >> t;
  for(int i = 0;i < n;i++){
    cin >> name >> time;
    que.push((P){name,time});
  }
  int cnt = 0;
  while(!que.empty()){
    name = que.front().name;
    time = que.front().time;
    que.pop();
    cnt += min(t,time);
    time -= t;
    if(time <= 0)cout << name << " " << cnt << endl;
    else que.push((P){name,time});
  }
  return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    if (s.size() == 26u) {
        string t(s);
        if (!next_permutation(t.begin(), t.end())) {
            cout << -1 << endl;
            return 0;
        }
        while (t.substr(0, t.size()-1) > s) t.pop_back();
        cout << t << endl;
    } else {
        for (char nc = 'a'; nc <= 'z'; nc++) {
            bool used = false;
            for (char c : s) if (c == nc) used = true;
            if (used) continue;
            cout << s << nc << endl;
            return 0;
        }
    }
}

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

ll N= 998244353;

ll m_pow(ll n, ll k){
    if(k==0) return 1;
    else{
        ll a = (m_pow(n,k/2)*m_pow(n,k/2))%N;
        if(k%2==0) return a;
        else return (a*n)%N;
    }
}

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> mod_pow(n,1),combi(k+1,1);
    for(int i=1; i<n; i++){
        mod_pow.at(i) = mod_pow.at(i-1)*(m-1);
        mod_pow.at(i) %= N;
        if(i>k) continue;
        combi.at(i) = ((n-i)*combi.at(i-1))%N;
        combi.at(i) *= m_pow(i,N-2);
        combi.at(i) %= N;
    }
    ll ans = 0;
    for(int i=0; i<=k; i++){
        ll plus= (m*mod_pow.at(n-1-i))%N;
        plus = (plus*combi.at(i))%N;
        ans += plus;
        ans %= N;
    }
    cout << ans << endl;
    /*
    for(int i=0; i<k+1; i++){
        cout << combi.at(i) << endl;
    }*/

}

Measured memory_bytes: 6348
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] arg) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int n = Integer.parseInt(scan.next());
        scan.nextLine();
        List<Integer> aList = Arrays.stream(scan.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        for(int a : aList) {
            h-=a;
        }
        if(h > 0) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 48732
function Main(input) {
  input = input.trim();
  var S = input.split("");
  const test = ["A", "C", "G", "T"];
  var ans = 0;
  var now = 0;
  for (var i = 0; i < S.length; i++) {
    if (test.indexOf(S[i]) != -1) {
      now++;
      ans = Math.max(now, ans);
    } else {
      now = 0;
    }
  }

  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
    for (int n; cin >> n, n;) {
        int cur = 0, prev = 0, cnt = 0;
        while (n--) {
            string f; cin >> f;
            if (f == "lu") cur |= 2;
            if (f == "ru") cur |= 1;
            if (f == "ld") cur &= 1;
            if (f == "rd") cur &= 2;
            if ((cur ^ prev) == 3) cnt++, prev = cur;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
ll solve(ll n, ll i)
{
	ll l = (i - 1) * i / 2;
	ll r = (n - i + 1 + n) * i / 2;
	return (r - l + 1) % mod;
}
int main()
{
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for(int i = k; i <= n + 1; ++i)
		ans = (ans + solve(n, i)) % mod;
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  string c;
  cin >> n >> c;
  int a = 0, b = 0;
  rep(i, n)if(c[i] == 'R') ++a;
  int ans = max(a, b);
  rep(i, n){
    if(c[i] == 'R') --a;
    else ++b;
    int now = max(a, b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
bool C = false,ans = false;  
//C存放字母“C”是否出现
//ans存放答案
void Ss( char c ){
    if ( ( C ) && ( c == 'F' ) )  
    //由于必须以“CF”的形式出现，在判断出现“F”时需先判断“C”是否出现
        ans = true;  //都出现了，ans变true
    return;
}
using namespace std;
int main(){
    char c;
    while ( cin >> c )  //程序段解释如上
    {
        if ( c == 'C' )  //“C”出现了
            C = true;
        Ss( c );
    }
    if ( ans )  //ans为true，输出Yes；反之，输出No
    {
        printf( "Yes" );
        return 0;  //直接return是个人习惯，用else当然可以
    }
    printf( "No" );
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC112
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nt = Console.ReadLine().Split(' ');
            int n = int.Parse(nt[0]);
            int T = int.Parse(nt[1]);
            int c, t;
            int cost_min = 1001;
            for (int i = 0; i < n; i++)
            {
                string[] ct = Console.ReadLine().Split(' ');
                c = int.Parse(ct[0]);
                t = int.Parse(ct[1]);
                if (t <= T)
                {
                    if (c <= cost_min)
                    {
                        cost_min = c;
                    }
                }
            }
            if (cost_min == 1001) { Console.WriteLine("TLE"); }
            else
            {
                Console.WriteLine(cost_min);
            }
            
        }

    }
}

Measured memory_bytes: 11092
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
            double a = Double.parseDouble(sc.next());
            System.out.println((long)(a + Math.pow(a, 2) + Math.pow(a, 3)));

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_n = 1e5 + 50, inf = 1e15;
ll dp1[max_n], dp2[max_n]; // dp1 is the no. of ways to paint the subtree at i if i is black
// dp2 is final answer for node i
vector<ll> adj[max_n];
ll n, m;

void dfs1(ll curr, ll par)
{
    dp1[curr] = 1;
    for (ll &neigh : adj[curr])
    {
        if (neigh == par)
            continue;
        dfs1(neigh, curr);
        dp1[curr] *= dp1[neigh] + 1;
        dp1[curr] %= m;
    }
}

void dfs2(ll curr, ll par, ll par_contrib)
{
    dp2[curr] = (1 + par_contrib) * dp1[curr];
    dp2[curr] %= m;
    vector<ll> pref, suff;
    for (ll &neigh : adj[curr])
    {
        if (neigh == par)
            continue;
        pref.push_back(1 + dp1[neigh]);
        suff.push_back(1 + dp1[neigh]);
    }
    for (int i = 1; i < pref.size(); ++i)
    {
        pref[i] = pref[i - 1] * pref[i];
        pref[i] %= m;
    }
    for (int i = int(suff.size()) - 2; i >=0; --i)
    {
        suff[i] = suff[i+1] * suff[i];
        suff[i] %= m;
    }
    ll cnt = 0;
    for (ll &neigh : adj[curr])
    {
        if (neigh == par)
            continue;
        ll ways = (1 + par_contrib);
        if (cnt > 0)
            ways *= pref[cnt - 1];
        ways %= m;
        if (cnt < (int(suff.size()) - 1))
            ways *= suff[cnt + 1];
        ways %= m;
        dfs2(neigh, curr, ways);
        ++cnt;
    }
}

int main()
{
    cin >> n >> m;
    ll x, y;
    for (int i = 1; i < n; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs1(1, -1);
    dfs2(1, -1, 0);
    for (int i = 1; i <= n; ++i)
        cout << dp2[i] << "\n";
    return 0;
}

Measured memory_bytes: 26512
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vll s(n),t(m) ;
	for(auto &i:s) cin >> i ;
	for(auto &i:t) cin >> i ;
	vvll dp(n+2,vll(m+2,0)) ;
//	dp.at(0).at(0) = 1 ;
	for(int i=0;i<=n;i++) dp.at(i).at(0) = 1 ;
	for(int j=0;j<=m;j++) dp.at(0).at(j) = 1 ;
	vll last(1e5+1,-1) ;
	for(int i=1;i<=n;i++){
//		vll sub(1e5+1,m+1) ;
		last.at(s.at(i-1)) = i ;
		for(int j=1;j<=m;j++){
			dp.at(i).at(j) = dp.at(i).at(j-1) ;
			if(last.at(t.at(j-1))!=-1) dp.at(i).at(j) += dp.at(last.at(t.at(j-1))-1).at(j) ;
//			if(s.at(i-1)==t.at(j-1)) dp.at(i).at(j) += dp.at(i-1).at(j-1) ;
			dp.at(i).at(j) %= mod ;
//			sub.at(t.at(j-1)) = j ;
		}
//		last.at(s.at(i-1)) = i ;
	}
	cout << dp.at(n).at(m) << endl ;
//	for(int i=0;i<=n;i++){
//		for(int j=0;j<=m;j++) cout << dp.at(i).at(j) << " " ;
//		cout << endl ;
//	}
}


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

long long n, x;
vector<long long> a;

int main() {
  cin >> x >> n;
  a.resize(n);
  for (auto& p : a) cin >> p;
  vector<bool> ch(20010);
  for (int i = 0; i < n; ++i) ch[a[i] + 10000] = 1;
  long long res = 1e8;
  for (int i = -10000; i <= 10000; ++i)
    if (!ch[i + 10000]) {
      if (res == (long long)(1e8) || abs(res - x) > abs(i - x)) res = i;
    }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3628
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=[]
for i,j in zip(a,b):
    c.append(i-j)
cm=[i for i in c if i<0]
cp=[i for i in c if i>=0]
cp.sort(reverse=True)
scm=sum(cm)
ans=len(cm)
for i in cp:
    if scm>=0:break
    ans+=1
    scm+=i
if scm<0:ans=-1
print(ans)

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

using namespace std;

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

    while (true) {
        c -= b;
        if (c < 1) {
            cout << "Yes\n";
            break;
        }
        a -= d;
        if (a < 1) {
            cout << "No\n";
            break;
        }
    }
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    auto t = unique(S.begin(), S.end());
    S.erase(t, S.end());
    cout << S.size() << endl;
}

Measured memory_bytes: 3720
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<list>
using namespace std;


int main() {
	int q;
	int d;
	int x;
	int query;
	list<int> arr;
	list<int>::iterator itr = arr.begin();

	cin >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> query;
		switch (query)
		{
		case 0:
			cin >> x;
			itr=arr.insert(itr,x);
			break;
		case 1:
			cin >> d;
			if (d > 0)
			{
				for (int i = 0; i < d; i++)
				{
					itr++;
				}
			}
			else
			{
				for (int i = 0; i >d; i--)
				{
					itr--;
				}
			}
			break;
		case 2:
			itr=arr.erase(itr);
			break;
		}
	}
	
	//順番に表示する
	itr = arr.begin();
	for (;itr!=arr.end(); itr++)
	{
		cout << *itr << endl;
	}

	return 0;
}


Measured memory_bytes: 18552
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int D, N;
    cin >> D >> N;
    if(D == 0) {
        if(N != 100)
            cout << N << endl;
        else
            cout << 101 << endl;
    } else if(D == 1) {
        if(N != 100)
            cout << 100 * N << endl;
        else
            cout << 10100 << endl;
    } else {
        if(N != 100)
            cout << 10000 * N << endl;
        else
            cout << 1010000 << endl;
    }
    return 0;
}

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

#define DEBUG(a) printf("%s %d\n", #a, a)
#define startTimer() double st = clock();
#define stopTimer() double en = clock();
#define elapsedTime (en-st)/CLOCKS_PER_SEC

int grid[120][120], flag[120][120][3], moves[120][120][3], h, w;

int min(int a, int b)
{
	if(a < b) return a;
	return b;
}

int fn(int x, int y, int ulta)
{
	int a, b, c, d, cost = grid[x][y];

	if(x == h && y == w) 
	{
		if(ulta) cost = 0;

		moves[x][y][ulta] = cost;
		return cost;
	}

	a = b = c = d = 1000000;

	if(flag[x][y][ulta]) return moves[x][y][ulta];

	if(cost)
	{
		if(ulta) cost = !cost;

		if(x + 1 <= h) a = cost + fn(x + 1, y, 1);
		if(y + 1 <= w) b = cost + fn(x, y + 1, 1);
	}
	else
	{
		if(x + 1 <= h) a = fn(x + 1, y, 0);
		if(y + 1 <= w) b = fn(x, y + 1, 0);	
	}

	moves[x][y][ulta] = min(a, b);
	flag[x][y][ulta] = 1;
	return moves[x][y][ulta];
}

int fn(int x, int y)
{
	moves[x][y][0] = fn(x, y, 0);
	return moves[x][y][0];
}

int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("in", "r", stdin);
	// 	freopen("out", "w", stdout);
	// #endif

	int lc1, lc2;
	char c;

	cin >> h >> w;
	getchar();

	for(lc1 = 1; lc1 <= h; lc1++)
	{
		for(lc2 = 1; lc2 <= w; lc2++)
		{
			scanf("%c", &c);
			if(c == '#') grid[lc1][lc2]++;
		}
		getchar();
	}

	cout << fn(1, 1) << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;

int w[110],v[110];
ll dp[110][100010];
int main(){
  int N,W;
  cin>>N>>W;
  for(int i=0;i<N;i++)
    cin>>w[i]>>v[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(j+w[i] <= W)
        if(dp[i+1][j+w[i]] < dp[i][j] + v[i])
          dp[i+1][j+w[i]] = dp[i][j] + v[i];
      if(dp[i+1][j] < dp[i][j])
        dp[i+1][j] = dp[i][j];
    }
  }
  cout<<dp[N][W]<<endl;
  return 0;
}


Measured memory_bytes: 79360
from collections import defaultdict
import itertools
n, c = map(int, input().split())
D = [list(map(int, input().split()))for _ in range(c)]

# 集計
diago = [defaultdict(int)for _ in range(3)]
for i in range(n):
    for j, color in enumerate(map(int, input().split())):
        color -= 1
        if (i+j) % 3 == 0:
            diago[0][color] += 1
        elif (i+j) % 3 == 1:
            diago[1][color] += 1
        else:
            diago[2][color] += 1


# 0列目をcにするときのcにするときの最小コスト
costs = [[0]*c for _ in range(3)]
for i in range(3):
    for j in range(c):
        for k, v in diago[i].items():
            costs[i][j] += D[k][j]*v

INF = 10**18
ans = INF
for trio in itertools.combinations(range(c), 3):
    for color in itertools.permutations(trio, 3):
        cost = sum(costs[i][j] for i, j in enumerate(color))
        if cost < ans:
            ans = cost
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int h,w;
cin>>h>>w;
char m[59][59];
int n[59][59];

for(int i = 1;i<=h;i++){
for(int j = 1;j<=w;j++){
cin>> m[i][j];
n[i][j]=0;
}
}
for(int i = 1;i<=h;i++){
for(int j = 1;j<=w;j++){
if(m[i][j]=='#'){
n[i-1][j-1]++;
n[i-1][j]++;
n[i-1][j+1]++;
n[i][j-1]++;
n[i][j]=9;
n[i][j+1]++;
n[i+1][j-1]++;
n[i+1][j]++;
n[i+1][j+1]++;
}
}
}
for(int i = 1;i<=h;i++){
for(int j = 1;j<=w;j++){
if(n[i][j]>=9)cout<<'#';
else cout<<n[i][j];
}
cout<<endl;
}
cout<<endl;
}

Measured memory_bytes: 256
s = gets.chomp.split(//).map(&:to_i)
k = gets.chomp.to_i

onecount = 0
ans = 0
s.each do |n|
  if n == 1
    onecount += 1
  else
    ans = n
    break
  end
end

if k <= onecount
  puts s.first
else
  puts ans
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0;
	cin >>n;
	Vi a(n);
	int bef=0;
	rep(i,n){
		cin>>a[i];
		bef+=a[i]-1;
	}

	cout<<bef<<endl;
}
/*
3 4 6
4 6   2,3,5 (10)

2 4 8 (15)
1,3,7
7 11 11 20 46
6 10 10 19 45
*/

Measured memory_bytes: 256
n=int(input())
s=list(input())
s=[int(i) for i in s]
res=[[0 for i in range(10)]for i in range(n)]
for i in range(n-1,0,-1):
    for j in range(10):
        res[i-1][j]=res[i][j]
    res[i-1][s[i]]+=1
cnt=0
#print(res)
a=[0]*10
for i in range(n-2):
    if a[s[i]]!=0:
        continue
    a[s[i]]+=1
    b=[0]*10
    for j in range(i+1,n-1):
        if b[s[j]]==0:
            b[s[j]]+=1
            cnt+=10-res[j].count(0)

print(cnt)


Measured memory_bytes: 49756
e=enumerate
(h,w),*a=[list(map(int,t.split()))for t in open(0)]
dp=[0]*w
c=12800
for i,a in e(zip(a,a[h:])):
  for j,(x,y)in e(zip(*a)):
    x=abs(x-y)
    t=0
    if j:t|=dp[j-1]<<x|dp[j-1]>>x
    if i:t|=dp[j]<<x|dp[j]>>x
    dp[j]=t if i+j else 2**c<<x
*a,=map(int,(bin(dp[w-1])[2:]).zfill(c-~c))
print(min(i for i,(f,g)in e(zip(a[c:],a[c::-1]))if f+g))

Measured memory_bytes: 3896
#include<iostream>
#include<vector>
using namespace std;
typedef long long int integer;

struct edge {
  integer to, cap, rev;
};

const integer VMAX = 2000, INF = 1e10;

vector<edge> G[VMAX];
bool used[VMAX];

void add_edge(integer from, integer to, integer cap) {
  G[from].push_back((edge) {to, cap, (integer)G[to].size()});
  G[to].push_back((edge) {from, 0, (integer)G[from].size()-1});
}

integer dfs(integer v, integer t, integer f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0, size = G[v].size(); i < size; i++) {
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      integer d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

integer max_flow(integer s, integer t) {
  integer flow = 0;
  while (true) {
    for (int i = 0; i < VMAX; i++) {
      used[i] = false;
    }
    integer f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

integer gcd(integer a, integer b) {
  return (b == 0 ? a : gcd(b, a % b));
}

int main() {
  const int SEPARATOR = 600, SOURCE = 1900, SINK = 1901;
  int m, n;
  while (cin >> m >> n && m) {
    for (int i = 0; i < VMAX; i++) {
      G[i].clear();
    }
    vector<integer> b(m), r(n);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> r[i];
    }
    
    for (int i = 0; i < m; i++) {
      add_edge(SOURCE, i, 1);
    }
    for (int i = 0; i < n; i++) {
      add_edge(SEPARATOR + i, SINK, 1);
    }

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (gcd(b[i], r[j]) > 1) {
          add_edge(i, SEPARATOR + j, 1);
        }
      }
    }
    cout << max_flow(SOURCE, SINK) << endl;
  }
  return 0;
}

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

int main (){
 int n,sum_top=0; cin >> n;
 vector<int> top_sum(n),bot(n),bot_sum(n);
 rep(i,n){
   int x; cin >> x;
   sum_top+=x;
   top_sum[i]=sum_top;
 }
 int sum_bot=0;
 rep(i,n){
   cin >> bot[i];
  sum_bot+=bot[i];
 }
 rep(i,n){
   bot_sum[i]=sum_bot;
   sum_bot-=bot[i];
 }

 int ans=0;

  rep(i,n){
    int d =top_sum[i]+bot_sum[i]; 
    ans=max(ans,d);
  }
  cout << ans << endl;

}

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

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

using namespace std;

int main() {
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
}


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

#define Max 1000000

int prime [10000000];

int main()
{
	int n, out;

	for (int i = 2; i * i < Max; i++){
		if (prime[i] == 0){
			for (int j = i; j < Max; j += i){
				if (!(j == i)) prime[j] = 1;
			}
		}
	}

	while (cin >> n){
		out = 0;
		for (int i = 0; i <= n; i++){
			if (prime[i] == 0) out++;
		}
		cout << out - 2 << endl;
	}
	return(0);
}

Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
const int MAX_HW = 50;
using namespace std;

char masu[MAX_HW][MAX_HW];
int dp[MAX_HW][MAX_HW];

int main(void) {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> masu[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dp[i][j] = 0;
        }
    }

    dp[0][0] = masu[0][0] - '0';
    for (int i = 1; i < h; i++) {
        dp[i][0] = dp[i-1][0] + (masu[i][0] - '0');
    }
    for (int j = 1; j < w; j++) {
        dp[0][j] += dp[0][j-1] + (masu[0][j] - '0');
    }
    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + (masu[i][j] - '0');
        }
    }

    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>

int calculateMin(const int& N, const int& A, const int& B, const int& C, const int& D) {
	int ret;
	int x_price = B;
	int y_price = D;
	int total_x_price, total_y_price;

	int i = 0;
	do {
		i++;
		total_x_price = i*x_price;
	} while ( i*A < N);

	 i = 0;
	do {
		i++;
		total_y_price = i*y_price;
	} while (i*C < N);

	if (total_x_price < total_y_price)
	{
		ret = total_x_price;
	}
	else {
		ret = total_y_price;
	}
	return ret;
}

int main() {

	int N, A, B, C, D;
	std::cin >> N;
	std::cin >> A;
	std::cin >> B;
	std::cin >> C;
	std::cin >> D;

	auto min = calculateMin(N, A, B, C, D);
	std::cout << min << std::endl;
	return 0;
}




Measured memory_bytes: 3096
n,m = map(int, input().split())
h = list(map(int, input().split()))

g = [1 for i in range(n)]
for i in range(m):
	a,b = map(int, input().split())
	if(h[a-1] <= h[b-1]):
		g[a-1] = 0
	if(h[a-1] >= h[b-1]):
		g[b-1] = 0
#	print(a,b,g[a-1],g[b-1])

ret = 0
for i in range(n):
	if(g[i] == 1):
		ret+=1
#print(g)
print(ret)


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

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

  int64_t ans= 0;
  for(int64_t div=1; div<=N; div++){
    for(int64_t num= div; num<=N; num+= div){
      ans+= num;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main (String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			StringTokenizer st = new StringTokenizer(br.readLine(), " ");
			int A = Integer.parseInt(st.nextToken());
			int B = Integer.parseInt(st.nextToken());
			int C = Integer.parseInt(st.nextToken());
			System.out.println(Math.min(B/A, C));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int kei[26] = {};
    for (int i = 0; i < n; i++) {
        if (s[i] == '+') continue;
        kei[s[i]-'a']++;
    }
    int v[10] = {};
    for (int i = 0; i < 26; i++) {
        v[kei[i]]++;
    }

    int sm = v[1]*2;
    for (int i = 2; i < 10; i++) {
        if (v[i] == 0) continue;
        if (v[i] == 1) sm += 4;
        else sm += 4+2*v[i];
    }
    printf("%d\n", sm-1);
    return 0;
}

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

int main() {
  int Cnt = 0;
  string S;
  string ans = "No";

  cin >> S;

  for (int i = 0; i < S.size()-1; i++) {
      if (S.at(0) == S.at(i+1)) {
        Cnt++;
      }
  }
  
  for (int i = 1; i < S.size()-1; i++) {
      if (S.at(1) == S.at(i+1)) {
        Cnt++;
      }
  }

  for (int i = 2; i < S.size()-1; i++) {
      if (S.at(2) == S.at(i+1)) {
        Cnt++;
      }
  }

  if (Cnt == 2) {
    ans = "Yes";
  }
  
  cout << ans << endl;
}


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

#define rep(i,l,r) for(int i=l;i<=r;++i)
int m,n,x;

int main()
{
	//freopen("1.in","r",stdin);
	cin>>m>>x;
	n=m*2-1;
	if(x==1||x==n)
	{
		puts("No");
		exit(0);
	}
	if(n==3)
	{
		if(x==2)puts("Yes\n1\n2\n3");
		else puts("No");
		exit(0);
	}
	puts("Yes");
	if(x==2)
	{
		int i=3;
		rep(j,1,m-2)
		{
			while(++i==x);
			printf("%d\n",i);
		}
		printf("%d\n%d\n%d\n%d\n",n,x,1,3);
		rep(j,1,m-3)
		{
			while(++i==x);
			printf("%d\n",i);
		}
		exit(0);
	}
	int i=2;
	rep(j,1,m-3)
	{
		while(++i==x);
		printf("%d\n",i);
	}
	printf("%d\n%d\n%d\n%d\n",2,n,x,1);
	rep(j,1,m-2)
	{
		while(++i==x);
		printf("%d\n",i);
	}
}

Measured memory_bytes: 1536
data = [False] * 1000001

for i in range(1, 1000001):
  if i % 3 == 0 or i % 5 == 0:
    continue
  data[i] = True

n = int(input())
result = 0

for i in range(1, n + 1):
  if data[i]:
    result += i

print(result)

Measured memory_bytes: 73576
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        int n = Integer.parseInt(input);
        int a=0,b=0;
        int suma=0,sumb=0;
        int min=100;

        for(int i = 1 ; i <= n/2 ;i++){
            a=i;
            b=n-i;
   //         System.out.println("a: "+ a + "  b:"+ b);
            while(a/10 != 0){
                suma = suma + a %10;
                a = a / 10;
            }
            while(b/10!=0){
                sumb = sumb + b %10;
                b = b / 10;
            }
            suma = suma +a %10;
            sumb = sumb +b %10;

            if(min > suma+sumb){
                min = suma+sumb;
            }
    //        System.out.println("suma: "+ suma + "  sumb:"+ sumb);
            suma = 0;
            sumb = 0;
        }
        System.out.println(min);
    }
}


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

int main() {
  int n;
  cin >> n;
  printf("%.12f\n",(double)((n + 2 - 1) / 2) / n);
}


Measured memory_bytes: 3736
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    double ans = 0.;
    rep(i, n) {
        ans += 1.0 / a[i];
    }
    printf("%.7lf\n", 1 / ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a,mn=1e9,ans;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		if(a<mn)mn=a;
		m-=a;
		if(m<0){
			printf("%d",i-1);
			return 0;
		}
	}
	ans=n+m/mn;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>
bool ask(T x)
{
    static int tot = 0;
    ++tot;
    cerr << "ASK " << tot << endl;
    cout << "? " << x << endl;
    char c;
    cin >> c;
    return c == 'Y';
}
void ans(ll x)
{
    cout << "! " << x << endl;
    exit(0);
}
int main()
{
    ll p10[11];
    p10[0] = 1;
    for (int i = 1; i < 11; ++i)
        p10[i] = 10 * p10[i - 1];

    int lo = 0, hi = 10;
    while (lo <= hi) {
        int mi = (lo + hi) / 2;
        if (ask(p10[mi]))
            lo = mi + 1;
        else
            hi = mi - 1;
    }
    if (lo == 11) {
        if (ask(2))
            ans(1);
        for (int i = 1; i < 11; ++i)
            if (ask(p10[i] + 1))
                ans(p10[i]);
    }
        
    int len = hi + 1;
    ll a = 0;
    for (int i = 0; i < len - 1; ++i) {
        lo = 0, hi = 9;
        while (lo <= hi) {
            int mi = (lo + hi) / 2;
            if (ask(10 * a + mi))
                lo = mi + 1;
            else
                hi = mi - 1;
        }
        a = 10 * a + hi;
    }
    lo = 0, hi = 9;
    while (lo <= hi) {
        int mi = (lo + hi) / 2;
        if (ask(100 * a + 10 * mi))
            hi = mi - 1;
        else
            lo = mi + 1;
    }
    ans(a * 10 + lo);
}


Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main(void){
    int n, m, ball[100000], ans = 0;
    bool po[100000];
    cin >> n >> m;
    for(int i=0;i<n;i++){
        ball[i] = 1;
        po[i] = false;
    }
    po[0] = true;
    for(int i=0;i<m;i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if(po[x]){
            po[y] = true;
            if(ball[x] <= 1){
                po[x] = false;
            }
        }
        ball[x]--;
        ball[y]++;
    }
    for(int i=0;i<n;i++){
        if(po[i])ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub trait Monoid {
    fn empty() -> Self;
    fn append(&self, other: &Self) -> Self;
}

pub struct SegmentTree<T>
where
    T: Monoid + Clone,
{
    size: usize,
    data: Vec<T>,
}

impl<T> SegmentTree<T>
where
    T: Monoid + Clone,
{
    pub fn new(size: usize) -> Self {
        let size = Self::normalize_data_size(size);
        let data = vec![T::empty(); size * 2 - 1];
        Self { size, data }
    }

    pub fn from_slice(values: &[T]) -> Self {
        let mut st = SegmentTree::new(values.len());
        for (i, v) in values.into_iter().enumerate() {
            st.data[i + st.size - 1] = v.clone();
        }
        if st.size < 2 {
            return st;
        }
        for i in (0..=(st.size - 2)).rev() {
            st.data[i] = st.data[i * 2 + 1].append(&st.data[i * 2 + 2]);
        }
        st
    }

    // 0-origin
    pub fn update(&mut self, i: usize, v: T) {
        let mut i = i + self.size - 1;
        self.data[i] = v;
        while i > 0 {
            i = (i - 1) / 2;
            self.data[i] = self.data[i * 2 + 1].append(&self.data[i * 2 + 2]);
        }
    }

    // [a, b)
    // 0-origin
    pub fn query(&self, a: usize, b: usize) -> T {
        self.execute_query(a, b, 0, 0, self.size)
    }

    fn normalize_data_size(size: usize) -> usize {
        let mut n = 1;
        while n < size {
            n *= 2;
        }
        n
    }

    fn execute_query(&self, a: usize, b: usize, i: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return T::empty();
        }
        if a <= l && r <= b {
            return self.data[i].clone();
        }
        let vl = self.execute_query(a, b, i * 2 + 1, l, (l + r) / 2);
        let vr = self.execute_query(a, b, i * 2 + 2, (l + r) / 2, r);
        vl.append(&vr)
    }
}

impl Monoid for usize {
    fn empty() -> Self {
        0
    }
    fn append(&self, other: &Self) -> Self {
        self ^ other
    }
}

fn solve() {
    input! {
        n: usize,
        av: [usize; n]
    };

    let st = SegmentTree::from_slice(&av);
    let v = st.query(1, n);
    let mut res = av.clone();
    res[0] = v;
    let all = v ^ av[0];
    for i in 1..n {
        res[i] = av[i] ^ all;
    }
    println!("{}", res.into_iter().join(" "));
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 13696
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    int p;
    scanf("%d",&p);
    int s0=0,s1=0;
    for (i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if (x%2==0) s0++; else s1++;
    }
    if (s1==0)
    {
        if (p==1)
        {
            printf("0\n");
            return 0;
        }
        else
        {
            n++;
        }
    }
    long long ans=1;
    for (i=0;i<n-1;i++)
    {
        ans*=2;
    }
    cout<<ans<<endl;
    return 0;
} 


Measured memory_bytes: 256
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var s = o.a(1);
  s = s.split("");
  for(var i = 0; i < s.length; i++){
    s[i] = String.fromCharCode((s[i].charCodeAt()-65+n)%26+65);
  }
  return s.join("");
}

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    int N, M, X, Y;
    std::cin >> N >> M >> X >> Y;
    std::vector<int> x(N), y(M);
    for (int i = 0; i < N; i++) std::cin >> x.at(i);
    for (int i = 0; i < M; i++) std::cin >> y.at(i);
    std::sort(x.begin(), x.end());
    std::sort(y.begin(), y.end());
    std::cout << ((std::max(x.at(N-1), X) < std::min(y.at(0), Y)) ? "No " : "") << "War" << std::endl;
}

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

int main(){
	long long X, Y;
	cin >> X >> Y;

	for(long long kame = 0; kame <= X; kame++) {
		long long tsuru = X - kame;
		if(Y == tsuru * 2 + kame * 4) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3556
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int k,s[10],g[10],ans;
void dfs(int c,int step){
	if(c==k){
		if(ans>step)ans=step;
	}else if(s[c]==g[c])dfs(c+1,step);
	else{
		for(int e=c+1;e<=k;e++){
			int mv=(g[c]+10-s[c])%10;
			for(int i=c;i<e;i++)s[i]=(s[i]+mv)%10;
			dfs(c+1,step+1);
			for(int i=c;i<e;i++)s[i]=(s[i]+10-mv)%10;
		}
	}
}
int main(){
	while(cin>>k,k){
		char buf[11];
		cin>>buf;rep(i,k)s[i]=buf[i]-'0';
		cin>>buf;rep(i,k)g[i]=buf[i]-'0';
		ans=10;dfs(0,0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 876
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()

int main()
{
    Imposter

    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, k, x=0;
  cin >> a >> b >> c >> k;
  while(a>=b){
    b=b*2;
    x++;
    }
  while(b>=c){
    c=c*2;
    x++;
  }
  if(x<=k) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

	int id = -1;
	int res;
	for (int i = 0; i < s.length(); i++)
	{
		if (id == -1 && s.at(i) == 'A')
		{
			id = i;
		}
		else if (s.at(i) == 'Z')
		{
			res = i - id + 1;
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100007;
typedef long long ll;
struct node {
    int v,w;
    node(int x=0,int y=0) {
        v=x,w=y;
    }
};
int deg[MAXN],X,n,m,x1,x2,y,tot[MAXN];
ll pos[MAXN];
bool vis[MAXN];
char c;
vector<node> edge[MAXN];
int read() {
    X=0,c=getchar();
    while(!isdigit(c))c=getchar();
    while(isdigit(c))X=(X<<1)+(X<<3)+c-'0',c=getchar();
    return X;
}
bool ok;
bool check(int &u) {
    vis[u]=true;
    for(int i=0; i<tot[u]; i++) {
        if(vis[edge[u][i].v]) {
            if(pos[edge[u][i].v]-edge[u][i].w!=pos[u])return false;
        } else {
            pos[edge[u][i].v]=pos[u]+edge[u][i].w;
            if(!check(edge[u][i].v))return false;
            else continue;
        }
    }
    return true;
}
int main() {
        n=read(),m=read();
        if(!m){
            cout<<"Yes";
            return 0;
        }
        for(int i=0; i<m; i++) {
            x1=read(),x2=read(),y=read();
            tot[x1]++;
            deg[x2]++;
            edge[x1].push_back(node(x2,y));
        }
        for(int i=0; i<n; i++)if(!deg[i]&&tot[i]) {
                ok=1;
                if(!check(i)) {
                    cout<<"No";
                    return 0;
                }
            };
        if(!ok) {
            cout<<"No";
            return 0;
        }
        cout<<"Yes";
        return 0;
}


Measured memory_bytes: 10496
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

int A[100];
int B[100];
ll dp[100][100001];

ll f(int i, int j) {
  if(j < 0) return -1e9;
  if(i < 0) return 0;
  if(dp[i][j] != -1) return dp[i][j];
  return dp[i][j] = max(f(i - 1, j), B[i] + f(i - 1, j - A[i]));
}

int main() {
  int n, v; cin >> n >> v;
  for(int i = 0; i < n; ++i)
    cin >> A[i] >> B[i];
  
  memset(dp, -1, sizeof dp);
  
  cout << f(n - 1, v);
  return 0;
}

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

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

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

int main(){

  int n, m, k;
  cin >> n >> m >> k;

  bool flag = false;
  rep(i, n + 1){
    rep(j, m + 1){
      //if(i == 2 && j == 2) cout << n * j + m * i - 2 * i * j << endl;
      if(n * j + m * i - 2 * i * j == k) flag = true;
    }
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++)
        cin >> A[i];
    B[0] = 0;
    B[1] = abs(A[1]-A[0]);
    for(int i = 2; i < N; i++)
        B[i] = min(B[i-1] + abs(A[i-1]-A[i]), B[i-2] + abs(A[i-2]-A[i]));
    cout << B[N-1] << endl;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>
using namespace std;
int solveMeFirst(int a,int b,int c){
    int reta = a*10 + b +c;
    int retb = a + b*10 +c;
    int retc = a + b +c*10;
    if(reta >= retb && reta >= retc){
          return reta;
    }
    else if(retb >= reta && retb >= retc){
          return retb;
    }
    else{
          return retc;
    }
}

int main(){
    int a,b,c;
    cin >> a  >>b >> c;
    int d = solveMeFirst(a,b,c);
    cout << d;
    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int a,b,ans=0; 
    cin >> a >> b; 
    for (int i=a;i<=b;i*=2) ans++;
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	ll limit = pow(10, 18);
	ll ret = 1;
	int n;
	cin >> n;
	vector<ll> A;
	for (int i=0; i<n; i++) {
		ll a; cin >> a;
		A.push_back(a);
		if (a==0) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i=0; i<n; i++) {
		ll now = A[i];
		if (now == limit) {
			cout << -1 << endl;
			return 0;
		}
		if (now > limit/ret) {
			cout << -1 << endl;
			return 0;
		} else {
			ret *= now;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4236