akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;
const int MOD = 1000000007;

// aのn乗mod(p) の繰り返し2乗法
int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main(){
    int x, y; cin >> x >> y;
    bool jud = true;

    if((x+y) %3 != 0) jud =false;
    if(2*y < x || 2*x < y) jud = false;

    int m = (2*y - x)/3;
    int n = (2*x - y)/3;

    ll X=1, Y=1;
    rep(i,n) X = (X*(m+1+i)) % MOD;
    rep(i,n) Y = (Y*(1+i)) % MOD;

    Y = modPow(Y, 1e9 + 5, 1e9 + 7);

    ll ans = (X* Y) % MOD;

    if(jud) dunk(ans);
    else dunk(0);
}

Measured memory_bytes: 256
#include<string>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>

using namespace std;


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

	long double x[N];
	string u[N];
	for(int i=0;i<N;i++)
	{
		cin >> x[i] >> u[i];
	}
	long double sum = 0;
	for(int i=0;i<N;i++)
	{
		if(u[i]==string("JPY"))
		{
			sum = sum + x[i];
		}
		else if(u[i]==string("BTC"))
		{
			sum = sum + x[i]*380000;
		}
	}
	cout << sum << endl;	
	
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, x;
    int i;
    int max, min;
    int t1, t2;

    scanf("%d", &N);
    
    scanf("%d", &x);
    max = min = x;
    
    for (i = 1; i < N; i++){
        scanf("%d", &x);
        if (min > x){
            min = x;
        }
        if (max < x){
            max = x;
        }
    }
    
    t1 = max - (max + min) / 2;
    t2 = (max + min) / 2 - min;
    
    if (t1 > t2){
        printf("%d\n", t1);
    }
    else {
        printf("%d\n", t2);
    }
    
    return (0);
}





Measured memory_bytes: 2104
#include<stdio.h>
 
int main()
{
  int A[100];
  int N;
  int key;
  int i, j, k;
 
  //Read N and keys
  scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d",&A[i]);
 
  //Sort
  for(i=0; i<N; i++){
    key=A[i];
    j=i-1;
 
      //if A[j]>key, change A[j] to A[j+1]
    while(j>=0 && A[j]>=key){
      A[j+1]=A[j];
      j=j-1;
    }
    A[j+1]=key;
 
      //print
    for(k=0; k<N; k++){
      printf("%d", A[k]);
      if(k<N-1)printf(" ");
    }
    printf("\n");
  } 
  return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int cont = 0;
	for(int i=0; i < s.size()/2; ++i)
	{
	//	if(i == s.size()-1-i) break;
		if(s[i] != s[s.size()-1-i])
		{
			cont++;
		}
		
	}
	
	cout << cont;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	long n;
	cin >> n;
	long answer = 0;
	long m = 1;
	
	for(m = 1; m < n; m++) {
		if (long(n / m) == 1) break;
		if (n / long(n / m) == n / (long(n / m) - 1)) {
			if (n % m == 0) {
				answer += (n - m) / m;
			}
		}
		if(n / (double(n / m) - 1) - n / double(n / m) >1 ) {
			break;
		}
	}

	cout << answer << endl;

	
    return 0;
}


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

int main(){
    vector<int> X(5);
    for(int i = 0; i < 5; i++){
        cin >> X.at(i);
    }

    for(int i = 0; i < 5; i++){
        if(X.at(i) == 0){
            cout << i + 1 << endl;
        }
    }
}

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> hoge(n);
  rep(i,n)cin>>hoge[i];
  sort(hoge.begin(),hoge.end());
  cout<<hoge[hoge.size()/2]-hoge[hoge.size()/2-1]<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int 	long long
using namespace std;
 
struct point 
{
	int x, y;
	int id;
};
 
int n, r, c;
 
bool av(point x)    {
    return  (x.x == 0 || x.y == 0 || x.x == r || x.y == c);
}
 
point center;
 
bool les(point a, point b)
{
    if (a.x - center.x >= 0 && b.x - center.x < 0)
        return true;
    if (a.x - center.x < 0 && b.x - center.x >= 0)
        return false;
    if (a.x - center.x == 0 && b.x - center.x == 0) {
        if (a.y - center.y >= 0 || b.y - center.y >= 0)
            return a.y > b.y;
        return b.y > a.y;
    }
    int det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y);
    if (det < 0)
        return true;
    if (det > 0)
        return false;
    int d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y);
    int d2 = (b.x - center.x) * (b.x - center.x) + (b.y - center.y) * (b.y - center.y);
    return d1 > d2;
}
 
 
vector<point> chec;
 
