akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() throws FileNotFoundException {
		solver();
	}

	@SuppressWarnings("unchecked")
	void solver() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int na = sc.nextInt();
		int nb = sc.nextInt();
		int w = sc.nextInt();
		int[][] p = new int[na + nb][3];
		for (int i = 0; i < na; ++i) {
			p[i][0] = 0;
			p[i][1] = sc.nextInt();// m
			p[i][2] = sc.nextInt();// c
		}
		for (int i = na; i < na + nb; ++i) {
			p[i][0] = 1;
			p[i][1] = sc.nextInt();// m
			p[i][2] = sc.nextInt();// c
		}

		Arrays.sort(p, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[2] != o2[2])
					return Integer.compare(o1[2], o2[2]);
				else
					return Integer.compare(o1[1], o2[1]);
			}
		});

		long[][] f = new long[2][w + 1];
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = -1;
			}
		}
		long ans = Long.MAX_VALUE / 16;
		int t = 0;
		for (int i = 0; i < na + nb; ++i) {
			if (p[i][1] > w)
				continue;
			for (int j = w - p[i][1]; j >= 1; --j) {
				f[p[i][0]][j + p[i][1]] = Math.max(f[p[i][0]][j + p[i][1]], f[p[i][0]][j]);
			}
			f[p[i][0]][p[i][1]] = p[i][2];
			ans = Math.min(ans, Math.max(g(f, p[t][2]), p[i][2] - p[t][2]));
			while (t + 1 <= i && g(f, p[t][2]) < p[i][2] - p[t][2]) {
				++t;
				ans = Math.min(ans, Math.max(g(f, p[t][2]), p[i][2] - p[t][2]));
			}
		}
		System.out.println(ans);
	}

	long g(long[][] f, long lower) {
		long ret = Long.MAX_VALUE / 16;
		long las = Long.MAX_VALUE / 16;
		for (int i = 1; i < f[0].length; ++i) {
			if (f[1][i] >= lower)
				las = i;
			if (f[0][i] < lower)
				continue;
			ret = Math.min(ret, Math.abs(i - las));
		}
		las = -Long.MAX_VALUE / 16;
		for (int i = 1; i < f[1].length; ++i) {
			if (f[0][i] >= lower)
				las = i;
			if (f[1][i] < lower)
				continue;
			ret = Math.min(ret, Math.abs(i - las));
		}
		return ret;
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 36436
N=int(input())
Num=list(map(int,input().split()))
for i in range(N):
    if Num[i]%2==1:
        None
    else:
        if Num[i]%3==0 or Num[i]%5==0:
            None
        else:
            print("DENIED")
            exit()
print("APPROVED")

Measured memory_bytes: 38384
s=input()
S=list(s)
m1=0
m2=0
if S[0]=='0':
    if S[1]!='0':
        m1=1
    else:
        m1=0

elif S[0]=='1':
    if S[1]=='0' or S[1]=='1' or S[1]=='2':
        m1=1
    else:
        m1=0
else:
    m1=0

if S[2]=='0':
    if S[3]!='0':
        m2=1
    else:
        m2=0
elif S[2]=='1':
    if S[3]=='0' or S[3]=='1' or S[3]=='2':
        m2=1
    else:
        m2=0
else:
    m2=0

if m1==1 and m2==1:
    print('AMBIGUOUS')

elif m1==1:
    print('MMYY')

elif m2==1:
    print('YYMM')

else:
    print('NA')


Measured memory_bytes: 38384
from sys import stdin, setrecursionlimit as srl
from threading import stack_size, Thread
from math import *
from collections import *
from heapq import *

srl(int(1e9)+7)
stack_size(int(1e8))

'''
deque
1) append
2) appendleft
3) pop
4) popleft
5) insert, remove, index, count, extend, extendleft, reverse
6) rotate           # negative value rotates to the left , positive to the right
'''

'''
heapq

minheap by default but can be used as maxheap by pushing elements after multiplying them with -1

1) heapify ( iterable )
2) heappush ( heap, element)
3) heappop (heap)                   # smallest is removed
4) heappushpop (heap, element)
5) heapreplace (heap, element)      # same as heappushpop but first popped then pushed
'''

def solve():
    #start here
    n = int(input())
    h = list(map(int,input().split()))
    dp = [0 for i in range(n)]
    dp[1] = abs(h[1] - h[0])
    for i in range(2, n):
        dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    print(dp[n-1])


Thread(target=solve).start()

Measured memory_bytes: 21456
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb emplace_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
typedef long long ll;
const int N=105,M=90;
struct node{
	ll x,y;
	inline node(R ll xx,R ll yy):x(xx),y(yy){}
};vector<node>g[N];
ll f[N],n,m,T,res,cnt;
int main(){
	f[0]=f[1]=1;fp(i,2,M)f[i]=f[i-1]+f[i-2];
	g[1].pb(node(1,2)),g[1].pb(node(1,3)),g[1].pb(node(1,4));
	fp(i,1,M-3){
		for(auto v:g[i]){
			R ll x=v.y,y=v.x+x;
			while(y<=f[i+3]+f[i])g[i+1].pb(node(x,y)),y+=x;
		}
	}
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld",&n,&m);if(n>m)swap(n,m);
		for(cnt=1;f[cnt+1]<=n&&f[cnt+2]<=m;++cnt);
		if(cnt==1){printf("%lld %lld\n",cnt,n*m%P);continue;}
		res=0;
		for(auto v:g[cnt-1]){
			R ll x=v.x,y=v.y;
			if(y<=n)res+=(m-x)/y%P;
			if(y<=m)res+=(n-x)/y%P;
			res%=P;
		}
		printf("%lld %lld\n",cnt,res);
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;

int k, ans, sum1, sum3, sum2;

char s[N];

bool vis[N];

signed main() {
    cin >> s >> k;
    int len = strlen(s);
    if (len == 1) {
        cout << k / 2;
        return 0;
    }
    for (int i = 1; i < len; ++i) {
        if (s[i] == s[i - 1] && !vis[i - 1]) vis[i] = 1, sum1++;
    }
    for (int i = len; i < len * 3; ++i) s[i] = s[i - len];
    memset(vis, 0, sizeof vis);
    for (int i = 1; i < len * 2; ++i) {
        if (s[i] == s[i - 1] && !vis[i - 1]) vis[i] = 1, sum2++;
    }
    memset(vis, 0, sizeof vis);
    for (int i = 1; i < len * 3; ++i) {
        if (s[i] == s[i - 1] && !vis[i - 1]) vis[i] = 1, sum3++;
    }
    // cout << sum1 << " " << sum2 << " " << sum3;
    if (sum1 == sum2 - sum1) cout << sum1 * k;
    else if (sum1 == sum3 - sum2) cout << (k / 2) * sum2 + (k % 2) * sum1;
    else if (sum3 - sum2 == sum2 - sum1) cout << sum1 + (sum2 - sum1) * (k - 1);
}

Measured memory_bytes: 384
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
t=[int(input())for i in range(n)]
ans=1
for i in t:
    ans=lcm(ans,i)
print(int(ans))



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

int main() {
    int N;
    cin >> N;
    vector<bool> time(13, false);
    vector<bool> dup(13, false);
    for (int i = 0; i < N; i++) {
        int D;
        cin >> D;
        if (dup[D]) {
            cout << 0 << endl;
            return 0;
        }
        if (time[D]) dup[D] = true;
        time[D] = true;
    }
    int ans = 0;
    for (int i = 0; i < 8192; i++) {
        vector<int> t;
        t = {0, 24};
        for (int j = 0; j < 13; j++) {
            if (!time[j]) continue;
            if (dup[j]) {
                t.push_back(j);
                t.push_back(24-j);
                continue;
            }
            if ((i >> j) & 1) t.push_back(j);
            else t.push_back(24-j);
        }
        sort(t.begin(), t.end());
        int s = 24;
        for (int j = 1; j < (int)t.size(); j++) {
            s = min(s, t[j]-t[j-1]);
        }
        ans = max(ans, s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){

  int n, T;
  cin >> n >> T;
  int c[n], t[n];
  for(int i=0; i<n; i++){
    cin >> c[i] >> t[i];
  }

  int cost = 1001;

  for(int i=0; i<n; i++){
    if(t[i]<=T){
      cost = min(cost, c[i]);
    } 
  }   

  if(cost == 1001){
    cout << "TLE" << endl;
  }else{
    cout << cost << endl;
  }
  
  return 0;  
}




Measured memory_bytes: 256
package main

import (
	"fmt"
)

var N int
var x, y, t []int

func main() {
	fmt.Scanf("%d", &N)

	x = make([]int, N+1)
	y = make([]int, N+1)
	t = make([]int, N+1)

	for i := 1; i < N+1; i++ {
		fmt.Scanf("%d %d %d", &t[i], &x[i], &y[i])
	}

	if travel(0) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func travel(i int) bool {
	if i+1 < N+1 {
		dt, dx, dy := t[i+1]-t[i], Abs(x[i]-x[i+1]), Abs(y[i]-y[i+1])
		if dt >= dx+dy && dt%2 == (dx+dy)%2 {
			return travel(i + 1)
		}
		return false
	}

	return true
}

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


Measured memory_bytes: 12160
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

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

    int N = scanner.nextInt();
    Ball[] balls = new Ball[N];
    for (int i = 0; i < N; i++) balls[i] = new Ball(scanner.nextInt(), scanner.nextInt());
    Arrays.sort(balls, (b1, b2) -> {
      if (b1.x == b2.x) return b1.y - b2.y;
      return b1.x - b2.x;
    });

    Set<Pair> pqSet = new HashSet<>();
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i == j) continue;
        pqSet.add(new Pair(balls[j].x - balls[i].x, balls[j].y - balls[i].y));
      }
    }
    int min = N;
    for (Pair pq : pqSet) {
      Set<Ball> set = new LinkedHashSet<>(Arrays.asList(balls));
      int cost = 0;
      Ball next = null;
      while (!set.isEmpty()) {
        if (next == null || !set.contains(next)) {
          cost++;
          Ball b = set.stream().findFirst().get();
          set.remove(b);
          next = new Ball(b.x + pq.p, b.y + pq.q);
        } else {
          set.remove(next);
          next = new Ball(next.x + pq.p, next.y + pq.q);
        }
      }
      min = Math.min(min, cost);
    }
    System.out.println(min);
  }

  private static class Pair {
    private final int p;
    private final int q;

    private Pair(int p, int q) {
      this.p = p;
      this.q = q;
    }

    @Override public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Pair pair = (Pair) o;
      return p == pair.p &&
          q == pair.q;
    }

    @Override public int hashCode() {
      return Objects.hash(p, q);
    }
  }

  private static class Ball {
    private final int x;
    private final int y;

    private Ball(int x, int y) {
      this.x = x;
      this.y = y;
    }

    @Override public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Ball ball = (Ball) o;
      return x == ball.x &&
          y == ball.y;
    }

    @Override public int hashCode() {
      return Objects.hash(x, y);
    }
  }
}


