akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

string str[10];
bool row[10],col[10];

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

	ll n,m,k,i,j,p,q,r,h,c,cnt = 0;

	cin >> n >> m >> r;
	for(i=0;i<n;++i)
		cin >> str[i];

	for(i=0;i<(1<<n);++i)
	{
		for(j=0;j<n;++j)
		{
			if((i>>j)&1)
				row[j] = 1;
		}
		for(k=0;k<(1<<m);++k)
		{
			for(h=0;h<m;++h)
			{
				if((k>>h)&1)
					col[h] = 1;
			}
			c = 0;
			for(p=0;p<n;++p)
			{
				for(q=0;q<m;++q)
				{
					if(row[p] == 1 || col[q] == 1)
						continue;
					if(str[p][q] == '#')
						c++;
				}
			}
			if(c == r)
				cnt++;
			for(h=0;h<m;++h)
			{
				if((k>>h)&1)
					col[h] = 0;
			}
		}
		for(j=0;j<n;++j)
		{
			if((i>>j)&1)
				row[j] = 0;
		}
	}

	cout << cnt << "\n";
}

Measured memory_bytes: 3656
import java.util.Scanner;

class Main{

	public static void main(String[] args) {


		Scanner scan = new Scanner(System.in);
				int N = scan.nextInt();
				int K = scan.nextInt();

				if((N % K) >= 1){
					System.out.println(1);
				}else{
				
			
				System.out.println(0);
				}
	
	}







}

Measured memory_bytes: 21844
class Node:
    def __init__(self, key):
        self.key = key
        self.prev = None
        self.next = None

class DoublyLinkedList:
    def __init__(self):
        self.nil = Node(None) # 番兵
        self.nil.prev = self.nil
        self.nil.next = self.nil # prevもnextも番兵に接続

    def insert(self, key):
        new = Node(key)
        new.next = self.nil.next   # 新しいNodeの後ろをもともと番兵の後ろにあったNodeに変更
        self.nil.next.prev = new   # もともと番兵の次にあったNodeの前を新しいNodeに変更
        self.nil.next = new        # 番兵の後ろを新しいNodeに変更
        new.prev = self.nil             # 新しいNodeの前をnilに指定

    def listSearch(self, key):
        cur = self.nil.next
        while cur != self.nil and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, t):
        if t == self.nil:
            return
        t.prev.next = t.next
        t.next.prev = t.prev

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, key):
        self.deleteNode(self.listSearch(key))


if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())

    dll = DoublyLinkedList()

    for _ in range(n):
        com = input().rstrip()
        # keyはinsert,deleteなら[x]になり、
        # deleteFirst,deleteLastなら[]になる。
        if com[0] == 'i':
            dll.insert(com[7:])
        elif com[6] == 'F':
            dll.deleteFirst()
        elif com[6] == 'L':
            dll.deleteLast()
        else:
            dll.deleteKey(com[7:])

    cur = dll.nil.next
    ans = []
    while cur != dll.nil:
        ans.append(cur.key)
        cur = cur.next

    print(' '.join(ans))



Measured memory_bytes: 227600
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a": " << a << endl;
#define mst(a, b) memset(a, b, sizeof(a))
#define lc rt << 1
#define rc rt << 1 | 1
#define X first
#define Y second
inline int lowbit(int x) { return x & -x; }
typedef long long LL;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int M = 2e6 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int dp[N];
int head[N];
int tot;
int nxt[N];
int to[N];

inline void addEdge(int u, int v) {
    nxt[++tot] = head[u];
    to[tot] = v;
    head[u] = tot;
}
int dfs(int u) {
    int& res = dp[u];
    if (~res)
        return res;
    res = 0;
    for (int i = head[u]; i; i = nxt[i])
        res = max(res, dfs(to[i]) + 1);
    return res;
}

int main() {
#ifdef purple_bro
    freopen("in.txt","r",stdin);
#endif
    mst(dp, -1);
    int n, m;

    scanf("%d%d", &n, &m);

    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        addEdge(u, v);
    }

    int ans = 0;

    for (int i = 1; i <= n; i++)
        ans = max(ans, dfs(i));

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

    return 0;
}


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