signed main()
{
	scanf("%lld%lld%lld", &r, &c, &n);
	for (int i = 1; i <= n; i++)
	{
		point temp1, temp2;
		scanf("%lld%lld%lld%lld", &temp1.x, &temp1.y, &temp2.x, &temp2.y);
		temp1.id = i;
		temp2.id = i;
		if (av(temp1) && av(temp2))
		{
			chec.push_back(temp1);
			chec.push_back(temp2);
		}
	}
	center.x = (1+r)/2;
	center.y = (1+c)/2;
	sort(chec.begin(), chec.end(), les);
	stack<int> s;
	for (int i = 0; i < chec.size(); i++)
	{
		if (s.empty())
		{
			s.push(chec[i].id);
		}
		else
		{
			if (s.top() == chec[i].id)
			{
				s.pop();
			}
			else
			{
				s.push(chec[i].id);
			}
		}
	}
	if (!s.empty()) 
	{
		printf("NO");
	}
	else
	{
		printf("YES");
	}
}

Measured memory_bytes: 8432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		long ans = 0,n;
		String str;
		str = bf.readLine();
		n = Long.parseLong(str);
		ans = n*(n-1)/2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21076
def main():
    H, W, D = list(map(int, input().split(' ')))
    cell_list = list()
    for h in range(H):
        a_list = list(map(int, input().split(' ')))
        cell_list.extend([(a - 1, h, w) for w, a in enumerate(a_list)])
    cell_list.sort(key=lambda c: c[0])  # sort by cell number
    # calculate cumulative sum of magical power
    cumsum = dict()
    for d in range(D):
        cumsum[d] = [0]
    for x in range(D, H * W):
        d = x % D
        bef_c, c = cell_list[x - D], cell_list[x]
        m = cumsum[d][-1] + abs(c[1] - bef_c[1]) + abs(c[2] - bef_c[2])
        cumsum[d].append(m)
    # answer queries
    Q = int(input())
    queries = [list(map(lambda x: int(x) - 1, input().split(' '))) for _ in range(Q)]
    for L, R in queries:
        d = L % D
        print(cumsum[d][R // D] - cumsum[d][L // D])


if __name__ == '__main__':
    main()

Measured memory_bytes: 56160
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> s,t;
	rep(i,n){
		ll a, b;
		cin >> a >> b;
		s.push_back(pair<ll, ll>(a, b));
	}
	rep(i,m){
		ll a, b;
		cin >> a >> b;
		t.push_back(pair<ll, ll>(a, b));
	}
	rep(i,n){
		ll c = -1,d = Inf;
		rep(j,m){
			
			if (abs(s[i].first - t[j].first) + abs(s[i].second - t[j].second) < d){
				c = j;
				d = abs(s[i].first - t[j].first) + abs(s[i].second - t[j].second);
			}
			
		}
		cout << c + 1 << endl;
	}

	return 0;
}




Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		// スペース区切りの整数の入力
		int X = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
        if (b > a + X ){
    		System.out.println("dangerous");
	    }else if(a >= b){
			System.out.println("delicious");
	    }else{
	    	System.out.println("safe");
	    }
	}
}


Measured memory_bytes: 22740
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.length()==2){
			System.out.println(s);
		}
		else{
			for(int i=2; i>=0; i--){
				System.out.print(s.charAt(i));
			}
			System.out.println("");
		}
	}
}

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

#define i64 long long int

i64 x;

int main() {
	scanf("%lld", &x);
	
	int ans = 0;
	for(i64 i=2;i*i<=x;i++) {
		int pw = 0;
		while(x%i==0) {
			x/=i;
			pw++;
		}
		int det = 1;
		while(pw>=det) {
			ans++;
			pw-=det;
			det++;
		}
	}
	if(x>1) ans++;
	printf("%d\n", ans);
	
	return 0;
}

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

int n, cnt; char c;
priority_queue<int, vector<int>, greater<int> > w_pq;
priority_queue<int> r_pq;

