akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    char x, y;
    cin >> x >> y;
    if(x<y)cout << "<" << endl;
    else if(x>y)cout << ">" << endl;
    else cout << "=" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, dist[50][50];

signed main() {
    cin >> N >> M;
    rep(i,0,N) rep(j,0,N) {
        if(i == j) dist[i][j] = 0;
        else dist[i][j] = INF;
    }

    rep(i,0,M) {
        int a, b, c, d;
        scanf("%lld,%lld,%lld,%lld", &a, &b, &c, &d);
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = d;
    }

    rep(k,0,N) rep(i,0,N) rep(j,0,N) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        // printf("dist[%lld][%lld] = %lld\n", i, j, dist[i][j]);
    }

    int s, g, V, P;
    scanf("%lld,%lld,%lld,%lld", &s, &g, &V, &P);
    s--; g--;
    int cost = dist[s][g] + dist[g][s];

    cout << V - P - cost << endl;
    return 0;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int A =nextInt();
		int B = nextInt();
		int T = nextInt();
		System.out.println(T/A*B);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main() {
  ll n;
  cin >>n;
  ll diff = n-1;
  ll N = sqrt(n);
  for(int i = 2; i<=N; i++){
    if(n%i==0){ 
      ll curDif = abs(i-2+n/i);
      if(curDif<diff) diff = curDif;
    }
  }
  cout << diff << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

int f[100][10], p[100][11];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++)
            scanf("%d", f[i] + j);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 11; j++)
            scanf("%d", p[i] + j);
    int m = -2000000000;
    for (int i = 1; i < 1024; i++) {
        int P = 0;
        for (int j = 0; j < n; j++) {
            int c = 0;
            for (int k = 0; k < 10; k++)
                c += (i & 1 << k) && f[j][k];
            P += p[j][c];
        }
        m = max(m, P);
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int get_leap_years(int* leap_years_list, int year_begin, int year_end);

bool is_leap_year(int y);

int main(void)
{
    int leap_years_list[1000];

    bool first_set = true;
    while (true) {
        int year_begin, year_end;
        scanf("%d %d", &year_begin, &year_end);
        if (year_begin == 0 && year_end == 0) {
            break;
        }
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n');
        }        
        if (leap_years_count == 0) {
            puts("NA"); 
        } else {
            for (int i = 0; i < leap_years_count; i++) {
                printf("%d\n", leap_years_list[i]);
            }
        }
    }
}

int get_leap_years(int leap_years_list[1000], int year_begin, int year_end)
{
    int leap_year_count = 0;
    for (int year = year_begin; year <= year_end; ++year) {
        if (is_leap_year(year) == true) {
            leap_years_list[leap_year_count] = year;
            ++leap_year_count;
        }
    }
    return leap_year_count;
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0;
    }
}

Measured memory_bytes: 1044
N,x=map(int, input().split())
A=list(map(int, input().split()))
ans=0
ans+=max(0,A[0]-x)
A[0]=min(A[0],x)
if A[0]+A[1]>x:
    ans+=A[1]-(x-A[0])
    A[1]=x-A[0]
ans+=max(0,A[-1]-x)
A[-1]=min(A[-1],x)
if A[-2]+A[-1]>x:
    ans+=A[-2]-(x-A[-1])
    A[-2]=x-A[-1]
for i in range(1,N-1):
    if A[i-1]+A[i]>x:
        ans+=A[i]-(x-A[i-1])
        A[i]=x-A[i-1]
print(ans)

Measured memory_bytes: 14812
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    print(num ** 3)




