akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> dp(n);
    F0R(i,n) cin >> arr[i];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    FOR(i,2,n)
        dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i <= n; i++)
#define REP2(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long LL;
typedef long long int LLI;

int solve(int a,int b);

int x,y,n,ans,c,d;
int road[20][20];
int memo[20][20];
int dx[2] = {0,1};
int dy[2] = {1,0};

int main()
{
    int i;
    
    while(cin >> x >> y, x||y){
        ans = 0;
    
        
        REP(i,1,y){
            REP(j,1,x){
                road[i][j]=true;
            }
        }
        
        cin >> n;
    
        REP2(i,0,n){
            
            cin >> c >> d;
            
            road[d][c] = false;
            if(c==0 && d==0)break;

        }
        
        solve(1,1);
    
        cout << ans << endl;
        
    }
    
    return 0;
}

int solve(int a,int b)
{
    if(x == a && y == b)ans++;
    
    for(int i=0; i < 2; i++){
        
        int tempa = a + dx[i];
        int tempb = b + dy[i];
        
        if(tempa <= x && tempb <= y && road[tempb][tempa] == true )
            solve(tempa, tempb);
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    int x;
    scanf("%d",&x);
    if (x < 30) {
        printf("No");
    } else {
        printf("Yes");
    }
    return 0;
}

Measured memory_bytes: 1732
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

# 1:先手　-1:後手
memo = [0]*(k+1)
def dp(x):
    if memo[x] != 0:
        return memo[x]
    for i in a:
        if x < i: break
        else:
            if dp(x-i) == -1:
                memo[x] = 1
                return 1
    memo[x] = -1
    return -1

if dp(k)==1:
    print("First")
else:
    print("Second")






    




Measured memory_bytes: 95220
from collections import deque

def main():
  def p(a,b):
    if a < b:
      return (a,b)
    else:
      return (b,a)
  input = open(0).readline
  N = int(input())
  E = [[] for i in range(N)]
  C = {}
  D = [0] * N
  parent = [0]*N
  for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)
    C[(a,b)] = c
    C[(b,a)] = c

  M, K = map(int, input().split())
  K -= 1
  parent[K] = K
  Q = deque()
  Q.append(K)

  while Q:
    u = Q.popleft()
    d = D[u]
    for v in E[u]:
      if parent[u] == v:
        continue
      parent[v] = u
      D[v] = d + C[(u,v)]
      Q.append(v)

  for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(D[x]+D[y])

main()
  
 

Measured memory_bytes: 56820
# 参考: White_Pie_46
# https://atcoder.jp/contests/abc176/submissions/16168825
from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [list(input()) for _ in range(height)]

    adjacents = (
        (1, 0),
        (0, 1),
        (-1, 0),
        (0, -1)
    )

    def gen_warp_can_reach():
        for h in range(-2, 3):
            for w in range(-2, 3):
                if h == 0 == w:
                    continue
                if (h, w) in adjacents:
                    continue
                yield (h, w)
    warp_can_reach = tuple(gen_warp_can_reach())
    qu = deque()
    qu.append((init_h, init_w, 0))  # 座標とワープ回数を保持
    reached = set()

    while qu:
        h, w, warps = qu.popleft()
        if h == dest_h and w == dest_w:
            return warps
        if (h, w) in reached:
            # 同じマスを複数回キューに追加しているかもしれない。
            # 短距離で調査済みなら再調査は不要。
            continue
        reached.add((h, w))

        for h_delta, w_delta in adjacents:
            new_h, new_w = h + h_delta, w + w_delta
            if 0 <= new_h < height and 0 <= new_w < width:
                if grid[new_h][new_w] == '.':
                    qu.appendleft((new_h, new_w, warps))

        for h_delta, w_delta in warp_can_reach:
            new_h, new_w = h + h_delta, w + w_delta
            if 0 <= new_h < height and 0 <= new_w < width:
                if grid[new_h][new_w] == '.':
                    qu.append((new_h, new_w, warps + 1))
    return -1


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 312864
import sys
A,B,C,D = map(int,input().split())
if A < 0 or B < 0 or B <= A or A > 100 or B > 100:
    sys.exit()
if C < 0 or D < 0 or D <= C or C > 100 or D > 100:
    sys.exit()

count = 0
for I in range(A,B):
    for J in range(C,D):
        if I == J:
            count += 1
print(count)

Measured memory_bytes: 9192
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  println(
    readLine.trim.toInt match {
      case 22 ⇒ "Christmas Eve Eve Eve"
      case 23 ⇒ "Christmas Eve Eve"
      case 24 ⇒ "Christmas Eve"
      case 25 ⇒ "Christmas"
      case _ ⇒ ???
    }
  )
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

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

