akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

/*[DSU TEMPLATE] int dsu[501], ranks[501];

void resetDSU(){
    for(int i = 0; i < 501; ++i){
        dsu[i] = i; ranks[i] = 0;
    }
}
int find(int node){
    if(dsu[node] == node) return node;
    return dsu[node] = find(dsu[node]);
}
void combine(int a, int b){
    a = find(a); b = find(b);
    if(ranks[a] < ranks[b]){ dsu[a] = b; }
    else if(ranks[a] > ranks[b]){ dsu[b] = a; }
    else { dsu[a] = b; ranks[b]++; }
}*/

int adj[10][10], best[10][10];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w;

    cin >> h >> w;

    for(int i = 0; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            cin >> adj[i][j];
            best[i][j] = -1;
        }
    }

    for(int dig = 0; dig < 10; ++dig){
        priority_queue<pair<int, int>> q;
        q.push(make_pair(0, dig));
        while(!q.empty()){
            pair<int, int> state = q.top();
            q.pop();
            if(best[dig][state.second] != -1)
                continue;
            best[dig][state.second] = -state.first;
            for(int nx = 0; nx < 10; ++nx){
                q.push(make_pair(state.first - adj[state.second][nx], nx));
            }
        }
    }

    long long tot = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            int k;
            cin >> k;
            if(k == -1) continue;
            tot += best[k][1];
        }
    }

    cout << tot;

    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll A,ans;
  cin >> A >>ans;
  if(A<13){
    ans = ans/2;
  }
  if(A<=5){
    ans = 0;
  }
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int h,w,ans=0;
    cin >> h >> w;
    int a[h][w],b[h][w];
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        b[i][j] = 0;
    } 
    int flag = 0;
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                if(a[i][j]%2) flag++;
                b[i][j] = flag;
            }
        }
        else{
            for(int j=w-1;0<=j;j--){
                if(a[i][j]%2) flag++;
                b[i][j] = flag;
            }
        }
    }
     rep(i,h){
        if(i%2==0){
            rep(j,w-1){
                if(b[i][j]%2) ans++;
            } 
            if(i+1<h&&b[i][w-1]%2) ans++;
        }
        else{
            for(int j=w-1;0<j;j--){
                if(b[i][j]%2) ans++;
            } 
            if(i+1<h&&b[i][0]%2) ans++;
        }
    }
    cout << ans << endl;
    rep(i,h){
        if(i%2==0){
            rep(j,w-1){
                if(b[i][j]%2) cout << i+1 <<' ' << j+1 << ' ' << i+1 <<' '<< j+2 << endl;
            } 
            if(i+1<h&&b[i][w-1]%2) cout << i+1 << ' ' <<w << ' ' << i+2 <<' '<< w << endl;
        }
        else{
            for(int j=w-1;0<j;j--){
                if(b[i][j]%2) cout << i+1 <<' '<< j+1 << ' ' << i+1 <<' '<< j << endl;
            } 
            if(i+1<h&&b[i][0]%2) cout << i+1 <<' '<< 1 << ' ' << i+2 <<' '<< 1 << endl;
        }
    }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	int l1{a.length()}, l2{b.length()};
	int grid[l1 + 1][l2 + 1]{};
	for (int i{}; i < l1; i++) {
		for (int j{}; j < l2; j++) {
			if (a[i] == b[j]) {
				grid[i+1][j+1] = 1 + grid[i][j];
			}
			else {
				grid[i+1][j+1] = max(grid[i][j+1], grid[i+1][j]);
			}
		}
	}
	string ans;
	while (l1 != 0 && l2 != 0) {
		if (a[l1 - 1] == b[l2 - 1]) {
			ans = a[l1 - 1] + ans;
			--l1; --l2;
		}
		else if (grid[l1 - 1][l2] > grid[l1][l2 - 1]) {
			--l1;
		}
		else {
			--l2;
		}
	}
	cout << ans<<endl;
}

Measured memory_bytes: 38724
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>


#define BUF_SIZE 2000000
typedef unsigned char uchar;

int comp(const void* a, const void* b) {
  return *(int*)b - *(int*)a;
}

#define BUCKET_SIZE 200001