Measured memory_bytes: 44980
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		int fivecount = 0;
		int sevencount = 0;
		Scanner scan = new Scanner(System.in);
		for(int i = 0; i < 3; i++){
			int a = scan.nextInt();
			if(a == 5){
				fivecount ++;
			}
			if(a == 7){
				sevencount ++;
			}
		}
		if(fivecount == 2 && sevencount == 1){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22484
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね

int main(){
    string s;
    cin >> s;
    int l=s.length();
    int r=0,p=0;
    int c[l][2];
    rep(i,s.length()){
        c[i][0]=r;
        c[l-1-i][1]=p;
        if(s[i]=='R'){
            r++;
        }else{
            r=0;
        }
        if(s[l-1-i]=='L'){
            p++;
        }else{
            p=0;
        }
    }
    int ans[l]={0};

    rep(i,l-1){
        if(s[i]=='R'&&s[i+1]=='L'){
            ans[i]=c[i][0]/2+c[i][1]/2+1;
            ans[i+1]=c[i+1][0]/2+c[i+1][1]/2+1;
            i++;
        }else{
            ans[i]=0;
        }
    }
    rep(i,l){
        cout<<ans[i]<<' ';
    }
    return 0;
}

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

int main(){

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

    int ans = 0;
    for(int i = 0; i < n; i += 2){
        int l = min(x[i], w - x[i + 1]);
        int r = max(w + x[i], 2 * w - x[i + 1]);
        ans += h * 2 * w - h * (r - l);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3124
s = input()
if len(s) < 7:
    print("NO")
if s[0] != "k":
    if s[-7] == "k" and s[-6] == "e" and s[-5] == "y" and s[-4] == "e" and s[-3] == "n" and s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[1] != "e":
    if s[-6] == "e" and s[-5] == "y" and s[-4] == "e" and s[-3] == "n" and s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[2] != "y":
    if s[-5] == "y" and s[-4] == "e" and s[-3] == "n" and s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[3] != "e":
    if s[-4] == "e" and s[-3] == "n" and s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[4] != "n":
    if s[-3] == "n" and s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[5] != "c":
    if s[-2] == "c" and s[-1] == "e":
        print("YES")
    else:
        print("NO")
elif s[6] != "e":
    if s[-1] == "e":
        print("YES")
    else:
        print("NO")
else:
    print("YES")


Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    
    char S[50] = {};
    int flagA = 0;
    int flagB = 0;
    scanf("%s",S);

    
    if (S[2] == '0' || ((S[2] == '1') & (S[3] == '0' || S[3] == '1' || S[3] == '2'))) {
        flagA++;
        if (S[2] == '0' & S[3] == '0') {
            flagA = 0;
        }
    }
    if (S[0] == '0' || ((S[0] == '1') & (S[1] == '0' || S[1] == '1' || S[1] == '2'))) {
        flagB++;
        if ((S[0] == '0' & S[1] == '0')) {
            flagB = 0;
        }
    }
    if (S[0] == '0' & S[1] == '0' & S[2] == '0' & S[3] == '0') {
        printf("NA");
        return 0;
    }
    if ((S[2] == '0' & S[3] == '0') & ((S[0] == '0') || ((S[0] == '1') & (S[1] == '0' || S[1] == '1' || S[1] == '2')))) {
        printf("MMYY");
        return 0;
    }
    if ((S[0] == '0' & S[1] == '0') & ((S[2] == '0') || ((S[2] == '1') & (S[3] == '0' || S[3] == '1' || S[3] == '2')))) {
        printf("YYMM");
        return 0;
    }

    if (flagA == 1 & flagB == 1) {
        printf("AMBIGUOUS");
    }else if(flagA == 1 && flagB == 0){
        printf("YYMM");
    }else if(flagA == 0 && flagB == 1){
        printf("MMYY");
    }else{
        printf("NA");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

void bubble (vector<int> &a, int n, int &cnt) {
    bool flag = 1;
    while (flag) {
        flag = 0;
        for (int i = n - 1; i > 0; i--) {
            if (a[i] < a[i - 1]) {
                int v = a[i];
                a[i] = a[i - 1];
                a[i - 1] = v;
                flag = 1;
                cnt++;
            }
        }
    }
    rep (i, n) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << "\n";
}

int main() {
    int n, cnt = 0;
    cin >> n;
    vector<int> vec (n);
    rep (i, n) cin >> vec[i];
    bubble (vec, n, cnt);
    cout << cnt << "\n";
}



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

int main() {
  int N, count;
  cin >> N;
  vector<char>S(N);
  vector<char>check(4);
  for (int i = 0; i < 4; i++) {
    check.at(i) = 'a';
  }
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'P') {
      check.at(0) = 'b';
    }
    else if (S.at(i) == 'W') {
      check.at(1) = 'b';
    }
    else if (S.at(i) == 'G') {
      check.at(2) = 'b';
    }
    else if (S.at(i) == 'Y') {
      check.at(3) = 'b';
    }
  }
  for (int i = 0; i < 4; i++) {
    if (check.at(i) == 'b') {
      count++;
    }
  }
  if (count == 3) {
    cout << "Three";
  }
  else if (count == 4) {
    cout << "Four";
  }
}

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

typedef long long ll;

using namespace std;
ll mod = 1000000007;
int n, m;

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

    cin >> n >> m;
    //vector<pair<int,int>> A;
    int l = 0;
    int r = 10000000;
    for (int i = 0; i < m; i++) {
        int q,p;
        cin >> q >> p;
        l = max(l, q);
        r = min(r, p);
    }
    if (l > r) {
        cout << 0;
    } else {
        cout << (r-l+1) << endl;
    }
    return 0;
}


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

int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << " " << y;
}


