akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
 
 
main(){
  int n;
  while(cin>>n,n){
    int m;
    cin>>m;
    m--;
    int hit;
    cin>>hit;
    hit--;

    int d;
    cin>>d;
    string sen[d];
    rep(i,d)cin>>sen[i];

    int ans=-1;

    int dan=0,hon=m;
    while(dan<d){
      if(hon && sen[dan][hon-1]=='1'){
	hon--;
      }else if(hon+1<n && sen[dan][hon]=='1')++hon;
      ++dan;
      //cout<<dan<<" "<<hon<<endl;
    }
    if(hon==hit){
      cout<<0<<endl;
      continue;
    }

    rep(i,d){
      rep(j,n-1){
	if(sen[i][j]=='1')continue;
	if(j && sen[i][j-1]=='1')continue;
	if(j+2<n && sen[i][j+1]=='1')continue;
	sen[i][j]='1';
	dan=0,hon=m;
	while(dan<d){
	  if(hon && sen[dan][hon-1]=='1'){
	    hon--;
	  }else if(hon+1<n && sen[dan][hon]=='1')++hon;
	  ++dan;
	}
	sen[i][j]='0';
	if(hon==hit){
	  cout<<i+1<<" "<<j+1<<endl;
	  goto NEXT;
	}
      }
    }
    cout<<1<<endl;
  NEXT:;
  }
}

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

using namespace std;

bool flag[30];

int main(void) {
    int a;
    for (int i = 0; i < 28; i++) {
        cin >> a;
        flag[a - 1] = true;
    }

    for (int i = 0; i < 30; i++)
        if (!flag[i]) cout << i + 1 << endl;
    
    return 0;
}


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

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int min_price;

  for (int i = 0; i <= X + Y; i++) {
    int price = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i);
    min_price = (i == 0) ? price : min(min_price, price);
  }

  cout << min_price << endl;
}

Measured memory_bytes: 3596
r, g, b, n = gets.split.map(&:to_i)
ans = 0
0.upto(n) do |i|
  break if r * i > n
  0.upto(n) do |j|
    break if r * i + g * j > n
    c = n - r * i - g * j
    ans += 1 if c % b == 0 && c <= n * b;
  end
end
puts ans

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

typedef long long ll;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(a<=b){
        if(a+w>=b) {cout << 0 << endl;
        return 0;
        }
    }else
    {
        if(b+w>=a){ cout << 0 << endl;
        return 0;
        }
    }
    
    cout << max(b-a-w, a-b-w) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

sum_w = [0]
sum_e = [0]

count = 0
for i in range(N-1):
  if S[i] == "W":
    count += 1
  sum_w.append(count)

count = 0
for i in range(N-1,0,-1):
  if S[i] == "E": 
    count += 1
  sum_e.append(count)
sum_e = sum_e[::-1]

#print(len(sum_e), len(sum_w))
sumu = [x+y for x, y in zip(sum_w, sum_e)]

print(min(sumu))

Measured memory_bytes: 30840
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int[] to = new int[26];
        int[] ds = new int[26];
        for (int i = 0; i < 26; i++) {
            to[i] = -1;
            ds[i] = -1;
        }
        String s = sc.next();
        String t = sc.next();
        boolean ok = true;
        for (int i = 0; i < s.length(); i++) {
            int a = s.charAt(i) - 'a';
            int b = t.charAt(i) - 'a';

            if (to[a] == -1) {
                to[a] = b;
            }
            if (ds[b] == -1) {
                ds[b] = a;
            }
            if (to[a] != b || ds[b] != a) {
                ok = false;
                break;
            }
        }
        System.out.println(ok ? "Yes" : "No");
    }

}


Measured memory_bytes: 27980
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 100005;

inline int read()
{
	int ret, f=1;
	char c;
	while((c=getchar())&&(c<'0'||c>'9'))if(c=='-')f=-1;
	ret=c-'0';
	while((c=getchar())&&(c>='0'&&c<='9'))ret=(ret<<3)+(ret<<1)+c-'0';
	return ret*f;
}

int n, m, v, p, a[maxn];

bool check(int x)
{
	int val = a[x] + m, cnt = 0;
	ll rst = 1LL * (v - 1) * m;
	for(int i = n; i > x; --i)
	{
		if(a[i] > val)
		{
			++ cnt;
			rst -= m;
		}
		else
		{
			if(cnt < p - 1)
			{
				++ cnt;
				rst -= m;
			}
			else
			{
				rst -= (val - a[i]);
			}
		}
	}
	if(cnt >= p)	return 0;
	return rst <= 1LL * m * (x - 1);
}

