akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1'000'000'007)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    set<int> d;
    REP(i, n){
        int a;
        cin >> a;
        d.insert(a);
    }
    pr(d.size());
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

long N, A, B;

int main(void) {
  cin >> N >> A >> B;
  if(A > B || (N == 1 && A != B)) {
    cout << 0 << endl;
  } else {
    cout << ((B * (N - 1) + A) - (A * (N - 1) + B) + 1) << endl;
  }


  return 0;
}


Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);
    let output = "";

    for (let i = 0; i < a; i++) {
        output = output + 'ACL';
    }
    console.log(output)
}

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

Measured memory_bytes: 29500
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

constexpr ll INF       = 1000000000;/* 1e+9a */
// for(auto && i : Range(l,r))
// -> i = [l..r)
class Range {
private: struct It{ int x; int operator*(){return x;}
 bool operator!=(It& lhs){ return x<lhs.x;} void operator++(){++x;} }; It l,r;
public: Range(int n):l({0}),r({n}){} Range(int i,int n):l({i}),r({n})
 {}It& begin(){return l;} It& end(){return r;} };

void solve(istream& cin) {
    ll M, N;
    while(cin >> N >> M){
        vector<ll> A;
        for (int i = 0; i < N; ++i) {
            ll tmp;
            cin >> tmp;
            A.push_back(tmp);
        }
        map<ll, ll> sumd;
        ll sum = 0;
        ll count = 0;
        sumd[sum]++;
        for (int i = 0; i < A.size(); ++i) {
            auto Sr = sum + A[i];
            Sr %= M;
            count += sumd[Sr];
            sum = Sr;
            sumd[sum]++;
        }
        cout << count << endl;
    }
}

int main(int argc, char *argv[]) {
    string FileName("D"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {    
	    cerr << sub << endl;
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

Measured memory_bytes: 4980
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding


	int n,m;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	vi v;
	for(int i=0;i<m;i++){
		if(i!=m-1)
			v.pb(a[i+1]-a[i]);
		else{
			int x  = min(a[i]-a[0],a[0]+n-a[i]);
			v.pb(x);
		}
	}
	sort(all(v));
	ll sum = 0LL;
	for(int i=0;i<v.size()-1;i++){
		sum+=(ll)v[i];
	}

	cout<<sum<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

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

using namespace std;


typedef pair <long long ,long long>	PII;
typedef vector <int>	VI;
typedef vector <PII>    VII;
typedef priority_queue<PII,vector<PII>,greater<PII>> pairMinHeap;
typedef priority_queue<PII> pairMaxHeap;
typedef priority_queue<long long ,vector<long long>,greater<long long>> minHeap;
typedef priority_queue<long long> maxHeap;

#define what_is(x) cerr <<#x<<" is "<<x<<endl;
#define wis(x,y) cerr <<#x<<" is "<<x<<" and "<<#y<<" is "<<y<<endl;
#define getarr(n,d) for(int i=0;i<n;i++)cin>>d[i];
#define getgraph(n,g) for(int i=1;i<n;i++){int a,b;cin>>a>>b;a--;b--;g[a].push_back(b);g[b].push_back(a);}
#define getpartree(n,tree) for(int i=1;i<n;i++){int a;cin>>a;tree[a-1].push_back(i);}

struct POS{
    int x=0,y=0;
    POS():x(0),y(0){}
    POS(int _x,int _y):x(_x),y(_y){}
};

struct triple{
    int f,s,t;
    triple():f(0),s(0),t(0){}
    triple(int _f,int _s,int _t):f(_f),s(_s),t(_t){}
};

const int INF = 1e9+9;
const long long LINF = 1e17+9;
const long long MD=998244353 ;

inline long long po(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1)ans = (ans*a)%MD;
        a = (a*a)%MD;
        b/=2;
    }
    return ans;
}


const int N=1e5+33;

long long n,m,k,t;
long long a[N],b[N],c[N];
string s;


int main() {
	ios_base::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);cout << fixed;cout << setprecision(10);
    cin>>n;
    getarr(n,a);
    getarr(n,b);

    for(int i=0;i<n;i++){
        c[i]=b[i]-a[i];
    }
    sort(c,c+n);

    long long sum=0;
    int ans=0;

    for(int i=n-1;i>=0;i--){
        if(c[i]<=0)break;
        sum+=c[i];
        ans++;

    }

    for(int i=0;i<n&& sum>0;i++){
        if(c[i]>=0)break;
        sum+=c[i];
        ans++;
    }
    if(sum<=0){
        cout<<ans;
    }else cout<<-1;





    return 0;
}


