akhauriyash/Code-Regression huggingface dataset:
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m, q) = in.readLine.split(" ").map(_.toInt)

  val table = Array.ofDim[Int](n+1, n+1)
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach { case Array(l, r) =>
      table(l)(r) += 1
    }

  for {
    i <- 1 to n
    j <- 1 to n
  } {
    table(i)(j) += table(i-1)(j)
    table(i)(j) += table(i)(j-1)
    table(i)(j) -= table(i-1)(j-1)
  }

  val solver = (l:Int, r:Int) =>
    table(r)(r) - table(r)(l-1) - table(l-1)(r) + table(l-1)(l-1)

  val out = new java.io.PrintWriter(System.out)
  Iterator.continually(in.readLine)
    .take(q)
    .map(_.split(" ").map(_.toInt))
    .foreach { case Array(l, r) =>
      out.println(solver(l,r))
    }
  out.flush
}

Measured memory_bytes: 106780
#include<iostream>
using namespace std;
 
int main(){
      double N;
      int NUM[100];
      double res =0.0;
      cin >> N;
      
       for(int i = 0; i < N; ++i){
               NUM[i] = i+1;
       }
     
       double cnt = 0;
        for(int i = 0; i < N; ++i){
               if(NUM[i]%2!= 0) cnt++;
       }
       res = cnt/N;
       cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
using namespace std;
int a[2010];
int main()
{
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	int gap = m, gap1 = m;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	int dap = abs(a[n] - k);
	if(n>1)
	dap = max(dap, abs(a[n - 1] - a[n]));
	printf("%d", dap);
}


Measured memory_bytes: 128
# coding: utf-8

S = input()
# print(S)

N = len(S)
# print(N)

def judge(N, S):
    # print("S:", S)
    # rev2 = S[(N+3) // 2 - 1:]
    # rev2 = rev2[::-1]
    if N % 2 == 0:
        fr = S[:N // 2]
        rev2 = S[(N+2) // 2 - 1:]
        rev2 = rev2[::-1]
        # print("fr*:", fr)
        # print("rev2*:", rev2)
    else:
        fr = S[:(N-1) // 2]
        rev2 = S[(N+3) // 2 - 1:]
        rev2 = rev2[::-1]
        # print("fr`:", fr)
        # print("rev2`:", rev2)
        
    if fr == rev2:
        flg = True
    else:
        flg = False

    return flg

b_S = S[:(N-1) // 2]
a_S = S[(N+3) // 2 - 1:]
rev = a_S[::-1]
# print("b_S:", b_S)
# print("a_S:", a_S)
# print("rev:", rev, "\n")

if b_S == rev:
    if judge(len(b_S), b_S) == True and judge(len(a_S), a_S) == True:
        print("Yes")
    else:
        print("No")
    exit()
else:
    print("No")

Measured memory_bytes: 3064
package main

import "fmt"

func main(){
	var K, A, B int

	fmt.Scan(&K, &A, &B);
	f := 0;
	for i := 1 ; i < 1000 ; i++{
		if A <= i*K && i*K <= B {
			f = 1;
		}
	}

	if f == 1 {
		fmt.Println("OK");
	}else {
		fmt.Println("NG");
	}
	
}

Measured memory_bytes: 1752
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define rep2(i,n) for(int i=1;i<=(n);++i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int NMAX = 100000;
const int MMAX = 100000;
const int k = 200000;
static const int INF = 1<<21;
static const int NIL = -1;
static const int mod = 1e9+7;

double dp[3000][3000]={0};
ll gcd(ll a, ll b){
if(a<b) swap(a,b);
    if(b==0) return a;
    return gcd(b, a%b);
}

vector<vi> pre(NMAX+1);
vi dist(NMAX+1);
vector<bool> visited(NMAX+1);


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

    int n;
    string s;
    cin >> n;
    cin >> s;

    if(n>=3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,0,n){
        cin>>a[i];
    }
    b[0] = a[0]; c[n-1] = a[n-1];
    rep(i,1,n) b[i] = max(b[i-1],a[i]);
    repp(i,n-2,0) c[i] = max(c[i+1],a[i]);
    rep(i,0,n){
        if (i==0){
            cout<<c[1]<<endl;
            continue;
        }
        if (i==n-1){
            cout<<b[n-2]<<endl;
            continue;
        }
        cout<<max(b[i-1],c[i+1])<<endl;
    }
}

Measured memory_bytes: 7956
package main

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

type node struct {
        i0, i1 int
        indeg  int
        out    []*node
}

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Split(bufio.ScanWords)
        w := bufio.NewWriter(os.Stdout)

        scanner.Scan()
        N, _ := strconv.Atoi(scanner.Text())

        graph := make([][]node, N)
        for i0 := range graph {
                graph[i0] = make([]node, N)
                for i1 := range graph[i0] {
                        graph[i0][i1].i0 = i0
                        graph[i0][i1].i1 = i1
                }
        }
        for i := 0; i < N; i++ {
                scanner.Scan()
                Aij, _ := strconv.Atoi(scanner.Text())
                Aij -= 1
                i0, i1 := i, Aij
                if i0 > i1 {
                        i0, i1 = i1, i0
                }
                for j := 1; j < N-1; j++ {
                        scanner.Scan()
                        Aij, _ := strconv.Atoi(scanner.Text())
                        Aij -= 1
                        o0, o1 := i, Aij
                        if o0 > o1 {
                                o0, o1 = o1, o0
                        }
                        graph[i0][i1].out = append(graph[i0][i1].out, &graph[o0][o1])
                        graph[o0][o1].indeg += 1
                        i0, i1 = o0, o1
                }
        }

        order := make([]*node, 0, N*(N-1)/2)
        for i0 := 0; i0 < N; i0 += 1 {
                for i1 := i0 + 1; i1 < N; i1 += 1 {
                        if graph[i0][i1].indeg == 0 {
                                order = append(order, &graph[i0][i1])
                        }
                }
        }
        for i := 0; i < len(order); i++ {
                for _, out := range order[i].out {
                        (*out).indeg -= 1
                        if (*out).indeg == 0 {
                                order = append(order, out)
                        }
                }
        }
        if len(order) < N*(N-1)/2 {
                w.WriteString("-1")
                w.Flush()
                return
        }

        cnt := 1
        rest := make([]bool, N)
        for _, n := range order {
                if rest[(*n).i0] || rest[(*n).i1] {
                        rest = make([]bool, N)
                        cnt += 1
                }
                rest[(*n).i0] = true
                rest[(*n).i1] = true
        }
        w.WriteString(strconv.Itoa(cnt))
        w.Flush()
}


Measured memory_bytes: 128468
N = int(input())
P = list(map(str, input().split()))
Q = list(map(str, input().split()))

P = int(''.join(P))
Q = int(''.join(Q))

import itertools
L = [int(''.join(_)) for _ in itertools.permutations(['1','2','3','4','5','6','7','8'][:N])]
L.sort()
print(abs(L.index(P) - L.index(Q)))

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int INF=1e9;
static const int MEM_SIZE=1000000;
struct edge{int to,cost;};
struct dat{
      int s,cost,num;
      dat(int s,int cost,int num):s(s),cost(cost),num(num){}
      bool operator<(const dat& a)const{return cost<a.cost;}
};
vector<edge> G[100];
int dist[100][11];
int n,c;
void dijkstra(int s){
      REP(i,100)REP(j,11)dist[i][j]=INF;
      priority_queue<dat>Q;
      Q.push(dat(s,0,0));
      dist[s][0]=0;
      while(!Q.empty()){
            dat p=Q.top();Q.pop();
            REP(i,G[p.s].size()){
                  edge e=G[p.s][i];
                  if(p.num<c){
                        if(dist[p.s][p.num]+e.cost/2<dist[e.to][p.num+1]){
                              dist[e.to][p.num+1]=dist[p.s][p.num]+e.cost/2;
                              Q.push(dat(e.to,dist[e.to][p.num+1],p.num+1));
                        }
                  }
                  if(dist[p.s][p.num]+e.cost<dist[e.to][p.num]){
                        dist[e.to][p.num]=dist[p.s][p.num]+e.cost;
                        Q.push(dat(e.to,dist[e.to][p.num],p.num));
                  }
            }
      }
}
int main(){
      int m,s,d;
      while(cin>>c>>n>>m>>s>>d&&(c||n||m||s||d)){
            s--;d--;
            REP(i,100)G[i].clear();
            REP(i,m){
                  int a,b,f;
                  cin>>a>>b>>f;
                  a--;b--;
                  G[a].PB((edge){b,f});
                  G[b].PB((edge){a,f});
            }
            dijkstra(s);
            int ans=INF;
            REP(i,c+1)ans=min(ans,dist[d][i]);
            cout<<ans<<endl;
      }
}

Measured memory_bytes: 1248
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


n, m, k = map(int, input().split())

friend = [[] for _ in range(n)]
block = [[] for _ in range(n)]

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)

    uf.union(a-1, b-1)

for i in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

candidate = [0] * n

for i in range(n):
    candidate[i] = uf.get_size(i) - len(friend[i]) - 1
    for j in block[i]:
        if uf.is_same(i, j):
            candidate[i] -= 1

print(' '.join(list(map(str, candidate))))

Measured memory_bytes: 125220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10;

void solve() {
    ll a; cin >> a;
    double b; cin >> b;
    ll c = (b * 100) + 0.5;

    ll ans = a * c;
    ans /= 100;
    
    cout << ans << endl;
}

int main(void) {
    int t; t = 1;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 3720
n, m, k = map(int, input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
sub = 0
a_ls_cnt = 0
a_ls_len = len(a_ls)
now_time = 0
#aのみを選択した場合
#このwhile終了後はa_ls_cntは読んだaの本数になる
while now_time < k:
    now_time+=a_ls[a_ls_cnt]
    if now_time > k:
        now_time-=a_ls[a_ls_cnt]
        break
    a_ls_cnt+=1
    if a_ls_len == a_ls_cnt:
        break
#print(a_ls_cnt)
b_ls_cnt = 0
b_ls_len = len(b_ls)
#a全部をよんだ段階で，bで読めるだけ
while now_time < k:
    now_time+=b_ls[b_ls_cnt]
    if now_time > k:
        now_time-=b_ls[b_ls_cnt]
        break
    b_ls_cnt+=1
    if b_ls_len == b_ls_cnt:
        break

sub = a_ls_cnt+b_ls_cnt
break_flg = 0
#print(sub)
#少しずつaで読んだ本数削る
while a_ls_cnt >= 1:
    if break_flg == 1:
        break
    now_time-=a_ls[a_ls_cnt-1]
    a_ls_cnt-=1
    while now_time < k:
        #print("b_ls",b_ls_cnt, b_ls_len)
        if b_ls_cnt == b_ls_len:
            break_flg = 1
            sub = max(sub, a_ls_cnt+b_ls_cnt)
            break
        now_time+=b_ls[b_ls_cnt]
        if now_time > k:
            now_time-=b_ls[b_ls_cnt]
            break
        b_ls_cnt+=1
    sub = max(sub, a_ls_cnt+b_ls_cnt)
    #print(a_ls_cnt, b_ls_cnt, sub)
print(sub)


Measured memory_bytes: 39780
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int g = a[0];
    int MAX = *max_element(all(a));
    rep(i, 1, n) g = __gcd(g, a[i]);
    cout << ((k % g || k > MAX) ? "IMPOSSIBLE" : "POSSIBLE") << endl;
}

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

long lucas(long n) {
    if(n == 0)
        return 2;
    if(n == 1)
        return 1;

    return lucas(n - 1) + lucas(n - 2);
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    long n;
    cin >> n;
    long lucas[100];
    lucas[0]=2;
    lucas[1] =1;
    for(int i = 2; i <= n; i++) {
        lucas[i] = lucas[i - 1] + lucas[i - 2];
    }
    cout << lucas[n] << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
using namespace std;


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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int X=gi();
	    int Y=gi();

	    //System.out.print((int)Math.pow(4, n));
	    int s=0;
	    if (X<=3) {
	    	s+=100000*(4-X);
	    }
	    if (Y<=3) {
	    	s+=100000*(4-Y);
	    }
	    if (X==1 && Y==1) {
	    	s+=400000;
	    }
System.out.print(s);


	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;
typedef pair<int, int> P;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int H, W;
    cin >> H >> W;
    string S[400];
    for(int i = 0; i < H; i++) cin >> S[i];

    bitset<400> visited[400];

    ll ans = 0;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(visited[i][j]) continue;
            visited[i][j] = true;
            vector<ll> num(2, 0);
            queue<pair<int, int>> que;
            que.push({i, j});

            while(que.size()){
                auto p = que.front();
                que.pop();
                int x = p.first;
                int y = p.second;
                num[S[x][y] == '#']++;

                for(int k = 0; k < 4; k++){
                    int x2 = x + dx[k];
                    int y2 = y + dy[k];
                    if(0 <= x2 && x2 < H && 0 <= y2 && y2 < W && !visited[x2][y2] && S[x][y] != S[x2][y2]){
                        que.push({x2, y2});
                        visited[x2][y2] = true;
                    }
                }
            }
            ans += num[0] * num[1];
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
        long long n, m;
        cin >> n >> m;
        if (m-n*2>=0) {
                long long rem = m-n*2;
                rem /= 4;
                cout << n+rem << endl;
        } else {
                cout << m/2 << endl;
        }
        return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<sstream>
using namespace std;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int INF=(1<<24);
int c2i(char ch){return ch-'a';}
int str2i(string str){
  stringstream ss;
  int res;
  ss<<str;
  ss>>res;
  return res-1; 
}
 
int M,N,D,ns,nc,nj,Sy,Sx,Gy,Gx,lcm;
int t[20][20][4];
int k[20][20];
 
bool u[20][20][101][4];
bool vd[20][20][101][4];
 
void input();
void init();
void solve();
void dijkstra();
 
int main(){
  while(1){
    cin>>N>>M;
    if(M==0&&N==0)break;
    cin>>D;
    init();
    input();
    solve();
  }
  return 0;
}
 
void dijkstra(){
  int Y,X,Z,dir,ny,nx,nz;
  u[Sy][Sx][0][1]=true;
 
  while(1){
    Y=X=-1;
    for(int a=0;a<101;a++)
      for(int b=0;b<N;b++)
    for(int c=0;c<M;c++)
      for(int d=0;d<4;d++)
        if(u[b][c][a][d]&&!vd[b][c][a%lcm][d]&&Y==-1&&X==-1){Y=b;X=c;Z=a;dir=d;}
    if(Y==-1&&X==-1)break;
    vd[Y][X][Z%lcm][dir]=true;
    if(Y==Gy&&X==Gx)break;
    //cout<<Y<<' '<<X<<' '<<Z<<' '<<dir<<endl;
    if(k[Y][X]>0&&dir%2==1&&(Z/k[Y][X])%2==0)continue;
    if(k[Y][X]>0&&dir%2==0&&(Z/k[Y][X])%2==1)continue;
    for(int i=0;i<4;i++){ 
      ny=Y+dy[i];nx=X+dx[i];nz=Z+t[Y][X][i];
      if((dir+2)%4==i)continue;
      if(ny<0||ny>=N||nx<0||nx>=M||nz>100)continue;
      u[ny][nx][nz][i]=true;
      //if(ny==1&&nx==3)cout<<Y<<'-'<<X<<'-'<<Z<<'-'<<dir<<endl;
    }
     
     
  }//while
}
 
void solve(){
  dijkstra();
  for(int i=0;i<101;i++){
    for(int j=0;j<4;j++){
      if(!u[Gy][Gx][i][j])continue;
      cout<<i<<endl;
      return;
    }
  }
}
 
void input(){
  string str;
  int y,x,Y,X,d;
  lcm=1;
  cin>>ns;
  for(int i=0;i<ns;i++){
    cin>>str;
    y=c2i(str[0]);
    x=str2i(str.substr(2));
    cin>>k[y][x];
    lcm=lcm/__gcd(lcm,k[y][x])*k[y][x];
  }
  cin>>nc;
 
  for(int i=0;i<nc;i++){
    cin>>str;
    y=c2i(str[0]);
    x=str2i(str.substr(2));
    cin>>str;
    Y=c2i(str[0]);
    X=str2i(str.substr(2));
    for(int j=0;j<4;j++){
      if(y+dy[j]==Y&&x+dx[j]==X){
    t[y][x][j]=INF;
    t[Y][X][(j+2)%4]=INF;
    break;
      }
    }
  }
 
  cin>>nj;
  for(int i=0;i<nj;i++){
    cin>>str;
    y=c2i(str[0]);
    x=str2i(str.substr(2));
    cin>>str;
    Y=c2i(str[0]);
    X=str2i(str.substr(2));
    cin>>d;
    for(int j=0;j<4;j++){
      if(y+dy[j]==Y&&x+dx[j]==X){
    t[y][x][j]+=d;
    t[Y][X][(j+2)%4]+=d;
    break;
      }
    }
  }
   
  cin>>str;
  Sy=c2i(str[0]);
  Sx=str2i(str.substr(2));
  cin>>str;
  Gy=c2i(str[0]);
  Gx=str2i(str.substr(2));
 
}
 
void init(){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      for(int K=0;K<4;K++){
	t[i][j][K]=D;
      }
      k[i][j]=0;
      for(int K=0;K<101;K++){
	for(int l=0;l<4;l++){
	  u[i][j][K][l]=false;
	  vd[i][j][K][l]=false;
	}
      }
    }
  }
}

Measured memory_bytes: 1556
using System;
using System.Linq;

static class Program
{
  static void Main()
  {
    var input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    var array = new int[] {
      Math.Abs(b-a) + Math.Abs(c-a),
      Math.Abs(a-b) + Math.Abs(c-b),
      Math.Abs(a-c) + Math.Abs(b-c)
    };
    Console.WriteLine(array.Min());
  }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) {
				break;
			}
			if(a>b) {
				System.out.printf("%s %s\n", b, a);
			}else {
				System.out.printf("%s %s\n", a, b);
			}
		
		}
		
	}
}



Measured memory_bytes: 40340
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<i64> a(n), s(n + 1);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	
	i64 mi = (1LL << 60);
	for(int i = 0; i <= n; i++) {
		i64 width_A = s[i], width_B = s[n] - s[i];
		int A = lower_bound(begin(s), begin(s) + i, width_A / 2) - begin(s);
		int B = lower_bound(begin(s) + i, end(s), s[i] + width_B / 2) - begin(s);
		
		for(int x = -1; x < 1; x++) {
			for(int y = -1; y < 1; y++) {
				if(A + x < 0 || B + y < 0) continue;
				i64 P = s[A + x];
				i64 Q = s[i] - s[A + x];
				i64 R = s[B + y] - s[i];
				i64 S = s[n] - s[B + y];
				
				mi = std::min(mi, std::max({P, Q, R, S}) - std::min({P, Q, R, S}));
			}
		}
	}
	
	cout << mi << endl;
	return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

int main() {
    ll n, a, b, c, d, e, res = 0;
    scanf("%lld%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d, &e);
    res = min({a, b, c, d, e});
    res = n / res + 4 + (n % res ? 1 : 0);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n,k;
	scanf("%d%d",&n,&k);
	puts(n*500>=k?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	string s; cin >> s;
	rep(i, 0, s.size()) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N, M; cin >> N >> M;

	
	N--, M--;
	LL ans = N*M;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

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

LL gcd(LL x, LL y) {
  LL r;

  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

LL primeFactorization(LL val) {
  LL cnt = 0;
  for (LL i = 2; i*i < val; i++) {
    if (val % i == 0) cnt ++;
    while(val % i == 0) val /= i;
  }

  if (val != 1) cnt ++;

  return cnt;
}

int main(void){
  LL a, b;
  cin >> a >> b;
  LL c = gcd(a, b);


  LL cnt = primeFactorization(c);

  cout << cnt + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    vector<int> dp(H+1, 1<<30);
    dp[0] = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<H; j++){
            dp[min(H, j+A[i])] = min(dp[min(H, j+A[i])], dp[j] + B[i]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = sorted([int(input()) for _ in range(N)])
sm = 0
for c in s:
    if c%10!=0:
        sm = c
        break
if sum(s)%10!=0:print(sum(s))
else:
    p = sum(s)-sm
    if p%10!=0:print(p)
    else:print(0)

Measured memory_bytes: 3064
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

struct RoadWork {
    int s, t, x;
} rws[200005];

int d[200005];

struct Block {
    int s, t, x;
} blocks[200005];

struct Comp{
    bool operator()(const Block& a, const Block& b){
        return a.x > b.x;
    }
};

int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++) {
        int s, t, x;
        scanf("%d%d%d", &s, &t, &x);
        blocks[i].s = s - x;
        blocks[i].t = t - x;
        blocks[i].x = x;
    }
    sort(blocks, blocks + n, [](Block a, Block b){return a.s < b.s;});
    for (int i = 0; i < q; i++) {
        scanf("%d", &d[i]);
    }

    priority_queue<Block, vector<Block>, Comp> pq;
    int cur = 0;
    for (int i = 0; i < q; i++) {
        while (cur < n && d[i] >= blocks[cur].s) {
            pq.push(blocks[cur++]);
        }
        while (!pq.empty()) {
            Block b = pq.top();
            if (b.t <= d[i]) {
                pq.pop();
            } else {
                break;
            }
        }
        if (pq.empty()) {
            printf("-1\n");
        } else {
            printf("%d\n", pq.top().x);
        }
    }
}


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

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> b(M);
  int ans = 0;
  for(int i = 0; i < M; i++){
    cin >> b[i];
  }
  for(int i = 0; i < N; i++){
    vector<int> a(M);
    int sum = 0;
    for(int i = 0; i < M; i++){
      cin >> a[i];
      sum += a[i] * b[i];
    }
    if(sum + C > 0){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&b==c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
	
	int b, i = 0;
	//char buf[1200];
	string a;
	getline(cin, a);
	/*
	while(i < 1200){
		b = buf[i];
		if(b == '\n')break;
		else if(b >= 96 && b <= 122){
			b -= 32;
		}
		
		else if(b >= 64 && b <= 90){
			b += 32;
		}
		cout << char(b);
		i++;
	}
	*/
	
	for(int i=0;i<a.size();i++)
	{
		b = a[i];
		if(b == '\n')break;
		else if(b >= 96 && b <= 122){
			b -= 32;
		}
		
		else if(b >= 64 && b <= 90){
			b += 32;
		}
		cout<<(char)b;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	long long n, k;
	cin >> n >> k;
	long long ans = 1;
	REP(i, n) {
		ans *= k;
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
  int N, ans = 1;
  cin >> N;
  vector<int> A;
  for (int i = 0, t; i < N; i++) {
    cin >> t;
    if (A.empty() || t != A.back()) A.push_back(t);
  }
  for (int i = 1; i < A.size() - 1; i++) {
    if (A[i] > max(A[i - 1], A[i + 1]) || A[i] < min(A[i - 1], A[i + 1])) {
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

const int MOD = 1e9+7;

void solve()
{
	int N, K, a;
	cin >> N >> K;
	vector<long> dp(K+1);
	dp[0] = 1;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		vector<long> nx = dp;
		for (int j = 1; j <= K; j++)
		{
			if (j > a)
			{
				(nx[j] += nx[j-1] - dp[j-a-1] + MOD) %= MOD;
			}
			else
			{
				(nx[j] += nx[j-1]) %= MOD;
			}
		}
		dp = nx;
	}

	cout << dp[K] << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1792
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  ll k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0)
  {
    cout << -1 << "\n";
    return;
  }
  ll p = 7 % k;
  rep(i, 1000010)
  {
    if (p == 0)
    {
      cout << i + 1 << "\n";
      return;
    }
    p = (p * 10 + 7) % k;
  }
  assert(false);
}

int main()
{
  init_main();
  solve();
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    double D1 = 0, D2 = 0, D3= 0, Di= 0, a[100], x[100], y[100];
    for(int i = 0 ; i < n ; i++) cin >> x[i];
    for(int i = 0 ; i < n ; i++) cin >> y[i];
    for(int i = 0 ; i < n ; i++) a[i] = fabs(x[i] - y[i]);
    for(int i = 0 ; i < n ; i++) D1 += a[i];
    for(int i = 0 ; i < n ; i++) D2 += a[i] * a[i];
    D2 = sqrt(D2);
    for(int i = 0 ; i < n ; i++) D3 += a[i] * a[i] * a[i];
    D3 = cbrt(D3);
    for(int i = 0 ; i < n ; i++){
        if(Di > a[i]) Di = Di;
        else Di = a[i];
    }
    cout << fixed << setprecision(10) << D1 << endl << D2 << endl << D3 << endl << Di << endl;
    return 0;
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll N,K; cin>>N>>K;
	ll r=N%K;
	cout<<min(r,K-r)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int data[2];
	int size;
	int *a, *b, *c;
	int i, j;
	
	scanf("%d %d", &data[0], &data[1]);
	size = data[0] * data[1];
	
	a = malloc(sizeof(int) * size);
	b = malloc(sizeof(int) * data[1]);
	c = malloc(sizeof(int) * data[0]);
	
	for(i=0 ; i < size ; i++){
		scanf("%d", &a[i]);
	}
	for(i=0 ; i < data[1] ; i++){
		scanf("%d", &b[i]);
	}
	
	for(i=0 ; i < data[0] ; i++){
		for(j=0 ;  j < data[1] ; j++){
			c[i] += a[i * data[1] + j ] * b[j]; 
		}
	}
	
	for(i=0 ; i < data[0] ; i++){
		printf("%d\n", c[i]);
	}	

	return 0;
}

Measured memory_bytes: 640
function main(input) {
	var a = input.split('\n');
	var N = parseInt(a[0], 10);
	var S = a[1];
	var countmax = 0;
	for(i=1;i<N;i++){
		var S1 = S.slice(0,i);
		var S2 = S.slice(i,N);
		//console.log(S1);
		//console.log(S2);
		var count = 0;
		for(j=0;j<S1.length;j++){
			var t = 0;
			for(k=j+1;k<S1.length;k++){
				if(S1[j] === S1[k]){
					t = -1;
					break;
				}
			}
			if(t >= 0){
				for(k=0;k<S2.length;k++){
					if(S1[j] === S2[k]){
						t = 1;
						break;
					}
				}
				if(t === 1){
					count += 1;
				}
			}
			//console.log(count);
		}
		countmax = Math.max(countmax,count);
	}
	console.log(countmax);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define endl '\n'

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

    int n,k; cin >> n >> k;
    int a[n];
    for (int i=0; i<n; i++) cin >>a[i];
    sort(a, a+n, greater<int>());

    long long resp  =0;
    for (int i=k; i<n; i++){
        resp += (a[i]);
    } 
    cout << resp << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string x;
    cin >> x;
    stack<char> st;
    string ans;
    rep(i, x.length()) {
        if ( x[i] == 'S' ) {
            st.push(x[i]);
        }
        else if ( x[i] == 'T' ) {
            if ( ( st.empty() || st.top() == 'T' ) && x[i] =='T' ) {
                st.push(x[i]);
            }
            else if ( !st.empty() && st.top() == 'S' && x[i] == 'T') {
                st.pop();
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}


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

using namespace std;

const int N = 55, inf = 1e9;
int nTest, n, ans;
bool vis[N], canUse[N];
vector< set<int> > gr[3];
set<int> inQ;

void dfs (int u) {
    vis[u] = 1;
    for (auto v : gr[2][u]) {
        if (vis[v]) continue ;
        if (gr[0][u].count(v) ) dfs(v);
        else inQ.insert(v);
    }
}

int solve (int root) {
    memset(vis, 0, sizeof vis);
    memset(canUse, 0, sizeof canUse);
    inQ.clear();
    int ret = 0;
    gr[0] = gr[1];
    for (int i = 1; i <= n; ++i) if (gr[0][i].size() == 1) canUse[i] = 1;
    dfs(root);
    while (1) {
        bool have = 0;
        for (auto i : inQ) if (canUse[i]) {
            gr[0][ *gr[0][i].begin() ].erase(i);
            gr[0][i].clear();
            have = 1, dfs(i), inQ.erase(i), ret ++;
            for (int j = 1; j <= n; ++j) if (gr[0][j].size() == 1) canUse[j] = 1;
            break;
        }
        if (!inQ.size() ) break;
        if (!have) return inf;
    }
    return ret;
}

void EntityIT() {
    cin >> n;
    ans = inf;
    for (int i = 1; i < 3; ++i) gr[i].assign(n + 5, set<int>() );
    for (int type = 1; type < 3; ++type) {
        for (int _ = 1; _ < n; ++_) {
            int u, v; cin >> u >> v;
            gr[type][u].insert(v); gr[type][v].insert(u);
        }
    }

    for (int root = 1; root <= n; ++root) ans = min(ans, solve(root) );
    for (int root = 1; root <= n; ++root) {
        if (gr[1][root].size() > 1) continue ;
        for (int i = 1; i <= n; ++i) {
            if (gr[1][root].count(i) || i == root) continue ;
            int tmp = (*gr[1][root].begin() );
            gr[1][i].insert(root);
            gr[1][root].clear(); gr[1][root].insert(i);
            gr[1][tmp].erase(root);
            ans = min(ans, solve(root) + 1);
            gr[1][i].erase(root);
            gr[1][root].clear(); gr[1][root].insert(tmp);
            gr[1][tmp].insert(root);
        }
    }

    if (ans >= inf) cout << "-1\n";
    else cout << ans << '\n';
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin >> nTest;
    while (nTest --) EntityIT();
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 42
#define off 2
#define FastIO  ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 100005

int main()
{
    i64 s ;

    scanf("%lld",&s) ;

    i64 sq = sqrt(s) ;
    sq = max( 0LL , sq-1 ) ;

    while( sq*sq < s ) sq++ ;

    if( sq*sq==s )
    {
        printf("0 0\n0 %lld\n%lld 0\n",sq,sq) ;
        return 0 ;
    }

    i64 mx = 1000000000LL ;

    if( s >= (sq-1)*(sq) )
    {
        printf("%lld 1\n",sq) ;
        printf("%lld %lld\n", sq*sq-s , sq ) ;
        printf("0 0\n") ;
    }
    else{
        printf("%lld 1\n",sq-1);
        printf("%lld %lld\n",(sq-1)*sq - s , sq  ) ;
        printf("0 0\n") ;
    }

    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005;

ll n, ind[N], mis[N], ans, mx;
pll dt[N][2];

char col[N];
bool out[N], bl[N];

vector<ll> adj[N];
queue<ll> q;

void upd (ll C, ll V, ll T) {
	if(dt[C][0].X < V) {
		if(dt[C][0].Y != T) dt[C][1] = dt[C][0];
		dt[C][0] = {V, T};
	}
	else if(dt[C][0].Y != T && dt[C][1].X < V) {
		dt[C][1] = {V, T};
	}
}

ll get (ll C, ll T) {
	return dt[T][dt[T][0].Y == C].X;
}

void solve (ll C, ll P) {
	if(mis[C] == -1) return;
	if(!mis[C]) {
		for(auto &T : adj[C]) {
			if(T == P || out[T]) continue;
			solve(T, C);
			upd(C, get(C, T)+2-2*bl[C], T);
		}
		mis[C] = P;
	}
	else if(mis[C] != P) {
		solve(mis[C], C);
		upd(C, get(C, mis[C])+2-2*bl[C], mis[C]);
		mis[C] = -1;
	}
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<n;i++) {
		ll A, B;
		scanf("%lld%lld",&A,&B);
		adj[A].push_back(B); ind[B]++;
		adj[B].push_back(A); ind[A]++;
	}
	scanf("%s",col+1);
	for(ll i=1;i<=n;i++) {
		bl[i] = (col[i] == 'B');
		if(ind[i] == 1 && bl[i]) {
			out[i] = true; q.push(i);
		}
	}
	while(!q.empty()) {
		ll C = q.front(); q.pop();
		for(auto &T : adj[C]) {
			if(--ind[T] <= 1 && bl[T] && !out[T]) {
				out[T] = true; q.push(T);
			}
		}
	}
	for(ll i=1;i<=n;i++) {
		if(out[i]) continue;
		bl[i] ^= ind[i]%2;
		ans += ind[i] + !bl[i];
	}
	if(ans == 0) {puts("0"); return 0;}
	for(ll i=1;i<=n;i++) {
		if(out[i]) continue;
		solve(i, -1);
		mx = max(mx, dt[i][0].X);
	}
	printf("%lld\n", ans-mx);

    return 0;
}


Measured memory_bytes: 14848
import math

N,M=map(int,input().split())

d=[]
i=1
while math.sqrt(M)>=i:
    if M%i==0:
        d.append(i)
        if i**2!=M:
            d.append(M//i)
    i=i+1
d.sort()#Mの約数列

m=0
i=0
while  len(d)-1>=i and M//N>=d[i]:
    if  M%d[i]==0:
        m=d[i]
    i=i+1
print(m)

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    int ans = 0;
    bool allzero = false;
    int i = 0;
    while (true) {
        if (accumulate(h.begin(), h.end(),0) <= 0) break;
        while (h[i] <= 0 && i < N) i++;
        while (h[i] > 0 && i < N) {
            h[i]--;
            i++;
        }
        ans++;
        i = 0;
    }

    cout << ans << endl;
}


            



Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    if N % 2 == 0:
        if S[:N//2] == S[N//2:]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.*;
public class Main {
    public static void main(String[] args) {
        for(int i = 1; i < 10; i++) {
            for(int j = 1; j < 10; j++) {
                System.out.println(i+"x"+j+"="+i*j);
            }
        }    
     
    }
 } 


Measured memory_bytes: 24188
#include <iostream>
#include <cstdlib>

void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int main()
{
    int x[3];
    for (int i=0; i<3; i++)
    {
        std::cin >> x[i];
    }
    for (int j=2; j>=0; j--)
        for (int i=0; i<j; i++)
            if (x[i] > x[i + 1])
                swap(&x[i], &x[i + 1]);
    for (int i=0; i<3; i++)
    {
        std::cout << x[i];
        if (i == 2)
            std::cout << std::endl;
        else
            std::cout << " ";
    }
    return 0;
}



Measured memory_bytes: 3112
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var n, d, ans int
	fmt.Scan(&n, &d)
	for i := 0; i < n; i++ {
		x, y := nextInt(), nextInt()
		if d*d >= x*x+y*y {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 4952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A[3][3];
  rep(i, 3) rep(j, 3) cin >> A[i][j];
  int N;
  cin >> N;
  bool bl[3][3];
  rep(i, 3) rep(j, 3) bl[i][j] = false;
  rep(i, N) {
    int B;
    cin >> B;
    rep(j, 3) {
      auto index = find(A[j], A[j]+3, B) - A[j];
      if (index<3) bl[j][index] = true;
    }
  }
  bool flag = false;
  rep(i, 3) {
    if (bl[i][0] == true && bl[i][1] && bl[i][2]) flag = true;
    if (bl[0][i] == true && bl[1][i] == true && bl[2][i] == true) flag = true;
  }
  if (bl[0][0] == true && bl[1][1] == true && bl[2][2] == true) flag = true;
  if (bl[0][2] == true && bl[1][1] == true && bl[2][0] == true) flag = true;
  if (flag) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char c[w];
  for(int i=0;i<h;i++){
    cin >> c;
    for(int j=0;j<2;j++){
      cout << c << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;



    return 0;
}

Measured memory_bytes: 256