akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
bool isNumber(char c){
  return (c>='0' && c<='9');
}
int main() {
  int a,b;cin>>a>>b;
  string s;cin>>s;
  bool ans=true;
  if(s[a]=='-'){
    string sub=s.substr(0,a);
    rep(i,a){
      if(!isNumber(sub[i])){
        ans=false;
        break;
      }
    }
    string sub2=s.substr(a+1);
    rep(i,b){
      if(!isNumber(sub2[i])){
        ans=false;
        break;
      }
    }
  }else{
    ans=false;
  }
  cout << btos(ans) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N;
  cin>>N;
  
  vector<int64_t> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum+=vec.at(i);
  }
  int64_t S=0;
  int64_t A=sum;
  int64_t D=100000000000000;
  for(int i=0;i<N-1;i++){
    S+=vec.at(i);
    A-=vec.at(i);
    D=min(D,abs(S-A));
  }
  cout<<D<<endl;
    
}

Measured memory_bytes: 4824
def min_value(w, h):
	ans = float('inf')
	for i in range(1, h):
		a = w*i
		v_t = (h-i)//2 * w
		v_b = (h-i)*w - v_t
		v_re = max(a, v_t, v_b) - min(a, v_t, v_b)
		h_l = (h-i)*(w//2)
		h_r = (h-i)*w-h_l
		h_re = max(a, h_l, h_r) - min(a, h_l, h_r)
		ans = min(ans, v_re, h_re)
	return ans

def resolve():
	h, w = map(int, input().split())
	a = min_value(w, h)
	b = min_value(h, w)
	print(min(a, b))
resolve()

Measured memory_bytes: 3064
from collections import Counter

ans_0 = False
N = int(input())
l = list(map(int, input().split()))
l_Counter = Counter(l)
if N % 2 == 1:
    if l_Counter[0] != 1:
        ans_0 = True
    else:
        l_Counter[0] = 2
        for i in l_Counter.items():
            # print(i)
            if i[1] != 2 or i[0] % 2 == 1:
                ans_0 = True
                break
else:
    for i in l_Counter.items():
        # print(i)
        if i[1] != 2 or i[0] == 0 or i[0] % 2 == 0:
            ans_0 = True
            break
#     print(An)
# print(end_0)
if ans_0:
    print(0)
else:
    print((2 ** (N // 2)) % 1000000007)

Measured memory_bytes: 14820
from itertools import accumulate

N = int(input())
P = list(map(int, input().split()))

ans = 0

"""
for i, p in enumerate(P):
    # if np.any(P[0:i] < p): あまり以下と変わらなかった
    # if any([True for p2 in P[0:i] if p2 < p]): # 2回のループが☓ O(n^2)なので
        pass
    else:
        ans += 1
"""

P_min = list(accumulate(P, min))

for p, p_min in zip(P, P_min):
    if p == p_min:
        ans += 1

print(ans)

Measured memory_bytes: 25252
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,k,a,b,ans=0;
	string s;
	cin>>s;
	rep(i,4){
	    if(s[i]=='+')ans++;
	    else ans--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int w, h;
	
	while (scanf("%d %d", &h, &w) * h != 0){
		int field[100][100] = {0};
		char tile[100][100] = {0};
		int x, y;
		int i, j;
		
		for (i = 0; i < h; i++){
			scanf("%s", tile[i]);
		}
		x = y = 0;
		while (tile[y][x] != '.'){
			if (field[y][x] != 0){
				puts("LOOP");
				break;
			}
			else {
				field[y][x] = 1;
			}
			switch (tile[y][x]){
				case '<':
					x--;
					break;
				case '>':
					x++;
					break;
				case '^':
					y--;
					break;
				case 'v':
					y++;
					break;
			}
		}
		if (tile[y][x] == '.'){
			printf("%d %d\n", x, y);
		}
	}
	
	return 0;
}

Measured memory_bytes: 672
a = input().split(' ')
n, k = a
n, k = int(n), int(k)
ps = input().split(' ')
pf = []
for i in ps:
    t = int(i)
    pf.append(t)
pf = sorted(pf)
c = []
s = 0

for i in range(k):
    for j in range(n):
        if j in c:
            continue
        c.append(j)
        s += pf[j]
        break

print(s)


Measured memory_bytes: 9140
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            sum = i * 500 + j * 100 + k * 50
            if sum == X:
                count += 1
print(count)

Measured memory_bytes: 3064
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var priorityQueue=(function(){
  function f(){return new PriorityQueue();}
  function PriorityQueue(){
    this.heap=[];
  }
  PriorityQueue.prototype.push=function(x){
    var h=this.heap,i=h.length++,j;
    while(i){
      j=i-1>>1;
      if(h[j][0]<=x[0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  };
  PriorityQueue.prototype.pop=function(){
    var h=this.heap,r=h[0],x=h.pop(),l=h.length,i=0,j;
    if(l===0)return r;
    var k=l>>1;l--;
    while(i<k){
      j=(i<<1)+1;
      if(j<l&&h[j+1][0]<h[j][0])j++;
      if(x[0]<=h[j][0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
    return r;
  };
  return f;
})();
function gcd(a,b){return b?gcd(b,a%b):a;}

console.log(main());
function main(){
  var n = o.a();
  var x = o.a();
  var d = o.a();
  if(d === 0){
    if(x === 0)return 1;
    return n+1;
  }
  if(d < 0)x = -x, d = -d;
  var g = gcd(d,Math.abs(x));
  x /= g, d /= g;
  var pq = new priorityQueue();
  var mn = Math.min(d,n);
  var ans = 1, zero = 1;
  for(var i = 0; i < mn; i++){
    var xx = -(i+1)*x%d;
    for(var j = i+1; j <= n; j += d){
      var xj = x*j+xx;
      xj /= d;
      var l = xj+(j-1)*j/2;
      var r = xj+j*n-(j+1)*j/2;
      if(zero && xx === 0 && l <= 0 && r >= 0)ans--, zero = 0;
      pq.push([l,r]);
    }
    var p = pq.pop();
    while(pq.heap.length){
      var t = pq.pop();
      if(t[0] <= p[1])p[1] = Math.max(p[1],t[1]);
      else{
        ans += 1+p[1]-p[0];
        p = t;
      }
    }
    ans += 1+p[1]-p[0];
  }
  return ans;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i+=2)
    {
        int yaku = 0;
        for(int j = 1; j <= i; j++)
        {
            if (i%j == 0) {
                yaku++;
            }
        }
        if (yaku == 8) {
            ans++;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
    x,y = map(int,input().split())
    l.append(x)
    r.append(y)
if min(r)-max(l) >= 0:
    print(min(r)-max(l)+1)
else:
    print(0)


Measured memory_bytes: 10996
#include <stdio.h>
int main(){
    int n,m,l;
    int i,j,k;
    int a[110][110];
    int b[110][110];
    long long c[110][110]={0};
    scanf("%d %d %d",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
            if(j!=0) printf(" ");
            printf("%ld",c[i][j]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
const int N(555);
char st[2][N][N];
int main() {
    int n, m;
    cin >> n >> m;
    for(int i(0); i < n; i++) {
        cin >> st[0][i];
    }
    memcpy(st[1], st[0], sizeof(st[0]));
    for(int i(0); i < n; i++) {
        if(i != 0 && i != n - 1) {
            memset(st[i % 2][i] + (i % 2), '#', m - 1);
            st[1][i][m - 1] = '#';
            st[0][i][0] = '#';
        }
    }
    for(int i(0); i < n; i++) {
        cout << st[0][i] << endl;;
    }
    cout << endl;
    for(int j(0); j < n; j++) {
        cout << st[1][j] << endl;
    }
}

Measured memory_bytes: 1280
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long cum_sum_d[1000000];
long long cum_sum_m[1000000];
long long cum_sum_dm[1000000];
//int cum_sum_dmc[1000000];
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    if(S[0] == 'D'){
        cum_sum_d[0] = 1;
    }
    if(S[0] == 'M'){
        cum_sum_m[0] = 1;
    }
    for(int i = 1; i < N; i++){
        cum_sum_d[i] = cum_sum_d[i - 1];
        cum_sum_m[i] = cum_sum_m[i - 1];
        cum_sum_dm[i] = cum_sum_dm[i - 1];
        if(S[i] == 'D'){
            cum_sum_d[i] ++;
        }
        if(S[i] == 'M'){
            cum_sum_m[i] ++;
            cum_sum_dm[i] += cum_sum_d[i];
        }
    }
    for(int i = 0; i < Q; i++){
        int k;
        cin >> k;
        long long ans = 0;
        for(int i = 0; i < N; i++){
            if(S[i] == 'C' && i >= 2){
                long long tmp = cum_sum_dm[i - 1];
                if(i - k >= 0){
                    tmp -= cum_sum_dm[i - k];
                    tmp -= cum_sum_d[i - k] * (cum_sum_m[i - 1] - cum_sum_m[i - k]);
                }
                ans += tmp;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 24836
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#define LL long long
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int i,j,cnt,t;
	int n,cont;
	while(cin>>n){
		cont=0;
		for(i=1;i<=n;i+=2){
			cnt=1;t=i;
			for(j=3;t!=0&&j<=n;j+=2){
				if(t%j==0){
					t/=j;
					cnt++;
				}
			}
			if(cnt==4)
				cont++;
		}
		cout<<cont<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
 
int main(){
 int n;
 double a,m,sum;
 while(1){
  cin >> n;
  int s[n+1]={};
  if(n==0) break;
 
  sum=0;
  for(int i=0;i<n;++i){
   cin >> s[i];
   sum+=s[i];
  }
  m=sum/n;
 
  a=0;
  for(int i=0;i<n;++i){
   a+=pow(s[i]-m,2);
  }
  a=sqrt(a/n);
  cout << fixed << setprecision(8) << a << endl ;
 }
 return 0;
}

Measured memory_bytes: 3276
N,K = gets.chomp.split().map(&:to_i)
MOD=10**9+7

def fac i
  return 1 if i == 0
  (1..i).inject(&:*)
end

def cal_ordering_balls i
  return 0 if N-K+1 < i
  ( fac(N-K+1)/(fac(i)*fac(N-K+1-i)) * fac(K-1)/(fac(i-1)*fac(K-i)) )%MOD
end

(1..K).each do |i|
  puts cal_ordering_balls(i)
end

Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;


vector<vector<bool>> vvi(15, vector<bool>(15, false));

int main(void) {
    int n, x;
    cin >> n >> x;
    int l[n + 1];
    rep (i, n) cin >> l[i + 1];

    int ans = 1;
    vector<int> d(n + 3, 0);
    for (int i = 2; i <= n + 1; i++) {
        d[i] = d[i - 1] + l[i - 1];
        if (d[i] <= x) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int a,b,p;
  cin >> a >> b;

  p=a*b%2;
  
  if (p==0) {
    cout << "Even" << endl;
    }
  else {
    cout << "Odd" << endl;
    }
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

h,w=nii()
ch,cw=nii()
dh,dw=nii()
s=[list(input()) for i in range(h)]

ch-=1
cw-=1
dh-=1
dw-=1

ans=[[-1 for i in range(w)] for i in range(h)]
ans[ch][cw]=0

que=deque()
que.append((ch,cw))

def BFS():
  while que:
    y,x=que.popleft()

    if y==dh and x==dw:
      print(ans[y][x])
      exit()

    for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]:
      ny=y+dy
      nx=x+dx
      if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#':
        que.appendleft((ny,nx))
        s[ny][nx]='#'
        ans[ny][nx]=ans[y][x]

      for i in range(-2,3):
        for j in range(-2,3):
          ny=y+i
          nx=x+j
          if 0<=ny<h and 0<=nx<w and s[ny][nx]!='#' and ans[ny][nx]==-1:
            que.append((ny,nx))
            ans[ny][nx]=ans[y][x]+1

BFS()

print(-1)

Measured memory_bytes: 137640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string S;
int cnt;
ll num;
ll ans;
ll l[500005], r[500005];

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

  cin >> S;
  int N=S.size();
  rep(i, N) {
    if (S[i]=='<')l[i+1] = l[i] +1; //左側に何個<が連続するか
  }
  for (int i=N-1;i>=0; i--) {
    if (S[i]=='>') r[i] = r[i+1]+1;
  }
  ll ans=0ll;
  rep(i, N+1) ans+=max(l[i], r[i]);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 8732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> cd;
  for(int i = 1; i <= 100; i++){
    if(a%i == 0 && b % i == 0) cd.push_back(i);
  }
  reverse(all(cd));
  cout << cd[k-1] <<endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#define N 500000
int temp[N],cnt=0;
int main();
void mergesort(int A[],int left,int right)
{
int mid,i,j,k;
if(left<right){

mid=(left+right)/2;

mergesort(A,left,mid);
mergesort(A,mid+1,right);

for(i=mid;i>=left;i--){temp[i]=A[i];}
for(j=mid+1;j<=right;j++){
  temp[right-(j-(mid+1))]=A[j];
}
i=left;
j=right;
for(k=left;k<=right;k++){
if(temp[i]<temp[j])
A[k]=temp[i++];
else A[k]=temp[j--];
cnt++;
}
}
}
int main()
{
int i,kazu,A[N];

scanf("%d",&kazu);
for(i=0;i<kazu;i++){
scanf("%d",&A[i]);
}
mergesort(A,0,kazu-1);
for(i=0;i<kazu;i++)
{
  if(i>0)printf(" ");
  printf("%d",A[i]);
}
printf("\n");
printf("%d\n",cnt);
return 0;
}



Measured memory_bytes: 5632
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	int n, x, m[100], tmp=1000000;
	cin >> n >> x;
	for(int i=0; i<n; i++){
		cin >> m[i];
		x-=m[i];
		tmp=min(m[i], tmp);
	}
	int cnt=n;
	x/=tmp;
	cout << cnt+x << endl;

	return 0;
}

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

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

int main(){
    long long x;
    cin >> x;

    while(1){
        if(is_prime(x) == true){
            break;
        }
        x++;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

import java.util.HashSet;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int turn = scan.nextInt();
    int object = scan.nextInt();

    while(!(turn==0&&object==0)) {
      HashSet<Point> canMove = new HashSet<>();
      HashSet<Point> nextMove = new HashSet<>();
      HashSet<Point> objects = new HashSet<>();

      for(int i = 0; i < object; i++) {
        Point dummyP = new Point(scan.nextInt(),scan.nextInt());
        objects.add(dummyP);
      }

      Point startP = new Point(scan.nextInt(),scan.nextInt());
      canMove.add(startP);
      nextMove.add(startP);

      for(int i = 0; i < turn; i++) {
        HashSet<Point> dummyMove = new HashSet<>();
        for(Point _p : nextMove) {
          Point[] parr = new Point[6];
          parr[0] = new Point(_p.x+1,_p.y);
          parr[1] = new Point(_p.x,_p.y+1);
          parr[2] = new Point(_p.x+1,_p.y+1);
          parr[3] = new Point(_p.x-1,_p.y);
          parr[4] = new Point(_p.x,_p.y-1);
          parr[5] = new Point(_p.x-1,_p.y-1);

          for(Point _pa : parr) {
            if(!canMove.contains(_pa)&&!objects.contains(_pa)) {
              //System.out.println(_pa);
              dummyMove.add(_pa);
              canMove.add(_pa);
            }
          }
        }
        if(dummyMove.size()<=0) break;

        nextMove = dummyMove;
      }

      System.out.println(canMove.size());

      turn = scan.nextInt();
      object = scan.nextInt();
    }
  }
}

class Point{
  int x,y;
  Point(int _x, int _y) {
    x = _x;
    y = _y;
  }

  @Override
  public String toString() {
    return "("+x+","+y+")";
  }

  @Override
  public int hashCode() {
    return x*10000+y;
  }

  @Override
  public boolean equals(Object obj) {
    if(x==((Point)obj).x&&y==((Point)obj).y) return true;
    return false;
  }
}

Measured memory_bytes: 83088
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    for(ll i=0;i<n;i++){
        ll acu=a+i*d,acd=a+i*c;
        if(!(acu<b+c*(n-i-1)||acd>b+d*(n-i-1))||!(acu<b-d*(n-i-1)||acd>b-c*(n-i-1))){
            cout<<"YES"<<"\n";
            return 0;
        }
        acu=a-i*c,acd=a-i*d;
        if(!(acu<b+c*(n-i-1)||acd>b+d*(n-i-1))||!(acu<b-d*(n-i-1)||acd>b-c*(n-i-1))){
            cout<<"YES"<<"\n";
            return 0;
        }
    }
    cout<<"NO"<<"\n";
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){
    int a,b,t;
    cin >> a >> b >> t;

    int ans = 0;
    
    ans = b * (t/a);

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    vector<pair<pair<string, int>, int>> a(n);
    rep(i, n)
    {
        string s; int b; cin >> s >> b;
        a[i] = make_pair(make_pair(s, -b), i + 1); // マイナスB
    }

    sort(ALL(a));

    rep(i, n)
    {
        cout << a[i].second << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int x,y;
    cin>>x>>y;
    if((y-2*x)>=0&&(4*x-y)>=0&&(y-2*x)%2==0&&(4*x-y)%2==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

string s;
map<long long, int> cnt;
long long ans;

int main() {

    getline(cin, s);
    cnt[0] = 1;

    long long cur = 0;
    long long p = 1;
    for (int i = sz(s) - 1; i >= 0; i--) {
        p = p * 10 % 2019; 
        cur = ((1ll * (s[i] - '0') * p % 2019) + cur) % 2019;
        ans += cnt[cur];
        cnt[cur]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3736
let n = read_int ()

let rec f x = if n mod x = 0 then n / x else f (pred x)

let len_int x =
  let rec f tmp c = if tmp > 0 then f (tmp / 10) (succ c) else c in
  f x 0

let () = int_of_float (float n ** 0.5) |> f |> len_int |> Printf.printf "%d\n"

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  int k,n;
  cin >> k >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  int b[n];
  int mx = 0;
  int c;
  for(int i=0; i<n-1; i++){
    int d = a[i+1]-a[i];
    b[i] = d;
    if(d >= mx){
      mx = d;
      c = i;
    }
  }
  b[n-1] = k-a[n-1]+a[0];
  mx = max(mx,b[n-1]);
  cout << k-mx << endl;
}
  

Measured memory_bytes: 1792
import collections

h,w,m = map(int,input().split())
l=[]
x=[]
y=[]
for i in range(m):
    hw=list(map(int,input().split()))
    l.append(hw)
    y.append(hw[0])
    x.append(hw[1])

xc = collections.Counter(x)
yc = collections.Counter(y)

tuplex = xc.most_common()[0]
tupley = yc.most_common()[0]

mostx=tuplex[0]
mosty=tupley[0]

if tuplex[1]>tupley[1]:
    y=[]
    for i in range(m):
        if l[i][1]!=mostx:
            y.append(l[i][0])
    if len(y) != 0:
        yc = collections.Counter(y)
    tupley = yc.most_common()[0]
    mosty=tupley[0]
    ans=0
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx:
            ans+=1
    print(ans)

elif tuplex[1]<tupley[1]:
    x=[]
    for i in range(m):
        if l[i][0]!=mosty:
            x.append(l[i][1])
    if len(x) != 0:
        xc = collections.Counter(x)
    tuplex = xc.most_common()[0]
    mostx=tuplex[0]
    ans=0
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx:
            ans+=1
    print(ans)

else:
    #y基準
    ans1=0
    x1=[]
    for i in range(m):
        if l[i][0]!=mosty:
            x1.append(l[i][1])
    if len(x1) != 0:
        x1c = collections.Counter(x1)
    else:
        x1c = collections.Counter(x)
    tuplex1 = x1c.most_common()[0]
    mostx1=tuplex1[0]
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx1:
            ans1+=1
    #x基準
    ans2=0
    y1=[]
    for i in range(m):
        if l[i][1]!=mostx:
            y1.append(l[i][0])
    if len(y1) != 0:
        y1c =collections.Counter(y1)
    else:
        y1c = collections.Counter(y)
    tupley1 = y1c.most_common()[0]
    mosty1=tupley1[0]
    for j in range(m):
        if l[j][0] == mosty1 or l[j][1] == mostx:
            ans2+=1
    print(max(ans1,ans2))

Measured memory_bytes: 143888
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

const long long mod=1e9+7;

int main(){

    int n;
    string s;
    cin>>n>>s;

    for(int i=0;i<s.size();i++){
        cout<<(char)( (s[i]-'A' + n)%26 + 'A' );
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys

def findGCD(a, b):
  if b == 0:
    return a
  return findGCD(b, a%b)

if __name__ == "__main__":
  for line in sys.stdin:
    a, b = [int(i) for i in line.strip().split(" ")]
    GCD = findGCD(a,b)
    LCM = a*b//GCD
    print(GCD, LCM)



Measured memory_bytes: 5600
X = int(input())

import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

for i in range(X, 10**6):
    if is_prime3(i) == True:
        print(i)
        break

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,d;
    cin >> n >> d;
    int32 x[n][d];
    REP(i,n)REP(j,d)
        cin >> x[i][j];
    int32 ans = 0;
    REP(i,n-1)FOR(j,i+1,n){
        int64 sum = 0;
        REP(k,d){
            sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        int64 dist = sqrt(sum);
        if(dist * dist == sum)ans++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
# Generated by AtcoderGreedy on 2018-05-26
# ARC098 C
# Your code here

N = gets.chomp.to_i
S = gets.chomp

[:left, :right].map { |d| [d, {left: 0, right: 0}] }.to_h

acc = {
  left: Array.new(N+1),
  right: Array.new(N+1)
}

acc[:left][0] = { left: 0, right: 0 }
acc[:right][N] = { left: 0, right: 0 }

N.times do |i|
  if S[i] == 'W'
    acc[:left][i + 1] = { left: acc[:left][i][:left] + 1, right: acc[:left][i][:right] }
  else
    acc[:left][i + 1] = { left: acc[:left][i][:left], right: acc[:left][i][:right] + 1 }
  end
  if S[N - i - 1] == 'W'
    acc[:right][N - i - 1] = { left: acc[:right][N - i][:left] + 1, right: acc[:right][N - i][:right] }
  else
    acc[:right][N - i - 1] = { left: acc[:right][N - i][:left], right: acc[:right][N - i][:right] + 1 }
  end
end

mins = (0...N).map do |i|
  acc[:left][i][:left] + acc[:right][i + 1][:right]
end

puts mins.min


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

int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  int b=0;
  int c=0;
  for(int i=0;i<3;i++){
    if(a[i]==5){
      b++;
    }
    else if(a[i]==7){
      c++;
    }
    else{
      continue;
    }
  }
  if(b==2&&c==1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int n, k; cin >> n >> k;
    set<ll> s;
    FOR(i, 0, k) {
        int d; cin >> d;
        FOR(i, 0, d) {
            ll tmp; cin >> tmp;
            s.insert(tmp);
        }
    }
    cout << n - s.size() << endl;
    
}

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    set<int> x;
    REP(i,n){
        int a;
        cin>>a;
        if(x.count(a))x.erase(a);
        else x.insert(a);
    }
    cout<<x.size()<<endl;
    return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        
        int x = N * 800;
        int y = (N / 15) * 200;
        System.out.println(x - y);
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> a(n); for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int s = 0;
    for(int i=0; i<k; i++) s+= a[i];
    cout << s << endl;
}


Measured memory_bytes: 3660
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

void test() {
    int M = 2, N = (1<<M);
    vector<int> v(2*N);
    for(int i=0; i<N; i++) v[2*i] = v[2*i+1] = i;

    do {
        vector<int> il(N, -1), ir(N, -1);
        for(int i=0; i<2*N; i++) {
            int val = v[i];
            if(il[val] < 0) il[val] = i;
            else ir[val] = i;
        }

        vector<int> rec(N);
        set<int> S;
        for(int i=0; i<N; i++) {
            int xor_sum = 0;
            for(int k=il[i]; k<=ir[i]; k++) {
                xor_sum ^= v[k];
            }
            // fprintf(stderr, "# xor_sum (%lld) = %lld\n", i, xor_sum);
            S.insert(xor_sum);
            rec[i] = xor_sum;
        }
        // fprintf(stderr, "\n");

        if(S.size() > 1 or *S.begin() == 0) continue;
        for(int i=0; i<N; i++) {
            fprintf(stderr, "# xor_sum (%lld) = %lld\n", i, rec[i]);
        }
        
        fprintf(stderr, "[");
        for(int i=0; i<2*N; i++) {
            fprintf(stderr, "%lld%c", v[i], " ]"[i+1 == 2*N]);
        }
        fprintf(stderr, "\n\n");
        
    }while(next_permutation(v.begin(), v.end()));
}

signed main() {
    // test();
    int M, K; cin >> M >> K;

    int sum = 0;
    for(int i=0; i<(1<<M); i++) {
        if(i != K) {
            // fprintf(stderr, "val = %lld, sum: %lld -> %lld\n", i, sum, sum ^ i);
            sum ^= i;
        }
    }

    if(K == 0) {
        vector<int> vec;
        int lim = 2*(1<<M);
        
        for(int i=0; i<lim; i++) {
            printf("%lld%c", i/2, " \n"[i+1 == lim]);
        }
        return 0;
    }

    // fprintf(stderr, "sum = %lld\n", sum);
    if(K >= (1<<M) or sum != K) {
        cout << -1 << endl;
    }
    else {
        deque<int> deq;
        deq.push_back(K);
        for(int i=0; i<(1<<M); i++) {
            if(i == K) continue;
            deq.push_front(i);
            deq.push_back(i);
        }
        deq.push_back(K);

        int lim = 2*(1<<M);
        for(int i=0; i<lim; i++) {
            printf("%lld%c", deq[i], " \n"[i+1 == lim]);
        }
    }
    return 0;
}


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

int main() {
	string S;
	cin >> S;
	bool No=false, We=false, So=false, Ea=false;
	for (char c : S) {
		if (c == 'N') No = true;
		if (c == 'S') So = true;
		if (c == 'W') We = true;
		if (c == 'E') Ea = true;
	}
	cout << (No == So && We == Ea ? "Yes" : "No") << endl;
}

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

using namespace std;
int main(){
  int n,r,s;
  int max=-1000000000;
  cin>>n;
  cin>>r;
  s=r;
  for(int i=1;i<n;i++)
  {
    cin>>r;
    if(max<r-s) max=r-s;
    if(s>r) s=r;
  }
  cout << max << endl;
  return 0;
}



Measured memory_bytes: 3100
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(x: "List[int]"):
    ret = 0
    for i, v in enumerate(x):
        if v == 0:
            ret = i + 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61732
fun main(args: Array<String>) {
    var n = readLine()!!.toLong()
    val az = arrayOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
    var result = StringBuilder()

    while (n > 0) {
        val h = (n % 26).toInt()
        if (h == 0) {
            result.append(az[25])
            n--
        } else {
            val s = h
            result.append(az[s - 1])
        }
        n /= 26
    }
    val output = result.split("").reversed().joinToString("")
    println(output)
}

Measured memory_bytes: 39684
import sys
import copy
import time
import random

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline

D = None
C = None
S = None

def cnt_score(t):
    global D, C, S
    score = 0
    cnt = [-1] * 26

    for i in range(D):
        score += S[i][t[i] - 1]
        minusscore = 0
        cnt[t[i] - 1] = i
        for j in range(26):
            minusscore += (i - cnt[j]) * C[j]
        score -= minusscore
    return score


def main():
    global D, C, S
    D = int(input())
    C = [int(x) for x in input().split()]
    S = [[int(x) for x in input().split()] for _ in range(D)]

    start = time.time()

    ans = []
    for s in S:
        ans.append(C.index(max(C)) + 1)

    # 初期値をランダムで探す
    while True:
        # time up
        current = time.time()
        if current - start > 1.0:
            break

        # main
        new_ans = []
        for _ in range(D):
            new_ans.append(random.randint(1, 26))

        if cnt_score(new_ans) > cnt_score(ans):
            ans = new_ans

    #ans = [1] * D

    day = 0
    while True:
        # time up
        current = time.time()
        if current - start > 1.8:
            break

        # main
        new_ans = copy.deepcopy(ans)
        old_score = cnt_score(ans)

        max_sore = old_score
        max_contest = ans[day]
        for i in range(26):
            new_ans[day] = i + 1
            new_score = cnt_score(new_ans)
            if new_score > old_score:
                max_contest = i + 1
                old_score = new_score
        ans[day] = max_contest

        # increment day
        day = (day + 1) % D

    for a in ans:
        print(a)



if __name__ == '__main__':
    main()


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    int a[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a+3);
    bool ok = false;
    if(a[0] == a[1] and a[2] != a[0]) ok = true;
    if(a[1] == a[2] and a[0] != a[1]) ok = true;
    if(a[0] == a[2] and a[0] != a[1]) ok = true;
    
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
import collections

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

v1 = v[::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if (v1 == v2 and len(c1.most_common()) == 1):
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] < c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])

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


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i]

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


int main(){
  int N; cin >> N;
  vector<int> h(N);
  for(auto &x : h) cin >> x;
  vector<int> dp(N);
  dp[0]=0, dp[1]=abs(h[1]-h[0]);
  for(int i=0;i<N-2;i++){
    int h1, h2;
    h1=abs(h[i+2]-h[i+1]);
    h2=abs(h[i+2]-h[i]);
    dp[i+2]=min(dp[i+1]+h1, dp[i]+h2);
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n), y(n); 
    vector<int> sx, sy;
    REP(i, n){
        cin >> x[i] >> y[i];
        sx.pb(x[i]); sy.pb(y[i]);
    }
    SORT(sx); SORT(sy);
    ll ans = 1LL * (sx[n - 1] - sx[0]) * (sy[n - 1] - sy[0]);
    for(int lx = 0; lx < n; ++lx){
        for(int ux = lx + 1; ux < n; ++ux){
            for(int ly = 0; ly < n; ++ly){
                for(int uy = ly + 1; uy < n; ++uy){
                    int cnt = 0;
                    REP(i, n){
                        if(sx[lx] <= x[i] && x[i] <= sx[ux] && sy[ly] <= y[i] && y[i] <= sy[uy]){
                            cnt++;
                        }
                    }
                    if(cnt >= k) ans = min(ans, 1LL * (sx[ux] - sx[lx]) * (sy[uy] - sy[ly]));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256