int main()
{
	n = read(); m = read(); v = read(); p = read();
	for(int i = 1; i <= n; ++i)
		a[i] = read();
	sort(a + 1, a + n + 1);
	int l = 1, r = n, mid, ans;
	while(l <= r)
	{
		int mid = (l + r) >> 1;
		if(check(mid))
			ans = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	printf("%d", n - ans + 1);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,n,c=0;
    
    cin>>n;
    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            c+=i;
        }
    }
    
    cout<<c;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    cin >> N;
    print((N-1)/2);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, l, r; cin >> l >> r;
	if (r - l >= 2019) {
		cout << '0' << endl;
		return 0;
	}
	long long ans = 2020;
	for (long long i = l; i <= r - 1; i++) {
		for (long long h = i + 1; h <= r; h++) {
			ans = min(ans, i * h % 2019);
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	string S,T;
	cin >> S >> T;
	vector<string> koho;
	for(int i=0; i<S.size()-T.size()+1; i++){
		string tmp = "";
		int j = 0;
		for(; j<i; j++){
			if(S[j] == '?') tmp += 'a';
			else tmp += S[j];
		}
		for(; j<i+T.size(); j++){
			if(S[j] == T[j-i] || S[j] == '?') tmp += T[j-i];
			else j = 100;
		}
		for(; j<S.size(); j++){
			if(S[j] == '?') tmp += 'a';
			else tmp += S[j];
		}
		if(j != 101) koho.push_back(tmp);
	}
	if(koho.size() > 0){
		sort(koho.begin(), koho.end());
		cout << koho[0] << endl;
	}
	else{
		cout << "UNRESTORABLE" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
int main(){
  int i, j, n;
  cin >> n;
  long long a[n], ans=0, ct=0, sum=0;
  for(i=0; i<n; i++)
    cin >> a[i];
  long long b[n+1];
  b[0]=0;
  b[1]=a[0];
  for(i=1; i<n; i++)
    b[i+1]=b[i]+a[i];
  sort(b, b+n+1);
  for(i=0; i<n; i++){
    if(b[i]==b[i+1]) {ct++;
      ans+=ct;
    }
    else{
      //if(ct>0) ans+=factorial(ct);
      ct=0;
    }
  }
  //if(ct>0) ans+=factorial(ct);
  cout << ans;
  return 0;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fft(A, B):
    """ 
    高速フーリエ変換(FFT)
        A：出現回数をカウントしたリスト
        B：出現回数をカウントしたリスト
    """
    import numpy as np
    from numpy.fft import rfft, irfft

    # 出現数カウント
    MAXA = max(A)
    MAXB = max(B)
    C1 = [0] * (MAXA+1)
    C2 = [0] * (MAXB+1)
    for a in A:
        C1[a] += 1
    for b in B:
        C2[b] += 1
    # max(A)+max(B)より大きい2冪
    L = 1
    k = 0
    while L <= MAXA + MAXB:
        k += 1
        L = 2**k
    # FFT
    res = irfft(rfft(C1, L) * rfft(C2, L), L)
    # 四捨五入して整数に
    res = np.rint(res).astype(np.int64)
    return res

N, M, L = MAP()
A = LIST()
B = LIST()

res = list(fft(A, B))

mn = INF
for i, a in enumerate(res):
    if a != 0:
        mn = i
        break

for _ in range(L):
    x, y, c = MAP()
    x -= 1; y -= 1
    mn = min(mn, A[x] + B[y] - c)
print(mn)


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

#define min(a, b) ((a) > (b) ? (b) : (a))
#define INT_MAX 0x7fffffff


int main(void) {
    int n, k ;
    scanf("%d %d", &n, &k);

    int *arr = malloc(sizeof(int) * n);
    for(int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    int dp[100001] = {
        [ 0 ... 100000 ] = INT_MAX
    };
    dp[0] = 0; 
    
    for(int i = 1; i < n; i++) {
        for(int j = i - k; j < i; j++) 
            if(j >= 0)
                dp[i] = min(dp[i], dp[j] + abs(arr[j] - arr[i]));
    }
    
    printf("%d\n", dp[n - 1]);

    return 0;
}





Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, x, i, j, k, p;
	cin >> n >> x;
	vector<int> a(n * 2 - 1, -1);

	if ((x == 1) || (x == 2 * n - 1)) cout << "No\n";
	else {
		if (n == 2) cout << "Yes\n1\n2\n3\n";
		else {
			set<int> s;
			if (x == 2) {
				a[n - 2] = x + 1;
				a[n - 1] = x;
				a[n] = x - 1;
				a[n + 1] = x + 2;
			}
			else {
				a[n - 2] = x - 1;
				a[n - 1] = x;
				a[n] = x + 1;
				a[n + 1] = x - 2;
			}
			s = { a[n - 2], a[n - 1], a[n], a[n + 1] };
			p = 0;
			for (i = 1; i <= 2 * n - 1; i++) {
				if (s.find(i) == s.end()) {
					while ((p < 2 * n + 1) && (a[p] != -1)) p++;
					a[p] = i;
				}
			}

			cout << "Yes\n";
			for (auto p : a) cout << p << "\n";
		}
	}
		

	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
using namespace std;
#define LEN 100
int A,B,C,D;
void solve()
{
    int i,ans=0,*inp=new int[LEN+1];
    for (i=0;i<=LEN;i++)
        inp[i]=0;
    for (i=A;i<B;i++)
        inp[i]=1;
    for (i=C;i<D;i++)
        if (!inp[i]) inp[i]=2;
        else inp[i]=3;
    for (i=0;i<=LEN;i++)
        if (inp[i]==3) ans++;
    cout<<ans<<endl;
}
int main()
{
    while(cin>>A>>B>>C>>D)
        solve();
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;

const int maxn=100010;
int n;
int a[maxn], b[maxn];
int s;
map<int,int> mp;
vector<int> g[maxn];
int ans;
int vis[maxn];

void dfs(int x){
	vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i];
		if(!vis[v]){
			dfs(v);
		}
	}
}

int res;
int num[maxn], cnt;
int main(){

	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]), s^=a[i], mp[a[i]]++;
	mp[s]++;
	for(int i=1;i<=n;i++) num[++cnt]=a[i];
	num[++cnt]=s;
	sort(num+1,num+1+cnt);
	cnt=unique(num+1, num+1+cnt)-num-1;
	for(int i=1;i<=n;i++){
		scanf("%d", &b[i]);
		if(!mp.count(b[i])){ puts("-1"); return 0; }
		if(!mp[ b[i] ]){ puts("-1"); return 0; }
		mp[ b[i] ]--;
	}
	for(int i=1;i<=n;i++) if(mp[ a[i] ]) res=a[i];
	if(!res) res=s;
	int x, y;
	for(int i=1;i<=n;i++){
		if(a[i]==b[i]) continue;
		ans++;
		x=lower_bound(num+1, num+1+cnt, a[i])-num;
		y=lower_bound(num+1, num+1+cnt, b[i])-num;
		g[x].push_back(y);
	}
	x=lower_bound(num+1, num+1+cnt, s)-num;
	y=lower_bound(num+1, num+1+cnt, res)-num;
	g[x].push_back(y); ans++;
	// printf("%d\n", ans);
	for(int i=1;i<=cnt;i++){
		if(!vis[i] && g[i].size()) dfs(i), ans++;
	}
	printf("%d", ans-2);
	return 0;
}


Measured memory_bytes: 15104
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 1005

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int dp[ARRAY_MAX][ARRAY_MAX];//dp[i][j]:=i番目までを見た時に重さとなる時の最大価値

int main() {

	int W;
	int cnt = 1;
	while (cin >> W, W)
	{
		int n;
		char c;
		cin >> n;
		vector<int> v(n), w(n);
		for (int i = 0; i < n; i++)
		{
			cin >> v[i] >> c >> w[i];
		}

		for (int i = 0; i < ARRAY_MAX; i++)
		{
			for (int j = 0; j < ARRAY_MAX; j++)
			{
				dp[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= W; j++) {
				if (j + w[i] > W) {
					//重さを上限を超える場合は入れられない
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				}
				else {
					//入れられる場合
					dp[i + 1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i]);//入れる場合
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);//入れない場合
				}	
			}
		}
		int ans_w = 0;
		int ans_v = 0;

		for (int i = 0; i <= W; i++)
		{

			if (ans_v < dp[n][i])
			{
				ans_v = dp[n][i];
				ans_w = i;
			}
		}
		cout << "Case " << cnt << ":" << endl;
		cout << ans_v << endl << ans_w << endl;
		cnt++;
		v.shrink_to_fit();
		w.shrink_to_fit();
	}
}


Measured memory_bytes: 7024
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

const int INF = 1 << 30;

void m_min(int& a, int b)
{
    if (a > b) a = b;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n+k, 0);
    for (int i = 0; i < n; ++i) cin >> h[i];
    
    vector<int> dp(n+k, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            m_min(dp[i + j], abs(h[i] - h[i+j]) + dp[i]);
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[33000]={0,0,1,1},c,i,j;
  for(i=4;i<33000;i++){
    for(j=2,c=1;j*j<=i;j++){
      if(i%j==0)c--;
    }
    if(c>0)a[i]=1;
    else a[i]=0;
  }
  while(cin>>n,n){
    for(i=3,c=0;i<n;){
      for(j=n-1;j>2;){
	if(i+j==n)c++;
	while(!a[--j]);
      }
      while(!a[++i]);
    }
    cout<<(c-1)/2+1<<endl;
  }
}

Measured memory_bytes: 3132
n, m = map(int, input().split())
mod = (10 ** 9) + 7

arr = [int(input()) for i in range(0, m)]
dp = [0] * (n + 1)
dp[0] = 1

def solve():

  ok = [True] * (n+1)
  for i in range(0, m):
    ok[arr[i]] = False

  for step in range(1, n+1):
    if ok[step] == False:
      dp[step] = 0
    else:
      if step == 1:
        dp[step] = 1
      else:
        dp[step] = dp[step-1] + dp[step-2]

  print(dp[n] % mod)

def main():
  solve()

if __name__ == "__main__":
  main()

Measured memory_bytes: 460788
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return


template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int)2e5+123