Measured memory_bytes: 2560
def main():
    N, M = map(int, input().split())

    ac_count = 0
    wa_count = 0

    if M == 0:
        print('{} {}'.format(ac_count, wa_count))
        exit()

    result_list = []

    for i in range(N):
        result_list.append([i+1, 0, 0])

    for i in range(M):
        str_list = input().split()
        if result_list[int(str_list[0])-1][1] == 1:
            continue
        if str_list[1] == 'AC':
            result_list[int(str_list[0])-1][1] = 1
        if str_list[1] == 'WA' and result_list[int(str_list[0])-1][1] == 0:
            result_list[int(str_list[0])-1][2] += 1

    for i in range(N):
        if result_list[i][1] == 1:
            ac_count +=1
            wa_count += result_list[i][2]

    print('{} {}'.format(ac_count, wa_count))

if __name__ == '__main__':
    main()

Measured memory_bytes: 55968
#include<stdio.h>
int main()
{
    int r,t,m,n;
    scanf("%d%d",&m,&n);
    if(m<n)
    {
        t=m;
        m=n;
        n=t;
    }
    r=m%n;
    while(r)
    {
        m=n;
        n=r;
        r=m%n;
    }
    printf("%d\n",n);
    return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    ll n, a, b; cin >> n >> a >> b;
    if((b - a) % 2 == 0) {
        cout << (b-a) / 2 << endl;
        return 0;
    }
    ll c = min(b-1, n-a);
    ll d=0;
    if(a-1 > n-b) {
        ll da = a+n-b+1;
        d += n-b+1;
        d += (n - da) / 2;
    }
    else {
        ll db = b-a;
        d += a;
        d += (db - 1) / 2;
    }
    cout << min(c, d) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
  int N, X, L[100];
  int i, a;

  scanf ("%d %d", &N, &X);

  for (i = 0; i < N; i++) {
    scanf ("%d", &L[i]);
  }
  
  a = 0;

  for (i = 0; i < N; i++) {
    a = a + L[i];
    if (a > X) {
      break;
    }
  }

  printf ("%d", i+1);
}

Measured memory_bytes: 128
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

