akhauriyash/Code-Regression huggingface dataset:
n,m,x,y=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
c=0
max_x=max(s)
min_y=min(t)

for i in range(x+1,y+1):
    if i>max_x and i<=min_y:
        c+=1
if c>0:
    print('No War')
else:
    print('War')
    

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

//https://beta.atcoder.jp/contests/agc028/tasks/agc028_a

public class Program_AGC028_A // ←Class名変更！！
{
    public static void Main(string[] args)
    {
        var st = Console.ReadLine();
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var l = Lcm(s.Length, t.Length);
        var x = new Dictionary<long, char>();

        for (int i = 0; i < s.Length; i++)
        {
            var pos = i * (l / s.Length) + 1;
            x[pos] = s[i];
        }


        for (int i = 0; i < t.Length; i++)
        {
            var pos = i * (l / t.Length) + 1;
            if (x.ContainsKey(pos))
            {
                if (x[pos] != t[i])
                {
                    Console.WriteLine(-1);
                    return;

                }
            }
        }

        Console.WriteLine(l);
    } // Main



    //最小公倍数 least common multiple
    public static long Lcm(int a, int b)
    {
        return (long)a * b / Gcd(a, b) ;
        //return (long)(a  / Gcd(a, b)) * (long)b;    //桁あふれをさせないために早めに割る。
    }

    //ユークリッドの互除法
    public static long Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す

        while (b != 0)
        {
            var temp = a % b;
            a = b;
            b = temp;
        }

        return a;
    }

}     // Class