void solve(){
	ll a, b;
	cin >> a >> b;
	cout << a * b << endl;
}
int main(){_
    solve();
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    string S;cin >> S;
    vector<int> East(N);
    vector<int> West(N);

    rep(i,N){
        if(S[i] == 'E')East[i] = 1;
        else West[i] = 1;
    }     
    vector<int> right_E(N); //累積和たち(i番目までに左or右にいるEorWの人数。)
    vector<int> left_W(N);

    rep(i,N){
        if(i == 0){
            left_W[0] = 0;
        }
        else{
            left_W[i] = left_W[i-1] + West[i-1];
        }
    }
    for(int i = N-1;i >= 0;i--){
        if(i == N-1){
            right_E[N-1] = 0;
        }
        else{
            right_E[i] = right_E[i+1] + East[i+1];
        }
    }
    
    int ans = 1 << 30;  //INF
    rep(i,N){
        ans = min(ans,left_W[i] + right_E[i]);
    }

/*  for(auto x : left_W){
        cout << x << " ";
    }
    cout << endl;
    for(auto y : right_E){
        cout << y << " ";
    }
    cout << endl;
*/

    cout << ans << endl;
}

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

int max(int a,int b){
    return a>b?a:b;
}

int main() {
	
    ll n,k,i,j;
    cin>> n >> k;
    ll a[n+1],w[n+1];
    ll dp[k+1][n+1];
    
    for(i=1;i<=n;i++) {
    cin>>a[i] >> w[i];
    dp[0][i] = 0;
    }
    dp[0][0] = 0;
    
    for(i=1;i<=k;i++) {
        dp[i][0] = 0;
        for(j=1;j<=n;j++) {
            if(a[j]>i)
            dp[i][j] = dp[i][j-1];
            else
            dp[i][j] = max(dp[i][j-1], w[j] + dp[i-a[j]][j-1]);
        }
    }
    cout << dp[k][n];
}


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