#define MIN -1000000000
int main(void){
    int arr[200000];
    int min[200000], max[200000];
    int i;
    int n;
    int result;
    
    cin >> n;
    cin >> arr[0];
    min[0] = arr[0];
 //   cout << min[0] << endl;
    
    for(i = 1; i < n; i++){
        cin >> arr[i];
        
        if(arr[i] < min[i-1]) min[i] = arr[i];
        else min[i] = min[i-1];
        
 //      cout << min[i] << endl;
    }
    
    max[n-2] = arr[n-1];
    result = max[n-2] - min[n-2];
//    cout << max[n-2] << endl;
    for(i = n-3; 0 <= i; i--){
        if(max[i+1] < arr[i+1]) max[i] = arr[i+1];
        else max[i] = max[i+1];
        
        if(result < (max[i] - min[i])) result = (max[i] - min[i]);
    }
    
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 5412
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

i = X + 1
while i < Y + 1:
    if max(x) < i and i <= min(y):
        print('No War')
        break
    else:
        i += 1
if i == Y + 1:
    print('War')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;

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

int main(){
    int N;
    cin >> N;
    ll A[100000];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    ll left[100000];
    ll right[100000];
    
    left[0]=0;
    right[N-1]=0;
    
    for(int i=1; i<N; i++){
        left[i] = gcd(left[i-1],A[i-1]);
    }
    for(int i=N-2; i>=0; i--){
        right[i] = gcd(right[i+1],A[i+1]);
    }
    
    ll ans=1;
    for(int i=0; i<N; i++){
        ans = max (gcd(left[i],right[i]),ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        char a[]=sc.nextString().toCharArray();
        char b[]=sc.nextString().toCharArray();
        char c[]=sc.nextString().toCharArray();
        int ans=0;
        for (int i = 0; i < c.length; i++) {
        	int d[]=new int[26];
        	d[a[i]-'a']++;
        	d[b[i]-'a']++;
        	d[c[i]-'a']++;
        	sort(d);
        	if(d[25]==1)ans+=2;
        	if(d[25]==2)ans+=1;
		}

        out.println(ans);
        out.flush();
    }
    
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21204
import java.util.Scanner;

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

        a = sc.nextInt();
        s = sc.next();

        if (a < 3200) {
            System.out.print("red");
        }
        else {
            System.out.print(s);
        }
    }
}

Measured memory_bytes: 21588
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
	int pos = 0;
	for (int i = 0; i < 120000; i++) {
		if (pos == 1) {
			cout << i << endl;
			break;
		}
		pos = a[pos];
	}
	if (pos != 1) cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define MOD 1e+9;

using namespace std;

auto f=[](){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
};

int main()
{
	f();
	int N;
	cin>>N;
	int i=0;
	vector<int> v(N,0);
	int sum=0;
	while(i<N)
	{
		cin>>v[i];
		sum+=v[i];
		++i;
	}

	int avg=floor(sum/N);
	//cout<<avg<<"\n";
	int result=numeric_limits<int>::max();	
	int start=avg-3;
	int end=avg+3;
	
	for(int j=start;j<=end;++j)
	{	
		int temp=0;
		for(auto i:v)
		{
			int diff=j-i;
			//result+=(diff*diff);
			temp+=(diff*diff);
		}
		result=min(result,temp);
	}		
	cout<<result<<"\n";
	return 0;
}


Measured memory_bytes: 256
dbflag=0
def debug(*args):
	if dbflag: print(*args)

result = 0

N =  input() 
N=int(N)

#A =  map(int,input() .split())
A = [int(i) for i in input().split(' ')]

flag= 1

while flag:
	for i in range(len(A)):
		debug(i, A[i])
		if A[i] %2 == 0:
			A[i] = A[i] //2
		else:
			flag = 0
			break
		
	if flag:
		result += 1

print(result)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<int> p(N);
    rep(i,N){
        cin >> p[i];
        p[i]--;
    }
    ll d = 20000 + 1;
    vector<ll> a(N),b(N);
    a[0] = 1;
    rep(i,N-1)a[i+1] = a[i] + d;
    b.back() = 1;
    int start = 0;
    rep(i,N){
        if(p[i] == N - 1)start = i;
    }
    for(int i = start; i+1 < N; i++){
        ll y = p[i];
        ll x = p[i+1];
        ll delta_a = abs(a[y] - a[x]);
        if(x < y){
            b[x] = b[y] + delta_a + 1;
        }
        else{
            b[x] = b[y] - delta_a + 1;
        }
    }
    for(int i = start; i - 1 >= 0; i--){
        ll y = p[i-1];
        ll x = p[i];
        ll delta_a = abs(a[x] - a[y]);
        if(x < y){
            b[y] = b[x] - delta_a - 1;
        }
        else{
            b[y] = b[x] + delta_a - 1;
        }
    }
    // print(p);
    // print(a);
    // print(b);
    rep(i,N){
        cout << a[i] << " ";
    }
    cout << endl;
    rep(i,N){
        cout << b[i] << " ";
    }
    cout << endl;
    // rep(i,N){
    //     cerr << a[i] + b[i] << " ";
    // }
    // cout << endl;
}