Measured memory_bytes: 3552
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long int ll;

int MAX(int a, int b){return a>b?a:b;}
int MIN(int a, int b){return a>b?b:a;}
int compare(const void* a, const void* b){return *(int*)a - *(int*)b;}
int llcompare(const void* a, const void* b){return (int)(*(ll*)a - *(ll*)b);}
ll llMAX(ll a, ll b){return a>b?a:b;}
ll llMIN(ll a, ll b){return a>b?b:a;}
ll digits(ll a){ll tmp=a; ll cnt=0; while(tmp>0){tmp/=10; cnt+=1;} return cnt;}

int main(void){
    int n;
    scanf("%d", &n);
    ll a[n];
    for(int i=0; i<n; i++){scanf("%lld", &a[i]);}
  
    qsort(a, n, sizeof(ll), llcompare);

    int b_idx = 0;
    ll b[n];//本数が2本以上4本未満の長さ(長方形用)
    int c_idx = 0;
    ll c[n];//本数が4本以上の長さ(正方形用)
    for(int i=0; i<n; i++){b[i]=0; c[i]=0;}

    int cnt = 0;
    ll tmp = a[n-1];
    for(int i=n-1; i>=0; i--){
        if(tmp == a[i]){
            cnt += 1;
        }else{
            if(cnt > 3){
                c[c_idx] = tmp;
                c_idx += 1;
                b[b_idx] = tmp;
                b_idx += 1;
            }else if(cnt > 1){
                b[b_idx] = tmp;
                b_idx += 1;
            }
            tmp = a[i];
            cnt = 1;
        }
    }

    if(cnt > 3){
        c[c_idx] = tmp;
        c_idx += 1;

    }
    else if(cnt > 1){
        b[b_idx] = tmp;
        b_idx += 1;
    }

    ll ans = 0;

    for(int i=0; i<c_idx; i++){
        ans = llMAX(c[i]*c[i], ans);
    }

    for(int i=0; i<b_idx; i++){
        ans = llMAX(b[i]*b[i+1], ans);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2564
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int n,d,u = 1,v,r;

int main() 
{
	
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> d;
		if(d == u) u++;
		else r++;
		if(d == 1) v = 1;
	}
	if (v != 1)
		cout << "-1";
	else
		cout << r;



	return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.List (sort)

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  putStrLn . showResult $ solve s t

showResult True  = "Yes"
showResult False = "No"

solve s t = sort s < reverse (sort t)


Measured memory_bytes: 508
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < (limit); counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  int n;
  cin>>n;
  vector<string> s(n);
  rep(i,n)cin>>s[i];
  sort(s.begin(),s.end());
  int ans=1;
  int size=s.size()-1;
  rep(i,size){
    if(s[i]!=s[i+1])ans++;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 9540
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()
if all(i == a[0] for i in a):
    print(n//2)
    exit()

a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
m1 = c1.most_common(2)
m2 = c2.most_common(2)
if m1[0][0] == m2[0][0]:
    if len(c1) == 1:
        print(n-m1[0][1]-m2[1][1])
    elif len(c2) == 1:
        print(n - m1[0][1] - m2[1][1])
    else:
        print(min(n-m1[0][1]-m2[1][1], n-m1[1][1]-m2[0][1]))
else:
    print(n-m1[0][1] - m2[0][1])

Measured memory_bytes: 19040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  vector<bool> b(n,false);
  rep(i,k){
    int s,c;cin>>s>>c;s--;
    if(s==0&&c==0&&n!=1){
      cout<<-1;return 0;
    }
    if(b[s]&&a[s]!=c){
      cout<<-1;return 0;
    }
    a[s]=c;b[s]=true;
  }
  if(!b[0]&&n!=1)a[0]=1;b[0]=true;
  rep(i,n){
    cout<<(b[i]?a[i]:0);
  }
}

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

int main(void)
{
    int n, x, t; cin >> n >> x >> t;
    int s = n / x;
    int ans;
    if (n % x == 0)
    {
        ans = s * t;
    }
    else
    {
        ans = (s + 1) * t;
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int ret = false;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (4*i + 7*j == n) {
                ret = true;
                break;
            }
        }
    }
    if (ret == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int H, W; cin >> H >> W;
  vector<string> ss(H);
  for (int i = 0; i < H; ++i) cin >> ss[i];
  vector<bool> br(H, true), bc(W, true);

  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      if (ss[r][c] == '#') {
        br[r] = false, bc[c] = false;
      }
    }
  }

  for (int r = 0; r < H; ++r) {
    if (br[r]) continue;
    for (int c = 0; c < W; ++c) {
      if (bc[c]) continue;
      cout << ss[r][c];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3656
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize, k: i64, q: usize,
        a: [Usize1; q],
    }
    let mut p = vec![0; n];
    for i in a {
        p[i] += 1;
    }
    println!(
        "{}",
        p.iter()
            .map(|&p| if p + k > q as i64 { "Yes" } else { "No" })
            .join("\n")
    );
}


Measured memory_bytes: 4088
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;

ll N,M;
vector<int> graph[MAX_N];
int color[MAX_N];

bool dfs(int u,int p){
  // 二部グラフでなかったらtrue
  bool res = false;
  // cout << u << "," << p << endl;
  for(auto v:graph[u]){
    if(v==p) continue;
    if(res) break;
    if(color[v]==-1){
      color[v] = (color[u]+1)%2;
      res |= dfs(v,u);
    }else{
      if(color[u]==color[v]){
        return true;
      }
    }
  }
  return res;
}

int main(){
  cin >> N >> M ;
  rep(i,M){
    int a,b;
    scanf("%d%d",&a,&b);
    a--; b--;
    graph[a].pb(b); graph[b].pb(a);
  }
  fill(color,color+MAX_N,-1);
  color[0] = 0;
  ll ans;
  if(!dfs(0,-1)){
    ll a[2]; a[0] = a[1] = 0LL;
    rep(i,N) a[color[i]]++;
    ans = a[0] * a[1] - M;
  }else{
    ans = N*(N-1)/2 - M;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<cmath>
using namespace std;
#define int long long
int ans=1000000000000;
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            ans=min(ans,i+(n/i)-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long int x, y;
	cin >> x >> y;
	if(2*x <= y && y <= 4*x && ((y%2) == 0)) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3652
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random




def main():
    row,col = map(int, input().split())
    grid = [[] for _ in range(row)]
    cnt_grid_row = [[0]*col for _ in range(row)]
    cnt_grid_col = [[0]*col for _ in range(row)]
    # eprint(grid)
    for i in range(row):
        grid[i] = input()
    # eprint(grid)

    for i in range(len(grid)):
        cnt_temp=0
        start_temp=0
        for j in range(len(grid[i])):
            if grid[i][j]=='.':
                cnt_temp+=1
            if grid[i][j]=='#':
                for k in range(start_temp,j):
                    cnt_grid_row[i][k]=cnt_temp
                start_temp=j+1
                cnt_temp=0
                cnt_grid_row[i][j]=0
            elif j==col-1:
                for k in range(start_temp,col):
                    cnt_grid_row[i][k]=cnt_temp




    for i in range(col):
        cnt_temp=0
        start_temp=0
        for j in range(row):
            if grid[j][i]=='.':
                cnt_temp+=1
            if grid[j][i]=='#':
                for k in range(start_temp,j):
                    cnt_grid_col[k][i]=cnt_temp
                start_temp=j+1
                cnt_temp=0
                cnt_grid_col[j][i]=0
            elif j==row-1:
                for k in range(start_temp,row):
                    cnt_grid_col[k][i]=cnt_temp

    # for i in range(row):
    #     for j in range(col):
    #         eprint(cnt_grid_row[i][j],end="")
    #     eprint()

    # eprint()

    # for i in range(row):
    #     for j in range(col):
    #         eprint(cnt_grid_col[i][j],end="")
    #     eprint()

    max=0
    for i in range(row):
        for j in range(col):
            if grid[i][j]!='#':
                if cnt_grid_col[i][j]+cnt_grid_row[i][j]-1>max:
                    max=cnt_grid_col[i][j]+cnt_grid_row[i][j]-1
    print(max)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 119644
listW = list(input())
listW.sort()
counter=0
bef=0
index=0
flag=0
while index < len(listW):
    if index==0:
        bef=listW[index]
        counter=1
    elif listW[index]==bef:
        counter+=1
    else:
        if counter%2==0:
            bef=listW[index]
            counter=1
        else:
            flag=1
            break
    index+=1

if flag==0 and len(listW)%2==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;	
public class Main {	
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();	
        String str[] = line.split(" ");	
        int x = Integer.parseInt(str[0]);	
        int y = Integer.parseInt(str[1]);
        int z = x*y;
      if(z%2==0){
        System.out.println("Even");
      }else{
        System.out.println("Odd");
      }
    }
}

Measured memory_bytes: 21844
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();

		// 計算
		int result = a;
		if(a > b) result--;

		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){

int s,m,h ;   //変数を宣言

cin>> s;
h=s/3600 ;
m=(s%3600)/60;	//
s=s%60;
cout<< h << ":" << m << ":" << s << endl;	//面積・空白スペース・州の長さ・改行を出力
//ここに処理を記述していきます（この行は残しておいても、消しても大丈夫です）


return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a + b >= 24) {
		cout << a + b - 24 << endl;
	}
	else {
		cout << a + b << endl;
	}

	return 0;
}


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

template<class T,class U> inline void chmax(T&a,U b){if(a<b)a=b;}

int main(int argc, char *argv[])
{
	int n,m,q;
	scanf("%d %d %d", &n,&m,&q);
	vector<int> a(q), b(q), c(q), d(q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &a[i],&b[i],&c[i],&d[i]);
		a[i]--;b[i]--;
	}
	vector<int> A(n,1);
	int ans = 0;
	auto dfs = [&](auto&& dfs, int v) -> void{
		while (A[v] <= m) {
			if (v == n-1) {
				int tmp = 0;
				for (int i = 0; i < q; i++) {
					tmp += A[b[i]] - A[a[i]] == c[i] ? d[i] : 0;
				}
				chmax(ans,tmp);
			}
			else {
				if (A[v+1] < A[v]) {
					A[v+1] = A[v];
				}
				dfs(dfs, v+1);
			}
			A[v]++;
		}
		A[v] = 1;
		return;
	};
	dfs(dfs, 0);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int N,M,a;
  cin>>N>>M;
  vector<int>X(N,0);
  for(int i=0;i<2*M;i++){
    cin>>a;
    X.at(a-1)++;
  }
  for(int i=0;i<N;i++)cout<<X.at(i)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
 
int main(void){
	int n, k;
	cin >> n >> k;
	vector<int> arr = vector<int>(n);
	int min_index = -1;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		if(arr[i] == 1) min_index = i;
	}
 
	int result = 0;
	int j = 0;
	for(int i = 0; i < n; i++, j++){
		if(j == k){
			result++;
			j = 1;
		}
	}
	if(j > 1) result++;
 
	cout << result << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll k,n,z=0;
    cin >> k >> n;
    ll nl[n],ans[n];
    for (ll i=0;i<n;i++){
        cin >> nl[i];
    }
    ans[0]=k-nl[n-1]+nl[0];
    for (ll i=1;i<n;i++){
        ans[i]=nl[i]-nl[i-1];
    }
    for (ll i=0;i<n;i++){
        z=max(z,ans[i]);
    }
    cout << k-z << endl;
    return 0;
}


Measured memory_bytes: 3328
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

#define __DBG__


void solve(void){

  int A[3][3];
  int C[3][3];
    
  REP (i,3){
    REP (j,3){
      cin >> A[i][j];
      C[i][j]=0;
    }
  }
  
  int N;
  
  cin >> N;
  
  int b[N];
      
  REP(i,N){
    cin >> b[i];
    
    REP(p,3){
      REP(q,3){
        if (A[p][q]==b[i]){
          C[p][q]=1;
        }
      }
    }
  }
  
  bool flag = 0;
  
  
  REP(p,3){
    int count=0;
    REP(q,3){
      if (C[p][q]==1){
        count++;
      }
    }
    if(count==3){
      flag=1;
      break;
    }
  }
  
  REP(q,3){
    int count=0;
    REP(p,3){
      if (C[p][q]==1){
        count++;
      }
    }
    if(count==3){
      flag=1;
      break;
    }
  }
  
  if(C[0][0]==1&&C[1][1]==1&&C[2][2]==1){
    flag=1;
  }
  
  if(C[2][0]==1&&C[1][1]==1&&C[0][2]==1){
    flag=1;
  }
  
  if(flag){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  

  return;
}

int main(int argc, const char * argv[]) {


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}



Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = [int(x.strip()) for x in input().split()]
toll = [0 for x in range(n+1)]
ans = 0
for i in a:
  toll[i] = 1
ans = min(sum(toll[0:x+1]),sum(toll[x:n+1]))
print(ans)

Measured memory_bytes: 9112
import java.util.Scanner;

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

		// 整数の入力
		String S = sc.next();

		if(S.endsWith("s")){
			System.out.println(S + "es");
		}else{
			System.out.println(S + "s");
		}

		sc.close();
	}
}