int main () {
  int64_t n , k ; 
  cin >> n >> k ; 
  vector<int> a(n) ;
  vector<int> s ; //訪れた街
  vector<int> ord(n+1,-1) ;//i番目に訪れた街の順番 
  
  for(int i = 0 ; i < n ; i++){
    cin >> a.at(i) ; //行き先
    
  }

  int c = 1 ; 
  int l = 0 ; 
  {
    int v = 1;//一番最初の街は1
    while(ord[v] == -1){
      ord[v] = s.size(); 
      s.push_back(v);
      v = a[v-1] ; 
    }
    c = s.size() - ord[v] ;
    l = ord[v] ; 
  }


  if(k < l) cout << s[k] << endl ;
  else {
    k -= l ; 
    k %= c ;
    cout << s[l+k] << endl ; 
  }
}

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  set<string> SE;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j <= i; j++) {
      if (i - j + 1 > K) continue;
      SE.insert(S.substr(j, i - j + 1));
    }
  }
  cout << *next(SE.begin(), K - 1) << "\n";
}

Measured memory_bytes: 4780
//my vegetable has exploded. :(
#include<bits/stdc++.h>
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MM(x,y) memset(x,y,sizeof(x))
#define MCPY(a,b) memcpy(a,b,sizeof(b))
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define fi first
#define se second
using namespace std;
#define int long long