int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; ++i){
        scanf(" %c", &c);
        if (c == 'W') w_pq.push(i);
        else r_pq.push(i);
    }
    if (r_pq.empty() || w_pq.empty()){
        printf("0");
        return 0;
    }
    while (r_pq.top() > w_pq.top()){
        int _r = r_pq.top(); r_pq.pop();
        int _w = w_pq.top(); w_pq.pop();
        ++cnt;
        w_pq.push(_r); r_pq.push(_w);
    }
    printf("%d", cnt);
}


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

int main() {
  int N, K, ans = 1e9;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];
  sort(h.begin(), h.end());
  
  for (int i = 0; i < N - K + 1; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int n,k;cin>>n>>k;
  vector<long long int> h(n);for(int i=0;i<n;i++) cin>>h[i];
  vector<long long int> dp(n,100000000000);
  
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      	if(i+j>n-1) continue;
    	dp[i+j]=min(abs(h[i]-h[i+j])+dp[i],dp[i+j]);
    }
  }
     cout<<dp[n-1]<<endl;
 }

Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        x: i32,
        a: i32,
        b: i32,
    }

    if b <= a {
        println!("delicious");
    } else if b <= a + x {
        println!("safe");
    } else {
        println!("dangerous");
    }
}


Measured memory_bytes: 2112
import sys
def solve(S):
    if not S[0] == 'A':
        return False
    cnt = 0
    c = 0
    for i in range(2,len(S)-1):
        if S[i] == 'C':
            cnt = cnt+1
            c = i
    if not cnt == 1:
        return False
    for i in range(len(S)):
        if not (ord(S[i]) <= ord('z') and ord(S[i]) >= ord('a')):
            if(i == 0 or i == c):
                continue
            else:
                return False
    return True
            
S = input()
print("AC" if solve(S) else "WA")


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

int main() {
  int A,B;
  cin >> A >> B;
  int sum=0;
  for(int i=A;i<B+1;i++){
    if(10000*(i%10)+1000*((i/10)%10)+100*((i/100)%10)+10*((i/1000)%10)+(i/10000)%10==i)sum+=1;
  }
  cout << sum;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var result = GetSumOfGcds(k);

            Console.WriteLine(result);
        }

        private static long GetSumOfGcds(int k)
        {
            long result = 0L;
            for (int i=1; i <= k; i++)
            {
                for (int j = 1; j <= k; j++)
                {
                    for(int l = 1; l <= k; l++)
                    {
                        result += GetGcdOfTuple(new List<int> { i, j, l });
                    }
                }
            }

            return result;
        }

        private static int GetGcdOfTuple(List<int> tuple)
        {
            int result = tuple[0];

            for (int i=1; i < tuple.Count; i++)
            {
                result= Gcd(tuple[i], result);

                if (result == 1)
                {
                    return 1;
                }
            }

            return result;
        }

        static int Gcd(int a, int b)
        {
            if (a == 0)
            {
                return b;
            }
            return Gcd(b % a, a);
        }
    }

Measured memory_bytes: 40992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll n, l, dp[5005][5005], m = 1e9+7;
string s;

ll qexp(ll a, ll b) {
    a %= m;
    ll res = 1, base = a;
    while (b) {
        if (b & 1) {
            res *= base;
            res %= m;
        }
        base *= base;
        base %= m;
        b >>= 1;
    }
    return res % m;
}

void add(ll &a, ll b) {
	b %= m;
	a += b;
	a %= m;
}

int main() {
	fastio;
	cin >> n >> s;
	l = s.length();
	dp[0][0] = 1, dp[1][0] = 1, dp[1][1] = 2;
	FOR(i, 1, n) FOR(j, 0, i) {
		if (j == 0) {
			add(dp[i+1][j], dp[i][j]);
			add(dp[i+1][j+1], 2*dp[i][j]);
		} else {
			add(dp[i+1][j-1], dp[i][j]);
			add(dp[i+1][j+1], 2*dp[i][j]);
		}
	}
	cout << (dp[n][l] * qexp(qexp(2, l), m-2)) % m;
}
	


