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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 1e9 + 7;

ll pow(ll x, ll m)
{

    ll re = 1, y = 1;

    for (int i = 0; i < 60; ++i)
    {
        if (m & y)
            re = re * x % mod;
        x = x * x % mod;
        y *= 2;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num - rhs.num + mod) % mod;
    }
    mint operator/(const mint &rhs) const
    {
        return num * inv(rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return *this = *this + rhs;
    }
    mint operator*=(const mint &rhs)
    {
        return *this = *this * rhs;
    }
    mint operator-=(const mint &rhs)
    {
        return *this - *this / rhs;
    }
    mint operator/=(const mint &rhs)
    {
        return *this = *this / rhs;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

constexpr int MAX = 2 * 1e5 + 5;

int size[MAX];

mint sub[MAX];

std::vector<int> to[MAX];

mint fact[MAX];

bool used[MAX];

void dfs1(int v)
{
    size[v] = 1;
    sub[v] = 1;

    for (auto x : to[v])
    {
        if (!used[x])
        {
            used[x] = 1;
            dfs1(x);
            size[v] += size[x];
            sub[v] *= sub[x] / fact[size[x]];
        }
    }
    sub[v] *= fact[size[v] - 1];
}

int n;

mint ans[MAX];

mint psub = 1;

int psize;

void dfs2(int v)
{
    //std::cerr << v << ' ' << psize << ' ' << psub << std::endl;
    int ppsize = psize;
    mint ppsub = psub;
    ans[v] = sub[v] / fact[size[v] - 1] * fact[n - 1] / fact[psize] * psub;
    for (auto x : to[v])
    {
        if (!used[x])
        {
            used[x] = 1;
            //std::cerr << "DD" << std::endl;
            psize += size[v] - size[x];
            psub *= sub[v] / sub[x] * fact[size[x]] * fact[psize - 1] / fact[size[v] - 1] / fact[ppsize];
            dfs2(x);
            psize = ppsize;
            psub = ppsub;
        }
    }
}

int main()
{

    std::cin >> n;

    fact[0] = 1;

    rep(i, n)
        fact[i] = fact[i - 1] * i;

    rep(i, n - 1)
    {
        int a, b;
        std::cin >> a >> b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    used[1] = 1;
    dfs1(1);

    std::memset(used, 0, sizeof(used));
    used[1] = 1;

    dfs2(1);

    rep(i, n)
            std::cout
        << ans[i] << std::endl;

    //std::cerr << "DEBUG" << std::endl;

    /*rep(i, n)
    {
        std::cerr << size[i] << ' ' << sub[i] << std::endl;
    }*/

    return 0;
}

Measured memory_bytes: 21076
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_D
  * Structured Program I - Structured Programming
  */
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    //Memory Limit Exceeded
    //    val result = (1 to n).filter(i => i % 3 == 0 || i.toString.contains('3'))
    //      .foldLeft("") { (str, i) => str + s" $i" }
    val result = " " + (1 to n).filter(i => i % 3 == 0 || i.toString.contains('3')).mkString(" ")
    println(result)
  }
}

Measured memory_bytes: 46816
#include <stdio.h>
 
int main(void){
	int n, m, t;
    int f[101] = {}, tar[101] = {}, score[101] = {};
    int i, j;
     
    scanf("%d", &n);
     
    scanf("%d", &m);
     
    for (i = 0; i < m; i++){
        scanf("%d", &t);
        tar[i] = t;
    }
     
    for (i = 0; i < m; i++){
        for (j = 0; j < n; j++){
            scanf("%d", &f[j]);
             
            if (f[j] == tar[i]) score[j]++;
            else score[tar[i]-1]++;
        }
    }
     
    for (i = 0; i < n; i++)  printf("%d\n", score[i]);
     
    return 0;
}

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

int main() {
	double R;
	cin >> R;
	cout << setprecision(10) << R*2*3.1415926539 << endl;
}

Measured memory_bytes: 3780
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


map<ll, int> get_primes(ll m, ll M) {
    map<ll, int> p;
    p[1] = 1;
    int s[m];
    REP(i, m) s[i] = i;
    for(int i = 2; i <= m; ++i) {
        if (s[i] != i) continue;

        for(int j=i+i; j <= m; j += i) {
            s[j] = i;
        }

        int cnt = 0;
        while(M % i == 0) {
            M /= i;
            ++cnt;
        }
        if (cnt > 0) p[i] = cnt;
    }
    if (M != 1) p[M] = 1;

    return p;
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N; ll M;
    cin >> N >> M;

    int m = int(floor(sqrt(M))) + 1;
    map<ll, int> p = get_primes(m, M);

    int n = N + 1;
    bool c[n][2];
    REP(i, n) {
        c[i][0] = false;
        c[i][1] = false;
    }
    c[1][0] = true;

    ll mm = inf;
    int b = 0;
    for (auto it = p.begin(); it != p.end(); ++it) debug(it->fi, it->se)
    for (auto it = p.begin(); it != p.end(); ++it) {
        REP(i, it->se) {
            REP(i, n) {
                if (c[i][b]) {
                    ll t = i * it->fi;
                    if(t < N) {
                        c[i][b^1] = true;
                        c[t][b^1] = true;
                    } else {
                        debug(t)
                        mm = min(mm, t);
                    }
                }
            }
            b ^= 1;
        }
    }
    
    cout << fixed << setprecision(20);
    cout << int(M / mm) << endl;

}


Measured memory_bytes: 512
x,y=map(float,input().split(','))
bx,by=map(float,input().split(','))
s=0
while 1:
    try:xx,yy=map(float,input().split(','))
    except:break
    a=((bx-xx)**2+(by-yy)**2)**0.5;
    b=((x-bx)**2+(y-by)**2)**0.5;
    c=((x-xx)**2+(y-yy)**2)**0.5;
    z=(a+b+c)/2
    s+=(z*(z-a)*(z-b)*(z-c))**0.5
    bx,by=xx,yy
print(s)

Measured memory_bytes: 7556
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=1e5+5;
const int INF=1e9;
struct Edge{
	int to,ne,c;
}e[N<<4];
struct Line{
	int x,y;
}line[N];
int h[N<<1],cnt=1,dis[N<<1],n,S,T,id[N];
vint G[N];
void add(int x,int y,int c){
	e[++cnt]=Edge{y,h[x],c};
	h[x]=cnt;
	e[++cnt]=Edge{x,h[y],0};
	h[y]=cnt;
}
bool bfs(int S,int T){
	queue<int>q;
	for(int i=1;i<=T;i++)dis[i]=0;
	dis[S]=1;q.push(S);
	while(q.size()){
		int x=q.front();q.pop();
		if(x==T)return true;
		for(int i=h[x];i;i=e[i].ne){
			int y=e[i].to;
			if(dis[y]||!e[i].c)continue;
			dis[y]=dis[x]+1;
			q.push(y);
		}
	}return false;
}
int dfs(int x,int maxn,int T){
	if(x==T||!maxn)return maxn;
	int dt=0,re=0;
	for(int i=h[x];i;i=e[i].ne){
		int y=e[i].to;
		if(dis[y]!=dis[x]+1||!e[i].c)continue;
		dt=dfs(y,min(maxn,e[i].c),T);
		if(!dt)dis[y]=0;
		e[i].c-=dt,e[i^1].c+=dt;
		maxn-=dt,re+=dt;
		if(!maxn)return re;
	}return re;
}
int dinic(int S,int T){
	int re=0;
	while(bfs(S,T))re+=dfs(S,INF,T);
	return re;
}
bool solve(){
	for(int x=1;x<n;x++)for(int i=h[x];i;i=e[i].ne){
		int y=e[i].to;
		if(y==S||e[i].c)continue;
		id[x]=y-n+1;
	}int su=0;
	queue<int>q;q.push(n);
	while(q.size()){
		int x=q.front();
		su++;q.pop();
		int siz=G[x].size();
		for(int i=0;i<siz;i++){
			int t=G[x][i];
			if(id[t])line[t]=Line{x,id[t]},q.push(id[t]),id[t]=0;
		}
	}return su==n;
}
signed main(){
	n=read(),S=(n<<1)-1,T=S+1;
	for(int i=1;i<n;i++)add(i+n-1,T,1);
	for(int i=1;i<n;i++){
		int nu=read();
		add(S,i,1);
		for(int j=1;j<=nu;j++){
			int x=read();
			if(x!=n)add(i,x+n-1,1);
			G[x].pb(i);
		}
	}
	if(dinic(S,T)!=n-1)return puts("-1"),signed();
	if(!solve())return puts("-1"),signed();
	for(int i=1;i<n;i++)cout<<line[i].x<<' '<<line[i].y<<'\n';
	return signed();
}

Measured memory_bytes: 22584
package main

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

func main() {
	N := ReadInt()
	dp := make([]int, N+1)
	for i := 1; i <= N; i++ {
		dp[i] = 1 + dp[i-1]
		for j := 1; j <= 6; j++ {
			if i-j >= 0 {
				dp[i] = Min(dp[i], j+dp[i-j])
			}
		}
		for p := 6; p <= i; p *= 6 {
			dp[i] = Min(dp[i], 1+dp[i-p])
		}
		for p := 9; p <= i; p *= 9 {
			dp[i] = Min(dp[i], 1+dp[i-p])
		}
	}
	fmt.Println(dp[N])
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int length = S.size();
	string ans = "Yes";
	if (length%2 != 0){
		ans = "No";
	}
	else{
		length /= 2;
		rep(i, length){
			if (S[i] != S[i + length]) ans = "No";
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.141592653589793
#define epsilon 0.000000001
#define INF 1000000000000
#define MOD 1000000007

int main(){
    //freopen("dec.in", "r", stdin); freopen("dec.out", "w", stdout);
    set<int> lol; int N; cin >> N;
    for(int i = 0; i < N; i++){
        int x; cin >> x;
        if(lol.find(x) == lol.end()) lol.insert(x);
        else lol.erase(x);
    }
    cout << lol.size() << '\n';
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0] <<" "<< a[1] <<" "<< a[2] << endl;

	return 0;
}

Measured memory_bytes: 1180
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		long[] num = new long[5];  // 0:M, 1:A, 2:R, 3:C, 4:H 
		for(int i = 0; i < N ; i++)
		{
			string s = Console.ReadLine();
			switch(s[0])
			{
				case 'M':
					num[0]++;
					break;

				case 'A':
					num[1]++;
					break;

				case 'R':
					num[2]++;
					break;

				case 'C':
					num[3]++;
					break;

				case 'H':
					num[4]++;
					break;
				
				default:
					break;
			}
		}

		long ans = 0;
		long comb = (1 << 3) - 1;
		while(comb < (1 << 5))
		{
			long tmp = 1;
			for(int i = 0; i < 5; i++)
				if(((comb >> i) & 1) == 1)
					tmp *= num[i];
			ans += tmp;
			comb = next_combination(comb);
		}
		Console.WriteLine(ans);
	}

	public static long next_combination(long comb)
	{
		long x = comb & -comb;
		long y = comb + x;
		return (((comb & ~y) /x) >> 1) | y;
	}
}





Measured memory_bytes: 15188
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
ll solve(string &s){
    ll res = 0;
    ll sum = 0;
    rep(i,s.size()){
        if(s[i] == 'A'){
            sum++;
        }else{
            res += sum;
        }
    }
    return res;
}
int main(){
    string s;
    string t;
    cin >> s;
    s += "F";
    ll ans = 0;
    rep(i,s.size()){
        if(s[i] == 'B' and i + 1 < s.size() and s[i+1] == 'C'){
            t += "X";
            i++;
        }else if(s[i] == 'A'){
            t += "A";
        }else{
            ans += solve(t);
            t = "";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 776
import java.util.*;

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

    while(sc.hasNextLine()){
      String s = sc.nextLine();

      for(int i = 0; i < 26; i++){
        if(s.contains("this") || s.contains("that") || s.contains("the")){
          System.out.println(s);
          break;
        }

        String ns = "";

        for(int j = 0; j < s.length(); j++){
          char ch = s.charAt(j);
          if('a' <= ch && ch <= 'z'){
            ch = (char)((ch - 'a' + 1) % 26 + 'a');
          }
          ns += ch;
        }

        s = ns;
      }
    }
  }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

int modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 
int main()
{
	int n;
	cin>>n;
	int a[n];
	map<ll,ll>m;
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;

	}
	ll s;

	for(int i=0;i<=n;i++)
	{
		if(m[i]>=2)
		{
			ll temp=m[i];
			s=s+((temp*(temp-1))/2);
		}
		//i=i+m[a[i]]
	}
	for(int i=0;i<n;i++)
	{
		cout<<s-m[a[i]]+1<<endl;
	}
}

Measured memory_bytes: 15872
def main():
    n, m = map(int, input().split())
    p = 2**n
    dp = [float('inf')]*p
    dp[0] = 0
    for _ in range(m):
        a, _ = map(int, input().split())
        c = sum([2**(int(i)-1) for i in input().split()])
        for s in range(p):
                t = s|c
                if dp[t] > dp[s] + a:
                    dp[t] = dp[s] + a
    ans = dp[-1]
    if ans == float('inf'):
        ans = -1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
const ll MOD = 1000000007;

void solve(ll N) {

  ll ans(1);
  vector<bool> prime(N + 1, true);

  FOR(i, 2, N + 1) {

    if (!prime[i])
      continue;
  
    ll ni(1);
    FOR(j, i + 1, N + 1) {
      if (j % i)
	continue;
      prime[j] = false;
      int x = j;
      while (x % i == 0) {
	x /= i;
	ni++;
      }
    }
    ans *= (ni + 1);
    ans %= MOD;
  }

  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  solve(N);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
    
    size_t n, k;

    std::cin >> n >> k;

    size_t ans = k;

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

    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string s;
  cin >> s;
  ll cn=0;
  for(char c:s){
    if(c=='1') cn ++;
  }
  cout << cn <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    int a[100001];
    int i,flag;
    long long int tmp; 
    
    long long int memo1[100001] = {0};
    long long int memo2[100001] = {-2000000000};
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    
    for(i = 1; i <= n; i++){
        if(memo1[i-1] + a[i] > memo2[i-1] - a[i]){
            memo1[i] = memo1[i-1] + a[i];
        }else{
            memo1[i] = memo2[i-1] - a[i];
        }
        
        if(memo1[i-1] - a[i] > memo2[i-1] + a[i]){
            memo2[i] = memo1[i-1] - a[i];
        }else{
            memo2[i] = memo2[i-1] + a[i];
        }
    }
    
    printf("%lld\n", memo1[n]);
    
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define int long long
#define N 100004

using namespace std;

main() {
    ios_base::sync_with_stdio(false);
    string s; cin >> s;

    int index = s.size()-1;
    while(index >= 0 and s[index] == 'B') index--;

    if (index <= 0) {
        cout << 0 << endl; exit(0);
    }

    int ans = 0;

    int no = 0;

    for (int i = index-1; i >= 0; --i) {
        if (s[i] == 'B') {
            ans += index-i-no;
            no++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 720
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ts = vec![0; n + 1];
    let mut xs = vec![0; n + 1];
    let mut ys = vec![0; n + 1];
    for i in 0..n {
        ts[i + 1] = read();
        xs[i + 1] = read();
        ys[i + 1] = read();
    }
    for i in 0..n {
        let d = (xs[i + 1] - xs[i] as i32).abs() + (ys[i + 1] - ys[i] as i32).abs();
        let t = ts[i + 1] - ts[i];
        if t < d || (t - d) % 2 == 1 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
#include<stdio.h>

int main(){
	char s1[20], s2[20];
	scanf("%s", s1);
	int i = 0, j = 0;
	while(s1[i] != '\0')
		i++;
	scanf("%s", s2);
	for(j = 0; j < i; j++){
		if(s1[j] != s2[j])
			break;
	}
	if(j == i)
		printf("Yes");
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <string.h>

#define FOR(i,k,n) for((i)=(k);(i)<(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long int64;

inline int readint(){
    int ret = 0, x;
    bool plus = true;
    while(x=getchar(), !('0'<=x&&x<='9' || x=='-'));
    if(x=='-') plus = false;
    else ret = (x&15);
    while(x=getchar(), '0'<=x&&x<='9') ret = (ret<<3) + (ret<<1) + (x&15);
    return plus?ret:-ret;
}

char board[22][22];
int sx, sy, gx, gy;
int n, m;
int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

inline int dfs(int y, int x, int depth){
    if(depth >= 10) return 1<<10;
    int k, nx, ny, ans = 1<<10;
    REP(k,4){
        ny = y + dy[k];
        nx = x + dx[k];
        if(board[ny][nx] == 1) continue;
        while(!board[ny][nx]){
            ny += dy[k];
            nx += dx[k];
        }
        if(board[ny][nx] == 3) return depth+1;
        if(board[ny][nx] == 1){
            board[ny][nx] = 0;
            ans = min(ans, dfs(ny-dy[k],nx-dx[k],depth+1));
            board[ny][nx] = 1;
        }
    }
    return ans;
}

int main(){
    int i, j;
    while(m = readint(), n = readint(), n){
        REP(i,n+2)REP(j,m+2) board[i][j] = 4;
        FOR(i,1,n+1)FOR(j,1,m+1){
            board[i][j] = readint();
            if(board[i][j] == 2){
                sy = i, sx = j;
                board[i][j] = 0;
            }
            if(board[i][j] == 3){
                gy = i, gx = j;
            }
        }
        int ans = dfs(sy,sx,0);
        printf("%d\n",ans<=10?ans:-1);
    }

    return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            int n = cin.ReadInt;
            long[] data = cin.ReadLongArray(n);
            Array.Sort(data);
            for(int i = 0; i < n - 1; i++)
            {
                if(data[i] == data[i + 1])
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

using namespace std;

int main() {
int h;
cin>>h;long sum=0;
for(int i=0;i<h;i++)
{
    int a,b;
    cin>>a>>b;
    sum+=b-a+1;
}


cout<<sum;
cout<<endl;    
    return 0;
}

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

int N;
vector<double> x(0), y(0);

double f(double x0, double y0){
	double ans = 0;
	for(int i = 0; i < N; i++){
		ans = max(ans, hypot(x[i] - x0, y[i] - y0));
	}
//	printf("f(%lf, %lf) = %lf\n", x0, y0, ans);
	return ans;
}

double f(double x0){
	double l = 0, h1, h2, r = 1000;
	for(int i = 0; i < 50; i++){
		h1 = (2 * l + r) / 3;
		h2 = (l + 2 * r) / 3;
		if(f(x0, h1) > f(x0, h2)){
			l = h1;
		}
		else{
			r = h2;
		}
	}
	return f(x0, (l + r) / 2);
}

int main(){
	int i;
	scanf("%d", &N);
	x.assign(N, 0);
	y.assign(N, 0);
	for(i = 0; i < N; i++){
		scanf("%lf%lf", &x[i], &y[i]);
	}
	double l = 0, h1, h2, r = 1000;
	for(i = 0; i < 50; i++){
		h1 = (2 * l + r) / 3;
		h2 = (l + 2 * r) / 3;
		if(f(h1) > f(h2)){
			l = h1;
		}
		else{
			r = h2;
		}
	}
	printf("%.10lf\n", f((l + r) / 2));
	return 0;
}

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

class prog{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int K = int.Parse(Console.ReadLine());
    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
    
    int sum = 0;
    for(int i = 0; i < N; i++){
      sum += 2 * Math.Min(Math.Abs(x[i]), Math.Abs(x[i] - K));
    }
    
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 13396
package main

import (
	"fmt"
)

func main() {
	var a string

	fmt.Scan(&a)
	if a[2:3]== a[3:4] &&a[4:5]== a[5:6]{
		fmt.Println("Yes")
	}  else {
		fmt.Println("No")
	}
	

}

Measured memory_bytes: 512
n,x=map(int,input().split())
A=list(map(int,input().split()))
B=A[:]

s1=0

for i in range(n-1):
    w=B[i]+B[i+1]
    if w>x:
        s1+=w-x
        B[i+1]=0 if x<=B[i] else x-B[i]

print(s1)

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

int main() {
    int n;
    cin >> n;
    vector<int> weigh(n);
    for (int i = 0; i < n; ++i) {
        cin >> weigh.at(i);
    }
    vector<int> weighSum(n, 0);
    weighSum.at(0) = weigh.at(0);
    for (int j = 1; j < n; ++j) {
        weighSum.at(j) = weighSum.at(j - 1) + weigh.at(j);
    }
    int ans = INFINITY;
    for (int t = 0; t < n; ++t) {
        int start = weighSum.at(t);
        int end = weighSum.at(n - 1) - weighSum.at(t);
        ans = min(ans, abs(start - end));
    }
    cout << ans << endl;
}


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

int main() {
    string s;
    int k;
    cin >> k >> s;
    string ans ="";
    if((int)s.length()<=k)ans=s;
    else ans = s.substr(0,k)+"...";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		ArrayDeque<String> list = new ArrayDeque<String>();
		
		for(int i=0;i<n;i++) list.push(sc.next());
		
		int m = sc.nextInt();
		String s = "";
		boolean flag = false;
		for(int i=0;i<m;i++){
			s = sc.next();
			if(list.contains(s)==true){
				if(flag==false){
					System.out.println("Opened by " + s);
					flag = true;
				}else{
					System.out.println("Closed by " + s);
					flag = false;
				}
			}else{
				System.out.println("Unknown " + s);
			}
		}
	
	}	
}

Measured memory_bytes: 20612
#include <cstdio>
#include <cstring>
#include <cstdlib>

int main () {
    
    char a[1000], b[1000];
    
    scanf("%s%s", a, b);
    
    if (strlen(a) > strlen(b)) {
        printf("GREATER");
    }
    else if (strlen(a) < strlen(b)) {
        printf("LESS");
    }
    else {
        for (int i = 0; i < strlen(a); i++) {
            if (a[i] > b[i]) {
                printf("GREATER");
                return 0;
            }
            if (a[i] < b[i]) {
                printf("LESS");
                return 0;
            }
        }
        printf("EQUAL");
    }
}

Measured memory_bytes: 128
x, y = map(int, input().split())
mod = 10**9+7

if (2*y-x < 0) or (2*x-y < 0):
    print(0)
    exit()

if (2*y-x)%3 != 0 or (2*x-y)%3 != 0:
    print(0)
    exit()

xc = (2*y-x)//3
yc = (2*x-y)//3
p = 1
k = 1
for i in range(1, xc+1):
    p *= (yc+i)
    k *= i
    p %= mod
    k %= mod

ans = p*pow(k, mod-2, mod)%mod
print(ans)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int L;
  int m,n;
  while(1){
    int sum=0;
    int mon;
    int flag=0;
    cin>>L;
    if(L==0) break;
    
    for(int i=0;i<12;i++){
      cin>>m>>n;
      sum=sum+(m-n);
      if(sum>=L && flag==0){
	mon=i+1;
	flag=1;
      }
    }
    if(sum>=L){
      cout<<mon<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}

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

using namespace std;

int main(void)
{
    int N;

    cin >> N;

    for (int i = 1; i <= 9; i++)
    {
        if (N % i == 0)
        {
            if (N / i <= 9)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
char s[N];

int main() {
  int n;
  scanf("%d %s", &n, s);
  int r = 0, b = 0;
  for (int i = 0; i < n; ++i)
    r += s[i] == 'R';
  b = n - r;
  puts(r > b ? "Yes" : "No");
  return 0;
}

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

using namespace std;

int main(){
    int a,b,C,d,i,k;

    k=0;
    cin>>a>>b>>C;
    for(i=a;i<=b;i++){
        d=C%i;
        if(d==0){
            k=k+1;
        }
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))

int main(){
	string s;
    cin >> s;
    map<char,int> m;
    rep(i,0,s.size())m[s[i]]++;
    rep(i,0,26){
        if(m[(char)('a'+i)] % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

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

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		char[] wk = next().toCharArray();
		for (int i = 1; i < wk.length; i++) {
			if (wk[i] == wk[i - 1]) {
				out.println("Bad");
				return;
			}
		}
		out.println("Good");
	}

	private void solveB() {
		int n = nextInt();
		int l = nextInt();

		int total = 0;
		int temp = Integer.MAX_VALUE;
		for (int i = 1; i <= n; i++) {
			total += l + i - 1;
			if (Math.abs(temp) > Math.abs(l + i - 1)) {
				temp = (l + i - 1);
			}
		}
		out.println(total - temp);
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
void ok(){
	cout << "Yes" << endl;
	exit(0);
}
 
void ng(){
	cout <<  "No" << endl;
	exit(0);
}
 
int p[324000], n;
 
int main(){
	cin >> n;
	for(int i  = 0;i < n;i++){
		cin >> p[i];
		if(i % 2 == p[i] % 2)ng();
	}
 
		for(int i = n-3;i >= 0;i--){
			int a = p[i], b = p[i+1], c = p[i+2];
			if(a > b && b > c){
				swap(p[i], p[i+2]);
			}
		}
		for(int i = 1;i < n-1;i++){
		int a = p[i-1], b = p[i], c = p[i+1];
		if((a > c) && (a < b || b < c))ng();
	}
	ok();
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ <<"]"<< pp(x)
#define dg2(x,y) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y)
#define dg3(x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x , y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

int mat[3003][3003];
int dp[3003][3003][4];
int N , M , K;

int cal(int i ,int j , int r) {
  if(i >= N) return 0;
  if(j >= M) return 0;
  if(dp[i][j][r] != -1) return dp[i][j][r];
  int ans = 0;
  // ans = max({ans , cal(i , j + 1, r), cal(i+1 , j , 0)});
  int a = cal(i , j + 1, r);
  int b = cal(i + 1, j , 0);
  int x = 0 , y = 0;
  if(r < 3) {
    x = cal(i ,j + 1, r + 1) + mat[i][j];
    y = cal(i + 1, j , 0) + mat[i][j];
  }
  return dp[i][j][r] = max({ans , x , y,a,b});
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> K;
  for(int i = 0; i < K; i++) {
    int r , c, v;
    cin >> r >> c >> v;
    r--,c--;
    mat[r][c] = v;
  }   
  clr(dp , -1);
  int ans = cal(0, 0, 0);
  cout << ans << '\n';
}

Measured memory_bytes: 356496
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


ll binomial(ll N, ll K) {
	if (K < 0 || N < K) return 0;
	ll ret = 1;
	for (int i = 1; i <= K; ++i) {
		ret *= N--;
		ret /= i;
	}
	return ret;
}


int main() {


	ll n, ans = 0, mon = 1;
	cin >> n;
	vector<string>v;
	for (int i = 0; i < n; ++i) {
		string h;
		cin >> h;
		sort(all(h));
		v.push_back(h);
	}

	sort(all(v));
	if (v[0] == v[v.size() - 1]) { cout << binomial((ll)v.size(), (ll)2) << endl; return 0; }
	for (int i = 1; i < n; ++i) {
		if (v[i] == v[i - 1]) { ++mon; }
		else { ans += binomial(mon, 2); mon = 1; }
	}
	//cout << binomial(100000, 2) << endl;
	cout << ans + binomial(mon, 2) << endl;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, a[200005], b[200005];
int main() {
	n=readint();
	rep(i,1,n) a[i]=readint();
	int x=1, y=n;
	repd(i,n,1) {
		if ((n-i+1)&1) {
			b[x++]=a[i];
		} else {
			b[y--]=a[i];
		}
	}
	rep(i,1,n) {
		printint(b[i]);printchar(' ');}
	return 0;
}


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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

print(min(N%K,abs(K-N%K)))


Measured memory_bytes: 72796
#include <cstdio>

#define N 100
int main(){
    int a[N+1][N+1] = {};

    int n;
    std::scanf("%d", &n);

    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        int m;
        std::scanf("%d", &m);
        for(int j = 1; j <= m; ++j){
            int x;
            std::scanf("%d", &x);
            a[id][x] = 1;
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            std::printf("%d", a[i][j]);
            if(j != n) std::printf(" ");
            else std::printf("\n");
        }
    }

    return 0;
}



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

using namespace std;

#define MAX 51

struct State{
  int x1,y1,x2,y2;
  State(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

int H, W;
char f1[MAX][MAX], f2[MAX][MAX];
bool vis[MAX][MAX][MAX][MAX];
const int lx[] = {0,-1,1,0};
const int ly[] = {-1,0,0,1};
const int rx[] = {0,1,-1,0};
const int ry[] = {-1,0,0,1};

bool inField(int y, int x){
  return 0 <= y && y < H && 0 <= x && x < W;
}

bool bfs(int Lx, int Ly, int Rx, int Ry){
  memset(vis, false, sizeof(vis));
  queue<State> Q;
  Q.push(State(Lx, Ly, Rx, Ry));

  while(!Q.empty()){
    State s = Q.front(); Q.pop();

    if(f1[s.y1][s.x1] == '%' && f2[s.y2][s.x2] == '%'){
      return true;
    }

    for(int i = 0 ; i < 4 ; i++){
      int nlx = s.x1 + lx[i], nly = s.y1 + ly[i];
      int nrx = s.x2 + rx[i], nry = s.y2 + ry[i];

      if(!inField(nly, nlx) || f1[nly][nlx] == '#'){
        nlx = s.x1;
        nly = s.y1;
      }
      if(!inField(nry, nrx) || f2[nry][nrx] == '#'){
        nrx = s.x2;
        nry = s.y2;
      }

      if((f1[nly][nlx] == '%' && f2[nry][nrx] != '%') ||
         (f1[nly][nlx] != '%' && f2[nry][nrx] == '%')) continue;

      if(vis[nly][nlx][nry][nrx]) continue;
      vis[nly][nlx][nry][nrx] = true;
      Q.push(State(nlx, nly, nrx, nry));
    }
  }

  return false;
}

int main(){
  while(cin >> W >> H, (W | H)){
    string str;
    int Lx, Ly, Rx, Ry;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < 2 ; j++){
        cin >> str;
        for(int k = 0 ; k < W ; k++){
          if(j % 2 == 0){
            f1[i][k] = str[k];
            if(f1[i][k] == 'L'){
              Lx = k;
              Ly = i;
            }
          }else{
            f2[i][k] = str[k];
            if(f2[i][k] == 'R'){
              Rx = k;
              Ry = i;
            }
          }
        }
      }
    }
    cout << (bfs(Lx, Ly, Rx, Ry) ? "Yes" : "No") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 8756
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

// const int N = ;
int n;

int main() {
	ios_base::sync_with_stdio(false);
	int x, l;
	cin >> n >> x;
	int d = 0, ans = 1;
	for(int i = 1; i <= n; i++) {
		cin >> l;
		d += l;
		ans += (d <= x);
	}
	cout << ans << '\n';
}	

	

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

vector<set<ll>> net;

vector<ll> dist;

void bfs(ll s){
    dist.resize(net.size(), -1);
    dist.at(s) = 0;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll x = q.front();
        q.pop();
        for(ll y : net.at(x)){
            if(dist.at(y) == -1){
                dist.at(y) = dist.at(x) + 1;
                q.push(y);
            }
        }
    }
}

int main(){
    ll n;
    cin >> n;
    net.resize(n);

    REP(i, n){
        string s;
        cin >> s;
        REP(j, n){
            if(s.at(j) == '1'){
                net.at(i).insert(j);
                net.at(j).insert(i);
            }
        }
    }

    // REP(i, n){
    //     for(ll j : net.at(i)){
    //         for(ll k : net.at(j)){
    //             if(net.at(k).count(i)){
    //                 cout << -1 << endl;
    //                 return 0;
    //             }
    //         }
    //     }
    // }

    ll ans = 2;
    REP(i, n){
        fill(dist.begin(), dist.end(), -1);
        bfs(i);
        for(ll j = 0; j < n; ++j){
            for(ll k : net.at(j)){
                if(dist.at(j) == dist.at(k)){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
        ans = max(ans, *max_element(dist.begin(), dist.end()) + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176