akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		Console.WriteLine("{0}",(s[0]/s[1])+(s[0]%s[1]==0?0:1));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 11220
<?php
$n = trim(fgets(STDIN));
$i = 0;
while($i < $n){
$a[] = trim(fgets(STDIN));
++$i;
}

rsort($a);
$ans = $a[0];
if($ans > pow(10,17)*5){
echo $ans;
}else{
$i = 1;
while($i < $n){
$ans = lcm($ans,$a[$i]);
++$i;
}
echo $ans;
}

function gcd($a,$b){
return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function lcm($a,$b){
return $a / gcd($a,$b) * $b;
}

Measured memory_bytes: 3576
N, x = map(int, input().split())
a = list(map(int, input().split()))
dp = [[]]
a.sort()
ans = 0
f = False
for b in a:
    if b <= x:
        ans += 1
        x -= b
        f = True
    else:
        f = False
if x > 0 and f:
    ans -= 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int X;
	cin >> X;
	if (X >= 30) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

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

int main()
{
    string s; cin >> s;
    bool ans = false;

    int n = s.size();
    int j = n-1;
    for(int i = 0; i < (n-1)/2; i++) {
        if(s.at(i) == s.at(j)) {
            ans = true;
            j--;
            continue;
        } else {
            ans = false;
            break;
        }
    }

    if (ans) {
        int n2 = (n-1)/2;
        string s2 = s.substr(0, n2);
        j = n2-1;
        for(int i = 0; i < n2; i++) {
            if(s2.at(i) == s2.at(j)) {
                ans = true;
                j--;
                continue;
            } else {
                ans = false;
                break;
            }
        }
    }

    if(ans) {
        int n3 = n - ((n+3)/2-1);
        // cout << "n3 = " << n3 << endl;
        string s3 = s.substr((n-n3), n-1);
        // cout << "s3 = " << s3 << endl;
        j = n3-1;
        // cout << "j = " << j << endl;
        for(int i = 0; i < n3; i++) {
            if(s3.at(i) == s3.at(j)) {
                ans = true;
                j--;
                continue;
            } else {
                ans = false;
                break;
            }
        }
        
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, m) = (line[0], line[1]);
    let m: u64 = m as u64;
    let a: Vec<u64> = read_as_vec();


    let mut b: Vec<u64> = vec![0];
    let mut sum = 0;
    for elem in a{
        sum = (elem + sum) % m;
        b.push(sum);
    }

    let mut map = HashMap::new();
    let mut ans: u64 = 0;


    for elem in b{
        let x = map.entry(elem%m).or_insert(0);
        ans += *x;
        *x += 1;
    }

    /*
    for i in 0..n + 1 {
        let x = map.entry(b[i]).or_insert(0);
        ans += *x;
        *x += 1;
    }
    */


    println!("{}", ans);
}


Measured memory_bytes: 12756
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
typedef struct{
    int x,y;
}data;

int main(void){
    int n,i,m,d,tx,ty,ax,ay,bx,by;
    data a[200];
    while(1){
        n=in();
        if(!n)break;
        a[0].x=a[0].y=0;
        ax=ay=bx=by=0;
        rep(i,n-1){
            m=in();
            d=in();
            switch(d){
                case 0:tx=a[m].x-1;ty=a[m].y;break;
                case 1:tx=a[m].x;ty=a[m].y-1;break;
                case 2:tx=a[m].x+1;ty=a[m].y;break;
                case 3:tx=a[m].x;ty=a[m].y+1;break;
            }
            a[i+1].x=tx;
            a[i+1].y=ty;
            ax=max(ax,tx);
            ay=max(ay,ty);
            bx=min(bx,tx);
            by=min(by,ty);
        }
        print2(ax-bx+1,ay-by+1);
    }
    return 0;
}



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

int Q;

bool check(int n1, int K, int A, int B){
    int n2 = A - n1;
    int m1 = (n1 + K - 1) / K - 1;
    m1 = max(0, m1);
    int m2 = B - m1;
    if(m2 <= 1LL * (n2 + 1) * K) return true;
    else return false;
}

string compute(int A, int B, int C, int D){
    int num = max(A, B);
    int dom = min(A, B) + 1;
    int K = (num + dom - 1) / dom;
    int l = 0, r = A;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(check(mid, K, A, B)){
            l = mid;
        }else{
            r = mid - 1;
        }
    }
    int n1 = l, n2 = A - n1;
    int m1 = (n1 + K - 1) / K - 1;
    m1 = max(m1, 0);
    int m2 = B - m1;
    string ans = "";
    for(int i = C;i <= D;i++){
        if(i <= n1 + m1){
            if((i - 1) % (K + 1) + 1 == K + 1){
                ans.push_back('B');
            }else{
                ans.push_back('A');
            }
        }else{
            int j = i - n1 - m1;
            int left = m2 - K * n2;
            if(j <= left){
                ans.push_back('B');
            }else{
                j -= left;
                if((j - 1) % (K + 1) + 1 == 1){
                    ans.push_back('A');
                }else{
                    ans.push_back('B');
                }
            }
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> Q;
    while(Q--){
        int A, B, C, D;
        cin >> A >> B >> C >> D;
        cout << compute(A, B, C, D) << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int X = 0;
  if (n < a + b){
    X = a + b - n;
  }else{
    X = 0;
  }
  cout << min(a,b) << " " << X << endl;
}

Measured memory_bytes: 3640
def inpl(): return [int(i) for i in input().split()]
from collections import deque
H,W = inpl()
S =  []
for i in range(H):
    S.append(input())
    
dist = [[-1 for _ in range(W)] for _ in range(H)]
dist[0][0] = 1
Q = deque()
Q.append((0,0))
d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
while Q:
    nw, nh = Q.pop() 
    for dw, dh in d:
        if not 0 <= nh + dh <= H-1:
            continue
        if not 0 <= nw + dw <= W-1:
            continue
        if S[nh+dh][nw+dw] == '#':
            continue
        if dist[nh+dh][nw+dw] != -1:
            continue
        dist[nh+dh][nw+dw] =dist[nh][nw] +1
        Q.appendleft((nw+dw,nh+dh))
if dist[H-1][W-1] == -1:
    print(-1)
else:
    ans = 0
    for i in range(H):
        ans += S[i].count('.')
    ans -= dist[H-1][W-1]
    print(ans)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
#define Length 80000
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

bool used[110];

bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
	return a.first * a.first + a.second * a.second > b.first*b.first + b.second * b.second;
}

void solve(int n) {
	vector<pair<int, int>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0;i < n;i++) {
		cin >> q[i].first >> q[i].second;
	}
	int dist = Length, flag = 0;
	int ans = 0;
	sort(p.begin(), p.end());
	for (int i = 0;i < n;i++) {
		dist = Length;
		flag = 0;
		for (int j = 0;j < n;j++) {
			if (!used[j]) {
				int x = q[j].first - p[i].first;
				int y = q[j].second - p[i].second;
				if ((x > 0) && (y > 0) && y < dist) {
					dist = y;
					flag = j;
				}
			}
		}
		if (dist < Length) {
			ans++;
			used[flag] = true;
		}
	}
	cout << ans << endl;
}

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

ll rightvalue[100010];
ll leftvalue[100010];
ll rightmaxvalue1[100010];
ll leftmaxvalue1[100010];

int main(void){
	ll n, c, ans = 0, tmp = 0;
	cin >> n >> c;
	vector<ll>x(n + 1), v(n + 1);
	x[0] = 0;
	for (ll i = 1;i <= n;i++) {
		cin >> x[i] >> v[i];
		rightvalue[i] = rightvalue[i - 1] + v[i] - (x[i] - x[i - 1]);
		rightmaxvalue1[i] = max(rightvalue[i], rightmaxvalue1[i - 1]);
	}
	leftvalue[1] = leftvalue[0] + v[n] - (c - x[n]);
	leftmaxvalue1[1] = leftvalue[1];
	for (ll i = 2;i <= n;i++) {
		leftvalue[i] = leftvalue[i - 1] + v[n - i + 1] - (x[n - i + 2] - x[n - i + 1]);
		leftmaxvalue1[i] = max(leftvalue[i], leftmaxvalue1[i - 1]);
	}
	tmp = 0;
	for (ll i = 1;i <= n;i++) {
		ans = max(ans, rightvalue[i]);
		ans = max(ans, rightvalue[i] - x[i] + leftmaxvalue1[n - i]);
	}
	tmp = 0;
	for (ll i = 1;i <= n;i++) {
		ans = max(ans, leftvalue[i]);
		ans = max(ans, leftvalue[i] - (c - x[n - i + 1]) + rightmaxvalue1[n - i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  ll a,b,k;
  cin>>a>>b>>k;
  ll ag=min(a+k-1,b),bs=max(b-k+1,a);
  for(int i=a;i<=ag;i++)
    cout<<i<<"\n";

  for(int i=max(bs,ag + 1);i<=b;i++){
    cout<<i<<"\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100010
int n,X,Y,Z,a[N],b[N],c[N],id[N];
ll ans,tmp,s1[N],s2[N];
priority_queue<int,vector<int>,greater<int> >q;
inline char gc(){
    static char *S,*T,buf[1<<16];
    if(T==S){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=gc();}
    while('0'<=ch && ch<='9') x=x*10+ch-'0',ch=gc();
    return x*f;
}
inline bool cmp(int x,int y){return a[x]-b[x]>a[y]-b[y];}
int main(){
	X=read();Y=read();Z=read();n=X+Y+Z;
	for(int i=1;i<=n;++i){
		a[i]=read();b[i]=read();c[i]=read();
		id[i]=i;tmp+=b[i];
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=X;++i){
		s1[i]=s1[i-1]+a[id[i]]-b[id[i]];//1-i算ac的最大值 
//		sum+=a[id[i]]-c[id[i]];//堆中权值和 
		q.push(a[id[i]]-c[id[i]]);
	}
	for(int i=X+1;i<=X+Z;++i){
		s1[i]=s1[i-1]+c[id[i]]-b[id[i]];
		if(a[id[i]]-c[id[i]]>q.top()){
			int x=q.top();q.pop();
			q.push(a[id[i]]-c[id[i]]);
			s1[i]+=-x+a[id[i]]-c[id[i]];
		}
	}
	while(!q.empty()) q.pop();
	for(int i=n;i>=n-Y+1;--i){
//		s2[i]=s2[i-1]+c[id[i]]-b[id[i]];//1-i算ac的最大值 
//		sum+=a[id[i]]-c[id[i]];//堆中权值和 
		q.push(b[id[i]]-c[id[i]]);
	}
	for(int i=n-Y;i>=X+1;--i){
		s2[i]=s2[i+1]+c[id[i]]-b[id[i]];
		if(b[id[i]]-c[id[i]]>q.top()){
			int x=q.top();q.pop();
			q.push(b[id[i]]-c[id[i]]);
			s2[i]+=-x+b[id[i]]-c[id[i]];
		}
	}
	for(int i=X;i<=X+Z;++i){
		ans=max(ans,tmp+s1[i]+s2[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3324
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(n+1):
    total += abs(a[i] - a[i + 1])

for i in range(1,n+1):
    print(total + abs(a[i-1] - a[i + 1]) - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]))


Measured memory_bytes: 20532
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#define mod 1000000007
#define ll long long int 
using namespace std;
char a[1003][1003];
ll dp[1003][1003];

 ll h,w;
ll path(ll i,ll j)
{
    if(i==h && j==w)
      {;return 1;}
      
    if(a[i][j]=='#')
      return 0;
      
    if(dp[i][j]!=-1)
       return dp[i][j];
      
    if(i==h && j<w)
      return dp[i][j]=path(i,j+1)%mod;
      
    if(j==w && i<h)
      return dp[i][j]=path(i+1,j)%mod;
    else
      return  dp[i][j]=(path(i+1,j) + path(i,j+1))%mod;
}


int main()
{
   
    cin>>h>>w;
    memset(dp,-1,sizeof dp);
    for(ll i=1;i<=h;i++)
       for(ll j=1;j<=w;j++)
          cin>>a[i][j];
          
         
        
    ll ans=0;
    ans=path(1,1);
    
    cout<<ans;
   
    return 0;
}


Measured memory_bytes: 9088
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		String S = sc.get();
		String T = sc.get();
		System.out.println(T.startsWith(S) ? "Yes" : "No");
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 32756
A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+'+'+b+'+'+c+'+'+d
e2 = a+'+'+b+'+'+c+'-'+d
e3 = a+'+'+b+'-'+c+'+'+d
e4 = a+'+'+b+'-'+c+'-'+d
e5 = a+'-'+b+'+'+c+'+'+d
e6 = a+'-'+b+'+'+c+'-'+d
e7 = a+'-'+b+'-'+c+'+'+d
e8 = a+'-'+b+'+'+c+'-'+d
if eval(e1) == 7:
    print(e1+'=7')
elif eval(e2) == 7:
    print(e2+'=7')
elif eval(e3) == 7:
    print(e3+'=7')
elif eval(e4) == 7:
    print(e4+'=7')
elif eval(e5) == 7:
    print(e5+'=7')
elif eval(e6) == 7:
    print(e6+'=7')
elif eval(e7) == 7:
    print(e7+'=7')
elif eval(e8) == 7:
    print(e8+'=7')

Measured memory_bytes: 3064
n = int(input())
s_1 = list(input())
s_2 = list(input())
m = 1000000007
# h: 3
# w: 6(3*2)
# h->h: 2, h->w: 1
# w->h: 2, w->w: 3
combi, hist = 0, ''
for i in range(n):
    try:
        if s_1[i] == s_2[i]: # h
            if hist == '':
                combi = 3
            elif hist == 'h':
                combi *= 2
            else:
                combi *= 1
            hist = 'h'
        else: # w
            if hist == '':
                combi = 6
            elif hist == 'h':
                combi *= 2
            else:
                combi *= 3
            hist = 'w'
            s_1.pop(i)
            s_2.pop(i)
    except:
        break
print(combi%m)
exit(0)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			int[][] dp = new int[n+1][n+1];
			int max = 0;
			for(int i=1;i<=n;i++) {
				String line = sc.next();
				for(int j=1;j<=n;j++) if( line.charAt(j-1) == '.' ) {
					dp[i][j] = Math.min( Math.min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1] )+1;
					max = Math.max(max, dp[i][j]);
				}
			}
			System.out.println(max);
		}
	}
}

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

vector<int>E[100000];
int v[100000], d[100000], c[100000];
int c1[100000], c2[100000];
int d1[100000];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
	}
	int q; scanf("%d", &q);
	rep(i, q) {
		scanf("%d%d%d", &v[i], &d[i], &c[i]); v[i]--;
	}
	for (int i = q - 1; i >= 0; i--) {
		queue<int>que;
		memset(d1, -1, sizeof(d1));
		d1[v[i]] = d[i];
		if (c1[v[i]] == 0)c1[v[i]] = c[i];
		if (c2[v[i]] >= d1[v[i]])continue;
		c2[v[i]] = d1[v[i]];
		if (d1[v[i]])que.push(v[i]);
		while (!que.empty()) {
			int p = que.front(); que.pop();
			for (int u : E[p]) {
				if (d1[u] != -1)continue;
				d1[u] = d1[p] - 1;
				if (c1[u] == 0)c1[u] = c[i];
				if (c2[u] >= d1[u])continue;
				c2[u] = d1[u];
				if (d1[u])que.push(u);
			}
		}
	}
	rep(i, n)printf("%d\n", c1[i]);
}

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

int main()
{
    string s;
    int zero, one;
    getline(cin, s);
    zero = one = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '0')
            zero++;
        else
            one++;
    }
    cout << min(zero, one) * 2 << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
struct node{
	int num;
	int ans;
	int place;
}a[200005];
bool cmp1(node _1,node _2){
	return _1.num<_2.num;
}
bool cmp2(node _1,node _2){
	return _1.place<_2.place;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i].num);
		a[i].place=i;
	}
	sort(a+1,a+n+1,cmp1);
	for (int i=1;i<n;i++)
	    a[i].ans=a[n].num;
	a[n].ans=a[n-1].num;
	sort(a+1,a+n+1,cmp2);
	for (int i=1;i<=n;i++){
		printf("%d\n",a[i].ans);
	}
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
  int D, N;
  cin >> D >> N;
  if(N == 100){
    switch(D){
    case 0:
      cout << N + 1 << endl;
      break;
    case 1:
      cout << N * 100 + 100<< endl;
      break;
    case 2:
      cout << N  * 10000 + 10000 << endl;
      break;
    }
  }else{
    switch(D){
    case 0:
      cout << N << endl;
      break;
    case 1:
      cout << N * 100 << endl;
      break;
    case 2:
      cout << N * 10000 << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        bool isFirst = true;
        int[] coins = new int[] { 10, 50, 100, 500 };
        int range = 4;
        int bill, ownedMoney, changeMoney;
        int[] ownedCoins = new int[range], changeCoins = new int[range], paymentCoins = new int[range];

        while (true)
        {
            bill = int.Parse(Console.ReadLine());
            if (bill == 0) break;
            if (isFirst) { isFirst = false; } else { Console.WriteLine(); }
            ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            ownedMoney = 0;
            for (int i = range - 1; i >= 0; i--)
                ownedMoney += coins[i] * ownedCoins[i];

            changeMoney = ownedMoney - bill;

            for (int i = 3; i >= 0; i--)
            {
                changeCoins[i] = changeMoney / coins[i];
                changeMoney = changeMoney % coins[i];
                paymentCoins[i] = ownedCoins[i] - changeCoins[i];
            }
            for (int i = 0; i <= 3; i++)
                if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]);
        }
    }
}


