akhauriyash/Code-Regression huggingface dataset:
def main():
    P = 2019
    S = [int(s) for s in input()]
    ans = 0
    if P == 2:
        for i, v in enumerate(S, start=1):
            if v % 2 == 0:
                ans += i
    elif P == 5:
        for i, v in enumerate(S, start=1):
            if v == 0 or v == 5:
                ans += i
    else:
        cnt = [0]*P
        d = 1
        pre = 0
        cnt[pre] += 1
        for v in S[::-1]:
            v *= d
            v += pre
            v %= P
            cnt[v] += 1
            d *= 10
            d %= P
            pre = v

        ans = sum(cnt[i]*(cnt[i]-1)//2 for i in range(P))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 86628
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n/100==n%10)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 768
import sys
N, M = map(int, input().split())
ansl = 1
ansr = N
for _ in range(M):
    l, r = map(int, sys.stdin.readline().split())
    ansl = max(ansl, l)
    ansr = min(ansr, r)
ans = max(0, ansr - ansl + 1)
print(ans)

Measured memory_bytes: 8980
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
    unsigned short *A, *B;

    int C[VMAX+1];
    int n,i,j;
    scanf("%d", &n);

    A = malloc(sizeof(short)*n+1);
    B = malloc(sizeof(short)*n+1);

    for(i=0;i<=VMAX;i++) C[i] = 0;

    for(i=0;i<n;i++){
        scanf("%hu", &A[i+1]);
        C[A[i+1]]++;
    }

    for(i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];

    for(j=1;j<=n;j++){
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

    for(i=1;i<=n;i++){
        if(i>1) printf(" ");
        printf("%d",B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 9624
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
#include<utility>
using namespace std;
using ll = long long;

bool f[3][3];

int main(){
  int a[3][3];
  for(int y=0;y<3;y++){
    for(int x=0;x<3;x++){
      cin >> a[y][x];
      f[y][x] = false;
    }
  }
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    for(int y=0;y<3;y++){
      for(int x=0;x<3;x++){
        if(b == a[y][x]) f[y][x] = true;
      }
    }
  }
  if( (f[0][0]&&f[0][1]&&f[0][2])||(f[1][0]&&f[1][1]&&f[1][2])||(f[2][0]&&f[2][1]&&f[2][2])){
    cout << "Yes";
  }
  else if( (f[0][0]&&f[1][0]&&f[2][0])||(f[0][1]&&f[1][1]&&f[2][1])||(f[0][2]&&f[1][2]&&f[2][2])){
    cout << "Yes";
  }
  else if( (f[0][0]&&f[1][1]&&f[2][2])||(f[0][2]&&f[1][1]&&f[2][0]) ){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

struct City {
  long no, p, y, id;
};

int main() {
  int n, m;
  cin >> n >> m;
  auto cities = vector<City>(m);
  for (int i=0; i<m; ++i) {
    cities[i].no = i;
    cin >> cities[i].p >> cities[i].y;
  }
  sort(begin(cities), end(cities), [](City& c1, City& c2) {
      return c1.y <= c2.y;
  });
  auto counts = vector<long>(n+1, 0);
  for (auto& city : cities) {
    long count = ++counts[city.p];
    city.id = 1000000 * city.p + count;
  }
  sort(begin(cities), end(cities), [](City& c1, City& c2) {
    return c1.no <= c2.no;    
  });
  for (auto&& city : cities) {
    printf("%012ld\n", city.id);
  }

  return 0;
}


Measured memory_bytes: 5376
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500 + b*100 + c*50==X:
                ans+=1
print(ans)

Measured memory_bytes: 9192
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define nl cout<<endl
#define P 1000000007
#define MOD(x) ((x%P)+P)%P
#define NMAX 100100

#define INF 1000000000
int mod=1e9;

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

    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];

    int dp[n]={0};
    dp[1]= abs(h[1]-h[0]);

    for(int i =2;i<n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n-1];

	return 0;
    	
}

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

using namespace std;

int main(){
	cin.tie(0);
  	ios::sync_with_stdio(false);
  	int x, y;
  	int large;
  	cin >> x >> y;
  	
  	large = x > y?x:y;
  	
  	if(large <= 8)
  		cout << "Yay!" << endl;
  	else
      	cout << ":(" << endl;
	return 0;
}

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

unsigned GetDigit(unsigned num)
{
    return log10(num) + 1;
}
int main(){
    ll N;
    cin >> N;
    ll digit = GetDigit(N);
    int digitsum = 0;
    string S = to_string(N);
    while(digit >= 0){
        digit--;
        char c = S[digit];
        if(c > 9){
            digitsum += c - 48;
        }
        else{
            digitsum += c;
        }
    }
    if(N%digitsum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    i64 ans = 0;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int h,w,H,W;
    for(;;){
        scanf("%d %d",&H,&W);
    if(H==0 && W==0)break;
    for(h=0; h<H; h++){
        for(w=0; w<W; w++){
            printf("#");
        }
        printf("\n");
        
    }
    printf("\n");
    }
    return 0;   
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
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; }

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int sum_total = 0;
    for(int i=0; i <= n; i++){
        int q = i, total = 0;
        while(q != 0){
            total += (q % 10);
            q /= 10;
        }
        if (a <= total && total <= b){
            sum_total += i;
        }
    }
    cout << sum_total << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long d,i,reslt;
    while(scanf("%ld",&d)==1)
    {
        reslt=0;
        for(i=1;i<600;i++)
        {

            reslt+=(i*d*d*d*i);
            reslt%=72000000;
            if(i*d==(600-d))
                break;
        }
        printf("%ld\n",reslt);
    }
    return 0;
}

Measured memory_bytes: 596
var input=require("fs").readFileSync("/dev/stdin","utf8");
input=input.split("\n");

var str,oup;
var H,W,h,w;
var i=0;

while(1){
    str=input[i].split(" ");
    H=str[0];
    W=str[1];
    if(H==0&&W==0){
        break;
    }
    
    for(h=0;h<H;h++){
        oup="";
        for(w=0;w<W;w++){
            oup+="#";
        }
        console.log(oup);
    }
    console.log();
    i++;
}


Measured memory_bytes: 18700
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int,input().split())))
flag = False
for cx in range(101):
    if flag:
        break
    for cy in range(101):
        h1 = set()
        zero = []
        for x,y,h in xyh:
            if h != 0:
                h1.add(h + abs(cx-x)+abs(cy-y))
            else:
                zero.append([x,y])

        if len(h1) == 1:
            ah = list(h1)[0]
            f = True
            for zx,zy in zero:
                if ah - abs(cx-zx) - abs(cy-zy) > 0:
                    f = False
            if f:
                ax = cx
                ay = cy
                flag = True
                break