Measured memory_bytes: 194048
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let line = line.unwrap();
        let vec: Vec<&str> = line.split_whitespace().collect();
        let (a, b) = (vec[0].parse::<i32>().unwrap(), vec[2].parse::<i32>().unwrap());
        match vec[1] {
            "?"   => break,
            "+" => println!("{}", a + b),
            "-" => println!("{}", a - b),
            "*" => println!("{}", a * b),
            "/" => println!("{}", a / b),
            _   => continue,
        }
    }
}



Measured memory_bytes: 5036
s = int(input())
numbers = [s]
while True:
    predecessor = numbers[-1]
    if predecessor % 2 == 0:
        new_number = predecessor/2
    else:
        new_number = 3*predecessor+1
    if new_number in numbers:
        print(len(numbers)+1)
        break
    else:
        numbers.append(new_number)

Measured memory_bytes: 2940
//最悪O(Q^2) 最短O(N+Q)
//番号→名簿番号(hashT[]から検索) 名簿番号→番号(meibo2[]から検索)
//サンプル通るし、自作サンプル通るし…でもWA…。何がいけないのだろう。
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int> P;

struct Pos{
	int num,cnt;
};
int N,Q;
int hashT[1000001];
int meibo[100001],meibo2[100001],mcor = 0;	//mcor = 登録人数,meibo[] = cnt,meibo2[] = num;
vector<P> ans;

int main(){
	int i;
	Pos pos;
	cin >> N >> Q;
	for(i = 1;i <= N;i++){
		hashT[i] = -1;
	}
	//pos(ランキング1位)の初期化っぽいこと
	{
		int a = 1,b = 0;
		hashT[a] = mcor;
		meibo[mcor] = b;
		meibo2[mcor] = a;
		pos.num = a;
		pos.cnt = b;
		//ans.push_back(P(a,b));
		mcor++;
	}
	//2回目の大会から
	for(i = 0;i < Q;i++){
		int a,b;
		cin >> a >> b;
		//meiboに登録されていなければ登録
		if(hashT[a] == -1){
			hashT[a] = mcor;
			meibo[mcor] = b;
			meibo2[mcor] = a;
			mcor++;
		}
		//登録されていたら指定された所を更新
		else{
			meibo[hashT[a]] += b;
		}
		//現在の1位の魚の数の更新
		pos.cnt = meibo[hashT[pos.num]];
		//今の更新について
		//1位のキャッチ、1位以外のリリースなら順位はそのまま
		if((b > 0 && a == pos.num) || (b < 0 && a != pos.num))
			goto SAVEPOS;
		//1位以外のキャッチの場合
		else if(b > 0){
			//今キャッチした人と今の1位を比べる
			if((meibo[hashT[a]] > pos.cnt)||(a < pos.num && meibo[hashT[a]] == pos.cnt)){
				//最高記録の塗り替え
				pos.num = a;
				pos.cnt = meibo[hashT[a]];
			}
		}
		//1位のリリースの場合
		else if(b < 0){
			//最高記録を愚直に調べる。(記録を調べる順番は番号昇順でなくてもよいはず(任意のはず))
			//追記:meibo2[j] < pos.num を meibo2[j] < pos.cntとしていた。カウントと番号間違えるなんて＞＜
			for(int j = 0;j < mcor;j++){
				if((meibo[j] == pos.cnt && meibo2[j] < pos.num)||(meibo[j] > pos.cnt)){
					pos.num = meibo2[j];
					pos.cnt = meibo[j];
				}
			}
			//全ての参加者が0匹の時は1番が1位
			if(pos.cnt == 0){
				pos.num = 1;
				pos.cnt = 0;
			}
		}
SAVEPOS:
		ans.push_back(P(pos.num,pos.cnt));
	}
	int size = ans.size();
	for(i = 0;i < size;i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 6712
# -*- coding: utf-8 -*-
import sys

def main():
	N, M = map(int, input().split(" "))
	ankete = []
	for _ in range(N):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		ankete.append(tmp[1:])
	
	ans = {}
	for i, val in enumerate(ankete):
		for j in val:
			if j in ans:
				ans[j] += 1
			else:
				ans[j] = 1
	
	aaa = 0
	for i in ans.values():
		if i == N:
			aaa += 1
	print(aaa)
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
a = 0
for i in range(N):
	if A[i] > 0:
		a += A[i]
p = sum([i for i in A[:K] if i > 0])
m = sum([i for i in A[:K] if i < 0])
ans = max(a+m,a-p)
for i in range(N-K):
	p = p - max(0,A[i]) + max(0,A[i+K])
	m = m - min(0,A[i]) + min(0,A[i+K])
	ans = max(ans, a-p, a+m)
print(ans)

Measured memory_bytes: 14608
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	boolean[][] m=new boolean[24][60];
	int a=sc.nextInt();
	for(int i=0;i<a;i++){
	    int x=sc.nextInt();
	    int y=sc.nextInt();
	    m[x][y]=true;
	}
	a=sc.nextInt();
	for(int i=0;i<a;i++){
	    int x=sc.nextInt();
	    int y=sc.nextInt();
	    m[x][y]=true;
	}
        int s=0;
	for(int i=0;i<24;i++){
	    for(int j=0;j<60;j++){
		if(m[i][j]){
		    if(s!=0)System.out.print(" ");
		    System.out.print(i+":"+j/10+j%10);
		    s++;
		}
	    }
	}
	System.out.println();	
    }
    public static void main (String[]arg){
	new Main();
    }
}