inline int quickpow(int m,int n,int p){int b=1;while(n){if(n&1)b=b*m%p;n=n>>1;m=m*m%p;}return b;}
inline int getinv(int x,int p){return quickpow(x,p-2,p);}
inline int read(void){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){f=ch=='-'?-1:1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x * f;
}
int n,k;
///------------------head------------------
signed main(signed argc, char *argv[]){
    n = read(),k = read();
    if (k & 1)
        printf("%lld\n",(n/k)*(n/k)*(n/k));
    else {
        int d = 0;
        rep(i,1,n) if(i % k == (k >> 1)) ++d;
        printf("%lld\n",(n/k)*(n/k)*(n/k) + d*d*d);
    }
    return 0;
}

/* Examples: */
/*

*/

/*

*/


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

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long A, long long B, long long C){
  op(max((C-(A-B)),(ll)0))
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
import static java.lang.Math.*;

import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];

		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}

		int[] dp = new int[N];
		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			int m = Integer.MAX_VALUE;
			for (int j = max(0, i - K); j < i; j++) {
				m = min(m, dp[j] + abs(h[j] - h[i]));
			}
			dp[i] = m;
		}
		out.println(dp[N - 1]);
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 51248
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    if L[a] + L[b] > L[n-1]:
      count += n - b - 1
      continue
    left = b + 1
    right = n - 1
    while right - left > 0:
      c = (left+right) // 2
      if L[c] < L[a] + L[b]:
        left = c + 1
      else:
        right = c
    count += left - b - 1
print(count)

Measured memory_bytes: 43356
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,ans1=0,ans2=0;
	cin >> n >> m >> x;
	int a[n];
	for(int i=0;i<n;i++)
		a[i]=0;
	for(int i=0;i<m;i++)
	{
		int b;
		cin >> b;
		a[b]++;
	}
	for(int i=0;i<x;i++)
		ans1 += a[i];
	for(int i=x;i<n;i++)
		ans2 += a[i];
	cout << min(ans1,ans2);
	return 0; 
} 

Measured memory_bytes: 256
# frozen_string_literal: true

def chmin(a, b)
  a > b ? b : a
end
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l = 10_000_000_000
a.each do |i|
  l = chmin(l, i)
end
cnt = 0
a.each do |i|
  cnt += 1 if l == i
end

n -= cnt
ans = 0
ans += (n / (k - 1)) if n != 0
ans += 1 if n % (k - 1) != 0
puts ans


Measured memory_bytes: 8076
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    ll sum = 0;
    vll A(N), B(N), C(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
    }
    sort(all(A));
    sort(all(B));
    if(N%2)
    {
        int medA = A[(N+1)/2-1],medB=B[(N+1)/2-1];
        cout<<medB-medA+1;
    }
    else
    {
        int medA = (A[N/2-1]+A[N/2]),medB=(B[N/2-1]+B[N/2]);
        cout<<medB-medA+1;
    }
    
    return 0;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1,T2> &p) const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ h2;  
    }
};
using Vote = pair<ll,ll>;
using Unordered_map = unordered_map<Vote, int, pair_hash>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define showvec(arr,a,b) for(ll i=a;i<b;i++) cout<<arr[i]<<" ";
#define read_input(arr,a,b) for(ll i=a;i<b;i++) cin>>arr[i];
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define SmooothOperatorrrrr()                 \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                    \
    cout.tie(0);                   
#define deci(n) cout<<fixed<<setprecision(n)
const int mod=998244353;
const int mod2=1000000007;
#define M_PI 3.14159265358979323846
#define LL_MAX 9223372036854775807
#define MAXN 2000001
/**************************************************************************************************/
int h,w;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