print(ax,ay,ah)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
char a[100],b[100],p=0;
int main()
{
	scanf("%s",&a);scanf("%s",&b);
	for(int i=2;i>=0;--i)
	{
		if(b[i]!=a[2-i])
		p=1;
	}
	if(p==0)
	printf("YES");
	else
	printf("NO");
	return 0;
}

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

using namespace std;

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

  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  string message = "APPROVED";
  for (int ai : a)
  {
    if (ai % 2 == 0)
    {
      if (ai % 3 == 0) continue;
      if (ai % 5 == 0) continue;
      message = "DENIED";
      break;
    }
  }

  cout << message << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

long long N, K;

long long count(long long n)
{
	long long ans = 0;
	long long p = 9;
	long long l = 1;
	
	for(long long k = n; k >= 10; k /= 10, p *= 10, l++) ans += l * p;
	
	ans += l * (n - p/9 + 1);
	return ans;
}

string make(long long v)
{
	string ret;
	char tmp[50];
	for(long long i = 0; i < 100; i++){
		sprintf(tmp, "%d", v+i);
		ret += tmp;
	}
	return ret;
}

int main(void)
{
	while(1){
		cin >> N >> K;
		if(N == 0 && K == 0) break;
		
		long long lb = -1, ub = 1000000001, mid;
		while(ub - lb > 1){
			mid = (lb + ub) / 2;
			if(count(mid) < N) lb = mid;
			else ub = mid;
		}
		long long offset = N - count(lb);
		
		string s = make(ub);
		cout << s.substr(offset-1, K) << endl;
	}
	return 0;
}

Measured memory_bytes: 3252
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;

long long solve_1 (int N, int P, string S) {
  long long cnt = 0;

  for (int i = N - 1; i >= 0; i--) {
    if ((S[i] - '0') % P == 0) cnt += i + 1;
  }

  return cnt;
}

long long solve_2 (int N, int P, string S) {
  auto MOD = [&](int a) {
    int res = a % P;
    if (res < 0) res += P;
    return res;
  };

  long long cnt = 0;
  map<int, int> dp;
  dp[0] = 1;
  int x = 0;
  int ten = 1;
  for (int i = N - 1; i >= 0; i--) {
    x = MOD(x + MOD(S[i] - '0') * ten);
    cnt += dp[x];
    dp[x]++;
    (ten *= 10) %= P;
  }

  return cnt;
}

/**
 * main
 */
int main () {
  int N, P; cin >> N >> P;
  string S; cin >> S;

  cout << ((P == 2 || P == 5) ? solve_1(N, P, S) : solve_2(N, P, S))
       << '\n';
}


Measured memory_bytes: 1028
from collections import Counter

S = input()
N = len(S)

M = []
cum = [0]

ans = 0

for i in range(N):
    M.append(pow(10, i, 2019) * int(S[-1 - i]) % 2019)

for i in range(N):
    cum.append((cum[-1] + M[i]) % 2019)

C = Counter(cum)

for v in C.values():
    ans += v * (v - 1) // 2

print(ans)

Measured memory_bytes: 87176
n = int(input())
v = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [0]*3 for _ in range(n) ]
for i in range(n):
  for j in range(3):
    if i == 0:
      dp[i][j] = v[i][j]
    else:
      for k in range(3):
        if j != k:
          dp[i][j] = max(dp[i][j], dp[i-1][k]+v[i][j])