Measured memory_bytes: 9252
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	set := make(map[string]bool)
	for i := 0; i < N; i++ {
		set[sc.nextStr()] = true
	}

	if len(set) == 3 {
		fmt.Fprintln(wtr, "Three")
	} else {
		fmt.Fprintln(wtr, "Four")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include<math.h>
#include<stdio.h>

int main() {
	int a, b, S, l;
	scanf("%d %d", &a, &b);//scanf?????´???/////////////////

	S = a*b;
	l = 2 * (a + b);

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

Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  int count = 0;
  for(int i = 0; i <=N/R; i++){
    for(int j = 0; G*j<=N-R*i; j++){
        int k = N-R*i-G*j;
        if(k>=0 && k%B==0 ){
          count ++;
        }
      }
    }
  cout << count << endl;
}



Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var b = [];
  var ans = [];
  for(var i = 0; i < n; i++)b.push([a[i],i+1]);
  b.sort((a,b)=>a[0]-b[0]);
  for(var i = 0; i < n; i++)ans.push(b[i][1]);
  return ans.join(" ");
}

Measured memory_bytes: 55916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		if(n == m) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define int long long int 
using namespace std;
void solve() {
	int n;
	cin >> n;
	vector<int> v(n + 1);
	vector<int> cnt(100010);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		ans += v[i];
		cnt[v[i]]++;
	}
	int q;
	cin >> q;
	while (q--) {
		int b , c;
		cin >> b >> c;
		ans += (c - b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << ans << endl;
	}
}