if __name__ == '__main__':
    main()



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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define rf(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i,b,a) for(int (i) = (b); (i) >= (a); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl
#define test(t) int(testCnt) = 0; int(t); cin >> (t); while(t -- && ++testCnt)

const int INF = 2e9 + 7;
const int MAXA = 1e5 + 10;
const ll MOD = (ll) 1e9 + 7;
const ll INFLL = 9e18 + 7;

typedef pair<int, int> ii;
typedef pair<ii, int> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int f[MAXA], h[MAXA];
int n, k;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
    #endif
    cin >> n >> k;
    rf(i, 1, n) {
        f[i] = INF;
        cin >> h[i];
    }
    f[1] = 0;
    rf(i, 2, k)
        rf(j, 1, i - 1) {
            f[i] = min(f[i], f[j] + abs(h[i] - h[j]));
        }

    rf(i, k + 1, n)
        rf(j, 1, k){
            f[i] = min(f[i], f[i - j] + abs(h[i] - h[i - j]));
        }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
L = int(input())

r = 0
while 2 ** (r + 1) <= L:
    r += 1
    
N = r + 1
edges = []
for i in range(1, N):
    edges.append([i, i + 1, 0])
    edges.append([i, i + 1, 2 ** (i - 1)])
    
for t in reversed(range(1, N)):
    if L - 2 ** (t - 1) >= 2 ** r:
        edges.append([t, N, L - 2 ** (t - 1)])
        L -= 2 ** (t - 1)
    
print(N, len(edges))
for v in edges:
    print(*v)



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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::string S, T;
  std::cin >> N;
  std::cin >> S >> T;

  rep(i, N) {
    std::cout << S[i] << T[i];
  } std::cout << '\n';
}


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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n, k;
    cin >> n >> k;

    int cnt = 0;
    for (int i = 1; i <= n; i += 2, cnt++);
    cout << (cnt >= k ? "YES" : "NO") << '\n';
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];

  map<ll,ll> m;
  REP(i,n)m[a[i]] += 1;

  vll x(n);
  REP(i,n)x[i]=a[i];
  SORT_UNIQUE(x);
  ll sum=0;
  REP(i,x.size()){
    sum += m[x[i]]*(m[x[i]]-1)/2;
  }

  REP(i,n){
    ll ans = sum;
    ans -= m[a[i]]*(m[a[i]]-1)/2;
    ans += (m[a[i]]-2)*(m[a[i]]-1)/2;
    cout<<ans<<endl;
  }

}