print(max(dp[n-1]))


Measured memory_bytes: 47348
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int pos = -1;
    for( int i = 0; i < s.size(); ++i ) {
        if( s[i] == 'C' ) pos = i;

    }
    int fpos = -1;
    if( pos == -1 ) cout << "No";
    else {
        for( int i = pos; i < s.size(); ++i ) {
            if( s[i] == 'F' ) fpos = i;
        }
        if( fpos != -1 ) cout << "Yes";
        else cout << "No";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define ll long long int 
	#define pii pair<int,int> 
	#define pb push_back
	#define INF INT_MAX 
	#define mod 1000000007ll
	#define fi first
	#define se second
	#define f(i,p,q) for(int i=p;i<q;i++)
	#define si(a) scanf("%d",&a)
	#define sii(a,b) scanf("%d %d",&a,&b)
	#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
	#define pi(a) printf("%d\n",a)
	#define psi(a) printf(" %d",a)
	#define poi(a) printf("%d",a)
	#define sl(a) scanf("%lld",&a)
	#define pl(a) printf("%lld\n",a)
	#define Nline() printf("\n")
	#define sstr(str) scanf("%s",str)
	#define pstr(str) printf("%s\n",str)
	#define SET(a) memset(a,-1,sizeof(a))
	#define CLR(a) memset(a,0,sizeof(a))
	#define vi vector<int>
	#define vvi vector<vi>
	#define all(v) (v).begin(),(v).end()
	#define SORT(v) sort(all(v))
	#define RSORT(v) sort(all(v), greater<int>())
	#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
	#define MAX(a, b) ((a) > (b) ? (a) : (b))
	#define MIN(a, b) ((a) < (b) ? (a) : (b))
	#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
	#define S(X) ( (X) * (X) )
	#define SZ(V) (int )V.size()
	#define FORN(i, n) for(i = 0; i < n; i++)
	#define FORAB(i, a, b) for(i = a; i <= b; i++)
	#define ALL(V) V.begin(), V.end()
	#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
	#define AIN(A, B, C) assert(IN(A, B, C))
	
	void solve(){
	     ll n;cin>>n;
	    ll ar[n];
	    f(i,0,n)cin>>ar[i];
	    sort(ar,ar+n);
	    reverse(ar,ar+n);
	    int j=1;
	    ll ans=ar[0];
	    int c=0;
	    for(int i=1;i<n-1;i++){
	    	ans+=ar[j];
	    	c++;
	    	if(c==2){
	    		j++;
	    		c=0;
	    	}
	    	//cout<<ans<<" "<<i<<" ";
	    }
	    cout<<ans;
	    
	}
	int main() {
	    ios;
		int t=1;
		//cin>>t;
		while(t--)solve();
	 
	    
	}
	

Measured memory_bytes: 5204
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
int N,K;
struct xy{
	int x;
	int y;
	int c;
};
double distance(double x,double y, xy k){
	return sqrt(pow(x-k.x,2)+pow(y-k.y,2));
}
bool niku_judge(double t,vector<xy> &niku){
	for (int i = 0; i < N; i++){
		for (int j = i; j < N; j++){
			if(i==j){
				int count=0;
				for (int k = 0; k < N; k++){
					if(distance(niku[i].x,niku[i].y,niku[k])<=t/niku[k].c)count++;
				}
				if(count>=K)return true;
			}else{
				double a=niku[j].x-niku[i].x;
				double b=niku[j].y-niku[i].y;
				bool b_zero=false;
				if(b==0){
					b=a;a=0;
					b_zero=true;
				}
				double c=-a/b;
				double d=(a*a+b*b+pow(t/niku[i].c,2)-pow(t/niku[j].c,2))/(2*b);
				double e=1+c*c;
				double f=2*c*d;
				double g=d*d-pow(t/niku[i].c,2);
				double x1;
				if(f*f-4*e*g<0)continue;
				if(f>0)x1=(-f-sqrt(f*f-4*e*g))/(2*e);
				else x1=(-f+sqrt(f*f-4*e*g))/(2*e);
				double x2=-x1-f/e;
				double y1=c*x1+d;
				double y2=c*x2+d;
				if(b_zero){
					swap(x1,y1);swap(x2,y2);
				}
				x1+=niku[i].x;x2+=niku[i].x;
				y1+=niku[i].y;y2+=niku[i].y;
				int count=0;
				for (int k = 0; k < N; k++){
					if(k==i||k==j)continue;
					if(distance(x1,y1,niku[k])<=t/niku[k].c)count++;
				}
				if(count>=K-2)return true;
				count=0;
				for (int k = 0; k < N; k++){
					if(k==i||k==j)continue;
					if(distance(x2,y2,niku[k])<=t/niku[k].c)count++;
				}
				if(count>=K-2)return true;
			}
		}
	}
	return false;
}
double bi_search(double l, double r, vector<xy> &niku){
	double m=(l+r)/2.0;
	if(niku_judge(m,niku)==false)return bi_search(m,r,niku);
	else if(niku_judge(m-eps,niku)==true)return bi_search(l,m,niku);
	else return m;
}
int main() {
	cin>>N>>K;
	vector<xy> niku(N);
	int x_max=0;int y_max=0;int c_max=0;
	for (int i = 0; i < N; i++){
		cin>>niku[i].x>>niku[i].y>>niku[i].c;
		x_max=max(x_max,abs(niku[i].x));
		y_max=max(y_max,abs(niku[i].y));
		c_max=max(c_max,abs(niku[i].c));
	}
	double t_max=(x_max+y_max)*c_max;
	printf("%.6f\n",bi_search(0,t_max,niku));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string n;
  cin >> n;
  int L = n.size();
  int ans = 0;
  int before = 0;
  for(int i= L-1;i>=0;i--){
    int nd = n.at(i) - '0' + before ;
    //cout << nd << endl;
    if( nd == 5 && i > 0){
      if( n.at(i-1) - '0' >= 5){
        ans += 10 - nd;
        before = 1;
      }else{
        ans += nd;
        before = 0;
      }
    }
    else if(nd <= 5){
      ans += nd;
      before = 0;
    }else{
      ans += 10-nd;
      before = 1;
    }
    //cout << ans << endl;
  }
  ans += before;
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 1412
#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;
  rep(q, n) {
    string X,Y; cin>>X>>Y;
    int x=X.size();
    int y=Y.size();
    vector<vector<int>> dp(x+1,vector<int>(y+1, 0));
    rep(i, x) {
      rep(j, y) {
        dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
        if (X[i]==Y[j]) dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1);
      }
    }
    cout<<dp[x][y]<<endl;
  }
}