int32_t main()
{
	solve();
	
	
   
}

Measured memory_bytes: 4844
import java.util.*;
    public class Main {
    	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
	    // 整数の入力
	    int k = sc.nextInt();
	    // 出力

	    if(k == 1){
		System.out.println("1");
		System.out.println("1");
	    }else if(k == 2){
		System.out.println("2");
		System.out.println("1 2");
		System.out.println("2 1");
	    }else if(k == 3){
		System.out.println("2");
		System.out.println("1 2");
		System.out.println("3 1");
	    }else if(k == 4){
		System.out.println("2");
		System.out.println("1 2");
		System.out.println("3 4");
	    }else{
		int cut = 4 - k % 4;
		int n;
		int amari;
		if (cut != 4){
		    n = (k + cut) / 2;
		}else{
		    n = k / 2;
		    cut = 0;
		}
		System.out.println(n);
		for(int r = 0; r < n; r++){
		    for(int c = 0; c < n; c++){
			if (r % 2 == 0){
			    System.out.print((c + r) % n + 1 + " ");
			}else{
			    amari = (c + r) % n;
			    if(amari == n-1 && cut >= 1 ||
			       amari == n-2 && cut >= 2 ||
			       amari == n-3 && cut >= 3){
				System.out.print((c + r) % n + 1 + " ");
			    }else{
				System.out.print((c + r) % n + n + 1 + " ");
			    }
			}
		    }
		    System.out.println();
		}
	    }
	}
    }