Measured memory_bytes: 20616
Ai = list(map(int, input().split()))
Ai.sort()

d1 = Ai[2] - Ai[1]
d2 = Ai[2] - Ai[0]

total = 0
total += (d1 // 2) + (d2 // 2)

if d1 % 2 > 0 and d2 % 2 > 0:
    total += 1
elif d1 % 2 > 0 or d2 % 2 > 0:
    total += 2

print(total)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    long long ans =1;
    for(int i =0;i<n;i++){
        if(s[i]!= '0'){
            char c = s[i];
            s[i] = '0';
            int temp=1;
            for(int j=i+1;j<n;j++){
                if(s[j]==c){
                    temp++;
                    s[j]='0';
                }
            }
            ans*= (temp+1);
          	ans = (ans%1000000007);
        }
    }
    ans--;
    cout<<(ans%1000000007);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1) {
        cout << "No\n";
        return;
    }
    int half = n / 2;
    for (int i = 0; i < half; ++i) {
        if (s[i] != s[i + half]) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto sqr(T x) { return (x) * (x); }
void printd(double x) { printf("%.10lf\n", x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const int INF = INT_MAX;

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

	int ans;
	ans = (N - 1)/2;

	COL(ans);

	return 0;
}

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

int main() {
  
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }

  
  cout << ans << endl;
  
}


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

using namespace std;
typedef long long ll ;
#define forl(i,n) for(int i=0 ; i<n ; i++)

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n ;
		cin>>n ;
		int h[n+1] ;
		for(int i=1 ; i<=n ; i++)
			cin>>h[i] ;

		int dp[n+1] ;
		dp[0]=0 ;
		dp[1]=0 ;

		for(int i=2 ; i<=n ; i++)
		{
			dp[i]=1e9 ;

			for(int k=i-1 ; k>max((i-3),0) ; k-- )
			{
				dp[i]=min(dp[i] , abs(h[i]-h[k])+dp[k]) ;
			}
		}
		cout<<dp[n]<<endl ;
	}
	return 0;
}

Measured memory_bytes: 4376
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

inline int replace_one_nine(int n) {
    if (n == 1) return 9;
    else if (n == 9) return 1;
    else return n;
}

