akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define update(a, b) a = add(a + b) 
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
const int mod = 1e9 + 7;
const int maxn = 50 + 5;
int n;
int a[maxn << 1];
int f[maxn][maxn << 1][maxn << 1];
bool vis[maxn << 1];
inline int add(int x) {
	return x >= mod ? x - mod : x;
}
int solve() {
	sort(a + 1, a + 2 * n);
	f[n][0][0] = 1;
	vis[a[n]] = 1;
	for(int x = n, i = n - 1, j = n + 1; x > 1; --x, --i, ++j) {
		bool d = 0, e = 0;
		if(!vis[a[i]]) vis[a[i]] = d = 1;
		if(!vis[a[j]]) vis[a[j]] = e = 1;
		for(int y = 0; y <= n * 2; ++y) {
			for(int z = 0; z <= n * 2; ++z) if(f[x][y][z]) {
				update(f[x - 1][y + d][z + e], f[x][y][z]);
				for(int k = 1; k <= y + d; ++k) {
					update(f[x - 1][k - 1][z + e + 1], f[x][y][z]);
				}
				for(int k = 1; k <= z + e; ++k) {
					update(f[x - 1][y + d + 1][k - 1], f[x][y][z]);
				}
			}
		}
	}
	int an = 0;
	for(int i = 0; i <= n * 2; ++i) {
		for(int j = 0; j <= n * 2; ++j) {
			update(an, f[1][i][j]);
		}
	}
	return an;
}
int main() {
	read(n);
	for(int i = 1; i <= 2 * n - 1; ++i) {
		read(a[i]);
	}
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define MAXN 200010
#define LL long long
using namespace std;

const LL P=1000000007;

int n,a[MAXN];
int mins[MAXN],maxs[MAXN];
int p[MAXN];

namespace Queue{
	queue< pair<int,LL> > Q;
	LL s=0;

	void push(int x,LL y){
		Q.push(make_pair(x,y));
		s=(s+y)%P;
	}

	void pop(){
		s=(s-Q.front().second+P)%P;
		Q.pop();
	}
}

void init(){
	static pair<int,int> v0[MAXN];
	for(int i=1;i<=n;i++)
		scanf("%d%d",&v0[i].first,&v0[i].second);
	sort(v0+1,v0+n+1);
	for(int i=1;i<=n;i++) a[i]=v0[i].second;
	maxs[1]=a[1];
	for(int i=2;i<=n;i++) maxs[i]=max(maxs[i-1],a[i]);
	mins[n]=a[n];
	for(int i=n-1;i>=1;i--) mins[i]=min(mins[i+1],a[i]);
}

void getP(int x){
	int l=1,r=x;
	while(l<r){
		int mid=(l+r)>>1;
		if(maxs[mid]>a[x]) r=mid;
		else l=mid+1;
	}
	int p0=l;
	l=x; r=n;
	while(l<r){
		int mid=(l+r+1)>>1;
		if(mins[mid]<a[x]) l=mid;
		else r=mid-1;
	}
	int p1=l;
	p[p1]=max(p[p1],p0);
}

void dp(){
	Queue::push(0,1);
	for(int i=1;i<=n;i++){
		Queue::push(i,Queue::s);
		while(p[i] && Queue::Q.front().first<p[i]) Queue::pop();
	}
}

int main(){
	scanf("%d",&n);
	init();
	for(int i=1;i<=n;i++) getP(i);
	dp();
	printf("%lld\n",Queue::s);
	return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e4+7;
const ll INF = (ll)1e18+7;

int val[MAXN],wei[MAXN];
ll dp[MAXN];

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

    int H,N;
    cin >> H >> N;
    rep(i,1,N) {
        cin >> val[i] >> wei[i];
    }
    rep(i,1,H) dp[i] = INF;
    rep(i,1,N) {
        rep(j,0,H) {
            int toH = j+val[i];
            toH = min(toH,H);
            dp[toH] = min(dp[toH],dp[j]+wei[i]);
        }
    }
    cout << dp[H] << endl;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int nums[n];
  map<int, int> mp;
  int ans = 0;
  REP(i,n) {
    cin >> nums[i];
    if(++mp[nums[i]] % 2 != 0) ++ans;
    else --ans;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

ll fac(ll n){  // 階乗
	ll sum = 1;
	for(ll i=1; i <= n; i++){ sum *= i; }
	return sum;
}

int main() {
  ll n, m, k, x, y = 0, z = 0, h, ans=0, w, sum = 0, Max = -1, Min = 1e9+1;
  string s, t, u;
  bool ok=true;
  cin >> n;
  VI a(1001);
  for(int i=1; i<=n; i++){
    x = i;
    for(int j=2; j<=n;j++){
      while(x%j==0){
        a[j]++;
        x/=j;
      }
    }
  }
  ans = 1;
  rep2(i,2,n+1) ans = ans * (a[i]+1) % mod;
  pri(ans);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define p pair<ll,ll>
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
ll mod= 1e9+7;
ll a[200005];
void init()
{
     a[1]=1;
     for(int i=2;i<=200000;i++)
      {
           a[i] = a[i-1]+i ;
      }
}
int main()
{     
    //   init();
    // ll n,k;
    // cin>>n>>k;
    // ll ans=0;
    // for(int i=k;i<=n+1;i++)
    //   {   if(i==n+1){ans++;continue;}
    //      ans+=  ( a[n]-a[n-i] -a[i-1] +1   )%mod;

    //   }
    // cout<<ans%mod<<endl;
    int a,b;cin>>a>>b;
    if(a>b)cout<<"safe";
    else  cout<<"unsafe";
    return 0;
}



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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
//const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

signed main()
{
	int h,w; cin >> h >> w;

	vector<vector<char>> c(h+2, vector<char>(w+2));

int cnt{};
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;	
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    S = Counter(A)
    V = sorted(list(S.values()), reverse=True)
    print(sum(V) - sum(V[:K]))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 95188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 5000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

//power_mod
inline int Pow_mod(int x, int pow){
    if(pow==0) return 1;
    int a=Pow_mod(x, pow/2);
    a=a*a%mod;
    if(pow%2==1) a*=x;
    return a%mod;
}

//factorial_mod
int fact[200010];
inline int factorial_mod(int x){
    if(x==0)return 1;
    if(fact[x]!=0)return fact[x];
    else return fact[x]=(factorial_mod(x-1)*x)%mod;
}

//permutation_mod
inline int nPr_mod(int n, int r){
    int res=1;
    for(int i=n; i>n-r; i--){
        res=(res*i)%mod;
    }
    return res;
}

//combination_mod
inline int nCr_mod(int n, int r){
    return factorial_mod(n)*Pow_mod(factorial_mod(r)*factorial_mod(n-r)%mod, mod-2)%mod;
}

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<int> vec;
    for(int i=2; i<=m; i++){
        if(m%i==0){
            vec.push_back(0);
            while(m%i==0){
                m/=i;
                vec.back()++;
            }
        }
    }
    vector<int> comb(vec.size());
    rep(i,vec.size()){
        comb.at(i)=nCr_mod(vec.at(i)+n-1, n-1);
    }
    int ans=1;
    rep(i,comb.size()){
        ans=(ans*comb.at(i))%mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2688
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    println!("{}", n / 3);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int fiveCount = 0;
		int sevenCount = 0;
		int total = 0;

	    int[] array = new int[3];
	    for(int i = 0; i<3; i++){
	        array[i] = sc.nextInt();
	    }

	    for(int i = 0; i < array.length; i++) {
	    	total += array[i];
	    	if(array[i] == 5) {
	    		fiveCount++;
	    	}else if(array[i] == 7) {
	    		sevenCount++;
	    	}
	    }

		if(total != 17) {
			System.out.println("NO");
		}else if(fiveCount != 2 && sevenCount != 1) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
	}
}


Measured memory_bytes: 21204
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int M=6000;
int n,mod;
int f[6005][12005];
long long ans=0;
int add(int v)
{
	return v>=mod?v-mod:v;
}
int main()
{
	scanf("%d%d",&n,&mod);n*=3;
	f[0][M]=1;
	for(int i=0;i<n;i++)
	for(int j=-i;j<=i;j++)
	{
		f[i+1][j+M+1]=add(f[i+1][j+M+1]+f[i][j+M]);
		f[i+3][j+M]=add(f[i+3][j+M]+1ll*f[i][j+M]*(i+1)%mod*(i+2)%mod);
		f[i+2][j+M-1]=add(f[i+2][j+M-1]+1ll*f[i][j+M]*(i+1)%mod);
	}
	for(int i=0;i<=n;i++) ans=(ans+f[n][i+M])%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 167428
lines = $stdin.read.split("\n")
N,M=lines.shift.split(" ").map(&:to_i)
Hs = lines.shift.split(" ").map(&:to_i)

res = (1..N).map{|x| [x, 1]}.to_h
lines.each do |line|
  a,b=line.split(" ").map(&:to_i)
  if Hs[a-1] == Hs[b-1]
    res[a]=0
    res[b]=0
  elsif Hs[a-1] > Hs[b-1]
    res[b]=0
  else
    res[a]=0
  end
end

puts res.values.sum

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

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> fac(n+1);
  vector<ll> val(n+1);
  fac[0] = 1;
  rep(i,n) fac[i+1] = mu(fac[i], (i+1));
  rep1(i,n) val[i] = dv(fac[n],i);
  ll sum = 0;
  rep1(i,n) sum = ad(sum,val[i]);
  vector<ll> a(n);
  ll ans = 0;
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    // cout << sum << endl;
    ans = ad(ans,mu(sum,a[i]));
    if(i==n-1) break;
    sum = ad(sum,mod - val[n-i]);
    sum = ad(sum,val[i+2]);
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 2560
#include <iostream>
#include <map>

int main(){

  int N;
  std::cin >> N;

  int n[N];
  int emps[N];

  for(int i=0;i<N;i++){
    n[i] = 0;
  }

  for(int i=1; i<N; i++){
   std::cin >> emps[i];
  }

  for(int i=1; i<N; i++){
    n[emps[i]-1]++;
  }


  for(int i=0; i<N; i++){
    std::cout << n[i] << std::endl;
  }


  return 0;
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)
 
#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second
 
#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";
 
const int logN = 20;
const int M = 1000000007;
const int INF = 1e18;
#define PI 3.14159265;
const int N = 200005;
 
#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>
 
void solve()
{
       int n,ans=1;
       cin>>n;
       rep(c,0,n)
       {
              int x;
              cin>>x;
              if(x>floor((INF)/(ans)))
              {
                     rep(d,c+1,n)
                     {
                            int y;
                            cin>>y;
                            if(y==0)
                            {
                                   cout<<"0";
                                   return;
                            }
                     }
                     cout<<"-1";
                     return;
              }
              else
              {
                     ans*=x;
              }
       }
       cout<<precise(0)<<ans;
}
 
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 3668
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n, q; rd(n, q);
  auto tree=new SquareRootDecomposition(n);
  while(q--){
    auto args=readln.split.to!(int[]);
    if(args[0]==0){
      tree.add(args[1], args[2]+1, args[3]);
    }else{
      writeln(tree.rmin(args[1], args[2]+1));
    }
  }
}

class SquareRootDecomposition{
  import std.algorithm;
  int D=1;
  int[] val, buc, laz;
  this(int n){
    while(D*D<n) D++;
    val.length=D*D;
    buc.length=laz.length=D;
  }

  void add(int ql, int qr, int x){
    foreach(k; 0..D){
      int l=k*D, r=(k+1)*D;
      if(r<=ql || qr<=l){
        // 
      }else if(ql<=l && r<=qr){
        buc[k]+=x;
        laz[k]+=x;
      }else{
        push(k);
        foreach(i; max(l, ql)..min(r, qr)){
          val[i]+=x;
        }
        buc[k]=reduce!(min)(val[l..r]);
      }
    }
  }

  int rmin(int ql, int qr){
    int ret=1_000_000_000;
    foreach(k; 0..D){
      int l=k*D, r=(k+1)*D;
      if(r<=ql || qr<=l){
        // 
      }else if(ql<=l && r<=qr){
        chmin(ret, buc[k]);
      }else{
        push(k);
        foreach(i; max(l, ql)..min(r, qr)) chmin(ret, val[i]);
      }
    }
    return ret;
  }

  void push(int k){
    val[(k*D)..((k+1)*D)]+=laz[k];
    laz[k]=0;
  }

  void chmin(T)(ref T l, T r){
    if(l>r) l=r;
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int main() {
    int W; 
    int W1 = 0;
    int H; 
    int H1 = 0;
    int x; 
    int y; 
    int r; 
    cin >> W >> H >> x >> y >> r;
    
    if (W >= (x + r) && W1 <= (x - r) && H >= (y + r) && H1 <= (y - r))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    };
}


Measured memory_bytes: 3112
import scala.io.StdIn.readLine

object Main {
  val daysOfMonth = List(31,29,31,30,31,30,31,31,30,31,30,31)
  val days = Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

  def getDays(sb:StringBuilder):Unit = {
    val r = readLine.split(" ").map(_.toInt)

    if(r(0)==0 && r(1)==0) print(sb.result)
    else {
      sb.append(days((daysOfMonth.take(r(0)-1).sum + r(1) + 3) % 7) + "\n")
      getDays(sb)
    }
  }

  def main(args:Array[String]) = getDays(new StringBuilder)
}

Measured memory_bytes: 43624
#include<stdio.h>

int main(void){
  
  char S[256];
  int i;
  int count = 0;
  int max = 0;
  
  scanf("%s", &S);
  
  for(i = 0; S[i]; i++){
   
    if(S[i] == 'A') count++;
    else if(S[i] == 'T') count++;
    else if(S[i] == 'G') count++;
    else if(S[i] == 'C') count++;
    else {
      if(count >= max) max = count;
      count = 0;
    }
  }
  
  if(count > max) max = count;
  
  printf("%d\n", max);
    
  

  
  return 0;
}
  
  

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

using namespace std;

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

    int h[n];
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    // a[i] is the minimum steps to reach the the i'th stone
    int a[n] = {};
    a[0] = 0;
    a[1] = abs(h[1] - h[0]);

    int mi;
    for(int i = 2; i < n; i++)
    {
        mi = INT_MAX;
        for(int j = 1; j <= k && j <= i; j++)
        {
            mi = min(mi, (a[i - j] + abs(h[i] - h[i - j])));
        }
        a[i] = mi;
    }
    cout << a[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;


int count(long n){
	int c=0;
	while(n!=0){
		if(n%10==4 || n%10==7){
			c++;
			n=n/10;
		}else{
			n=n/10;
		}
	}
	return c;
}

int main(){
	int n;
	cin >> n;
	int array[n+1];
	int max=0;
	int sum=0;
	for(int i=1;i<n+1;i++){
		cin >> array[i];
		sum+=array[i];
		if(array[i]>max){
			max=array[i];
		}
	}	
	sum=sum-max;
	if(sum>max){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

#include <atcoder/all>
using namespace atcoder;

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	vector<ll> c = convolution(a, b);
	rep(i, n + m - 1) cout << c[i] << ' ';
	cout << '\n';
}

Measured memory_bytes: 27256
def pre(k):
    global nodes

    print(' ' + str(k), end= '')

    if nodes[k][1] != -1:
        pre(nodes[k][1])

    if nodes[k][2] != -1:
        pre(nodes[k][2])

def ino(k):
    global nodes

    if nodes[k][1] != -1:
        ino(nodes[k][1])

    print(' ' + str(k), end= '')

    if nodes[k][2] != -1:
        ino(nodes[k][2])
    


def pos(k):
    global nodes

    if nodes[k][1] != -1:
        pos(nodes[k][1])

    if nodes[k][2] != -1:
        pos(nodes[k][2])


    print(' ' + str(k), end= '')



n = int(input())
nodes = []

for i in range(n):
    nodes.append([-1])


for i in range(n):
    a = list(map(int, input().split()))
    if a[1] != -1:
        nodes[a[1]][0] = a[0]
    if a[2] != -1:
        nodes[a[2]][0] = a[0]
    
    nodes[a[0]] += a[1:]

for i in range(len(nodes)):
    if nodes[i][0] == -1:
        ro = i
        break

print('Preorder')
pre(ro)
print()
print('Inorder')
ino(ro)
print()
print('Postorder')
pos(ro)
print()


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

int main() 
{
	int n;
	cin >> n;
	long double a[n];
	for(int i=0;i<n&&cin>>a[i];i++);
	sort(a,a+n);
	long double ans=a[0];
	for(int i=1;i<n;i++)
		ans+=a[i],ans/=2;
	cout<<ans;
}

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


signed main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll ans = 0;

    h = min(h, q*2);
    s = min(s, 2*h);

    if(2*s < d){
        ans = n * s;
    }else{
        if(n % 2 == 0){
            ans = n * d / 2;
        }else{
            ans = (n-1) * d / 2+ s;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            int[] counts = new int[101];
            while (true) {
                String[] values = line.split(" ");
                int a = Integer.parseInt(values[0]);
                int b = Integer.parseInt(values[1]);
                if (a == 0 && b == 0) {
                    break;
                }
                counts[a]++;
                counts[b]++;
                line = reader.readLine();
            }
            String result = "NG";
            if (counts[1] % 2 == 1 && counts[2] % 2 == 1) {
                boolean found = false;
                for (int i = 3; i <= 100; i++) {
                    if (counts[i] % 2 != 0) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    result = "OK";
                }
            }
            out.println(result);
        }
    }
}

Measured memory_bytes: 10000
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		String[] s = stdIn.next().split("");
		
		long a = 0;
		for(int i = 0; i < s.length; i++) {
			a += Integer.parseInt(s[i]);
		}
		if(a % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		

	}

}


Measured memory_bytes: 55092
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	int o = 0;
	int ans = 0;
	for (auto& c : str)
	{
		if (c == 'g')
		{
			if (o > 0) ans++, o--;
			else o++;
		}
		else
		{
			if (o > 0) o--;
			else o++, ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int n = s.size();
	vector<int> suf(s.size(), 0);
	suf[n-1] = s[n-1] - '0';
	int ans = 0, pw = 10;
	for (int i = n-2; i >= 0; --i) {
		suf[i] = suf[i+1] + pw*(s[i] - '0'); suf[i] %= 2019;
		pw = (pw * 10) % 2019;
	}
	int ct[2020] = {0}; ct[0] = 1;
	for (int i = n-1; i >= 0; --i) {
		ans += ct[suf[i]];
		++ct[suf[i]];
	}
	cout << ans;
}

Measured memory_bytes: 5188
(defun f (n a b)
  (cond ((or (= a 1) (= n 1)) b)
    ((= (rem n a) 0) (f (/ n a) a (1+ b)))
    (t 0)))

(let ((n (read))
      (flg t))
     (loop for i from n downto 1 while flg do
           (loop for j from i downto 1 while flg do
                 (if (< 1 (f i j 0)) (progn (princ i)
                                            (setf flg nil)))))
     (if flg (princ 1)))

Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
int frogrec(int n,int h[],int track[])
    {
        if (n==1)
        {
            track[0]=0;
            return(track[0]);
        }
        else if (n==2)
        {
            track[1]=abs(h[1]-h[0]);
            return(track[1]);
        }

        else if (track[n]!=0)
        {
            return(track[n]);
        }
        else
        {
            track[n]=min(abs(h[n-1]-h[n-2])+frogrec(n-1,h,track),abs(h[n-1]-h[n-3])+frogrec(n-2,h,track));
            return(track[n]);
        }
    }
int frog1(int n,int h[])
    {
        int track[n+1]={0};
        return(frogrec(n,h,track));

    }
int main()
    {
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int track[n+1]={0};
    track[0]=0;
    track[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        track[i]=min(abs(h[i]-h[i-1])+track[i-1],abs(h[i]-h[i-2])+track[i-2]);
    }
    cout<<track[n-1];
    return(0);
    }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;

int main(){
    int K;
    string S;
    cin>>K>>S;
    for(int i=0;i<S.length();i++){
        if(i<K){
            cout<<S[i];
        }else{
            cout<<"..."<<endl;
            return 0;
        }
    }
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; cin >> n;

    cout << n * n;
}


Measured memory_bytes: 256
#include <stdio.h>

int ori[100000];
int n;

int Partition(int );

int main()
{
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&ori[i]);

  j=Partition(0);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    if(i==j) printf("[");
    printf("%d",ori[i]);
    if(i==j) printf("]");
  }
  printf("\n");
}

int Partition(int x)
{
  int i,j,k,l;

  k=ori[n-1];
  i=x-1;

  for(j=x;j<n-1;j++){
    if(k>=ori[j]){
      i++;
      l=ori[i];
      ori[i]=ori[j];
      ori[j]=l;
    }
  }

  l=ori[i+1];
  ori[i+1]=ori[n-1];
  ori[n-1]=l;

  return i+1;
}



Measured memory_bytes: 2096
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	x := scanInt(sc)
	k := scanInt(sc)
	d := scanInt(sc)
	if k < abs(x/d) {
		return abs(x) - k*d
	}
	x = abs(x)
	r := x % d
	base := k - x/d
	if r > abs(r-d) {
		if base > 0 {
			base--
			r = abs(r - d)
		}
	}
	switch base % 2 {
	case 1:
		return abs(r - d)
	case 0:
		return r
	}
	panic(-1)
}
func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

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

	     }
	     else if(b<=a&&a<=c){
	    	 System.out.println(b + " " + a + " " + c);

	     }
	     
	     else if(c<=a&&a<=b){
	    	 System.out.println(c + " " + a + " " + b);

	     }
	     else if(a<=c&&c<=b){
	    	 System.out.println(a + " " + c + " " + b);

	     }

	     else if(c<=b&&b<=a){
	    	 System.out.println(c + " " + b + " " + a);

	     }

	     else if(b<=c&&c<=a){
	    	 System.out.println(b + " " + c + " " + a);

	     }
	}

}