Measured memory_bytes: 12672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArCorder
{
    class Program
    {
        static void Main()
        {

            int studentsCount = int.Parse(Console.ReadLine());

            int result = studentsCount / 3;
            Console.WriteLine(result);

        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;


int main(){
int dp[3][3];
 for(int i=0;i<3;i++)
 {
  for(int j=0;j<3;j++)
  {
   int a;
    cin>>a;
 
    dp[i][j]=a;
  }
 }

  int y;
  cin>>y;
  for(int k=0;k<y;k++)
  {
    int z;
    cin>>z;
    for(int i=0;i<3;i++)
 {
  for(int j=0;j<3;j++)
  {
   if(dp[i][j]==z) dp[i][j]=0;
  }
 }

  } 
     
  if(dp[0][1]==0 & dp[0][2]==0 & dp[0][0]==0) cout<<"Yes";
  else if (dp[1][1]==0 & dp[1][2]==0 & dp[1][0]==0) cout<<"Yes";
  else if (dp[2][1]==0 & dp[2][2]==0 & dp[2][0]==0) cout<<"Yes";
  else if (dp[0][0]==0 & dp[1][0]==0 & dp[2][0]==0) cout<<"Yes";
else if (dp[0][1]==0 & dp[1][1]==0 & dp[2][1]==0) cout<<"Yes";
else if (dp[0][2]==0 & dp[1][2]==0 & dp[2][2]==0) cout<<"Yes";
  else if (dp[0][0]==0 & dp[1][1]==0 & dp[2][2]==0) cout<<"Yes";
  else if (dp[0][2]==0 & dp[1][1]==0 & dp[2][0]==0) cout<<"Yes";
else cout<<"No";

}





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

int main(){
    int n;
    long long a, b, c;
    cin >> n;
    a = 1;
    b = 2;
    for(int i = 1; i < n; i++){
        c = a + b;
        b = a;
        a = c;
    }
    if(n == 0) cout << "2" << endl;
    else if(n == 1) cout << "1" << endl;
    else if(n == 2) cout << "3" << endl;
    else cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
character(100),allocatable,dimension(:)::A,B
integer N,M,check
read*,N,M
allocate(A(N))
allocate(B(M))
read*,A
read*,B
do i=1,N-M+1
 do j=1,N-M+1
 	if(A(i)(j:j+M-1)==trim(B(1)))then
     check=0
     do k=1,M
      if(A(i+k-1)(j:j+M-1)/=trim(B(k)))check=1
     end do
     if(check==0)then
      print"(A)","Yes"
      stop
     endif
    endif
 end do
end do
print"(A)","No"
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int H,W; cin >> H >> W;
  vvi c(10, vi(10)); rep(i, 10) rep(j, 10) cin >> c[i][j];
  vvi a(H, vi(W)); rep(i, H) rep(j, W) cin >> a[i][j];

  vi go1_from(10,1e9);
  vi v = {0,1,2,3,4,5,6,7,8,9};
  do {
    if(v[0] == 1) continue;
    int sum = 0;
    rep(i, 9){
      sum += c[v[i]][v[i+1]];
      if(v[i+1] == 1) break;
    }
    chmin(go1_from[v[0]], sum);
  } while(next_permutation(all(v)));

  ll ans = 0;
  rep(i, H) rep(j, W){
    if(a[i][j] == -1 || a[i][j] == 1) continue;
    ans += go1_from[a[i][j]];
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 384
import java.util.*;

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

        int N = sc.nextInt();
        int[] t = new int[N + 1];
        int[] x = new int[N + 1];
        int[] y = new int[N + 1];

        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        for(int i=1; i<=N; i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            int r = Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1]);
            int T = t[i] - t[i - 1];
            if(r > T){
                System.out.println("No");
                break;
            }
            else if(r < T){
                T = T - r;
                if(T%2!=0){
                    System.out.println("No");
                    break;
                }
            }
            if(i==N){
                System.out.println("Yes");
            }
        }

    }
}

Measured memory_bytes: 89868
#include<bits/stdc++.h>
using namespace std;
int a,b,num;
int main(){
	while(cin>>a>>b){
		num=a+b;
		if(num>=0&&num<=9){
			cout<<"1"<<endl;
		}
		else if(num>=10&&num<=99){
			cout<<"2"<<endl;
		}
		else if(num>=100&&num<=999){
			cout<<"3"<<endl;
		}
		else if(num>=1000&&num<=9999){
			cout<<"4"<<endl;
		}
		else if(num>=10000&&num<=99999){
			cout<<"5"<<endl;
		}
		else if(num>=100000&&num<=999999){
			cout<<"6"<<endl;
		}
		else{
			cout<<"7"<<endl;
		}
	}
 }
		  
		  



Measured memory_bytes: 3068
#include <iostream>
#include <set>

int main(void) {
    int q;
    std::cin >> q;

    std::set<int> my_set{};
    for (int i = 0; i < q; ++i) {
        int kind, x;
        std::cin >> kind >> x;

        switch (kind) {
            case 0:
                my_set.insert(x);
                std::cout << my_set.size() << std::endl;
                break;
            case 1:
                if (my_set.find(x) != my_set.end())
                    std::cout << 1 << std::endl;
                else
                    std::cout << 0 << std::endl;
                break;
            case 2:
                my_set.erase(x);
        }
    }
}


Measured memory_bytes: 12444
'use strict'

const main = arg => {
    var input = arg.trim().split("\n")[0];
    var result = [];
    [...Array(input.length)].forEach((a, i) => {
        if(input[i].match(/[A-Z]/)){ 
            result.push(input[i].toLowerCase()); 
        } else {
            result.push(input[i].toUpperCase()); 
        } 
    });

    console.log(result.join(""));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 16292
/* ***************************************
Author        :Scau.ion
Created Time  :2016/11/28 11:04:36 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=100010;
const int mod=1e9+7;

struct num
{
    int x;
    bool type;
    bool operator <(const num &b)const
    {
        return x<b.x;
    }
}ab[maxn*2];

int main()
{
    IOS;
    int n;
    cin>>n;
    int nn=n*2;
    for (int j=1;j<=nn;++j)
    {
        cin>>ab[j].x;
        ab[j].type=(j>n);
    }
    sort(ab+1,ab+n*2+1);
    LL ans=1;
    int sum=0;
    for (int j=1;j<=nn;++j)
    {
        int add;
        if (ab[j].type) add=1;
        else add=-1;
        if (!((sum<=0&&add<0)||(sum>=0&&add>0))) ans=ans*abs(sum)%mod;
        sum+=add;
    }
    cout<<ans<<endl;
    return 0;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        long a = in.nl(), b = in.nl();
        int k = in.ni();
        for (int i = 0; i < k; i++) {
            if(i%2==0){
                if(a%2==1)a--;
                a /= 2;
                b += a;
            }else{
                if(b%2==1)b--;
                b /= 2;
                a += b;
            }
        }
        out.printf("%d %d\n",a,b);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];
int b[MAX_N];

int main()
{
	int n;
	ll asum = 0;
	cin >> n;
	rep(i,n){
		scanf("%d",&a[i]);
		asum += a[i];
	}
	rep(i,n-1){
		b[i] = a[i+1] - a[i];
	}
	b[n-1] = a[0] - a[n-1];
	ll nsum = (ll)n * (n+1) / 2;
	bool flag = false;
	if(asum % nsum != 0){
		cout << "NO" << "\n";
	}else{
		ll cnt = asum / nsum;	//cnt回の操作を行った
		ll hoge=0;
		rep(i,n){
			if((cnt-b[i]) % n != 0 || cnt - b[i] < 0 || cnt - b[i] > n*cnt){
				flag = true;
				break;
			}else{
				hoge += (cnt-b[i]) / n;
			}
		}
		if(flag == true || hoge != cnt){
			cout << "NO" << "\n";
		}else{
			cout << "YES" << "\n";
		}
	}
}

Measured memory_bytes: 1024
use std::cmp;

fn main() {
  
  let s = gets();
  let n = s.len();
  let t = gets();
  let m = t.len();
  
  // .chars().enumerate() -> (c, i)
  let mut dp: Vec<Vec<usize>> = vec![vec![0; m+1]];
  for (i, c) in s.chars().enumerate() {
    let mut row: Vec<usize> = vec![0];
    for (j, d) in t.chars().enumerate() {
      let mut max = dp[i][j+1];
      if c == d {
        max = cmp::max(max, dp[i][j] + 1);
      };
      max = cmp::max(max, row[j]);
      row.push(max);
    }
    dp.push(row);
  }
  
  let chars = s.chars().collect::<Vec<char>>();
  let mut u = "".to_string();
  let mut i = n;
  let mut j = m;
  while dp[i][j] > 0 {
    // go up
    while dp[i][j-1] == dp[i][j] {
      j -= 1;
    }
    // go left
    while dp[i-1][j] == dp[i][j] {
      i -= 1;
    }
    u.insert(0, chars[i-1]);
    i -= 1;
    j -= 1;
  };
  
  println!("{}", u);
}

fn read<T: std::str::FromStr>() -> Vec<T> {
  gets().split_whitespace().filter_map(|s|s.parse().ok()).collect()
}

fn gets() -> String {
  let mut line = String::new();
  std::io::stdin().read_line(&mut line).ok();
  line.trim().to_string()
}


Measured memory_bytes: 84504
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b;
  	int n=0;
  	cin >> a;
  	cin >> b;
  	for(int i=0;i<a.size();++i){
    	if(a[i] != b[i]){
          n++;
        }
    }
  	cout<<n;
}  


Measured memory_bytes: 3920
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
	while(1){
		double stu=0,sum=0,avg=0,tmp=0;
		double data[1000]={};		
		scanf("%lf",&stu);
		if(stu==0){
			break;
		}
		for(int i=0; i<stu; i++){
			scanf("%lf",&data[i]);
			sum+=data[i];
		}
		avg=sum/stu;
		for(int i=0; i<stu; i++){
			tmp+=(data[i]-avg)*(data[i]-avg);
		}
		printf("%.8lf\n",sqrt(tmp/stu));
	}
}



Measured memory_bytes: 2668
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=2e5+10;
LL t[M],s[M],d[M];
int n;
int main(){
	n=read(); n++;
	F(i,1,n) {
		t[i]=read();
	}
	DF(i,n,1) s[i]=s[i+1]+t[i];
	LL ans=1; d[1]=1; 
	F(i,2,n){
		LL tmp=max(0ll,2ll*(d[i-1]-t[i-1])-s[i]);
		if (d[i-1]-t[i-1]<=0){
			puts("-1");
			return 0;
		}
		d[i]=tmp+2ll*(d[i-1]-t[i-1]-tmp),ans+=d[i];
//		cout<<d[i]<<" "<<tmp<<"   fuck\n";
	}
	if (d[n]==t[n]) 
	cout<<ans<<"\n";
	else cout<<"-1\n";
	
	return 0;
}




Measured memory_bytes: 5976
#include<stdio.h>

int main(void){
	long n,m,ans;
	scanf("%ld %ld",&n,&m);
	if(n==1){
		if(m==1){
			ans=1;
		}else if(m==2){
			ans=0;
		}else{
			ans=m-2;
		}
	}else if(n==2){
		ans=0;
	}else{		// n>=3
		if(m==1){
			ans=n-2;
		}else if(m==2){
			ans=0;
		}else{		// m>=3
			ans=(n-2)*(m-2);
		}
	}
	
	printf("%ld\n",ans);
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(N, A):
    c = Counter()

    for a in A:
        if a % 4 == 0:
            c[2] += 1
        elif a % 2 == 0:
            c[1] += 1
        else:
            c[0] += 1

    if c[0] - c[2] > 1:
        return 'No'

    if c[0] - c[2] == 1 and c[1] > 0:
        return 'No'

    return 'Yes'


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 88684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void){
    ll q,h,s,d; cin>>q>>h>>s>>d;
    ll Q = 4*q, H = 2*h;
    ll n; cin>>n;
    ll ans1,  ans2, ans3;
    ll smallest = INF;
    chmin(smallest,Q); chmin(smallest,H); chmin(smallest,s);
    
    /// 2Lで頑張る
    int rest = n%2;
    if(rest) ans1 = (n/2)*d + smallest;
    else ans1 = (n/2)*d;
    //
    ans2 = n*smallest;
    if(ans1<ans2) cout<<ans1<<endl;
    else cout<<ans2<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  FOR(i, N) cin >> A[i];
  ll sum = accumulate(ALL(A), 0LL);
  vector<ll> div;
  for (int x = 1; x * x <= sum; ++x) {
    if (sum % x == 0) {
      div.push_back(x);
      div.push_back(sum / x);
    }
  }
  sort(ALL(div), greater<ll>());
  for (int x : div) {
    vector<int> list(N);
    FOR(j, N) { list[j] = A[j] % x; }
    sort(ALL(list), greater<int>());
    ll a = accumulate(ALL(list), 0LL), b = 0;
    ll mn = a;
    FOR(j, N) {
      a -= list[j];
      b += x - list[j];
      mn = min(mn, max(a, b));
    }
    if (mn <= K) {
      print(x);
      return 0;
    }
  }
  return 0;
}


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


int main() {
    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (x != i) ++cnt;
    }
    if (cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
int n,cnt=0;
vector<int>ans;
signed main(){
    cin>>n;
    for(int i=1;i<sqrt(n);i++){
        if(n%i==0&&i*(i+1)!=n)ans.push_back((n-i)/i);
    }
    int l=ans.size();
    rep(i,l){
        cnt+=ans[i];
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc064_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  string S;
  cin >> N >> S;

  int tr = 0, tl = 0;
  int d = 0, x = 0;
  rep(i, N) {
    if (S[i] == '(') d++;
    else
      d--;
    x = min(d, x);
  }

  tr = -x;
  tl = d - x;
  rep(i, tr) { cout << '('; }
  cout << S;
  rep(i, tl) { cout << ')'; }
}

Measured memory_bytes: 3616
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 1e6+5;

ll dp[N],pw[N],pw9[N],pw8[N];

void solve(){
	int n;
	cin>>n;
	if(n<2){
		cout<<0;
		return;
	}
	if(n==2){
		cout<<2;
		return;
	}
	ll ans=0;
	pw[1]=10,pw9[1]=9,pw8[1]=8;
	for(ll i=2;i<=n;i++){
		pw[i]=pw[i-1]*10LL;
		pw[i]%=mod;
		pw9[i]=pw9[i-1]*9LL;
		pw9[i]%=mod;
		pw8[i]=pw8[i-1]*8LL;
		pw8[i]%=mod;
	}
	cout<<(pw[n]-(pw9[n]*2)%mod+pw8[n]+mod)%mod;
	
}

int main(){
 Speed();
	int T=1; 
	//cin>>T;	
	while(T--)solve();
}


Measured memory_bytes: 26964
# 2020/05/03
# AtCoder Beginner Contest 048 - B

# Input
a, b, x = map(int,input().split())

# Calc
wk_v1 = (a - 1) // x
wk_v2 = b // x
ans = wk_v2 - wk_v1

# Output
print(ans)


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	ll n;
	cin >> n;
	string ans;
	while (n)
	{
		n--;
		ans = char(97 + n % 26) + ans;
		n /= 26;
	}
	cout << ans;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int A, B, X;

int main(void)
{
  cin >> A >> B >> X;
  if (A > X || (A + B) < X) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D){
    cout << "Left" << endl;
  }else if(A + B == C + D){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <map>
using namespace std;

typedef long long ll;

const int MAXn = 1000 * 1000 + 13, N = 2 * 100 * 1000 + 13;

vector<int> adj1[MAXn], adj2[MAXn], news;
ll cmp1[MAXn], cmp2[MAXn], cnt1, cnt2;
bool mark1[MAXn], mark2[MAXn];
map<pair<ll, ll>, ll> ans;

void bfs1(int r){
	queue<int> q;
	q.push(r);
	mark1[r] = true;
	while(!q.empty()){
		int v = q.front();
		q.pop();
		cmp1[v] = cnt1;
		for(int i = 0; i < adj1[v].size(); i++){
			int u = adj1[v][i];
			if(!mark1[u]){
				mark1[u] = true;
				q.push(u);
			}
		}
	}
}

void bfs2(int r){
	queue<int> q;
	q.push(r);
	mark2[r] = true;
	while(!q.empty()){
		int v = q.front();
		q.pop();
		cmp2[v] = cnt2;
		for(int i = 0; i < adj2[v].size(); i++){
			int u = adj2[v][i];
			if(!mark2[u]){
				mark2[u] = true;
				q.push(u);
			}
		}
	}
}

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	for(int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		x--;
		y--; 
		adj1[x].push_back(y);
		adj1[y].push_back(x);
	}
	for(int i = 0; i < l; i++){
		int x, y;
		cin >> x >> y;
		x--;
		y--; 
		adj2[x].push_back(y);
		adj2[y].push_back(x);
	}
	for(int i = 0; i < n; i++)
		cmp1[i] = cmp2[i] = -1;
	cnt1 = cnt2 = 1;
	memset(mark1, 0, sizeof mark1);
	memset(mark2, 0, sizeof mark2);
	for(int i = 0; i < n; i++)
		if(!mark1[i]){
			bfs1(i);
			cnt1++;
		}
	for(int i = 0; i < n; i++)
		if(!mark2[i]){
			bfs2(i);
			cnt2++;
		}
	for(int i = 0; i < n; i++)
		ans[make_pair(cmp1[i], cmp2[i])]++;
	for(int i = 0; i < n; i++)
		cout << ans[make_pair(cmp1[i], cmp2[i])] << " ";
	cout << endl;
	return 0;
}

	


Measured memory_bytes: 73252
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
    ll a,b,c; cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	map<int,int> mp;

	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	
	ll ans = 0;
	for(int i = 0;i < n;i++){
		ans += mp[i+1-a[i]];
		mp[a[i]+i+1]++;
	}

	cout << ans << endl;
	
}


Measured memory_bytes: 21028
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  int ans;
  for(long long i=1;i<100000;i++){
    if(i*(i+1)/2>=x){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()

	ans := 0
	for i := 1; i <= n; i++ {
		count := n / i
		ans += i * (1 + count) * count / 2
	}

	fmt.Println(ans)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1792
from heapq import heapify, heappush, heappop
N, M = map(int, input().split())
q = list(map(int, input().split()))
heapify(q)
pairs = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda t: t[1], reverse=True)
for b, c in pairs:
    for _ in range(b):
        x = heappop(q)
        if x < c:
            heappush(q, c)
        else:
            heappush(q, x)
            print(sum(q))
            quit()
print(sum(q))


Measured memory_bytes: 22256
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    i, j = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    ans = min(
        max(abs(s[i] - x), abs(t[j] - x)),
        max(abs(s[i - 1] - x), abs(t[j - 1] - x)),
        2 * min(abs(s[i] - x), abs(t[j - 1] - x)) + max(abs(s[i] - x), abs(t[j - 1] - x)),
        2 * min(abs(s[i - 1] - x), abs(t[j] - x)) + max(abs(s[i - 1] - x), abs(t[j] - x))
    )
    print(ans)


Measured memory_bytes: 13968
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	LL W;
	while(cin >> n >> W) {
		vector<LL> w(n);
		vector<LL> v(n);
		REP(i,n) cin >> w[i] >> v[i];
		LL hoge = n*5+100;
		vector<vector<LL>> dp (n+1, vector<LL>(hoge,-1e15));
		dp[0][0] = 0;
		REP(i,n){
			vector<vector<LL>> dpn = dp;
			LL cw = w[i]-w[0];
			REP(j,n){
				RREP(k,hoge-cw){
					chmax(dpn[j+1][k+cw],dp[j][k]+v[i]);
				}
			}
			swap(dpn,dp);
			REP(i,n+1) dpite(ALL(dp[i]));
			DEBUG(endl);
		}
		LL ans = 0;
		REP(i,n+1){
			REP(k,hoge){
				LL we = i*w[0]+k;
				if(we <= W){
					chmax(ans,dp[i][k]);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
arr = Array.new
numberOflines = gets.to_i
numberOflines.times do
   arr << gets
end

arr.each do |i|
   a = i.split(" ")
   a.map!{|j| j.to_i}
   a.sort!
   if a[0] ** 2 + a[1] ** 2 == a[2] ** 2
      puts "YES"
   else
      puts "NO"
   end
end

Measured memory_bytes: 6104
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    String ans = "Christmas";
    if (D == 24) {
      ans += " Eve";
    } else if (D == 23) {
      ans += " Eve Eve";
    } else if (D == 22) {
      ans += " Eve Eve Eve";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

int d[2020][2020];
ll g[2020][2020];
char A[2020];// "1trkvznlbqskroaokextbfscsfosftpbuvoxotdsvefnviqidzjmdegxlisrumfkpxlzuveovvthtqndm";//"1uzuzvzuw";
ll K;
int N, len;
char ans[4040];

void D(){for(int i=1;;i++);}

void Do(int L, int R, ll T, int id){
	//printf("%d %d %lld %lld %d\n", L, R, g[L][R], T, d[L-1][R+1]);
	if(L > R)return;
	if(L == R){
		ans[id] = A[L];
		//if(id != len/2+1)D();
		return;
	}
	
	if(A[L] == A[R]){
		ans[id] = ans[len + 1 - id] = A[L];
		Do(L+1, R-1, T, id+1);
	}
	else{
		if(A[L] < A[R]){
			if(d[L-1][R+1] + 2 == d[L][R+1]){
				if(g[L+1][R] >= T){
					ans[id] = ans[len + 1 - id] = A[L];
					Do(L+1, R, T, id+1);
				}
				else{
					ans[id] = ans[len + 1 - id] = A[R];
					Do(L, R-1, T - g[L+1][R], id+1);
				}
			}
			else{
				ans[id] = ans[len + 1 - id] = A[R];
				Do(L, R-1, T, id+1);
			}
		}
		else{
			if(d[L-1][R+1] + 2 == d[L-1][R]){
				if(g[L][R-1] >= T){
					ans[id] = ans[len + 1 - id] = A[R];
					Do(L, R-1, T, id+1);
				}
				else{
					ans[id] = ans[len + 1 - id] = A[L];
					Do(L+1, R, T - g[L][R-1], id+1);
				}
			}
			else{
				ans[id] = ans[len + 1 - id] = A[L];
				Do(L+1, R, T, id+1);
			}
		}
	}
}

void solve(int tc){
	scanf("%s", A+1);
	//srand(time(NULL));
	//for(int i=1;i<=2000;i++)A[i] = rand() % 26 + 'a';
	N = (int)strlen(A+1);
	
	d[0][N+1] = 0;
	for(int i=1;i<=N;i++)d[i][N+1] = 2*i, d[0][i] = 2*(N+1 - i);
	for(int i=1;i<=N;i++){
		for(int j=N;j>i;j--){
			d[i][j] = min(d[i-1][j] + 2, d[i][j+1] + 2);
			if(A[i] == A[j])d[i][j] = min(d[i][j], d[i-1][j+1] + 2);
		}
	}
	
	len = 2*N + 1;
	for(int i=1;i<=N;i++){
		len = min(len, 1 + d[i-1][i+1]);
	}
	for(int i=1;i<N;i++)len = min(len, d[i][i+1]);
	
	int chk = 0;
	for(int i=1;i<=N;i++){
		if(len == 1 + d[i-1][i+1]){
			g[i][i] = 1;
		}
	}
	for(int i=1;i<N;i++){
		if(len == d[i][i+1]){
			chk = g[i][i+1] = 1;
		}
	}
	
	for(int i=1+chk;i<N;i++){
		for(int j=1;j+i<=N;j++){
			if(A[j] == A[j+i] && d[j-1][j+i+1] + 2 == d[j][j+i])g[j][j+i] += g[j+1][j+i-1];
			if(A[j] != A[j+i]){
				if(d[j-1][j+i+1] + 2 == d[j-1][j+i])g[j][j+i] += g[j][j+i-1];
				if(d[j-1][j+i+1] + 2 == d[j][j+i+1])g[j][j+i] += g[j+1][j+i];
			}
			if(g[j][j+i] > 2e18)g[j][j+i] = 2e18;
		}
	}
	
//	for(int i=0;i<=N;i++){for(int j=1;j<=N+1;j++)printf("%-2d", d[i][j]);puts("");}
//	for(int i=1;i<=N;i++){for(int j=1;j<=N;j++)printf("%lld ", g[i][j]);puts("");}
	
	//printf("%lld\n", g[1][N]);
	//printf("%s\n", A+1);
	scanf("%lld", &K);
	if(g[1][N] < K)puts("NONE");
	else{
		Do(1, N, K, 1);
		printf("%s\n", ans+1);
	}
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 48568
package main

import (
	"fmt"
	"sort"
)

type arr []int

func (a arr) Len() int {
	return len(a)
}

func (a arr) Swap(i, k int) {
	a[i], a[k] = a[k], a[i]
}

func (a arr) Less(i, k int) bool {
	return a[i] < a[k]
}

func main() {
	a, m := input()
	sort.Sort(a)
	c := 0
	f := make([]bool, a[len(a)-1]+1, a[len(a)-1]+1)
	for i := 0; i < len(a); i++ {
		if f[a[i]] {
			continue
		} else if !m[a[i]] {
			c++
		}
		for k := a[i]; k < len(f); k += a[i] {
			f[k] = true
		}
	}
	fmt.Println(c)
}

func input() (arr, map[int]bool) {
	var n int
	fmt.Scan(&n)
	a := make([]int, n, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	f := make(map[int]bool, n)
	for _, v := range a {
		_, ok := f[v]
		if ok {
			f[v] = true
			continue
		}
		f[v] = false
	}
	k := 0
	b := make([]int, len(f), len(f))
	for i := range f {
		b[k] = i
		k++
	}
	return b, f
}


Measured memory_bytes: 11188