akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

struct Node {
public:
    vector<int> to;
};

int main() {
    int N; cin >> N;
    vector<set<int>> vs(N);
    vector<int> rank(N);
    vector<vi> edges(N - 1);
    vector<Node> vec(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b;
        --a; --b;
        rank[a]++; vec[a].to.push_back(b);
        rank[b]++; vec[b].to.push_back(a);
        edges[i] = { a,b };
    }
    vector<int> c(N); rep(i, N) cin >> c[i];
    sort(ALL(c));

    for (int r = 0; r < N; r++) {
        int rk = rank[r];
        vs[rk].insert(r);
    }
    int ind = 0;
    vector<int> ans(N);

    while (!vs[1].empty()) {
        int u = *vs[1].begin();
        ans[u] = c[ind];
        ind++;
        // cとそれにadjacentなNodeのrankを一つずつ下げて回る
        vs[1].erase(u);
        rank[u] = 0;
        for (int i = 0; i < vec[u].to.size(); i++) {
            int v = vec[u].to[i];
            vs[rank[v]].erase(v);
            if (rank[v] > 0) {
                rank[v]--;
                vs[rank[v]].insert(v);
            }
        }
    }
    while (!vs[0].empty()) {
        int u = *vs[0].begin();
        ans[u] = c[ind];
        ind++;
        // cとそれにadjacentなNodeのrankを一つずつ下げて回る
        vs[0].erase(vs[0].begin());
    }
    ll score = 0;
    for (auto e : edges) {
        score += min(ans[e[0]], ans[e[1]]);
    }
    cout << score << endl;
    for (auto& a : ans) {
        cout << a << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5336
# -*- coding: utf-8 -*-

from collections import defaultdict, Counter
from string import ascii_lowercase as abc
def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)

R = [0]*N
L = [0]*N
R[0] = 1
L[-1] = 1

for i in range(1, N):
    x = S[i] == "L"
    L[i] = L[i-1]*x + x

for i in range(N-2, -1, -1):
    x = S[i] == "R"
    R[i] = R[i+1]*x + x

ans = [0]*N
for i in range(N):
    if S[i] == "R":
        ans[i+R[i]-R[i]%2] += 1
    else:
        ans[i-L[i]+L[i]%2] += 1

print(*ans)

Measured memory_bytes: 11636
program main
    implicit none
    integer i,n,c
    character s*200000, t*200000
    read(*,*) s
    read(*,*) t
    n = len_trim(s)
    c = 0
    do i = 1,n
        if(s(i:i) /= t(i:i)) then
            c = c + 1
        end if
    end do
    write(*,*) c

end program


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

int main(){
    int a,b;
    cin>>a>>b;
    int c=0;
    for (int i = 0; i < b - a-1; ++i) {
        c+=i+1;
    }
    cout<<c-a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

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

signed main(void) {
    int i,j;
    int h,w;
    cin >> h >> w;
    vs s(h);
    rep(i,h)cin >> s[i];
    vector<vi> g(h*w);
    rep(i,h)rep(j,w){
        rep(k,4){
            int nx = i + dx[k];
            int ny = j + dy[k];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
            if(s[i][j] == s[nx][ny])continue;
            g[i*w+j].push_back(nx*w+ny);
        }
    }
    /*
    rep(i,h*w){
        cout << i << endl;
        rep(j,g[i].size())cout << " " << g[i][j];cout << endl;
    }
    */
    vi used(h*w);
    int ans = 0;
    rep(i,h)rep(j,w)if(g[i*w+j].size() && s[i][j] == '#'){
        if(used[i*w+j] == 0){
            int white = 0;
            int black = 0;
            queue<int> q;
            q.push(i*w+j);
            used[i*w+j]++;
            while(q.size()){
                int now = q.front();
                q.pop();
                int x = now/w;
                int y = now%w;
                if(s[x][y] == '#')black++;
                else white++;
                rep(p,g[now].size()){
                    int ne = g[now][p];
                    if(used[ne])continue;
                    used[ne]++;
                    q.push(ne);
                }
            }
            //cout << i << " " << j << " " << white << " " << black << endl;
            ans += white * black;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 12928
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize, m: usize, x: usize,
        ca: [[usize; m + 1]; n],
    }
    let mut ans = 1 << 30;
    for i in 0..1 << n {
        let mut xs = vec![0; m];
        let mut cs = 0;
        for j in 0..n {
            if (i >> j) & 1 == 0 {
                continue;
            }
            cs += ca[j][0];
            for k in 0..m {
                xs[k] += ca[j][k + 1];
            }
        }
        if xs.iter().filter(|&&v| v >= x).count() == m {
            ans = min(ans, cs);
        }
    }
    println!("{}", if ans < 1 << 30 { ans as isize } else { -1 });
}


Measured memory_bytes: 2168
#include<iostream>
#include<vector>
typedef unsigned long long ull;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF

ull ABS(ull a,ull b)
{
  return a>b?a-b:b-a;
}

int main()
{
  ull i,N;
  cin >> N;
  vector<ull> h(N),dp(N);
  for(i=0;i<N;++i)
  {
    cin >> h[i];
    dp[i]=INF;
  }
  dp[0]=0;
  for(i=0;i+2<N;++i)
  {
    dp[i+1]=min(dp[i+1],dp[i]+ABS(h[i],h[i+1]));
    dp[i+2]=min(dp[i+2],dp[i]+ABS(h[i],h[i+2]));
  }
  dp[N-1]=min(dp[N-1],dp[N-2]+ABS(h[N-2],h[N-1]));
  cout << dp[N-1];
  return 0;
}

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

int main(){
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	printf("%lf\n",d);

	return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
	/*int t; cin>>t;

	while(t--)
	{
		int c=0, st=105, end;
		string s; cin>>s; int n=s.size();
		for(int i=0; i<n; ++i)
		{
					if(s[i]=='1') {st=i; break;}
	    }
		for(int j=n-1; j>=0; --j)
		{
					if(s[j]=='1') {end=j; break;}
		}
		for(int x=st; x<=end; ++x)
		{
			if(s[x]=='0') c++;

		}
		cout<<c<<endl;
	}
*/

	//nastya and rice

	string s; cin>>s; long long int sum=0;

	for(int i=0; i<s.size(); ++i)
	{
		sum+=s[i]-'0';
	}
	if(sum%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;

}



Measured memory_bytes: 3736
while True:
    H,W = map(int,input().split())

    if H == 0 and W == 0:
        break

    else:
        
        h = 0
        while h < H:
            if h%2 == 0:
                if W%2 == 0:
                    print("#."*(W//2))
                else:
                    print("#."*(W//2)+"#")

            else:
                if W%2 == 0:
                    print(".#"*(W//2))
                else:
                    print(".#"*(W//2)+".")

            h += 1
                
    print("")



Measured memory_bytes: 5608
#include <stdio.h>

int gcd(int,int);

int main(){

  int x,y,d;
  
  scanf("%d %d",&x,&y);

  d=gcd(x,y);
  
  printf("%d\n",d);

  return 0;
}

int gcd(int x,int y){
  int d;

  if(x>=y){
    d=x%y;
    if(d==0) return y;
    gcd(y,d);
    return ;   
  }
  else {
    d=y%x;
    if(d==0) return x;
    gcd(x,d);
    return ;

  }
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    for (int i = 0; i < S.size(); i++) {
        if (S[i]+N > 'Z')
            S[i] = 'a'+(N-('z'-S[i])-1);
        else
            S[i] = S[i]+N;
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	ll N, A, B;
	cin >> N >> A >> B;
	ll syou = N/(A+B);
	ll amari = N-syou*(A+B);
	ll ans;
	if(A==0) ans = 0;
	else if(amari>A) ans  = syou*A + A;
	else ans  = syou*A + amari;
	cout << ans << endl;
	return 0;
}


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

int func(int arr[][3], int n){
  int dp[n][3], maxval, i;
  dp[0][0]=arr[0][0], dp[0][1]=arr[0][1], dp[0][2]=arr[0][2];
  for(i=1; i<n; i++){
	dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][0]);
  }
  maxval = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  return maxval;
}

int main(){
  int n, i, j;
  cin>>n;
  int arr[n][3];
  for(i=0; i<n; i++){
    for(j=0; j<3; j++){
      cin>>arr[i][j];
    }
  }
  int val = func(arr, n);
  cout<<val;
  return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-6
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,m,a[N],len[N],f[N];
vi opens[N],closes[N];
multiset<int> curr;

ll solve(int x){
    ll ret = 0;
    lp(i,2,n){
        if(a[i] >= a[i-1]){
            if(x > a[i-1] and x <= a[i]) ret += 1 + a[i] - x;
            else ret += a[i] - a[i-1];
        }
        else{
            if(x > a[i-1]) ret += 1 + m - x + a[i];
            else if(x <= a[i]) ret += 1 + a[i] - x;
            else ret += m - a[i-1] + a[i];
        }
    }
    return ret;
}

int main(){
    read2i(n,m);
    lp(i,1,n){
        readi(a[i]);
        if(i > 1){
            len[i-1] = a[i] > a[i-1] ? a[i] - a[i-1] : m - a[i-1] + a[i];
            opens[a[i-1]].pb(i-1);
            closes[a[i]].pb(i-1);
            if(a[i-1] < a[i] and a[i-1] == 1) curr.insert(i-1), ++f[a[i-1]];
            if(a[i-1] > a[i] and a[i] >= 1) curr.insert(i-1), ++f[a[i-1]];
        }
    }

    ll ans = solve(1);
    ll best = ans;
    lp(i,2,m){
        for(int j : closes[i-1]) ans += len[j] - 1, curr.erase(curr.find(j)), --f[a[j]];
        ans -= sz(curr) - f[i-1];
        for(int j : opens[i]) curr.insert(j), ++f[a[j]];
        best = min(best, ans);
        //cout <<ans <<" " <<solve(i) <<endl ;
    }
    cout <<best;
}

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 15488
import sys
input=sys.stdin.readline
x,y=map(int,input().split())
INF=10**9+7
def modcomb(n,k,m):
    fac=[0]*(n+1)
    finv=[0]*(n+1)
    inv=[0]*(n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,n+1):
        fac[i]=fac[i-1]*i%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m
if (-x+2*y)%3==0 and (2*x-y)%3==0 and -x+2*y>=0 and 2*x-y>=0:
    a=(-x+2*y)//3
    b=(2*x-y)//3
    ans=modcomb(a+b,a,INF)
    print(ans)
else:
    print(0)


    



Measured memory_bytes: 54384
using System;

public class Security
{
    public static void Main(string[] args)
    {
        int S = Int32.Parse(Console.ReadLine());
        int[] digits = new int[4];
        digits[0] = S % 10;
        digits[1] = S % 100 / 10;
        digits[2] = S % 1000 / 100;
        digits[3] = S / 1000;
        int tmp = digits[0];
        for (int i = 1; i < 4; i++)
        {
            if (tmp == digits[i])
            {
                Console.WriteLine("Bad");
                return;
            }
            tmp = digits[i];
        }
        Console.WriteLine("Good");
    }
}

Measured memory_bytes: 13140
w,h,n=map(int,input().split());b=d=0
for _ in[0]*n:
    x,y,a=map(int,input().split())
    if a<2:b=max(x,b)
    elif a<3:w=min(x,w)
    elif a<4:d=max(y,d)
    else:h=min(h,y)
print([(w-b)*(h-d),0][(w<b)|(h<d)])

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
	int a, b, c, k;
	scanf("%d %d %d %d", &a, &b, &c, &k);
	if (k <= a)
	{
		printf("%d\n", k);
		return 0;
	}
	else
	{
		if (k - a <= b)
		{
			printf("%d\n", a);
			return 0;
		}
		else
		{
			printf("%d\n", 2 * a - k + b);
			return 0;

				
		}
	}

	return 0;
}

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

int main(){
    int k; 
    string s;
    
    cin >> k >> s;
    
    if(s.size()>k){
        for(int i = 0; i < k; i++){
            cout << s[i];
        }
        cout<<"...\n";
    }else{
        cout << s <<"\n";
    }


}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

void Funca() {
	int a, b, x;
	std::cin >> a >> b >> x;
	if (a <= x && a + b >= x) {
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;

	}
}

void Funcb() {
	int n, m, x;
	int cost0 = 0;
	int cost1 = 0;
	std::map<int, int> mp;
	std::vector<int> vec;
	std::cin >> n >> m >> x;
	for (int i = 0; i < m; ++i) {
		int t;
		std::cin >> t;
		vec.push_back(t);
	}
	for (auto it : vec) {
		if (0 < it&&it < x) {
			++cost0;
		}
		else {
			++cost1;
		}
	}
	std::cout << std::min(cost0, cost1) << std::endl;

}
int main()
{
	int n;
	std::map<int, int> mp;
	std::vector<int> vec;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int t;
		std::cin >> t;
		vec.push_back(t);
		mp.insert(std::make_pair(i, t));
	}
	int anum = n / 2;
	std::sort(vec.begin(), vec.end(), [](int i, int j) {return i < j; });
	for (int i = 0; i < n; ++i) {
		if (mp[i] < vec[anum]) {
			std::cout << vec[anum] << std::endl;
		}
		else
		{
			std::cout << vec[anum-1] << std::endl;

		}
	}
	return 0;
}

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

#define i64 long long int
#define ran 101101

int n;
int a[ran];

int main() {
	scanf("%d", &n);
	
	int cnt = 0;
	i64 s = 0;
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		if(a[i]<0) cnt++;
		s += labs(a[i]);
	}

	int mi = labs(a[0]);
	for(int i=1;i<n;i++)
		mi = min(mi, (int)labs(a[i]));
	
	if (cnt%2) s -= mi*2;
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 640
# 入力
InpList=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
result=0

# 処理
print(InpList[K-1])

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

int main() {
  ll N,M;
  cin>>N>>M;
  ll a[M];
  vector<bool> j(N,true);
  rep(i,M){
    cin>>a[i];
    j[a[i]]=false;
  }
  ll dp[N+1];
  dp[0]=0;
  if(j[1]==true&&j[2]==true){
    dp[1]=1;
    dp[2]=2;
  }
  else if(j[1]==false&&j[2]==true){
    dp[1]=0;
    dp[2]=1;
  }
  else if(j[1]==true&&j[2]==false){
    dp[1]=1;
    dp[2]=0;
  }
  else{
    dp[1]=0;
    dp[2]=0;
  }
  
  for(ll i=3;i<=N;i++){
    if(j[i-1]==true&&j[i-2]==true){
      dp[i]=dp[i-1]+dp[i-2];
      dp[i]%=INF;
    }
    else if(j[i-1]==false&&j[i-2]==true){
      dp[i]=dp[i-2];
      dp[i]%=INF;
    }
    else if(j[i-1]==true&&j[i-2]==false){
      dp[i]=dp[i-1];
      dp[i]%=INF;
    }
    else{
      dp[i]=0;
    }
  }
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
typedef long long ll;
int n,m,sz[3],vis[N],all_sz,cnt,flag;
vector<pair<int,int> >g[N];
void dfs(int x,int y){
	vis[x]=y;sz[y]++;all_sz++;
	for(auto i:g[x]){
		++cnt;
		int u=(y+i.second)%3;
		if(vis[i.first]==-1)dfs(i.first,u);
		else if(vis[i.first]!=u)flag=0;
	}
}
ll ans;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	memset(vis,-1,sizeof vis);
	for(int i=1;i<=m;++i){
		int x,y;cin>>x>>y;
		g[x].emplace_back(y,1);
		g[y].emplace_back(x,2);
	}
	for(int i=1;i<=n;++i)if(vis[i]==-1){
		flag=1;memset(sz,0,sizeof sz);all_sz=0;cnt=0;
		dfs(i,0);
		if(!flag)ans+=(ll)all_sz*all_sz;
		else if(sz[0]&&sz[1]&&sz[2])ans+=(ll)sz[0]*sz[1]+(ll)sz[1]*sz[2]+(ll)sz[2]*sz[0];
		else ans+=cnt/2;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 10752
def solve(n):
  cnt = 0
  for i in range(len(S)):
    if (i + n) % 2:
      if S[i] == '0':
        cnt += 1
    else:
      if S[i] == '1':
        cnt += 1
  return cnt

S = input()
print(min(solve(0), solve(1)))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;

int main()
{
	int n, d;
	cin >> n >> d;	
	double x, y;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> x >> y;
		double m = sqrt(pow(x, 2) + pow(y, 2));
		if(m <= d)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3788
k, n = map(int, input().split())
a = list(map(int, input().split()))

ans = a[n-1] - a[0]

for i in range(len(a)):
  a[n - 1 - i] -= k
  new = -(a[n - 1 - i]) + a[n - 2 - i]
  # print(new)
  if new < ans:
    ans = new
print(ans)



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

const long MOD = 1e9 + 7;

long pow(long n, long k) {
    long res = 1;
    while (k) {
        if (k & 1) res = res * n % MOD;
        n = n * n % MOD;
        k >>= 1;
    }
    return res;
}

int main() {
    int n;
    string sa, sb;
    cin >> n;
    cin >> sa >> sb;
    long res = 1;
    int last = 0;
    for (int i = 0; i < n; ++i) {
        if (sa[i] == sb[i]) {
            assert(!((i - last) & 1));
            int len = (i - last) >> 1;
            if (len == 0) {
                if (last == 0)
                    res = res * 3;
                else
                    res = (res << 1) % MOD;
            } else {
                if (last == 0)
                    res = res * 6;
                else
                    res = (res << 1) % MOD;
                res = res * pow(3, len - 1) % MOD;
            }
            last = i + 1;
        }
    }
    int len = (n - last) >> 1;
    if (len) {
        if (last == 0)
            res = res * 6;
        else
            res = (res << 1) % MOD;
        res = res * pow(3, len - 1) % MOD;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int ans = a^b^c;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AOneCardPoker {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b;
	    in >> a >> b;
	    if(a == b) out << "Draw" << endl;
	    else if(a == 1) out << "Alice" << endl;
	    else if(b == 1) out << "Bob" << endl;
	    else{
	        if(a > b) out << "Alice" << endl;
	        else out << "Bob" << endl;
	    }
	}
};


int main() {
	AOneCardPoker solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool flag = false;
  for (int i = 1; i <= B; ++i) {
    if (A * i % B == C) {
      flag = true;
      break;
    }
  }
  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadLong();
        var sq = Math.Sqrt(N);
        var ans = long.MaxValue;
        for (int i = 1; i <= sq; i++)
        {
            if (N%i == 0)
            {
                ans = Math.Min(ans, i - 1 + N / i - 1);
            }
        }
        Console.WriteLine(ans);
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


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

int main() {
    string C1,C2;
    cin >> C1 >> C2;

    if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

int main(){
  string a,b;
  cin>>a>>b;
  for(int i=0;i<=a.size();i++){
    for(int j=0;j<b.size();j++){
      if(i+j>=a.size()||a[i+j]!=b[j])break;
      if(j+1==b.size())cout <<i<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 2000010


int main(){
	IOS;
	
	
	ll k,n;cin>>k>>n;
	ll a[n];
	rep(i,0,n)cin>>a[i];
	vll d;
	rep(i,0,n-1){
		d.pb(abs(a[i]-a[i+1]));
	}
	d.pb(a[0]+k-a[n-1]);
	ll sum=0,mx=-1;
	rep(i,0,n){
		sum+=d[i];
		mx=max(mx,d[i]);
	}
	//teln(d,n);
	sum-=mx;
	cout<<sum;
	
	
	
	
	return 0;
}



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

int main()
{
	int N, Q;
	char S[131072];
	scanf("%d %d\n%s\n", &N, &Q, S);

	int count = 0;
	int res[131072];
	res[0] = 0;
	for(int n=1; n<N; n++){
		if(S[n-1] == 'A' && S[n] == 'C'){
			count++;
		}
		res[n] = count;
	}

	for(int q=0; q<Q; q++){
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", res[r-1]-res[l-1]);
	}
}


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

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

  string ans = "yes";

  for (char c = 'a'; c <= 'z'; c++)  {
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S.at(i) == c) cnt++;
    }
    if (cnt > 1) ans = "no";
  }

  cout << ans << "\n";
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

ll DIV = 1000000007;

int main()
{
  int n;
  cin >> n;
  ll result = 0LL;
  ll dp[105][4][4][4] = {};

  REP(i,4) {
    REP(j,4) {
      REP(k,4) {
        dp[3][i][j][k] = 1;
        if (i == 0 && j == 1 && k == 2) {
          dp[3][i][j][k]--;
        }
        if (i == 0 && j == 2 && k == 1)
        {
          dp[3][i][j][k]--;
        }
        if (i == 2 && j == 0 && k == 1)
        {
          dp[3][i][j][k]--;
        }
      }
    }
  }

  FOR(m,4,n+1) {
    REP(i,4) {
      REP(j,4) {
        REP(k,4) {
          REP(l,4) {
            if ((j == 0 && k == 1 && l == 2) || (j == 2 && k == 0 && l == 1) || (j == 0 && k == 2 && l == 1)) {
              continue;
            } else if ((i == 0 && k == 2 && l == 1) || (i == 0 && j == 2 && l == 1)) {
              continue;
            } else {
              dp[m][j][k][l] += dp[m-1][i][j][k]%DIV;
            }
          }
        }
      }
    }
  }

  REP(i, 4) {
    REP(j, 4) {
      REP(k, 4 ){
        result = (result + dp[n][i][j][k])%DIV;
      }
    }
  }

  cout << result << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+8+7;
ll n,m,l;
string s,t;
int d[100000],dp[50][410][410];
int a[50],b[50],c[50];

int main(){
  cin >> n >> m >> l;
  rep(i,0,n)cin >> a[i] >> b[i] >> c[i];
  lep(i,0,n){
    rep(j,0,410){
      rep(k,0,410){
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  rep(i,0,n){
    lep(j,0,400){
      lep(k,0,400){
        if(dp[i][j][k] == INF)continue;
        dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]]+c[i],dp[i][j][k]+c[i]);
      }
    }
  }
  int ans = INF;
  lep(i,1,400){
    lep(j,1,400){
      if(i*l == j*m)ans = min(ans,dp[n][i][j]);
    }
  }
  if(ans == INF)ans = -1;
  print(ans);
  return 0;
}

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

using namespace std;
typedef long long ll;

int n;
vector<int> w;
vector<vector<int> > dp;


int rec(int l,int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(abs(l - r) <= 1) return 0;

    int res = 0;
    if(abs(w[l] - w[r - 1]) <= 1 && rec(l + 1,r - 1) == r - l - 2) res = r - l;

    for(int mid = l + 1;mid <= r - 1;mid++) {
        res = max(res , rec(l,mid) + rec(mid,r));
    }
    return dp[l][r] = res;
};

int main() {
    vector<int> ans(0);
    while (true) {
        cin >> n;
        if (n == 0) break;
        w.resize(n);
        for (int i = 0; i < n; i++) {
            cin >> w[i];
        }
        dp = vector<vector<int> >(n+2, vector<int>(n+2, -1));
        ans.push_back(rec(0, n));
    }

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




Measured memory_bytes: 3560
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
		int b = sc.nextInt();
      	
      	if(b%a==0) System.out.println(a+b);
      	else System.out.println(b-a);
    }
}

Measured memory_bytes: 35664
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int A,B,C,D;

int main(){
    cin>>A>>B>>C>>D;

    int i=1;
    while(true){
        if(i&1){
            C-=B;
        }else{
            A-=D;
        }
        if(A<=0){
            cout<<"No"<<endl;
            return 0;
        }
        if(C<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        i++;
    }
}

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

int main()
{

  int K, N;

  cin >> K >> N;

  vector<int> A(N);

  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<int> D(N);

  for (int i = 0; i < N; i++)
  {
    if (i < N - 1)
    {
      D.at(i) = A.at(i + 1) - A.at(i);
    }
    else
    {
      D.at(i) = (K - A.at(i)) + A.at(0);
    }
  }

  sort(D.begin(), D.end());

  int sum;

  for (int i = 0; i < N - 1; i++)
  {
    sum += D.at(i);
  }

  cout << sum << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


int main(){
    int n, m;   cin >> n >> m;
    if(n % 2 == 1){
        int l = 1, r = n;
        for(int i = 0; i < m; i++){
            cout << l << " " << r << endl;
            l++; r--;
        }
    }
    else{
        bool trigger = false;
        int l = 1, r = n;
        for(int i = 0; i < m; i++){
            int dif = r - l;
            if(!trigger && dif <= n / 2){
                r--;
                trigger = true;
            }
            cout << l << " " << r << endl;
            l++; r--;
        }
    }


    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll k,a,b;
   cin>>k>>a>>b;
   for(ll i=a;i<=b;i++)
   {
       if(i%k == 0)
       {
           cout<<"OK\n";
           return 0;
       }
   }
   cout<<"NG";
   
   return 0;        
}  
  
   

Measured memory_bytes: 3652
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let l: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut m: i32 = l;
    let mut s: i32 = 0;
    for i in 0..n {
        s += l + i;
        m = if m.abs() < (l + i).abs() { m } else { l + i };
    }
    let ans = s - m;
    println!("{}", ans);
}


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

int main(){
    int n;
    cin >> n;
    map<string,vector<pair<int,int>>> mp;
    for(int i = 0;i < n;i ++){
        string s;
        int p;
        cin >> s >> p;
        mp[s].push_back(make_pair(p,i+1));
    }
    for(auto ite = mp.begin();ite != mp.end();++ite){
        sort(ite->second.begin(),ite->second.end());
        reverse(ite->second.begin(),ite->second.end());
        for(int i = 0;i < ite->second.size();i ++){
            cout << ite->second[i].second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N,A = map(int,input().split())
src = list(map(int,input().split()))

dp = [Counter() for i in range(N+1)]
dp[0][0] = 1
for i,a in enumerate(src):
    for j in reversed(range(i+1)):
        for k,v in dp[j].items():
            dp[j+1][k+a] += v
ans = 0
for i,ctr in enumerate(dp):
    if i==0: continue
    ans += ctr[i*A]
print(ans)

Measured memory_bytes: 5492
#include <cstdio>

int d[120000],f[120000],h[120000];
int i,m,n,x,y,dx,dy,fx,fy,z;

inline int getfather(int x)
{
	if (f[x]==x)
		return x;
	else
		return getfather(f[x]);
}

inline int getdis(int x)
{
	if (f[x]==x)
		return 0;
	else
		return d[x]+getdis(f[x]);
}

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		f[i]=i,h[i]=1;
	for (i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		fx=getfather(x);
		fy=getfather(y);
		if (fx!=fy)
			if (h[fx]<h[fy])
				d[fx]=z-getdis(x)+getdis(y),f[fx]=fy,h[fy]=h[fy]+h[fx];
			else
				d[fy]=-z-getdis(y)+getdis(x),f[fy]=fx,h[fx]=h[fx]+h[fy];
		else
		{
			dx=getdis(x);
			dy=getdis(y);
			if (dx!=dy+z)
				return puts("No"),0;
		}
	}
	return puts("Yes"),0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	n=n%10;
	if(n==2 || n==4 || n==5 || n==7 || n==9)
		printf("hon\n");
	else if(n==0 || n==1 || n==6 || n==8)
		printf("pon\n");
	else
		printf("bon\n");
}


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

using namespace std;

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

    long n = N;
    long S = 0;
    while(n > 0){
	S += n % 10;
	n = n / 10;
    }

    if(N % S == 0){
	cout << "Yes" << endl;
    }else{
	cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
main(){
	double a,b,c,d,e,f,g,h;
	for(scanf("%lf",&a);~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f,&g,&h);)
		puts(fabs((c-a)*(h-f)-(d-b)*(g-e))>1e-10?"NO":"YES");
	return 0;
}

Measured memory_bytes: 1040
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[200100];
int u[200100], v[200100];

vector<int> G[200100];
int len[200100];

vector<int> vec;

void dfs(int t, int prev) {
    int idx = (int)(lower_bound(ALL(vec), a[t]) - vec.begin());
    int orig = -1;
    if (idx < vec.size()) {
        orig = vec[idx];
        vec[idx] = a[t];
    } else {
        vec.push_back(a[t]);
    }
    len[t] = (int)vec.size();

    for (int s : G[t]) {
        if (s == prev) continue;
        dfs(s, t);
    }

    if (orig >= 0) {
        vec[idx] = orig;
    } else {
        vec.pop_back();
    }
}

void solve() {
    for (int i = 0; i < n-1; i++) {
        G[u[i]].push_back(v[i]);
        G[v[i]].push_back(u[i]);
    }

    dfs(1, -1);

    for (int i = 1; i <= n; i++) {
        cout << len[i] << endl;
    }
}

void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n-1; i++) cin >> u[i] >> v[i];
}

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

    input();
    solve();
}


Measured memory_bytes: 31644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            int N = int.Parse(line[0]);
            int D = int.Parse(line[1]);
            int[,] X = new int[N, D];

            for(int i=0; i<N; i++)
            {
                S = Console.ReadLine();
                line = S.Split(' ');
                for(int j=0; j<D; j++)
                {
                    X[i, j] = int.Parse(line[j]);
                }
            }

            int ans = 0;
            for(int i=0; i<N-1; i++)
            {
                for(int j=i+1; j<N; j++)
                {
                    double B = 0;
                    for(int k=0; k<D; k++)
                    {
                        B = B + Math.Pow(X[i, k] - X[j, k], 2);
                    }
                    if(Math.Sqrt(B) % 1 == 0)
                    {
                        ans++;
                    }
                }
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 11092
package main

import(
      "fmt"
)

func main(){

  var n,y int
  cnt := 0
  fmt.Scan(&n,&y)
  for i:=0; i<=n; i++{//10000
    for j:=0; j<=n-i; j++{//5000
      k := n-i-j
      if i*10000+j*5000+k*1000 == y{
        fmt.Print(i);
        fmt.Print(" ");
        fmt.Print(j);
        fmt.Print(" ");
        fmt.Println(k);
        cnt++
      }
      if(cnt==1){
        break
      }
    }
    if(cnt==1){
      break;
    }
  }
  if(cnt==0){
    fmt.Println("-1 -1 -1")
  }
}

//====  ↓↓↓ template functions ↓↓↓  ======================

func min(a, b int64) int64{
  if a < b {
    return a
  }
  return b
}

func max(a, b int64) int64{
  if a > b {
    return a
  }
  return b
}

func abs(x int64) int64{
  if x < 0 {
    return -x
  }
  return x
}

func gcd(a, b int64) int64{
  if b == 0 {
    return a
  }else{
    return gcd(b, a%b)
  }
}

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

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

int main() {
  int n, k, d, tmp, ans = 0;
  cin >> n >> k;
  vector<int> a(n, true);
  rep(i, k) {
    cin >> d;
    rep(j, d) {
      cin >> tmp;
      a[tmp - 1] = false;
    }
  }
  rep(i, n) if(a[i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FAST_IO std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define pause system("pause")
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
using namespace std;
const int maxn = 2e5 + 10;

inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }

struct node {
    int pos;
    ll val;
    bool operator<(const node &p) const {
        if (val == p.val)
            return pos < p.pos;
        return val < p.val;
    }
}a[maxn];

struct seg {
    int l, r;
    ll sum;
}tree[maxn << 2];

void push_up(int p) {
    tree[p].sum = tree[lc(p)].sum + tree[rc(p)].sum;
}

void bulid(int p, int l, int r) {
    tree[p].l = l, tree[p].r = r;
    tree[p].sum = 0;
    if (l == r)
        return;
    int mid = (l + r) >> 1;
    bulid(lc(p), l, mid);
    bulid(rc(p), mid + 1, r);
    push_up(p);
}

void update(int p, int pos) {
    if (tree[p].l == pos && tree[p].r == pos) {
        tree[p].sum++;
        return;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    if(pos <= mid)
        update(lc(p), pos);
    else 
        update(rc(p), pos);
    push_up(p);
}

ll query(int p, int l, int r) {
    if(tree[p].l == l && tree[p].r == r) {
        return tree[p].sum;
    }
    int mid = (tree[p].l + tree[p].r) >> 1;
    if (mid < l)
        return query(rc(p), l, r);
    else if (mid >= r)
        return query(lc(p), l, r);
    else 
        return query(lc(p), l, mid) + query(rc(p), mid + 1, r);
}

int main(void) {
    FAST_IO;
    ll n, k, x;
    cin >> n >> k;
    for (int i = 1; i<= n; i++) {
        cin >> x;
        x -= k;
        a[i].pos = i;
        a[i].val = a[i - 1].val + x;
    }
    sort(a + 1, a + 1 + n);
    bulid(1, 1, n);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        update(1, a[i].pos);
        if (a[i].val >= 0)
            ans++;
        if (a[i].pos == 1)
            continue;
        ans += query(1, 1, a[i].pos - 1);
    }
    cout << ans << endl;
    // pause;
    return 0;
}

Measured memory_bytes: 13824
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    val (n, k) = line.split(" ").map {it.toInt()}

    val sunukes: MutableList<MutableList<Int>> = (0..n-1).map { mutableListOf<Int>() }.toMutableList()

    for (i in (0..k-1)) {
        val d = readLine()!!.trim().toInt()
        val ary = readLine()!!.trim().split(" ").map {it.toInt()}.take(d)
        ary.forEach {sunukes[it - 1].add(i + 1)}
    }

    println("${sunukes.filter {it.isEmpty()}.size}")
}

Measured memory_bytes: 39332
N = int(input())
S = input()

ABCtoNum = dict()
NumtoABC = dict()
for i, s in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
    ABCtoNum[s] = i
    NumtoABC[i] = s
ABC_N = dict()
for s, i in ABCtoNum.items():
    ABC_N[s] = NumtoABC[(i+N)%26]

ans = list()
for s in S:
    ans.append(ABC_N[s])
print(''.join(ans))

Measured memory_bytes: 3064