Measured memory_bytes: 26160
#include<stdio.h>
int main()
  { 
    int n,i,count=0;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
      { 
        scanf("%d",&arr[i]);
      }
  for(i=1;i<=(n-2);i++)
    { 
      if(arr[i]<arr[i+1]&&arr[i-1]<arr[i])
        { count++; }
       if(arr[i]>arr[i+1]&&arr[i-1]>arr[i])
        { count++; }
    }
  printf("%d",count);
  return 0;
  }
      
    
    


Measured memory_bytes: 128
#include <stdio.h>


int main(void)
{
    int N, K,i,j,sum;
    int p[1001];
    scanf("%d %d", &N, &K);
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &p[i]);
    }

    for (i = 1; i < N; i++)
    {
        for (j = i + 1; j <= N; j++)
        {
            
            if (p[i] >= p[j])
            {
                sum = p[i];
                p[i] = p[j];
                p[j] = sum;
            }
        }

    }
    sum = 0;

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


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

int main(){
    int N,T; cin >> N >> T;
    vector<pair<int,int>> dish(N);
    for(int i=0;i<N;i++){
        int a,b; cin >> a >> b;
        dish[i]={a,b};
    }
    int dp1[N+1][T+1];
    int dp2[N+1][T+1];
    memset(dp1,0,sizeof(dp1));
    memset(dp2,0,sizeof(dp2));
    for(int i=0;i<N;i++){
        for(int j=0;j<T;j++){
            if(j-dish[i].first>=0){
                dp1[i+1][j]=max(dp1[i][j-dish[i].first]+dish[i].second,dp1[i][j]);
            }else{
                dp1[i+1][j]=dp1[i][j];
            }
        }
    }
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<T;j++){
            if(j-dish[i].first>=0){
                dp2[i][j]=max(dp2[i+1][j-dish[i].first]+dish[i].second,dp2[i+1][j]);
            }else{
                dp2[i][j]=dp2[i+1][j];
            }
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<T;j++){
            ans=max(ans,dp1[i][j]+dish[i].second+dp2[i+1][T-1-j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 70656
#include <stdio.h>
int main(void){
    char d[5];
    scanf("%s", d);
    if(d[2] == 'N' && d[1] == 'U'){
        printf("7\n");
    }
    else if(d[2] == 'N' && d[1] == 'O'){
        printf("6\n");
    }
    else if(d[2] == 'E'){
        printf("5\n");
    }
    else if(d[2] == 'D'){
        printf("4\n");
    }
    else if(d[2] == 'U'){
        printf("3\n");
    }
    else if(d[2] == 'I'){
        printf("2\n");
    }
    else if(d[2] == 'T'){
        printf("1\n");
    }
    return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・偶数番号、奇数番号の中では入れ替え放題
・偶、奇の間：並べてからスワップ。操作2を1回で、正しいものを2つ増やせる
"""

N,*A = map(int,read().split())

x_to_i = {x:i for i,x in enumerate(sorted(A))}
rank = [x_to_i[x] for x in A]

answer = sum((x^i) & 1 for i,x in enumerate(rank)) // 2
print(answer)

Measured memory_bytes: 21220
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,ans = 0;
    cin >> N;
    char hako;
    string S;
    cin >> S;

    for(ll i = 0;i < S.size();i++){
        if(i == 0 || hako != S.at(i)){
            hako = S.at(i);
            ans++;
        }
    }

    cout << ans << endl;

    
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

int x,y,z,k;

int main() {
	cin >> x >> y >> z >> k;
	vector<ll> a(x);
	vector<ll> b(y);
	vector<ll> c(z);
	for(int i = 0; i < x; i++) { cin >> a[i]; }
	for(int i = 0; i < y; i++) { cin >> b[i]; }
	for(int i = 0; i < z; i++) { cin >> c[i]; }
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	reverse(c.begin(),c.end());

	vector<ll> ab(x*y);
	for(int i = 0; i < x; i++) {
		for(int j = 0; j < y; j++) {
			ab[i*y+j] = a[i]+b[j];
		}
	}
	sort(ab.begin(),ab.end());
	reverse(ab.begin(),ab.end());

	int len = min(k,x*y);
	vector<ll> abc(len*z);
	for(int i = 0; i < len; i++) {
		for(int j = 0; j < z; j++) {
			abc[i*z+j] = ab[i]+c[j];
		}
	}
	sort(abc.begin(),abc.end());
	reverse(abc.begin(),abc.end());

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

	return 0;
}


Measured memory_bytes: 31616
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

long N;
long a[(int)1e5];

//#define LOCAL_DEBUG
int main() {
#ifdef LOCAL_DEBUG
	freopen("input.txt","r", stdin);
#endif

	cin >> N;
	long b = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b += a[i];
	}

	long s = N * (N + 1) / 2;
	if (b % s != 0) {
		cout << "NO" << endl;
		return 0;
	}

	long k = b / s;
	for (int i = 0; i < N; i++) {
		long d = a[(i + 1) % N] - a[i];
		if (d > k) {
			cout << "NO" << endl;
			return 0;
		}
		if ((d - k) % N != 0) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#define INF 1145141919
#define SIZE1 131072
#define SIZE2 262144
using namespace std;

class segtree{
	int score[SIZE1];
	int tree[SIZE2];//not use 0;
public:
	void reset(int n){
		for (int i = 0; i < n; i++){
			score[i] = 0;
		}
		for (int i = n; i < SIZE1; i++){
			score[i] = -INF;
		}
		for (int i = SIZE2 - 1; i >= SIZE1; i--){
			tree[i] = i - SIZE1;
		}
		for (int i = SIZE1 - 1; i >= 1; i--){
			tree[i] = tree[i * 2];
		}
		return;
	}
	void setting(int team, int up){
		score[team] += up;
		int now = team + SIZE1;
		while (now != 1){
			now /= 2;
			tree[now] = (score[tree[now * 2]] < score[tree[now * 2 + 1]]) ? tree[now * 2 + 1] : tree[now * 2];
		}
		return;
	}
	int top(){
		return tree[1];
	}
};

int n, r, l, ans = 0;
int tim[100000];
int d[1000002], t[1000002], x[1000002];
segtree s;
int main()
{
	cin >> n >> r >> l;
	s.reset(n);
	for (int i = 1; i <= r; i++){
		cin >> d[i] >> t[i] >> x[i];
	}
	t[r + 1] = l;
	int nowtop = 0;
	for (int i = 1; i <= r + 1; i++){
		s.setting(d[i] - 1, x[i]);
		tim[nowtop] += t[i] - t[i - 1];
		nowtop = s.top();
	}
	for (int i = 1; i < n; i++){
		if (tim[ans] < tim[i]) ans = i;
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 13572
import itertools
def func(n):
  rest= {i**2%n for i in range(1,n)}
  count=[0]*n
  for x,y in itertools.combinations(rest,2):
    count[x-y] +=2
  for i in range(n//2):print(count[i+1]+count[n-i-1])
while True:
  n = int(input())
  if n == 0:break
  func(n)


Measured memory_bytes: 6628
#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: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] c = new int[17];
		int[] p = new int[100];
		int[] w = new int[100];
		int[] sit = new int[100];
		for (int i = 0; i < 100; i++) {
			p[i] = i % 5 == 1 ? 5 : 2;
			w[i] = 17 * (i % 2) + 3 * (i % 3) + 19;
		}
		int i = 0;
		int t = 0;
		Deque<Integer> deque = new ArrayDeque<Integer>();
		Deque<Integer> m = new ArrayDeque<Integer>();
		int a = -1;
		loop1: while (true) {
			if (t == i * 5 && i < 100) {
				deque.offer(i++);
				m.offer(t);
			}
			for (int k = 0; k < 17; k++) {
				c[k] = Math.max(0, c[k] - 1);
			}
			while (!deque.isEmpty()) {
				int de = deque.peekFirst();
				a = getA(p[de], c);
				if (a == -1) {
					break;
				}
				int id = deque.poll();
				for (int j = a; j < a + p[id]; j++) {
					c[j] = w[id];
				}
				sit[id] = t - m.pollFirst();
				if (id == 99) {
					break loop1;
				}

			}
			t++;
		}
		while (scanner.hasNext()) {
			int n = scanner.nextInt();
			System.out.println(sit[n]);
		}
	}

	private static int getA(int d, int[] c) {
		int count = 0;
		int a = -1;
		for (int i = 0; i < 17; i++) {
			if (c[i] == 0) {
				count++;
				if (d == count) {
					return i - count + 1;
				}
			} else {
				count = 0;
			}
		}
		return a;
	}

}

Measured memory_bytes: 18388
program sample
    implicit none
  
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    m=sum(x)
    if (mod(m,10)/=0)then
        write(*,*)m
        stop
    end if

    call msort(x)
    do i=1,n
        if(mod(x(i),10)/=0)then
            m=m-x(i)
            write(*,*)m
            stop
        end if
    end do

    write(*,*) 0
  
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 2776
#include<cstdio>
const int mod=1000000007;
int N,M,A[20],f[20][1<<16];
long long fac[1<<17],ifac[1<<17];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
long long C(int n,int m){return fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=1;i<=M;i++)scanf("%d",A+i);
	for(int i=*fac=1;i<=1<<N;i++)fac[i]=fac[i-1]*i%mod;
	ifac[1<<N]=inv(fac[1<<N]);
	for(int i=1<<N;i;i--)ifac[i-1]=ifac[i]*i%mod;
	f[M][0]=1;
	for(int i=M;i;i--)for(int s=0;s<1<<N;s++)if(f[i][s]){
		//printf("f(%d,%d)=%d\n",i,s,f[i][s]);
		int rst=(1<<N)-A[i]-s;
		(f[i-1][s]+=f[i][s])%=mod;
		for(int j=N;j--;)if(!(s>>j&1)&&(1<<j)-1<=rst){
			f[i-1][s|1<<j]=(f[i-1][s|1<<j]+(mod-C(rst,(1<<j)-1))*f[i][s]%mod)%mod;
		}
	}
	int ans=0;
	for(int i=0;i<1<<N;i++){
		long long tmp=f[0][i];
		int sz=(1<<N)-1-i;
		tmp=tmp*fac[sz]%mod;
		for(int j=0;j<N;j++)if(!(i>>j&1))tmp=tmp*ifac[1<<j]%mod;
		(ans+=tmp)%=mod;
	}
	ans=ans*(1ll<<N)%mod;
	for(int i=0;i<N;i++)ans=ans*fac[1<<i]%mod;
	printf("%d\n",ans);
}

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

int main(void)
{
  int array[10];
  int i, j;
  int end;
  int temp;
  for(i = 0; i < 10; i ++){
    cin >> array[i];
  }

   while(1){
    end = 0;

    for(j = 0; j < 9; j++){
      
      if(array[j] > array[j + 1]){
	temp = array[j];
	array[j] = array[j + 1];
	array[j + 1] = temp;
	end = 1;

      }

    }

  if(end == 0){ break ; }

  }

  cout << array[9] << endl <<  array[8] << endl << array[7] << endl;

  return 0;
}

Measured memory_bytes: 3100