akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
//インクリメントデクリメント
	public static void main(String[] args) {
		int N, x = 0, max = 0;
		String S;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		S = sc.next();
		for(int i = 0; i < N; i++)
		{
			char s = S.charAt(i);
			if(s == 'I') x++;
			else if(s == 'D') x--;
			if(max < x) max = x;
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 21844
from collections import defaultdict as dd
from collections import deque
from itertools import combinations as combination
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))

def subset(A):
    for l in range(len(A) + 1):
        for comb in combination(A, l):
            yield comb

def solve():
    n, m, x = rl()
    C = []
    A = []
    for i in range(n):
        line = rl()
        C.append(line[0])
        A.append(line[1:])

    min_cost = 10**20
    for sub in subset(range(n)):
        skills = [0] * m
        cost = 0
        for s in sub:
            for i in range(m):
                skills[i] += A[s][i]
            cost += C[s]

        for skill in skills:
            if skill < x:
                break
        else:
            min_cost = min(min_cost, cost)

    if min_cost == 10**20:
        print (-1)
    else:
        print (min_cost)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 74280
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

ll powMod(ll a, ll y, ll mod)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % mod; 
  
        y = y>>1;
        a = (a*a) % mod; 
    } 
    return ans;
}

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

const int N = 2e5 + 5;
vector <int> ans(N, 0);

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    for (int i = 1; i < N; i++) {
        int y = __builtin_popcount(i), count = 1, temp = i;
        while (i%y != 0) {
            i %= y;
            y = __builtin_popcount(i);
            if (i != 0) count++;
        }
        ans[temp] = count;
        i = temp;
    }
    int n, n1 = 0 , n2 = 0;
    cin >> n;
    string x;
    cin >> x;
    int c1 = 0;
    for (char c : x) {
        if (c == '1') c1++;
    }
    for (int i = 0; i < n; i++) {
        int r = x[i]-'0';
        if (r == 1) {
            n1 += powMod(2, n-1-i, c1+1);
            n1 %= (c1+1);
            if (c1 != 1) {n2 += powMod(2, n-1-i, c1-1); n2 %= (c1-1);}
        }
    }
    for (int i = 0; i < n; i++) {
        int r = 1;
        r = r^(x[i]-'0');
        if (r == 1) {
            int solve = powMod(2, n-1-i, c1+1);
            solve = (solve+n1)%(c1+1);
            cout << ans[solve]+1 << endl;
        }
        else {
            if (c1 != 1) {
                int solve = powMod(2, n-1-i, c1-1);
                solve = (n2-solve+c1-1)%(c1-1);
                cout << ans[solve]+1 << endl;
            }
            else cout << 0 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 4396
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c;
	cin>>k;
	int n=max(c,max(a,b));
	int sum=0;
	if(c==n)
	{
		sum+=a+b+c*pow(2,k);
	}
	else if(a==n)
	{
		sum+=b+c+a*pow(2,k);
	}
	else
	{
		sum+=a+c+b*pow(2,k);
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a1,a2,a3;cin>>a1>>a2>>a3;
  int sum1 = abs(a2-a1) + abs(a3-a2);
  int sum2 = abs(a3-a1) + abs(a2-a3);
  int sum3 = abs(a1 - a2) + abs(a3-a1);
  int sum4 = abs(a3-a2) + abs(a1-a3);
  int sum5 = abs(a1-a3) + abs(a2-a1);
  int sum6 = abs(a2-a3) + abs(a1-a2);
  int ans=min(sum1, min(sum2, min(sum3, min(sum4, min(sum5, sum6)))));
  P(ans);
  return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input()) + 1
ans = 0
for i in range(1,n):
    for j in range(1,i+1):
        for k in range(1,j+1):
            if i == j == k:
                m = 1
            elif i == j or j == k or k == i:
                m = 3
            else:
                m = 6
            a = [i,j,k]
            ans += gcd_list(a) * m
print(ans)

Measured memory_bytes: 9536
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int n, C;
	cin >> n >> C;
	int d[C][C];
	rep (i, C) rep (j, C) cin >> d[i][j];
	int c[n][n];
	rep (i, n) rep (j, n) cin >> c[i][j];

	vector<int> per[3];
	rep (i, n) rep (j, n) {
		if ((i + j + 2) % 3 == 0) per[0].pb(c[i][j]);
		if ((i + j + 2) % 3 == 1) per[1].pb(c[i][j]);
		if ((i + j + 2) % 3 == 2) per[2].pb(c[i][j]);
	}

	int num[3][31] = {};
	rep (i, 3) {
		rep (j, per[i].size()) num[i][per[i][j]]++;
	}

	ll ans = 10000000000;
	rrep (col0, C) rrep (col1, C) rrep (col2, C) {
		if (col0 == col1 || col0 == col2 || col2 == col1) continue;

		int cols[] = {col0, col1, col2};

		ll sum = 0;
		rep (i, 3) rrep (col, C) {
			if (col != cols[i]) sum += d[col - 1][cols[i] - 1] * num[i][col];
		}
		chmin(ans, sum);
	}

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

Measured memory_bytes: 2416
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct Point
{
    int x, y;
    int a;

    bool operator < (const Point& other)
    {
        return this->a < other.a;
    }
    bool operator <= (const Point& other)
    {
        return this->a < other.a;
    }
    bool operator > (const Point& other)
    {
        return this->a > other.a;
    }
    bool operator >= (const Point& other)
    {
        return this->a >= other.a;
    }

};

int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    vector<Point> p(N);
    rep (i, N) { cin >> p[i].x >> p[i].y >> p[i].a; }

    int S = W * H;

    sort(ALL(p));

    int max1, max2, max3, max4;
    max1 = max3 = -1;
    max2 = max4 = 1000;
    rep (i, N)
    {
        switch(p[i].a)
        {
        case 1:
            chmax(max1, p[i].x);
            break;
        case 2:
            chmin(max2, p[i].x);
            break;
        case 3:
            chmax(max3, p[i].y);
            break;
        case 4:
            chmin(max4, p[i].y);
            break;
        }
    }

    if (max2 != 1000)
    {
        W = max2;
    }
    if (max1 != -1)
    {
        W -= max1;
    }
    if (max4 != 1000)
    {
        H = max4;
    }
    if (max3 != -1)
    {
        H -= max3;
    }

    if (W > 0 && H > 0)
    {
        cout << W * H << "\n";
    }
    else
    {
        cout << 0 << "\n";
    }

    return 0;
}



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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

int N;
// *********************************************************
int main(){

    cin >> N ;

    ll w=1;
    rep(i,N){
        w=w*10%MOD;
    }
    //cout << w<<endl;
    

    ll t=1;
    rep(i,N){
        t = t*9% MOD;
    }
    //cout << t <<endl;
    
    ll s=1;
    rep(i,N){
        s=s*8%MOD;
    }

    ll ans= (w-t-t+s)%MOD;
    ans = (ans+MOD)%MOD;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3640
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
INF = 10**18
mod = 10**9+7
def dijkstra(start, n, graph):
    route_cnt = [start] * n
    route_cnt[start] = 1
    que = [(0, start)]
    dist = [INF] * n
    dist[start] = 0
    while que:
        min_dist, u = heappop(que)
        if min_dist > dist[u]:
            continue
        for c, v in graph[u]:
            if dist[u] + c < dist[v]:
                dist[v] = dist[u] + c
                route_cnt[v] = route_cnt[u]
                heappush(que, (dist[u] + c  , v))
            elif dist[u] + c == dist[v]:
                route_cnt[v] = (route_cnt[v] + route_cnt[u]) % mod
    return route_cnt, dist
N, M = map(int, input().split())
S, T = map(int, input().split())
G = [[] for _ in range(N)]
edges = []
for _ in range(M):
    u, v, d = map(int, input().split())
    G[u-1].append((d, v-1))
    G[v-1].append((d, u-1))
    edges.append((v-1, u-1, d))
num_s, dist_s = dijkstra(S-1, N, G)
num_t, dist_t = dijkstra(T-1, N, G)
ans = num_s[T-1]**2%mod
l = dist_s[T-1]
for u, v, d in edges:
    if dist_s[v]<dist_s[u]:
        u, v = v, u
    if dist_s[u]*2<l<dist_s[v]*2 and dist_s[u]+dist_t[v]+d == l:
        ans-=(num_s[u]**2%mod)*(num_t[v]**2%mod)
        ans%=mod
for v in range(N):
    if dist_s[v] == dist_t[v] == l/2:
        ans-=(num_t[v]**2%mod)*(num_s[v]**2%mod)
        ans%=mod
print(ans%mod)







Measured memory_bytes: 109180
#include<stdio.h>
int main(){
  int n,x;
  int i,j,k;
  int a=0;
  for(;;){
    scanf("%d%d", &n, &x);
                if(n==0 && x==0) break;
                for(i=1; i<=n-2; i++){
                        for(j=i+1; j<=n-1; j++) {
                                for(k=j+1; k<=n; k++) {
                                        if(i+j+k==x) a++;
                                }
                        }
                }
                
                printf("%d\n", a);
                a=0;
        }
        return 0;
}



Measured memory_bytes: 2040
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let s = str2vec(&input_line_str());
    let (a, b): (char, char);
    a = s[0];
    b = s[2];
    if a == 'H' {
        if b == 'H' {
            p("H");
        } else {
            p("D");
        }
    } else {
        if b == 'H' {
            p("D");
        } else {
            p("H");
        }
    }
}


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

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<char>> G(H, vector<char>(W));
    char c;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> G.at(i).at(j);
        }
    }

    vector<bool> X(W, false);
    vector<bool> Y(H, false);

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (G.at(i).at(j) == '#')
            {
                X.at(j) = true;
                Y.at(i) = true;
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        if (!Y.at(i))
        {
            continue;
        }
        for (int j = 0; j < W; j++)
        {
            if (X.at(j))
            {
                cout << G.at(i).at(j);
            }
        }

        cout << "" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ll long long
#define endl '\n'
#define vi vector<int>
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <=n; i++)
#define rep2(i, n) for (i = 0; i < n-1; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend() //Sort in reverse,Vector.
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.

