akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define NIL -1
 
struct setu { /*構造体*/
  int r;
  int l;
  int p;
};
struct setu T[100000];
int n,K[100000];
 
int depth(int,int);/*次数をもとめる*/
void strk(int);/*出力関数*/
 
int main(){
 
  int i,j,id,k,c,l,r;
 
  scanf("%d",&n);
 
 
  for(i=0;i<n;i++){ /*構造体をNILで初期化*/
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  } 
  for(i=0;i<n;i++){
 
    scanf("%d %d",&id,&k); /*id =節点番号 k = 次数*/
 
    for(j=0;j<k;j++){
 
      scanf("%d",&c);
      if( j==0 ) T[id].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = id;
 
    }
  }
 
  for(i=0;i<n;i++){
    if(T[i].p == NIL) r = i;
  }
  depth(r,0);
 
  for(i = 0;i<n ;i++) strk(i);
 
  return 0;
}
 
int depth(int u, int p){ /*次数を求める*/
  K[u] = p;
  if(T[u].r != NIL) depth(T[u].r,p);
  if(T[u].l != NIL) depth(T[u].l,p + 1);
}
 
void strk(int u){ /*出力関数*/
 
  int i,c;
 
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("depth = %d, ", K[u]);
 
  if(T[u].p == NIL ) printf("root, ");
 
  else if(T[u].l == NIL) printf("leaf, ");
 
  else printf("internal node, ");
 
  printf("[");
 
  for(i=0,c = T[u].l ; c !=NIL;i++,c = T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = n*(n-1)/2+1;
    vector<ll> c(26, 0);
    for(int i = 0; i < n; i++) {
        c[s[i]-'a']++;
    }
    for(int i = 0; i < 26; i++) {
        ans -= c[i]*(c[i]-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    AReqTime = [0]
    BReqTime = [0]

    for i in range(N):
        AReqTime.append(AReqTime[i] + A[i])
    for i in range(M):
        BReqTime.append(BReqTime[i] + B[i])

    j = M
    answer = 0

    for i in range(N + 1):
        if(AReqTime[i] > K):
            break

        while BReqTime[j] > K - AReqTime[i]:
            j = j - 1

        answer = max(i + j, answer)

    print(answer)

if __name__ == "__main__":
    main()

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

vector<int> enumerateDivisors(int M) {
    vector<int> res;
    for (int n = 1; n * n <= M; n++) {
        if (M % n == 0) {
            res.push_back(n);
            res.push_back(M / n);
        }
        if (n * n == M) {
            res.pop_back();
        }
    }
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;

    int ans = 1;
    for (auto d : enumerateDivisors(M)) {
        if ((int64_t)N * d <= M and (M - N * d) % d == 0) {
            ans = max(ans, d);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
string s;
cin>>s;
s[k-1]+=('a'-'A');
cout<<s<<endl;
}

Measured memory_bytes: 3588
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

int main(void) {
	uint32_t A[3];

	scanf("%"PRIu32" %"PRIu32" %"PRIu32, &A[0], &A[1], &A[2]);

	uint32_t min = ABSS(A[0], A[1]) + ABSS(A[1], A[2]);
	uint32_t cost = ABSS(A[0], A[2]) + ABSS(A[2], A[1]);
	if (cost < min) {
		min = cost;
	}
	cost = ABSS(A[1], A[0]) + ABSS(A[0], A[2]);
	if (cost < min) {
		min = cost;
	}
	cost = ABSS(A[1], A[2]) + ABSS(A[2], A[0]);
	if (cost < min) {
		min = cost;
	}
	cost = ABSS(A[2], A[0]) + ABSS(A[0], A[1]);
	if (cost < min) {
		min = cost;
	}
	cost = ABSS(A[2], A[1]) + ABSS(A[1], A[0]);
	if (cost < min) {
		min = cost;
	}

	printf("%"PRIu32, min);

	return 0;
}


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

using namespace std;

int main()
{

    int n, ans = 0;
    cin >> n;

    for (size_t i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if(i % 2 == 1)
        {
            if(x % 2 == 1)
            {
                ans++;
            }
        }
    }

    cout << ans;
    

    return 0;
}

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


int main() {
  long long N;
  cin >> N;
  vector<long long> vec(N);
  for (long long i = 0; i < N; ++i) {
    cin >> vec.at(i);
    vec.at(i) -= (i + 1);
  }
  sort(vec.begin(), vec.end());
  long long median;
  if (N % 2 == 0) {
    median = N / 2 - 1;
  } else {
    median = (N - 1) / 2;
  }
  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    ans += abs(vec.at(i) - vec.at(median));
  }
  cout << ans << endl;
  return 0;
}





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


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

	int h1,m1,s1;
	int h2,m2,s2;
	int time,ah,am,as,bh,bm,bs,ch,cm,cs;

	cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
	
	time = (((h2*3600) + (m2*60) + (s2)) -  ((h1*3600) + (m1*60) + (s1)));
	
	ah = time / 3600;
	am = (time % 3600) / 60;
	as = time - (ah*3600) - (am*60);


        cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;

        time = (((h2*3600) + (m2*60) + (s2)) -  ((h1*3600) + (m1*60) + (s1)));



	bh = time / 3600;
        bm = (time % 3600) / 60;
        bs = time - (bh*3600) - (bm*60);

        cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;

        time = (((h2*3600) + (m2*60) + (s2)) -  ((h1*3600) + (m1*60) + (s1)));


	ch = time / 3600;
        cm = (time % 3600) / 60;
        cs = time - (ch*3600) - (cm*60);


	
	printf("%d %d %d\n", ah, am, as);
	printf("%d %d %d\n", bh, bm, bs);
	printf("%d %d %d\n", ch, cm, cs);
	return 0;
}

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

int LCS(string a,string b){
    int n1=a.size(),n2=b.size();
    int DP[n1+1][n2+1];
    DP[0][0]=0;
    rep(i,n1)DP[i+1][0]=0;
    rep(i,n2)DP[0][i+1]=0;
    rep(i,n1){
        rep(j,n2){
            if(a[i]==b[j])DP[i+1][j+1]=1+DP[i][j];
            else DP[i+1][j+1]=max(DP[i][j+1],DP[i+1][j]);
        }
    }
    return DP[n1][n2];
}

int main(){
    int q;cin>>q;
    string s,t;
    rep(i,q){
        cin>>s>>t;
        int ans=LCS(s,t);
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 7200
def examB():
    N, M, K = LI()
    ans = "No"
    for i in range(N+1):
        for j in range(M+1):
            cur = M*i + N*j - i*j*2
#            print(i,j,cur)
            if cur==K:
                ans = "Yes"
                break
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 38896
n = int(input())
# graph = [[-1]*n]*n この初期化の仕方はよくない。すべてが同じ要素だと判断されて一個要素を変えるとすべてに反映される
graph = [[-1]*n for _ in range(n)]
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    graph[i][x-1] = y
    
ans = 0
# n人が正直or不親切の場合を全探索
for i in range(2**n):
  honesty = [0]*n
  for j in range(n):
    if ((i >> j) & 1):
      honesty[j] = 1 # 0~n-1までの2進数表記

  ok = True # 矛盾しないかのフラッグok
  for j in range(n): # 一人ずつ証言と矛盾しないか確かめる
    if honesty[j]: # 正直の時は証言は確実でなければならない
      for k in range(n): # その人の他の人(自分も含める-1だから関係ないけど)への証言
        if graph[j][k] == -1: continue
        if graph[j][k] != honesty[k]: ok = False # 証言の有向グラフと仮定のhonestyが違ったらこれは矛盾している
  if ok: # 矛盾せずにここまでこれたbitの中でフラグが一番多いのが勝ち
    ans = max(ans, honesty.count(1))

print(ans)


Measured memory_bytes: 3064
"""参考
ベスパリブ プログラミングを主とした日記・備忘録です 2019-09-14
id:takeg
https://takeg.hatenadiary.jp/entry/2019/09/14/132409
"""
# 初期入力
S =input().strip()
ans=[0]*len(S)
count_R =0
count_L =0
#Rについて考える 左右両方から攻めようと思ったが×
for i in range(len(S)):
    if S[i]=="R":
        count_R +=1
        #continue
    else:
        even_num_R  =count_R//2
        odd_num_R   =count_R -even_num_R
        ans[i-1]    +=odd_num_R
        ans[i]      +=even_num_R
        count_R =0

#Lについて考える
for i in range(len(S)-1,-1,-1):
    if S[i]=="L":
        count_L +=1
        continue
    else:
        even_num_L  =count_L //2
        odd_num_L   =count_L -even_num_L
        ans[i+1]    +=odd_num_L     #小さくなっていくから、+１が右側
        ans[i]      +=even_num_L
        count_L =0

print(*ans)

Measured memory_bytes: 6512
from collections import defaultdict
from collections import deque
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
field=[[float('inf') for i in range(w)] for j in range(h)]

q=deque()
q.append((0,0))
field[0][0]=0

dx=[0,1,0,-1]
dy=[1,0,-1,0]

while q:
    y,x=q.popleft()
    
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        if 0<=nx<w and 0<=ny<h and field[ny][nx]==float('inf') and s[ny][nx]!='#':
            field[ny][nx]=field[y][x]+1
            q.append((ny,nx))
check=field[h-1][w-1]

dic=defaultdict(int)
for i in range(h):
    for j in range(w):
        dic[field[i][j]]+=1
ans=0

for key,value in dic.items():
    if key!=float('inf') and key <=check:
        ans+=value-1
    elif key!=float('inf') and key >check:
        ans+=value
    

for i in range(h):
    for j in range(w):
        if field[i][j]==float('inf') and s[i][j]=='.':
            ans+=1
print(ans if check!=float('inf') else -1)



Measured memory_bytes: 42096
#include<stdio.h>
#include<string.h>
int main(void){
    char x[100],y[100];
    int i,xlen,ylen;
    scanf("%s",&x);
    scanf("%s",&y);
    xlen=strlen(x);
    ylen=strlen(y);
    for(i=0;i<ylen;i++){
        printf("%c%c",x[i],y[i]);
    }
    if(xlen!=ylen){
        printf("%c\n",x[i]);
    }else{
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
import math
import sys
from operator import itemgetter

# N, K = map(int, input().split())
# h = list(map(int, input().split()))
# S = [input() for _ in range(H)]
# X = [[0 for j in range(100)] for i in range(200)]


### input
N, K = map(int, input().split())
A = list(map(int, input().split()))

## solve
MAX_BIT = 41

dp = [[-1 for j in range(2)] for i in range(MAX_BIT+1)]
# dp[i][smaller]: 上位i桁まで決めたときの暫定maximum
# smaller=0のとき、X=K
# smaller=1のとき、X<K

dp[0][0] = 0
for i in range(1, MAX_BIT+1):
	count = 0
	chk_num = 1 << (MAX_BIT - i)
	for j in range(N):
		if (chk_num & A[j]):
			count += 1
	cost0 = chk_num * count # K_i = 0
	cost1 = chk_num * (N - count) # K_i = 1
	
	if (chk_num & K):
		dp[i][0] = dp[i-1][0] + cost1
		if (dp[i-1][1] == -1):
			dp[i][1] = cost0
		else:
			dp[i][1] = max(dp[i-1][0] + cost0, dp[i-1][1] + cost0, dp[i-1][1] + cost1)
	else:
		dp[i][0] = dp[i-1][0] + cost0
		if (dp[i-1][1] != -1):
			dp[i][1] = max(dp[i-1][1] + cost0, dp[i-1][1] + cost1)
			
print(max(dp[MAX_BIT][0], dp[MAX_BIT][1]))

Measured memory_bytes: 14748
n, m = map(int,input().split())
ab_list=[list(map(int,input().split())) for i in range(n)]

sorted_ab = sorted(ab_list)

count = 0
current_price = 0
flag = False
for sab in sorted_ab :
    if count + sab[1] <= m :
        count += sab[1]
        current_price += sab[0] * sab[1]
    else :
        for i in range(sab[1]):
            if count == m :
                flag = True
                break
            count += 1
            current_price += sab[0]
    
    if flag == True:
        break
print(current_price)

Measured memory_bytes: 28644
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int N=1e5;
int n,w,f[101][100001];
int we[101],v[101];
int main()
{
    cin >>n>>w;
    forinc(i,1,n) cin >>we[i]>>v[i];
    forinc(i,0,n)
    forinc(t,0,N) f[i][t]=INT_MAX;
    f[0][0]=0;
    forinc(i,0,n-1)
    forinc(t,0,N) if(f[i][t]<INT_MAX)
    {
        if(f[i][t]+we[i+1]<=w) f[i+1][t+v[i+1]]=min(f[i][t]+we[i+1],f[i+1][t+v[i+1]]);
        f[i+1][t]=min(f[i+1][t],f[i][t]);
    }
    for(int i=N;i>=0;--i)
    {
        if(f[n][i]<INT_MAX)
        {
            cout <<i;
            return 0;
        }
    }
}

Measured memory_bytes: 39680
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    string s, t;
    cin >> s;


    for(int i =0; i < s.length(); ++i){
        t += 'x';
    }

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
		
		System.out.println(Math.min(
				Math.min(a * x + b * y, Math.min(x, y) * c * 2 + (x - Math.min(x, y)) * a + (y - Math.min(x, y)) * b),
				Math.max(x, y) * c * 2));
	}
}

Measured memory_bytes: 35636
#include <bits/stdc++.h>
using namespace std;
#define BE(x) (x).begin(), (x).end()

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<vector<int>> v(n+1);
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int s = v[1].size();
    for (int i = 0; i < s; i++) {
        int x = v[1][i];
        sort (BE(v[x]));
        if (v[x].back() == n) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


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

int n, m, k_;
vector<pair<int, int>> s, t;
string p1, p2;

void solve(int x, int p) {
  int k = k_ - 1;
  if (x != 3) {
    if (x) s.emplace_back(x, p);
    return;
  }
  ++p;
  t.clear();
  while (!s.empty()) {
    int y = s.back().first, q = s.back().second;
    if (q > p) {
      if (x != 3) {
        t.emplace_back(x, p);
        k = -1;
        break;
      } else if (k <= 0) {
        t.emplace_back(3, p);
        k = -1;
        break;
      } else if (q - p > k) {
        t.emplace_back(3, p + k);
        k = -1;
        break;
      } else {
        k -= q - p;
        p = q;
      }
    }
    s.pop_back();
    if (y == 2) {
      if (x == 3) {
        t.emplace_back(1, p);
        x = 2;
      } else if (x == 2) {
        x = 2;
      } else if (x == 1) {
        x = 3;
        --k;
        if (k < 0) {
          t.emplace_back(3, p);
          break;
        }
      }
    } else if (y == 1) {
      if (x == 3) {
        t.emplace_back(2, p);
        x = 1;
      } else if (x == 1) {
        x = 1;
      } else if (x == 2) {
        x = 3;
        --k;
        if (k < 0) {
          t.emplace_back(3, p);
          break;
        }
      }
    } else {
      assert(0);
    }
    ++p;
  }
  if (k >= 0) {
    if (x != 3) {
      s.emplace_back(x, p);
    } else {
      s.emplace_back(3, p + k);
    }
  }
  while (!t.empty()) {
    s.push_back(t.back());
    t.pop_back();
  }
}

int main() {
  cin >> n >> m >> k_ >> p1 >> p2;
  reverse(p1.begin(), p1.end());
  reverse(p2.begin(), p2.end());
  while (n < m) p1.push_back('0'), ++n;
  while (m < n) p2.push_back('0'), ++m;
  for (int i = n - 1; i >= 0; i--) {
    solve(p1[i] - '0' << 1 | p2[i] - '0', i);
  }
  string q1(s[0].second + 1, '0'), q2(s[0].second + 1, '0');
  for (auto x : s) {
    q1[x.second] = '0' + (x.first >> 1);
    q2[x.second] = '0' + (x.first & 1);
  }
  while (q1.length() > 1 && q1.back() == '0') q1.pop_back();
  while (q2.length() > 1 && q2.back() == '0') q2.pop_back();
  reverse(q1.begin(), q1.end());
  reverse(q2.begin(), q2.end());
  cout << q1 << endl << q2 << endl;
}


Measured memory_bytes: 17784
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

ll a[512][512];
int n;ll r;

int main(){
	scanf("%d",&n);
	fore(i,0,n)fore(j,0,n)scanf("%lld",&a[i][j]);
	fore(i,0,n)fore(j,i+1,n){
		bool asd=true;
		fore(k,0,n){
			if(k==i||k==j)continue;
			if(a[i][k]+a[k][j]<a[i][j]){puts("-1");return 0;}
			else if(a[i][k]+a[k][j]==a[i][j])asd=false;
		}
		if(asd)r+=a[i][j];
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
#define MAX 200200
#define lson (now<<1)
#define rson (now<<1|1)
const int inf=1e9;
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,Rmin,Rmax,Bmin,Bmax;ll ans=2e18;
struct Node{int x,y;}a[MAX];
bool operator<(Node a,Node b){if(a.x!=b.x)return a.x>b.x;return a.y>b.y;}
struct SegMentTree
{
	int t1[MAX<<2],t2[MAX<<2],a[MAX];
	void pushup(int now){t1[now]=max(t1[lson],t1[rson]);t2[now]=min(t2[lson],t2[rson]);}
	void Build(int now,int l,int r)
	{
		if(l==r){t1[now]=t2[now]=a[l];return;}
		int mid=(l+r)>>1;
		Build(lson,l,mid);Build(rson,mid+1,r);
		pushup(now);
	}
	int Querymx(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t1[now];
		int mid=(l+r)>>1,ret=0;
		if(L<=mid)ret=max(ret,Querymx(lson,l,mid,L,R));
		if(R>mid)ret=max(ret,Querymx(rson,mid+1,r,L,R));
		return ret;
	}
	int Querymn(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t2[now];
		int mid=(l+r)>>1,ret=1e9;
		if(L<=mid)ret=min(ret,Querymn(lson,l,mid,L,R));
		if(R>mid)ret=min(ret,Querymn(rson,mid+1,r,L,R));
		return ret;
	}
}T;
int main()
{
	n=read();int mn=1e9;
	for(int i=1;i<=n;++i)a[i].x=read(),a[i].y=read();
	for(int i=1;i<=n;++i)if(a[i].x<a[i].y)swap(a[i].x,a[i].y);
	for(int i=1;i<=n;++i)mn=min(mn,a[i].y);
	for(int i=1;i<=n;++i)if(a[i].y==mn){swap(a[i],a[n]);break;}
	Rmin=mn;sort(&a[1],&a[n]);
	for(int i=1;i<n;++i)T.a[i]=a[i].y;
	T.Build(1,1,n-1);
	for(int i=1;i<n;++i)
	{
		Rmax=a[1].x;
		Bmax=max(a[n].x,max(T.Querymx(1,1,n-1,1,i),a[i+1].x));
		Bmin=min(a[n].x,min(T.Querymn(1,1,n-1,1,i),i==n-1?inf:a[n-1].x));
		ans=min(ans,1ll*(Rmax-Rmin)*(Bmax-Bmin));
	}
	for(int i=1;i<n;++i)
	{
		Bmax=max(a[n].x,a[1].x);
		Rmax=max(T.Querymx(1,1,n-1,1,i),i==n-1?0:max(T.Querymx(1,1,n-1,i+1,n-1),a[i+1].x));
		Bmin=min(a[n].x,min(i==n-1?inf:a[i+1].y,i==n-2?inf:a[n-1].x));
		ans=min(ans,1ll*(Rmax-Rmin)*(Bmax-Bmin));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 8832
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, W = map(int, input().split())
    vw = [list(map(int, input().split())) for _ in range(N)]

    # i個目まで使って重さj以下の場合の最大価値
    dp = [[0]*(W+1) for _ in range(N+1)]

    for i in range(1, N+1):
        for j in range(0, W+1):
            v_i = vw[i-1][0]
            w_i = vw[i-1][1]
            if w_i<=j:
                dp[i][j] = max(dp[i-1][j-w_i]+v_i, dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]

    print(dp[N][W])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 41888
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int k, q;
	cin >> k >> q;
	vl d(k);
	vl n(q);
	vl x(q);
	vl m(q);
	rep(i, k)
		cin >> d[i];
	rep(i, q)
		cin >> n[i] >> x[i] >> m[i];

	rep(i, q) {
		ll ans = n[i] - 1;
		ll incnum = 0;
		rep(j, k) {
			incnum += ((d[j] + m[i] - 1) % m[i] + 1) * ((n[i] - 1 + k - j - 1) / k);
		}
		ll endnum = x[i] % m[i];
		endnum += incnum;
		ans -= endnum / m[i];

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

Measured memory_bytes: 512
import sys

icase=0
if icase==0:
    n,m=map(int,input().split())
    ab=[[] for i in range(m)]
    for i in range(n):
        ai,bi=map(int,input().split())
        if m-ai>=0:
            ab[m-ai].append(-bi)
elif icase==1:
    n,m=3,4
    ab=[[-3, -1], [], [-2], []]    
elif icase==2:
    n,m=5,3
    ab=[[], [-1, -3], [-2, -3, -4]]
elif icase==3:
    n,m=1,1
    ab=[[]]

from heapq import heappop,heappush

if len(ab)==0:
    print(0)
    sys.exit()

n=len(ab)
h=[]
asum=0
for i in range(m-1,-1,-1):
    if len(ab[i])>0:
        for abi in ab[i]:
            heappush(h,abi)
#    print(i,h,asum)
    if len(h)>0:
        asum+=heappop(h)

print(-asum)
    


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

int h[200000];
long long a[200000];
long long dp[200000];

struct segtree{

  int n=1;
  std::vector<long long> v;

  segtree(int n_){
    while(n<n_)n*=2;
    v.assign(2*n-1, 0);
  }

  void set(int k,long long val){
    k+=n-1;
    v[k]=val;
    while(k>0){
      k=(k-1)/2;
      v[k]=std::max(v[2*k+1],v[2*k+2]);
    }
  }

  void update(int k,long long val){
    k+=n-1;
    v[k]=std::max(v[k],val);
    while(k>0){
      k=(k-1)/2;
      v[k]=std::max(v[2*k+1],v[2*k+2]);
    }
  }

  long long query(int a,int b){
    return query(0,n,a,b,0);
  }

  long long query(int l,int r,int a,int b ,int k){
    if(b<=l||r<=a){
      return 0;
    }else if(a<=l&&r<=b){
      return v[k];
    }else{
      return std::max(query(l,(l+r)/2,a,b,2*k+1),query((l+r)/2,r,a,b,2*k+2));
    }
  }

};

int main(){
  int n;
  std::cin>>n;
  for(int i=0;i<n;++i){
    std::cin>>h[i];
  }
  for(int i=0;i<n;++i){
    std::cin>>a[i];
  }
  segtree seg(200001);
  for(int i=0;i<n;++i){
    long long val=a[i]+seg.query(0,h[i]);
    seg.update(h[i],val);
  }
  std::cout<<seg.query(0,200001)<<std::endl;
  return 0;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

ll n, k;

void solve() {
	ll ans = 0;
	for (ll b = 1; b <= n; b++) {
		ans += n / b * max(0LL, b - k);
		ans += max(0LL, n % b + 1 - k);
	}

	if (k == 0) ans -= n;

	printf("%lld\n", ans);
}

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

	solve();
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
 
int main(){
	ll N ,M;
	scanf("%lld %lld",&N,&M);
	if(N>2&&M>2){
		ll h = N*M-(N-2)*(M-2);
		printf("%lld",N*M-h);
	}
	if((N==1||M==1)&&(N!=1||M!=1)){
		printf("%lld",max(N,M)-2);
	}
	if(N==1&&M==1){
		printf("%d",1);
	}
	if((N==2||M==2)){
		printf("%d",0);
	}
	
	return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e4+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
int x[5];
int y[5];
int main()
{
    while(~scanf("%d%d%d%d",&x[1],&y[1],&x[2],&y[2]))
    {
        int dx=x[2]-x[1];int dy=y[2]-y[1];
        x[3]=x[2]-dy;y[3]=y[2]+dx;
        x[4]=x[3]-dx;y[4]=y[3]-dy;
        printf("%d %d %d %d\n",x[3],y[3],x[4],y[4]);
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

unsigned long gcd(unsigned long a, unsigned long b) {
  unsigned long tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  unsigned long c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}

int main(void) {
  unsigned long n;
  cin >> n;
  unsigned long a, c;
  for (int i; i < n; i++) {
    if (i == 0) cin >> c;
    else {
      cin >> a;
      c = gcd(a, c);
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int A[N][N], color[N];
int d[N], Q[N+1];
int n, q1 = 0, q2 = 0;

void bfs(void);

int main() {
  int u, v, k, i, j;

  scanf("%d", &n);
  for(i = 1; i <= n; i++) {
    Q[i] = -1;
    for(j = 1; j <= n; j++) {
      A[i][j] = 0;
    }
  }
  Q[n+1] = -1;

  for(i = 1; i <= n; i++) {
    scanf("%d", &u);
    scanf("%d", &k);
    for(j = 1; j <= k; j++) {
      scanf("%d", &v);
      A[u][v] = 1;
    }
  }

  bfs();

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

  return 0;
}


void bfs() {
  int i, u;
  for(i = 1; i <= n; i++) {
    color[i] = WHITE;
    d[i] = -1;
  }
  color[1] = GRAY;
  d[1] = 0;
  Q[q1] = 1;
  q1++;
  while(q1 != q2) {
    u = Q[q2];
    q2++;
    for(i = 1; i<= n; i++) {
      if(A[u][i] == 1) {
        if(color[i] == WHITE) {
          color[i] = GRAY;
          d[i] = d[u] + 1;
          Q[q1] = i;
          q1++;
        }
      }
    }
    color[u] = BLACK;
  }
}

Measured memory_bytes: 636
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = 2;
			int n = sc.nextInt();
				for(int i=1; i<n; i++){
					a = a +  i + 1;
				}
				
				System.out.println(a);
		}

	}

}

Measured memory_bytes: 12000
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////



///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    double n;
    cin >> n;
    double objetosc = 0;
	double x;
	
	n /= 3;
	x = n;
	objetosc = x * x * x;
	
	cout << setprecision(12) << fixed << objetosc << '\n';
    
	
	return 0;
}


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

int main() {
    long long N;
    cin >> N;
    bool find  = false; 
    for ( ; N > 0; ) {
        long long Remainder = N % 10;
        long long Quit = N / 10;
        if (Remainder == 7) {
            find = true;
        }
        N = Quit;
    }
    if (find == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
while True:
    n=int(input())
    if n==0:
        break
    
    a=list(map(int,input().split()))
    
    ave=sum(a)/n
    
    k=0
    m=0
    for i in range(n):
        k=(a[i]-ave)**2
        m+=k
    
    s=(m/n)**(1/2)
    print('{:.8f}'.format(s))
        


Measured memory_bytes: 5672
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long n, d[100000], i, ans;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d, d+n);
    ans=d[n/2]-d[(n/2)-1];
    cout << ans <<endl;

    return 0;
}
    


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pre[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    while(cin>>n)
    {
        pre[0]=0;
        ll sum=0;
        for(int i=0;i<n;i++)
        {
            ll x;
            cin>>x;
            sum +=x;
            pre[i+1]=pre[i]+x;
        }
        ll ans=1e18;
        for(int i=1;i<n;i++)
        {
            ll dif=sum-pre[i];
            ll x=pre[i];
            ans=min(ans,abs(x-dif));
        }
        cout<<ans<<endl;

    }
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> koma(N);
	for (int i = 0; i < N; i++)
		cin >> koma[i];
	int M;
	cin >> M;

	int num = 0;
	for(int i = 0; i < M; i++) {
		cin >> num;
		if(num<N) {
			if(koma[num-1] < 2019 && koma[num-1]+1 < koma[num])
				koma[num-1]++;
		} else {
			if(koma[num-1] < 2019)
				koma[num-1]++;
		}
	}

	for(int i = 0; i < N; i++)
		cout << koma[i] << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i <int(n);++i)
#define forsn(i,s,n) for(int i=s;i <int(n);++i)
struct vec {
	double x, y;
	double operator ^ (vec const& o) const {
		return x*o.y - y*o.x;
	}
	double operator * (vec const& o) const {
		return x*o.x + y*o.y;
	}
	vec operator * (double o) const {
		return {x*o , y*o};
	}
	vec operator - (vec const& o) const {
		vec res = *this;
		res.x -= o.x; res.y -= o.y;
		return res;
	}
	vec operator + (vec const& o) const {
		vec res = *this;
		res.x += o.x; res.y += o.y;
		return res;
	}
	double n2 () const {
		return *this * *this;
	}
	double n1 () const {
		return sqrt(n2());
	}
};
using ll = long long;

vec intersect(vec p1, vec q1, vec p2, vec q2){
	vec d1 = q1-p1;
	vec d2 = q2-p2;;
	double alpha = ((d2^p2)-(d2^p1))/(d2^d1);
	return p1+d1*alpha;
}

int main () {
	int n;
	cin >> n;
	vector<vec> ps(n);
	forn(i,n) cin >> ps[i].x >> ps[i].y;
	ps.push_back(ps[0]);
	int q;
	cin >> q;
	forn(i,q){
		vec p1, p2;
		cin >> p1.x >> p1.y >> p2.x >> p2.y;

		auto side = [&](vec p)->int{
			double res = (p2-p1)^(p-p1);
			return (res < 0) ? -1 : (res > 0 ? 1 : 0);
		};

		vector<vec> chiquito;
		forn(i,n){
			int s = side(ps[i]);

			if(s == 1 && side(ps[(i+n-1)%n]) == -1)
				chiquito.push_back(intersect(p1,p2, ps[i],ps[(i+n-1)%n]));

			if(s >= 0) chiquito.push_back(ps[i]);

			if(s == 1 && side(ps[(i+n+1)%n]) == -1)
				chiquito.push_back(intersect(p1,p2, ps[i],ps[(i+n+1)%n]));
		}

		double res = 0;
		// cerr << "<@@\n";
		forn(i,chiquito.size()){
			// cerr << chiquito[i].x << ' ' << chiquito[i].y << '\n';
			res += (chiquito[i]^chiquito[(i+1)%chiquito.size()])/2;
		}
		// cerr << "@@>\n";
		printf("%.9f\n",res);
	}
}


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

int main(){
  int n,m;
  cin >> n >> m;
  if(n==m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
import Numeric
import Control.Applicative

func :: Int -> String -> Int -> Int
func a op b | op == "+" = a + b
			| op == "-" = a - b
			| op == "*" = a * b
			| op == "/" = a `div` b
			| otherwise = 0

main = do
{
	exprs <- map words . init . fst . (break (=="")) . lines <$> getContents;
	let {
        ans = [ (func ((read::String->Int) (x!!0)) (x!!1) ((read::String->Int) (x!!2))) | x<-exprs ];
    };
    mapM_ putStrLn $ (map show) ans;
}

Measured memory_bytes: 4056
import math
N = int(input())
p = []
for n in range(0,N):
  x,y = map(int, input().split(" "))
  p.append((x,y))

sum = 0
for i in range(0,N):
  for j in range(0,N):
    #print(math.sqrt( (p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2 ))
    sum += math.sqrt( (p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2 )
print(sum/N)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CSubarraySum {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, K, S;
        const int MX = ten(9);
        in>>N>>K>>S;
        REP(i, K) out<<S<<' ';
        REP(i, N-K){
            if(S==MX) out<<1<<' ';
            else out<<MX<<' ';
        }
        out<<'\n';
    }
};


int main() {
	CSubarraySum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

#define nmax 100010

int n, W;
int w[nmax], v[nmax];

ll dp[nmax];

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

    for (int i = 1; i <= n; i++) scanf("%d %d", &w[i], &v[i]);

    for (int i = 1; i <= W; i++) dp[i] = -1;

    dp[0] = 0;

    for (int i = 1; i <= n; i++) {

        for (int j = W - w[i]; j >= 0; j--)
            if (dp[j] != -1) dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
    }

    ll answer = 0;

    for (int i = 0; i <= W; i++) answer = max(answer, dp[i]);

    printf("%lld", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

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

using namespace std;

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

    int ans = 1;
    for (int a = 1; a * a < m; a++) {
        if (m % a != 0) {
            continue;
        }

        int b = m / a;

        if (m >= (long)a * n) {
            ans = max(ans, a);
        }
        if (m >= (long)b * n) {
            ans = max(ans, b);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include<iostream>
#include<map>
#include<algorithm>

using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int c[26];
	for (int i = 0; i < 26; i++) { c[i] = 1; }

	for (int i = 0; i < n; i++) {
		c[s[i] - 'a'] += 1;
	}

	long long int ans = 1;

	for (int i = 0; i < 26; i++) {
		ans = ans*c[i]%1000000007;
	}

	cout << (ans - 1) % 1000000007 << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,ans=INT_MAX,x[101];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	for(int i=1;i<=100;i++)
	{
		int tmp=0;
		for(int j=1;j<=n;j++)
		{
			tmp+=pow(x[j]-i,2);
		}
		ans=min(ans,tmp);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

char int_to_alph(int n) {
    if (n == 1) return 'A';
    else if (n == 2) return 'B';
    else if (n == 3) return 'C';
    else if (n == 4) return 'D';
    else if (n == 5) return 'E';
    else if (n == 6) return 'F';
    else if (n == 7) return 'G';
    else if (n == 8) return 'H';
    else if (n == 9) return 'I';
    else if (n == 10) return 'J';
    else if (n == 11) return 'K';
    else if (n == 12) return 'L';
    else if (n == 13) return 'M';
    else if (n == 14) return 'N';
    else if (n == 15) return 'O';
    else if (n == 16) return 'P';
    else if (n == 17) return 'Q';
    else if (n == 18) return 'R';
    else if (n == 19) return 'S';
    else if (n == 20) return 'T';
    else if (n == 21) return 'U';
    else if (n == 22) return 'V';
    else if (n == 23) return 'W';
    else if (n == 24) return 'X';
    else if (n == 25) return 'Y';
    else if (n == 0) return 'Z';
    else return '#';
}

int alph_to_int(char c) {
    if (c == 'A') return 1;
    else if (c == 'B') return 2;
    else if (c == 'C') return 3;
    else if (c == 'D') return 4;
    else if (c == 'E') return 5;
    else if (c == 'F') return 6;
    else if (c == 'G') return 7;
    else if (c == 'H') return 8;
    else if (c == 'I') return 9;
    else if (c == 'J') return 10;
    else if (c == 'K') return 11;
    else if (c == 'L') return 12;
    else if (c == 'M') return 13;
    else if (c == 'N') return 14;
    else if (c == 'O') return 15;
    else if (c == 'P') return 16;
    else if (c == 'Q') return 17;
    else if (c == 'R') return 18;
    else if (c == 'S') return 19;
    else if (c == 'T') return 20;
    else if (c == 'U') return 21;
    else if (c == 'V') return 22;
    else if (c == 'W') return 23;
    else if (c == 'X') return 24;
    else if (c == 'Y') return 25;
    else if (c == 'Z') return 0;
    else return -1;
}

int main(){ 
    int N;
    cin >> N;
    string S;
    cin >> S;
    string ans = "";
    rep(i,S.size()) {
        ans += int_to_alph((alph_to_int(S[i]) + N) % 26);
    }

    cout << ans << endl;
}




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

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

void solve() {
	int n, m;
	cin >> n >> m;
	map <int, vector <int>> work;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		work[a].eb(b);
	}
	multiset <int> S;
	LL ans = 0;
	for (int day = m; day >= 1; --day) {
		int a = m - day + 1;
		for (auto &b : work[a]) {
			S.emplace(b);
		}
		if (!S.empty()) {
			auto it = S.end();
			--it;
			ans += 1LL * (*it);
			S.erase(it);
		}
	}
	cout << ans << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 13172
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    string a;
    cin >> a;
    vec(b,26);
    int c = a.size();
    int ans=0;
    REP(i,c){
        int t = a[i] - 'a';
        b[t]++;
        if(b[t]==2){
            ans=1;
            break;
        }
    }
    (ans == 0)? cout << "yes" << endl : cout << "no" << endl;

    return 0;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,k;cin>>n>>k&&n|k;){
		int res=1;
		rep(i,n) res=min(2*res,res+k);
		cout<<res<<endl;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void){

  char a[102], b[102];
  scanf("%s %s", a, b);
  int a_length = strlen(a);
  int b_length = strlen(b);
  if (a_length > b_length) {
    printf("GREATER\n");
  } else if (b_length > a_length) {
    printf("LESS\n");
  } else {
    if (strcmp(a,b) > 0) {
      printf("GREATER\n");
    } else if (strcmp(a,b) < 0) {
      printf("LESS\n");
    } else {
      printf("EQUAL\n");
    }
  }

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
long long int min(long long int a,long long int b){
  if(a>b) return b;
  return a;
}
int main(void){
  int n,i;
  long long int ans=0;
  scanf("%d",&n);
  int a[n+1],b[n];
  for(i=0;i<n+1;i++) scanf("%d",&a[i]);
  for(i=0;i<n;i++) scanf("%d",&b[i]);
  for(i=0;i<n;i++){
    if((a[i]+a[i+1])<=b[i]){
      ans += a[i]+a[i+1];
      a[i+1] = 0;
    }else{
      ans += b[i];
      if(a[i]<b[i]){
        a[i+1] = a[i+1] - (b[i]-a[i]);
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        //コード
      Scanner sc = new Scanner(System.in);
	  String n = sc.next();
      switch (n) {
        case "Sunny":
            System.out.println("Cloudy");
            break;
        case "Cloudy":
            System.out.println("Rainy");
            break;
        case "Rainy":
            System.out.println("Sunny");
            break;
      }
    }
}

Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  
  int old;
  int h;
  cin >> h;
  old = h;
  int out =0;
  for(int i=1;i<N;i++){
    cin >> h;
    if(h-old<=-1){
      out=out+(h-old);
    }else if(h-old>0){
      out=0;
    }
    if(out<-1){
      cout << "No" << endl;
      return 0;
    }
    old=h;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

k = int(input())

q =deque([1,2,3,4,5,6,7,8,9])

num = 0

while True:
    x = q.popleft()
    num += 1
    if num == k:
        break
    y = x % 10
    if y != 0:
        q.append(10*x+y-1)
    q.append(10*x+y)
    if y != 9:
        q.append(10*x+y+1)

print(x)


Measured memory_bytes: 40816
import Control.Applicative 
import Data.Char
import Debug.Trace
import Data.List

splitInt :: String -> [Integer]
splitInt "" = [] :: [Integer]
splitInt str =
    let charToInt :: Integer -> Char -> Integer
        charToInt d c = d * 10 + (fromIntegral $ digitToInt c) :: Integer
        checkInt :: Integer -> String -> (Integer, String)
        checkInt d "" = (d, "")
        checkInt d (' ':rest) = (d, rest)
        checkInt d (c:rest) = checkInt (charToInt d c)  rest
        (num, rest) = checkInt 0 str
        in num : splitInt rest

separate :: [Integer] -> (Integer, Integer)
separate [] = (0, 0)
separate [x] = (x, 0)
separate (x:y:rest) = 
    let (a, b) = separate rest
        in (a + x, b + y)

minus :: (Integer, Integer) -> Integer
minus (a, b) = a - b
main = do
    getLine
    print =<< minus <$> separate <$> reverse <$> sort <$> splitInt <$> getLine


Measured memory_bytes: 508