Measured memory_bytes: 6908
//use proconio::{input, fastout};
use proconio::input;
use std::collections::HashMap;

//#[fastout]
fn main() {
    input! {
        n: usize, k: u64,
        a: [usize; n],
    }

    let mut h = HashMap::new();
    let mut count = 0;
    let mut p = 1;
    while count < k {
        h.insert(p, count);
        count += 1;

        let next = a[p - 1];
        if let Some(s) = h.get(&next) {
            let loops = count - s;
            let k = (k - s) % loops + s;
            let (p, _) = h.iter().find(|(_, v)| **v == k).unwrap();
            println!("{}", p);
            return;
        }

        p = next;
    }
    println!("{}", p);
}


Measured memory_bytes: 11424
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y,z;
	cin >> x;
      cout << x/100+(x/10)%10+x%10 << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
count = [0]*(N+1)
for i in range(M):
    a, b = map(int, input().split())
    count[a] += 1
    count[b] += 1
for i in range(N):
    if count[i] % 2 != 0:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 3828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        List<int> answers = new List<int>() { 1, 2, 3 };

        answers.Remove(cin.nextInt());
        answers.Remove(cin.nextInt());

        WriteLine(answers[0]);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};



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

    int x,y;
    cin >> x >> y;
    rep(i,x+1){
        rep(j,x+1){
            if(i+j == x) {
                int w = 0;
                w += i * 2;
                w += j * 4;
                if(w == y) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

const int INF = 1e18L + 5;

void minSelf(ll &a, ll b)
{
	a = min(a, b);
}

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

	vector<int> weight(n), value(n);
	for (int i = 0; i < n; i++)
	{	
		cin >> weight[i] >> value[i];
	}

	int sumValue = 0;
	for (int x : value)
	{
		sumValue += x;
	}

	vector<ll> dp(sumValue + 1, INF);
	dp[0] = 0;

	for (int item = 0; item < n; item++)
	{
		for (int valueAlready = sumValue - value[item]; valueAlready >= 
		0; valueAlready--)
		{
			minSelf(dp[valueAlready + value[item]], dp[valueAlready] + 
			weight[item]);
		}
	}

	ll answer = 0; 
	for (int i = 0; i <= sumValue; i++)
	{
		if (dp[i] <= W)
		{
			answer = max(answer, (ll)i);
		}
	}

	cout << answer << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int n, l;
  cin >> n >> l;

  if (l >= 0) {
    cout << (l + 2 - 1 + l + n - 1) * (n - 1) / 2 << endl;
  } else {
    cout << (l + 1 - 1 + l + n - 1) * n / 2 - (l + min(n, 1 - l) - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
long long n, cnt=0;
void dfs(int a, int b, int c, long long cur){
	if(cur > n) return;
	if(a && b && c) cnt++ ;
	
	dfs(a+1, b, c, cur*10+3);
	dfs(a, b+1, c, cur*10+5);
	dfs(a, b, c+1, cur*10+7);	
}
 
 
int main() {
	cin>>n;
	dfs(0,0,0,0);
	cout<<cnt;
	return 0;
}

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

for i in range(n-2, 0 , -1):
  if h[i] > h[i+1]:
    h[i] -= 1
    if h[i] > h[i+1]:
      print('No')
      break
else:
   print('Yes') 

Measured memory_bytes: 15020
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[100005],x,ans,dis[100005];
int gcd(int a,int b)
{
	return a==b?a:gcd(max(a-b,b),min(a-b,b));
}
int main()
{
	register int i;
	scanf("%d%d",&n,&x);
	for (i=1;i<=n;++i)
		scanf("%d",&a[i]);
	a[n+1]=x;n=n+1;
	sort(a+1,a+1+n);
	for (i=2;i<=n;++i)
	{
		dis[i-1]=a[i]-a[i-1];
		if (i>2)
			ans=gcd(max(ans,dis[i-1]),min(ans,dis[i-1]));
		else
			ans=dis[i-1];
	}
	return !printf("%d",ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int n,m,X,Y;
	cin >> n >> m >> X >> Y;
	std::vector<int> x, y;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		x.push_back(a);
	}
	for (int i = 0; i < m; ++i) {
		int a;
		cin >> a;
		y.push_back(a);
	}
	{
		int maxx = *max_element(x.begin(), x.end()) + 1;
		int miny = *min_element(y.begin(), y.end());
		if (maxx > miny) {
			cout << "War" << endl;
			return 0;
		}
		for (int i = maxx; maxx <= miny; ++maxx) {
			if (X < maxx&&maxx <= Y) {
				cout << "No War" << endl;
				return 0;
			}
		}
		cout << "War" << endl;
	}
	return 0;
}

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

using ll = long long;

#define MOD (1000000007)

#define MAX (1000000)

// 階乗のテーブル
ll fac[MAX];
// 逆元の階乗のテーブル
ll inv[MAX];

ll mpow(ll i, ll j)
{
    if (j == 0) return 1;
    ll res = mpow(i, j / 2) % MOD;
    res = (res * res) % MOD;
    return (j & 1) ? (res * i) % MOD : res;
}

void ComInit()
{
    fac[0] = fac[1] = 1;
    inv[0] = inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = (inv[i - 1] * mpow(i, MOD - 2)) % MOD;
    }
}

int main()
{
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int m = ((2 * x) - (1 * y)) / 3;
    int n = ((2 * y) - (1 * x)) / 3;

    if (m < 0 || n < 0) {
        cout << 0 << endl;
        return 0;
    }

    ComInit();

    ll result = (((fac[m + n] * inv[n]) % MOD) * (inv[m])) % MOD;
    cout << result << endl;

    return 0;
}


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

int main(){
    string num;
    cin>>num;
    bool flag = false;
    for(int i=1;i<num.length();i++){
        if(num[i]==num[i-1]){
            flag = true;
            break;
        }
    }
    if(flag){
        cout<<"Bad\n";
    }
    else{
        cout<<"Good\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int k;
    cin >> s >> k;
    set<string> st;
    int len = s.length(); // ここで置かないと、len - i < 0の時うまくいかない
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j <= len - i; j++) {
            st.insert(s.substr(j, i));
        }
    }
    auto itr = st.begin();
    for (int i = 1; i < k; i++) itr++;
    cout << *itr << endl;
}


Measured memory_bytes: 1664
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
c,d=[],[]
for s,t in zip(a,b):
    if s<t:
        c.append(t-s)
    elif s>t:
        d.append(s-t)
c.sort()
d.sort(reverse=1)
i=0
j=0
f=0
while i<len(c) and j<len(d):
    if c[i]<=d[j]:
        d[j]-=c[i]
        i+=1
        f=1
    elif c[i]>d[j]:
        c[i]-=d[j]
        j+=1
if i<len(c):
    print(-1)
else:
    print(i+j+f)

Measured memory_bytes: 18356
N, T = map(int, input().split())
ct = list([tuple(map(int, input().split())) for i in range(N)])

ans = 9999
for c,t in ct:
    if t <= T:
        ans = min(ans, c)
    
if ans == 9999:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 998244353
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(n) for(int i=0; i<n; i++)
void solve()
{
	int n;
	cin>>n;
	map<string,int> m;
	string a;
	for(int i=0;i<n;i++)
	{
	     cin>>a;
	     if(m.find(a)==m.end())m[a]=1;
	     else m[a]++;
	}
	int l=m.size();
	cout<<l<<"\n";
	return;
}




int32_t main() 
{ 
	fast;
	int t=1;//cin>>t;
	while(t--){solve();}
	return 0; 
}

Measured memory_bytes: 19132
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, K;
ll P[5010], C[5010];
bool used[5010];

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

  rep( i, N )
    std::cin >> P[i], --P[i];
  rep( i, N )
    std::cin >> C[i];

  ll ans = -INF;

  rep( i, N ) {
    ll cur = i;
    ll cnt = 0;
    ll sum = 0;
    std::vector<ll> vs = { 0 };

    rep( j, N )
      used[j] = false;

    ll ma = -INF;

    while( !used[cur] ) {
      used[cur] = true;

      cur = P[cur];
      ++cnt;

      if( cnt <= K ) {
        sum += C[cur];
        chmax( ma, sum );
        chmax( ans, ma );
        vs.emplace_back( ma );
      }
    }

    //std::cout << "[]: " << i << endl;
    //std::cout << vs << endl;
    //std::cout << cnt << endl;

    if( K > cnt && sum > 0 ) {
      chmax( ans, sum*(K/cnt)+vs[K%cnt] );
      chmax( ans, sum*(K/cnt-1)+vs.back() );
    }
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    double a,b;
    cin >> a >> b;
    double sum = (a+b)/2;
    int ans = (a+b)/2;
    if(sum-ans!=0){
        ans+=1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define res register ll
#define ll long long
#define mod 1000000007
using namespace std;
map<ll,ll> f;
ll n;
inline ll read() {
	res w=0,X=0;
	register char ch=0;
	while(!isdigit(ch)) {
		w|=ch=='-';
		ch=getchar();
	}
	while(isdigit(ch)) {
		X=(X<<1)+(X<<3)+(ch^48);
		ch=getchar();
	}
	return w?-X:X;
}
inline int dfs(res x){
	if(f[x]) return f[x];
	f[x]=((dfs(x>>1)+dfs((x-1)>>1))%mod+dfs((x-2)>>1))%mod;
	return f[x];
}
int main() {
	f[0]=1;
	f[1]=2;
	n=read();
	printf("%lld\n",dfs(n));
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
a = inpl()
b = [0] * m
for i in range(m):
    x,y = inpl()
    b[i] = [x,y]
a.sort()
b.sort(key=lambda x:x[1], reverse = True)
res = sum(a)
i = 0
j = 0
while True:
    # print(i,j)
    if a[i] < b[j][1]:
        res += b[j][1] - a[i]
        i += 1
    else:
        break
    b[j][0] -= 1
    if b[j][0] == 0:
        j += 1
    if i >= n or j >= m:
        break
print(res)


Measured memory_bytes: 71452
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	ll x,k,d;
	cin>>x>>k>>d;
	ll ans=0;
	if(x==0){
		if(k%2==0){
			cout<<0<<ln;
		}
		else{
			cout<<d<<ln;
		}
	}
	else if(x>0){
		if(x/d>=k){
			ans=x-d*k;
			cout<<ans<<ln;
		}
		else{
			if(((x/d)%2==0 && k%2==0) || ((x/d)%2!=0 && k%2!=0)){
				cout<<(x-(x/d)*d)<<ln;
			}
			else{
				cout<<abs(x-(x/d)*d-d)<<ln;
			}
		}
	}
	else{
		if(-1*(x/d)>=k){
			ans=-1*(x+d*k);
			cout<<ans<<ln;
		}
		else{
			if(((x/d)%2==0 && k%2==0) || ((x/d)%2!=0 && k%2!=0)){
				cout<<-1*(x-(x/d)*d)<<ln;
			}
			else{
				cout<<abs(x-(x/d)*d+d)<<ln;
			}
		}
	}
}	

int main(){
	boost_io;
	solve();
	return 0;
}


Measured memory_bytes: 3636
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c,d,e,f=parseMap(split(readline()))
    a_water=0
    a_suger=0
    a_nodo=0
    a*=100
    b*=100
    for i in 0:a:f,j in 0:b:f
        water=i+j
        if water==0 || water>f
            continue
        end
        for k in 0:c:f,l in 0:d:f
            suger=k+l
            if water+suger>f
                continue
            end
            if water/100*e>=suger
                nodo=100*suger/(water+suger)
                if nodo>=a_nodo
                    a_suger=suger
                    a_water=water
                    a_nodo=nodo
                end
            end
        end
    end
    println("$(a_suger+a_water) $a_suger")
end
main()

Measured memory_bytes: 119460
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  bool f = true;
  if (c - b - a <= 0) f = false;
  if (4 * a * b >= (c - b - a) * (c - b - a)) f = false;
  cout << (f ? "Yes" : "No") << endl;


  
  return 0;
}

Measured memory_bytes: 256
main = do
  getLine
  as<-map read.words<$>getLine
  print $ solve as

solve :: [Int]->Int
solve as = maximum $ zipWith gcd' (scanl gcd' 0 as) (tail (scanr gcd' 0 as))
  where
  gcd' 0 a = a
  gcd' a 0 = a
  gcd' a b = gcd a b

Measured memory_bytes: 63612
#include <stdio.h>
int main() {
  int N, i;
  scanf("%d", &N);
  int A[N];
  int B[N];
  for(i = 0; i < N; ++i){
    scanf("%d", &A[i]);
    B[i] = A[i];
  }
  merge_sort(B, 0, N - 1, N);
  for(i = 0; i < N; ++i){
    if(A[i] != B[N - 1]){
      printf("%d\n", B[N - 1]);
    } else {
      printf("%d\n", B[N - 2]);
    }
  }
  return 0;
}

void merge_sort (int array[], int left, int right, int N) {
  int i, j, k, mid;
  int work[N];  // 作業用配列
  if (left < right) {
    mid = (left + right)/2; // 真ん中
    merge_sort(array, left, mid, N);  // 左を整列
    merge_sort(array, mid+1, right, N);  // 右を整列
    for (i = mid; i >= left; i--) { work[i] = array[i]; } // 左半分
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j]; // 右半分を逆順
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}

Measured memory_bytes: 17152
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f

//std::ios::sync_with_stdio(0); std::cin.tie(0);
int main() {
	int x, y;
	cin >> x >> y;
	if (2 * x <= y && y <= 4 * x&&y%2==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll base = n / (a + b) * a;
  ll add = min(n % (a + b), a);
  cout << base + add << endl;
  
  
  return 0;
}

Measured memory_bytes: 3652
def nibutan(th, a):
    top = len(th)
    btm = 0

    while top > btm:
        mid = (top + btm)//2
        if th[mid] < a <= th[mid + 1]:
            return mid
        elif a <= th[mid]:
            top = mid
        else:
            btm = mid

N = int(input())
A = [int(i) for i in input().split()]

th = [0]
num_th = []
rem = []
max_i = 0
nonzeros = dict()

for i, a in enumerate(A):
    if a > th[-1]:
        th.append(a)
        num_th.append(1)
        rem.append(0)
        nonzeros[i] = max_i
        max_i += 1
    else:
        j = nibutan(th, a)
        if j - 1 >= 0:
            num_th[j - 1] += 1
        rem[j] += a - th[j]

for i in range(len(num_th) - 1, 0, -1):
    num_th[i - 1] += num_th[i]

for i in range(N):
    if i in nonzeros:
        ans = (th[nonzeros[i] + 1] - th[nonzeros[i]])*num_th[nonzeros[i]]
        ans += rem[nonzeros[i]]
        print(ans)
    else:
        print(0)

Measured memory_bytes: 26848
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

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

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll a[100010];
ll d[100010];

void solv() {
	
	int n;
	cin >> n;
	int t[110];
	for (size_t i = 0; i < n; i++)
	{
		cin >> t[i];
		if (i > 0) t[i] += t[i - 1];
	}

	int r = INF;
	for (size_t i = 0; i < n; i++)
	{
		r = min(r, abs(t[i] - (t[n - 1] - t[i])));
	}
	cout << r << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[100010];

int main(){
  int n,k; cin >> n >> k;
  rep(i,n) dp[i]=inf;
  dp[0]=0;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  rep(i,n){
    for(int j=1;j<=k;j++){
      if(i+j<n) chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums=new int[55];
        int primes=0;
        boolean tmp;
        int num=-7;
        flag:while(primes<55){
            num+=10;
            for(int i=2;i<Math.sqrt(num);i++){
                if(num%i==0)continue flag;
            }
            nums[primes]=num;
            primes++;
        }
        int n=sc.nextInt();
        for(int i=0;i<n;i++)System.out.print(nums[i]+" ");

    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    cout << (N * (2 + (N - 1))) / 2 - N << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			double q = scan.nextDouble();
			if(q == -1){
				break;
			}
			double x = q / 2.0;
			double y = 0;
			while(true){
				y = x*x*x - q;
				if(y < 0.00001*q && y > -0.00001*q){
					break;
				}
				x = x - y / (3 * x * x);
			}
			System.out.printf("%.6f\n",x);
		}
	}
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<string> S(H);
    rep(i, H) cin >> S[i];

    queue<P> q;
    q.emplace(0, 0);

    vector<vector<bool>> used(H, vector<bool>(W));
    used[0][0] = true;
    bool flg = false;
    while (!q.empty()) {
        P p = q.front(); q.pop();
        int y = p.first, x = p.second;
        if (y == H-1 && x == W-1) {
            flg = true;
            break;
        }
        if (y+1 < H && !used[y+1][x] && S[y+1][x] == S[0][0]) {
            q.emplace(y+1, x);
            used[y+1][x] = true;
        }
        if (x+1 < W && !used[y][x+1] && S[y][x+1] == S[0][0]) {
            q.emplace(y, x+1);
            used[y][x+1] = true;
        }
    }

    if (flg) {
        int ans = 0;
        if (S[0][0] == '#') ans = 1;
        cout << ans << endl;
        return 0;
    }

    vector<vector<int>> ans(H, vector<int>(W, INF));
    queue<P> q1, q2;
    if (S[0][0] == '.') {
        ans[0][0] = 0;
        q1.emplace(0, 0);
    } else {
        ans[0][0] = 1;
        q2.emplace(0, 0);
    }

    while (1) {
        while (!q1.empty()) {
            P p = q1.front(); q1.pop();
            int y = p.first, x = p.second;
            if (y == H-1 && x == W-1) {
                cout << ans[y][x] << endl;
                return 0;
            }
            if (y+1 < H && ans[y+1][x] == INF) {
                if (S[y+1][x] == '.') {
                    ans[y+1][x] = ans[y][x];
                    q1.emplace(y+1, x);
                } else {
                    ans[y+1][x] = ans[y][x] + 1;
                    q2.emplace(y+1, x);
                }
            }
            if (x+1 < W && ans[y][x+1] == INF) {
                if (S[y][x+1] == '.') {
                    ans[y][x+1] = ans[y][x];
                    q1.emplace(y, x+1);
                } else {
                    ans[y][x+1] = ans[y][x] + 1;
                    q2.emplace(y, x+1);
                }
            }
        }

        while (!q2.empty()) {
            P p = q2.front(); q2.pop();
            int y = p.first, x = p.second;
            if (y == H-1 && x == W-1) {
                cout << ans[y][x] << endl;
                return 0;
            }
            if (y+1 < H && ans[y+1][x] == INF) {
                if (S[y+1][x] == '.') {
                    ans[y+1][x] = ans[y][x];
                    q1.emplace(y+1, x);
                } else {
                    ans[y+1][x] = ans[y][x];
                    q2.emplace(y+1, x);
                }
            }
            if (x+1 < W && ans[y][x+1] == INF) {
                if (S[y][x+1] == '.') {
                    ans[y][x+1] = ans[y][x];
                    q1.emplace(y, x+1);
                } else {
                    ans[y][x+1] = ans[y][x];
                    q2.emplace(y, x+1);
                }
            }
        }
    }
}

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

int main() {
  int N;
  int M;
    cin >> N >> M;
  int count=0;
  int ans;
  int  aa;
 for(int i=0;i<M;i++){
  cin >> aa;
   count = count+aa;
 }
  ans= N -count;
  if(ans < 0){
    
    cout << -1 << endl;
  }
  else{
    
    cout << ans << endl;
  }
  return 0;
 
}
    


Measured memory_bytes: 3592
n = int(input())
AB = [ 0 for _ in range(4)]
for i in range(n):
    s = str(input())
    m = len(s)
    for j in range(m-1):
        if s[j]=="A" and s[j+1]=="B":
            AB[3] +=1
    if s[0]=="B" and s[-1]=="A":
        AB[0] +=1
    elif s[0]=="B" and s[-1]!= "A":
        AB[1] += 1
    elif s[0]!="B" and s[-1]=="A":
        AB[2] +=1
    else:
        continue
ans = 0
if AB[0]==0:
    ans = min(AB[1], AB[2]) + AB[-1]
elif  AB[1]+AB[2]>0:
    ans = AB[0] + min(AB[1], AB[2]) + AB[-1]
elif AB[1]==0 and AB[2]==0:
    ans = AB[0]-1 +AB[-1]
print(ans) 

Measured memory_bytes: 3064
#include <iostream>

typedef long long ll;

int main() {
  ll N; std::cin >> N;
  ll ans = 0;
  for (ll x = 1; x <= N; ++x) {
    ll y = N/x;
    ans += y * (y+1) * x / 2;
  }
  std::cout << ans << "\n";

  return 0;
}


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

using namespace std;

const int Maxn = 11; 
int ans, n, a[Maxn];

int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	stable_sort(a + 1, a + 1 + n);
	for(int i = 1; i < n; ++i)
		ans += a[i];
	ans += a[n] / 2;
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int k[20001],bit[20001];

int dp[1<<22];
set<int> cnt[1<<22];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k[i]);
		for(int j=0;j<k[i];j++){
			int a=0;
			scanf("%d",&a);
			a--;
			bit[i]+=(1<<a);
		}
		dp[bit[i]]=bit[i];
		if(cnt[bit[i]].size()<3)cnt[bit[i]].insert(i);
	}
	int res=0;
	for(int i=(1<<22)-1;i>=0;i--){
		for(int j=0;j<22;j++){
			if(!((i>>j) & 1)){
				dp[i]|=dp[i+(1<<j)];
				set<int>::iterator it=cnt[i+(1<<j)].begin();
				while(cnt[i].size()<3 && it!=cnt[i+(1<<j)].end()){
					cnt[i].insert(*it);
					it++;
				}
			}
		}
		if(cnt[i].size()==3){
			int v=__builtin_popcount(i)*__builtin_popcount(dp[i]);
			res=max(res,v);
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 805904
from collections import deque
def add(x):
    return x+97

N = int(input())
i = 1
while N > 26**i:
    N = N - 26**i
    i += 1
    
N -= 1
shinsu = deque([])
for j in range(i):
    shinsu.appendleft(N%26)
    N //= 26

shinsu = list(map(add, shinsu))
ans = list(map(chr, shinsu))
print(''.join(ans))

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

using namespace std;

int main() {
  long long a[3], k, ans = 0;
  scanf("%lld %lld %lld", &a[0], &a[1], &a[2]);
  scanf("%lld", &k);
  sort(a, a + 3);
  ans = a[0] + a[1] + (a[2] << k);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
//itp1_9-c
#include <iostream>
#include <cstring>
using namespace std;

int main(){
 int n;
 string s1,s2;
 int cntt=0;
 int cnth=0;
 
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>s1>>s2;
  if(s1>s2) cntt+=3;
  else if(s1<s2) cnth+=3;
  else{
   cntt++;
   cnth++;
  }
 }
 cout<<cntt<<" "<<cnth<<endl;

return 0;
}

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

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    if(a.size()==2)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256