bool isValid(int x,int y,string arr[])
{
    if(x>=0&&x<=h-1&&y>=0&&y<=w-1)
    {
        if(arr[x][y]=='.')
            return true;
    }
    return false;
}

int main()
{
    SmooothOperatorrrrr();
    cin>>h>>w;
    int ch,cw,dh,dw;cin>>ch>>cw>>dh>>dw;
    ch--;cw--;dh--;dw--;
    string arr[h];
    FOR(i,0,h)
        cin>>arr[i];
    int dp[h][w];
    FOR(i,0,h)
        FOR(j,0,w)
            dp[i][j]=1e7;
    // 0-1 BFS
    deque<pair<int,int>> q;
    q.push_front({ch,cw});
    dp[ch][cw]=0;

    while(!q.empty())
    {
        int x=q.front().F;
        int y=q.front().S;
        q.pop_front();
        FOR(i,0,4)
        {
            int newx=x+dx[i];
            int newy=y+dy[i];
            if(isValid(newx,newy,arr))
            {
                if(dp[newx][newy]>dp[x][y])
                {
                    dp[newx][newy]=dp[x][y];
                    q.push_front({newx,newy});
                }
            }
        }
        for(int a=x-2;a<=x+2;a++)
        {
            for(int b=y-2;b<=y+2;b++)
            {
                if(isValid(a,b,arr))
                {
                    if(dp[x][y]+1<dp[a][b])
                    {
                        dp[a][b]=dp[x][y]+1;
                        q.push_back({a,b});
                    }
                }
            }
        }
    }
    if(dp[dh][dw]==1e7)
        cout<<"-1\n";
    else
        cout<<dp[dh][dw]<<endl;
}


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

int main() {
  int n, L;

  cin >> n >> L;
  int taste[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    taste[i] = L + i;
    sum += taste[i];
  }
  int min_abs_index = 0;
  for (int i = 0; i < n; i++) {
    if (abs(taste[min_abs_index]) > abs(taste[i])) {
      min_abs_index = i;
    }
  }
  sum -= taste[min_abs_index];

  cout << sum << endl;
}


Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : April 22 2020 21:32:47 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    for(char c:s){
        if(c=='I') x++;
        else x--;
        ans = max(ans,x); 
    }
    cout << ans << endl;


    time_taken();
    return 0;
}

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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const vector<pair<T, U>> p) {
	os << "P(" << p.first << ", " << p.second << endl;
}

/*
template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << P << " ";
	return os << "}";
}
*/

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Insert from here! */
/* Cut from here! */
int solve(int N) {
	vector<int> k(N);
	bool able = false;
	rep(i, N) {
		cin >> k[i];
		able |= k[i] > 1;
	}
	if (!able) return -1;
	
	int res = 0;
	rep(i, N) {
		if (k[i] != 0) ++res;
	}
	return res + 1;
}

void Main() {
	int N; cin >> N;
	vector<int> ans;
	while (1) {
		if (N == 0) break;
 		ans.eb(solve(N));
		cin >> N;
	}
	rep(i, ans.size()) {
		if (ans[i] == -1) cout << "NA" << endl;
		else cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3268
import std.stdio;

int[10000][7] memo;
int[7] a, b;
int m, g, n;

void main(){
	while (readf("%d\n", &m), m) {
		foreach (i; 0..m) readf("%d %d\n", &a[i], &b[i]);
		readf("%d\n", &g);
		foreach (i; 0..g) {
			foreach (j; 0..m) memo[j][] = -1;
			readf("%d\n", &n);
			writeln(solve(0, 0));
		}
	}
}

int solve(int sum, int p){
	if (m == p) return (sum == n ? 1:0);
	if (memo[p][sum] != -1) return memo[p][sum];
	int res = 0;
	foreach (i; 0..b[p]+1) {
		res += solve(sum+a[p]*i, p+1);
	}
	return memo[p][sum] = res;
}

Measured memory_bytes: 1260
import java.util.*;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		int Max=0;
		int[] A=new int[N+2];

		A[0]=0;

		for(int i=1;i<=N;i++){
			A[i]=sc.nextInt();
			Max+=Math.abs(A[i]-A[i-1]);
		}
		A[N+1]=0;
		Max+=Math.abs(A[N+1]-A[N]);

		int ans=0;
		for(int i=1;i<=N;i++){
			ans=Max-(Math.abs(A[i]-A[i-1])+Math.abs(A[i+1]-A[i]))+Math.abs(A[i+1]-A[i-1]);
			//結果を出力
			System.out.println(ans);
		}
	}
} 