int main() {
    int N;
    cin >> N;
    cout << replace_one_nine(N / 100)*100 + replace_one_nine((N-(N/100)*100)/10)*10 + replace_one_nine(N % 10) << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

X = I()

ans = 0

ans += X // 500 * 1000
X %= 500

ans += X //5 * 5
X %= 5

print(ans)


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

int main () {
    int N, answer = 0;
    cin >> N;

    vector <int> a (N);
    for (int i = 0; i < N; i++){
        cin >> a .at(i);
    }
    for(int l = 0; l < N; l++){
        for(int i = 0; i < N - 1; i++){
        if (a .at(i) < a .at(i + 1)){
            int s = a .at(i + 1);

            a .at(i + 1) = a .at(i);
            a .at(i) = s;
            }
        }
    }
    /*for(int i = 0; i < N; i++){
        cout << a .at(i);
    }
    cout << endl;*/ /*並べ替えの確認*/
    for (int i = 0; i < N; i++){
        if(i % 2 == 0){
            answer += a .at(i);
        }
        else{
            answer -= a .at(i);
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;


int main(){
  char c; cin>>c;
  c=c-'a';
  c+=1;
  c=c+'a';
  cout<<c<<endl;

  return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T>
struct fenwick_tree {
    int n;
    T ZERO;
    std::vector<T> data;
    fenwick_tree(int n, T ZERO = T()) : n(n), ZERO(ZERO), data(n + 1, ZERO) {}
    void add(int i, T x) { for (i++; i <= n; i += i & -i) { data[i] += x; }}
    T get_sum(int i) const {
        if (i > n) { i = n; }
        T ret = ZERO;
        for (; i > 0; i -= i & -i) { ret += data[i]; }
        return ret;
    }
    T get_sum(int l, int r) const {
        if (l < r) { return get_sum(r) - get_sum(l); }
        else { return ZERO; }
    }
};

long long discrete_binary_search(long long ok, long long ng, const std::function<bool(long long)> &check) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

int N;
int a[110000];
signed main() {
    cin >> N;
    reps(i, N) { cin >> a[i]; }
    cout << discrete_binary_search(0, 1e9 + 1, [&](int x) {
        fenwick_tree<int> ft(220000);
        vint v(N + 1);
        reps(i, N) {
            if (a[i] >= x) { v[i] = 1; }
            else { v[i] = -1; }
            v[i] += v[i - 1];
        }
        int k = 0;
        for (int i = 0; i <= N; i++) {
            v[i] += 110000;
            k += ft.get_sum(v[i] + 1);
            ft.add(v[i], 1);
        }
        return k >= ((N * (N + 1)) / 2 + 1) / 2;
    }) << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vll a(n); for(auto& e : a) cin >> e;

    ll x = a[0];
    rep(i, 1, n){
        x += (i % 2 ? +1:-1) * a[i];
    }
    x /= 2;

    vll res(n);
    res[0] = 2 * x;
    rep(i, 1, n){
        x = a[i] - x;
        res[i] = 2 * x;
    }

    rep(i, n){
        cout << (i ? " ":"") << res[(i + n - 1) % n];
    }
    cout << endl;

    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  int N;
  scanf("%d", &N);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  std::vector<int> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &B[i]);
  }
  std::vector<int> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    scanf("%d", &C[i]);
  }

  int ans = 0;
  rep(i, 0, N - 1) {
    int index = A[i] - 1;
    ans += B[index];
    if (A[i] + 1 == A[i + 1]) {
      ans += C[index];
    }
  }
  ans += B[A[N - 1] - 1];

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

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string

	a := map[string]int{"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}

	fmt.Scanf("%s", &s)
	fmt.Println(a[s])
}

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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;
int a[Sz];
ll cnt[Sz];
void solveC() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    map <int, vec<int> > m;
    for (int i = 1; i <= n; i++)
        m[a[i]].pb(i);
    int mn = MX;
    int hv = 0;
    for (auto it = --m.end(); ; it--) {
        vec<int> &v = it->second;
        for (auto x : v)
            mn = min (mn, x);
        hv += sz(v);
        int times = it->first;  
        if (it != m.begin())
            times -= (--it)->first, it++;
        cnt[mn] += times * 1ll * hv;
        if (it == m.begin())
            break;
    }
    for (int i = 1; i <= n; i++)
        cout << cnt[i] << endl;
}
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  solveC();

  return 0;

}






// Coded by Z..

Measured memory_bytes: 14848
import java.util.Scanner;

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

    final String s = scanner.nextLine();

    for (int i = 0; i < s.length() - 2; i++) {
      if (s.charAt(i) == s.charAt(i + 2)) {
        System.out.println((i + 1) + " " + (i + 3));
        return;
      }
    }

    for (int i = 0; i < s.length() - 1; i++) {
      if (s.charAt(i) == s.charAt(i + 1)) {
        System.out.println((i + 1) + " " + (i + 2));
        return;
      }
    }

    System.out.println("-1 -1");
  }
}


Measured memory_bytes: 26296
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0&&W==0) break;
            for(int i=0;i<H;i++){
            for(int j =0;j<W;j++){
                System.out.printf("#");
                }
            System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}



