akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    x = int(input().strip())
    result = x // 500 * 1000
    x %= 500
    result += x // 5 * 5
    print(result)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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


int main(){
    int n;
    int mi=inf;
    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    rep(i,n) {
        int w;
        cin >> w;
        if(i==0) b[i]=w;
        else b[i]=b[i-1]+w;
    }
    rep(i,n){
        mi=min(mi,abs(b[n-1]-b[i]-b[i]));
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
x=["ooo","xxx"]
for s in sys.stdin:
    c="d"
    for i in range(3):
        if s[i:9:3]in x:
            c=s[i]
            break
        j=i*3
        if s[j:j+3]in x:
            c=s[j]
            break
    else:
        if s[0::4] in x or s[2:7:2] in x:c=s[4]
    print c

Measured memory_bytes: 4220
k,u,v=`dd`.scan(/-?\d+/).map &:to_i;x,y,*s=u.abs,v.abs;d=x+y;x,y=y,x if f=x>y;k%2-d%2<0&&(p -1;exit);n=(d-1)/k+1;n+=d<k ?1:(d-n*k)%2;a=n<2 ?x:(d-n*k)/2;b=k-a.abs;d%2-d/k>0&&(s=[[0,-k]];a=b=(d-k)/2);n.times{s<<[a,b];t=[x-a,k].min;a+=t;b+=k-t};p s.size;s.each{|a,b|f&&(a,b=b,a);puts [a*(u<=>0.1),b*(v<=>0.1)]*?\s}

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

signed main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if( A != C ){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
  
    
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
 
max_diff = max([a, b, c, d, e]) - min([a, b, c, d, e])
ans = "Yay!"
if(max_diff > k):
    ans = ":("
print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**6)

def DFS(v, p ,c):
    res[v] = c
    for next in tree[v]:
        if next[0] == p:
            continue
        if next[1] % 2:
            DFS(next[0], v, 1-c)
        else:
            DFS(next[0], v, c)


n = int(input())
tree = [[] for i in range(n)]
res = [0] * n
for i in range(n-1):

    u, v, w = map(int, input().split())
    tree[u-1].append([v-1, w])
    tree[v-1].append([u-1, w])

DFS(0, -1, 1)

for i in range(n):
    print(res[i])


Measured memory_bytes: 85204
n = int(input())

dg = 10**10
xl = []

for i in range(n):
    x,l = map(int,input().split())
    xl.append((x+l)*dg+l)
xl.sort()


start = -10**20
res = 0

for e in xl:
    end,s = e//dg,e//dg-2*(e%dg)

    if s >= start:
        res += 1
        start = end

print(res)

Measured memory_bytes: 59480
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <list>
using namespace std;

void solve(int m,int nmin,int nmax){
	vector<int> score(m);
	for(int i=0;i<m;i++){
		cin>>score[i];
	}
	
	int maxdiff=0;
	int result;
	for(int i=nmin;i<=nmax;i++){
		int diff=score[i-1]-score[i];
		if(diff>maxdiff){
			maxdiff=diff;
			result=i;
		}else if(diff==maxdiff){
			result=i;
		}
	}
	cout<<result<<endl;
}
int main(void){
	while(1){
		
		int m,nmin,nmax;
		cin>>m>>nmin>>nmax;
		if(m==0) break;
		solve(m,nmin,nmax);
		
		}
	return 0;
}	



Measured memory_bytes: 3060
#include<iostream>
#include<cassert>
#include<time.h>
#include<cmath>
using namespace std;

/**
作用：判断一个数是否是素数
参数x：待判断的素
参会primes：存储比x小的所有素数 的数组
返回：是素数返回true，否则返回false
*/
bool isPrime(int x,int *primes)
{
    for(int i=0;primes[i]*primes[i]<=x;++i) //用primes中存储的素数做为试除因子。
    {
        if(x%primes[i]==0) return false;
    }
    return true;
}


/**
作用：统计[2,n]之间的素数的个数
参数：n
返回：素数的个数
*/
int countPrimes(int n) {
    
    if(n<2) return 0;
    
    int count=0;
    int* primes = new int[(n-1)/2+1] ;
    
    if(n >=2) primes[count++] = 2;   //2是第一个素数，直接将他放入数组。

    for(int i=3;i<=n;++i)
    {
        if(isPrime(i,primes))   //如果 i为素数
        {
            primes[count++] = i; //则将 i存储到数组中
        }
    }

    delete[] primes;
    return count;

}

int main()
{
    int n;
    while (cin >> n) {
        int total = countPrimes(n);
        cout << total <<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3308
import java.util.*;

class Node{
	int parent;
	int depth;
	public ArrayList<Integer> children;
	
	Node(){
		children = new ArrayList<Integer>();
		parent = -1;
	}
	
	public int getParent() {
		return parent;
	}
	
	public void setParent(int parent) {
		this.parent = parent;
	}
	
	public int getDepth() {
		return depth;
	}
	
	public void setDepth(int depth) {
		this.depth = depth;
	}
}

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder output = new StringBuilder();
	
	//節点の個数
	int n;
	
	//木構造を示す配列。クラスNodeは自分で定義した。
	Node nodes[];
	
	//題意より以下は入力のための変数
	/*
	 * id 親
	 * k 親の配下の子ノードの数
	 * child 各子ノードの値
	 */
	int id,k,child;
	
	public void input() {
		n = sc.nextInt();
		nodes = new Node[n];
		//インスタンス化
		for(int i=0; i<n; i++) nodes[i] = new Node(); 
	}
	
	public void solve() {
		for(int i=0; i<n; i++) {
			id = sc.nextInt();
			k = sc.nextInt();
			for(int j=0; j<k; j++) {
				child = sc.nextInt();
				nodes[id].children.add(child);
				nodes[child].setParent(id);
			}
		}
		
		for(int i=0; i<n; i++) {
			//ノードが根だった場合深さは0に設定する
			if(nodes[i].getParent() == -1) compute(i,0);
		}
	}
	
	public void compute(int id, int value) {
		nodes[id].setDepth(value);
		//根以降のノードは深さがプラス１した値になるので再帰で呼び出してセットする
		for(int i=0; i<nodes[id].children.size(); i++) compute(nodes[id].children.get(i), value+1);
	}
	
	public void output() {
		for(int i=0; i<n; i++) {
			output.append("node ").append(Integer.toString(i)).append(": parent = ").append(Integer.toString(nodes[i].getParent())).append(", depth = ").append(Integer.toString(nodes[i].getDepth())).append(", ");
			if(nodes[i].getParent() == -1) output.append("root, ");
			else if(nodes[i].children.size() == 0) output.append("leaf, ");
			else output.append("internal node, ");
			
			output.append("[");
			if(nodes[i].children.size() > 0) {
				output.append(Integer.toString(nodes[i].children.get(0)));
				for(int j=1; j<nodes[i].children.size(); j++) output.append(", ").append(Integer.toString(nodes[i].children.get(j)));
			}
			output.append("]\n");
		}
		System.out.print( output.toString() );
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.solve();
		obj.output();
	}
}


Measured memory_bytes: 133916
/*
 * “My code isn't a mess! It's organised chaos!”
 */

/*
 * short     2^15-1 ~ 3e4
 * int       2^31-1 ~ 2e9
 * long x86  2^31-1 ~ 2e9
 * long long 2^63-1 ~ 9e18
 */

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a,b) for (int a=0; a<b; ++a)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000007ll;
const int infty = numeric_limits<int>::max();
struct _{_(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}_;
void err() {cerr << endl;}
template<typename T, typename... Ts>
void err(T a, Ts... as) {cerr << a << ' '; err(as...);}

 /*
  * Всегда прогоняй макс-тест перед 
  * нажатием «Отослать». Всегда.
  */ 

ll g(ll a) {
    if (!a) return 1;
    ll c = 0;
    while (a > 0) {
        ++c;
        a /= 10;
    }
    return c;
}

ll f(ll a, ll b) {
    return max(g(a), g(b));
}

int main() {
    ll n;
    cin >> n;
    ll m = 100;
    for (ll a = 1; a * a <= n; ++a) {
        if ( (n/a) * a == n ) {
            m = min(m, f(a, n/a));
            // err(a, n/a, f(a, n/a));
        }
    }
    cout << m << endl;

    return 0;
}


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



int main(){
    int N;
    int a[101];
    cin >> N;
    for (int i = 0; i < N; i ++){
        cin >> a[i];
    }
    sort(a, a + N, greater<int>());
    int A = 0;
    int B = 0;
    for (int i = 0; i < N; i++){
        if(i % 2 == 0){
            A += a[i];
        }else{
            B += a[i];
        }
    }
    cout << A - B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string w;
    cin>>w;
    int i,h[26]={0},f=0;
    for (i=0;i<w.size();i++)
        h[w[i]-'a']++;
    for (i=0;i<26;i++)
    {
        if (h[i]&1)
        {
            f=1;
            break;
        }
    }
    if (f)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}

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

using namespace std;

int main() {
    int n, a;  cin >> n;
    multiset<long long> st;
    for (int i = 0; i < n; i++) {
        cin >> a;
        auto ite = st.upper_bound(-a);
        if (ite == st.end()) {
            st.insert(-a);
            continue;
        }

        st.erase(ite);
        st.insert(-a);
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 8300
#include<stdio.h>
int main(void)
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	a=-a+b;
	if(a<=0){
		printf("delicious\n");
	}
	else if(x>=a){
		printf("safe\n");
	}
	else{
		printf("dangerous\n");
	}
	return 0;
}

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

int main(){
	int A,B,K;
	cin>>A>>B>>K;
	
	int ans;
	int j=0;
	for(int i=min(A,B);i>0;i--){
		if(A%i==0&&B%i==0){
			j++;
			if(j==K){
				ans=i;
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

int main(){
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int sum=0;
  int i;

  for(i=0;cin>>ch;i++){
    if(ch=='\\') S1.push(i);
    else if(ch=='/' && S1.size()>0){
      int j=S1.top();
      S1.pop();
      sum+=i-j;
      int a=i-j;

      while(S2.size()>0 && S2.top().first>j){
	a+=S2.top().second;
	S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }

  vector<int> ans;
  while(S2.size()>0){
    ans.push_back(S2.top().second);
    S2.pop();
  }

  reverse(ans.begin(),ans.end());

  cout<<sum<<endl;
  cout<<ans.size();

  for(i=0;i<ans.size();i++){
    cout<<" ";
    cout<<ans[i];
  }

  cout<<endl;
  return 0;
}



Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_172
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int a = ReadInt();
            WriteLine(a + a * a + a * a * a);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  set<string> dict;
  int n;
  cin >> n;
  string com, key;
  for (int i = 0; i < n; i++) {
    cin >> com >> key;
    if (com[0] == 'i') {
      dict.insert(key);
    }
    else {
      if (dict.count(key)) {
        cout << "yes" << endl;
      }
      else {
        cout << "no" << endl;
      }
    }
  }
}


Measured memory_bytes: 32596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int a[1000];
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	int sum  = 0;
	for(int i = 0; i < k; ++i) {
		sum += a[i];
	}
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
  long long int h, w;
  while(1) {
    cin >> h >> w;

    if(h == 0 && w == 0) break;
    
    for(int j=0; j<h; j++) {
        for(int i=0; i<w; i++) {
            if((j+i) % 2 == 0) {
                cout << "#";
            } else {
                cout << ".";
            }
        }
        cout << endl;
    }
  
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <limits>
#define ll long long
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = 1;
    for(int i=0;i<a;i++){
        ans = min(ans+b,ans*2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  int n;
  cin>>n;
  int res,ans=0;
  for(res=1;ans<n;++res)ans+=res;
  out(res-1);
  

  return 0;
}



Measured memory_bytes: 256
result = ["AC","WA","TLE","RE"]
result_num = [0,0,0,0]


case = input("")
case = int(case)

list = []
A = 0

while A < case:
  inp = input("")
  if inp == result[0] or inp == result[1] or inp == result[2] or inp == result[3]:
    list.append(inp)
    A = A + 1

A = 0
while A < case:
  if list[A] == result[0]:
    result_num[0] = result_num[0] + 1
  elif list[A] == result[1]:
    result_num[1] = result_num[1] + 1
  elif list[A] == result[2]:
    result_num[2] = result_num[2] + 1
  elif list[A] == result[3]:
    result_num[3] = result_num[3] + 1
  A =A + 1

print("AC x" , result_num[0])
print("WA x" , result_num[1])
print("TLE x" , result_num[2])
print("RE x" , result_num[3])


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

int main(){
  int N;
  cin >> N;
  int D = N % 10;
  N /= 10;
  int C = N % 10;
  N /= 10;
  int B = N % 10;
  N /= 10;
  int A = N;
  
  char opa;
  char opb;
  char opc;
  for (int tmp=0; tmp < (1 << 3); tmp++){
    bitset<3> s(tmp);
    int result= A;
    if(s.test(0)){
      opa = '+';
      result += B;
    }
    else{
      opa = '-';
      result -= B;
    }
    
    if(s.test(1)){
      opb = '+';
      result += C;
    }
    else{
      opb = '-';
      result -= C;
    }
    
    if(s.test(2)){
      opc = '+';
      result += D;
    }
    else{
      opc = '-';
      result -= D;
    }
    
    if(result == 7){
      break;
    }
  }
  
  cout << A << opa << B << opb << C << opc << D << "=7" << endl; 
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a, a + N);
    int answer = a[N-1] -a[0];
    cout << answer << endl;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    k=INT()
    temp=7
    ans=-1
    for i in range(k):
        if i==0:
            temp=temp%k
        else:
            temp=(temp*10+7)%k

        if temp==0:
            ans=i+1
            break

    print(ans)
if __name__=='__main__':
    do()

Measured memory_bytes: 9200
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int n,k;
int a[300000]; 
double g[200001];
double b[200001];
double sum[200001];
double ans;

inline int qr()
{
	int x=0,w=1;char a=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return x*w;
}

int main()
{
	n=qr(),k=qr();
    for(int i=1;i<=n;i++)
        a[i]=qr();
    g[1]=1;
    for(int i=2;i<=20001;i++)
        g[i]=g[i-1]+i;
    for(int i=1;i<=20001;i++)
        g[i]/=i;
    for(int i=1;i<=n;i++)
        b[i]=g[a[i]];
    for(int i=1;i<=k;i++)
        sum[k]+=b[i];
    for(int i=k+1;i<=n;i++)
        sum[i]=sum[i-1]+b[i]-b[i-k];
    for(int i=k;i<=n;i++)
        if(sum[i]>ans)
            ans=sum[i];
    printf("%.12f\n",ans);
	return 0;
}

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

int x,y,z;

int main (){
    scanf("%d %d %d\n",&x,&y,&z);
    if(0<=x&&x<y&&y<z&&z<=100){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


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

int main(){
	for(int D=0; D<50; D++){
		int n;
		cin >> n;
		if(n == 0)break;

		else{
			for(int i=0; i<n; i++){
				int x1,y1,z1,w1,x2,y2,z2,w2;// nomal,i,j,k
				cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
				int k1[4] = {x1,y1,z1,w1};
				int k2[4] = {x2,y2,z2,w2};
				int kans[4];

				//teisuko
				kans[0] = x1*x2 - y1*y2 - z1*z2 - w1*w2;
				kans[1] = x1*y2 + y1*x2 + z1*w2 - w1*z2;
				kans[2] = x1*z2 - y1*w2 + z1*x2 + w1*y2;
				kans[3] = x1*w2 + y1*z2 - z1*y2 + w1*x2;

			cout << kans[0] << " " << kans[1] << " " << kans[2] << " " << kans[3] << endl;

			}
		}
	}
	return 0;

}



Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int n = sc.nextInt();
			int k = sc.nextInt();

			int ans = k;
			for (int i = 0; i < n - 1; i++) {
				ans *= (k - 1);
			}

			System.out.println(ans);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21844
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let mut io = IO::new(stdin(), stdout(), stderr());
    // ===================================== //
    let (n, k): (usize, u64) = (io.read(), io.read());
    let mut a = io.readn::<usize>(n as usize);
    let mut nextb = vec![0; n as usize];
    for i in 0..n {
        a[i] = a[i] - 1;
    }
    let mut iter = 0;
    let mut found = a[0];
    let mut now = 0;

    let mut k = k;
    while k > 0 {
        if (k & 1) == 1 {
            now = a[now];
            //     io.debug(now);
        }
        let mut nb = a.clone();
        let mut tmp = nb.clone();
        for i in 0..n {
            nb[i] = a[tmp[i]];
        }
        a = nb.clone();
        k >>= 1;
    }
    io.writeln(now + 1);

    // while iter <= 0 && now != 0 {
    //     now = a[now];
    //     iter += 1;
    // }

    // let k = k % iter;
    // for _ in 0..k {
    //     now = a[now];
    // }
    // io.writeln(now);
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
}


Measured memory_bytes: 8392
def codei
  return gets.split.map &:to_i
end
n, t = codei
c = []; j = []; ans = []
count = 0
n.times do |i|
  c[i], j[i] = codei
  if j[i] <= t
    count += 1
    ans.push(c[i])
  end
end
if count == 0
  puts "TLE"
end
puts ans.min


Measured memory_bytes: 1788
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int rows, cols, colors;
    cin >> rows >> cols >> colors;

    vector<int> count(colors);
    for (auto &c : count) {
        cin >> c;
    }

    vector<vector<int>> mat(rows, vector<int>(cols));
    auto index = 0;

    for (auto i = 0; i < rows; i += 1) {
        auto start = (i % 2 == 0 ? 0 : (cols - 1));
        auto mod = (i % 2 == 0 ? 1 : -1);

        for (auto j = start; 0 <= j && j < cols; j += mod) {
            mat[i][j] = index + 1;
            count[index] -= 1;
            if (count[index] <= 0) {
                index += 1;
            }
        }
    }

    for (const auto &row : mat) {
        for (const auto &elem : row) {
            cout << elem << " ";
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
N , K = map(int, input().split())
S     = input()

ls = []

for n in range(N):
	ls.append(S[n])

result = ""

for n in range(N):
	if n != K-1:
		result += ls[n]
	else:
		if S[K-1] == "A":
			result += "a"
		if S[K-1] == "B":
			result += "b"
		if S[K-1] == "C":
			result += "c"

print(result)


Measured memory_bytes: 3060
object Main extends App {
  var count = List(readInt,readInt,readInt,readInt,readInt)
  var k = readInt
  var flag = 0
  for(i <- 0 to count.size - 1) {
    for(j <- 1 to count.size - 1) {
      if(count(j) - count(i) > k)
      flag=1
    }
  }
  println(if(flag!=1){"Yay!"}else{":("})
}

Measured memory_bytes: 25288
import sys
def input(): return sys.stdin.readline().rstrip()

S = list(input())
n = len(S)

dp = [0] * 2019
dp[0] = 1
tmp = 0
ten = 1
for i in range(n):
    tmp += int(S[n-1-i]) * ten
    tmp %= 2019
    ten *= 10
    ten %= 2019
    dp[tmp%2019] += 1
# print(dp)

ans = 0
for i in dp:
    if i >= 2:
        ans += i*(i-1)//2
        # print(i, dp[i])
print(ans)

Measured memory_bytes: 10500
#coding:utf-8
N=input()
S=raw_input()

st=[]
for s in S:
    if len(st) >= 1:
        a=st.pop()
        if a == '(' and s == ')':
            continue
        st.append(a)
    st.append(s)
migi=0
hidari=0
for s in st:
    if s == ")":migi+=1
    else: hidari+=1
print "("*migi + S + ")"*hidari


Measured memory_bytes: 2696
//In The Name Of God
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 1e5 + 5, Mod = 1e9 + 7, P = 727, Lg = 22, TOF = 1900, Inf = 3e18 + 10;


int W[N], V[N], Dp[105][N];
int32_t main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n, w, Ans = 0; cin >> n >> w;
      for(int i = 1; i <= n; i++)
            cin >> W[i] >> V[i];
      for(int i = 0; i < 105; i++)
            for(int j = 0; j < N; j++)
                  Dp[i][j] = Inf;
      Dp[0][0] = 0;
      for(int i = 1; i <= n; i++){
            for(int j = 0; j <= 1000 * i; j++){
                  if(j < V[i])
                        Dp[i][j] = Dp[i - 1][j];
                  else
                        Dp[i][j] = min(Dp[i - 1][j], Dp[i - 1][j - V[i]] + W[i]);
                  if(Dp[i][j] <= w)
                        Ans = max(Ans, j);
            }
      }
      cout << Ans;
      return 0;
}



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

int main(){
    int A,B,ans;
    cin>>A>>B;
    if(A>=13){
        ans=B;
    }
    else if(6<=A&&A<=12){
        ans=B/2;
    }
    else{
        ans=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>

#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;

int main() {
    int n,min=0,max=0,f[9]={0},i;
    cin>>n;
    int a[n];
    rep(i,n){
    	
    	cin>>a[i];
    	
    	if(a[i]<=399){
    		f[0]=1;
    	}
    	else if( a[i]<=799){
    		f[1]=1;
    	}
    	else if(a[i]<=1199){
    	    f[2]=1;
    	}
    	else if(a[i]<=1599){
    	    f[3]=1;
    	}
    	else if(a[i]<=1999){
    	    f[4]=1;
    	}
    	else if(a[i]<=2399){
    	    f[5]=1;
    	}
    	else if(a[i]<=2799){
    	    f[6]=1;
    	}
    	else if(a[i]<=3199){
    	    f[7]=1;
    	}
    	else{
    		f[8]++;
    	}
    }
    rep(i,9){
    		if(i!=8){
    		  min+=f[i];
    		  max+=f[i];
    		}
    		else{
    			max=min+f[8];
    			if(min==0 && f[8]>0){
    				min=1;
    				max=f[8];
    			}
    		}
    }
    cout<<min<<" "<<max<<endl;
	// your code goes here
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    double t, x;
    cin >> t >> x;
    double ans;
    ans = t / x;
    print(ans);
}

Measured memory_bytes: 256
S = input()
N = len(S)
rS = S[::-1]

cum = [0] * (N+1)
for i in range(N):
    cum[i+1] = (cum[i] + (int(rS[i]) * pow(10,i,2019)) % 2019) % 2019

ans = 0
from collections import Counter
from math import factorial
c = Counter(cum)
for v in c.values():
    if v >= 2:
        ans += factorial(v) // (factorial(v-2)*2)

print(ans)

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

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

using namespace std;
using lint=long long;

int main(){
	int n;
	lint k; cin>>n>>k;
	pair<int,int> a[100000];
	rep(i,n) cin>>a[i].first>>a[i].second;

	sort(a,a+n);

	rep(i,n){
		k-=a[i].second;
		if(k<=0){
			cout<<a[i].first<<endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
const int N = 100010;
 
std::vector <int> e[N];
int n;
 
int dfs(int u, int fa){
	int cnt = 0;
	for (auto v : e[u]){
		if (v == fa){
			continue;
		}
		if (dfs(v, u)){
			++ cnt;
		}
	}
	if (cnt >= 2){
		printf("First\n");
		exit(0);
	}
	return !cnt;
}
 
int main(){
	scanf("%d", &n);
	for (int i = 0, u, v; i < n - 1; ++ i){
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	return printf(dfs(1, 0) ? "First\n" : "Second\n"), 0;
}

Measured memory_bytes: 5888
#067c
N = int(input())
l_list = [int(e) for e in input().split()]

ans = 10**9 * 2 * 10 ** 5

#愚直解
#for i in range(1,N):
#    x = sum(l_list[0:i])
#    y = sum(l_list[i:])
#    
#    print(l_list[0:i],l_list[i:],x,y,x-y,abs(x-y))
#    
#    if ans > abs(x-y):
#        ans = abs(x-y)

#高速解
x = 0
y = sum(l_list)

for i in range(0,N-1):
    x += l_list[i]
    y -= l_list[i]
    
    if ans > abs(x-y):
        ans = abs(x-y)    
        
print(ans)

Measured memory_bytes: 24832
#include <iostream>
#include <vector>
#include <list>

int main() {
    
    int N, K;
    std::cin >> N >> K;
    std::vector<int> h;
    h.resize(N);
    for (int &a : h) {
        std::cin >> a;
    }

    std::list<int> ks;
    int mn, tmp;
    for (int i = 0; i < N; i++) {
        auto iter = ks.begin();
        if (ks.empty()) mn = 0;
        else mn = ks.front() + abs(h[i]-h[i-1]);
        for (int k = 1; k < K; k++) {
            if (k >= i) break;
            if ((tmp = *++iter + abs(h[i] - h[i - k - 1])) < mn) mn = tmp;
        }
        ks.push_front(mn);
        if (ks.size() > K) ks.pop_back();
    }
    std::cout << ks.front();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000003
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
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; }
using namespace std;

//AGC034
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n,x; cin>>n>>x;
    vector<int> b(n),l(n),u(n);
    vector<P> val(n);
    rep(i,n){
        cin>>b[i]>>l[i]>>u[i];
        val[i].F=b[i]*l[i]+(x-b[i])*u[i];
        val[i].S=i;
    }
    sort(all(val),greater<P>());

    vector<int> sums(n+1); sums[0]=0;
    rep(i,n){
        sums[i+1]=sums[i]+val[i].F;
    }

    int score=0;
    rep(i,n)score+=b[i]*l[i];

    int left=-1,right=n*x+1;
    while(right-left>1){
        int mid=(right+left)/2;
        int take_all=mid/x;
        int incmp=mid-take_all*x;
        int final_sum=0;

        rep(i,n){
            int j=val[i].S;
            int tmp_sum;
            if(i<take_all and take_all<n)tmp_sum=sums[take_all+1]-val[i].F;
            else tmp_sum=sums[take_all];
            tmp_sum+=max<int>(0,incmp-b[j])*u[j]+min<int>(incmp,b[j])*l[j];
            chmax(final_sum,tmp_sum);
        }

        if(final_sum>=score)right=mid;
        else left=mid;
    }

    cout<<right<<endl;
    return 0;

}

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

const int mxN = 100;
char a[mxN][mxN];

void solve() {
    int n, m;
    read(n, m);
    
    FOR(n) {
        FOR(j, m) {
            read(a[i][j]);
        }
    }
    
    FOR(n + 2) {
        FOR(j, m + 2) {
            if (i == 0 || i == n + 1 || j == 0 || j == m + 1) {
                write("#");
            }
            else{
                write(a[i - 1][j - 1]);
            }
        }
        print();
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        
        solve();
        
    }
    
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
//ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  bool f=false;
  rep(i,k+1){
    rep(j,k+1-i){
      rep(l,k+1-i-j){
        if(a*pow(2,i)<b*pow(2,j)&&b*pow(2,j)<c*pow(2,l)){
          f=true;
        }
      }
    }
  }
  YesNo(f);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 4064
#include<stdio.h>
int main(){
  int h[10], i, j, tmp;
  for(i = 0; i < 10; i++){
    scanf("%d", &h[i]);
  }

  for(i = 0; i < 9; i++){
    for(j = i+1; j < 10; j++){
      if(h[i] < h[j]){
        tmp = h[i];
        h[i] = h[j];
        h[j] = tmp;
      }
    }
  }

  for(i = 0; i < 3; i++){
    printf("%d\n", h[i]);
  }
  return 0;
}

Measured memory_bytes: 600
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    string s;
    scan(s);

    foreach (cmb ; 0 .. 16) {
        string t;
        t ~= (cmb & 1) ? "AKIH" : "KIH";
        t ~= (cmb & 2) ? "AB" : "B";
        t ~= (cmb & 4) ? "AR" : "R";
        t ~= (cmb & 8) ? "A" : "";

        if (s == t) {
            writeln("YES");
            return;
        }
    }

    writeln("NO");
}



struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
        }
        else {
            p[v] = u;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}



struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = 10000000
    min_l = min(l)
    max_l = max(l)
    for y in range(min_l, max_l+1):
        temp = 0
        for x in l:
            temp += (x - y) ** 2
        ans = min(ans, temp)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
n = int(input())
a = list(map(int, input().split()))
flag = False
ans = 0
while not flag:
    for i in range(n):
        if a[i]%2 == 0:
            a[i] = a[i]//2
        else:
            flag = True
            break
    if not flag:
        ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
res = [int()]*n
for i in range(n):
    res[i] = a[i] - i - 1
res.sort()
x = res[int(n/2)]
for j in range(n):
    res[j] = abs(res[j] - x)
print(sum(res))


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

using namespace std;

typedef long long ll;

ll A[202020];
ll n, ans;

int main()
{
	ll i, prev;
	
	scanf("%lld", &n);
	
	for(i=0;i<n;i++){
		scanf("%lld", A+i);
	}
	
	prev = 0;
	
	for(i=n-1;i>=0;i--){
		if(A[i] < prev || A[i] > i){
			printf("-1\n");
			return 0;
		}
		
		if(A[i] > prev) ans += A[i];
		prev = max(0ll, A[i] - 1);
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <unordered_map> //C++11
using namespace std;

typedef long long ll;

bool table[100002];
int a[100002];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i + 1], table[i + 1] = true;
	int now = 1;
	for (int i = 0; i < n; i++) {
		if (a[now] == 2) {
			cout << i + 1 << endl;
			break;
		}
		else if (table[now]) {
			table[now] = false;
			now = a[now];
		}
		else {
			cout << -1 << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef std::pair<int, int> int_pair;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {

	int n = 0, biggest = 0, other = 0;
	int l[10] = {};
	cin >> n;
	rep(i, n) {
		cin >> l[i];
	}
	sort(l, l + n,greater<int>());

	biggest = l[0];

	for (int i = 1; i < n; i++) {
		other += l[i];
	}



	if (biggest < other) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>
#include <exception>
#include <stdexcept>

using namespace std;

typedef long long i64;

vector<int> adj[60];
int edges[2500][2];

bool visited[60];

void dfs(const int v, const int excluded_edge)
{
    visited[v] = true;

    for (int adj_v : adj[v])
    {
        bool bad_edge = visited[adj_v];
        bad_edge |= edges[excluded_edge][0] == v && edges[excluded_edge][1] == adj_v;
        bad_edge |= edges[excluded_edge][1] == v && edges[excluded_edge][0] == adj_v;

        if (!bad_edge)
            dfs(adj_v, excluded_edge);
    }
}

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);

        edges[i][0] = u;
        edges[i][1] = v;
    }

    int bridges = 0;
    for (int i = 0; i < m; i++)
    {
        dfs(1, i);

        bool exists_not_visited = false;
        for (int v = 1; v <= n; v++)
        {
            exists_not_visited |= !visited[v];
            visited[v] = false;
        }

        bridges += exists_not_visited;
    }

    cout << bridges;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
typedef pair<ll, ll> P;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<int> gate(n);
    int l, r;
    for (int i = 0; i < n; i++) {
        gate[i] = 0;
    }
    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        l--;
        gate[l]++;
        gate[r]--;
    }
    for (int i = 0; i < n; i++) {
        gate[i + 1] += gate[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (gate[i] == m) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#define MAXN 106
using namespace std;
int n,x,a[MAXN];
int main()
{
	scanf("%d",&n);
	scanf("%d",&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		if(x>=a[i])
		{
			x-=a[i];
		}
		else
		{
			printf("%d",i-1);
			return 0;
		}
	}
	if(x) printf("%d",n-1);
	else printf("%d",n);
}

Measured memory_bytes: 128
#include <stdio.h>
 
#define MAX 100
#define MaxVal 2000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int main(){
  int n, i, j, u, k, v, c, min;
  int color[MAX], arr[MAX];
 
  scanf("%d", &n);
 
  int d[n];
  int matrix[n][n];
 
  for( i=0; i<n; i++){
    d[i] = 0;
    arr[i] = MaxVal;
    color[i] = WHITE;
    for( j=0; j<n; j++){
      matrix[i][j] = MaxVal;
    }
  }
 
  arr[0] = 0;
  color[0] = GRAY;
 
  for( i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    for( j=0; j<k; j++){
      scanf("%d %d", &v, &c);
      matrix[u][v] = c;  
    }
  }
 
  while(1){
    min = MaxVal;
    u = -1;
 
    for( i=0; i<n; i++){
      if( min > arr[i] && color[i] != BLACK ){
    u = i;
    min = arr[i];
      }
    }
 
    if( u == -1 )break;
 
    color[u] = BLACK;
 
    for( i=0; i<n; i++){
      if( color[i] != BLACK && matrix[u][i] != MaxVal ){
    if( arr[i] > (arr[u] + matrix[u][i]) ){
      arr[i] = arr[u] + matrix[u][i];
      color[i] = GRAY;
    }
      }
    }
  }
 
  for( i=0; i<n; i++){
    printf("%d ", i);
    if( arr[i] == MaxVal ) arr[i] = -1;
    printf("%d\n", arr[i]);
  }
 
  return 0;
}

Measured memory_bytes: 640
R, G, B, N = map(int, input().split())

cnt = 0
r, g, b = 0, 0, 0

while r*R <= N:
    tank = N - r*R
    while True:
        if divmod(tank, B)[1] == 0:
            cnt += 1
        tank -= G
        if tank < 0:
            break
    r += 1

print(cnt)


Measured memory_bytes: 2940
def waku(i,W):
    a = ""
    if i%2 == 0:
        for j in range(W):
            if j%2 == 0:
                a += "#"
            else:
                a += "."
    else:
        for j in range(W):
            if j%2 == 0:
                a += "."
            else:
                a += "#"
    return a


while 1:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        print(waku(i,W))
    print("")
    
    


Measured memory_bytes: 5616