Measured memory_bytes: 3736
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int R, C, K;
ll dp[2][3005][5];

ll v[3005][3005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> R >> C >> K;
    for(int i = 0; i < K; i++){
        ll r, c, u; cin >> r >> c >> u; r--; c--;
        v[r][c] = u;
    }
    dp[0][0][1] = v[0][0];
    for(int r = 0; r < R; r++){
        int r_cur = r%2;
        int r_next = (r+1)%2;
        for(int c = 0; c < C; c++){
            for(int i = 0; i <= 3; i++){
                    // ->
                    dp[r_cur][c+1][i] = max(dp[r_cur][c+1][i], dp[r_cur][c][i]);
                    dp[r_cur][c+1][i+1] = max(dp[r_cur][c+1][i+1], dp[r_cur][c][i]+v[r][c+1]);

                    // 下
                    dp[r_next][c][0] = max(dp[r_next][c][0], dp[r_cur][c][i]);
                    dp[r_next][c][1] = max(dp[r_next][c][1], dp[r_cur][c][i]+v[r+1][c]);
            }
        }
        if(r != R-1){
            for(int c = 0; c < C; c++){
                for(int i = 0; i <= 3; i++){
                    dp[r_cur][c][i] = 0;
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= 3; i++){
        ans = max(ans, dp[(R-1)%2][C-1][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 74216
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n,m = LI()
    p = LI()
    f = [None]*n
    for i in range(n):
        p[i] -= 1
        f[p[i]] = i
    par = [i for i in range(n)]
    rank = [0]*n
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        if root(a) != root(b):
            unite(a,b)
    ans = 0
    for i in range(n):
        if root(f[i]) == root(i):
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 94932
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N % 1000 != 0:
        print(1000 - N % 1000)
    else:
        print(0)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
using System;
namespace kozaiyApp
{
    public class EKnapsack2
    {
        static void Main()
        {
            int ans = 0;
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int Knapsack = int.Parse(input[1]);

            long[] W = new long[N];
            long[] V = new long[N];
            int totalV = 0;

            for (int i = 0; i < N; i++)
            {
                string[] inputData = Console.ReadLine().Split(' ');
                W[i] = long.Parse(inputData[0]);
                V[i] = long.Parse(inputData[1]);
                totalV += int.Parse(inputData[1]);
            }

            long[,] DP = new long[N + 1, totalV + 1];

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= totalV; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        DP[i, j] = 0;
                    }
                    else if (i == 0) 
                    {
                        DP[i, j] = 100000000000;
                    }
                    else if (V[i - 1] > j)
                    {
                        DP[i, j] = DP[i - 1, j];
                    }
                    else
                    {
                        DP[i, j] = Math.Min(DP[i - 1, j], W[i - 1] + DP[i - 1, j - V[i - 1]]);
                    }
                }
            }

            for (int j = totalV; j >= 0; j--)
            {
                if (DP[N, j] <= Knapsack)
                {
                    ans += j;
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 89056
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.util.Random
import java.util.Date

object Main extends App {
  val startTime = new Date().getTime // to milli seconds

  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }


  /** functions **/
  def calcScore(t: Array[Int]): Long = {
    val last = new Array[Int](26+1)
    var res = 0L

    for (d <- 1 to D) {
      val ty = t(d)

      res += s(d)(ty)
      last(ty) = d

      for (i <- 1 to 26) {
        res -= c(i) * (d - last(i))
      }
    }

    res
  }


  /** solve **/
  val t = new Array[Int](D+1)
  val last = new Array[Int](26+1)
  for (d <- 1 to D) {
    val (_, ty) =
      s(d).zipWithIndex
        .drop(1)
        .map{ case (s, ty) => (s + c(ty) * (d - last(ty)), ty) }
        .max

    t(d) = ty
    last(ty) = d
  }

  val endTime = 1400
  var currentScore = calcScore(t)
  var bestAns = t.clone
  var bestScore =  currentScore

  val annStartTime = new Date().getTime
  var currentTime = annStartTime

  val T = endTime - annStartTime // 焼きなましにかける時間
  val R = 10000

  while ((new Date().getTime - startTime) < endTime) {
    for (_ <- 1 to 1000) {
      val time = currentTime - annStartTime // 焼きなまし法開始からの時間

      // 遷移を実施
      val d = Random.nextInt(D) + 1
      val ty = Random.nextInt(26) + 1

      val tmp = t(d)
      t(d) = ty

      val nextScore = calcScore(t) // 遷移後のスコアを計算

      // スコアが悪くなったときでも、次の状態に移動する遷移する場合はtrue。
      val ForceNext = T * Random.nextInt(R) < (T-time) * R // １次関数
      
      if (nextScore > currentScore || ForceNext) {
        // 遷移を適用
        currentScore = nextScore
      }
      else {
        // 遷移を破棄
        t(d) = tmp
      }

      // ベストスコアを保存
      if (currentScore > bestScore) {
        bestScore = currentScore
        bestAns = t.clone // 現在の盤面を渡す
      }
    }
  }


  for (d <- 1 to D) {
    pw.println(t(d))
  }
  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

int main()
{
    string s;
    cin >> s;
    int a[128]={0};

    for( int i = 0; i < 4; i++ )
    {
        a[(int)s[i]] ++;
    }

    int n = 0;
    int m = 0;
    for( int i = 0; i < 128; i++ )
    {
    
        if( a[i] != 0 ){
            n++;  
        }
        if( a[i]%2 != 0 ){
            cout << "No" << endl;
            return 0;
        }
    }
    if( n == 2 ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define      TEST    ll t ; cin >> t ; while( t -- )


//------------------------------------------------------------------------//

#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)

//------------------------------------------------------------------------//

const ll big = 10e15 + 11 ;


int  main (  ) {

    FASTIO ;

    ll n ;
    cin >> n ;

    map < ll , ll > mp ;

    vector < int > v( n + 2 ) ;

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

        mp[ i - v[ i ]  ]++ ;

       // cout <<  i - v[ i ] << " " ;
    }

   // cout << endl;

    ll ans = 0 ;

    for( int i = 1 ; i <= n ; i++ ){
       ll x = v[ i ] + i ;

     //  cout << x << " " ;

        ans += mp[ x ] ;
    }

    cout << ans  ;



    return  0 ;
}


Measured memory_bytes: 26572
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        short i = scanner.nextShort();
        short j = scanner.nextShort();
        if (i > 9){
            System.out.println(j);
        }else {
            System.out.println(j+1000-100*i);
        }

    }
    
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  vi v(n);
  REP(i, n) {
    cin >> v[i];
  }
  SORT(v);
  UNIQUE(v);
  ans = SZ(v);

  cout << (ans % 2 == 0 ? ans - 1 : ans) << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<pair<int, int>>>;

vector<int> color;
void dfs(const Graph &G, int v, int parent_v, int cur = 0) {
  color[v] = cur;

  for (auto next_v : G[v]) {
    if (parent_v == next_v.first) continue;

    if (next_v.second)
      dfs(G, next_v.first, v, 1 - cur);
    else
      dfs(G, next_v.first, v, cur);
  }
}

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

  Graph G(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    w %= 2;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }

  color.assign(N, -1);
  dfs(G, 0, -1);

  for (auto c : color) {
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 9728
def solve n, a, b
  if (b - a) % 2 == 0
    (b - a) / 2
  else
    [a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2].min
  end
end

n, a, b = gets.chomp.split.map(&:to_i)
puts solve(n, a, b)

Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	int n; cin >> n;
	vector< vector<int> > w(3);
	for (int i = 0; i < n; ++i) {
		w[(i+1) % 3].push_back(i+1);
	}
	int s0 = w[0].size(), s1 = w[1].size(), s2 = w[2].size();
	vector< vector<int> > g(n);
	for (int i = 1; i < n; ++i) {
		int a, b; cin >> a >> b; --a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	vector<int> le, ri;
	
	function<void(int, int, bool)> dfs = [&](int v, int p, bool c) {
		(c ? le : ri).push_back(v);
		for (int to : g[v]) {
			if (to == p) continue;
			dfs(to, v, !c);
		}
	};
	dfs(0, 0, 0);
	
	if (le.size() > ri.size()) {
		swap(le, ri);
	}
	
	int ls = le.size(), rs = ri.size();
	vector<int> ans(n);
	if (s2 <= ls) {
		assert(s1 <= rs);
		for (int i = 0; i < s2; ++i) {
			ans[le.back()] = w[2].back();
			le.pop_back();
			w[2].pop_back();
 		}
 		for (int i = 0; i < s1; ++i) {
			ans[ri.back()] = w[1].back();
			ri.pop_back();
			w[1].pop_back();
		}
		for (int i = 0; i < s0; ++i) {
			if (ri.empty()) {
				ans[le.back()] = w[0].back();
				le.pop_back();
				w[0].pop_back();
			} else {
				ans[ri.back()] = w[0].back();
				ri.pop_back();
				w[0].pop_back();
 			}
		}
	} else {
		assert(ls <= s0);
		for (int i = 0; i < ls; ++i) {
			ans[le.back()] = w[0].back();
			le.pop_back();
			w[0].pop_back();
		}
		for (int i = 0; i < s1; ++i) {
			ans[ri.back()] = w[1].back();
			ri.pop_back();
			w[1].pop_back();
		}
		for (int i = 0; i < s2; ++i) {
			ans[ri.back()] = w[2].back();
			ri.pop_back();
			w[2].pop_back();
		}
		assert(ri.size() == w[0].size());
		while (!ri.empty()) {
			ans[ri.back()] = w[0].back();
			ri.pop_back();
			w[0].pop_back();
		}
	}
	
	for (int i = 0; i < n; ++i) {
		cout << ans[i] << " ";
	}
	cout << endl;
	
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    int val[N][3];
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> val[i][j];
        }
    }
    long long int dp[N][3];
    for(int i = 0; i < 3; i++) {
        dp[0][i] = val[0][i];
    }
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            dp[i][j] = max(dp[i-1][(j+1)%3] + val[i][j], dp[i-1][(j+2)%3]+ val[i][j]);
        }
    }
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
   
int n;
cin>>n;
int h[n+1];
for(int i=1;i<=n;i++)
cin>>h[i];
h[0]=INF;
int dp[n+1];
dp[0]=INF;
dp[1]=0;
for(int i=2;i<=n;i++)
dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
cout<<dp[n]<<endl; 
    
}




int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

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


bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    // vector<pair<int, int>> R(A), G(B), M(C), RM(A+C), GM(B+C), RGM(A+B+C);
    vector<pair<int, int>> R, G, M, RM, GM, RGM;
    int pi, qi, ri;
    rep(i, A) {
        cin >> pi;
        R.push_back(make_pair(1, pi));
        RM.push_back(make_pair(1, pi));
        RGM.push_back(make_pair(1, pi));
    }
    rep(i, B) {
        cin >> qi;
        G.push_back(make_pair(2, qi));
        GM.push_back(make_pair(2, qi));
        RGM.push_back(make_pair(2, qi));
    }
    rep(i, C) {
        cin >> ri;
        M.push_back(make_pair(3, ri));
        RM.push_back(make_pair(3, ri));
        GM.push_back(make_pair(3, ri));
        RGM.push_back(make_pair(3, ri));
    }

    sort(R.begin(), R.end(), compare_by_b); // 降順
    sort(G.begin(), G.end(), compare_by_b); // 降順
    sort(M.begin(), M.end(), compare_by_b); // 降順
    sort(RM.begin(), RM.end(), compare_by_b); // 降順
    sort(GM.begin(), GM.end(), compare_by_b); // 降順
    sort(RGM.begin(), RGM.end(), compare_by_b); // 降順

    ull accum_RX = 0, accum_GY = 0, accum_RMX = 0, accum_GMY = 0;
    rep(i, X) accum_RX += R[i].second;
    rep(i, Y) accum_GY += G[i].second;
    rep(i, X) accum_RMX += RM[i].second;
    rep(i, Y) accum_GMY += GM[i].second;

    ull ans = 0, num_R=0, num_G=0;
    rep(i, X+Y) {
        ans += RGM[i].second;
        if (RGM[i].first == 1) num_R++;
        if (RGM[i].first == 2) num_G++;
    }
    if (num_R > X) ans = accum_RX + accum_GMY;
    if (num_G > Y) ans = accum_GY + accum_RMX;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h,w,ans=0x7fffffff;
void getf_ans(){
    if(h%3) ans=min(ans,w);
    else ans=0;
//    ans=min(ans,max(abs(h/3*w-w/2*(h-h/3)),abs(h/3*w-(h-h/3)*(w-w/2))));
//    ans=min(ans,max(abs((h/3+1)*w-w/2*(h-h/3-1)),abs((h/3+1)*w-(h-h/3-1)*(w-w/2))));
    ans=min(ans,max(abs(h/3*w-w/2*(h-h/3)),abs(h/3*w-(h-h/3)*(w-w/2))));
    ans=min(ans,max(abs((h/3+1)*w-w/2*(h-h/3-1)),abs((h/3+1)*w-(h-h/3-1)*(w-w/2))));
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie();
    cin>>h>>w;
    getf_ans();
    swap(h,w);
    getf_ans();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

for n_10000 in range(min(N+1, Y//10000+1)):
    for n_5000 in range(min(N-n_10000+1, (Y-n_10000*10000)//5000+1)):
        n_1000 = N - n_10000 - n_5000
        if n_10000 * 10000 + n_5000 * 5000 + n_1000 * 1000 == Y:
            print(n_10000, n_5000, n_1000)
            exit()

print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
             cout << std::setprecision(15) ;
         int h,w,k;
         cin>>h>>w>>k;
         string s[h];
         for(int i=0;i<h;i++)cin>>s[i];
      
        int p,q,d[h][w+1],dd[h]={},r0,ans=h*w+1;bool t=true,tt;
        for(int i=0;i<h;i++)d[i][0]=0;
        for(int i=(1<<(h-1));i<(1<<h);i++){
            r0=0;
                p=1;q=0;t=true;
                for(int r=0;r<w;r++){
                        tt=false;
               for(int j=0;j<h;j++){
                       if(s[j][r]=='1')q++;
                       if(i&(1<<j)){
                               if(q>k)t=false;
                             d[j][r+1]=d[j][r]+q;
                             if(d[j][r+1]>k+d[j][r0]){r0=r;p++;}
                               q=0;
                       }

               }
             
              
              
               //  cerr<<p<<' ';
                }
              //  cerr<<endl;
               
                if(t){
                       
                        for(int j=0;j<h;j++)if(i&(1<<j))p++;
                        ans=min(p-2,ans);
                }


        }
        cout<<ans;

         
}

        


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


long long gcd(long long a, long long b) {
	while (b) {
		long long tmp = a;
		a = b;
		b = tmp % b;
	}
	return a;
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	long long a, b, c, d;

	std::cin >> a >> b >> c >> d;

	long long sum = b - (b / c + b / d - b / lcm(c, d));

		a--;
		sum -= a - (a / c + a / d - a / lcm(c, d));
	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
mincost=float('inf')
mina = min(A)
_ = max(A) - mina

for i in range(mina,mina+_+1):
    cost = 0
    for a in A:
        cost += (a-i)**2
    if cost < mincost:
        mincost = cost
print(mincost)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[3],b[3];
    for(int i=0;i<3;i++){
    	cin>>a[i];
    }
    for(int i=0;i<3;i++){
    	cin>>b[i];
    }
    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<3;i++){
    	ll w=a[i],v=b[i];
    	for(ll j=w;j<=n;j++){
    		dp[j]=max(dp[j],dp[j-w]+v);
    	}
    }
    ll m=0;
    for(ll i=0;i<=n;i++){
    	m=max(m,dp[i]-i);
    }
    n+=m;
    ll d[n+1];
    memset(d,0,sizeof(d));
    for(int i=0;i<3;i++){
    	ll w=b[i],v=a[i];
    	for(ll j=w;j<=n;j++){
    		d[j]=max(d[j],d[j-w]+v);
    	}
    }
    m=0;
    for(ll i=0;i<=n;i++){
    	m=max(m,d[i]-i);
    }
    n+=m;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 195584
#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;

#define int long long

void solve() {
	int n, d;
	cin >> n >> d;
	d=d*d;
	int cnt = 0;
	for(int i=0; i<n; ++i){
		int a, b;
		cin >> a >> b;
		if(a*a+b*b<=d)
		cnt++;
	}
	cout << cnt;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
     
      //入力
      int K = sc.nextInt();
      int X = sc.nextInt();
      
      //黒石の可能性がある小さい数字から大きい数字まで
    for(int i = (X-K)+1; i<=(X+K)-1; i++){
      
        System.out.print(i+" ");
     
     }
    }
}

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

int solve(int n);

int N;
int C[500], S[500], F[500];

int main(){
	cin >> N;
	for(int i=0; i<N-1; i++){
		cin >> C[i] >> S[i] >> F[i];
	}
	
	for(int i=0; i<N; i++){
		cout << solve(i)<< endl;
	}
}

//駅nから駅Nへの到達時刻
int solve(int n){
	if(n == N){ return 0; } //最初からゴールにいれば0
	
	//現在時刻を乗り込んだ時間に
	int time = S[n];
	
	for(int i=n; i<N-1; i++){
		//まだ始発が出ていなければそこまで待って乗る
		if(time < S[i]){
			time = S[i] + C[i];
		}//すぐ次の電車に乗れるときは現在時刻にC[i]を足す
		else if(time % F[i] == 0){
			time += C[i];
		} //すぐ乗れないときは次の電車まで待って乗る
		else if(time % F[i] != 0){
			time += F[i] - (time % F[i]);
			time += C[i];
		}
	}
	
	return time;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int L, R;
  cin >> L >> R;
  if (R - L >= 2019) {
	  cout << 0 << endl;
	  return 0;
	}
  int ans = 2019;
  for (int i = L; i <= R; i++) {
	  for (int j = i + 1; j <= R; j++) {
		  ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
		}
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

int n, m;
int a[15][15];
int main() {
	fio;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> a[i][j];
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i+1; j <= n; ++j) {
			LL tot = 0;
			for (int k = 1; k <= m; ++k) {
				tot += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			LL d = sqrt(tot);
			while(d*d < tot) ++d;
			while(d*d > tot) --d;
			if(d*d == tot) ans++;
		}
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct edge
{
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;//first:cost,second:vertice
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_)
{
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty())
	{
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
		{
			continue;
		}
		for (auto ed : graph_[thv])
		{
			if (dist[ed.to] > ed.cost + thd)
			{
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>graph[100000];
LL dist[100000];

int main(void)
{
	LL K;
	cin >> K;
	for (int i = 0; i < K; ++i) {
		for (int n = 0; n < 10; ++n) {
			if (i == 0 && n == 0)continue;
			graph[i ? i : K].push_back(edge((10 * i + n) % K, n));
		}
	}
	dijkstra(graph,dist,K+1,K);
	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 35956
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  char s1[10], s2[10], s3[10];

  unused = scanf("%s %s %s", s1, s2, s3);
  s1[0] = s1[0] - ('a'-'A');
  s2[0] = s2[0] - ('a'-'A');
  s3[0] = s3[0] - ('a'-'A');
  printf("%c%c%c", s1[0], s2[0], s3[0]);
  return 0;
}

Measured memory_bytes: 128
#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);

/* -----  2019/05/19  Problem: ABC 126 E / Link: http://abc126.contest.atcoder.jp/tasks/abc126_e  ----- */

struct UnionFind {
	vector<int> data;
	UnionFind(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, M; cin >> N >> M;
	UnionFind uf(N);
	FOR(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		uf.unionSet(a, b);
	}
	LL ans = 0LL;
	FOR(i, 0, N) {
		if (uf.root(i) == i)ans++;
	}

	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    char s[a+b+1];
    cin >> s;

    int i;
    for(i=0;i<a;i++){
        if(s[i]>='0' && s[i]<='9');
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    if(s[a]!='-'){
        cout << "No" << endl;
        return 0;
    }
    for(i=a+1;i<a+b+1;i++){
        if(s[i]>='0' && s[i]<='9');
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

int main(){
    ll x;
    cin >> x;
    vector<ll> p(1001);
    for(ll i=1;i*i<=1000;i++){
        if(i==1) p[1]=1;
        else{
            ll val=i*i;
            while(val<=1000){
                p[val]=1;
                val*=i;
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=x;i++){
        if(p[i]){
            ans=max(ans,i);
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
import sys

s = input()
k = int(input())

if (k <= len(s)):
    for i in range(k):
        if s[i] != '1':
            print(s[i])
            sys.exit()
    print('1')
else:
    for i in range(len(s)):
        if s[i] != '1':
            print(s[i])
            sys.exit()
    print('1')


Measured memory_bytes: 3060