akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int n,q; 
const int MAX = 1 << 17;
int dat[MAX*2];
void SegT(){
    int tmp = 1;
    while (tmp < n) tmp *= 2;
    n = tmp;
    for (int i = 0; i < n*2-1; i++){
        dat[i] = INT_MAX;
    }
}
void update(int k,int x){
    k += n-1;
    dat[k] = x;
    while (k > 0){
        k = (k-1)/2;
        dat[k] = min(dat[k*2 + 1], dat[k*2 + 2]);
    }
}
int find(int a,int b,int k,int l,int r){
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return dat[k];
    int v1 = find(a,b,k*2 + 1, l, (l+r)/2);
    int v2 = find(a,b,k*2 + 2, (l+r)/2, r);
    return min(v1,v2);
}

int main(){
    cin >> n >> q;
    SegT();
    for (int i = 0; i < q; i++){
        int c,x,y; cin >> c >> x >> y;
        if (c == 0) {
            update(x,y);
        } else {
            cout << find(x,y+1,0,0,n) << endl;
        }
    }
}


Measured memory_bytes: 4052
import sys

from math import floor


def check(t):
    maxx, minx, maxy, miny = ud_maxx, ud_minx, lr_maxy, lr_miny
    for x, y in dots['R']:
        maxx = max(maxx, x + t)
        minx = min(minx, x + t)
    for x, y in dots['L']:
        maxx = max(maxx, x - t)
        minx = min(minx, x - t)
    for x, y in dots['U']:
        maxy = max(maxy, y + t)
        miny = min(miny, y + t)
    for x, y in dots['D']:
        maxy = max(maxy, y - t)
        miny = min(miny, y - t)
    return (maxx - minx) * (maxy - miny)


n = int(input())
dots = {'R': set(), 'L': set(), 'U': set(), 'D': set()}
lr_maxy, lr_miny, ud_maxx, ud_minx = -1e9, 1e9, -1e9, 1e9
for line in sys.stdin:
    x, y, d = line.rstrip().split()
    x, y = int(x), int(y)
    dots[d].add((x, y))
    if d in 'LR':
        lr_maxy = max(lr_maxy, y)
        lr_miny = min(lr_miny, y)
    else:
        ud_maxx = max(ud_maxx, x)
        ud_minx = min(ud_minx, x)

l = 0.0
r = float(1 << 30)

while l < r - 1:
    m1 = l + floor((r - l) / 3 * 2) / 2
    m2 = l + floor((r - l) / 3 * 4) / 2
    c1 = check(m1)
    c2 = check(m2)
    # print(l, r, m1, m2, c1, c2)
    if c1 >= c2:
        l = m1
    else:
        r = m2

ans = float(1e17)
l = max(0.0, floor(l * 2 - 16) / 2)
while l <= r + 8:
    ans = min(ans, check(l))
    l += 0.5
print(ans)


Measured memory_bytes: 67036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
 
// https://atcoder.jp/contests/abc045/submissions/878750
public class Main {
 
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = in.readLine().split(" ");
		Integer h = Integer.parseInt(tmp[0]);
		Integer w = Integer.parseInt(tmp[1]);
		Integer n = Integer.parseInt(tmp[2]);
		Integer a, b;
		Map<String, Integer> candidates = new HashMap<>();
		long[] result = new long[10];
		
		for (int i = 0; i < n; i++) {
			tmp = in.readLine().split(" ");
			a = Integer.parseInt(tmp[0]);
			b = Integer.parseInt(tmp[1]);
			for (int x = 2; x >= 0; x--) {
				for (int y = 2; y >= 0; y--) {
					if (a - x >= 1 && b - y >= 1 && (a - x + 2) <= h && (b - y + 2) <= w) {
						String key = (a - x) + "+" + (b - y);
						if (candidates.containsKey(key)) {
							candidates.put(key, candidates.get(key) + 1);
						} else {
							candidates.put(key, 1);
						}
					}
				}
			}
		}
		
		result[0] = (long) (h - 2) * (w - 2) - candidates.size();
		for (Map.Entry<String, Integer> candidate : candidates.entrySet()) {
			result[candidate.getValue()]++;
		}
		
		for (int j = 0; j <= 9; j++) {
			System.out.println(result[j]);
		}
	}
}

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

const long long INF = 1LL<<60;
const int MAX_VALUE = 100000;