Measured memory_bytes: 61544
import sys
input = sys.stdin.readline
N, S = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
  dp[i][0] = i + 1
  for j in range(S + 1):
    if j + a[i] < S:
      dp[i + 1][j + a[i]] += dp[i][j]
      dp[i + 1][j + a[i]] %= mod
    elif j + a[i] == S:
      dp[i + 1][j + a[i]] += dp[i][j] * (N - i)
      dp[i + 1][j + a[i]] %= mod
    dp[i + 1][j] += dp[i][j]
    dp[i + 1][j] %= mod
print(dp[-1][-1])


Measured memory_bytes: 113372
import numpy as np
a, b, h, m = map(int, input().split())

theta_a = 2*np.pi * (h+(m / (60.0))) / (12.0)
theta_b = 2*np.pi * m / (60.0)


def pos(r, theta):
    return r*np.cos(theta), r*np.sin(theta)

x_a, y_a = pos(a, theta_a)
x_b, y_b = pos(b, theta_b)

d2 = (x_a - x_b)**2 + (y_a - y_b)**2
print(np.sqrt(d2))

Measured memory_bytes: 27220
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n; cin >> n; if (n == 0) break;
		vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i];
		int res = -1;
		for (int i = 0; i < n; i++) {
			int f = 0;
			int sum = 0;

			for (int j = i; j < n; j++) {
				sum += vs[j].size();
				if (f == 0 or f == 2) {
					if (sum == 5) {
						f++;
						sum = 0;
					}
					else if (sum > 5) {
						break;
					}
				}
				else {
					if (sum == 7) {
						f++;
						sum = 0;
					}
					else if (sum > 7) break;
				}
				if (f == 5) {
					res = i + 1;
					break;
				}
			}
			if (res != -1) break;
		}
		cout << res << "\n";
	}
	return 0;

}



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

// o(n * log(n)) 最大公約数はo(log(n))

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

int main() {
  int n;
  cin >> n;
  ll x;
  cin >> x;
  ll res = 0;
  rep(i, n) {
    ll xi;
    cin >> xi;
    res = gcd(res, abs(xi - x));
  }
  cout << res << endl;
}

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

vector<int> G[100000];
int64_t A[100000];
int N;

bool flag = true;

int64_t rec(int v, int parent){
    // cout<<v<<endl;
    if(!flag) return 0;
    vector<int64_t> f;
    for(auto c:G[v]){
        if(c!=parent) f.push_back(rec(c,v));
    }
    if(!flag) return 0;
    if(!f.size()) return A[v];
    int64_t F = 0;
    for(auto e:f) F+=e;
    int64_t G = A[v];
    int64_t down = F-G;
    int64_t up = G-down;
    int64_t ret = up;
    if(up<0||down<0){
        flag = false;
        return 0;
    }
    f.push_back(up);
    //下で相殺できるかテスト
    if(down){
        sort(f.begin(), f.end(),greater<int64_t>());
        F+=up;
        if(F%2||f[0]>F/2){
            // cout<<v<<'C'<<endl;
            flag = false;
            return 0;
        }
    }
    return ret;
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++) cin>>A[i];
    for(auto &g:G) g.clear();
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(rec(0,-1)&&G[0].size()!=1)flag=false;
    if(flag){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 17152
#include <stdio.h>

int main() {
    
    int n, t = 0;
    scanf("%d", &n);
    
    while (n >= 1000)
        n -= 1000;    

    if (n == 0)
        printf("%d", 0);
    else
        printf("%d", (1000 - n));
    
    return 0;
}

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

int main() {
  long n,ans=0,xx=1;
  cin >> n;
  vector<long> a(n);
  map<long,long> mp;
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<31;i++) xx*=2;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(long i=0;i<n;i++) {
    bool b=true;
    long x=xx;
    while(x>a[i]&&b) {
      if(mp[x-a[i]]>0) {
        b=false;
        ans++;
        mp[x-a[i]]--;
      }
      x/=2;
    }
    if(b)mp[a[i]]++;
  }
  cout << ans << endl;
}

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

using namespace std;