n, m = map(int, input().split())
d = [[-1] * n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = 1
    d[b][a] = 1

dp = [[-1] * n for i in range(1<<n)]
#訪れた集合がs、今いる点がvの時０に戻る最短経路
def rec(s,v,dp):
    if dp[s][v] >= 0:
        return dp[s][v]
        
    if s == (1<<n)-1:
        dp[s][v] = 1
        return 1
    
    res = 0
    for u in range(n):
        if (s>>u&1) == 0 and d[v][u] == 1:
            res += rec(s|(1<<u),u,dp)
    dp[s][v] = res
    return res

print(rec(1,0,dp))

Measured memory_bytes: 9296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int d=1;
	for(int i=1;i<=k;i++)
	{
		if(a>=b)
		{
			b=b*2;
		}
		else if(b>=c)c=c*2;
		else if(c<=a)c=c*2;
		if(a<b && b<c && a<c )
		{
			d=0;
			cout<<"Yes";
			break;
		}
	}
	if(d!=0)
	cout<<"No";
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <stack>
using namespace std;

int main(void)
{
    int n;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        stack < int > b, c;
        int j;
        
        b.push(0);
        c.push(0);
        
        int ball[10];
        for (int i = 0; i < 10; i++){
            scanf("%d", &ball[i]);
        }
        
        for (j = 0; j < 10; j++){
            if (b.top() < ball[j]){
                if (c.top() < ball[j]){
                    if (c.top() < b.top()){
                        b.push(ball[j]);
                    }
                    else {
                        c.push(ball[j]);
                    }
                }
                else {
                    b.push(ball[j]);
                }
            }
            else if (c.top() < ball[j]){
                c.push(ball[j]);
            }
            else {
                break;
            }
        }
        
//        printf("%d\n", j);
        
        if (j == 10){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

const int SIZE=100000;
const int INF=1001001001001001001LL;

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int N,M,K,S;
int P,Q;
int C[SIZE];
vector<edge>G[SIZE];
int dist[SIZE];

void bfs(){
    fill_n(dist,N,INF);
    queue<int>que;

    rep(i,K){
        dist[C[i]]=0;
        que.push(C[i]);
    }

    while(que.size()){
        int v=que.front();que.pop();
        rep(i,G[v].size()){
            int to=G[v][i].to;
            if(dist[to]<=dist[v]+1)continue;
            dist[to]=dist[v]+1;
            que.push(to);
        }
    }
}

void build(){
    rep(i,N){
        vector<edge>vec;
        rep(j,G[i].size()){
            int to=G[i][j].to;
            if(dist[to]==0)continue;
            if(to==N-1)vec.pb(edge(to,0));
            else if(dist[to]<=S)vec.pb(edge(to,Q));
            else vec.pb(edge(to,P));
        }
        G[i]=vec;
    }
}

void dijkstra(){
    fill_n(dist,N,INF);
    dist[0]=0;

    priority_queue<pint,vector<pint>,greater<pint> >que;
    que.push(pint(0,0));

    while(que.size()){
        pint p=que.top();que.pop();
        if(dist[p.second]<p.first)continue;
        rep(i,G[p.second].size()){
            edge &e=G[p.second][i];
            if(dist[e.to]<=p.first+e.cost)continue;
            dist[e.to]=p.first+e.cost;
            que.push(pint(dist[e.to],e.to));
        }
    }
}

signed main(){
    cin>>N>>M>>K>>S;
    cin>>P>>Q;
    rep(i,K)cin>>C[i],C[i]--;
    rep(i,M){
        int a,b;cin>>a>>b;a--;b--;
        G[a].pb(edge(b,1));
        G[b].pb(edge(a,1));
    }

    bfs();
    build();
    dijkstra();

    cout<<dist[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 16916
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N, M, X  = [int(x) for x in stdin.readline().rstrip().split()]

CA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

knowledge_list = [[0 for _ in range(M)]]
money_list = [0]

for i in range(N):
    C = CA[i][0]
    A = CA[i][1:]

    # 購入する場合
    tmp2 = []
    for i, knowledge in enumerate(knowledge_list):
        tmp = []
        for k in range(len(knowledge)):
            tmp.append(knowledge[k] + A[k])
        
        tmp2.append(tmp)
        money_list.append(money_list[i]+C)

    knowledge_list = knowledge_list + tmp2

ans = INF
for i in range(len(money_list)):
    if min(knowledge_list[i]) >= X:
        ans = min(ans, money_list[i])

if ans != INF:
    print(ans)
else:
    print(-1)


            


Measured memory_bytes: 77956
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,m,a,b[1005]={0},i;
	scanf("%d%d",&n,&k);
	while(k--)
	{
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&a);
			b[a]++;
		}
	}
	int x=0;
	for(i=1;i<=n;i++)
	{
		if(b[i]==0)
		x++;
	}
	printf("%d\n",x);
} 

Measured memory_bytes: 3820
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		List<int[]> ansList = new ArrayList<>();
		int[] ans = new int[3];
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= N-i; j++) {	
				int k = N - i - j;
				if (10000 * i + 5000 * j + 1000 * k == Y && i+j+k == N) {
					ans[0] = i;
					ans[1] = j;
					ans[2] = k;
					ansList.add(ans);
				}				
			}	
		}
		if (ansList.isEmpty()) System.out.println("-1 " +  "-1 " + "-1");
		else {
			ans = ansList.get(0);
			System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
		}
	}
}

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

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

    vector<int> V(N);
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    vector<int> C(N);
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }

    vector<pair<int, int>> VC(N);
    for(int i = 0; i < N; i++){
        VC[i] = make_pair(V[i], C[i]);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
       if(VC[i].first >= VC[i].second){
           ans += VC[i].first - VC[i].second;
       }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main() -> None:
    n = next_int()
    mx = mn = 0

    for i in range(n):
        ai = next_int()
        if i == 0:
            mx = mn = ai
        else:
            mx = max(mx, ai)
            mn = min(mn, ai)

    print(mx - mn)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#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<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 111;
const int INF = 1e9;
int mat[MAXN][MAXN];
int ans;
int n, m;

void dfs(vector<int>& v) {
    int sz = v.size();
    if (v.size() > 1) {
        int tmp = 0;
        for (int i = 0; i < sz; i++) {
            int mini = INF;
            for (int j = 0; j < sz; j++) if (j != i) {
                mini = min(mini, mat[v[i]][v[j]]);
            }
            tmp += mini;
        }
        ans = max(ans, tmp);
    }
    int last = v.back();
    for (int i = last+1; i < n; i++) {
        bool ok = true;
        for (int j = 0; j < sz; j++) {
            if (!mat[i][v[j]]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            v.push_back(i);
            dfs(v);
            v.pop_back();
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v, f;
        cin >> u >> v >> f;
        u--; v--;
        mat[u][v] = mat[v][u] = f;
    }
    ans = 0;
    for (int i = 0; i < n; i++) {
        vector<int> v(1, i);
        dfs(v);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
v = [[] for _ in range(N)]
for _ in range(N - 1) :
    a, b, c = map(int, input().split())
    v[a-1].append((b-1, c))
    v[b-1].append((a-1, c))

visited = [-1] * N
def bfs(a, dist) :
    for b, c in v[a] :
        if visited[b] < 0 :
            visited[b] = dist + c
            bfs(b, dist + c)
          
Q, K = map(int, input().split())
visited[K-1] = 0
bfs(K-1, 0)
for _ in range(Q) :
    x, y = map(int, input().split())
    print(visited[x-1] + visited[y-1])

Measured memory_bytes: 191280
import java.awt.*;
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		Point[]a=new Point[n];
		Arrays.setAll(a,o->new Point(s.nextInt(),s.nextInt()));


		double r=0;

		for(int i=0;i<n;++i)
			for(int j=i+1;j<n;++j)
				r+=a[i].distance(a[j]);
		System.err.println(r);
		System.out.println(r*2/n);
	}
}


Measured memory_bytes: 26964
#include <stdio.h>
#include <limits.h>

#ifndef KOTAISUU
#define KOTAISUU 12
#endif
#ifndef SEDAISUU
#define SEDAISUU 17000
#endif
#ifndef KAKURITU
#define KAKURITU 30 /* * 0.01 % */
#endif

#ifndef NO_ENABLE_REVERSE
#define ENABLE_REVERSE
#endif

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

unsigned int randint2(unsigned int max) {
	unsigned int amari = ((UINT_MAX % max) + 1) % max;
	unsigned int ret;
	do {
		ret = randint();
	} while (ret < amari);
	return ret % max;
}

#define KIND 26
#define MAX 365

struct horieyui {
	int mamegu[MAX];
};

int D;
int c[KIND];
int s[MAX][KIND];

int mizuhasu(const struct horieyui* kitaeri) {
	int sumipe = 0;
	int i, j;
	int last[KIND] = {0};
	for (i = 0; i < D; i++) {
		sumipe += s[i][kitaeri->mamegu[i]];
		last[kitaeri->mamegu[i]] = i + 1;
		for (j = 0; j < KIND; j++) {
			sumipe -= c[j] * ((i + 1) - last[j]);
		}
	}
	return sumipe;
}

int main(void) {
	int i, j;
	struct horieyui otehon;
	struct horieyui saikyou;
	int saikyou_score = 0;
	if (scanf("%d", &D) != 1) return 1;
	for (i = 0; i < KIND; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < D; i++) {
		for (j = 0; j < KIND; j++) {
			if (scanf("%d", &s[i][j]) != 1) return 1;
		}
	}

	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i + j) % KIND;
		score = mizuhasu(&otehon);
		if (i == 0 || score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
#ifdef ENABLE_REVERSE
	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i - (j % KIND) + KIND) % KIND;
		score = mizuhasu(&otehon);
		if (score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
#endif
	otehon = saikyou;

	for (i = 0; i < SEDAISUU; i++) {
		struct horieyui saituyo;
		int saituyo_score = 0;
		for (j = 0; j < KOTAISUU; j++) {
			struct horieyui kore = otehon;
			int k;
			int score;
			for(k = 0; k < D; k++) {
				if (randint2(10000) < KAKURITU) {
					kore.mamegu[k] = randint2(KIND - 1);
					if (kore.mamegu[k] >= otehon.mamegu[k]) kore.mamegu[k]++;
				}
			}
			score = mizuhasu(&kore);
			if (j == 0 || score > saituyo_score) {
				saituyo = kore;
				saituyo_score = score;
			}
		}
#ifdef NO_FORCE_UPDATE
		if (saituyo_score > saikyou_score)
#endif
		otehon = saituyo;
		if (saituyo_score > saikyou_score) {
#ifdef PRINT_UPDATE
			fprintf(stderr, "update at generation %d : %d -> %d\n", i + 1, saikyou_score, saituyo_score);
#endif
			saikyou = saituyo;
			saikyou_score = saituyo_score;
		}
	}
	for (i = 0; i < D; i++) {
		printf("%d\n", saikyou.mamegu[i] + 1);
	}
#ifdef PRINT_SCORE
	printf("score = %d\n", saikyou_score < -1000000 ? 0 : 1000000 + saikyou_score);
#endif
	return 0;
}


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

int main(){
    int n; cin >> n;
    map<string,int> S;
    for(int i=0;i<n;i++){
        string s; cin >> s;
        if(S.count(s)){
            S.at(s)++;
        }else{
            S[s] = 1;
        }
    }

    int m; cin >> m;
    for(int i=0;i<m;i++){
        string t; cin >> t;
        if(S.count(t)){
            S.at(t)--;
        }else{
            S[t] = -1;
        }
    }

    int ans = -10000;
    for(auto p : S){
        auto A = p.second;
        ans = max(ans,A);
    }
    
    if(ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}



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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i=0;i<n;i++) cin >> h[i];
    bool flag=true;
    for (int i=n-1;i>0;i--) {
        if (h[i-1]>h[i]) {
            h[i-1]--;
            if (h[i-1]>h[i]) {
                flag=false;
                break;
            }
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 768
import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(lambda: collections.defaultdict(int))
G2 = collections.defaultdict(lambda: collections.defaultdict(int))

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b


def dijkstra(V, G, start):
    INF = float('inf')
    D = [INF for _ in range(V)]
    D[start] = 0
    H = [(0, start)]
    while H:
        du, u = heappop(H)
        if D[u] < du:
            continue
        for v, d in G[u].items():
            if D[v] > du + d:
                D[v] = du + d
                heappush(H, (D[v], v))
    return D


D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [10**15 - sum(_) for _ in zip(D1, D2)]
for i in range(N - 1, 0, -1):
    D[i - 1] = max(D[i - 1], D[i])
print(*D, sep='\n')


Measured memory_bytes: 167252
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

int popcount(int x) {
  int a = 0;
  while (x > 0) {
    if (x & 1) a++;
    x >>= 1;
  }
  return a;
}

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  ll ans = 0;
  ll x = 1;
  for (int k = 0; k < 61; k++) {
    ll t = 0;
    ll f = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] & 1) t++;
      else f++;
    }
    for (int i = 0; i < n; i++) {
      if (a[i] & 1) {
        t--;
        ans = (ans + (x * f)) % mod;
      }
      else {
        f--;
        ans = (ans + (x * t)) % mod;
      }
    }
    for (int i = 0; i < n; i++) {
      a[i] >>= 1;
    }
    x = (x << 1) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
s = list(input())
s = list(set(s))
flag = True
if "N" in s and not "S" in s:
    flag = False
if "S" in s and not "N" in s:
    flag = False
if "E" in s and not "W" in s:
    flag = False
if "W" in s and not "E" in s:
    flag = False
print("Yes" if flag else "No")

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

using namespace std;
int sieve[1000005]= {0}, n, i, j, cnt=0;;
int main()
{
    while(cin>>n)
    {
        cnt=0;
        for(i=2; i<=n+2; i++)
        {
            if(!sieve[i])
            {
                for(j=2*i; j<=n+1; j+=i)
                {
                    sieve[j]=1;
                }
            }
        }

        for(i=2; i<=n; i++)
        {
            if(!sieve[i])
            {
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 6968
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int ar[N + 5];
int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	int now = 0;
	int maks = 0;
	for(int i = 0;i < n; ++i){
		scanf("%d", &ar[i]);
		maks = max(maks, ar[i]);
		now = __gcd(now, ar[i]);
	}
	if(maks < k){
		puts("IMPOSSIBLE");
		return 0;
	}
	if(__gcd(now, k) == now){
		puts("POSSIBLE");
	}
	else{
		puts("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#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) begin(x),end(x)
typedef long long ll; 
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	map<int, int> a;
	int N;
	cin>>N;
	rep(i,N){
		int x;
		cin>>x;
		a[x]++;
	}
	int ans = 0;
	for(auto x : a){
		if(x.second < x.first){ans += x.second; continue;}
		ans += x.second-x.first;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb; 

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


int main() {
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> A[i];
    }
    B = A;

    sort(B.begin(),B.end());

    rep(i,N){
        if(A[i] == B[N-1]){
            cout << B[N-2] << endl;
        }else{
            cout << B[N-1] << endl;
        }
    }
}


Measured memory_bytes: 6360
h, w = map(int, input().split())

newGrid = []
for i in range(h):
    a = list(input())
    for j,a_j in enumerate(a):
        if a_j == "#":
            newGrid.append(a)
            break
        else:
            continue

ans = []
for j in range(w):
    for i in range(len(newGrid)):
        if newGrid[i][j] == "#":
            ans.append([newGrid[k][j] for k in range(len(newGrid))])
            break
        else:
            continue
            
for ansi in list(zip(*ans)):
    print("".join(ansi))

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...) (void)0
#endif // sahdsg
#define REP(r,x,y) for(register int r=(x); r<y; r++)
using namespace std;
typedef long long LL;
inline void read(int&x) {
	x=0;char ch=getchar(); while(ch<'0') ch=getchar();
	while(ch>='0') x=x*10+ch-'0',ch=getchar();
}
map<int,int> a;
int main()
{
	int n; read(n);
	REP(i,0,n) {
		int t; read(t);
		if(a.count(t)==0) a[t]=0;
		a[t]++;
	}
	int ans=0;
	for(map<int,int>::reverse_iterator it=a.rbegin(); it!=a.rend(); it++) {
		int now=it->first;
		int k=now;
		k|=k>>1;
		k|=k>>2;
		k|=k>>4;
		k|=k>>8;
		k|=k>>16;
		k++;
		k-=now;
		DBG("%d %d %d\n", k, now, a[k]);
		if(k==now) ans+=a[k]/2,it->second%=2;
		else ans+=min(it->second,a[k]),a[k]-=min(it->second,a[k]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 64256
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(1000000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))

    N = int(input())
    m = float('inf')
    for i in range(1, int(math.sqrt(N))+1):
        if N % i == 0:
            j = N // i
            m = min(m, i+j-2)
    print(m)


if __name__ == "__main__":
    main()


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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N)cin >> A[i];

	vector<pair<int, int>> vpii;
	rep(i, N)vpii.push_back({ A[i],i });
	sort(vpii.begin(), vpii.end());

	for (auto p : vpii)cout << p.second + 1 << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 2164
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());

//グラフ理論用変数
//vector<vector<llong> > graph(N);

int main(){
    string S;
    string T;
    cin >> S;
    cin >> T;
    llong ans=0;
    for(int i=0; i<S.size(); i++){
        if(S[i]!=T[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n;
  	int sum=0;
  	cin>>n;
  	vector<int>v(n);
  	vector<int>c(n);
  	for(int i=0;i<n;++i)cin>>v[i];
  	for(int i=0;i<n;++i)cin>>c[i];
  	for(int i=0;i<n;++i){
    	if(v[i]-c[i]>0)sum+=(v[i]-c[i]);
    }
  	cout<<sum<<endl;
  	return 0;
}

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


unsigned long int nxt = 1;

int getrand(int RANGE=1000000007)
{
    nxt = nxt*1103515245+12345;
    return (nxt) % RANGE;
}

void Srand(unsigned long int seed)
{
    nxt = seed;
}

class Treap
{
    typedef struct _Node
    {
        int x,y,cnt;
        _Node *l,*r;
        _Node(int _x) : x(_x),y(getrand()),cnt(1),l(NULL),r(NULL) {}
        ~_Node()
        {
            delete l;
            delete r;
        }
        void recalc()
        {
            cnt = 1;
            if(l)
                cnt+=l->cnt;
            if(r)
                cnt+=r->cnt;
        }
    }
    *Node;
    Node merge(Node l,Node r)
    {
        if(!l || !r)
            return l?l:r;
        if(l->y < r->y)
        {
            l->r = merge(l->r,r);
            l->recalc();
            return l;
        }
        else
        {
            r->l = merge(l,r->l);
            r->recalc();
            return r;
        }
    }
    void split(Node v,int x,Node &l,Node &r)
    {
        l = r = NULL;
        if(!v)
            return;
        if(v->x < x)
        {
            split(v->r,x,v->r,r);
            l = v;
        }
        else
        {
            split(v->l,x,l,v->l);
            r = v;
        }
        v->recalc();
    }
    Node root;
public:
    Treap():root(NULL) {}
    ~Treap()
    {
        delete root;
    }
    bool search(Node v,int x)
    {
        if(!v) return 0;
        if(v->x == x) return 1;
        else if(v->x > x) return search(v->l,x);
        else return search(v->r,x);
    }
    bool search(int x)
    {
        return search(root,x);
    }
    void insert(int x)
    {
        if(search(x)) return;
        Node l,r;
        split(root,x,l,r);
        root = merge(merge(l,new _Node(x)),r);
    }

    void erase(int x)
    {
        Node l,m,r;
        split(root,x,l,m);
        split(m,x+1,m,r);
        //assert(m && m->cnt == 1 && m->x == x);
        delete m;
        root = merge(l,r);
    }
    void printTreap(Node v)
    {
        if(!v) return;
        printf("v : %d  p : %d  cnt : %d\n",v->x,v->y,v->cnt);
        printTreap(v->l);
        printTreap(v->r);
    }
    void printTreap()
    {
        printTreap(root);
    }
    void inorder(Node v)
    {
        if(!v) return;
        inorder(v->l);
        printf("%d ",v->x);
        inorder(v->r);
    }
    void inorder()
    {
        inorder(root);
    }
    /*
    int k_th_node(Node v,int k)
    {
        if()
    }
    int k_th_node(int k)
    {
        return k_th_node(root,k);
    }
    */
    int size() const
    {
        return root? root->cnt : 0;
    }
};

int main()
{
    Srand(2333333);
    Treap st;
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a==0)
        {
            st.insert(b);
            printf("%d\n",st.size());
        }
        else if(a==1)
        {
            printf("%d\n",st.search(b));
        }
        else if(a==2)
        {
            st.erase(b);
        }
    }
    return 0;
}



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

using lint = int64_t;
using std::vector;

int n, cnt, p1, d, d1;
lint sum;
int f[10000010], divisor[10000010];
bool is_prime[10000010], used[10000010];
int main() {
	scanf("%lld", &n);
	f[1] = 1;
	for (int i = 2; i <= n; ++i) {
		if (!used[i]) {
			is_prime[i] = true;
			for (int j = 2, end = n / i; j <= end; ++j) {
				int k = i * j;
				used[k] = true;
				is_prime[k] = false;
				divisor[k] = i;
			}
		}
	}
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) f[i] = 2;
		else {
			p1 = divisor[i];
			d = i / p1;
			if (p1 == d) {
				f[i] = f[d] + 1;
			}
			else {
				cnt = 0, d1 = d;
				while (d1 % p1 == 0) {
					cnt++;
					d1 /= p1;
				}
				f[i] = f[d] / (cnt + 1) * (cnt + 2);
			}
		}
		sum += (lint)i * f[i];
	}
	printf("%lld\n", sum + 1);
}


Measured memory_bytes: 101452
#include<iostream>
#define MAXN 2048
using namespace std;
int tot;
int n;
struct ST{
	int l,r,num;
}tree[MAXN];
void s(int i){
	tot++;
	if (tree[i].l != -1) s(tree[i].l);
	if (tree[i].r != -1) s(tree[i].r);
}
void s1(int i){
	cout<<" "<<i;
	if (tree[i].l != -1) s1(tree[i].l);
	if (tree[i].r != -1) s1(tree[i].r);
}

void s2(int i){
	if (tree[i].l != -1) s2(tree[i].l);
	cout<<" "<<i;
	if (tree[i].r != -1) s2(tree[i].r);
}

void s3(int i){
	if (tree[i].l != -1) s3(tree[i].l);
	if (tree[i].r != -1) s3(tree[i].r);
	cout<<" "<<i;
}

int f;
int main(){
	int i,a;
	cin>>n;
	for (i = 0;i <= n;++i){
		tree[i].l=tree[i].r=-1;
	}
	
	//cin>>tree[0].num>>tree[0].l>>tree[0].r;
	for (i = 0;i < n;++i){
		cin>>a;
		cin>>tree[a].l>>tree[a].r;
	}
	for (i = 0;i < n;++i){
		tot=0;
		s(i);
		if (tot == n) {
			f=i;
			break;
		}
	}
	cout<<"Preorder\n";
	s1(f);
	cout<<"\n";
	cout<<"Inorder\n";
	s2(f);
	cout<<"\n";
	cout<<"Postorder\n";
	s3(f);
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 3112
init=list(map(int,input().split()))
nm=[[0 for i in range(init[1])] for j in range(init[0])]
m1=[0 for i in range(init[1])]
res=[0 for i in range(init[0])]

for i in range(init[0]):
    row=list(map(int,input().split())) 
    for j in range(init[1]):
        nm[i][j]=row[j]

for i in range(init[1]):
    m1[i]=int(input())


#solve
for i in range(init[0]):
    sum=0
    for j in range(init[1]):
        sum+=nm[i][j]*m1[j]
    res[i]=sum


for i in range(init[0]):
    print(res[i])


Measured memory_bytes: 6008
x,y = map(int,input().split())
money = 0
if x == 1:
    money += 300000
if y == 1:
    money += 300000
if x == 2:
    money += 200000
if y == 2:
    money += 200000
if x == 3:
    money += 100000
if y == 3:
    money += 100000
if x == 1 and y == 1:
    money += 400000
print(money)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

int matrix[16][16];

int main(){
    int n,i,j;

    while( cin >> n, n ){
        // input
        rep(i,n) rep(j,n) cin >> matrix[i][j];

        // yoko
        rep(i,n){
            int yoko = 0;
            rep(j,n) yoko += matrix[i][j];
            matrix[i][n] = yoko;
        }

        // tate
        rep(j,n){
            int tate = 0;
            rep(i,n) tate += matrix[i][j];
            matrix[n][j] = tate;
        }

        int sum = 0;
        rep(i,n) sum += matrix[i][n];
        matrix[n][n] = sum;

        // output
        rep(i,n+1){
            rep(j,n+1){
                printf("%5d",matrix[i][j]);
            }
            puts("");
        }
    }

    return 0;
}

Measured memory_bytes: 0
/*
[abc150] D - Semi Common Multiple
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;

int N, M;
int A[MAX_N];

ll gcd(ll a, ll b) {
    while (b > 0) {
        swap(b, a %= b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    ll d = gcd(a, b);
    return a * b / d;
}

ll solve() {
    ll l = 1;
    for (int i = 0; i < N; i++) {
        l = lcm(l, A[i] / 2);
        if (l > M) {
            return 0;
        }
    }
    for (int i = 0; i < N; i++) {
        if ((l / (A[i] / 2)) % 2 == 0) {
            return 0;
        }
    }

    int ans = (M - l) / (2 * l) + 1;

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

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

int main(){
	ll n;
	int a[2][3];
	scanf("%lld",&n);
	for(int i = 0 ; i < 2 ; i ++){
		for(int j = 0 ; j < 3 ; j ++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(int i = 0 ; i < 2 ; i ++){
		static ll dp[5002*5002];
		for(int k = 0 ; k < 5002*5002 ; k ++)dp[k] = n-k;
		for(int j = 0 ; j < 3 ; j ++){
			for(int k = 0 ; k+a[i][j] < 5002*5002 ; k ++){
				dp[k+a[i][j]] = max ( dp[k+a[i][j]] , dp[k]+a[i^1][j]-a[i][j] );
			}
		}
		ll n_ = 0;
		for(int k = 0 ; k <= n ; k ++){
			n_ = max ( n_ , dp[k] );
		}
		n = n_;
	}
	cout << n << endl;
}

Measured memory_bytes: 195712
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 10**18
    for i in range(n-k+1):
        ans = min([ans, abs(a[i])+abs(a[i]-a[i+k-1]),\
                abs(a[i+k-1])+abs(a[i]-a[i+k-1])])
    print(ans)
        

    
if __name__ == '__main__':
    main()

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

#define SPEED cin.tie(0);ios::sync_with_stdio(false);
template <class T> void chmax(T& a, const T b){a=max(a,b);}

int main() {
    SPEED
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for(int i = 1; i <= N; ++i) cin >> V[i] >> W[i];

    //O(Q)
    const int nl = 1<<10,nr=1<<8,L_max=100001;
    vector<int> msb(nl,0);
    for(int i = 1; i < nl; ++i) msb[i]=31-__builtin_clz(i);

    vector<int> bit_w_dp(nl,0);
    vector<int> bit_v_dp(nl,0);
    vector<vector<int>> dp(nl,vector<int>(L_max,0));
    //前計算
    int m = min(nl,N+1);
    for(int n = 1; n < m; ++n) {
        int k = 2*n;
        vector<int> l;
        while(k/=2) l.push_back(k);
        int sz=l.size();
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[l[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[l[msb[i]]];
            if(bit_w_dp[i]<=L_max) chmax(dp[n][bit_w_dp[i]],bit_v_dp[i]);
        }
        //累積max
        for(int i = 1; i < L_max; ++i) {
            chmax(dp[n][i],dp[n][i-1]);
        }
    }

    int Q; cin >> Q;
    string ans_str="";

    //クエリ
    while(Q--) {
        int p,L,l_idx=0;; cin >> p >> L;
        vector<int> r;
        p *= 2;
        while(p/=2) {
            if(p<nl) chmax(l_idx,p);
            else r.push_back(p);
        }
        int sz = r.size(),ans=dp[l_idx][L];
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[r[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[r[msb[i]]];
            if(bit_w_dp[i]<=L) chmax(ans,dp[l_idx][L - bit_w_dp[i]]+bit_v_dp[i]);
        }
        ans_str += to_string(ans)+"\n";
    }
    cout << ans_str;

    return 0;
}


Measured memory_bytes: 408248
#include <bits/stdc++.h>
#define repz(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;
void debug_out(){ cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// 1E+9 +7
const ll mod = 1000000000+7;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int k,n; cin >> k >> n;
  vector<int> a(n);
  vector<int> d(n);
  int sum;
  rep(i,n){
    cin >> a[i];
    if(i>0) d[i]=a[i]-a[i-1];
    if(i==n-1) d[0]=k+a[0]-a[n-1]; 
  }
//  for(auto i:d) cout << i << endl;
  cout << accumulate(ALL(d),0)-MAX(d);  
  return 0;
}


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

int main(){
    ll N;
    cin >> N;
    ll a=1;
    for(ll i=2;i*i<=N;i++) {
        if(N%i == 0) a = i;
    }
    cout << a+(N/a)-2 << endl;

}


    


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    char a;
    cin>>a;
    if (a==toupper(a)) cout<<'A'<<endl;
    else cout<<'a'<<endl;
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var p = Input().ToInt();
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			for(int j = i; j < n; j++)
			{
				if(i==j)continue;
				wa+=p[i]*p[j];
			}
		
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}

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

int main(){
	ll a;
	double b;
	cin >> a >> b;
	ll c = b*100 + 0.1;
	ll d = a*c;
	ll e = d/100;
	cout << e << endl;
}

Measured memory_bytes: 3660
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				System.out.println(process.split(" ")[0] + " " + current_time);
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
		}

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

}

Measured memory_bytes: 161428
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#define MOD 998244353
using namespace std;
typedef long long ll;
int main() {
  ll h, w, n;
  char s[10][10];
  scanf("%lld%lld%lld", &h, &w, &n);

  printf("%lld\n", (n + max(h, w) - 1) / max(h, w));
}

Measured memory_bytes: 128