int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif

   int a;

   cin>>a;

   cout<<a + pow(a,2) + pow(a,3);
  
   
}  
   




Measured memory_bytes: 4240
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n,h,w,x,y,ans=0;
    cin>>n>>h>>w;
    rep(i,n){
        cin>>x>>y;
        if(x>=h&&y>=w){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
int main(){
	int num,tmp,money=100000;
	cin>>num;
	for(int i=0;i<num;i++){
		money*=1.05;
		tmp=money%1000;
		if(tmp>0) money=money-tmp+1000; 
	}
	cout<<money<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<string>
#include<math.h>
#include<vector>
#include <algorithm>
 
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin>>N;
    if(N<=9){
        cout<<N;
        return 0;
    }
    else if(N<=99){
        cout<<9;
        return 0;
    }
    else if(N<=999){
        int diff=N-100+1;
        cout<<9+diff;
        return 0;
    }
    else if(N<=9999){
        cout<<909;
        return 0;
    }
    else if(N<=99999){
        int diff=N-10000+1;
        cout<<909+diff;
        return 0;
    }
    else
        cout<<90909;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int h,w,d; cin >> h >> w >> d;
	map<int, P> mp;
	rep(i, h)rep(j, w)
	{
		int a;cin >> a;
		mp[a] = {i, j};
	}
	mp[0] = mp[d];
	vector<vector<int>> cost(d, vector<int>(h*w/d+1, 0));
	rep(i, d)rep(j, h * w / d)
	{
		int from = i + d * j;
		int to = i + d * (j + 1);
		if(to > h * w)continue;
		int from_x = mp[from].first, from_y = mp[from].second;
		int to_x = mp[to].first, to_y = mp[to].second;

		cost[i][j+1] = cost[i][j] + abs(from_x-to_x)+abs(from_y-to_y);
	}
	int q; cin >> q;
	vector<ll> ans;
	rep(i, q)
	{
		int l, r; cin >> l >> r;
		int s = l % d;
		int n = l / d,m = r / d;
		ans.push_back(cost[s][m]-cost[s][n]);
	}
	rep(i, q)cout << ans[i] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main()
{
    string str1,str2;
    cin >> str1 >> str2;
    sort(str1.begin(), str1.end());
    sort(str2.begin(),str2.end(),greater<char>());
    if(str1 < str2) cout << "Yes" << endl;
    else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
using vs = vector<string> ;
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

ll factori(ll i){
  ll tmp = 1;
  while(i>1){
    tmp*=i;
    i--;
    tmp%=mod;
  }
  return tmp;
}


int main(){
  ll N;cin>>N;
  vll A(N),B(100010,0),C(100010,0);rep(i,N)cin>>A[i];
  rep(i,N){
    if(i<=(N-1)/2) B[N-2*i-1]++;
    else B[2*i-N+1]++;
  }
  rep(i,N) C[A[i]]++;
  bool flag=true;
  ll ans=1;
  rep(i,100010){
    if(B[i]!=C[i]) flag=false;
    else if(B[i]>1){
      ans *= factori(B[i]);
      ans %= mod;
    }
  }
  if(flag) cout << ans << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 2560
n=gets.to_i
a=gets.split.map(&:to_i)
s = a.sort
cnt = 0
n.times do |i|
    if a[i] != s[i]
        cnt += 1
    end
end

if cnt == 0 || cnt == 2
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 1916
N = int(input())
pts = [(list(map(int,input().split()))) for _ in range(0,N)]

from itertools import combinations
def f(x1,y1,x2,y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2+dy**2)**0.5
dst = 0
for i,j in combinations(range(0,N),2):
    dst += f(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
print(dst / (N / 2))

Measured memory_bytes: 3188
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int a, b ,c;    cin >> a >> b >> c;
    int rem = a -b;

    int ans = max(c - rem , 0LL);
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b,x;
  cin>>a>>b>>x;
  if(x>=a&&x<=a+b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct Edge {
    int u;
    int v;
    int cost;
    Edge(int u, int v, int cost) : u(u), v(v), cost(cost) {}
};

class UnionFindTree {
   public:
    vector<int> parent;

    UnionFindTree(int n) {
        parent.resize(n);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

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

    void unite(int x, int y) {
        int rx = root(x); int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

ll kruscal(vector<Edge> e, int n) {
    UnionFindTree uft(n + 1); // 1 origin
    sort(e.begin(), e.end(), [](Edge l, Edge r) { return l.cost < r.cost; });

    ll cost = 0;
    for (auto edge : e) {
        if (!uft.same(edge.u, edge.v)) {
            uft.unite(edge.u, edge.v);
            cost += edge.cost;
        }
    }

    return cost;
}

int main() {
    int N; cin >> N;
    vector<pair<int, int>> XY(N), X(N), Y(N);
    REP(i, 0, N) {
        cin >> XY[i].first >> XY[i].second;
        X[i].first = XY[i].first;
        X[i].second = i;
        Y[i].first = XY[i].second;
        Y[i].second = i;
    }

    sort(ALL(X));
    sort(ALL(Y));

    vector<Edge> E;
    REP(i, 0, N - 1) {
        int a = X[i].second;
        int b = X[i + 1].second;
        int cost = min(abs(XY[a].first - XY[b].first), abs(XY[a].second - XY[b].second));
        E.push_back(Edge(a, b, cost));
    } 
    REP(i, 0, N - 1) {
        int a = Y[i].second;
        int b = Y[i + 1].second;
        int cost = min(abs(XY[a].first - XY[b].first), abs(XY[a].second - XY[b].second));
        E.push_back(Edge(a, b, cost));
    }

    cout << kruscal(E, N) << endl;
    return 0;
}

Measured memory_bytes: 8304
#include <iostream>
#include <set>
#include <vector>

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

  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> B[i];
  }
  std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> s;

  for (int i = 0; i < N; i++) {
    s.emplace(B[i], i);
  }

  long long ans = 0;
  while (!s.empty()) {
    int i = s.begin()->second;
    s.erase(s.begin());

    int d = B[i] - A[i], t = B[(i + 1) % N] + B[(N + i - 1) % N];
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    B[i] -= d / t * t;

    if (B[i] != A[i])
      s.emplace(B[i], i);
  }

  std::cout << ans;

  return 0;
}

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

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	while (t--) {
		int n;
		cin >> n;
		n--;
		int ans = 0;
		for (int i = 1; i <= n; i++)
			ans += n / i;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


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

int main(){
  const vector<int> group= {-1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x,y;
  cin >> x >> y;

  string ans= (group.at(x)==group.at(y)) ? "Yes"
                                         : "No";

  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int N;
  cin >> N;
  
  //factorize N!
  int fac[100] = {};
  int p[4] = {2, 3, 5, 7};
  for(int i=1; i <=N; ++i) {
    int t = i;
    REP(j, 4) {
      int tp = p[j];
      while(t%tp==0) {
        fac[tp]++;
        t/=tp;
      }
    }
    if(t!=1) fac[t]++;
  }
  
  int cf[100] = {};
  REP(i, 100) {
    if(fac[i] > 100) fac[i] = 100;
    cf[fac[i]]++;
  }
  for(int i=100; i>0; --i) {
    cf[i-1] += cf[i];
  }
  
  int r = 0;
  //A: x^4y^4z^2
  r += cf[4] * (cf[4]-1) * (cf[2]-2) / 2;
  //B: x^14y^4
  r += cf[14] * (cf[4]-1);
  //C: x^24y^2
  r += cf[24] * (cf[2]-1);
  //D: x^74
  r += cf[74];
  cout << r << endl;
}

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

int ans = 0;
int ABfind(string a){
  int pos = a.find("AB");
  if(pos >= 0 && pos <= 10){
    ans++;
    string b = a.substr(pos+2);
    ABfind(b);
  }else{

  }
}
int main(){
  int a;
  cin >> a;
  string b[a];
  int c = 0;
  int d = 0;
  int e = 0;
  for(int i = 0;i < a;i++){
    cin >> b[i];
    ABfind(b[i]);
    if(b[i].substr(0,1) == "B"){
      c++;
      if(b[i].substr(b[i].length()-1) == "A"){
        e++;
        c--;
      }
    }else{
      if(b[i].substr(b[i].length()-1) == "A"){
        d++;
      }
    }

  }
/*
  int kari = min(c,d);
  int kari2 = max(c,d);
  if(e < kari){
    ans += e*2;
    kari -= e;
    ans += kari;
  }else{
    ans += kari*2;
    e -= kari;
    ans += e/2;
  }
  cout << ans << endl;
  */
  if(c > 0 && d > 0){
    ans += e+1;
    c--;
    d--;
    int kari = min(c,d);
    ans += kari;
  }else{
    if(c > 0 && d == 0 || c == 0 && d > 0){
      ans += e;
    }else{
      if(e <= 1){
        int aaa = 114514;
      }else{
        ans += e-1;
      }
    }
  }
  cout << ans << endl;
}


/*
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  */


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll tmp = gcd(n, m);
  set <ll> s;
  s.insert(1);
  for (ll i = 2; i*i <= tmp; i++) {
    while (tmp%i == 0) {
      s.insert(i);
      tmp /= i;
    }
  }
  s.insert(tmp);
  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A < B) {
        swap(A, B);
    }
    if (A - B >= 1) {
        cout << 2 * A - 1 << endl;
    } else if (A == B) {
        cout << A + B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
l=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            Total=500*i+100*j+50*k
            if Total==X:
                l+=1
print(l)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int a, p;
   cin >> a >> p;
   cout << (a * 3 + p) / 2 << endl;
   return 0;
}


Measured memory_bytes: 256
//while (clock()<=69*CLOCKS_PER_SEC)
#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>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

const int nax=100*1007;

int k;
char wcz[nax];

int n;

int oj[nax];

int sum[nax];

int fin(int v)
{
	if (v!=oj[v])
		oj[v]=fin(oj[v]);
	return oj[v];
}

void uni(int v, int u)
{
	oj[fin(u)]=fin(v);
}

int main()
{
	scanf("%s", wcz+1);
	k=strlen(wcz+1);
	wcz[0]='a';
	wcz[k+1]='a';
	for (int i=0; i<=k; i++)
		oj[i]=i;
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		uni(l-1, r);
	}
	for (int i=1; i<=k/2+1; i++)
		uni(i-1, k-(i-1));
	for (int i=0; i<=k; i++)
		sum[fin(i)]+=(wcz[i]-wcz[i+1]);
	for (int i=0; i<=k; i++)
	{
		if (sum[i]%26)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 896
n = int(input())
int_a = list(map(int, input().split()))

if n % 2 == 0:
    kakeru = n
else:
    kakeru = n + 1

if sum(int_a) == kakeru * (n // 2):
    syou = n // 2
    answer = 2 ** syou
    print(answer % ((10 ** 9) + 7))
else:
    print("0")


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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;++i) cin>>a[i];
  
  map<int,int> mp;
  vector<int> one_2_n(n+1,1e9+1);
  bool isFirst = true;
  for(int i=0;i<n;++i){
    mp[a[i]] = mp[a[i]-1] + 1;
  }
  
  int mx=0;
  for(auto mi: mp){
    mx = max(mi.second, mx);
  }
  int ans  = n - mx;
  cout << ans <<endl;
  
  return 0;
}


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

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

const int N = 2e5+2;
int n, m;
int dist[N], ans[N];
vector<int> adj[N];

void bfs(int s)
{
    memset(dist,-1,sizeof(dist));
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty())
    {
        int cur = q.front();
        q.pop();
        for (int nx : adj[cur])
        {
            if (dist[nx] != -1)
                continue;
            dist[nx] = dist[cur] + 1;
            ans[nx] = cur;
            q.push(nx);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    bfs(1);
    // for (int i = 1; i <= n; i++)
    // {
    //     cout << dist[i] << ' ';
    // }
    // cout << '\n';
    bool good = 1;
    for (int i = 2; i <= n && good; i++)
    {
        if (dist[i] == -1)
            good = 0;
    }
    if (!good)
    {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    for (int i = 2; i <= n; i++)
    {
        cout << ans[i] << '\n';
    }
    return 0;
}

/*
4 5
1 2
1 3
2 3
2 4
3 4

10 11
1 2
2 3
3 4
4 5
5 6
6 1
4 7
7 8
8 9
9 10
10 5

13 15
1 2
2 3
3 4
4 5
5 6
6 1
4 7
7 8
8 9
9 10
10 5
3 11
11 12
12 13
13 7
*/

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

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

#define PI 3.14159265358979
#define INF INT_MAX

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

int main(int, char**)
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta = abs((h *30 + m * 0.5) -m * 6);
    double c2 = a * a + b * b - 2 * a * b * cos(theta * PI / 180);

    cout << setprecision(20) << sqrt(c2) << endl;

    return 0;
}

Measured memory_bytes: 4288
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int dp[101][10];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, 10) dp[0][i] = -INF;
  dp[0][0] = 0;
  rep(i, N) {
    int s; cin >> s;
    rep(k, 10) {
      dp[i+1][k] = dp[i][k];
    }
    rep(k, 10) {
      int nk = (k+s)%10;
      dp[i+1][nk] = max(dp[i+1][nk], dp[i][k] + s);
    }
  }
  dp[N][0] = 0;
  cout << *max_element(dp[N],dp[N]+10) << "\n";
  return 0;
}


Measured memory_bytes: 256
#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>;

// header area

int main(){
    int N, M; cin >> N >> M;
    
    vector<int> ac_list(N, 0);
    vector<int> penalty(N, 0);

    rep(i, M){
        int p; string s; cin >> p >> s; p--;
        if(s=="WA"){
            if(ac_list[p]==0) penalty[p]++;
        }else if(s=="AC"){
            if(ac_list[p]==0) ac_list[p]=1;
            
        }
    }

    int ac_sum = accumulate(ac_list.begin(), ac_list.end(), 0);
    int penalty_sum=0;
    for(int i=0;i<N;i++){   // AC=0でWAだけの場合は加算しない
        if(ac_list[i]!=0) penalty_sum += penalty[i];
    }

    cout << ac_sum << " "<< penalty_sum << endl;

    return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> vec(n + 1);
  vec[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> vec[i];
    vec[i] += vec[i-1];
  }
  
  vector<int> subt(n - k + 1);
  for (int i = 0; i < n - k + 1; i++) {
    subt[i] = vec[i+k] - vec[i];
  }
  double ans = 0;
  for (int i = 0; i < n - k + 1; i++) {
    double ave = (subt[i] + k) / 2.0;
    if (ans < ave) {
      ans = ave;
    }
  }
  printf("%f", ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

bool isprime[150000];
vector<ll int> prime;
void makeprime(){
	REP(i,150000) isprime[i] = true;
	for(int i=2;i<sqrt(150000);i++){
		for(int j=i+1;j<150000;j++){
			if(j%i==0) isprime[j] = false;
		}
	}
	for(int i=2;i<150000;i++) if(isprime[i]) prime.push_back(i);
}
int main(){
	makeprime();
	while(1){
		int n,p;
		cin >> n >> p;
		if(n==-1&&p==-1) break;
		vector<ll int> tmp;
		int k=0;
		while(1){
			if(prime[k] > n) goto label;
			else k++;
		}
label:		
		FOR(i,k,k+1+p){
			FOR(j,i,i+1+p){
				tmp.pb(prime[i]+prime[j]);
			}
		}
		sort(All(tmp));
		cout << tmp[p-1] << endl;

	}
	return 0;
 }

Measured memory_bytes: 1592
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll dp[k+1];
    memset(dp,0,sizeof(dp));
    rep(i,1,k){
        rep(x,0,n-1){
            if(i-a[x]>=0&&dp[i-a[x]]==0)dp[i]=1;
        }
    }
    cout<<(dp[k]?"First":"Second")<<endl;
    
    
    return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env python
# coding: utf-8

def gcd ( ax, ay):
    x = ax
    y = ay
    while (True):
        if x < y :
            tmp = x
            x = y
            y = tmp
        x=x %y
        if x == 0:
            return y
        elif x == 1:
            return 1



x,y = map(int, input().split())
print(gcd(x,y))


Measured memory_bytes: 5604
// 解説放送AC
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int tmp = 0;
    for (char c = 'a'; c <= 'z'; c++) {
      bool foundl = false;
      bool foundr = false;
      for (int j = 0; j < i; j++) {
        if (s.at(j) == c) foundl = true; 
      }
      for (int j = i; j < n; j++) {
        if (s.at(j) == c) foundr = true;
      }
      if (foundl && foundr) tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#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>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

 const int N=200005;
 const int inf=1e18;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
vector<int>adj[N];
vector<int>d;
vector<int>out,a;
void dfs(int x,int p,int ans){
    int j=upper_bound(d.begin(),d.end(),a[x])-d.begin();
    int rest=d[j];
    if(d[j-1]<a[x]&&a[x]<d[j]){
        d[j]=a[x];
        ans=max(ans,j);}
        out[x]=ans;
        for(int i=0;i<adj[x].size();i++){
            if(adj[x][i]!=p){
                dfs(adj[x][i],x,ans);
            }
        }
    
    d[j]=rest;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
    cin>>n;
    a.resize(n+1);
    // int a[n+1];
    for(int x=1;x<=n;x++){
        cin>>a[x];
    }
    for(int x=1;x<n;x++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    d.resize(n+1,inf);
    out.resize(n+1);
    d[0]=-1*inf;
    // oa(d);
    dfs(1,0,0);
    for(int x=1;x<=n;x++){
        cout<<out[x]<<endl;
    }









	
return 0;
}


Measured memory_bytes: 33204
#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;
	cin >> n;
	string s;
	map<string, int> mp;
	rep(i,n) {
		cin >> s;
		mp[s]++;
	}
	auto iter = mp.find("AC");
	if ( iter != end(mp) ) {
        cout << "AC x " << iter->second << endl;
    } else {
		cout << "AC x " << 0 << endl;
	}
	iter = mp.find("WA"); 
	if ( iter != end(mp) ) {
        cout << "WA x " << iter->second << endl;
    } else {
		cout << "WA x " << 0 << endl;
	}
	iter = mp.find("TLE"); 
	if (iter != end(mp) ) {
        cout << "TLE x " << iter->second << endl;
    } else {
		cout << "TLE x " << 0 << endl;
	}
	iter = mp.find("RE"); 
	if (iter != end(mp) ) {
        cout << "RE x " << iter->second << endl;
    } else {
		cout << "RE x " << 0 << endl;
	}
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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;}

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int q;
  cin >> s >> q;
  bool flg = true;
  string a = "", b = "";
  REP(i, q)
  {
    int t;
    cin >> t;
    if (t == 1)
    {
      if (flg) flg = false;
      else flg = true;
    }
    else
    {
      int f;
      string c;
      cin >> f >> c;
      if (f == 1 && flg) a = c + a;
      else if (f == 1 && !flg) b =  b + c;
      else if (f == 2 && flg) b = b + c;
      else a = c + a;
    }
  }
  if (flg) cout << a + s + b;
  else
  {
    REVERSE(s);
    REVERSE(a);
    REVERSE(b);
    cout << b + s + a;
  }

  return 0;
}


Measured memory_bytes: 1404