const int N = 10000005;
int lp[N+1];


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

    vector<int> pr;
    int n;
    cin >> n;
    for (int i=2; i<=n; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        int si = pr.size();
        for (int j=0; j<si && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }

    long long sum = 1;
    for(long long i = 2; i <= n; i++){

        long long h = i;
        map<int, int> mp;
        while(h != 1){
            mp[lp[h]]++;
            h /= lp[h];
        }

        long long t = 1;
        for(auto x : mp){
            t *= (x.second + 1);
        }

        sum += t * i;
    }
    cout << sum << '\n';
    return 0;
}
/* take it easy */

Measured memory_bytes: 46484
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <numeric>
#define rep(i,n) for(int i=0;i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main(){
        string s;
        string t;
        set<string>ans;
        cin >> s >> t;
        if(s.size() < t.size()){
                cout << "UNRESTORABLE" << endl;
                return 0;
        }
        for(int i = 0; i < s.size()-t.size()+1; i++){
                string temp = s.substr(i,t.size());
                bool flag = true;
                string hoge = s;
                for(int j = 0; j < t.size(); j++){
                        if(temp[j] != t[j] && temp[j] != '?'){
                                flag = false;
                                break;
                        }else{
                                hoge[i+j] = t[j];
                        }
                }
                if(flag){
                        rep(i,hoge.size()){
                                if(hoge[i] =='?'){
                                        hoge[i] = 'a';
                                }
                        }
                        ans.insert(hoge);
                }
        }
        
        if(ans.size())cout << *ans.begin() << endl;
        else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<usize>() - 1;
    }
    let mut ds0 = vec![0i64; 2 * m];
    let mut ds1 = vec![0i64; 2 * m];
    let mut sum = 0;
    for i in 0..n - 1 {
        let d = (m + aseq[i + 1] - aseq[i]) % m;
        sum += d;
        if d > 0 {
            ds1[aseq[i] + 1] += 1;
            ds1[aseq[i] + d] -= 1;
            ds0[aseq[i] + d + 1] -= d as i64 - 1;
        }
    }
    let mut dec = vec![0; m];
    let mut v = 0;
    let mut d1 = 0;
    for i in 0..2 * m {
        v += d1;
        v += ds0[i];
        dec[i % m] += v;
        assert!(v >= 0);
        d1 += ds1[i];
        assert!(d1 >= 0);
    }
    let mut ans = sum;
    for i in 0..m {
        ans = std::cmp::min(ans, sum - dec[i] as usize);
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
n,m=[int(i) for i in input().split()]
badone=[int(input()) for i in range(m)]
badstares=[1 for i in range(n)]
for i in badone:
    badstares[i-1]=0


stares=[-1 for i in range(n)]
if n==1:
    print(1)
else:
    for i in range(n):

        i=n-1-i
        if i==n-1:
            stares[i]=1
        elif i==n-2:
            if badstares[i]==0:
                stares[i]=-1
            else:
                stares[i]=1
        else:
            if badstares[i]==0:
                stares[i]=-1
            else:
                if stares[i+1]==-1 and stares[i+2]==-1:
                        stares[i]=-1
                elif stares[i+1]==-1 and stares[i+2]!=-1:
                        stares[i]=stares[i+2]
                elif stares[i+2]==-1:
                    stares[i]=stares[i+1]
                else:
                    stares[i]=stares[i+1]+stares[i+2]

    if stares[0]==-1 and stares[1]==-1:
        print(0)
    elif stares[0]==-1:
        print(stares[1]%1000000007)
    elif stares[1]==-1:
        print(stares[0]%1000000007)
    else:
        print((stares[0]+stares[1])%1000000007)

Measured memory_bytes: 471220
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

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

using namespace std;

int main(void){
    int A, B, M;

    cin >> A >> B >> M;

    vector<int> a(A);
    vector<int> b(B);
    int x[M], y[M], z[M];

    rep(i, A){
        cin >> a[i];
    }
    rep(i, B){
        cin >> b[i];
    }

    rep(i, M){
        cin >> x[i] >> y[i] >> z[i];
    }

    int amin, bmin, summin, dis;

    amin = *min_element(a.begin(), a.end());
    bmin = *min_element(b.begin(), b.end());
    summin = amin + bmin;

    rep(i, M){
        dis = a[x[i]-1] + b[y[i]-1] -z[i];
        if(summin > dis){
            summin = dis;
        }
    }

    cout << summin << endl;

    return 0;
}

Measured memory_bytes: 2176