Measured memory_bytes: 38448
using System;

namespace At_Coder_Beginner_Contest147__A_Blackjack
{
    class Program
    {
        static void Main(string[] args)
        {
            int A1, A2, A3;
            var word = Console.ReadLine().Split(' ');
            A1 = int.Parse(word[0]);
            A2 = int.Parse(word[1]);
            A3 = int.Parse(word[2]);
            if (A1+A2+A3>=22)
            {
                Console.WriteLine("bust");
            }
            else if (A1+A2+A3<=21)
            {
                Console.WriteLine("win");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n,x,y;
  cin>>n>>x>>y;
  x--;y--;
  vector<vector<int>>d(n+5,vector<int>(n+5));
  rep(i,n){
    REP(j,i+1,n)d[i][j]=j-i;
  }
  rep(i,n){
    REP(j,x+1,n){
      d[i][j]=min(d[i][j],d[min(i,x)][max(i,x)]+1+abs(y-j));
    }
  }
  // rep(i,n){
  //   REP(j,i+1,n){
  //     cout<<i<<" "<<j<<" "<<d[i][j]<<endl;
  //   }
  // }
  vector<int>dist(n+5);
  rep(i,n){
    REP(j,i+1,n){
      dist[d[i][j]]++;
    }
  }
  REP(i,1,n)cout<<dist[i]<<endl;
}

int main(){
    ios::sync_with_stdio(false);
  cin.tie(0);
    cout<<fixed<<setprecision(15);
  solve();
    return 0;
}


Measured memory_bytes: 16000
def replacing_integer():
    # 入力
    N, K = map(int, input().split())
    # 処理
    now_num = N % K
    while True:
        if abs(now_num - K) <= now_num:
            now_num = abs(now_num - K)
        else:
            return now_num

result = replacing_integer()
print(result)

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {
  int K, A, B;
  cin >> K >> A >> B;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;


}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main(void)
{
    int n;
    int a[100001];

    cin >> n;

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

    int t = 1;
    int count = 1;
    bool flag = false;
    while(1) {
        if (count == n) {
            break;
        }
        if (a[t] == 2) {
            flag = true;
            break;
        }
        t = a[t];
        count++;
    }

    if (flag) {
        cout << count << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
 
        int a = scan.nextInt();
        int b = scan.nextInt();
 
        int c = a + b;
        int d = a - b;
        int e = a * b;
 
        if(c > d){
            if(c > e){
                System.out.print(c);
                System.exit(0);
            }
            System.out.print(e);
            System.exit(0);
        }
 		if(d > e){
        	System.out.print(d);
          	System.exit(0);
        }
      	System.out.print(e);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int D;
  cin>>D;
  VL C(26);
  rep(i,26) cin>>C[i];
  VVL S(D,VL(26));
  rep(i,D) rep(j,26) cin>>S[i][j];
  VL T(D);
  rep(i,D) cin>>T[i];
  int M;
  cin>>M;
  VL d(M),q(M);
  rep(i,M) cin>>d[i]>>q[i];
  ll ans=0;
  VL L(26);
  vector< set<ll> > X(26);
  rep(i,D){
    ll tmp=0;
    X[T[i]-1].insert(i+1);
    L[T[i]-1]=i+1;
    rep(j,26) tmp+=C[j]*(i+1-L[j]);
    ans+=S[i][T[i]-1]-tmp;
  }
  rep(i,26){
    X[i].insert(0);
    X[i].insert(D+1);
  }
  rep(i,M){
    int prv=T[d[i]-1];
    int nxt=q[i];
    auto itr=ub(all(X[prv-1]),d[i]);
    ll tmp=*itr;
    itr--;
    itr--;
    T[d[i]-1]=q[i];
    auto itr2=ub(all(X[nxt-1]),d[i]);
    ll tmp2=*itr2;
    itr2--;
    ans=ans-S[d[i]-1][prv-1]-C[prv-1]*(d[i]-*itr)*(tmp-d[i]);
    X[prv-1].erase(d[i]);
    ans=ans+S[d[i]-1][nxt-1]+C[nxt-1]*(d[i]-*itr2)*(tmp2-d[i]);
    X[nxt-1].insert(d[i]);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 4592
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> ans(n);
    rep(i,n){
        cin >> ans[i];
    }
    rep(i,n){
        if(ans[i]==0){
            cout <<"0"<< endl;
            return 0;
        }
    }
    ll res = ans[0];
    rep(i,n-1){
        if(ans[i+1]>(INF/res)){
            cout<<"-1"<<endl;
            return 0;
        }
        res *= ans[i+1];
    }
    cout <<res<< endl;
    return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++) 
#define FOR(i,ini,n) for(int i=(ini);i<(n);i++)

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> vi(9);
	REP(i,9){
		cin >> vi[i];
	}
	
	bool ans = true;
	if(vi[4] != vi[1] + vi[3] - vi[0]) ans = false;
	if(vi[5] != vi[2] + vi[3] - vi[0]) ans = false;
	if(vi[7] != vi[4] + vi[6] - vi[3]) ans = false;//a2+b2+a3+b1 = a3+b2-a2-b1
	if(vi[8] != vi[5] + vi[7] - vi[4]) ans = false;
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256