Measured memory_bytes: 63364
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = float('inf')

for _ in range(M):
  x, y, c = map(int, input().split())
  t = a[x - 1] + b[y - 1] - c
  ans = min(ans, t)
  
a.sort()
b.sort()

ans = min(ans, a[0] + b[0])

print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
    
        
        long long int n,m,o=0,l,d=1,i,j,p=0,k,f;
       double pie=3.141592653589793238;
    long long int MOD=1000000007;
    cin>>n;
    string s;
    vector<string>v;
    unordered_map<string,int>ma;
    for(i=0;i<n;i++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        ma.insert(make_pair(s,0));
        v.push_back(s);
    }
    auto it=v.begin();
    ma[v[0]]++;
    for(i=1;i<v.size();i++)
    {
        if(ma[v[i]]>0)
        {
            p=p+ma[v[i]];
         //   ma[v[i]]++;
            
        }
        ma[v[i]]++;
        
    }
    cout<<p;
    
    
 return 0;
}

Measured memory_bytes: 16024
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int A, B;
  cin >> A >> B;
  for (int i = 0; i < 40; i++) {
    if (i * A - i + 1 >= B) {
      cout << i << endl;
      break;
    }
  }
}

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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    ArrayList<Double> x, y;
	    x = new ArrayList<Double>();
	    y = new ArrayList<Double>();
	    while((st=sc.readLine())!=null){
		String[] sp = st.split(",");
		x.add(Double.valueOf(sp[0]));
		y.add(Double.valueOf(sp[1]));
	    }
	    double sum1 = x.get(x.size()-1)*y.get(0), sum2 = x.get(0)*y.get(y.size()-1);;
	    for(int i=0; i<x.size()-1; i++){
		sum1+=x.get(i)*y.get(i+1);
		sum2+=x.get(i+1)*y.get(i);
	    }
	    System.out.println(Math.abs(sum1-sum2)/2.0);
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9780
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = int(readline())
    B = int(readline())
    
    if A > B:
        A,B= B, A
    
    if A == 1:
        if B == 2:
            print('3')
        else:
            print('2')
    else:
        print('1')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61896
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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











int main(){
    ll k;
    string s;
    cin >> k >> s;
    if(s.size() <= k){
        cout << s << endl;
    }
    else{
        cout << s.substr(0, k) + "..." << endl;
    }
}


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




public class Main
{

	static String s1,s2;


	static int[][] dp;


	static int find(int i,int j)
	{
		if(i>=s1.length() || j>=s2.length()) return 0;

		if(dp[i][j]!=-1) return dp[i][j];

		if(s1.charAt(i)==s2.charAt(j)) return dp[i][j]=1+find(i+1,j+1);

		else return dp[i][j]=Math.max(find(i+1,j),find(i,j+1));
	}


	public static void main(String[] Rohan)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));





		// String[] s=br.readLine().split(" ");

		s1=br.readLine();
		s2=br.readLine();


		dp=new int[s1.length()][s2.length()];

		for(int i=0;i<s1.length();i++)
			for(int j=0;j<s2.length();j++) dp[i][j]=-1;

		find(0,0);

		int[][] dp2=new int[s1.length()+2][s2.length()+2];

		for(int i=1;i<=s1.length();i++)
		{
			for(int j=1;j<=s2.length();j++)
			{
				dp2[i][j]=dp[i-1][j-1];
			}
		}

		int i=1,j=1;

		while(i<=s1.length() && j<=s2.length())
		{
			if(s1.charAt(i-1)==s2.charAt(j-1))
			{
				System.out.print(s1.charAt(i-1));
				i++;j++;
			}
			else if(dp2[i+1][j]>dp2[i][j+1]) i++;
			else j++;

		}
		
		System.out.println();
		

	}
}


Measured memory_bytes: 129576
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

n = int(input())
p_list = list(map(int, input().split()))

q_list = np.minimum.accumulate(p_list)
ans = np.count_nonzero(q_list == p_list)

print(ans)

Measured memory_bytes: 48960
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/agc040/tasks/agc040_a

s = input()
a = [0] * (len(s) + 1)

for i in range(0, len(s)):
    if (s[i] == '<'):
        a[i+1] = a[i] + 1
for i in range(len(s)-1, -1, -1):
    if (s[i] == '>'):
        a[i] = max(a[i], a[i+1]+1)
