akhauriyash/Code-Regression huggingface dataset:
def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        dp2 = dp1[:]
        for j in range(m):
            if x[i] == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))


Measured memory_bytes: 5628
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    if N ==1:
        print(abs(A[-1]-W))
    else:
        print(max(abs(A[-1]-W), abs(A[-2]-A[-1])))
    
    '''
    A_max = max(A)
    A_min = min(A)
    
    ans = 0
    tmp1 = abs(Z - A[-1])
    tmp2 = abs(A[-1] - W)
    tmp3 = abs(A_max - A[-1])
    tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max == A[-1] or A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    print(max(tmp1, tmp2, tmp3, tmp4, tmp5))
    '''
            	
if __name__ == "__main__":
	main()


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

int main(){
    ll n; cin >> n;
    ll a,b; cin >> a >> b;
    cout <<  n/(a+b)*a + min(a, n-(n/(a+b))*(a+b) ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    int N, res = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        res += a - 1;
    }
    cout << res << endl;
}

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

int main(){
  int w, n;
  //vector<int> vec;
  int array[30];
 
 cin >> w >> n;

 // for(int i = 1; i <= w; i++) vec.push_back(i);
 // for(int i = 0; i < n; i++){
 //  int a, b, c;   
 //  scanf("%a,%b", &a, &b);
 //  c = vec.at(a);
 //  vec[a] = vec.at(b);
 //  vec[b] = c;
 //}

 for(int i = 1; i <= w; i++) array[i-1] = i;
 for(int i = 0; i < n; i++){
   int a, b, c;
   scanf("%d,%d", &a, &b);
   c = array[a-1];
   array[a-1] = array[b-1];
   array[b-1] = c;
 }

 // for(int i = 0; i < vec.size(); i++) cout << vec.at(i) << endl;
 for(int i = 0; i < w; i++) cout << array[i] << endl;

  return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N, K;
ll ans;
vector<ll> to[100005];

void dfs(ll pa, ll cur) {
	ll col;
	if(pa == -1) {
		col = K-1;
	} else {
		col = K - 2;
	}

	for(ll next: to[cur]) {
		if(next == pa) continue;
		ans *= col;
		ans %= DIV;
		col--;
		dfs(cur, next);
	}
}

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

	rep(i, N - 1) {
		ll a, b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	ans = K;
	dfs(-1, 0);
	cout << ans << endl;
}

Measured memory_bytes: 13712
#include <iostream>
#include <iomanip>
#include <math.h>
#include <vector>

using namespace std;

void Print(int wide, int height);

void Print(int wide, int height)
{
	for(int h = 0; h < height; h++){
		for(int w = 0; w < wide; w++){
			cout << "#";
		}
		cout << endl;
	}
}

int main(){
	int w, h;
	vector<int> wide;
	vector<int> height;
	
	wide.clear();
	height.clear();
	while(1){
		cin >> h;
		cin >> w;
		if(h == 0 && w == 0)	break;
		height.push_back(h);
		wide.push_back(w);
	}
	
	for(int i = 0; i < height.size(); i++){
		Print(wide[i], height[i]);
		cout << endl;
	}
	
}

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

typedef long long ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
#define pb push_back

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
    for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
    os << "("; os << v.first << ", " << v.second << ")"; return os;
}
void go() {
    cin.tie(nullptr) -> sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
const int N = 1e5 + 5;
vector<vector<int>> adj(N);
vector<int> vis(N), topo, dp(N);
void dfs(int node) {
    vis[node] = 1;
    for (int c : adj[node]) {
        if (!vis[c]) {
            dfs(c);
        }
    }
    topo.push_back(node);
}
int32_t main() {
    go();
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i);
        }
    }
    reverse(all(topo));
    for (int node : topo) {
        for (int c : adj[node]) {
            dp[c] = max(dp[c], dp[node] + 1);
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans;
}

Measured memory_bytes: 12132
#include <bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

const int N = 1e5 + 10;

int n, cnt, nxt[N], vis[N];
int a[N], sortA[N];
int b[N], sortB[N];

std::map <int, int> rankA, rankB;

il int read() {
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main() {
	n = read();
	for(rgi i = 1; i <= n; ++i)	a[i] = read();
	for(rgi i = 1; i <= n; ++i)	b[i] = read();
	//Input
	
	for(rgi i = 1; i <= n; ++i)	sortA[i] = a[i];
	for(rgi i = 1; i <= n; ++i)	sortB[i] = b[i];
	std::sort(sortA + 1, sortA + n + 1);
	std::sort(sortB + 1, sortB + n + 1);
	//Smallest Permutation
	
	for(rgi i = 1; i <= n; ++i) rankA[sortA[i]] = i;
	for(rgi i = 1; i <= n; ++i)	rankB[sortB[i]] = i;
	//Discrete 
	
	for(rgi i = 1; i <= n; ++i)	if(sortA[i] > sortB[i]) {
		puts("No");
		return 0;
	}
	
	for(rgi i = 1; i <= n - 1; ++i)	if(sortA[i + 1] <= sortB[i]) {
		puts("Yes");
		return 0;
	}
	//Exclusion
	
	for(rgi i = 1; i <= n; ++i) nxt[rankB[b[i]]] = rankA[a[i]];
	//Add edges
	
	for(rgi i = 1; i <= n; ++i) {
		if(!vis[i]) {
			int cur = i;
			do {
				vis[cur] = 1;
				cur = nxt[cur];
			} while(!vis[cur]); 
			cnt++;
		}
	}
	
	puts(cnt == 1 ? "No" : "Yes");
	
	return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>

int main(){
  int A,B,M;
  int a[100002],b[100002];
  int min_a=200000,min_b=200000,min;
  scanf("%d %d %d",&A,&B,&M);
  for(int i=1;i<=A;i++){
    scanf("%d",a+i);
    if(a[i]<min_a) min_a=a[i];
  }
  for(int i=1;i<=B;i++){
    scanf("%d",b+i);
    if(b[i]<min_b) min_b=b[i];
  }
  min=min_a+min_b;
  int x,y,c;
  for(int i=1;i<=M;i++){
    scanf("%d %d %d",&x,&y,&c);
    if(a[x]+b[y]-c<min) min=a[x]+b[y]-c;
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 2472
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  string s;
  cin >> s;
  
  if((s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) ||(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) ||(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[2])) cout <<"Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]
shift = 10**5+1

nodes = {}
visited = {}

for x,y in xy:
    y += shift
    if x in nodes:
        nodes[x].append(y)
    else:
        nodes[x] = [y]
    if y in nodes:
        nodes[y].append(x)
    else:
        nodes[y] = [x]
    visited[x] = False
    visited[y] = False

ans = 0

def dfs(s, nodes,visited):
    q = [s]
    cnt_x = 0
    cnt_y = 0
    
    while q:
        v = q.pop()
        if visited[v]:
            continue
        visited[v] = True
        
        if v//shift < 1:
            cnt_x += 1
        else:
            cnt_y += 1
            
        q.extend(nodes[v])
        
    return visited, cnt_x*cnt_y

for s in nodes:
    if visited[s]:
        continue
    visited, cnt = dfs(s,nodes, visited)
    ans += cnt
    
print(ans - N)

Measured memory_bytes: 43816
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
using namespace std;
#define REP(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define REP1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(){
    int judge=0,i,M,L;
    string S;
    cin>>S;
    M=(SZ(S)-1)/2;
    L=(SZ(S)+3)/2;
    REP1(i,0,M){
        if(S.at(i)!=S.at(SZ(S)-1-i))break;
        if(i==M)judge++;
    }
    REP1(i,0,M/2){
        if(S.at(i)!=S.at(M-1-i))break;
        if(i==M/2)judge++;
    }
    REP1(i,L-1,(L-1+M/2)){
        if(S.at(i)!=S.at(SZ(S)+L-i-2))break;
        if(i==(L-1+M/2))judge++;
    }
    if(judge==3)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a, b = map(int,readline().split())
print(max(2 * a - 1, 2 * b - 1, a + b))

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){
  ll h;
  std::cin >> h;

  ll ans = 0;
  ll multiplier = 0;
  while(h >= 1){
    ans += pow(2, multiplier);
    multiplier += 1;
    h /= 2;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
N = int(input())
h = list(map(int, input().split()))

dp = []
dp.append(0)
dp.append(abs(h[1]-h[0]))

for i in range(2,N):
     t1 = dp[i - 2] + abs(h[i] - h[i - 2])
     t2 = dp[i - 1] + abs(h[i] - h[i - 1])
     dp.append(min(t1, t2))



print(dp[N-1])


Measured memory_bytes: 20468
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;

struct C {
    ll A_{};
    ll B_{};
    explicit C(ll A, ll B) : A_(A), B_(B) {}
    ll resolve() {
        return max(A_*B_, max (A_+B_, A_-B_));
    }
};

int main() {
    ll A,B;
    cin >> A >> B ;
    C c{A, B};

    cout << c.resolve() << endl;
    return 0;
}


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

void solve()
{
    int n, k;
    cin >> n >> k;
    set<int> st;
    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        while (d--)
        {
            int temp;
            cin >> temp;
            st.insert(temp);
        }
    }
    cout << n - (int)st.size() << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int test = 1;
    if (multi_test)
        cin >> test;

    while (test--)
        solve();
    return 0;
}

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

int v[] = {7,56,73,84,146,273,292,448};

int main() {
	char c;
	while (cin >> c, c != '0') {
		int b = c=='b';
		int w = c=='w';
		for (int i=1; i<9; ++i) {
			cin >> c;
			b = b*2+(c=='b');
			w = w*2+(c=='w');
		}
		string res = "NA";
		for (int i=0; i<8; ++i) {
			if ((b|v[i])==b) res = "b";
			if ((w|v[i])==w) res = "w";
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1180
import scala.math.{abs, min}

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val h = Array.fill(n)(sc.nextInt)
  val dp = Array.fill(n)(10000)
  dp(0) = 0
  dp(1) = abs(h(0) - h(1))
  for (i <- 2 until n) {
    val x = dp(i-2) + abs(h(i-2) - h(i))
    val y = dp(i-1) + abs(h(i-1) - h(i))
    dp(i) = min(x, y)
  }
  println(dp.last)
}

Measured memory_bytes: 59348
n,m,p,i,x,s,w;
main()
{
  for(;scanf("%d%d%d",&n,&m,&p),n; printf("%d\n",w?(int)(s*((100-p)/100.0))/w:0))
    for(s=i=0;i++<n;s+=x*100)
      scanf("%d",&x),w=i-m?w:x;    
  exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    ll N, X;
    cin >> N >> X;
    vl A(N);
    rep(i, N) { cin >> A[i]; }

    vl suma(N - 1);
    rep(i, N - 1) { suma[i] = A[i] + A[i + 1]; }

    ll cnt = 0;
    rep(i, N - 1) {
        if (suma[i] > X) {
            ll diff = suma[i] - X;
            A[i + 1] = min(diff, A[i + 1]);
            suma[i + 1] -= min(diff, A[i + 1]);
            cnt += diff;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 4740
N, M = list(map(int, input().split()))
students = list()
checkpoints = list()

for i in range(N):
	students.append(list(map(int, input().split())))

for i in range(M):
	checkpoints.append(list(map(int, input().split())))

ans = [0] * N

for i in range(N):
	mindif = 4 * 10**8 + 1
	for j in range(M):
		dif = abs(students[i][0] - checkpoints[j][0]) + abs(students[i][1] - checkpoints[j][1])
		if dif < mindif:
			mindif = dif
			ans[i] = j + 1

for i in range(N):
	print(ans[i])


Measured memory_bytes: 3064
S = input()
T = input()

m = 0
for i in range(len(S) - len(T) + 1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            cnt += 1
    m = max(m, cnt)

ANS = len(T) - m

print(ANS)

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
const int N=2e5+3;
ll a[N],d[N],d1[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll i,j,n,l;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    d[0]=a[0];
    for(i=1;i<n;i++)
    {
        d[i]=a[i]+d[i-1];
    }
    d1[n-1]=a[n-1];
    for(i=n-2;i>=0;i--)
    {
        d1[i]=a[i]+d1[i+1];
    }
    ll mn=2e18;
    for(i=0;i<(n-1);i++)
    {
        mn=min(mn,(abs(d[i]-d1[i+1])));
    }
    cout<<mn<<"\n";
    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    LL n,a,b;
    cin>>n>>a>>b;

    LL result = 0;

    result += (LL)(n/(a+b)) * a;
    result += min(a,n%(a+b));

    cout<<result<<endl;

	return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;

int main (void){
	char s[11];
	int i,n,a[11],b[11];
	cin >> s;
	n=strlen(s);
	for(i=0;i<n;i++) a[i]=s[i]-'0';
	for(i=0;i<n-2;i++) b[i]=abs(100*a[i]+10*a[i+1]+a[i+2]-753);
	sort(b,b+n-2);
	cout << b[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; while(getline(stream,res,sp_word))
#define rem_space(x) x.erase(remove(all(x), ' '),x.end())
#define scl(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
typedef long long ll;
using namespace std;

int main(){
  string rgb;
  getline(cin,rgb);
  rem_space(rgb);

  if(i_str(rgb) % 4 == 0) puts("YES");
  else puts("NO");

  return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split()))
ax = []
for i in a:
    if (i % 4 == 0):
        t = 4
    elif (i % 2 == 0):
        t = 2
    else:
        t = 1
    ax.append(t)

ay = collections.Counter(ax)
if((ay[2] == 0 and ay[1] <= ay[4]+1) or(ay[2] != 0 and ay[1] <= ay[4])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14636
#include <bits/stdc++.h>      
#define pb push_back 
#define fr first 
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii; 

int main() {

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

    //int t; cin>>t; while(t--) { 
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k;
    else if(k<=a+b) cout<<a;
    else cout<<a-(k-b-a);
    return 0 ;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> CNT(26);
  string s;
  cin >> s;
  REP(i,SZ(s)){
    CNT[s[i]-'a']++;
  }
  string ans = "Yes";
  REP(i,26){
    if(CNT[i] % 2 != 0){
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,0,s.size()){
    if(s[i] != t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3912
fn main(){
    let mut line1 = String::new();
    let mut line2 = String::new();
    let stdin = std::io::stdin();
    stdin.read_line(&mut line1).expect("Could not read line");;
    stdin.read_line(&mut line2).expect("Could not read line");
    let p : Vec<_> = line1.trim().split(' ').collect();
    let n : usize = p[0].parse().unwrap();
    let s = line2.trim().as_bytes();
    for c1 in vec!['S', 'W'] {
        for c2 in vec!['S', 'W'] {
            let mut ret = Vec::new();
            ret.push(c1);
            ret.push(c2);
            for i in 2 .. n {
                if ret[i - 1] == 'S' {
                    if s[i - 1] == b'o' {
                        let x = ret[i - 2];
                        ret.push(x);
                    }
                    else {
                        let x = if ret[i - 2] == 'S' {'W'} else {'S'};
                        ret.push(x);
                    }
                }
                else {
                    if s[i - 1] == b'o' {
                        let x = if ret[i - 2] == 'S' {'W'} else {'S'};
                        ret.push(x);
                    }
                    else {
                        let x = ret[i - 2];
                        ret.push(x);
                    }
                }
            }
            if ((ret[1] == ret[n - 1]) == ((ret[0] == 'S') ^ (s[0] != b'o'))) && 
                ((ret[0] == ret[n - 2]) == ((ret[n - 1] == 'S') ^ (s[n - 1] != b'o'))) {
                    for i in 0 ..n {
                print!("{}", ret[i]);
                    }
            println!("");
                    return;
                }
        }
    }
    println!("-1");
    return;
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>

using namespace std;

int main(){
  int h,w;
  cin >> h >> w;
  for(int i=0;i<w+2;++i) cout << "#" ;
  cout << endl;
  for(int i=0;i<h;++i){
    string str;
    cin >> str;
    cout << "#" << str << "#" << endl;
  }
  for(int i=0;i<w+2;++i) cout << "#" ;
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
	int line[5];
	for (int i = 0; i < 5; ++i) {
		cin >> line[i];
	}
	int k;
	cin >> k;
	if (*max_element(line, line + 5) - *min_element(line, line + 5) > k) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define llint long long int
#define eps 1e-8

using namespace std;

llint w, h, v, t;
llint x, y, p, q;
llint R;

int main(void)
{
	cin >> w >> h >> v >> t >> x >> y >> p >> q;
	R = v*t;
	
	llint ans = 0;
	
	double X1, X2, Y, n1, n2;
	for(int i = 0; ; i++){
		Y = q + 2*h*i;
		X1 = R*R - (Y-y)*(Y-y);
		if(X1 < 0) break;
		if(X1 > 0) X1 = sqrt(X1);
		X2 = x - X1, X1 += x;
		
		n1 = (X1-p)/(2*w), n2 = (X2-p)/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
		
		n1 = (X1-p - 2*(w-p))/(2*w), n2 = (X2-p - 2*(w-p))/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
	}
	for(int i = -1; ; i--){
		Y = q + 2*h*i;
		X1 = R*R - (Y-y)*(Y-y);
		if(X1 < 0) break;
		if(X1 > 0) X1 = sqrt(X1);
		X2 = x - X1, X1 += x;
		
		n1 = (X1-p)/(2*w), n2 = (X2-p)/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
		
		n1 = (X1-p - 2*(w-p))/(2*w), n2 = (X2-p - 2*(w-p))/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
	}
	
	for(int i = 0; ; i++){
		Y = q + 2*h*i + 2*(h-q);
		X1 = R*R - (Y-y)*(Y-y);
		if(X1 < 0) break;
		if(X1 > 0) X1 = sqrt(X1);
		X2 = x - X1, X1 += x;
		
		n1 = (X1-p)/(2*w), n2 = (X2-p)/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
		
		n1 = (X1-p - 2*(w-p))/(2*w), n2 = (X2-p - 2*(w-p))/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
	}
	for(int i = -1; ; i--){
		Y = q + 2*h*i + 2*(h-q);
		X1 = R*R - (Y-y)*(Y-y);
		if(X1 < 0) break;
		if(X1 > 0) X1 = sqrt(X1);
		X2 = x - X1, X1 += x;
		
		n1 = (X1-p)/(2*w), n2 = (X2-p)/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
		
		n1 = (X1-p - 2*(w-p))/(2*w), n2 = (X2-p - 2*(w-p))/(2*w);
		ans += floor(n1) - floor(n2);
		if(n1 - (llint)n1 == 0 && n2 - (llint)n2 == 0) ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3064
import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * Created by khrom on 2017/06/15.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Point> rectList = new ArrayList<>();

        int h;
        int w;
        while (true) {
            h = scanner.nextInt();
            w = scanner.nextInt();
            if (h == 0 && w == 0)
                break;
            rectList.add(new Point(w, h));
        }

        for (Point point : rectList) {
            for (int i = 0; i < point.getY(); i++) {
                for (int j = 0; j < point.getX(); j++) {
                    if (i == 0 || i == point.getY() - 1 || j == 0 || j == point.getX() - 1)
                        System.out.print("#");
                    else
                        System.out.print(".");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 36536
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    while(1){
        cin >> s;
        if(s == "0") break;
        int n = s.size();
        vector<int> d(n + 1);
        d[0] = 0;
        rep(i, 0, n){
            if(i % 2 == 0){
                d[i + 1] = d[i] + (s[i] - '0');
            }else{
                d[i + 1] = d[i] - (s[i] - '0');
            }
        }
        map<int, int> mp;
        rep(i, 0, n + 1){
            mp[(d[i] % 11 + 11) % 11]++;
        }
        int ans = 0;
        for(auto it = mp.begin(); it != mp.end(); it++){
            ans += it -> second * (it -> second - 1) / 2;
        }
        int cnt[11] = {};
        rep(i, 0, n){
            int now = (d[i + 1] % 11 + 11) % 11;
            int pre = (d[i] % 11 + 11) % 11;
            if(s[i] == '0'){
                cnt[pre]++;
            }
            ans -= cnt[now];            
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    if (N % 2) {
        cout << 0 << endl;
        return 0;
    }

    ll k = 10;
    static ll cnt[30];
    for (int i = 0; k <= N; i++, k *= 5) {
        cnt[i] = N / k;
        if (i > 0)
            cnt[i - 1] -= cnt[i];
    }
    ll ans = 0;
    for (int i = 0; i < 30; ++i)
        ans += cnt[i] * (i + 1);

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


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<vector<int> > a(n, vector<int> (3)), dp(n, vector<int> (3));
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 3; j++)
		cin>>a[i][j];
	}
	dp[0][0]=a[0][0], dp[0][1]=a[0][1], dp[0][2]=a[0][2];
	for(int i = 1; i < n; i++)
	{
		// int m1 = max{a[i][2]
		dp[i][0] = max(a[i][0]+dp[i-1][1], a[i][0]+dp[i-1][2]);
		dp[i][1] = max(a[i][1]+dp[i-1][0], a[i][1]+dp[i-1][2]);
		dp[i][2] = max(a[i][2]+dp[i-1][1], a[i][2]+dp[i-1][0]);
	}
	int ans = max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
	cout<<ans<<endl;
}

Measured memory_bytes: 11264
import sys
import math
from decimal import Decimal
def input(): return sys.stdin.readline().rstrip()

A,B,H,M = map(float,(input().split()))

minute = H * 60 + M
short = minute / (60 * 12) * 2 * math.pi
long = M / 60 * 2 * math.pi
rad = abs(long - short) 

ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(rad))
print(ans)

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

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

    if(e - a<=k){
        cout << "Yay!" << endl;
    }

    else {
        cout << ":(" << endl;
    }
    
}

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

int main()
{
	int minn;
	int maxx=-2000000000;
	int n;
	cin>>n;
	int num=0;
	cin>>num;
	minn=num;
	for(int i=1;i<n;i++)
	{
		cin>>num;
		if(num-minn>maxx)
			maxx=max(num-minn,maxx);
			//maxx=num-minn;
		if(num<minn)
			//minn=num;
			minn=min(num,minn);
		
	}
	cout<<maxx<<endl;
	
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;

char s[N];

int main()
{
	fast;
	cin>>s+1;
	n=strlen(s+1);
	ll cnt=0;
	fo(i,1,n+1)
	{
		ar[i]=cnt;
		if(s[i]=='<')
			cnt++;
		else
			cnt=0;
	}
	cnt=0;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='>')
			cnt++;
		else
			cnt=0;
		ar[i]=max(cnt,ar[i]);

	}
	fo(i,1,n+1)
	{
		sum+=ar[i];
		// cout<<ar[i]<<sp;
	}
		// cout<<endl;
	cout<<sum;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 5888
n, k = [int(x) for x in input().split()]

prob = 0.0
t = 0

for i in range(1, n+1):
    point = i
    for j in range(0, k+1):
        point = i * 2 ** j
        if point >= k:
            t = j
            break
    prob += (1.0/n) * (0.5)**t

print(prob)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf LLONG_MAX/10000000
#define INF LLONG_MAX/3
#define P pair<int,int>
using namespace std;
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int b=a[n-1];
  int c=a[0];
  cout<<b-c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int R, G;
  cin >> R >> G;
  cout << 2 * G - R << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

/*
int S[3];
void rec( int i )
{
	cout<<i<<endl;
	if( i==3 )
	{
		cout<<S[0]<<S[1]<<S[2]<<endl;
		return;
	}
	
	rec( i+1 );
	S[i] = 1;
	rec( i+1 );
	S[i] = 0;
	return;
}

void makeCombination()
{
	rep( i,3 )
		S[i]=0;
	rec(0);
}
*/

int n,A[50];

int solve(int i, int m)
{
	if( m==0 )return 1;
	if( i>=n )return 0;
	int res = solve( i+1, m ) || solve( i+1, m-A[i] );
	return res;
}


int main()
{
	int q,m;
	cin>>n;
	rep(i,n)cin>>A[i];
	cin>>q;
	rep(i,q)
	{
		cin>>m;
		if(solve(0,m))cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


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

#define ll long long
#define eb emplace_back
#define nl '\n'
#define deb(x) cerr << #x" = " << x << nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int32_t main()
{
    int k; cin >> k; cout << a[k - 1] << nl;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
using namespace std;
vector<int> a,b,ans;
int pos = 0;
void dfs(int l,int r)
{
	if(l >= r) return ;
	int root = a[pos++];
	int dis = distance(b.begin(),find(b.begin(),b.end(),root));
	dfs(l,dis); dfs(dis+1,r);
	ans.push_back(root); 
}
int main(void)
{
	int n,k;
	scanf("%d",&n);
	for(int i = 0;i < n;i++) scanf("%d",&k),a.push_back(k);
	for(int i = 0;i < n;i++) scanf("%d",&k),b.push_back(k);
	dfs(0,n);
	for(int i = 0;i < n;i++) printf("%d%c",ans[i],(i == n-1)?'\n':' ');
	return 0;
}


Measured memory_bytes: 3280
#include <stdio.h>
int main()
{
  int n,i,t,max,min,sum;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    max=0;
    min=1001;
    sum=0;
    for(i=0;i<n;i++){
      scanf("%d",&t);
      if(t>max)max=t;
      if(t<min)min=t;
      sum+=t;
    }
    sum=sum-max-min;
    printf("%d\n",sum/(n-2));
  }
  return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <stdlib.h>
#define N 10
int cmp(const void * a, const void * b) {
  return (* (float *) a > * (float *) b) - (* (float *) a < * (float *) b);
}
int main(void){
  int d[10];
  int i;
  for(i=0;i<N;i++) scanf("%d",&d[i]);
  qsort(d,N,sizeof(float),cmp);
  for(i=N-1;i>N-4;--i) printf("%d\n",d[i]);
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <stdlib.h>

#define TRUE 1
#define FALSE 0

int solve(int, int, int, int A[]);

int main()
{
  int i, n, *A, q, m;

  scanf("%d", &n);

  /* 数列Aを動的に確保し、読み込む　*/
  A = (int *)malloc( sizeof(int) * n );
  for( i = 0; i<n; i++ )
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for( i = 0; i<q; i++ )
    {
      scanf("%d", &m);

      /* Aの要素の中のいくつかの要素を足し合わせてmが作れるか判定し、結果を出力　*/
      if( solve(0, m, n, A) == TRUE )
	printf("yes\n");
      else
	printf("no\n");
    }
  return 0;
}

/* Aの要素の中のいくつかの要素を足し合わせてmが作れるかを判定する関数
   引数：　i-> Aの添え字　　n-> Aの要素数　
　　戻り値：　作れる-> TRUE　　　作れない-> FALSE */
int solve(int i, int m, int n, int A[])
{
  if( m == 0 )
    return TRUE;
  if( i >= n )
    return FALSE;

  return solve( i+1, m, n, A) || solve( i+1, m-A[i], n, A);     /* 左の呼び出し：A[i]を選択しない場合
　右の呼び出し：A[i]を選択した場合*/
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("YES");
	else say("NO");
}

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	yn((10 * g + b) % 4 == 0);
}

Measured memory_bytes: 256
s = int(input())
s1 = s//100
s2 = s%100

if 0<s1<13 and 0<s2<13:
  print('AMBIGUOUS')
elif 0<s1<13:
  print('MMYY')
elif 0<s2<13:
  print('YYMM')
else:
  print('NA')


Measured memory_bytes: 2940
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    L = [i_list() for i in range(n-1)]

    ans = []

    for l in range(n-1):
        time = L[l][1] + L[l][0]
        for j in range(n-l-2):
            t = l+j+1
            if time <= L[t][1]: # まだ出発していない
                time = L[t][1] + L[t][0]
            elif (time - L[t][1]) % L[t][2] == 0: # ちょうど出発タイミング
                time += L[t][0]
            else: # すでに出発はしていて、待ち時間発生
                s = (time - L[t][1])//L[t][2] + 1
                time = L[t][1] + L[t][2]*s + L[t][0]
        print(time)
    print(0)




if __name__=="__main__":
    main()


Measured memory_bytes: 74672
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		String line = f.readLine();
		boolean[] dir = new boolean[4];
		for(int i = 0; i < line.length(); i++) {
			char now = line.charAt(i);
			if(now == 'N') dir[0] = true;
			if(now == 'S') dir[1] = true;
			if(now == 'E') dir[2] = true;
			if(now == 'W') dir[3] = true;
		}
		if(dir[0] == dir[1] && dir[2] == dir[3]) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 9428
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

ll dp[2][2019];

int main() {
    string s;
    cin >> s;
    for (int r : irange(2019)) {
        dp[0][r] = 0;
        dp[1][r] = 0;
    }
    ll ans = 0;
    for (int j : irange(0UL, s.size())) {
        int n = s[j] - '0';
        TRACE(j, n);
        for (int r : irange(2019)) {
            int nr = (r * 10 + n) % 2019;
            dp[(j+1)%2][nr] = dp[j%2][r];
        }
        dp[(j+1)%2][n]++;
        ans += dp[(j+1)%2][0];
    }
    cout << ans << nl;
}


Measured memory_bytes: 3812
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环
# def dfs(f, s, fa=-1):
#     if s % 2 == 0: 
#         used[f] = 1
#     for t, w in v[f]:
# #         print('%d->%d->%d'%(fa, f, t,), s, w)
#         if t == fa:continue
#         dfs(t, w + s, f)
from queue import Queue
q = Queue()
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1))
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]:
    print(used[i])

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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int zero=0,one=0;
  for(int i=0;i<n;i++){
    if(s[i]==')') one++;
    else break;
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]=='(') zero++;
    else break;
  }
  
  int a=0,b=0,c=0;
  for(int i=one;i<n-zero;i++){
    if(s[i]=='(') a++;
    else{
      if(b<a) b++;
      else c++;
    } 
  }
  
  one+=c;
  zero+=(a-b);
  
  for(int i=0;i<one;i++) cout<<'(';
  cout<<s;
  for(int i=0;i<zero;i++) cout<<')';
  cout<<endl;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
X = list(map(int, input().split()))

def calc_energy(i, X):
    X = np.array(X)
    return sum((X-i)**2)

min_energy = 1000000000
min_ind = min(X)
max_ind = max(X)
for i in range(min_ind, max_ind+1):
   energy = calc_energy(i, X) 
   if energy < min_energy:
       min_energy = energy
print(min_energy)


Measured memory_bytes: 12448
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A
// Prim's algorithm using a priority queue
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

int main(int arg, char **argv)
{
        int V, E;
        cin >> V >> E;
        vector<vector<pair<int, int>>> A(V);
        for (int i = 0; i < E; i++) {
                int s, t, w;
                cin >> s >> t >> w;
                A[s].push_back({w, t});
                A[t].push_back({w, s});
        }
        vector<bool> U(V);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
        q.push({0, 0});
        int sum = 0;
        while (!q.empty()) {
                auto c = q.top();
                q.pop();
                if (U[c.second])
                        continue;
                U[c.second] = true;
                sum += c.first;
                for (auto &a: A[c.second])
                        if (!U[a.second])
                                q.push(a);
        }
        cout << sum << endl;
        return 0;
}

Measured memory_bytes: 6760