int main(void) {
  int num, kind;
  char line[BUF_SIZE];
  FILE* fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d %d", &num, &kind);

  int i;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  long sz = sysconf(_SC_PAGESIZE);
  long pagesize = sizeof(int)*(num+1)+(sz-1)/sz;
  int* hist = mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
  for(i = 0; i < num; i++) {
    char* tmp = strtok(tmpbuf, " ");
    int n = strtol(tmp, NULL, 10);
    hist[n]++;
    tmpbuf = NULL;
  }
  qsort(hist, num+1, sizeof(int), comp); //descending order

  int sum = 0;
  for(i = kind; i < num+1 && hist[i] != 0; i++) {
    sum += hist[i];
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 2940
import sys

a, b, k = map(int, input().split())

for i in range(a, min(b, a + k)):
    print(i)

 # 左側の幅だけで全部網羅する場合
if b < a + k:
    print(b)
    sys.exit()

 # ベン図みたいにかぶってる時
for i in range(max( a + k, b + 1 - k ), b + 1):
    print(i)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var ai = new long[N];
            for (var i = 0; i < N; ++i)
                ai[i] = Sarray()[0] - 1;
            var cnt = 0L;
            for (var i = 0; i < N; ++i)
            {
                cnt = ai[cnt];
                if (cnt == 1)
                {
                    WriteLine(i + 1);
                    return;
                }
            }
            WriteLine(-1);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 47684
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool checkYYMM(const string& s){
  int yy = (int)(s[0]-'0') * 10 + (int)(s[1]-'0');
  int mm = (int)(s[2]-'0') * 10 + (int)(s[3]-'0');
  if(mm < 1 || 12 < mm) return false;
  return true;
}
bool checkMMYY(const string& s){
  int mm = (int)(s[0]-'0') * 10 + (int)(s[1]-'0');
  int yy = (int)(s[2]-'0') * 10 + (int)(s[3]-'0');
  if(mm < 1 || 12 < mm) return false;
  return true;
}

int main(){
  string S;
  cin >> S;

  bool yymm = checkYYMM(S);
  bool mmyy = checkMMYY(S);
  if(yymm && mmyy) cout << "AMBIGUOUS" << endl;
  else if(yymm && !mmyy) cout << "YYMM" << endl;
  else if(!yymm && mmyy) cout << "MMYY" << endl;
  else cout << "NA" << endl;
  
  return 0;
}


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

int main () {
  int N;
  cin >> N;
  string ans = "Three";
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if ( S == "Y" ) {
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
//Algorithm Visualizer
#include<bits/stdc++.h>
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first;
#define S second;
using namespace std;
typedef long long ll;

int fun(int i,int n,int l_c,unsigned short int a[][3],long dp[][3])
{
    if(i>=n) return 0;
    int x,y;
    if(l_c==0){
        x=1;
        y=2;
    }
    else if(l_c==1){
        x=0;
        y=2;
    }
    else{
        x=0,y=1;
    }
    if(i==n-1){
        return max(a[n-1][x],a[n-1][y]);
    }
    if(dp[i][l_c]!=-1){
        return dp[i][l_c];
    }
    return dp[i][l_c]=max(a[i][x]+fun(i+1,n,x,a,dp),a[i][y]+fun(i+1,n,y,a,dp));
}
void solve()
{
    int n;
    cin>>n;
    unsigned short int a[100000][3];
    long dp[100000][3];
    for(int i=0; i<n; i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        dp[i][0]=dp[i][1]=dp[i][2]=-1;
    }
    ll ans=max(a[0][0]+fun(1,n,0,a,dp),max(a[0][1]+fun(1,n,1,a,dp),a[0][2]+fun(1,n,2,a,dp)));
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int t,c=0;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
}


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

int main(){
  int N;
  cin>>N;
  string S;
  map <string,int> mp;
  long long ans=0;
  for (int i=0;i<N;i++){
    cin>>S;
    sort(S.begin(),S.end());
    if(mp.count(S)==0) mp[S]++;
    else {
      ans=ans+mp[S];
      mp[S]++;
    }
    
  }
  cout<<ans<<endl;
  return 0;
}

    
 

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
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;
}
ll mm[200010] = { 1,1 };
ll pow_mod(ll a, ll b) {
	if (b == 0) { return 1; }
	if (b == 1) { return a % mod; }
	ll r = pow_mod(a, b / 2);
	r *= r;
	r %= mod;
	if (b % 2 == 0) {
		return r;
	}
	return (r * a) % mod;
}
ll nCm(ll n, ll m) {
	ll res = mm[n];
	res *= pow_mod(mm[m], mod - 2);
	res %= mod;
	res *= pow_mod(mm[n - m], mod - 2);
	res %= mod;
	return res;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	string s;
	cin >> s;
	for (int i = 0; i < 12; i++) {
		if (i == 4)cout << " ";
		cout << s[i];
	}
	cout << endl;
}

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

int getHead(int);
int getTail(int);

int memo[10][10];

signed main() {
  int n;
  scanf("%d",&n);
  REPS(i,1,n+1) {
    ++memo[getHead(i)][getTail(i)];
  }
  ll ans = 0;
  REPS(i,1,10) REPS(j,1,10) ans += memo[i][j] * memo[j][i];
  cout << ans;
  cout << "\n";
  return 0;
}

int getHead(int a) {
  string s = to_string(a);
  return (int) s[0] - '0';
}
int getTail(int a) {
  string s = to_string(a);
  return (int) s[s.length()-1] - '0';
}


Measured memory_bytes: 256
N=int(input())
que=[[i for i in range(N)]]

ans={(i,j):-1 for i in range(N) for j in range(N)}

def classified(session):
    global que
    sub=[]
    while que:
        list=que.pop()
        n=len(list)
        if n!=1:
            left=list[:n//2]
            right=list[n//2:]
            for i in left:
                for j in right:
                    ans[(i,j)]=session
            sub.append(left)
            sub.append(right)
    que=sub

session=1
while que:
    classified(session)
    session+=1



Ans=[[] for i in range(N-1)]
for i in range(N-1):
    for j in range(i+1,N):
        Ans[i].append(ans[(i,j)])

for i in range(N-1):
    print(*Ans[i])

Measured memory_bytes: 72828
#include "cstdio"
#include "cstring"
#include"algorithm"
using namespace std;
long long gcd(long long a,long long b)
{
	if(a<b)return gcd(b,a);
	if(b==0)return a;
	return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
	return a*b/gcd(a,b);
}
int main()
{
    //freopen("input.txt","r",stdin);
   	long long a,b;
   	while(scanf("%lld%lld",&a,&b)!=EOF)
   	{	
   		printf("%lld %lld\n",gcd(a,b),lcm(a,b));
   	}

    return 0;
};

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		String h = sc.next();
		char c = h.charAt(0);
		int a = (int)c+1;
		System.out.println((char)a);
	}
	
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

const ll MOD = 1000000007;
const ll MOD_2 = 998244353;

ll modpow (ll radix,ll index){
    if(index == 0)return 1;
    if(index == 1)return radix%MOD;
    ll c;
    c = modpow(radix,index/2);
    c = c * c % MOD;
    if(index % 2){
        return c * radix % MOD;
    }else{
        return c;
    }
}

int main(){
    ll N,ans=0;
    cin >> N;
    vector<ll>A(N);
    vector<ll>B(N);
    REP(i,N){
        cin>>A[i];
        (ans+=modpow(A[i],MOD-2))%=MOD;
    }
    for(int i = 2; i*i <= 1e6;i++){
        int cnt = 0;
        for(int j=0;j<N;j++){
            int now=0;
            while(A[j]%i==0){
                now++;
                A[j]/=i;
            }
            if(cnt < now)cnt = now;
        }
        (ans*=modpow(i,cnt))%=MOD;
    }
    REP(i,N){
        if(A[i]>1){
            REP2(j,i+1,N){
                if(A[i]==A[j])A[j]=1;
            }
            (ans*=A[i])%=MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

l = [INT() for _ in range(5)]
m = 0
n = [0]

for i in range(5):
	m += -(-l[i]//10)
	if l[i]%10 != 0:
		n.append(10-l[i]%10)

print(10*m - max(n))

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

int main() {
    ll h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    bool f = 1;
    rep(i, n) {
        sum += a[i];
        if(h <= sum) {
            cout << "Yes" << endl;
            f = 0;
            break;
        }
    }
    if(f == 1) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3764
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();

        boolean isEven = n % 2 == 0;

        int[] aArr = new int[n];
        int[] bArr = new int[n];

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            aArr[i] = a;
            bArr[i] = b;
        }

        Arrays.sort(aArr);
        Arrays.sort(bArr);
        debug(aArr);
        int ans;
        double min, max;
        n = n - 1;
        if (isEven) {
            min = (aArr[n / 2] + aArr[(n / 2) + 1]) / (double) 2;
            max = (bArr[n / 2] + bArr[(n / 2) + 1]) / (double) 2;
            ans = (int) ((max - min) * 2) + 1;
        } else {
            min = aArr[n / 2];
            max = bArr[n / 2];
            ans = (int) (max - min) + 1;
        }
        System.out.println(ans);

        // out.println("Hello World");
        out.flush();
    }

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

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


Measured memory_bytes: 66068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n-1; i >= 0; i--)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd2(i, s, n) for (ll i = n-1; i >= (s); i--)

int main() {
    ll n, d;
    cin >> n >> d;
    ll ans = 0;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if (x*x+y*y<=d*d){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N;
vector<pair<ll, ll>> xy;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  xy.resize(N);
  for (int i = 0; i < N; i++) {
    ll xi, yi;
    cin >> xi >> yi;
    xy[i] = make_pair(xi, yi);
  }
  sort(xy.begin(), xy.end());

  map<pair<ll, ll>, ll> mp;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ll dx = xy[j].first - xy[i].first;
      ll dy = xy[j].second - xy[i].second;
      mp[make_pair(dx, dy)]++;
    }
  }

  ll m = 0;
  for (auto &e : mp) {
    m = max(m, e.second);
  }
  cout << N - m << endl;
  return 0;
}

Measured memory_bytes: 384
from collections import deque

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)
c = list(map(int, input().split()))
c.sort()
m = sum(c[:-1])
ans = [-1] * n

q = deque([(0, -1)])
while q:
    v, pv = q.popleft()
    ans[v] = c.pop()
    for nv in g[v]:
        if nv == pv: continue
        q.append((nv, v))

print(m)
print(*ans)


Measured memory_bytes: 6304
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    n,m = inputMap()
    
    print((n-1) * (m-1))
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, k, q, ans[110000];
int main() {
	cin >> n >> k >> q;
	REP(i, q) {
		ll a;
		cin >> a;
		a--;
		ans[a]++;
	}
	REP(i, n) {
		ll now = k - q + ans[i];
		if (now > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}




Measured memory_bytes: 1408
fn read<T: std::str::FromStr>() -> T
{
    std::io::Read::bytes(std::io::stdin())
                    .map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>()
                    .parse().ok().unwrap()
}

fn main() {
    let n: String = read();

    let mut ans: i32 = n.chars().map(|c| c.to_string().parse::<i32>().ok().unwrap()).sum();

    if ans == 1 {
        ans = 10;
    }

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


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
int f1[N], f2[N];

int find(int f[], int x) {
  if (f[x] != f[f[x]]) f[x] = find(f, f[x]);
  return f[x];
}

int main() {
  int n, m1, m2;
  scanf("%d%d%d", &n, &m1, &m2);
  for (int i = 0; i < n; ++i) {
    f1[i] = f2[i] = i;
  }
  while (m1--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    int rx = find(f1, x), ry = find(f1, y);
    if (rx != ry) {
      f1[ry] = rx;
    }
  }
  while (m2--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    int rx = find(f2, x), ry = find(f2, y);
    if (rx != ry) {
      f2[ry] = rx;
    }
  }
  map<ii, int> A;
  for (int i = 0; i < n; ++i) {
    int r1 = find(f1, i), r2 = find(f2, i);
    A[{r1, r2}]++;
  }
  for (int i = 0; i < n; ++i) {
    int r1 = find(f1, i), r2 = find(f2, i);
    printf("%d%c", A[{r1, r2}], " \n"[i + 1 == n]);
  }

  return 0;
}


Measured memory_bytes: 13568
def gcd(a,b):
  while b:
    a,b = b,a%b
  return a

n,s = map(int,input().split())
x = list(map(int,input().split()))

g = abs(x[0]-s)

for i in range(n):
  g = gcd(g,abs(x[i]-s))

print(g)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
 using namespace std;
 #define REP(i, a, n) for(int i=a; i<n; i++) //(i, 0, n)でi=0~n-1までn回
 #define sortv(v) sort(v.begin(), v.end());
 #define sortg(v) sort(v.begin(), v.end(), greater<>());
 #define rev(v) reverse(v.begin(), v.end());
 
 int main() {
   int n, m, a=0, b=100000;
   cin >> n >> m;
   REP(i, 0, m){
     int l, r;
     cin >> l >> r;
     if(l>a)a=l;
     if(r<b)b=r;
   }
   if((b-a+1)>0){
     cout << b-a+1 << endl;
   }else{
     cout << '0' << endl;
   }
 }


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

int t[110];	
vector<int> a[110];

void deep(int n,int time) {
	time++;
	for (int i = 0; i < a[n].size(); i++) {
		if (t[a[n][i]] >time) {
			t[a[n][i]] = time;
			deep(a[n][i],time);
		}
		else if (t[a[n][i]] == -1) {
			t[a[n][i]] = time;
			deep(a[n][i], time);
		}
	}
}


int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	int N; cin >> N;
	int u, k, v;
	fill(t, t + 110, -1);
	t[1] = 0;
	for (int i = 0; i < N; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			a[u].push_back(v);
		}
	}
	deep(1, 0);
	for (int i = 1; i <= N; i++) {
		cout << i << " " << t[i] << endl;
	}
}


Measured memory_bytes: 3160
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair



int main(){
  SCIN(s);
  CIN(x,y);
  
  int n = s.size();
  int sx=n;
  REP(i,n)
    if(s[i]=='T'){
      sx=i;break;
    }

  V vx,vy;
  bool xf=false;
  vy.pb(0);
  FOR(i,sx+1,n){
    if(s[i]=='T'){
      xf^=1;
      (xf?vx:vy).pb(0);
    }
    else (xf?vx:vy).back()++;
  }
  (xf?vx:vy).pb(0);

  bitset<20000> bx,by;
  bx[10000+sx]=1;
  by[10000]=1;
  FOREACH(xx,vx)
    bx=(bx<<xx)|(bx>>xx);
  FOREACH(xx,vy)
    by=(by<<xx)|(by>>xx);
  
  Yes(bx[x+10000]&&by[y+10000]);
  

  return 0;
}

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

int main() 
{ 
    
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> cost(n);
    vector<int> ans(n,INT_MAX);
    ans[0] = 0;
    for(int i=0;i<n;i++){cin>>cost[i];}
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j>=n){continue;}
            ans[j] = min(ans[j],ans[i]+abs(cost[i]-cost[j]));
        }
    }
    
    cout<<ans[n-1];
      
    return 0; 
} 

Measured memory_bytes: 4032
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
    see=a[i-1]
    for j in range(s+1):
        dp[i][j]=dp[i-1][j]*2
        dp[i][j]%=mod
        if see>j:
            continue
        dp[i][j]+=dp[i-1][j-see]
        dp[i][j]%=mod

print(dp[-1][-1])


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

#define int long long

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

char X, Y;

signed main() {
    cin >> X >> Y;
    if (X > Y) {
        cout << ">" << endl;
    } else if (X < Y) {
        cout << "<" << endl;
    } else {
        cout << "=" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 12 5 2
# cabbabaacaba

# 10 2 3
# abccabaabb
# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
yn = lambda b: print('Yes') if b else print('No')
####################################################################

N,A,B = map(int, input().split())
S = input()

a = b = 0

for s in S:
  p("   ",A,B,A+B,"_",s, a,b, a+b)
  if s == 'a':
    if (a+b) < (A+B):
      yn(True)
      a += 1
    else:
      yn(False)
  elif s == 'b':
    if ((a+b) < (A+B)) and (b < B):
      yn(True)
      b += 1
    else:
      yn(False)
  elif s == 'c':
    yn(False)



Measured memory_bytes: 9392
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>
#include<cstdio>
#include<iomanip>

int main(int argc, char *argv[])
{
	int k,n;

	cin>>k>>n;

	int s,a,b,t;
	cin>>a>>b;
	s=a;
	int d=b-a;
	//cerr<<d<<endl;
	for (int i=0;i<n-2;i++)
	{
		a=b;
		cin>>b;
		t=b-a;
		//cerr<<t<<endl;
		if (t>d) d=t;
	}
	t=s+k-b;
	//cerr<<t<<endl;
	if (t>d) d=t;

	cout<<(k-d)<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((d+s-1)/s <= t ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;


int main(void) {
    long n;
    cin >> n;

    vector<long> a(n), b(n);
    for(int i=0; i<n; i++)
        cin >> a[i] >> b[i];

    long m = 1e9;
    for(int i=0; i<n; i++)
        if(a[i]-b[i] > 0 && m > b[i]) m = b[i];

    if(m == 1e9) {
        cout << 0 << endl;
        return 0;
    }

    long r = 0;
    for(int i=0; i<n; i++)
        r += a[i];
    r -= m;
    cout << r << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
using namespace std;

int main(){
	int N;
	cin>>N;
	string keitai[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	while(N--){
		string s;
		cin>>s;

		string ans="";
		int b=0,c=0;
		REP(i,0,(int)s.size()){
			if(s[i]=='0'){
				if(b!=0){
					int num=(c+keitai[b].size()-1)%keitai[b].size();
					ans.push_back(keitai[b][num]);
					b=0,c=0;
				}
			}
			else{
				b=s[i]-'0';
				c++;
			}
		}
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define oo 2000000000
#define mod 998244353 
const int N = 200010;
int n , arr[N];

vector< pair<int,int> > v;

int main(){
    scanf("%d",&n);
    for(int i = 0 ;i < n;i++){
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    for(int i = 1;i < n - 1;i++){
        if(arr[i] > 0){
            v.push_back(make_pair(arr[0] , arr[i]));
            arr[0] = arr[0] - arr[i];
        }
        else{
            v.push_back(make_pair(arr[n - 1] , arr[i]));
            arr[n - 1] = arr[n - 1] - arr[i];
        }
    }
    v.push_back(make_pair(arr[n - 1] , arr[0]));
    int cur = arr[n - 1] - arr[0];
    cout << cur << endl;
    for(int i = 0 ;i < (int)v.size();i++){
        printf("%d %d\n",v[i].first,v[i].second);
    }
    return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	cout << (X - A) % B << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	int w, h;
	int[][] map;
	
	public void func(){
		int count = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==1){
					loop(i, j);
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	public void loop(int y, int x){
		map[y][x]--;
		
		if(x!=0 && map[y][x-1]==1)loop(y, x-1);
		if(x!=w-1 && map[y][x+1]==1)loop(y, x+1);
		if(y!=0 && map[y-1][x]==1)loop(y-1, x);
		if(y!=h-1 && map[y+1][x]==1)loop(y+1, x);
		
		if(x!=0 && y!=0 && map[y-1][x-1]==1)loop(y-1, x-1);
		if(x!=w-1 && y!=h-1 && map[y+1][x+1]==1)loop(y+1, x+1);
		if(y!=0 && x!=w-1 && map[y-1][x+1]==1)loop(y-1, x+1);
		if(y!=h-1 && x!=0 && map[y+1][x-1]==1)loop(y+1, x-1);		
	}
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main A = new Main();
		
		while(true){
			A.w = sc.nextInt();
			A.h = sc.nextInt();
			if(A.w==0 && A.h==0)break;
			A.map = new int[A.h][A.w];
			
			for(int i=0;i<A.h;i++){
				for(int j=0;j<A.w;j++){
					A.map[i][j] = sc.nextInt();
				}
			}
			A.func();
			
		}
	
	}	
}

Measured memory_bytes: 43104
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;
typedef long long LL;

const int N = 2e5 + 10;

LL a[N];

int main()
{
	LL n , t , sum = 0;
	scanf("%lld %lld",&n , &t);
	for(LL i = 1 ; i <= n ; i++) scanf("%lld",&a[i]);
	for(LL i = 1 ; i <= n ; i++){
		LL s = a[i];
		LL tmp = a[i] + t;
		while(tmp > a[i + 1] && i + 1 <= n) i++ , tmp = a[i] + t;
		sum += (tmp - s); 
	}
	printf("%lld\n",sum);
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int l,r;
    int ans_l = 1, ans_r = N;
    vector<int> counter(N, 0);
    for(int i=0;i<M;i++){
        cin >> l >> r;
        if(ans_l < l){
            ans_l = l;
        }
        if(r < ans_r){
            ans_r = r;
        }
        if(ans_l > ans_r){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans_r - ans_l + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 222222
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
int bef[MAXNUM],nowk[MAXNUM],isused[MAXNUM];
vector<int> e[MAXNUM];
int st,stlen,n;
int cal(int now,int x)
{
    if(now==n&&x==1)return 2;
    else if(x<=now+1)return 1;
    else return 0;
}
void dfs(int now,int k)
{
    if(isused[now])
    {
        stlen=k-nowk[now];
        st=now;
        return;
    }
    isused[now]=1,nowk[now]=k;
    for(int x:e[now])
        dfs(x,k+cal(now,x));
}
int num[MAXNUM],snex[MAXNUM],isok[MAXNUM],sta[MAXNUM],top;
int main()
{
    ll k;
    scanf("%d%lld",&n,&k);
    rep(i,1,n+1)scanf("%d",&num[i]);
    for(int i=n;i;i--)bef[num[i]]=i;
    for(int i=n;i;i--)
    {
        e[i].push_back(bef[num[i]]%n+1);
        snex[i]=bef[num[i]]%n+1;
        bef[num[i]]=i;
    }
    dfs(1,1);
    ll now=nowk[st],nowpos;
    if(now>k)now=1,nowpos=1;
    else{
        ll nowlen=k-now;
        nowlen/=stlen;
        now=now+nowlen*stlen;nowpos=st;
    }
    while(1)
    {
        now+=cal(nowpos,snex[nowpos]);
        if(now>k){now-=cal(nowpos,snex[nowpos]);break;}
        nowpos=snex[nowpos];
    }
    for(;now<=k;now++,nowpos=1)
        for(int i=nowpos;i<=n;i++)
        {
            if(!isok[num[i]])sta[top++]=num[i],isok[num[i]]=1;
            else{
                while(isok[num[i]])isok[sta[top-1]]=0,top--;
            }
        }
    rep(i,0,top)printf("%d ",sta[i]);
}

Measured memory_bytes: 28032
n = gets.to_i

m = {}
n.times do
  s = gets.chomp.split('').sort.join
  if m.include?(s)
    m[s] += 1
  else
    m[s] = 1
  end
end

count = 0
m.each do |key, value|
  count += value * (value - 1) / 2
end

puts count

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

int main(){
    int n, in;
    int loop = 0;
    std::cin >> n;
    std::vector<int> v;
    for (int i = 1;i <= n; i++){
        std::cin >> in;
        v.push_back(in);
    }
    bool flag = true;
    do{
        for (int i = 0;i <= n-1; i++){
            if(v[i] % 2 == 1){
                flag = false;
            }
        }
        if(flag == true){
            loop = loop + 1;
            for (int i = 0;i <= n-1; i++){
                v[i] = v[i] / 2;
            }
        }
    } while(flag == true);
    std::cout << loop << std::endl;
    return 0;
}

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

using namespace std;

int main() {
    int a, b, res;

    cin >> a >> b;

    res = 1;

    if (a < 0 && b < 0) {
        if ((b - a) % 2 == 0) {
            res = -1;
        }
    }

    if (a <= 0 && b >= 0) {
        res = 0;
    }

    if (res == 1) {
        cout << "Positive" << endl;
    }

    if (res == 0) {
        cout << "Zero" << endl;
    }

    if (res == -1) {
        cout << "Negative" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	var S string

	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)
	sR := []rune(S)

	for i := 0; i < len(S); i++ {
		i2 := int(sR[i]) - int('A')
		i3 := (i2 + N) % 26
		fmt.Printf("%s", string('A'+i3))
	}

	fmt.Println()
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

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

  int n; cin >> n;
  int g=0,k=0;
  rep(i,n){
    ll a; cin >> a;
    if(a%2==0) g++;
    else k++;
  }

  if(k%2==0) cout << "YES" << endl;
  else cout << "NO" << endl;


  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int a[MAXN],b[MAXN],a1[MAXN],b1[MAXN];
int ans,n,sum;
int main(){
    SF("%d",&n);
    for(int i=0;i<n;i++)
        SF("%d",&a[i]);
    for(int i=0;i<n;i++)
        SF("%d",&b[i]);
    for(int i=0;i<29;i++){
        for(int j=0;j<n;j++){
            a1[j]=a[j]%(1<<(i+1));
            b1[j]=b[j]%(1<<(i+1));
        }
        sort(b1,b1+n);
        sum=0;
        for(int j=0;j<n;j++){
            int s1=lower_bound(b1,b1+n,(1<<i)-a1[j])-b1;
            int t1=lower_bound(b1,b1+n,2*(1<<i)-a1[j])-b1;
            int s2=lower_bound(b1,b1+n,3*(1<<i)-a1[j])-b1;
            int t2=lower_bound(b1,b1+n,4*(1<<i)-a1[j])-b1;
            sum+=(t1-s1)+(t2-s2);
        }
        if(sum&1)
            ans+=(1<<i);
    }
    PF("%d",ans);
}

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

using namespace std;

int main() {
	vector<vector<int>> data(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> data.at(i).at(j);
		}
	}
	int N;
	cin >> N;
	int b = 0;

	for (int k = 0; k < N; k++) {
		cin >> b;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (data.at(i).at(j) == b) {
					data.at(i).at(j) = -1;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		if (data.at(i).at(0) < 0 && data.at(i).at(1) < 0 && data.at(i).at(2) < 0) {
			cout << "Yes";
			return 0;
		}
	}
	for (int j = 0; j < 3; j++) {
		if (data.at(0).at(j) < 0 && data.at(1).at(j) < 0 && data.at(2).at(j) < 0) {
			cout << "Yes";
			return 0;
		}
	}
	if (data.at(0).at(0) < 0 && data.at(1).at(1) < 0 && data.at(2).at(2) < 0)cout << "Yes";
	else if (data.at(2).at(0) < 0 && data.at(1).at(1) < 0&& data.at(0).at(2) < 0)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
#define PI 3.14159265359
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
signed main() {
	int a;
	string s;
	cin >> a >> s;
	if (s.size() <= a)cout << s << endl;
	else cout << s.substr(0, a) << "..." << endl;
}

Measured memory_bytes: 3604
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.List             (group)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn
  ps <- map readInt . BS.words <$> BS.getLine
  print $ solve n ps

solve :: Int -> [Int] -> Int
solve n = sum . map count . group . zipWith (==) [1 .. n]

count :: [Bool] -> Int
count xs
  | head xs   = (length xs + 1) `div` 2
  | otherwise = 0

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


Measured memory_bytes: 4604
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = 1
for i in a:
    if i%2==0:
        res *= 2
print(3**n - res)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - (ll)inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = (ll)fac[i-1] * i % MOD;
		finv[i] = (ll)finv[i-1] * inv[i] % MOD;
	}
}

int comb(int a,int b)
{
	if(a<b){
		return 0;
	}
	return fac[a] * ((ll)finv[b] * finv[a-b] % MOD) % MOD;
}

inline int add(int x,int y)
{
    return (x+y)%MOD;
}

inline int sub(int x,int y)
{
    return (x+MOD-y)%MOD;
}

inline int mul(int x,int y)
{
    return (ll)x*y%MOD;
}

int a[MAX_N];
int val[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    make();
    rep(i,n){
        val[i+1] = add(val[i], inv[i+1]);
    }
    int ans = 0;
    rep(i,n){
        ans = add(ans, mul(a[i], sub(add(val[n-i], val[i+1]),1)));
    }
    cout << mul(ans, fac[n]) << "\n";
    return 0;
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int n, k;
    cin >> n >> k;
    
    int ans = 0;
    rep(i,n){
        int x; cin >> x;
        ans += min(2 * abs(x), 2 * abs(x-k));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstring>
#include <cstdio>
#include <cstring>
using namespace std;

int list[100];

int main(void){
	int a, b;
	bool flag = false;
	while(scanf("%d %d", &a, &b) != EOF){
		memset(list, 0, 100);
		list[a-1]++;
		list[b-1]++;
		while(true){
			scanf("%d %d", &a, &b);
			if(!a && !b)	break;
			list[a-1]++;
			list[b-1]++;
		}
		flag = false;
		if(!(list[0] & 1) || !(list[1] & 1))	flag = true;
		for(int i = 2; i < 100; i++){
			if(list[i] & 1)	flag = true;
		}
		if(!flag) printf("OK\n");
		else printf("NG\n");
	}
  return 0;
}

Measured memory_bytes: 1012