#print(a)
print(sum(a))



Measured memory_bytes: 23340
import math
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

  divisors.sort()
  return divisors
  
n=int(input())
kirisute=math.floor(math.sqrt(n))
arr=make_divisors(n)

for i in arr:
  if kirisute<= i:
    j=n//i
    ans = i+j-2
    print(ans)
    break

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cnt(n, 0);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      cnt[a - 1]++;
    }
  }
  int ans = 0;
  rep(i, n) if (cnt[i] == 0) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  ans += (n/100+8)%16*100;
  n -= n/100*100;
  ans += (n/10+8)%16*10;
  n -= n/10*10;
  ans += (n+8)%16;
  cout << ans;
  return 0;
}

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

int main(){
    int H,W;
    string A="";
    
    cin >> H >> W;
    for(int i=0;i<H;i++){
        string s;
        cin >> s;
        A=A+s;
    }
    map<char,int> cnt;
    for(int i=0;i<A.size();i++) cnt[A[i]]++;

    if(W%2==0 && H%2==0){
        for(char k='a';k<='z';k++){
            if(cnt[k]%4!=0){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    if(W%2==0){
        int d=0;
        for(char k='a';k<='z';k++){
            if(cnt[k]%2!=0){
                cout << "No" << endl;
                return 0;
            }
            if(cnt[k]%4==2) d++;
        }
        if(W/2>=d && (W/2-d)%2==0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }else if(H%2==0){
        int d=0;
        for(char k='a';k<='z';k++){
            if(cnt[k]%2!=0){
                cout << "No" << endl;
                return 0;
            }
            if(cnt[k]%4==2) d++;
        }
        if(H/2>=d && (H/2-d)%2==0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }else{
        int u=0,d=0;
        for(char k='a';k<='z';k++){
            switch(cnt[k]%4){
                case 1:
                    u++;
                    break;
                case 2:
                    d++;
                    break;
                case 3:
                    u++;
                    d++;
                    break;
            }
        }
        if(u!=1) cout << "No" << endl;
        else if(W/2+H/2>=d && (W/2+H/2-d)%2==0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//ll _(){
//    ll n,T;
//    cin >> n >> T;
//    vl arr(n);
//    cin >> arr;
//    ll seen = 0;
//    ll ans = 0;
//    for(ll t : arr){
//        ans += min(t-seen+T,T);
//        seen = t+T;
//    }
//    return ans;
//}
//
//
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
ll _(){
    ll n,T;
    cin >> n >> T;
    vl arr(n);
    cin >> arr;
    ll seen = 0;
    ll ans = 0;
    for(ll t : arr){
        ans += min(t-seen+T,T);
        seen = t+T;
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
    
    
    int n;
    
    cin>>n;
    
    ll ans = 0;
    for(int i=1;i<=n;++i)
    for(int j=1;j<=n;++j)
    for(int k=1;k<=n;++k) ans+=gcd(gcd(i,j),k);
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define int int64

signed main(){
  string s;cin>>s;
  int ans=0,cnt=0;
  for(int i=0;i<s.size();++i){
    if(s[i]!='B') continue;
    ++cnt;
    ans+=i;
  }
  ans=((s.size()-1)+(s.size()-cnt))*cnt/2 - ans;
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    char s[15]={};
    char t[15]={};

    cin>>s>>t;
    
    int i;
    for(i=0;s[i]!='\0';i++){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(t[i]!='\0'&&t[i+1]=='\0'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    ll c=0;
    int A[N+10];rep(i,N+1)cin >> A[i];
    int B[N+10];rep(i,N)cin >> B[i];
    rep(i,N){
        if(B[i]<=A[i]){
            c+=B[i];
        }
        else if(B[i]<=A[i]+A[i+1]){
            c+=B[i];
            A[i+1]-=(B[i]-A[i]);
        }
        else{
            c+=(A[i]+A[i+1]);
            A[i+1]=0;
        }
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 1024
/*
* All my senses intensify
* Whenever you and I, we dive
*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define inf ((ll)1e18)
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
int main()
{
    // fast();
    set<ll> foo;
    ll n;
    cin>>n;
    for(ll i = 0 ; i < n ; i++)
    {
    	ll x;
    	cin>>x;
    	foo.insert(x);
    }
    if(foo.size() < n)
    	cout<<"NO\n";
    else
    	cout<<"YES\n";
}


Measured memory_bytes: 9600