void printAll(std::vector<int> A) {
    for (int i = 0; i < (A.size()-1); i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A.back() << std::endl;
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    int count = 0;
    for (int i = 0; i < A.size(); i++) {
        for (int j = A.size() - 1; j > i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                count++;
            }
        }
    }

    printAll(A);
    std::cout << count << std::endl;
}


Measured memory_bytes: 3156
#include <iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
    int n, m, sum = 0, ans = 0;cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    for (;;) {
        rep(i, n) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
            }
            else {
                cout << sum << endl;
                return 0;
            }
        }
        sum++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <functional>
#include <random>
using namespace std;
#define Would
#define you

const int MOD = 1e9 + 7;
const int INF = 999999999;

int a, b;
string s, h;

long long  gcd(long long  aa, long long  bb) {
	if (bb == 0) return aa;
	return gcd(bb, aa%bb);
}

long long lcm(long long aa, long long bb) {
	long long  g = gcd(aa, bb);
	return aa / g * bb;
}

int main() {
	cin >> a >> b >> s >> h;
	long long mon = lcm(a, b);
	for (int i = 0; i < gcd(a, b); ++i) {
		if (s[i*a / gcd(a, b)] != h[i*b / gcd(a, b)]) { mon = -1; }
	}
	cout << mon << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
typedef int ll;
using namespace std;

ll W, H, countinit=0, color[52][52]={{0}};
char M[52][52];

ll bfs(){
    queue<pair<ll, ll> > Q;
    queue<ll> QC;
    color[1][1]=1;
    Q.push(make_pair(1, 1));
    QC.push(0);
    ll A = -1;
    while(!Q.empty()){
        pair<ll, ll> u = Q.front();
        ll uc = QC.front();
        //cout << u.first << " " << u.second << " " << uc << endl;
        Q.pop();
        QC.pop();
        if(u.first==W&&u.second==H) {
            A = uc;
            break;
        }
        if(M[u.first+1][u.second]=='.'&&!color[u.first+1][u.second]){
            color[u.first+1][u.second]=1;
            Q.push(make_pair(u.first+1, u.second));
            QC.push(uc+1);
        }
        if(M[u.first-1][u.second]=='.'&&!color[u.first-1][u.second]){
            color[u.first-1][u.second]=1;
            Q.push(make_pair(u.first-1, u.second));
            QC.push(uc+1);
        }
        if(M[u.first][u.second+1]=='.'&&!color[u.first][u.second+1]){
            color[u.first][u.second+1]=1;
            Q.push(make_pair(u.first, u.second+1));
            QC.push(uc+1);
        }
        if(M[u.first][u.second-1]=='.'&&!color[u.first][u.second-1]){
            color[u.first][u.second-1]=1;
            Q.push(make_pair(u.first, u.second-1));
            QC.push(uc+1);
        }
    }
    return A;
}

signed main(){
    cin >> H >> W;
    for(ll i=0;i<52;i++){
        for(ll j=0;j<52;j++) M[j][i] = '#';
    }
    for(ll i=1;i<=H;i++){
        for(ll j=1;j<=W;j++) {
            cin >> M[j][i];
            if(M[j][i]=='#') countinit++;
        }
    }
    
    ll ans = bfs();
    //cout << countinit << endl;
    //cout << ans << endl;
    if(ans==-1) cout << -1 << endl;
    else cout << W*H-ans-1-countinit << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,m,a[1010],b[1010];
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	sort(a,a+n);
	sort(b,b+m);
	if(unique(a,a+n)!=a+n||unique(b,b+m)!=b+m){
		cout<<0<<endl;
		return 0;
	}
	int ans=1;
	for(int i=n*m;i>=1;i--){
		if(!binary_search(a,a+n,i)||!binary_search(b,b+m,i)){
			if(binary_search(a,a+n,i)){
				ans*=b+m-lower_bound(b,b+m,i);
			}
			else if(binary_search(b,b+m,i)){
				ans*=a+n-lower_bound(a,a+n,i);
			}
			else{
				ans*=(b+m-lower_bound(b,b+m,i))*(a+n-lower_bound(a,a+n,i))-(n*m-i);
			}
		}
		ans%=moder;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int casecheck(char letter){
    if(letter-'a'>=0&&letter-'a'<26){
        return 1;
    }
    else return 0;
}
int main(){
    string S,T;
    cin>>S>>T;
    int flag=1;
    if(S.length()+1!=T.length())
    {
        cout<<"No";
        return 0;
    }
    if(S.length()>10||S.length()<1){
        cout<<"No";
        return 0;
    }
    int j;
    for( j=0;j<S.length();j++){
        if(!casecheck(S[j])){
         cout<<"No";
            return 0;   
        }
         if(!casecheck(T[j])){
         cout<<"No";
            return 0;   
        }
        if(S[j]!=T[j]){
            cout<<"No";
            return 0;
        
    }
     if(!casecheck(T[j])){
         cout<<"No";
            return 0;   
        }
    

}

    cout<<"Yes";
}

Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<functional>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int>length;
	
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		length.push_back(l);
	}
	sort(length.begin(),length.end(),greater<int>());

	int ans = 0;
	for (int i = 0; i < k;i++) {
		ans += length[i];
	}
	cout << ans << endl;
	return 0;
}

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

// [0, i), time, last_ordered
lint dp[3001][6001][2];

void chmax(lint& a, lint b) {
    a = max(a, b);
}

int main() {
    lint n, tmax;
    cin >> n >> tmax;

    vector<lint> a(n), b(n);
    for(lint i=0; i<n; i++)  cin >> a[i] >> b[i];

    for(lint i=0; i<n; i++)
    for(lint t=0; t<=tmax; t++) {
        // 食べる
        chmax(dp[i+1][t+a[i]][0], dp[i][t][0] + b[i]);
        chmax(dp[i+1][t+a[i]][1], dp[i][t][1] + b[i]);
        chmax(dp[i+1][t][1], dp[i][t][0] + b[i]);

        // 食べない
        chmax(dp[i+1][t][0], dp[i][t][0]);
        chmax(dp[i+1][t][1], dp[i][t][1]);
    }

    lint ans = 0;
    for(lint t=0; t<tmax; t++) {
        chmax(ans, dp[n][t][0]);
        chmax(ans, dp[n][t][1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 281600
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#define Pll make_pair
using namespace std;
typedef long long ll;
const int MAXN=2e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int phi=1e9+6;
int a[MAXN];
int main()
{
    int n;
    cin>>n;
    map<int,int>p;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        p[a[i]]++;
    }
    int f=1;
    for(int i=1;i<=n;i++)if(p[a[i]]>=2){
        f=0;
            break;
    }
    if(f)printf("YES\n");
    else printf("NO\n");
    return 0;
}
/*

 */

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
int graph[51][51];
int subgraph[51][51];
int used[51];
void tansaku(int startx){
  for(int i=0;i<51;i++){
    if(subgraph[startx][i]==1){
      subgraph[startx][i]=0;
      subgraph[i][startx]=0;
      used[i]=0;
      tansaku(i);
    }
  }



}
std::vector<long> enum_div(long n)//nの約数を列挙
{
	std::vector<long> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}







int main() {
  long N,M;
  cin>>N>>M;
  std::vector<long> r = enum_div(M);
  long l=r.size();
  long max=0;
  for(long i=0;i<l;i++){
    if(r.at(i)>max){
      if(r.at(i)*N<=M){
        max=r.at(i);
      }
    }
    
  }
  if(N==1){
    cout<<M<<endl;
  }else{
  cout<<max<<endl;}



  
  
}

  

  






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

int main(){
  ll N;
  cin >> N;
  
  ll combo = 0;
  for (int i = 0; i < N; i++){
    ll a, b;
    cin >> a >> b;
    if (a == b){
      combo++;
    }
    else{
      combo = 0;
    }
    
    if (combo == 3){
      cout << "Yes" << endl;
      exit(0);
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  string tmp;
  bool can = false;
  for(int i=0;i<S.size();++i){
    for(int j=i;j<S.size();++j){
      tmp = "";
      for(int k=0;k<i;++k){
        tmp += S[k];
      }
      for(int k=j;k<S.size();++k){
        tmp += S[k];
      }
      if(tmp=="keyence") can = true;
    }
  }
  if(can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



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

int main()
{
        long long N;
        long long sum = 0;
        cin >> N;

        for(long long i = 1; i <= N; ++i)
        {
                if(i % 3 == 0 || i % 5 == 0) continue;

                sum += i;
        }

        cout << sum << endl;

        return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Forest_Uni {
	vector<UL> v;
	UL Sz;
	void init(UL n) {
		Sz = n;
		v.clear();
		rep(i, n) v.push_back(i);
	}
	void add() { v.push_back(v.size()); }
	UL root(UL p) {
		if (v[p] == p) return p;
		return v[p] = root(v[p]);
	}
	void unite(UL a, UL b) {
		UL A = root(a);
		UL B = root(b);
		if (A != B) {
			Sz--;
			v[A] = B;
		}
	}
};

struct Problem {

	void Solve(){
		UL N; cin >> N;
		vector<pair<UL, UL>> P(N);
		rep(i, N) cin >> P[i].first >> P[i].second;
		rep(i, N) { P[i].first--; P[i].second--; }
		Forest_Uni G;
		G.init(200000);
		rep(i, N) {
			G.unite(P[i].first, P[i].second + 100000);
		}
		vector<pair<ULL, ULL>> M(200000, { 0, 0 });
		rep(i, 100000) { M[G.root(i)].first++; }
		rep(i, 100000) { M[G.root(i + 100000)].second++; }
		ULL ans = 0;
		rep(i, M.size()) { ans += M[i].first * M[i].second; }
		ans -= N;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 5108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a <= c && c <= b){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}


	}

}

Measured memory_bytes: 22612
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 16:13:34 2017

@author: kotania
"""
 
from collections import Counter

N = int(input())
aList = input().split()

aList.sort()

countDict = Counter(aList)

delsum = 0    

for k,v in countDict.items():
    if int(k) < v:
        delsum += v - int(k)
    elif int(k) > v:
        delsum += v

print (delsum)

Measured memory_bytes: 20852
s = input()
x = int(s[0:2])
y = int(s[2:4])

flagx = flagy = 0
if 1 <= x <= 12:
  flagx = 1
if 1 <= y <= 12:
  flagy = 1
if flagx == 1 and flagy ==  1:
  print("AMBIGUOUS")
elif flagx == 1 and flagy == 0:
  print("MMYY")
elif flagx == 0 and flagy == 1:
  print("YYMM")
else:
  print("NA")

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

min_result = max(abs(x[0])*2, abs(x[-1])*2, abs(x[-1] - x[0])*2)

for i in range(0, len(x)-k+1):
    if x[i+k-1] <= 0:
        min_result = min(min_result, -x[i])
    elif x[i] < 0 and x[i+k-1] > 0:
        min_result = min(min_result, -x[i]*2+x[i+k-1], -x[i]+x[i+k-1]*2)
    else:
        min_result = min(min_result, x[i+k-1])

print(min_result)


Measured memory_bytes: 14660
#include <iostream>
using namespace std;
int main(){
    char c;
    cin>>c;
    switch(c){
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            cout<<"vowel";
            break;
        default :
            cout<<"consonant";

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long f(long long N, long long X){
	if (X == 0){
		return 0;
	} else if (N % X == 0){
		return N - X + (N / X * 2 - 3) * X;
	} else {
		return N - X + ((N - X) / X * 2 - 1) * X + f(N % X + X, N % X);
	}
}
int main(){
	long long N, X;
	cin >> N >> X;
	cout << X + f(N, X) << endl;
}

Measured memory_bytes: 3612
n=int(input())
f = [0]*10005

for x in range(1,101):
	for y in range(1,101):
		for z in range(1,101):
			c = x**2+y**2+z**2+x*y+y*z+z*x
			if c<=n: f[c]+=1
for i in range(1,n+1):
	print(f[i])


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

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

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

int prime[100010];
bool is_prime[100011];

void sieve(int n) {
	int p = 0;
	for(int i=0;i<=n;i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=n;i++) {
		if(is_prime[i]) {
			prime[p++] = i;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ;
}

/*ll partSum(ll l, ll r) {
	if(r < l) swap(l, r);
	if(l == 0) return s[r];
	return s[r] - s[l - 1];
}
*/

int q;
int a[100010], b[100010];

int main(void){
	sieve(100005);
	for(int i=1;i<100010;i++) if(is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
	for(int i=1;i<100010;i++) b[i] = b[i - 1] + a[i];

	cin>>q;
	for(int i=0;i<q;i++) {
		int l, r; cin>>l>>r;

		int ans = b[r] - b[l - 1];
		printf("%d\n", ans);
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

constexpr int INF=1e9;
int cnt[125252];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, a[125252];
	vi b;
	cin>>n;
	REP(i, n){
		cin>>a[i];
		b.push_back(a[i]);
	}
	sort(ALL(b));
	b.erase(unique(ALL(b)), b.end());
	REP(i, n){
		a[i]=lower_bound(ALL(b), a[i])-b.begin();
	}
	set<int> cnd;
	cnd.insert(a[n-1]);
	++cnt[a[n-1]];
	int ans=1;
	FORR(i, 0, n-1){
		auto itr=cnd.upper_bound(a[i]);
		//int tmp=itr-cnd.begin();
		if(itr==cnd.end()){
			++ans;
			cnd.insert(a[i]);
			++cnt[a[i]];
		}
		else{
			int num=cnt[*itr];
			if(num==1){
				--cnt[*itr];
				cnd.erase(*itr);
				cnd.insert(a[i]);
				++cnt[a[i]];
			}
			else{
				--cnt[*itr];
				cnd.insert(a[i]);
				++cnt[a[i]];
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

using namespace std;

int main() {
	int a, b; cin >> a >> b;
	
	if (a <= 0 && b >= 0) {
		puts("Zero");
	} else if (a > 0) {
		puts("Positive");	
	} else {
		int len = (b - a + 1);
		
		if (len % 2) puts("Negative");
		else puts("Positive");	
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=INF;
    for(ll i=0;i<=100000;i++){
        ans=min(ans,2*c*i+a*max(ll(0),(x-i))+b*max(ll(0),(y-i)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumDifference solver = new BMaximumDifference();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumDifference {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            out.println(a[n - 1] - a[0]);
        }

    }
}



Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int n;
void po(int *a){*a = (*a + n - 2) / n;}
int main(){
	int q; cin >> n >> q;
	for(int i = 0; i < q; ++i){
		int a, b; cin >> a >> b;
		if(n == 1){
			cout << min(a, b) << endl;
			continue;
		}
		while(a != b){
			if(a > b) po(&a);
			else po(&b);
		}
		cout << a << endl;
	}
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli data[2][100100];

signed main(){

	lli n;
	cin>>n;
	vector<lli> v(n);

	REP(i,0,n)cin>>v[i];

	vector<pair<lli,lli>> s[2];
	REP(i,0,n){
		data[i%2][v[i]]++;
	}

	REP(i,0,2)REP(j,0,100100)
	{
		s[i].push_back(make_pair(data[i][j],j));
	}

	sort(s[0].begin(),s[0].end(),greater<pair<lli,lli>>());
	sort(s[1].begin(),s[1].end(),greater<pair<lli,lli>>());

	if(s[0][0].second!=s[1][0].second){
		cout<<n-s[0][0].first-s[1][0].first<<endl;
	}
	else{
		cout<<min(n-s[0][0].first-s[1][1].first,n-s[0][1].first-s[1][0].first)<<endl;
	}

	return 0;
}

Measured memory_bytes: 7280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> s;
    vector<int> ord(n + 1, -1);
    int c = 1, l = 0;
    {
        int v = 1;
        while (ord[v] == -1)
        {
            ord[v] = s.size();
            s.push_back(v);
            v = a[v - 1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }
    if (k < l)
        cout << s[k] << endl;
    else
    {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 5704
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var X = input;
    var happy1 = 0;
    var happy2 = 0;
    var yen500 = X % 500;
    var yen5 = yen500 % 5;
    happy1 = (X - yen500) * 2;
    happy2 = yen500 - yen5;
    var happy = happy1 + happy2;
    console.log(happy);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;


int main() {
  unsigned long long co=0;
  int N;
  string S;
  //入力受付
  cin >> N;
  cin >> S;
  string str="";
  vector<int> n;
  int index =0;
  
  for(int i=0;i<N;i++){
    index=str.find(S[i]);
    if(index== string::npos){
      str +=S[i];
      n.push_back(2);
    }else{
      n[index]++;
    }
  }

  co = 1;
  for(int i=0; i<n.size();i++){
    co = (co * n[i])% 1000000007;
  }
  co--;  
  cout << co % 1000000007;

}


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

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

  	if(a==2 && b == 1){
    	cout << 3 << endl;	
    }else if(a == 1 && b== 2){
    	cout << 3 << endl;	
    }else if(a == 3 && b == 1){
    	cout << 2 << endl;	
    }else if(a == 3 && b== 2){
    	cout << 1 << endl;
    }else if(a == 1 && b == 3){
    	cout << 2 << endl;	
    }else{
    	cout << 1 << endl;
    }
	}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct edge {
	int from;
	int to;
	int cost;
};
typedef struct edge Edge;

int main(void) {
	int num, i, k, from, to, cost, update, ne = 0;
	int a[10000];
	Edge *edges, *p;

	edges = malloc(sizeof(Edge)*500000);

	scanf("%d", &num);

	for (i = 0; i < num; i++) {
		scanf("%d %d", &from, &k);

		while (k--) {
			scanf("%d %d", &to, &cost);

			p = &edges[ne++];
			p->from = from;
			p->to = to;
			p->cost = cost;
		}

		a[i] = INT_MAX;
	}
	a[0] = 0;

	update = 1;
	while (update) {
		update = 0;
		for (i = 0; i < ne; i++) {
			from = edges[i].from;
			to = edges[i].to;
			cost = edges[i].cost;
			if (a[from] < INT_MAX && a[to] > cost + a[from]) {
				a[to] = cost + a[from];
				update = 1;
			}
		}
	}

	for (i = 0; i < num; i++) {
		printf("%d %d\n", i, a[i]);
	}
	return 0;
}



Measured memory_bytes: 7636
h,w=map(int,input().split())
maze=['#'*(w+2)]
white=0
for i in range(h):
    r=input()
    maze.append('#'+r+'#')
    white+=r.count('.')
maze.append('#'*(w+2))
dxy=((1,0),(-1,0),(0,1),(0,-1))
dist=[[-1] *(w+2) for i in range(h+2)]
def bfs():
    queue=[]
    queue.insert(0,(1,1))
    dist[1][1]=0
    while len(queue):
        x,y=queue.pop()
        if x==w and y==h:
            break
        for (dx,dy) in dxy:
            nx, ny= x+dx, y+dy
            if maze[ny][nx]=='.' and dist[ny][nx]==-1:
                queue.insert(0,(nx,ny))
                dist[ny][nx]=dist[y][x]+1
    return dist

bfs()
if dist[h][w]==-1:
    print(-1)
else:
    print(white-dist[h][w]-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

int main() {
    int a, b, m;
    std::cin >> a >> b >> m;

    int min_a = 1e9, min_b = 1e9;
    std::vector<int> as(a), bs(b);
    for (int i = 0; i < a; i++) {
        std::cin >> as[i];
        min_a = std::min(min_a, as[i]);
    }
    for (int i = 0; i < b; i++) {
        std::cin >> bs[i];
        min_b = std::min(min_b, bs[i]);
    }

    int ans = min_a + min_b;
    for (int i = 0; i < m; i++) {
        int x, y, c;
        std::cin >> x >> y >> c;
        x--;
        y--;
        ans = std::min(ans, as[x] + bs[y] - c);
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;
typedef long long ll;

//#define DEBUG

int main()
{
//#ifdef DEBUG
  // freopen("in.txt", "r", stdin);
   //freopen("out.txt","w",stdout);
//#endif
   int n = 0;
   cin >> n;
   unordered_set<int> s;
   int count = 0;
   for (int i = 0; i < n; ++i) {
      int v = 0;
      cin >> v;
      if (s.find(v) != end(s)) ++count;
      else s.insert(v);
   }

   cout << n - count - (count % 2 == 0 ? 0 : 1) << endl;

   return 0;
}



Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;
ll fun(ll l,ll r){
    if(l>r)return 0;
    ll num;
    num=(r-l)/3+1;
    return num;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll n;cin>>n;
        ll arr[n],vis[1000005];for(ll i=0;i<1000005;i++)vis[i]=0;
        for(ll i=0;i<n;i++)cin>>arr[i],vis[arr[i]]++;ll sum=0,flg=0;
        
        for(ll i=0;i<n;i++){vis[arr[i]]--;flg=0;
            for(ll j=1;j*j<=arr[i];j++){
                if(flg)break;
                if(arr[i]%j==0){
                    if(vis[j]){
                    		// cout<<arr[i]<<" "<<j<<endl;
                        flg=1;
                        break;
                    }
                    if(vis[arr[i]/j]){
                    	
                        flg=1;
                        break;
                    }
                }
            }
            vis[arr[i]]++;
            if(flg)continue;
            sum++;
            	
            
        }
        cout<<sum;

}


Measured memory_bytes: 12980
using System;
using System.IO;
using System.Linq;

namespace AtCoder.R170.D
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            WriteAnswer(tw, Parse(tr));
        }

        private static void WriteAnswer(TextWriter tw, int answer)
        {
            tw.WriteLine(answer);
        }

        private static int Parse(TextReader tr)
        {
            var w = tr.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var a = tr.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            return Calc(a);
        }

        public static int Calc(int[] a)
        {
            Array.Sort(a);

            var isOk = new bool[a.Last() + 1];
            for (var i = 0; i < a.Length; ++i)
            {
                isOk[a[i]] = true;
            }

            for (var i = 0; i < a.Length; ++i)
            {
                if (!isOk[a[i]])
                    continue;

                if (i > 0 && a[i] == a[i - 1])
                {
                    isOk[a[i]] = false;
                    continue;
                }

                for (var j = a[i] * 2; j <= a.Last(); j += a[i])
                    isOk[j] = false;
            }

            return isOk.Count(x => x);
        }
    }
}


Measured memory_bytes: 44888
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=pow(fabs(a[i]-b[i]),2);
    o3+=pow(fabs(a[i]-b[i]),3);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}


Measured memory_bytes: 3408
// @skylag
//Practice -> Passion -> Patience -> 3 P's of my Life!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define SKY ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
int power(int a,int n,int mod)
{
    a=a%mod;
    
    int res=1;
    while(n)
    {
        if(n&1)
        {
            res=((res%mod)*(a%mod))%mod;
            n--;
        }
        else
        {
            a=((a%mod*(a%mod)))%mod;
            n/=2;
        }
    }
    return res;
}
void solve()
{
    int n;
    cin>>n;
    int n1=n%1000;
    if(n1!=0)
    cout<<1000-n1<<"\n";
    else cout<<0<<"\n";
}
int32_t main()
{
    SKY;
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}




Measured memory_bytes: 3512
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(void) {
    char s[200];
    scanf("%s", s);
    int len = strlen(s);
    char a[100];
    char b[100];
    int counter = 0;
    while (true) {
        counter += 2;
        strncpy(a,s,(len - counter)/2);
        a[(len - counter)/2] = '\0';
        strncpy(b,s+(len - counter)/2,(len - counter)/2);
        b[(len - counter)/2] = '\0';
        if (strcmp(a,b) == 0) {
            break;
        }
    }
    printf("%d\n", len - counter);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

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);
    }
}
#pragma endregion

#pragma region UnionFind
struct UnionFind
{
    vector<int> d;
    // d[x] is the index of the parent of x
    // d[x] is -size if x is a root

    UnionFind(int n) : d(vector<int>(n, -1)) {}
    int root(int x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (d[x] > d[y])
            swap(x, y); // x always bigger tree

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x) { return -d[root(x)]; }
};
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    using vp = vector<P>;
    vp e(m);
    rep(i, m)
    {
        cin >> e[i];
        e[i].first--;
        e[i].second--;
    }

    int ans = m;
    rep(i, m)
    {
        UnionFind uft(n);
        rep(j, m)
        {
            if (i == j)
                continue;
            uft.unite(e[j].first, e[j].second);
        }
        if (uft.size(0) == n)
            ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
S = list(input())
MOD = 10**9+7

if S[0] == 'B':
    Left = 1
    ans = 1
else:
    print(0)
    sys.exit()
    
flag = True
for i in range(1,2*N):
    if flag:
        if S[i-1] != S[i]:
            Left += 1
        else:
            flag = False
            ans *= Left
            ans %= MOD
            Left -= 1
    else:
        if S[i-1] != S[i]:
            ans *= Left
            ans %= MOD
            Left -= 1
        else:
            Left += 1
            flag = True
            
if Left != 0:
    print(0)
    sys.exit()
    
for i in range(1,N+1):
    ans *= i
    ans %= MOD

print(ans)
            
        





Measured memory_bytes: 4968
# coding=utf-8


N, M, X = map(int, input().split())
A_list = list(map(int, input().split()))

is_cost = []
for i in range(N+1):
    if i in A_list:
        is_cost.append(1)
    else:
        is_cost.append(0)

print(min(sum(is_cost[:X]), sum(is_cost[X+1:])))


Measured memory_bytes: 3064
n,k=map(int,input().split())
a=list(map(int,input().split()))

dic={}
kaisi=1
for i in range(1,n+1):
  if kaisi in dic:
    st=dic[kaisi]
    gl=i
    break
  else:
    dic[kaisi]=i
  kaisi=a[kaisi-1]

if k<st:
  kaisi=1
  for i in range(0,k):
    kaisi=a[kaisi-1]
  print(kaisi)
else:
  kaisuu=(k-st+1)%(gl-st)+st-1
  kaisi=1
  for i in range(0,kaisuu):
    kaisi=a[kaisi-1]
  print(kaisi)

Measured memory_bytes: 38880
#include "bits/stdc++.h"
using namespace std;

const long long INF = 1LL<<60;

int N, M;
vector<vector<int> > G;

// dp[v]:ノード v を始点としたときのGの有向パスの長さの最大値
int dp[100100];

int rec(int v) {
	if(dp[v] != -1) return dp[v];

	int res=0;
	for (auto nv : G[v]) {
		res = max(res, rec(nv)+1);
	}
	return dp[v] = res;
}

int main() {
	cin >> N >> M;
	G.assign(N, vector<int>());
	for (int i = 0; i < M; i++) {
		int x, y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}

	for(int v=0; v<N; v++) dp[v] = -1;

	int res=0;
	for(int v=0; v<N; v++) res = max(res, rec(v));
	cout << res << endl;
}

Measured memory_bytes: 8192
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader rd = new MyReader();  
        int N, K; {int[] a = rd.ii(); N = a[0]; K = a[1];}
        long[] A = rd.ll();
        long S = 0;
        for(long a : A)
            S += a;
       
        ArrayList<Long> list = new ArrayList<>();
        double root = Math.sqrt(S);
        for(long i = 1; i < root; i++){
            if(S%i == 0){
                int j = list.size()/2;
                list.add(j, i);
                list.add(j+1, S/i);
            }
        }
        if(root%1 == 0)
            list.add(list.size()/2, (long)root);
            
        for(int i = list.size()-1; i >= 0; i--){
            long d = list.get(i);
            long[] array = new long[N];
            int size = 0;
            for(int j = 0; j < N; j++){
                long r = A[j]%d;
                if(r > 0)
                    array[size++] = r;                  
            }
            Arrays.parallelSort(array, 0, size);
            long left = 0;
            long right = d*size;
            for(long r : array)
                right -= r;
            for(long r : array){
                if(left <= K && right <= K){
                    println(d);
                    return;
                } else{
                    left += r;
                    right -= d-r;
                }
            }
        }
        println(1);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 30376
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
#include<assert.h>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
int abs(int x)
{
	return x>0?x:-x;
}
const int N=100010;
int n;
int a[N],b[N];
ll gao()
{
	ll s=0;
	for(int i=1;i<n;i++)
		s+=abs(b[i]-b[i+1]);
	return s;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ll ans=0;
	if(n&1)
	{
		int t=0;
		for(int i=2;i<=n;i+=2)
			b[i]=a[++t];
		for(int i=1;i<=n;i+=2)
			b[i]=a[++t];
		swap(b[3],b[n]);
		ans=max(ans,gao());
		reverse(a+1,a+n+1);
		t=0;
		for(int i=2;i<=n;i+=2)
			b[i]=a[++t];
		for(int i=1;i<=n;i+=2)
			b[i]=a[++t];
		swap(b[3],b[n]);
		ans=max(ans,gao());
	}
	else
	{
		int t=0;
		for(int i=2;i<=n;i+=2)
			b[i]=a[++t];
		for(int i=1;i<=n;i+=2)
			b[i]=a[++t];
		ans=max(ans,gao());
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int a,b;
int main(){
	ios::sync_with_stdio(false);
	cin>>a>>b;
	cout<<a*b<<endl;
	return 0; 
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(void)
{
	int a, i, price=700;
	char topping;

	for(i=0; i<3; i++){
		scanf(" %c", &topping);
		if(topping=='o'){
			price += 100;
		}
	}
	printf("%d", price);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3010, M = 2e5+10;

int h, w;
int n;

struct pt {
  int x, y;
  bool operator<(const pt& o) const {
    return tie(x, y) < tie(o.x, o.y);
  }
};

pt ps[N];

ll fac[M], finv[M];
int dp[N];

void pre() {
  vector<ll> inv(M);
  inv[1] = 1;
  fac[0] = finv[0] = fac[1] = finv[1] = 1;
  for (int i = 2; i < M; i++) {
    inv[i] = (MOD - (ll) (MOD/i) * inv[MOD%i] % MOD) % MOD;
    fac[i] = fac[i-1] * i % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

inline ll binom(int n, int k) {
  return k < 0 || k > n ? 0 : fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  pre();
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> ps[i].x >> ps[i].y;
  }
  ps[n] = {h, w};
  n++;
  sort(ps, ps + n);
  for (int i = 0; i < n; i++) {
    int dx = ps[i].x - 1, dy = ps[i].y - 1;
    dp[i] = binom(dx + dy, dx);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      if (ps[j].y < ps[i].y) continue;
      int dx = ps[j].x - ps[i].x, dy = ps[j].y - ps[i].y;
      dp[j] = (dp[j] + MOD - dp[i] * binom(dx + dy, dx) % MOD) % MOD;
    }
  }
  cout << dp[n-1] << nl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    String X = "0x" + sc.next();
    String Y = "0x" + sc.next();

    int X16 = Integer.decode(X);
    int Y16 = Integer.decode(Y);

    if (X16 == Y16) {
      System.out.println("=");
    } else if (X16 < Y16) {
      System.out.println("<");
    } else {
      System.out.println(">");
    }

  }
}

Measured memory_bytes: 23124
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
  ll N, Y;
  cin >> N >> Y;
  int a1 = -1, a2 = -1, a3 = -1;
  for (int i=0; i<=N; i++){
    for (int j=0; j<=N; j++){
      if (i + j > N) continue;
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
        a1 = i;
        a2 = j;
        a3 = N - i - j;
      }
    }
  }
  
  cout << a1 << " " << a2 << " " << a3 << endl;
  return 0;
}

Measured memory_bytes: 256