int main() {
    int n, W; cin >> n >> W;
    vector<long long> w(n), v(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }
    vector<vector<long long>> dp(n+1, vector<long long>(MAX_VALUE+1));
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= MAX_VALUE; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[n][0] = 0;
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j <= MAX_VALUE; ++j) {
            dp[i][j] = min(dp[i][j], dp[i+1][j]);
            if (j - v[i] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i+1][j-v[i]] + w[i]);
            }
        }
    }
    long long ans = 0;
    for (int j = 0; j <= MAX_VALUE; ++j) {
        if (dp[0][j] <= W) {
            ans = j;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>

int main(){
	int x,y;
	int a[13];
	a[1]=0;
	a[2]=2;
	a[3]=0;
	a[4]=1;
	a[5]=0;
	a[6]=1;
	a[7]=0;
	a[8]=0;
	a[9]=1;
	a[10]=0;
	a[11]=1;
	a[12]=0;

	std::cin>>x>>y;

	if( a[x] == a[y] ){
		std::cout<<"Yes"<<std::endl;
	}else{
		std::cout<<"No"<<std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
function main(arg) {
	arg = arg.split("\n")
	var N = Number(arg[0])
	var _ta = arg[1].split(" ")
	var T = Number(_ta[0])
	var A = Number(_ta[1])
	var H = arg[2].split(" ").map(e => Number(e))
	const k = 0.006

	var result = []
	var result = Math.abs((T - H[0] * k) - A)
	var result_i = 0 

	for (var i = 1; i < H.length; i++) {
		var c = T - H[i] * k

		c = Math.abs(c - A)
		if (c < result) {
			result_i = i
			result = c
		}
	}

	console.log(result_i + 1) 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#include <unordered_map>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 9e18;
#define MOD 1000000007ll
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define vi vector < int >
#define vii vector < vector < int > >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
 
#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define gint(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define setZero(a,n) for(int i=0;i<n;i++) a[i]=0;
#define printArray(a,s,e) for(int i=s;i<e;i++) {cout << a[i] << " ";} cout << endl;
#define nl cout << endl
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------- 
int n, m;
vi edges[100005];
vi dist(100005);
vi visited(100005);

void dfs(int src){
	visited[src] = 1;
	for(auto it: edges[src]){
		if(visited[it] == 0){
			dfs(it);
		}
		dist[src] = max(dist[src], dist[it] + 1);
	}
	// dist[src]++;
}

int32_t main(){fast;
	

	int tt = 1;
	// cin >> tt;
	while(tt--){
		cin >> n >> m;
		for(int i=0;i<m;i++){
			int x, y;
			cin >> x >> y;
			edges[x].pb(y);
		}

		for(int i=0;i<=n;i++) visited[i] = 0;
		for(int i=0;i<=n;i++) dist[i] = 0;

		for(int i=1;i<=n;i++){
			if(visited[i]==0){
				dfs(i);
			}
		}
		int mx = 0;
		for(int i=1;i<=n;i++) mx = max(mx, dist[i]);

		cout << mx << endl;

	}
}	








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


int main() {
	long n, k = 0, ans = 0;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		k+=x;
	}
	k -= n;
	cout << k << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void selection_sort(int n,int a[])
{
    int i,j,mins,ans=0,h;
    for(i=0;i<=n-1;i++)
    {
        mins=i;
        for(j=i;j<=n-1;j++)
        {
            if(a[j]<a[mins])
            {
                mins=j;
            }
        }
        if(a[i]!=a[mins])
        {
         h=a[i];
        a[i]=a[mins];
        a[mins]=h;
        ans++;
        }
    }
     for(h=0;h<n;h++)
        {
            if(h>0)
                printf(" ");
            printf("%d",a[h]);
        }
        printf("\n");
        printf("%d\n",ans);
}
int main()
{
    int i,n,a[101];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        selection_sort(n,a);
        return 0;
}



Measured memory_bytes: 2076
import java.io.*;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int l = in.nextInt();
            PriorityQueue<String> heap = new PriorityQueue<>();
            for (int i = 0;i < n; i++) {
                heap.offer(in.next());
            }

            while (!heap.isEmpty()) {
                out.print(heap.poll());
            }
            out.println();
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 29780
//https://atcoder.jp/contests/nomura2020/tasks/nomura2020_e
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define int long long

int fullcombo(int x){
	int ans=0;for(int i=1;i<=x;i++) ans+=(i+1)/2;
	return ans; 
}
char str[nn];int n;vector<int> all;

int len[nn],m;
namespace trcyx{
	int len[nn*2],tag[nn*2],sum[nn*2];
	#define lc id<<1
	#define rc id<<1|1
	#define mid (l+r)/2
	void build(int l,int r,int id){
		len[id]=r-l+1;tag[id]=0;sum[id]=0;
		if(l<r) build(l,mid,lc),build(mid+1,r,rc);
	}
	void up(int id){
		sum[id]=sum[lc]+sum[rc];
	}
	void flip(int id){
		sum[id]=len[id]-sum[id];
		tag[id]^=1;
	}
	void down(int id){
		if(tag[id]){
			flip(lc);flip(rc);
			tag[id]=0;
		}
	}
	
	void flip(int a,int b,int l=1,int r=nn,int id=1){
		if(a>b) return ;
		if(l>=a and r<=b){
			flip(id);
			return ;
		}
		down(id);
		if(a<=mid) flip(a,b,l,mid,lc);
		if(b>mid) flip(a,b,mid+1,r,rc);
		up(id);
	}
	int ask(){
		return sum[1];
	}
	
};
int solve(){
	vector<int> pos;for(int i=0;i<all.size();i++) if(all[i]==1) pos.push_back(i);
	pos.push_back(all.size());all.clear();
	int lst=-1;m=0;
	for(int i=0;i<pos.size();i++){
		len[++m]=pos[i]-lst-1;
		lst=pos[i];
	}
	//cout<<m<<"asd\n";
	trcyx::build(1,nn,1);
	
	int s=0;m--;
	for(int i=1;i<=m;i++){
		s+=len[i];
		if(s%2==0) trcyx::flip(i,i);s++;
	}
//	cout<<trcyx::ask()<<"\n";
	int ans=0;
	for(int i=1;i<=m;i++) while(len[i]>(i>1)){
			ans+=trcyx::ask();
			trcyx::flip(i,m);
			len[i]--;
		}
		
	for(int i=1+m;i>=1;i--) while(len[i]>0){
			ans+=trcyx::ask();
			trcyx::flip(i,m);
			len[i]--;
		} 
	
	return ans;
}
signed main(){
	scanf("%s",str+1);n=strlen(str+1);
	int cnt1=0,lst=0,waste=0,cnt0=0;;
	for(int i=1;i<=n;i++) {
		if(str[i]=='1')
			lst++,cnt1++;
		if(str[i]=='0' or i==n){
			waste+=lst/2;lst%=2;
			if(lst) all.push_back(1);
			lst=0;
		}
		if(str[i]=='0') all.push_back(0),cnt0++;
	}
	if(!cnt1) return puts("0")*0;
	cout<<solve()+fullcombo(cnt1)+waste*cnt0<<"\n";
	return 0;
}

Measured memory_bytes: 19748
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			// 階乗の配列
			long[] frac = new long[h + w - 1];
			frac[0] = 1;
			IntStream.range(1, frac.length).forEach(i -> frac[i] = frac[i - 1] * i % MOD);
			// 階乗^-1の配列
			long[] reverseFrac = new long[h + w - 1];
			reverseFrac[h + w - 2] = powMod(frac[h + w - 2], MOD - 2);
			IntStream.range(1, reverseFrac.length).map(i -> reverseFrac.length - i - 1)
					.forEach(i -> reverseFrac[i] = reverseFrac[i + 1] * (i + 1) % MOD);
			long answer = 0L;
			for (int i = b; i < w; i++) {
				answer += frac[h - a - 1 + i] * reverseFrac[h - a - 1] % MOD * reverseFrac[i] % MOD
						* frac[a + w - 2 - i] % MOD * reverseFrac[a - 1] % MOD * reverseFrac[w - 1 - i] % MOD;
				answer %= MOD;
			}
			System.out.println(answer);
		}
	}

	/**
	 * @param n
	 * @param m
	 * @return n^m mod MOD
	 */
	private static long powMod(long n, long m) {
		long result = 1L;
		while (m > 0) {
			if (1 == (m & 1)) {
				result = result * n % MOD;
			}
			n = n * n % MOD;
			m >>= 1;
		}
		return result;
	}
}


Measured memory_bytes: 28876
#include <stdio.h>

int main(void){
    int h,w;

    while(1){
        scanf("%d %d",&h,&w);
        if(h ==0 && w==0){
            break;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if((i+j)%2==0){
                    printf("#");
                }else{
                    printf(".");
                }                
            }
        printf("\n");
        }
    printf("\n");
    }
}


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

int main()
{
    long long n,d;
    int counts = 0;
    cin >> n >> d;

    int xy[200010][2];

    for(int i = 0; i < n ; i++)
    {
        cin >> xy[i][0] >> xy[i][1];
        if (pow(xy[i][0],2) + pow(xy[i][1],2) <= d*d)
        {
            counts++;
        }
    }

    cout << counts << endl;

    return 0;
}

Measured memory_bytes: 5168
#include <stdio.h>

int main(void) {
	int C, i, K, N;
	scanf("%d%d", &N, &K);

	i = N-1;
	C = 1;
	while (i--) {
		C *= K-1;
	}
	C *= K;
	printf("%d\n", C);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
c1, c2, c3 = -1, -1, -1
ptn = 0
ptn_sum = 1

for i in range(n):
  if a[i] == c1+1:
    ptn += 1
  if a[i] == c2+1:
    ptn += 1
  if a[i] == c3+1:
    ptn +=1
    
  if a[i] == c1+1:
    c1 += 1
  elif a[i] == c2+1:
    c2 += 1
  elif a[i] == c3+1:
    c3 += 1  
  ptn_sum *= ptn
  ptn =0
print(ptn_sum%1000000007)

Measured memory_bytes: 15736
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int cost[128][128][4];
int field[128][128];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
char NEWS[4]={'N','E','S','W'};
int main(void)
{
  for(;;){
    LL h,w,l;
    cin >> h >> w >> l;
    if(!h&&!w&&!l) return 0;
    REP(i,h+2) REP(j,w+2) REP(k,4) cost[i][j][k]=0;
    REP(i,h+2) REP(j,w+2) field[i][j]=0;
    int robox,roboy,robodi;
    REP(i,h){
      string tmp;
      cin >> tmp;
      REP(j,tmp.size()) if(tmp[j]!='#') field[i+1][j+1]=1;
      REP(j,tmp.size()) if(tmp[j]!='#' && tmp[j]!='.') {
	roboy=i+1;
	robox=j+1;
	if(tmp[j]=='N') robodi=0;
	if(tmp[j]=='E') robodi=1;
	if(tmp[j]=='W') robodi=3;
	if(tmp[j]=='S') robodi=2;
      }
    }
    for(LL c=0;;++c){
      if(cost[roboy][robox][robodi]) l=(l-c)%(c-cost[roboy][robox][robodi])+c;
      else cost[roboy][robox][robodi]=c;
      if(c==l) break;
      while(!field[roboy+dy[robodi]][robox+dx[robodi]]) robodi=(robodi+1)%4;
      robox+=dx[robodi];
      roboy+=dy[robodi];
    }
    cout << roboy << ' ' << robox << ' ' << NEWS[robodi] << endl;
  }
}

Measured memory_bytes: 1468
h, w = gets.split.map(&:to_i)
costs = []
10.times { costs << gets.split.map(&:to_i) }
wall = []
h.times { wall << gets.split.map(&:to_i) }
updated = Array.new(10) { Array.new(10, false) }
10.times { |i| updated[i][i] = true }
10.times do |r|
  10.times do |c|
    next if updated[r][c]
    queue = [[c, costs[r][c]]]
    until queue.empty?
      tmp_r, tmp_cost = queue.shift
      costs[tmp_r].each_with_index do |cost, i|
        if tmp_cost + cost < costs[r][i]
          costs[r][i] = tmp_cost + cost
          updated[r][i] = true
          queue << [i, tmp_cost + cost]
        end
      end
    end
  end
end
wall.flatten!
ans = 0
10.times { |i| ans += wall.count(i) * costs[i][1] }
puts ans


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        long m = (long)n * (n + 1) / 2;
        long[] a = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            sum += a[i];
        }
        if (sum % m == 0) {
            long[] b = new long[n];
            b[0] = a[n - 1] - a[0] + sum / m;
            for (int i = 1; i < n; i++) {
                b[i] = a[i - 1] - a[i] + sum / m;
            }
            for (int i = 0; i < n; i++) {
                if (b[i] < 0 || b[i] % n != 0) {
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 60784
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
half = flip div 2
aliq = ((0==).).mod

main = do
 inputs <- readLnInt
 print $ solve inputs

solve [n,a] = (sum apples) - eaten where
 apples = [a+x-1|x<-[1..n]]
 eaten = calc 10000 apples

calc t (a:x) = (null x)?(t',calc t' x) where
 t' = (abs t<abs a)?(t,a)


Measured memory_bytes: 380
#include <iostream>
#include <bits/stdc++.h>
#define p 1000000007
using namespace std;
int N,k;


const int A = 2e5 + 11;
const int B = 1e6 + 11;
const int inf = 0x3f3f3f3f;

inline int read() {
	char c = getchar(); int x = 0, f = 1;
	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return x * f;
}

int T, fac[A];

inline int power(long long a, long long  b) {
	long long res = 1;
	while (b) {
		if (b & 1) res = res * a % p;
		a = a * a % p, b >>= 1;
	}
	return res;
}

inline int C(int n, int m) {
	if (m > n) return 0;

	return (1LL*fac[n] * power(fac[m], p - 2) % p) *  power(fac[n - m], p - 2) % p;
}

inline int Lucas(int n, int m) {
	if (!m) return 1;
	//cout <<"CL:"<<C(n%p,m%p) << " "<<Lucas(n / p, m / p)<<endl;
	return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}

inline void init() {
	int maxn = N*2;
	fac[0] = 1;
	for (int i = 1; i <= maxn; i++) fac[i] = (1LL*fac[i - 1] * i) % p;
}


int main()
{
    scanf("%d%d",&N,&k);
    long long b = k,r = N-k;
    init();

    for(int i=1;i<=k;++i)
    {
        long long i1 = 1,i2 = 1;
        if(r-i+1<0) {
            printf("0\n");continue;
        }
        i1 = Lucas(k-1,k-i);
        //cout << k << " "<<i<<" "<<i1 << endl;
        i2 = Lucas(r+1,r-i+1);
        //cout <<r+1<<" "<<r-i+1<<" "<<i2<<endl;
        printf("%lld\n",(1LL*i1*i2)%p);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 40

using namespace std;

int C,D,W,X;
int E[MAX][MAX];
int F[MAX][MAX];
int dp[40][60][10];//dp[D:day][W:burden][X:kurenai]

int main()
{
  while(scanf("%d %d %d %d",&C,&D,&W,&X),C|D|W|X)
    {  
      rep(i,C)rep(j,D)scanf("%d",&E[i][j]);
      rep(i,C)rep(j,D)scanf("%d",&F[i][j]);  

      rep(i,40)rep(j,60)rep(k,10)dp[i][j][k] = -inf;
      dp[0][0][0] = 0;

      rep(day,D)
	{
	  rep(burden,W+1)
	    {
	      rep(x,X+1)
		{
		  //何もしない
		  dp[day+1][burden][x] = max(dp[day+1][burden][x],
					     dp[day  ][burden][x]);

		  rep(region,C)
		    {
		      if(E[region][day] == 0)continue;
		      
		      //そこでラヴライヴ
		      if(burden + F[region][day] <= W)
			{
			  dp[day+1][burden+F[region][day]][x] = max(dp[day+1][burden+F[region][day]][x],
								    dp[day][burden][x]+E[region][day]);
			}

		      //ラブライブ！
		      int cost = 0;
		      int value = 0;
		      
		      for(int cur=region;cur>=0;cur--)
			{
			  cost  += F[cur][day];
			  value += E[cur][day];
			  if(cur == region)continue;
			  if(E[cur][day] == 0)break;
			  if(burden + cost <= W && x + 1 <= X)
			    {
			      dp[day+1][burden+cost][x+1] = max(dp[day+1][burden+cost][x+1],
								dp[day  ][burden     ][x  ]+value);
			    }
			  else break;
			}
		      
		      
		      cost = 0;
		      value = 0;
		      for(int cur=region;cur<C;cur++)
			{
			  cost  += F[cur][day];
			  value += E[cur][day];
			  if(E[cur][day] == 0)break;
			  if(cur == region)continue;
			  if(burden + cost <= W && x + 1 <= X)
			    {
			      dp[day+1][burden+cost][x+1] = max(dp[day+1][burden+cost][x+1],
								dp[day  ][burden     ][x  ]+value);
			    }
			  else break;
			}
		      
		    }

		}
	    }
	}

      int ans = 0;
      rep(i,W+1)rep(j,X+1)
	{
	  ans = max(ans,
		    dp[D][i][j]);
	}
      printf("%d\n",ans);

    }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;
using lint=long long;

const lint INF=1LL<<61;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=m.inverse(); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	mint inverse()const{
		int a=x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int s,t; scanf("%d%d",&s,&t); s--; t--;
	vector<vector<pair<int,lint>>> G(n);
	rep(i,m){
		int u,v;
		lint d; scanf("%d%d%lld",&u,&v,&d); u--; v--;
		G[u].emplace_back(v,d);
		G[v].emplace_back(u,d);
	}

	auto Dijkstra=[&](auto& d,auto& dp,int s){
		rep(u,n){
			d[u]=INF;
			dp[u]=0;
		}
		d[s]=0;
		dp[s]=1;

		priority_queue<pair<lint,int>> Q; Q.emplace(0,s);
		while(!Q.empty()){
			lint d0=-Q.top().first;
			int u=Q.top().second;
			Q.pop();

			if(d0>d[u]) continue;

			for(const auto& e:G[u]){
				int v=e.first;
				lint cost=e.second;
				if(d[v]>d[u]+cost){
					d[v]=d[u]+cost;
					dp[v]=dp[u];
					Q.emplace(-d[v],v);
				}
				else if(d[v]==d[u]+cost){
					dp[v]+=dp[u];
				}
			}
		}
	};
	vector<lint> d1(n),d2(n);
	vector<mint> dp1(n),dp2(n);
	Dijkstra(d1,dp1,s);
	Dijkstra(d2,dp2,t);

	mint ans=dp1[t]*dp2[s];
	rep(u,n) if(d1[u]+d2[u]==d1[t] && d1[u]==d2[u]) {
		ans-=(dp1[u]*dp2[u])*(dp2[u]*dp1[u]);
	}
	rep(u,n) for(const auto& e:G[u]) {
		int v=e.first;
		lint cost=e.second;
		if(d1[u]+cost+d2[v]==d1[t]){ // u-v belongs to the shortest path DAG
			if(d1[u]<d2[v]+cost && d2[v]<d1[u]+cost){ // (d1[u], d1[u]+cost) intersects (d2[v], d2[v]+cost)
				ans-=(dp1[u]*dp2[v])*(dp2[v]*dp1[u]);
			}
		}
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 18516
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll dp[3001][3001][2];
ll sol(ll a[],ll i,ll j,ll turn)
{
    if(i>j)
        return 0;
    if(dp[i][j][turn]!=-1)
        return dp[i][j][turn];
    if(turn==1)
    {
        dp[i][j][turn]=max(a[i]+sol(a,i+1,j,0),a[j]+sol(a,i,j-1,0));
    }
    else
        dp[i][j][turn]=min(sol(a,i+1,j,1),sol(a,i,j-1,1));
    return dp[i][j][turn];
}
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    ll sum=0;
    memset(dp,-1,sizeof(dp));
    for(ll i=1;i<=n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
    ll p1=sol(a,1,n,1);
    ll p2=sum-p1;
    ll ans=p1-p2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 144524
MOD = 10 ** 9 + 7
def comb(n, r):
    return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD)

N, K = map(int, input().split())
fact = [1] * N
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD
A = sorted(map(int, input().split()))
print(sum(comb(i, K - 1) * (A[i] - A[N - i - 1]) % MOD for i in range(K - 1, N)) % MOD)


Measured memory_bytes: 18520
#include<stdio.h>

int main()
{
	int S,h,m,s;
	scanf("%d",&S);
	if(S>=0 && S<=86400)
	{
		s=S;
		h=s/3600;
		s=s-3600*h;
		m=s/60;
		s=s-60*m;
		S=s;
	}
	printf("%d:%d:%d\n",h,m,S);
return(0);
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<long> data(N), front(N), back(N);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  front.at(N - 1) = data.at(N - 1);
  back.at(0) = data.at(0);
  for(int i = 1; i < N; i++){
    back.at(i) = __gcd(back.at(i - 1), data.at(i));
    front.at(N - 1 - i) = __gcd(front.at(N - i), data.at(N - 1 - i));
  }
  long ans = 1;
  for(int i = 0; i < N; i++){
    
    if(i == 0){
      ans = max(ans, front.at(i + 1));
    } else if (i == N - 1){
      ans = max(ans, back.at(N - 2));
    } else {
      ans = max(ans, __gcd(front.at(i + 1), back.at(i - 1)));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll N, M;
	cin >> N >> M;
	vll A(N);
	for (auto& e : A)cin >> e;
	ll s = accumulate(A.begin(), A.end(), 0);
	ll L = s / (4 * M);
	if (s % (4 * M) == 0) {
		L--;
	}
	ll num = 0;
	for (ll i = 0; i < N; i++) {
		if (A[i] > L) {
			num++;
		}
	}
	if (num >= M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int n; cin>>n;
    ll sum=0;
    unordered_map<ll,ll> um; 
    int arr[n]; F { cin>>arr[i]; um[arr[i]]++; sum+=arr[i]; }
    int q; cin>>q;
    int b,c;
    while(q--) {
        cin>>b>>c;
        sum = sum + um[b]*c - um[b]*b;
        um[c]+=um[b];
        um[b]=0;
        cout<<sum<<endl;
    }

    
    return 0;
}

Measured memory_bytes: 7524
def main():
    candies = list(map(int, input().split()))
    print("Yes" if candies[0] + candies[1] == candies[2] or candies[1] + candies[2] == candies[0] or
                   candies[0] + candies[2] == candies[1] else "No")


if __name__ == '__main__':
    main()



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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string c = Console.ReadLine();
		decimal a = decimal.Parse(c.Split()[0]);
        decimal b = decimal.Parse(c.Split()[1]);
		
		var res = (long)decimal.Multiply(a, b);
		
		Console.WriteLine(res);
        }
    }
}


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

int main() {
  
    string c;
  cin >> c;
  
  if ( c == "a"){
    cout << "vowel" << endl;
  }

  else if ( c == "e"){
    cout << "vowel" << endl;
  }

  else if( c == "i"){
    cout << "vowel" << endl;
  }

  else if ( c == "o"){
    cout << "vowel" << endl;
  }

  else if ( c == "u"){
    cout << "vowel" << endl;
  }
  
  else{
    cout << "consonant" << endl;
  }

  
 
}



Measured memory_bytes: 3560
//40
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  map<int,int> dat;
  vector<int> ansv;
  for(int id,ans;(cin>>id).ignore()>>ans,id|ans;){
    dat[id]=ans;
    ansv.push_back(ans);
  }
  sort(ansv.rbegin(),ansv.rend());
  ansv.erase(unique(ansv.begin(),ansv.end()),ansv.end());
  for(int n;cin>>n;){
    cout<<find(ansv.begin(),ansv.end(),dat[n])-ansv.begin()+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List

main :: IO()
main = do
  n <- getLine
  s <- getLine
  printf "%s" $ slv s

slv :: String -> String
slv s = show $ calc len s 0
  where len = length s

calc :: Int -> String -> Int -> Int
calc 0 _ ret = ret
calc n s ret = calc (n - 1) s (max ans ret)
  where ans = countStr alpha sl sr 0
        (sl, sr) = splitAt n s

alpha = "abcdefghijklmnopqrstuvwxyz"

countStr :: String -> String -> String -> Int -> Int
countStr [] _ _ ret = ret
countStr (c:cs) sl sr ret | elem c sl && elem c sr = countStr cs sl sr (ret+1)
                          | otherwise = countStr cs sl sr ret

Measured memory_bytes: 1020
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=4e3+10,mod=1e9+7,M=2e5+100;
ll dp[N][N];
ll val[N][N];
ll a[M],b[M];
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fac[M],fm[M];
ll ent(ll k,ll n){
    if (k==0 || k==n) return 1;
    if (k<0 || k>n) return 0;
    return (fac[n]*fm[k]%mod)*fm[n-k]%mod;
}
int32_t main(){
    fac[0]=1;
    for (int i=1;i<M;i++){
        fac[i]=fac[i-1]*i%mod;
        fm[i]=power(fac[i],mod-2);
    }
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i] >> b[i];
    for (int i=1;i<=n;i++){
        val[-a[i]+N/2][-b[i]+N/2]++;
    }
    ll ans=0;
    for (int i=1;i<N;i++){
        for (int j=1;j<N;j++){
            dp[i][j]+=dp[i][j-1]+dp[i-1][j]+val[i][j];
            dp[i][j]%=mod;
        }
    }
    for (int i=1;i<=n;i++){
        ans+=dp[a[i]+N/2][b[i]+N/2];
        ans-=ent(2*a[i],2*a[i]+2*b[i]);
        ans+=mod;
        ans%=mod;
    }
    cout << ans*power(2,mod-2)%mod << endl;

}


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

int main ()
{
    int n,a[100],i;
    for(i=0;i<5;i++)
    {
        cin>>a[i];
    }
    sort(a,a+5);
    int f=0;
    for(i=4;i>=0;i--)
    {
        if(f==0)
        {cout<<a[i]; f=1;}
        else
            cout<<" "<<a[i];

    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1180
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    x,y = LI()
    if x % y == 0:
        print(-1)
    else:
        print(x)
    return


#main
if __name__ == '__main__':
    solve()


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

using namespace std;
int s[3];
int main() {
  cin >> s[0] >> s[1] >> s[2];

  sort(s,s+3);

  int tmp = s[2];
  int tmp2 = tmp - s[1];
  int tmp3 = tmp - s[0];
 
  if((tmp2 & 1) && (tmp3 & 1)) {
    cout << tmp2 / 2 + tmp3 / 2 + 1 << endl;
  }
  else if(!(tmp2 & 1) && !(tmp3 & 1)) {
    cout << tmp2/ 2 + tmp3 / 2 << endl;
  }

  else {
    cout << tmp2 /2 + tmp3 / 2 + 2 << endl;
  }
}


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

int func(int a) {
	int res = 1;
	for (int i = 1; i <= a / 2; ++i) {
		if (a % i == 0) res++;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 2 != 0) {
			if (func(i) == 8) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;
vector<int> g[200005];
int done[200005]={};
int x=0;
void dfs(int u){
	done[u]=1;x++;
	for(auto v:g[u]){
		if(done[v])continue;
		dfs(v);
	}
}
int main()
{
	
	int n,m;cin>>n>>m;
	fr(i,1,m){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans=0;
	fr(i,1,n){
		x=0;
		if(done[i])continue;
		dfs(i);
		ans=max(ans,x);
	}
	cout<<ans<<'\n';

	return 0;
}



Measured memory_bytes: 21388
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h;
  SV(n,h);

  double ans;
  int idx;
  ans = abs(a - t + h[0] * 0.006);
  idx = 0;
  for(int i = 1; i < n; ++i){
     if(ans > abs(a - t + h[i] * 0.006)){
      ans = abs(a - t +h[i] * 0.006);
      idx = i;
     }
  }
  cout << idx + 1 << endl;
  return 0;
}



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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UnionFind(int N) : par(N),siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
             par[i] = i;
             siz[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        // merge technique（小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

signed main()
{
    gearup;
    int n; cin >> n;
    vvl a(n,vl(n));
    rep(i,n)rep(j,n)cin>>a[i][j];
    auto dp = a;
    vvb b(n,vb(n,true));
    //ワーシャルフロイド法
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(dp[i][j] > (dp[i][k] + dp[k][j]) ){ //矛盾発見
                    out(-1);
                    return 0;
                }
                if(dp[i][j] == dp[i][k] + dp[k][j] && dp[i][k] > 0 && dp[k][j] > 0)
                    b[i][j] = false; //迂回しても同じ距離なので迂回した方を採用
            }
        }
    }
    ll res = 0;
    rep(i,n)rep(j,n)if(b[i][j])res += dp[i][j];
    out(res/2);
}

Measured memory_bytes: 5092
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    size_t K, T;
    scanf("%zu %zu", &K, &T);

    if (T == 1)
        return !printf("%zu\n", K-1);

    int h=(K+1)/2;
    int res=0;
    for (size_t i=0; i<T; ++i) {
        int a;
        scanf("%d", &a);
        if (a > h)
            res = 2*a-K-1;
    }

    printf("%d\n", res);
    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<int> counts(n);
    int cnt = 0;
    counts[0] = cnt;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            cnt++;
        }
        counts[i] = cnt;
    }


    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << counts[r - 1] - counts[l - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left


def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right)


if __name__ == '__main__':
	n = int(input())
	S = [int(s) for s in input().split()]
	cnt = 0
	merge_sort(S)
	print(*S)
	print(cnt)

Measured memory_bytes: 63768
#include<bits/stdc++.h>
 
using namespace std;
const int N=2000+10;
typedef long long ll;
const ll llf=(1ll<<63)-1;
ll dp[N][N],a[N];
int main()
{
    int n;
    ll x,ans=llf;
    scanf("%d%lld",&n,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        dp[0][i]=a[i];
    }
    for(int i=1;i<=n-1;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int ind=j-i;
            if(ind<=0)  ind=n+ind;
            dp[i][j]=min(dp[i-1][j],a[ind]);
        }
    }
    for(int i=0;i<=n-1;i++)
    {
        ll ant=0;
        for(int j=1;j<=n;j++)
            ant+=dp[i][j];
        ans=min(ans,ant+i*x);
       // cout<<ans<<endl;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 31616
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;

int main()
{
    int N,M;
     cin>>N>>M;
     if(M==N)
        printf("Yes");
     else
        printf("No");
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;

const int MAX_N = 100;

int selection_sort(int *a, int n);

int main() {
    int n;
    int a[MAX_N];

    cin >> n;

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

    int count = selection_sort(a, n);

    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i < n - 1) {
            cout << " ";
        }
    }

    cout << endl;
    cout << count << endl;
}

int selection_sort(int *a, int n) {

    int count = 0;
     
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if(a[j] < a[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            count++;
            swap(a[i], a[minj]);
        }
    }

    return count;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 5) cout << 0 << endl;
  else if (a >= 13) cout << b << endl;
  else cout << b/2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

typedef long int lI;

bool check(int num){
	bool check[3] = {false, false, false};
	while(num!=0){
		if(num%10==3){
			check[0] = true;
		}
		else if(num%10==5){
			check[1] = true;
		}
		else if(num%10==7){
			check[2] = true;
		}
		num = num/10;
	}
	if(check[0] && check[1] && check[2]){
		return true;
	}	
	else return false;
}

void make753(lI num, lI N, int *count)
{
	if(num > N){
		return;
	}
	if(check(num)){
		*count += 1; 
	}
	make753(num*10+3, N, count);
	make753(num*10+5, N, count);
	make753(num*10+7, N, count);
}

// void make75(lI num, lI N, int *count)
// {
// 	if(num > N){
// 		return;
// 	}
// 	*count += 1;
// 	printf("%ld\n", num);
// 	make75(num*10+5, N, count);
// 	make75(num*10+7, N, count);
// }

// void make73(lI num, lI N, int *count)
// {
// 	if(num > N){
// 		return;
// 	}
// 	*count += 1;
// 	printf("%ld\n", num);
// 	make73(num*10+3, N, count);
// 	make73(num*10+7, N, count);
// }

// void make53(lI num, lI N, int *count)
// {
// 	if(num > N){
// 		return;
// 	}
// 	*count += 1;
// 	printf("%ld\n", num);
// 	make53(num*10+3, N, count);
// 	make53(num*10+5, N, count);
// }

// int plus753(lI num, lI N)
// {
// 	int count3=-2, count5=-2, count7=-2, copyNum;
// 	copyNum = num;
// 	while(copyNum <= N){
// 		copyNum = copyNum*10+3;
// 		count3 += 1;
// 	}
// 	copyNum = num;
// 	while(copyNum <= N){
// 		copyNum = copyNum*10+5;
// 		count5 += 1;
// 	}
// 	while(num <= N){
// 		num = num*10+7;
// 		count7 += 1;
// 	}
// 	return count3 + count5 + count7;
// }


int main()
{
	lI N;
	int ans=0; 
	// minus5=-4, minus7=-4, minus3=-4;
	scanf("%ld", &N);
	if(N < 357){
		printf("0\n");
		return 0;
	}
	make753(0, N, &ans);
	// printf("---------------------\n");
	// make75(0, N, &minus3);
	// make73(0, N, &minus5);
	// make53(0, N, &minus7);
	// ans = ans + plus753(0, N) - (minus3+minus5+minus7);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define ll long long int
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef struct a{
  int id;
  int num;
}k;
k arr[1000000];
bool ok(k lhs, k rhs){
  if(lhs.num<rhs.num){
    return true;
  }
  return false;

}
int main(){
  int to,k;
  cin>>to;
  for(int i=0;i<to;i++){
    cin>>arr[i].num;
    arr[i].id=i;

  }
  sort(arr,arr+to,ok);
  for(int i=0;i<to;i++){
    cout<<arr[i].id+1<<" ";

  }
}

Measured memory_bytes: 1536