Measured memory_bytes: 43888
a,b,c,d = map(int, (input().split()))


if a <= c and b <= d and c <= b:
    print(b-c)
elif c <= a and b <= d:
    print(b-a)
elif a <= c and d <= b:
    print(d-c)
elif c <= a and d <= b and a <= d:
    print(d-a)
else:
    print(0)

Measured memory_bytes: 3064
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1e5 + 10;
int a[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    int pp = 0;
    while (true) {
        int cnt_2 = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if (a[i] % 2 == 0) {
                cnt_2++;
            }
        }
        if (n % 2 == 0) {
            if (cnt_2 % 2 == 0) {
                cout << "Second\n";
            } else {
                cout << "First\n";
            }
            return 0;
        }
        if (cnt_2 != (n - 1)) {
            if ((cnt_2 % 2) == pp) {
                cout << "Second\n";
            }
            else {
                cout << "First\n";
            }
            return 0;
        }
        int where = -1;
        for (int i = 1; i <= n; i++) {
            if (a[i] % 2 == 1) {
                where = i;
                break;
            }
        }
        assert(where != -1);
        if (a[where] == 1) {
            if (pp == 0) cout << "Second\n";
            else cout << "First\n";
            return 0;
        }
        a[where]--;
        int gc_other = 0;
        for (int i = 1; i <= n; i++) {
            gc_other = __gcd(gc_other, a[i]);
        }
        assert(gc_other != 1);
        pp ^= 1;
        for (int i = 1; i <= n; i++) {
            a[i] /= gc_other;
        }
    }
    return 0;
}