Measured memory_bytes: 18912
// Very fast O(N^1.5) solution

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, P, Q, R;
	while (cin >> N, N) {
		cin >> M >> P >> Q >> R;
		vector<int> X(M), Y(M);
		for (int i = 0; i < M; ++i) {
			cin >> X[i] >> Y[i];
		}
		int B = 1;
		while (B * B < 4 * M) ++B;
		vector<int> sep = { 0, R, N }, col = { 1, 0 };
		for (int i = 0; i < B; ++i) {
			int L = i * M / B, R = (i + 1) * M / B;
			vector<pair<int, int> > ord = { make_pair(0, N) };
			for (int j = L; j < R; ++j) {
				vector<pair<int, int> > ordx, ordy, ordz;
				int sum = 0;
				for (int k = 0; k < ord.size(); ++k) {
					int seg = ord[k].second - ord[k].first, cur = ord[k].first;
					if (sum < X[j] && X[j] < sum + seg) {
						ordx.push_back(make_pair(cur, cur + X[j] - sum));
						cur += X[j] - sum;
						seg -= X[j] - sum;
						sum = X[j];
					}
					if (sum < Y[j] && Y[j] < sum + seg) {
						ordy.push_back(make_pair(cur, cur + Y[j] - sum));
						cur += Y[j] - sum;
						seg -= Y[j] - sum;
						sum = Y[j];
					}
					if (sum < X[j]) ordx.push_back(make_pair(cur, cur + seg));
					else if (sum < Y[j]) ordy.push_back(make_pair(cur, cur + seg));
					else ordz.push_back(make_pair(cur, cur + seg));
					sum += seg;
				}
				ordz.insert(ordz.end(), ordy.begin(), ordy.end());
				ordz.insert(ordz.end(), ordx.begin(), ordx.end());
				ord = ordz;
			}
			vector<int> sepptr;
			for (int j = 0; j < ord.size(); ++j) {
				sepptr.push_back(ord[j].first);
			}
			sepptr.push_back(N);
			sort(sepptr.begin(), sepptr.end());
			vector<int> newsep, newcol;
			int curptr = 0;
			for (int j = 0; j < col.size(); ++j) {
				newsep.push_back(sep[j]);
				newcol.push_back(col[j]);
				while (curptr < sepptr.size() && sepptr[curptr] < sep[j + 1]) {
					if (sepptr[curptr] != sep[j]) {
						newsep.push_back(sepptr[curptr]);
						newcol.push_back(col[j]);
					}
					++curptr;
				}
			}
			newsep.push_back(N);
			vector<int> nxtsep, nxtcol;
			int sum = 0;
			for (int j = 0; j < ord.size(); ++j) {
				int ptr = lower_bound(newsep.begin(), newsep.end(), ord[j].first) - newsep.begin();
				while (newsep[ptr] < ord[j].second) {
					nxtsep.push_back(sum);
					nxtcol.push_back(newcol[ptr]);
					sum += newsep[ptr + 1] - newsep[ptr];
					++ptr;
				}
			}
			nxtsep.push_back(N);
			sep = nxtsep, col = nxtcol;
		}
		int ans = 0;
		for (int i = 0; i < col.size(); ++i) {
			if (col[i] == 1) {
				int pl = max(P - 1, sep[i]), pr = min(Q, sep[i + 1]);
				if (pl < pr) ans += pr - pl;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s,t;
  char c;
  rep(i,n){
    cin>>s>>t;
    repn(j,s.size()-1 ){
      // cout<<s[j]<<endl;
      //cout<<t<<endl;
      if(s[j]=='J'){
	t=t[t.size() -1]+t.substr(0,t.size()-1);
      }
      if(s[j]=='C'){
	t=t.substr(1,t.size() -1)+t[0];
      }
      if(s[j]=='E'){
	if(t.size() % 2 ==0) t=t.substr((1+t.size())/2)+t.substr(0,t.size()/2);
	else t=t.substr((1+t.size())/2)+t[t.size()/2]+t.substr(0,t.size()/2);
      }
      if(s[j]=='A') reverse(t.begin(),t.end());
      if(s[j]=='M'){
	rep(k,t.size() ){
	  if(t[k]>=48 && t[k]<57){
	    t[k]++;
	  }
	  else if(t[k]==57) t[k]-=9;
	}
      }
      if(s[j]=='P'){
	rep(k,t.size() ){
	  if(t[k]>48 && t[k]<=57){
	    t[k]--;
	  }
	  else if(t[k]==48) t[k]+=9;
	}
      }
    }
    cout<<t<<endl;
  }
  return 0;
}



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

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    int x = stoi(s.substr(0, 2));
    int y = stoi(s.substr(2, 2));
    if(1 <= x && x <= 12){
        if(1 <= y && y <= 12)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "MMYY" << endl;
    }else{
        if(1 <= y && y <= 12)
            cout << "YYMM" << endl;
        else
            cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <random>
#include <cassert>
#include <limits>

using namespace std;

#define mp make_pair
#define pb push_back
#define repi(i, p, q) for (long i = p; i < q; i++)
#define repd(i, p, q) for (long i = p; i >= q; i--)
#define sz(x) x.size()
#define INF 2000000000
#define MOD 1000000007

typedef map<int, int> MI;
typedef pair<int, int> PI;
typedef long long int LLI;
typedef long int LI;
typedef int I;

int main()
{
    int n,t;
    cin >> n >> t;
    int a,b;
    int ans = 1003;
    for(int i = 0 ; i < n ; i++) {
        cin >> a >> b;
        if(b <= t) {
            ans = min(ans,a);
        }
    }
    if(ans == 1003) {
        cout << "TLE";
    }else {
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::{stdout, Write};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let out = stdout();
    let mut out = out.lock();

    input!{
        s: chars,
    };

    for c in s.iter() {
        if *c == '7' {
            writeln!(out, "Yes").unwrap();
            return ();
        }
    }
    writeln!(out, "No").unwrap()
}

Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	
int a,b; cin >> a >> b;
bool check = true;
	
	if(a==0){
		if(b!=0) check = false;
	}

	if(b%2 != 0){
		check = false;
	}
	if(a*4 < b or 2*a > b) check = false;

	if((b- 2*a)%2 !=0){
		check = false;
	} 

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

return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    long long ans = 0;
    for(int i=1; i<=N; i++){
        if(i%3&&i%5) ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    cin >> n;

    cout << n/3 << endl;

    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

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

    int n, w;
    cin >> n >> w;

    vll dp(w + 1, 0);
    rep(i, 0, n) {
        int wi, vi;
        cin >> wi >> vi;
        rrep(j, wi, w + 1) { dp[j] = max(dp[j], dp[j - wi] + vi); }
    }
    cout << dp[w] << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }

int q;

int main() {
	cin >> q;
	inc(qq, q) {
		LL a, b, c, d;
		cin >> a >> b >> c >> d;
		
		a -= b;
		LL s = (a <= c ? a : a - b * ce(a - c, b));
		
		bool ans = true;
		if(s < 0 || b > d) { ans = false; }
		else if(b == d || b <= c + 1) { ans = true; }
		else {
			assert(inII(s, 0, c) && c + 1 < b && b < d);
			ans = ((s + d - (c + 1)) % (gcd(b, d)) >= b - (c + 1));
		}
		
		cout << (ans ? "Yes" : "No") << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();		
		boolean ans = false;
		
		if(N % 7 == 0 || N % 4 == 0){
			ans = true;
		}
		
		for(int a = 0 ; a < N ; a += 7){
			if((N - a) % 4 == 0){
				ans = true;
				break;
			}
		}		
		System.out.println(ans ? "Yes" : "No");		
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;

int dp[100005];
int n,k;
vector <int> v;

int solve(int ind){
    if(ind > n) return INT_MAX;
    if(ind == n) return 0;
    if(dp[ind] != -1) return dp[ind];
    long long ans = INT_MAX;
    int curr_height = v[ind],next_height;
    for(int i=1 ; i<=k ; i++){
        if(ind <= n-i){
            next_height = v[ind+i];
            ans = min(ans,solve(ind+i) + abs(next_height-curr_height));
        }
    }
    return dp[ind] = ans;
}

int32_t main()
{
    cin>>n>>k;
    v.resize(n+1);
    for(int i=1 ; i<=n ; i++) cin>>v[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(1);
    return 0;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

#define FOR(i,n) for(ll i=0;i<n;i++) 
#define RFOR(i,n) for(ll i=n-1;i>=0;--i)
#define COUT(str) cout << str << endl


int A[3],SUM; 
bool a = true;
int ANS[3] = {5,5,7};


int main() {
	FOR(i, 3) {
		scanf("%d",&A[i]);
		SUM = SUM + A[i];
	}

	if (SUM == 5 + 5 + 7) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int D, T, S;
    cin >> D >> T >> S;
    if (S * T >= D) cout  << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main() {
	int P, Q, R, min;
	scanf("%d %d %d", &P, &Q, &R);
	min = P + Q;
	if (min > Q + R) {
		min = Q + R;
	}
	if (min > P + R) {
		min = P + R;
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 128
// -*- coding:utf-8-unix -*-

use proconio::{input, fastout};


#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let hold = n-1;
    let mut ans = 0;
    let mut lot = 1;

    loop{
        ans += hold/lot;
        
        if lot == hold{
            break;
        }
        
        lot += 1; 
    }

    println!("{}", ans);
    
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define lowbit(x) (x & -x)
#define ll long long
#define N 5010
#define memset(x) memset(x, 0, sizeof(x))
using namespace std;
ll n, m, a[N], st[N], num[N], b[210][N], igl[210][N], igr[210][N], ig[N][N], ans = 0;
int main()
{
	sc(n);
	sc(m);
	for (int i = 1; i < n; i++)
	{
		int x;
		sc(x);
		a[i + 1] = a[i] + x;
	}
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++)
	sc(b[j][i]);
	for (int i = 1; i <= m; i++)
	{
		int l = 0, r = 0;
		for (int j = 1; j <= n; j++)
		{
			while (l && b[i][j] > st[l]) l--;
			igl[i][j] = l ? num[l] + 1 : 1;
			st[++l] = b[i][j];
			num[l] = j;
		}
		for (int j = n; j; j--)
		{
			while (r && b[i][j] > st[r]) r--;
			igr[i][j] = r ? num[r] - 1 : n;
			st[++r] = b[i][j];
			num[r] = j;
		}
		for (int j = 1; j <= n; j++)
		{
			ig[igl[i][j]][j] += b[i][j];
			ig[igl[i][j]][igr[i][j] + 1] -= b[i][j];
			ig[j + 1][j] -= b[i][j];
			ig[j + 1][igr[i][j] + 1] += b[i][j];
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		ig[i][j] += ig[i][j - 1];
		for (int j = 1; j <= n; j++)
		ig[i][j] += ig[i - 1][j];
		for (int j = i; j <= n; j++)
		ans = max(ans, ig[i][j] - a[j] + a[i]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 220672
N = int(input())
[T, A] = list(map(int, input().split()))
H = list(map(int, input().split()))
c = 0.006
H_tem = [T - c*H[_] for _ in range(N)]
min_ans = float("inf")

for i in range(len(H)):
  ans = abs(A - H_tem[i])
  if ans < min_ans:
    min_ans = ans
    point = i+1

print(point)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL fact[100001];
int main()
{
	fact[1] = 1;
	for (int i = 2; i <= 100000; i++) fact[i] = (fact[i - 1] * i) % MOD;
	int N, M;
	cin >> N >> M;
	if (M < N - 1 || N + 1 < M) {
		cout << 0 << endl;
		return 0;
	}
	else if (M == N) {
		cout << (fact[N] * fact[M] * 2) % MOD << endl;
	}
	else {
		cout << (fact[N] * fact[M]) % MOD << endl;
	}
}

Measured memory_bytes: 1024
# coding: utf-8
from sys import setrecursionlimit


def dfs(node: int):
    if checked[node]:
        return

    checked[node] = True
    chain.add(node)
    for n in friends[node]:
        dfs(n)


def solve(*args: str) -> str:
    setrecursionlimit(2 * 10 ** 9)
    n, m, k = map(int, args[0].split())

    global friends
    friends = {i: set() for i in range(n+1)}
    blocked = {i: set() for i in range(n+1)}

    for a, b in map(str.split, args[1:1+m]):
        friends[int(a)].add(int(b))
        friends[int(b)].add(int(a))

    for c, d in map(str.split, args[1+m:1+m+k]):
        blocked[int(c)].add(int(d))
        blocked[int(d)].add(int(c))

    global checked
    checked = [False]*(n+1)

    ret = [0]*(n+1)
    for a in range(1, n+1):
        if checked[a]:
            continue

        global chain
        chain = set()
        dfs(a)
        count = len(chain) - 1
        for i in chain:
            ret[i] += count - len(chain & (friends[i] | blocked[i]))

    return ' '.join(map(str, ret[1:]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

#define int long long

int N;
int X;
vector<int> A;

int sub(int x, int y) {
    if(x < y) x += N;
    return x - y;
}

signed main() {
    cin >> N >> X;
    for(int i = 0; i < N; ++i) {
        int z;
        cin >> z;
        A.push_back(z);
    }

    int ans = LLONG_MAX;
    vector<vector<int> > b(N);
    for(int i = 0; i < N; ++i) {
        b[i].resize(N);
        fill(b[i].begin(), b[i].end(), 0);
        b[i][0] = A[i];
    }
    for(int k = 0; k < N; ++k) {
        int sum_b = 0;
        for(int i = 0; i < N; ++i) {
            if(k > 0) 
                b[i][k] = min(b[i][k-1], A[sub(i, k)]);
            sum_b += b[i][k];
        }
        ans = min(ans, k * X + sum_b);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define prev someone_else_0
#define last someone_else_1
#define next someone_else_2

using namespace std;

const long double eps = 1e-9;

const int MaxN = 2e5 + 15;

bool can[3][MaxN];
int n, m, x, y;

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        cin >> x >> y;
        if(x == 1)
            can[0][y] = true;
        if(x == n)
            can[1][y] = true;
        swap(x, y);
        if(x == 1)
            can[0][y] = true;
        if(x == n)
            can[1][y] = true;
        swap(x, y);
    }
    for(int i = 2; i < n; ++i)
        if(can[1][i] && can[0][i])
        {
            cout << "POSSIBLE\n";
            return 0;
        }
    cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

int main() {
	for(int n, w; scanf("%d %d", &n, &w), n;) {
		vector<int> cnt(11, 0);
		for(int i = 0; i < n; ++i) {
			int v;
			scanf("%d", &v);
			++cnt[v / w];
		}

		int mx = *max_element(cnt.begin(), cnt.end()), num;
		for(int i = 10; i >= 0; --i)
			if(cnt[i]) {
				num = i;
				break;
			}

		double ans = 0.01;
		for(int i = 0; i < num; ++i)
			ans += (double)cnt[i] / mx * (num - i) / num;

		printf("%.20lf\n", ans);
	}

	return EXIT_SUCCESS;
}

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

const int MAXN = 10000;
vector<vector<int>> vt;
queue<int> q;
int in[MAXN+2];
int ci[MAXN+2];
int ans[MAXN+2];
int sum = 0;
int N;

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  vt.resize(N+1);
  for(int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    vt[a].push_back(b);
    vt[b].push_back(a);
    in[a]++;
    in[b]++;
  }

  for(int i = 1; i <= N; i++)
    cin >> ci[i];
  sort(ci + 1, ci + N+1);
  for(int i = 1; i <= N; i++)
    if(in[i] == 1)
      q.push(i);

  int cur = 1;
  while(q.size()) {
    int here = q.front(); q.pop();
    ans[here] = ci[cur];
    sum += ci[cur++];
    for( int there : vt[here]) {
      in[there]--;
      in[here]--;
      if(in[there] == 1)
        q.push(there);
    }
  }
  sum -= ci[N];
  cout << sum << "\n";
  for(int i = 1; i <= N; i++)
    cout << ans[i] << " ";
}


Measured memory_bytes: 1024
#include<stdio.h>
typedef struct p{
	char name[10];
	int time;
}p;
void 	enqueue(p a);
p dequeue();
p s[100005];
int head = 0;
int tail = 0;
int n;
int limit;
int total;
int main()
{
	scanf("%d", &n);
	scanf("%d", &limit);
	for(int i = 0; i < n; i++)
		scanf("%s %d",s[i].name,&s[i].time);
	for(int i = 0; i < n; i++)
		enqueue(s[i]);
	while(head != tail)
	{
		p tem =dequeue();
		if(tem.time<=limit)
		{
			total += tem.time;
			printf("%s %d\n",tem.name,total);
		}else{
			total += limit;
			tem.time -=limit;
			enqueue(tem);
		}
	}
}

void 	enqueue(p a)
{
	s[tail] = a;
	tail++;
	tail = tail%100005;
}

p dequeue()
{
	int tem = head;
	head ++;
	head = head%100005;
	return s[tem];
}



Measured memory_bytes: 3244
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <strings.h>
#include <math.h>

int check(int h[], int x[], int n)
{
    int i;

    for (i = 0; i < n; i++) {
        if (h[i] != x[i]) {
            return 0;
        }
    }

    return 1;
}

int main(int argc, char *argv[])
{
    int n, i;
    int l, r;
    int h[100];
    int x[100];
    int ans;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &h[i]);
        x[i] = 0;
    }

    ans = 0;
    while(1) {
        //終了判定
        if (check(h, x, n)) {break;}
        //先頭出し
        for (l = 0; l < n; l++) {
            if (h[l] != x[l]) {break;}
        }
        for (r = l; r + 1 < n; r++) {
            if (h[r + 1] == x[r + 1]) {break;}
        }

        for (i = l; i <= r; i++) {
            x[i]++;
        }

        ans++;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
//
//  main.cpp
//  ITP1-8-D
//
//  Created by h3037153 on 2017/08/25.
//  Copyright ?? 2017??´ h3037153. All rights reserved.
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int i,ii,len=0,counter=0,d=0;
    string s,p;
    char max;
        getline(cin,s);
        getline(cin,p);
        //len = s.length();
    //if(s.find(p) != -1){
    //    cout<<"Yes"<<endl;
    //}
    //else{
    //    cout<<"No"<<endl;
    //}
    //cout<<s[1]<<p[1]<<endl;
    if(s.find(p) != -1){
        cout<<"Yes"<<endl;
        d++;
    }
     len = s.length();
    for(ii = 0;ii <= len; ii++){
        if(d == 1){
            break;
        }
        for(i = len-1;i >= 0; i--){
            if(i == len-1){
            max = s[i];
            }
            else{
                s[i+1]=s[i];
            }
        }
        swap(s[0],max);
        if(s.find(p) != -1){
                cout<<"Yes"<<endl;
            break;
            }
        else if(ii == len && s.find(p) == -1){
            cout<<"No"<<endl;
        }
        max = {};
    }
     
    
        //cout<<sizeof(s)<<len<<endl;}
    return 0;
}

Measured memory_bytes: 3204
//Be Name Khoda
/*
tane adami sharifast be jane adamiat
na hamin lebase zibast neshane adamiat
agar adami be cheshmasto dahano goosho bini
che miane naghshe divaro miane adamiat
khoro khabo khashmo shahvat shaghab asto jahlo zolmat
hayavan khabar nadarad ze jahane adamiat
be haghighat adami bash vagarna morgh bashad
ke hami sokhan begooyad be zabane adamiat
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; } //exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=2e5+5,LG=32,SM=2e4+5,inf=1e9+5;
ll mod=1e9+7;
#define MOK(x) if(x>mod) x-=mod;
ll pw(ll x,ll n) { return (n==0?1:pw(x*x%mod,n/2)*(n&1?x:1)%mod); }

ll n;
vll g[M];
ll cm[M],cn[M];
ll res;

ll lasb(ll x) { return (x<2?x:lasb(x>>1)+1); }
ll firb(ll x) { return (x&1?0:firb(x>>1)+1); }

void dfs(ll x,ll p)
{
    ll ba=0;
    for (ll y:g[x])
    {
        if (y==p) continue;
        dfs(y,x);
        ba|=cm[x]&cm[y];
        cm[x]|=cm[y];
    }
    ll nd=lasb(ba);
    cm[x]&=-(1<<nd);
    cm[x]+=(1<<nd);
    cn[x]=firb(cm[x]);
    smax(res,cn[x]);
}
 
int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,1,n)
    {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        g[a].PB(b);g[b].PB(a);
    }
    dfs(0,0);
    RET(res);
} 

Measured memory_bytes: 14976
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
List = list(map(int,input().split()))
M = List[0]
D = List[1]
count = 0
for a in range(1,M+1):
	for b in range(1,D+1):

		d_10 = int(b/10)
		d_1 = int(b - 10 * d_10)

		if d_1 >= 2 and d_10 >= 2 and d_1 * d_10 == a:
			count += 1

print(count)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const vector<int> emp;

int n;
int d[110];
int pt[110];
bool us[110];
int nd[110];

int main() {
	cin >> n;
	rep(i, n) cin >> d[i];
	int m = *max_element(d, d + n);

	int now = 0;

	if (m & 1) {
		for (int i = m; i >= (m + 1) / 2; --i) {
			bool fd = 0;
			rep(j, n) {
				if (!us[j] && d[j] == i) {
					fd = 1;
					us[j] = 1;
					nd[now] = i;
					pt[now++] = j;
					break;
				}
			}
			if (!fd) {
				puts("Impossible");
				return 0;
			}
		}
		for (int i = (m + 1) / 2; i <= m; ++i) {
			bool fd = 0;
			rep(j, n) {
				if (!us[j] && d[j] == i) {
					fd = 1;
					us[j] = 1;
					nd[now] = i;
					pt[now++] = j;
					break;
				}
			}
			if (!fd) {
				puts("Impossible");
				return 0;
			}			
		}
	} else {
		for (int i = m; i >= m / 2; --i) {
			bool fd = 0;
			rep(j, n) {
				if (!us[j] && d[j] == i) {
					fd = 1;
					us[j] = 1;
					nd[now] = i;
					pt[now++] = j;
					break;
				}
			}
			if (!fd) {
				puts("Impossible");
				return 0;
			}			
		}
		for (int i = m / 2 + 1; i <= m; ++i) {
			bool fd = 0;
			rep(j, n) {
				if (!us[j] && d[j] == i) {
					fd = 1;
					us[j] = 1;
					nd[now] = i;
					pt[now++] = j;
					break;
				}
			}
			if (!fd) {
				puts("Impossible");
				return 0;
			}			
		}
	}

	int lim = (m + 1) / 2;

	rep(i, n) {
		if (!us[i] && d[i] <= lim) {
			puts("Impossible");
			return 0;
		}
	}

	puts("Possible");

	return 0;
}


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

int main(){
    int m,f,r;
    cin >> m >> f >> r;
    while(m!=-1 || f!=-1){
      	
        if(m+f>=80){
            cout << "A" << endl;
        }
     	else if(m==-1 || f==-1){
            cout << "F" << endl;
        }
        else if(m+f>=65 && m+f<80){
            cout << "B" << endl;
        }
        else if(m+f>=50 && m+f<65){
            cout << "C" << endl;
        }
        else if(m+f>=30 && m+f<50){
                if(r>=50){
                    cout << "C" << endl;
                }
                else{cout << "D" << endl;}
        }
        else if( m+f<30){
            cout << "F" << endl;
        }
        
        
        cin >> m >> f >> r;
    }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int n;
  	cin >> n; 
  	for(int i=1; i<=9; i++){
    	int t=n/i;
      	if(t*i == n && t>=1 && t <=9){
        	cout << "Yes" << endl;
        	return 0;
        }
    }
  	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,p[10],ba,now;
	string c;
	while(cin>>n&&n) {
		cin>>c;
		ba=now=0;
		for(i=0;i<n;i++) p[i]=0;
		for(i=0;i<100;i++) {
			if(c[i]=='M') p[now]++;
			else if(c[i]=='S') {
				p[now]++;
				ba+=p[now];
				p[now]=0;
			}
			else {
				p[now]++;
				p[now]+=ba;
				ba=0;
			}
			now++,now=now%n;
		}
		sort(p,p+n);
		for(i=0;i<n;i++) {
			cout<<p[i]<<" ";
		}
		cout<<ba<<endl;
	}
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int A,B,C,D;
int ans[3005][3005];
bool used[3005][3005];
int f(int x,int y){
	if(x==A&&y==B)return 1;
	if(used[x][y])return ans[x][y];
	used[x][y]=true;
	if(x==A){
		ans[x][y]=f(x,y-1)*x%mod;
	}else if(y==B){
		ans[x][y]=f(x-1,y)*y%mod;
	}else {
		ans[x][y]=f(x,y-1)*x+f(x-1,y)*y;
		ans[x][y]%=mod;
		ans[x][y]-=f(x-1,y-1)*(x-1)%mod*(y-1)%mod;
		ans[x][y]+=mod;
		ans[x][y]%=mod;
	}
	return ans[x][y];
}
signed main(){
	cin>>A>>B>>C>>D;
	cout<<f(C,D)<<endl;
}


Measured memory_bytes: 83004
from bisect import bisect_left
n = int(input())
A = sorted(list(map(int,input().split())))
ind = bisect_left(A,A[-1]//2)
if A[ind]==A[-1]//2:
    print(A[-1],A[ind])
else:
    if ind>0 and A[ind-1]>=A[-1]-A[ind]:
        print(A[-1],A[ind-1])
    else:
        print(A[-1],A[ind])

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

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

int main() {
  int N;
  cin >> N;
  vector<int> an(N);
  for (int& ai : an) cin >> ai;
  if (N == 2) {
    cout << max(an[0], an[1]) << endl;
    return 0;
  }
  int maxgcd = 0;
  vector<int> L(N);
  L[0] = an[0];
  L[1] = gcd(an[0], an[1]);
  for (int i = 2; i < N; i++) {
    L[i] = gcd(L[i - 1], an[i]);
  }
  vector<int> R(N);
  R[N - 1] = an[N - 1];
  R[N - 2] = gcd(an[N - 1], an[N - 2]);
  for (int i = N - 3; i >= 0; i--) {
    R[i] = gcd(R[i + 1], an[i]);
  }

  maxgcd = max(maxgcd, R[1]);
  for (int i = 0; i < N - 2; i++) {
    maxgcd = max(maxgcd, gcd(L[i], R[i + 2]));
  }
  maxgcd = max(maxgcd, L[N - 2]);
  
  cout << maxgcd << endl;
  return 0;
}


Measured memory_bytes: 1408
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
using ll=long long;
const ll MOD = (ll)1e9+7;
//}}}

int main(){
  int H, W;
  cin >> H >> W;
  rep(h, H) rep(w, W){
    string s;
    cin >> s;
    if(s == "snuke"){
      printf("%c%d\n", 'A' + w, h + 1);
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

int main(){
    string s;
    getline(cin, s);
    vector<mint> x(13);
    x.at(0) = 1;

    ll p = 1;
    for(int i = s.size() - 1; i >= 0; --i){
        vector<mint> y(13);
        char c = s.at(i);
        if(c == '?'){
            for(int d = 0; d < 10; ++d){
                for(int j = 0; j < 13; ++j){
                    y.at((j + d * p) % 13) += x.at(j);
                }
            }
        }else{
            ll d = c - '0';
            for(int j = 0; j < 13; ++j){
                y.at((j + d * p) % 13) = x.at(j);
            }
        }
        x = y;
        p = (p * 10) % 13;
    }

    cout << x.at(5).v << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
int ruin(int a, int n, int p) {
	if (n == 0) {
		return (1%p);
	}
	else {
	int x = ruin(a, (n - (n % 2)) / 2, p);
		if (n % 2 == 0) {
			return (x*x) % p;
		}
		else {
			return (((x*x) % p)*a) % p;
			
		}
	
	}
	
}

int main() 
{
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<int> ss(n);
	string mo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 26; j++)
		{
			if (s[i] == mo[j]) 
			{
				ss[i] = j;
			}
		}
	}
	vector<long long> an(q);//3 12 2
	for (int aa = 0; aa < q; aa++) {
		int k;
		int dd = 3;
		int mm = 12;
		int cc = 2;
		cin >> k;
		vector<long long> all(6, 0);//d m c dm mc dmc
		for (int i = 0; i < k; i++) 
		{
			int x = ss[i];
			if (x == dd) 
			{
				all[0]++;
			}
			if (x == mm) 
			{
				all[1] ++;
				all[3] = all[3] + all[0];
			}
			if (x == cc) 
			{
				all[2]++;
				all[4] = all[4] + all[1];
				all[5] = all[5] + all[3];
			}
		}
		for (int i = 0; i + k < n; i++) 
		{
			int y = ss[i];
			int x = ss[i + k];
			if (y == dd) 
			{
				all[0]--;
				all[3] = all[3] - all[1];
			}
			else if (y == mm) 
			{
				all[1]--;
				all[4] = all[4] - all[2];
			}
			else if (y == cc) 
			{
				all[2]--;
			}
			if (x == dd)
			{
				all[0]++;
			}
			else if (x == mm)
			{
				all[1] ++;
				all[3] = all[3] + all[0];
			}
			else if (x == cc)
			{
				all[2]++;
				all[4] = all[4] + all[1];
				all[5] = all[5] + all[3];
			}
		}
		an[aa]=all[5];
	}
	for (int i = 0; i < q; i++) 
	{
		cout << an[i] << endl;
	}
}

Measured memory_bytes: 5252
cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S", "H", "C", "D"]

num_lines = int(input())

for i in range(num_lines):
    line = input().split()
    cards[pattern.index(line[0])][int(line[1]) - 1] = True

for mark in range(4):
    for j in range(13):
        if cards[mark][j] == False:
            print(pattern[mark], j+1)


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,ans=0;
	bool b=false;
	string s;
	cin >> n;
	vector<pair<string,ll>> st(n);
	rep(i,n) cin >> st[i].first >> st[i].second;
	cin >> s;
	rep(i,n){
		if(b) ans+=st[i].second;
		if(s==st[i].first) b=true;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


while true
  s=get_nsp.map(&:to_i)
  break if s.size==1 and s[0]==0
  puts s.inject(:+)
end


Measured memory_bytes: 6960
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int f=1,x=0;
    char ch;
    do{
        ch=getchar();
        if(ch=='-'){
            f=-1;
        }
    }while(ch<'0'||ch>'9');
    do{
        x=x*10+ch-48;
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
inline int cmp(int a,int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    string s1,s2;
    cin>>s1>>s2;
    reverse(s1.begin(),s1.end());
    if(s1==s2){
        cout<<"YES"<<'\n';
    }
    else{
        cout<<"NO"<<'\n';
    }
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    indic = {}
    for i in range(m):
        s, c = map(int, input().split())
        if s in indic:
            if indic[s] == c:
                pass
            else:
                print(-1)
                exit()
        else:
            indic[s] = c
    ans = ""
    if 1 in indic and indic[1] == 0 and n > 1:
        print(-1)
        exit()
    for i in range(n):
        if i+1 in indic:
            ans += str(indic[i+1])
        else:
            if i == 0 and n > 1:
                ans += "1"
            else:
                ans += "0"
    print(ans)


    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 62064
M = 1046527  # prime number
A = [-1 for i in range(M)]


def str2int(s):
    cnt = 0
    for i in range(len(s)):
        if s[i] == 'A':
            cnt += 1
        elif s[i] == 'T':
            cnt += 2
        elif s[i] == 'C':
            cnt += 3
        elif s[i] == 'G':
            cnt += 4
        cnt *= 4
    return cnt


def h1(k):
    return k % M


def h2(k):
    return 1 + k % (M - 1)


def h(k, i):
    return (h1(k) + h2(k) * i) % M


def insert(w):
    k = str2int(w)
    i = 0
    while i < M:
        j = h(k, i)
        if A[j] == -1:
            A[j] = w
            break
        i += 1


def find(w):
    k = str2int(w)
    i = 0
    while i < M:
        j = h(k, i)
        if A[j] == -1:
            break
        if A[j] == w:
            return True
        i += 1
    return False


if __name__ == '__main__':
    n = int(raw_input())
    for i in range(n):
        cmd, s = raw_input().split()
        if cmd == "insert":
            insert(s)
        elif cmd == "find":
            if find(s):
                print "yes"
            else:
                print "no"
        else:
            pass


Measured memory_bytes: 72676
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll N,C;
ll X[100009], V[100009];
ll turnL[100009], turnR[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>C;
    rep(i,N) cin>>X[i]>>V[i];
    
    ll sum=0, mx=0;
    rep(i,N){
        sum+=V[i];
        chmax(mx,sum-X[i]);
        turnL[i]=mx;
    }
    
    sum=0, mx=0;
    rrep(i,N-1){
        sum+=V[i];
        chmax(mx,sum-(C-X[i]));
        turnR[i]=mx;
    }
    
    ll ans=0;
    rep(i,N){
        ll tmp=turnL[i];
        if(i<N-1) tmp+=max(0ll,turnR[i+1]-X[i]);
        chmax(ans,tmp);
    }
    
    rrep(i,N-1){
        ll tmp=turnR[i];
        if(i) tmp+=max(0ll,turnL[i-1]-(C-X[i]));
        chmax(ans,tmp);
    }
    
    cout1(ans)
}

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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") { 
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  int n;
  cin >> n;
  set<int> f;
  for (int i = 0; i < n; i++) {
    int aa; cin >> aa;
    f.insert(aa);
  }

  cout << ((f.size() == n) ? "YES" : "NO") << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 13012
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var k = int.Parse(line[2]);
        var a = new int[n + 1];
        var dp = new long[n + 1];
        for (int i = 1; i <= n; i++)
        {
            a[i] = int.Parse(Console.ReadLine().Trim());
            dp[i] = long.MaxValue;
        }
        goDP(a, n, m, k, dp);
        Console.WriteLine(dp[n]);
    }
    static void goDP(int[] a, int n, int m, int k, long[] dp)
    {
        dp[1] = k;
        for (int i = 2; i <= n; i++)
        {
            var t = 0L;
            var maxa = 0L; var mina = long.MaxValue;
            for (int j = i; j >= Max(1, i - m + 1); j--)
            {
                maxa = Max(maxa, a[j]);
                mina = Min(mina, a[j]);
                t += a[j];
                var w = dp[j - 1] + (maxa - mina) * (i - j + 1) + k;
                dp[i] = Min(dp[i], w);
            }
        }
    }
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
ll dp[100'000][2];//0 黒, 1しろ
VVI node(100'000,VI());
const ll MOD = 1e9 + 7;
bool ok[100'000];
void dfs(int x){
    ok[x] = true;
    rep(i,node[x].size()){
        if(ok[ node[x][i] ]) continue;
        dfs(node[x][i]);
        (dp[x][1] *= dp[ node[x][i] ][0] + dp[ node[x][i] ][1])%=MOD;
        (dp[x][0] *= dp[ node[x][i] ][1])%=MOD;
    }

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

    int n;
    cin >> n;
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--, y--;
        node[x].push_back(y);
        node[y].push_back(x);
    }
    rep(i,100'000)rep(j,2) dp[i][j] = 1;
    dfs(0);
    cout << (dp[0][1] + dp[0][0]) % MOD << endl;
    return 0;
}


Measured memory_bytes: 11520