Measured memory_bytes: 4040
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
fact = [1]*n
for i in range(1, n):
  fact[i] = fact[i-1]*(i+1)

pl = [i+1 for i in range(n)]
ql = [i+1 for i in range(n)]

pn = 0
qn = 0
for i in range(n-1):
  pn += pl.index(p[i])*fact[n-i-2]
  qn += ql.index(q[i])*fact[n-i-2]
  pl.remove(p[i])
  ql.remove(q[i])
print(abs(pn-qn))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;


int main(){
    int n;
    cin>>n;
    vector<long long int> s;
    for(int i=0;i<n+1;i++) s.push_back(0);
    for(int i=1;i<n+1;i++){
        int t;
        t=n/i;
        for(int j=1;j<t+1;j++){
            s[i*j]+=1;
        }
    }
    long long int sum=0;
    for(int i=1;i<n+1;i++){
        sum+=i*s[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 134456
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    map<int, int> mp;
    rep(i, n-1){
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }

    rep(i, n){
        cout << mp[i+1] << endl;
    }
    return 0;
}


Measured memory_bytes: 12972
#include<iostream>

using namespace std;

int N;
int* A;
int* B;
int* C;

int search(int ryouri) {
  for (int i=0; i<N; i++) {
    if (A[i] == ryouri) return i;
  }
}

int main() {

  cin >> N;
  A = new int[N];
  B = new int[N];
  C = new int[N-1];
  
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int i=0; i<N; i++) {
    cin >> B[i];
  }
  for (int i=0; i<N-1; i++) {
    cin >> C[i];
  }
  
  int sum = 0;
  int previous = -1;
  for (int i=0; i<N; i++) {
    sum += B[A[i]-1];
    if (A[i] - previous == 1) sum += C[previous-1];
    previous = A[i];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(a-x) < abs(x-b)){
    cout << 'A' << endl;
  } else {
    cout << 'B' << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
MOD = 1000000007


def main():
  S = str(input())
  dp = [[0 for _ in range(3)] for _ in range(len(S)+1)]
  A,AB,ABC = [0,1,2]
  wc_num = 1
  for i,s in enumerate(S):
    if s in "A?":
      dp[i+1][A] = (dp[i+1][A]+dp[i][A]+wc_num) % MOD
      dp[i+1][AB] = (dp[i+1][AB]+dp[i][AB]) % MOD
      dp[i+1][ABC] = (dp[i+1][ABC]+dp[i][ABC]) % MOD
    if s in "B?":
      dp[i+1][A] = (dp[i+1][A]+dp[i][A]) % MOD
      dp[i+1][AB] = (dp[i+1][AB]+dp[i][AB]+dp[i][A]) % MOD
      dp[i+1][ABC] = (dp[i+1][ABC]+dp[i][ABC]) % MOD
    if s in "C?":
      dp[i+1][A] = (dp[i+1][A]+dp[i][A]) % MOD
      dp[i+1][AB] = (dp[i+1][AB]+dp[i][AB]) % MOD
      dp[i+1][ABC] = (dp[i+1][ABC]+dp[i][ABC]+dp[i][AB]) % MOD
    if s == "?":
      wc_num = (wc_num*3) % MOD
  print(dp[len(S)][ABC])



if __name__ == "__main__":
  main()

Measured memory_bytes: 56028
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
string s = "a";
int n;
set<string> v;
void solve(int u) {
  if (u == n - 1) {
    v.insert(s);
    return;
  }
  char mx = 0;
  for (int i = 0; i <= u; i++) {
    s += s[i];
    mx = max(mx, s[i]);
    solve(u + 1);
    s.pop_back();
  }
  s += mx + 1;
  solve(u + 1);
  s.pop_back();
}
int main() {
  IOS;
  cin >> n;
  solve(0);
  for (string i : v) {
    cout << i << endl;
  }
}


Measured memory_bytes: 12628
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

def main():
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))

    move = 0

    for x in X:
        move += min(2*x, 2*abs(x-K))

    print(move)

main()


Measured memory_bytes: 4800
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// #define mp make_pair
//#define endl '\n'
 
int main() {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }
    else{
        string red = "red";
        cout << red << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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 T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    if(n%2==1){cout << 0 << endl; return 0;}
    int ans = 0;
    int tmp = 10;
    while(tmp<=n){
        ans += n/tmp;
        tmp*=5;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
ll p=1e9+7;
ll inf=1e18;
vector<vector<ll>>adj(2001);
vector<ll>used(2001,0);
vector<ll>ans(2001,0);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll i,j,w,h,y,r,k,d,m,t,a,b,n,x;
	cin>>n;
	ll arr[n+1];
	map<ll,ll>mp;
	ll ans=0;
	for(i=1;i<=n;i++)
	cin>>arr[i];
	for(i=1;i<=n;i++)
	{
	    mp[i+arr[i]]++;
	    ans+=mp[i-arr[i]];
	}
	cout<<ans;
	 
	return 0;
	
	
}

Measured memory_bytes: 28032
import sys
input = sys.stdin.readline
from itertools import accumulate

N,W = map(int,input().split())
WV = [[int(i) for i in input().split()] for _ in range(N)]

MINW = WV[0][0]

W0 = sorted([0] + [v for w,v in WV if w == MINW])
W1 = sorted([0] + [v for w,v in WV if w == MINW+1])
W2 = sorted([0] + [v for w,v in WV if w == MINW+2])
W3 = sorted([0] + [v for w,v in WV if w == MINW+3])

W0 = tuple(accumulate(W0))
W1 = tuple(accumulate(W1))
W2 = tuple(accumulate(W2))
W3 = tuple(accumulate(W3))

ans = 0
for w0 in range(len(W0)):
    for w1 in range(len(W1)):
        for w2 in range(len(W2)):
            for w3 in range(len(W3)):
                tmp = (len(W0) - (w0 + 1)) * MINW
                tmp += (len(W1) - (w1 + 1)) * (MINW+1)
                tmp += (len(W2) - (w2 + 1)) * (MINW+2)
                tmp += (len(W3) - (w3 + 1)) * (MINW+3)

                if tmp <= W:
                    tmp = W0[-1] - W0[w0]
                    tmp += W1[-1] - W1[w1]
                    tmp += W2[-1] - W2[w2]
                    tmp += W3[-1] - W3[w3]
                    ans = max(ans, tmp)

print(ans)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;

vl A;
vl A2;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;


    ll tot = 0;
    cin >> n;
    for(int c1 = 0; c1 < n ;c1++){
        cin >> a;
        A.push_back(a);
    }
    for(int c1 = 0; c1 < n ;c1++){
        cin >> a;
        A[c1]-=a;
        A2.push_back(A[c1]);
        tot+=A[c1];
    }
    if(tot < 0){
        cout << "-1\n";
        return 0;
    }
    sort(all(A));
    sort(all(A2));
    ll r = n-1;
    ll ans = 0;
    for(int c1 = 0; c1 < n; c1++){
        if(A[c1] >= 0)break;
        while(-A[c1] > A[r]){
            A[c1] += A[r];
            A[r] = 0;
            r--;
        }
        A[r] += A[c1];
        ans++;
    }
    ans += (n-1-r)+(A[r] != A2[r]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2548
from collections import deque 


N, M = map(int, input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    to[a].append(b)
    to[b].append(a)
    
que = deque()
que.append(0)
dist = [-1] * N
dist[0] = 0

while que:
    island = que.popleft()
    for nxt in to[island]:
        if dist[nxt] != -1:
            continue
        que.append(nxt)
        dist[nxt] = dist[island] + 1
        
print('POSSIBLE' if dist[N - 1] == 2 else 'IMPOSSIBLE')

Measured memory_bytes: 112736
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll x, y;
    cin>>x>>y;
    ll a=-1, b=-1;
    if((y-2*x)%2==0){
        a = (y-2*x)/2;
        b = x-a;
        if(a>=0&&b>=0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<stack>
using namespace std;
int main() {
	static int N, A[200001] = {};
	cin >> N;
	for (int i = 1;i <= N;++ i) cin >> A[i];
	int ans = 0, max = N, mid, halfDiff, tmp;
	while(halfDiff = max - ans >> 1) { // 二分探索
		bool check = false;
		mid = ans + halfDiff;
		stack<pair<int, int> > stk;
		for (int j = 1;j <= N;++ j) { // シミュレーション
			if (A[j - 1] < A[j]) stk.push(make_pair(A[j], 1)); // 文字数が増えるパターン
			else { // 文字数が減るパターン
				while (!stk.empty() && stk.top().first > A[j]) stk.pop();
				if (stk.empty() || stk.top().first < A[j]) stk.push(make_pair(A[j], 1));
				while (++ stk.top().second > mid) {
					tmp = mid == 1 ? 1 : stk.top().first;
					if (tmp == 1) goto break_label;
					stk.pop();
					if (stk.empty() || stk.top().first != tmp - 1) stk.push(make_pair(tmp - 1, 1));
				}
			}
		}
		check = true;
		break_label:;
		(check ? max : ans) = mid;
	}
	cout << max;
	return 0;
}


Measured memory_bytes: 2720
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=17;
int g[MAX_N][MAX_N];
int dp[1<<MAX_N];
int n;
int calc(int mask)
{
	int ret=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if((mask>>i&1)  && (mask>>j&1))ret+=g[i][j];
		}
	}
	return ret;
}
signed main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>g[i][j];
		}
	}
	for(int i=0;i<(1<<n);i++)dp[i]=calc(i);
	for(int i=0;i<(1<<n);i++)
	{
		for(int sub=i&(i-1);sub;sub=(sub-1)&i)
		{
			dp[i]=max(dp[i],dp[sub]+dp[i^sub]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

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

long long qmin(long long a, long long b){
	return (a < b) ? a : b;
}
long long qmax(long long a, long long b){
	return (a > b) ? a : b;
}

string s;
int n;
long long len[500500];

int main(){
	cin >> s;
	n = (int)(s.size()) + 1;
	int now = 0, prenow = 0, cnt = 0;
	while(now < n-1){
		while(now < n-1 && s[now] == '<') now++;
		len[cnt++] = now - prenow;
		prenow = now;
		while(now < n-1 && s[now] == '>') now++;
		len[cnt++] = now - prenow;
		prenow = now;
	}
	long long ans = 0;
	for(int i = 0; i < cnt; i += 2){
		ans += (1LL * (len[i] * (len[i] - 1) / 2LL)) + (1LL * len[i+1] * (len[i+1] - 1) / 2LL) + qmax(len[i], len[i+1]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int W,H,X,Y,R;
  cin >> W >> H >> X >> Y >> R;
  if(0<=X-R && X+R<=W && 0<=Y-R && Y+R<=H){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3088
n, m = [int(x) for x in input().split()]
c = [0] + [int(x) for x in input().split()]
INF = float('inf')
dp = [[0] + [INF for _ in range(n)] for _ in range(2)]

for i in range(1, m + 1):
    for j in range(1, n + 1):
        if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1)

print(dp[m % 2][n])


Measured memory_bytes: 9796
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[112345];
int main() {
	int n, i;
	cin >> n;
	for (i = 0; i < n; ++i)cin >> a[i];
	sort(a, a + n);
	vector<pair<int, int>>t;
	int cnt = 0;
	t.push_back({ a[0],1 });
	for (i = 1; i < n; ++i) {
		if (a[i] != a[i - 1]) {
			t.push_back({ a[i],1 });
			++cnt;
		}
		else t[cnt].second++;
		if (cnt >= 3)break;
	}
	if (cnt >= 3)cout << "No" << endl;
	else if (cnt == 0) {
		if (t[0].first == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (n % 3)cout << "No" << endl;
		else {
			if (cnt == 1) {
				if (t[0].first == 0 && t[0].second == (n / 3))cout << "Yes" << endl;
				else cout << "No" << endl;
			}
			else {
				if (t[0].second == t[1].second && t[1].second == t[2].second) {
					if ((t[0].first ^ t[1].first ^ t[2].first) == 0)cout << "Yes" << endl;
					else cout << "No" << endl;
				}
				else cout << "No" << endl;
			}
		}
	}
}

Measured memory_bytes: 3988
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }

    for (int i = 0;; i++) {
      int plus = x + i;
      int minus = x - i;
      if (!list.contains(minus)) {
        System.out.println(minus);
        return;
      }
      if (!list.contains(plus)) {
        System.out.println(plus);
        return;
      }
    }

  }

}

Measured memory_bytes: 35828