akhauriyash/Code-Regression huggingface dataset:
using System;

public static class Solution
{
  private static int[] s_weights;
  private static int[] s_values;
  private static int s_maxWeight;
  private static long[,] s_memo;

  public static void Main()
  {
    string[] nw = Console.ReadLine().Split(' ');
	int n = int.Parse(nw[0]);
    s_maxWeight = int.Parse(nw[1]);

    s_weights = new int[n];
    s_values = new int[n];
	s_memo = new long[n, s_maxWeight];
    for (int i = 0; i < n; i++)
    {
      string[] wv = Console.ReadLine().Split(' ');
	  s_weights[i] = int.Parse(wv[0]);
      s_values[i] = int.Parse(wv[1]);
	  for (int j = 0; j < s_maxWeight; j++) s_memo[i, j] = -1;
    }
    Console.WriteLine(Solve(s_maxWeight, n));
  }

  private static long Solve(int weightLeft, int numberOfItemsToConsider)
  {
    if (weightLeft == 0 || numberOfItemsToConsider == 0) return 0;
	if (s_memo[numberOfItemsToConsider - 1, weightLeft - 1] != -1) return s_memo[numberOfItemsToConsider - 1, weightLeft - 1];
    long dontTakeCurrent = Solve(weightLeft, numberOfItemsToConsider - 1);
	if (weightLeft >= s_weights[numberOfItemsToConsider - 1])
	{
      long takeCurrent = s_values[numberOfItemsToConsider - 1] + Solve(weightLeft - s_weights[numberOfItemsToConsider - 1], numberOfItemsToConsider - 1);
	  return s_memo[numberOfItemsToConsider - 1, weightLeft - 1] = Math.Max(takeCurrent, dontTakeCurrent);
	}
	return s_memo[numberOfItemsToConsider - 1, weightLeft - 1] = dontTakeCurrent;
  }                          
}

Measured memory_bytes: 105148
#include <cstdio>
#include <algorithm>

using namespace std;

int v[110];

int main()
{
    //freopen("file.in","r",stdin);
   // freopen("file.out","w",stdout);
    int n,s=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        s+=v[i];
    }
    if(s%10!=0) {printf("%d",s);return 0;}
    sort(v+1,v+n+1);
    for(int i=1;i<=n;i++)
        if((s-v[i])%10!=0) {printf("%d",s-v[i]);return 0;}
    printf("0");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define min(a,b)((a)<(b)?(a):(b))

int n,k,t[1000],c;
int a,b;

int main(void){
	scanf("%d",&n);
	scanf("%d",&k); 
	for(c=0;c<k;c++){
		scanf("%d %d",&a,&b);
		t[c]=min(a-1,min(n-a,min(b-1,n-b)))%3+1;
	}
	for(c=0;c<k;c++){
		printf("%d\n",t[c]);
	}
	
	return 0;
}

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

const ll logx=30;
const ll N=2e5+5;
const ll M=3e5+5;
const ll mod=1e9+7;
const ll INF=1e18+5;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main()
{
  ll n,l;
  cin>>n>>l;
  ll sum=0;
  ll mini=INF,out;
  vector<ll> v;
  for(ll i=0;i<n;i++){v.pb(l+i);sum+=(l+i);}
  for(auto i:v)
  {
    ll dif=abs(i);
    if(mini>dif)
    {
      mini=dif;
      out=sum-i;
    }
  }
  cout<<out<<endl;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x=int(input())
    l=[]
    for i in range(1,33):
        for j in range(2,11):
            y=i**j
            if y<x:
                l.append(y)
            elif y==x:
                l.append(y)
                break
            else:
                break
    print(max(l))
resolve()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
void test_cases(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> v(k);
    for(int i = 0; i < k; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<int> pref(n, 0), dp(n, 0);
    dp[0] = 1;
    pref[0] = 1;
    for(int i = 1; i < n; i++){
        int sum = 0;
        for(int j = 0; j < k; j++){
            int r = i - v[j].first;
            int l = i - v[j].second;
//            cout << l << " " << r << endl;
            if(r >= 0 ) sum = (sum + pref[r]) % mod;
            if(l - 1 >= 0) sum = (sum + mod - pref[l - 1]) % mod;
//            sum = (sum + mod + pref[r] - pref[l - 1]) % mod;
        }
        dp[i] = sum;
        pref[i] = (pref[i - 1] + dp[i] + mod) % mod;
    }
    cout << dp[n - 1];
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt = 1;
//    cin >> tt;
    while(tt--){
        test_cases();
    }
    return 0;
}


Measured memory_bytes: 6364
while True:
    H, W = map(int, input().split())
    if not(H or W):
        break
    for i in range(H):
        if i % 2:
            print('.#' * (W // 2) + '.' * (W % 2))
        else:
            print('#.' * (W // 2) + '#' * (W % 2))
    print()

Measured memory_bytes: 7624
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
int rint();char rch();long long rlong();
int a[13];
int b[25];
int main() 
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; scanf("%d",&n);
  for (int i=0;i<n;i++) {
    int x;scanf("%d",&x);
    a[x]++;
  }
  a[0]++;
  int ans=0;
  for (int z=0;z<(1<<13);z++) {
    memset(b,0,sizeof b);
    int cand=24;
    for (int x=0;x<=12;x++) {
      int half=a[x]/2;
      int other=(a[x]+1)/2;
      if (z&(1<<x)) {
        swap(half,other);
      }
      b[24-x]+=half;
      b[x]+=other;
    }
    b[0]+=b[24];
    for (int x=0;x<24;x++) {
      if (b[x]>=2) cand=0;
      if (b[x]) for (int y=0;y<x;y++) {
        if (b[y]) {
          int d=x-y;
          chkmin(cand,min(d,24-d));
        }
      }
    }
    chkmax(ans,cand);
  }
  printf("%d\n",ans);
}




static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof (stdinBuffer);
static const char* stdinPos = stdinDataEnd;

void readAhead(size_t amount)
{
    size_t remaining = stdinDataEnd - stdinPos;
    if (remaining < amount) {
       memmove(stdinBuffer, stdinPos, remaining);
       size_t sz = fread(stdinBuffer + remaining, 1, sizeof (stdinBuffer) - remaining, stdin);
       stdinPos = stdinBuffer;
       stdinDataEnd = stdinBuffer + remaining + sz;
       if (stdinDataEnd != stdinBuffer + sizeof (stdinBuffer))
         *stdinDataEnd = 0;
    }
}

int rint()
{
    readAhead(16);

    int x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}
char rch()
{
    readAhead(16);
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    char ans=*stdinPos;
    ++stdinPos;
    return ans;
}
long long rlong()
{
    readAhead(32);

    long long x = 0;
    bool neg = false;
    while(*stdinPos==' '||*stdinPos=='\n') ++stdinPos;
    if (*stdinPos == '-') {
       ++stdinPos;
       neg = true;
    }

    while (*stdinPos >= '0' && *stdinPos <= '9') {
       x *= 10;
       x += *stdinPos - '0';
       ++stdinPos;
    }

    return neg ? -x : x;
}

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

int n [101];
int main()
{
  int num;
  while (cin >> num){
    n[num]++;
  }
  int max = 0;
  for (int i = 1; i <= 100; i++){
    if (max <= n[i]){
      max = n[i];
    }
  }
  for (int i = 1; i <= 100; i++){
    if (max == n[i]){
      cout << i << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	int k,i;
	char s[100];
	scanf("%d",&k);
	scanf("%s",s);
	int l = strlen(s);
	if(l>k)
	{
		for(i=0; i<k; i++)
		{
			printf("%c",s[i]);
		}
		printf("...");
	}
	else{
	printf("%s",s);
}
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100003;

int n,w[maxn],head[maxn],siz[maxn];
struct EDGE{
	int to,nxt;
}edge[maxn<<1];
void addedge(int u,int v){
	static int sz=0;edge[++sz].nxt=head[u];
	edge[sz].to=v;head[u]=sz;
}
ll d[maxn],dis[maxn],sum[maxn];
map<ll,int> mp;
vector<pii> v; 

void dfs(int u,int pre){
	int to;siz[u]=1;
	for(int i=head[u];i;i=edge[i].nxt){
		to=edge[i].to;
		if(to==pre) continue;
		dfs(to,u);
		sum[u]+=sum[to]+siz[to];
		siz[u]+=siz[to];
	}
}

void dfs1(int u,int pre){
	int to;
	for(int i=head[u];i;i=edge[i].nxt){
		to=edge[i].to;
		if(to==pre) continue;
		dis[to]=dis[u]+n-2*siz[to];
		dfs1(to,u);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%lld",&d[i]);
		mp[d[i]]=i;
		w[i]=1;
	}
	for(int i=1;i<n;++i){
		pair<ll,int> p=*mp.rbegin();
		int u=p.second;
		ll want=d[u]-n+2*w[u];
		if(mp.find(want)==mp.end()){
			puts("-1");
			return 0;
		}
		int to=mp[want];
		v.push_back(make_pair(u,to));
		addedge(u,to);
		addedge(to,u);
		w[to]+=w[u];
		mp.erase(--mp.end());
	}
	dfs(1,0);
	dis[1]=sum[1];
	dfs1(1,0);
	for(int i=1;i<=n;++i)
		if(dis[i]!=d[i]){
			puts("-1");
			return 0;
		}
	for(int i=0;i<v.size();++i)
		printf("%d %d\n",v[i].first,v[i].second);
	return 0;
}



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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int n;
int a[N], b[N], c[N];
LL sum[N], cnt[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++) scanf("%d", b + i);
    for(int i = 1; i <= n; i++) scanf("%d", c + i);
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    sort(c + 1, c + 1 + n);

    for(int i = 1, j = 1; i <= n; i++)
    {
        while(j <= n && b[i] >= c[j]) j++;
        cnt[i] = n - j + 1;
    }

    for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + cnt[i];

    LL res = 0;
    for(int i = 1, j = 1; i <= n; i++)
    {
        while(j <= n && a[i] >= b[j]) j++;
        res += sum[n] - sum[j - 1];
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 2944
N = int(input())
A = list(map(int, input().split()))
ans = 0

d = {}

for i, a in enumerate(A):
    tmp = i + 1 - a
    if tmp in d.keys():
        d[tmp] += 1
    else:
        d[tmp] = 1

# print(d)

for i, a in enumerate(A):
    tmp = a + i + 1
    tmptmp = i + 1 - a
    if tmp in d.keys():
        ans += d[tmp]
    if tmptmp in d.keys():
        d[tmptmp] = max(0, d[tmptmp] - 1)

print(ans)


Measured memory_bytes: 40528
n, k = map(int, input().split())
s = input()

if k == 1:
    print(s[0].lower() + s[1:])
elif k == n:
    print(s[:k-1] + s[k-1].lower())
else:
    print(s[:k-1] + s[k-1].lower() + s[k:])

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
 
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> da(n,vector<int>(0));
    vector<int> dp(n,0);
    vector<int> ju(n,0);
    for(int i=0;i<m;i++){
        int x,y;
        cin >> x >> y;
        ju[y-1]+=1;
        da[x-1].push_back(y-1);
    }
    queue<int> q;
    for(int i=0;i<n;i++){
        if(ju[i]==0){
            q.push(i);
        }
    }
    int ans=0;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=0;i<da[x].size();i++){
            ju[da[x][i]]--;
            if(dp[da[x][i]]<=dp[x]){
                ans=max(ans,dp[x]+1);
                dp[da[x][i]]=dp[x]+1;
            }
            if(ju[da[x][i]]==0){
                q.push(da[x][i]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <iostream>
#include <map>

using namespace std;

const int CMax = 100000005;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    if (n <= m) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)

	dx := x2 - x1
	dy := y2 - y1

	fmt.Println(x2-dy, y2+dx, x1-dy, y1+dx)
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	long double x,sum=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>s;
		if(s=="JPY"){
			sum+=x;
		}else{
			sum+=380000.0*x;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1e9;

const ll INF = 1LL << 60;

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


int main(){
  int n;ll k;cin>>n>>k;
  int dp[200005][60];
  rep(i,n){cin>>dp[i][0];dp[i][0]--;}
  for(int j=1;j<60;j++)rep(i,n)dp[i][j]=dp[dp[i][j-1]][j-1];
  int ans=0;
  
  rep(i,60)if(k & (1LL<<i)){
    ans=dp[ans][i];
  }
  cout<< ans+1;
}



Measured memory_bytes: 50472
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
 
a,b,c,k = Mi()
if k <= a:
  print(k)
  exit(0)
ans = a
k -= a
if k > b:
  ans -= k-b
  
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		A, B int
		T    float64
	)
	fmt.Scanf("%d %d %f\n", &A, &B, &T)
	T += 0.5
	ans := int(T/float64(A)) * B
	fmt.Println(ans)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WriteandErase
{
    class WriteandErase
    {
        static void Main(string[] args)
        {
            int intCnt = int.Parse(Console.ReadLine());

            // 動的配列宣言
            List<int> intArray = new List<int>();

            for (int i = 0; i < intCnt; i++)
            {
                int intWK = int.Parse(Console.ReadLine());

                // 配列に追加
                intArray.Add(intWK);
            }

            var sortedW = intArray
                .GroupBy(i => i)
                .Where(g => g.Count() % 2 == 1)
                ;


 

            Console.WriteLine(sortedW.Count());

            // for debug
            return;
        }
    }
}


Measured memory_bytes: 27372
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int dp[1<<15][20], dp2[15][15];
vector<string> t;

int intersect(int i, int j){
    if(dp2[i][j] > 0) return dp2[i][j];
    int ret = min(t[i].size(), t[j].size());
    while(ret > 0){
        bool f = 1;
        rep(k, ret){
            if(t[i][t[i].size()-ret+k] != t[j][k]){
                f = 0;
                break;
            }
        }
        if(f) break;
        ret--;
    }
    ret = t[j].size()-ret;
    // cout << ret << " : " << t[i] << ", " << t[j] << endl;
    return dp2[i][j] = ret;
}

int main(){
    fastcin();

    int n;
    cin >> n;
    while(n > 0){
        vector<string> s(n);
        t.clear();
        rep(i, n) cin >> s[i];
        vector<int> use(n, 1);
        rep(i, n)rep(j, n){
            if(!use[i] || !use[j]) continue;
            if(s[i].size() <= s[j].size()) continue;
            if(s[i].find(s[j]) != string::npos){
                use[j] = 0;
            }
        }
        rep(i, n)if(use[i]) t.push_back(s[i]);
        n = t.size();

        rep(i, (1<<15))rep(j, 20) dp[i][j] = INF;
        memset(dp2, 0, sizeof(dp2));
        rep(i, n){
            dp[1<<i][i] = t[i].size();
        }
        rep(i, (1<<n))rep(j, n){
            if((i&(1<<j)) == 0) continue;
            rep(k, n)if((i&(1<<k)) == 0){
                chmin(dp[i|(1<<k)][k], dp[i][j] + intersect(j, k));
            }
        }
        int ans = INF;
        rep(i, n) chmin(ans, dp[(1<<n)-1][i]);
        cout << ans << endl;
        cin >> n;
    }
}


Measured memory_bytes: 5676
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  while(true){
    int w,h;
    cin>>h>>w;
    if(!h&&!w)
      break;
    vector<string> room;
    for(int i=0;i<h;i++){
      string line;
      cin>>line;
      room.push_back(line);
    }
    int x,y;
    x=y=0;
    bool move = true;
    while(move){
      switch(room[y][x]){
      case'>':
	room[y][x] = '@';
	x++;
	break;
      case'<':
	room[y][x] = '@';
	x--;
	break;
      case'^':
	room[y][x] = '@';
	y--;
	break;
      case'v':
	room[y][x] = '@';
	y++;
	break;
      case'.':
	cout<<x<<" "<<y<<endl;
	move = false;
	break;
      case'@':
	cout<<"LOOP"<<endl;
	move = false;
	break;
      default:
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=[(0,0)]
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q+=[(w,d)]
print(*f)

Measured memory_bytes: 113360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
int n;
cin >> n;
map<int,int> mp;
rep(i,n){
  int a;
  cin >> a;
  mp[a]++;
}
int cnt  = 0;
for(auto itr = mp.begin(); itr != mp.end(); itr++){
  int x = itr->second;
  if(x%2!=0)cnt++;
}
cout << cnt << endl;
}

Measured memory_bytes: 8120
#include<bits/stdc++.h>
using namespace std;
const int W = 29, N = 2e5 + 87;
void ct_sort(int *& a, int *& v,int k, int n)
{
    int c[2] = {};
    for (int i = 0; i < n; ++i)
        ++c[a[i]>>k&1];
    c[1] += c[0];
    for (int i = n - 1; i >= 0; --i)
        v[--c[a[i]>>k&1]] = a[i];
    swap(a, v);
}
int g(int x,int k) {return x & ((1 << (k + 1)) - 1);}
int mem[3][N], n;
int * a = mem[0], * b = mem[1], * v = mem[2];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    int ans = 0;
    for (int k = 0; k < W; ++k) {
        ct_sort(a,v,k,n);
        ct_sort(b,v,k,n);
        int l,r,p=1<<k,c=0;
        l = r = n;
        for (int i = 0; i < n; ++i) {
            while (l - 1 >= 0 && g(a[l-1],k) >= p - g(b[i],k))
                --l;
            while (r - 1 >= 0 && g(a[r-1],k) >= 2 * p - g(b[i],k))
                --r;
            c = (r - l + c) & 1;
        }
        l = r = n;
        for (int i = 0; i < n; ++i) {
            while (l - 1 >= 0 && g(a[l-1],k) >= 3 * p - g(b[i],k))
                --l;
            while (r - 1 >= 0 && g(a[r-1],k) >= 4 * p - g(b[i],k))
                --r;
            c = (r - l + c) & 1;
        }
        ans |= c<<k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  double Ave;
  
  cin >> A >> B ;
  Ave = (A+B) / 2.0;
  C = (A+B)/2;
  if(C<Ave){
    cout << C + 1 << endl ;
  }else{
    cout << C << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
int pre[1002];
int res[1002][1002];
int main() {
    int n = read();
    int cnt = 0;
    while (1) {
        cnt++;
        pre[cnt] = pre[cnt - 1] + cnt;
        if (pre[cnt] >= n) break;
    }
    if (pre[cnt] != n) {
        puts("No");
        return 0;
    }
    puts("Yes");
    printf("%d\n", cnt + 1);
    int tmp = 0;
    for (int i = 1; i <= cnt + 1; ++i) {
        for (int j = i + 1; j <= cnt + 1; ++j) {
            res[i][j] = ++tmp;
            res[j][i] = tmp;
        }
    }

    for (int i = 1; i <= cnt + 1; ++i) {
        printf("%d ", cnt);
        for (int j = 1; j <= cnt + 1; ++j) {
            if (i == j) continue;
            printf("%d ", res[i][j]);
        }
        puts("");
    }
    return 0;
}

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

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<long long> money;
    for(int i=0;i<n;i++){
        long long mon;
        cin >> mon;
        money.push(mon);
    }
    for(int i =0;i<m;i++){
        long long cur = money.top();
        money.pop();
        cur = cur/2;
        money.push(cur);
    }
    long long sum = 0;
    for(int i=0;i<n;i++){
        sum+=money.top();
        money.pop();
    }
    cout << sum;
}

Measured memory_bytes: 1400
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, const tuple<T...> &t){
    os << (n == 0 ? "" : " ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T> ostream &operator << (ostream &os, const tuple<T...> &t){
    _ot<0>(os, t); return os;
}
template<class T, class U> ostream & operator << (ostream &os, const pair<T,U> &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T> ostream &operator << (ostream &os, const vector<T> &v){
    for(size_t i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : ", "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << make_tuple(__VA_ARGS__) \
                   << " (L : " << __LINE__ << ")" << endl)
#else
#define dump(...)
#endif
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); }
int const mod = 1000000007;
auto const inf = numeric_limits<int>::max()/8;

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

struct UnionFind {
    vector<int> par;
    int cnt;
    UnionFind(int size_) : par(size_, -1), cnt(size_) { }
    bool merge(int x, int y){
        x = find(x); y = find(y);
        if (x != y) {
            if (par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
        return x != y;
    }
    bool get(int x, int y){ return find(x) == find(y); }
    int find(int x){ return par[x] < 0 ? x : par[x] = find(par[x]); }
    int size(int x){ return -par[find(x)]; }
    int size(){ return cnt; }
};

bool operator < (const Edge &e, const Edge &f){ return e.weight > f.weight; }
pair<Weight, Edges> kruskal(Graph const& g){
    UnionFind uf(g.size());
    Edges es; rep(i, g.size()) for(auto &e : g[i]) es.emplace_back(e);
    sort(all(es)); reverse(all(es)); // !! INVERSE !!
    Weight total = 0; Edges T;
    for(auto &e : es){
        if(uf.get(e.src,e.dst)) continue;
        T.push_back(e); total += e.weight; uf.merge(e.src,e.dst);
    }
    return make_pair(total, T);
}

int main(){
    int n;
    cin >> n;
    Graph g(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int x;
            cin >> x;
            if(x != -1) g[i].emplace_back(i,j,x);
        }
    }
    cout << kruskal(g).first << endl;
}

Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			int n  =cin.nextInt();
			int m  =cin.nextInt();
			if(n+m==0){
				break;
			}
			int[] a = new int[n];
			int[] b = new int[m];
			int asum=0,bsum=0;
			for(int i = 0;i<n;i++){
				a[i]=cin.nextInt();
				asum+=a[i];
			}
			for(int j = 0;j<m;j++){
				b[j]=cin.nextInt();
				bsum+=b[j];
			}
			int x=0,y=0,min=Integer.MAX_VALUE;
			for(int i = 0;i<n;i++){
				for(int j = 0;j<m;j++){
					asum = asum + b[j]-a[i]; 
					bsum = bsum + a[i]-b[j];
					if(asum==bsum){
						if(min>a[i]+b[j]){
							x=a[i];
							y=b[j];
							min=a[i]+b[j];
						}
					}
					asum += a[i]-b[j];
					bsum += b[j]-a[i];
				}
			}
			if(min==Integer.MAX_VALUE){
				System.out.println(-1);
			}
			else{
				System.out.println(x+" "+y);
			}
		}

	}

}

Measured memory_bytes: 12000
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val strs = Array(N) { readLine()!!.toCharArray().sorted().joinToString("") }

    val map = mutableMapOf<String, Long>()
    for (str in strs) {
        val cnt = map[str] ?: 0L
        map[str] = cnt + 1
    }
//    map.forEach {
//        println("${it.key} ${it.value}")
//    }
    map.values.map { ((it / 2.toDouble()) * (it - 1)).toLong() }
//        .forEach(::println)
        .sum().let(::println)

}



Measured memory_bytes: 79340
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
j=M
ans=0
for i in range(N+1):
  if a[i] > K:
    break
  else:
    while b[j] > K - a[i]:
      j-=1
      if j<0:
        break
    if K>=a[i]+b[j]:
      ans=max(ans,i+j)
print(ans)

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

using namespace std;


#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)

const int MOD = 1000000007;



int main(){
    ll w,h; cin>> w >> h;
    if(w==1 || h ==1) cout << 1;
    else cout << ((w+1)/2)*((h+1)/2) + (h/2)*(w/2) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }
 
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(rall(a));
  ll ans = 0;
  rep(i, 1, n){
    ans += a[i/2];
  }
  cout << ans << endl;
  return 0;
}

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

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

	std::string S;
	std::cin >> S;
	std::string first(S.substr(0, 2)), second(S.substr(2, 2));
	int N = 0;

	if (1 <= std::atoi(first.c_str()) && std::atoi(first.c_str()) <= 12) {
		N |= 1;
	}

	if (1 <= std::atoi(second.c_str()) && std::atoi(second.c_str()) <= 12) {
		N |= 2;
	}

	switch (N) {
	case 0:
		std::cout << "NA";
		break;
	case 1:
		std::cout << "MMYY";
		break;
	case 2:
		std::cout << "YYMM";
		break;
	case 3:
		std::cout << "AMBIGUOUS";
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
  int main() {
  int i, k, n, m, max, idx, data[1000], data2[1000], data3[1000] = {0};
  scanf("%d %d", &n, &m);
  for(i = 0; i < n; i++) {
    scanf("%d", &data[i]);
  }
  for(i = 0; i < m; i++) {
    scanf("%d", &data2[i]);
  }
  for(i = 0; i < m; i++) {
    for(k = 0; k < n; k++) {
      if(data2[i] >= data[k]) {
        idx = k;
        break;
      }
    }
    data3[idx]++;
  }
  max = 0;
  for(i = 0; i < n; i++) {
    if(max < data3[i]) {
      max = data3[i];
      idx = i;
    }
  }
  printf("%d\n", idx +1);
  return 0;
}

Measured memory_bytes: 608
package main

import "fmt"

func search(n int, a int, b int, c int, s []string, temp []string) ([]string, bool){
	x := len(temp)
	var ans []string
	var flag bool
	if x == n {
		return temp, true
	}
//fmt.Println("search : n,a,b,c,s,temp ",n,a,b,c,s,temp)
	if s[x][0:1] == "A" {
		if a > 0 {
			if s[x][1:2] == "B" {
//fmt.Println("AB,a>0")
				ans,flag = search(n,a-1,b+1,c,s,append(temp,"B"))
				if !flag && b > 0{
//fmt.Println("AB,a>0->NG b>0")
					ans,flag = search(n,a+1,b-1,c,s,append(temp,"A"))
				}
			} else {
//fmt.Println("AC,a>0")
				ans,flag = search(n,a-1,b,c+1,s,append(temp,"C"))
				if !flag && c > 0 {
//fmt.Println("AC,a>0->NG c>0")
					ans,flag = search(n,a+1,b,c-1,s,append(temp,"A"))
				}
			}
		} else {
			if s[x][1:2] == "B" {
				if b > 0 {
//fmt.Println("AB,a<=0,b>0")
					ans,flag = search(n,a+1,b-1,c,s,append(temp,"A"))
				}
			} else {
				if c > 0 {
//fmt.Println("AC,a<=0->NG c>0")
					ans,flag = search(n,a+1,b,c-1,s,append(temp,"A"))
				}
			}
		}
	} else {
		if b > 0 {
//fmt.Println("BC,b>0")
			ans,flag = search(n,a,b-1,c+1,s,append(temp,"C"))
			if !flag && c > 0 {
//fmt.Println("BC,b>0->NG c>0")
				ans,flag = search(n,a,b+1,c-1,s,append(temp,"B"))
			}
		} else {
			if c > 0{
//fmt.Println("BC,b<=0,c>0")
				ans,flag = search(n,a,b+1,c-1,s,append(temp,"B"))
			}
		}
	}
//fmt.Println("return search : n,a,b,c,s,temp ",n,a,b,c,s,temp)
//fmt.Println("return : ans,flag  ",ans,flag)
	return ans, flag
}



func main(){
	var n,a,b,c int
	fmt.Scan(&n,&a,&b,&c)
	s := make([]string,n)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&s[i])
        }
	var temp []string
	ans, flag := search(n,a,b,c,s,temp)
	if flag {
		fmt.Println("Yes")
		for i:=0 ; i<n ; i++ {
			fmt.Println(ans[i])
		}
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 38388
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    let n = b - a;
    let tb = n * (n + 1) / 2;
    println!("{}", tb - b);
}


Measured memory_bytes: 4352
--bin search

import Data.Array


--assume that input array was sorted by assending

find::Array Int Int ->Int->(Int,Int)->Bool
find ar x (start,end)  =  let mid = div (start + end) 2 in
                          if (ar!mid ==x) || (ar!start ==x) || (ar!end ==x) then True else
                          if end - start <=1 then False else
                          if (ar!mid) > x then find ar x (start+1,mid-1) else
                          if (ar!mid) < x then find ar x (mid+1,end-1) else  False



--first
solver::Array Int Int -> [Int] -> Int
solver s t = sum (map (\ x -> if find s x (bounds s) then 1 else 0) t)

main::IO()
main = do
  nc<-getLine
  let n = read nc
  sc<-getLine
  let s = map read (words sc)::[Int]
  let s_arr = listArray (1,n) s
  _<-getLine
  tc<-getLine
  let t = map read (words tc)::[Int]
  print (solver s_arr t)

Measured memory_bytes: 63336
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
 
 
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        A[i] = a - (i + 1);
    }
    sort(A.begin(), A.end());

    int med = A[N / 2];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(A[i] - med);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//2
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){

ios::sync_with_stdio(false);
cin.tie(0);
long long int n;
cin>>n;

long long int d[n]={};

for(long long int i=0;i<n;i++){
cin>>d[i];
}

sort(d,d+n);

long long int res=d[n/2]-d[n/2-1];



cout<<res<<endl;

}



//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;



Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
uint64_t gcd(uint64_t a, uint64_t b);
uint64_t lcm(uint64_t a, uint64_t b);

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

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

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

  if (N & 0x01) {
    cout << 0 << endl;
  } else {
    uint64_t res = N / 10;
    for (uint64_t div = 50; div < 1000000000000000000; div *= 5) {
      res += N / div;
    }
    cout << res << endl;
  }

  return 0;
}

uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

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

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  int N;
  cin >> N;
  ull L[N];
  L[0] = 2, L[1] = 1;
  rep_s(i, 2, N+1){
    L[i] = L[i-1]+L[i-2];
  }
  cout << L[N] << endl;
  
  
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);
  rep(i, k) {
    int l;
    cin >> l;
    rep(j, l) {
      int m;
      cin >> m;
      v[m - 1]++;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (v[i] == 0) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

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


if(N%X==0){
    System.out.println(T*((N-N%X)/X));

}else{
  System.out.println(T*((N-N%X)/X+1));

}
}
}


Measured memory_bytes: 35624
n = int(input())
ti,xi,yi = [0],[0],[0]
ans = 'No'

for ni in range(n):
 t,x,y = [int(x) for x in input().split()]
 ti.append(t)
 xi.append(x)
 yi.append(y)

for i in range(n):
  dt = ti[i+1] - ti[i]
  dx = xi[i+1] - xi[i]
  dy = yi[i+1] - yi[i]

  if dt < abs(dx)+abs(dy):
    break

  odev1 = (xi[i]+yi[i])%2
  odev2 = (xi[i+1]+yi[i+1])%2

  if dt%2 == 0:
    if odev1 != odev2:
      break
  else:
    if odev1 == odev2:
      break
  if i == n-1:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 11728
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

int main() {
  int n, K;
  scanf("%d%d", &n, &K);
  vector<vector<int>> graph(n, vector<int>(n,0));
  int curcnt = (n - 1)*(n - 2) / 2;
  if (K > curcnt) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    graph[0][i] = 1;
    graph[i][0] = 1;
  }
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (curcnt > K) {
        graph[i][j] = 1;
        graph[j][i] = 1;
        curcnt--;
      }
    }
  }
  vector<pair<int, int>> edges;
  for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) {
    if (graph[i][j]) {
      edges.emplace_back(j + 1, i + 1);
    }
  }
  printf("%d\n", (int)edges.size());
  for (auto e : edges) {
    printf("%d %d\n", e.first, e.second);
  }
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    long long int a,b;
    scanf("%lld %lld",&a, &b);
    if(a!=1 && b!=1){
      printf("1");
    }
    else if(a!=2 && b!=2){
      printf("2");
    }
    else {
      printf("3");
    }
   
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL n, z, w;
  cin>>n>>z>>w;
  VEC<LL> a(n);
  REP(i,0,n)cin>>a[i];
  LL ans;
  if(n==1){
    ans=abs(a[n-1]-w);
  }else{
    ans=max(abs(a[n-1]-w), abs(a[n-2]-a[n-1]));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000

using namespace std;

typedef string str;
typedef long long int ll;
const ll mod=1000000007;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mpl;


int main()
{
    ll k,s,i,j,c=0;
    cin>>k>>s;
    rep(i,0,k+1){
       rep(j,0,k+1)
       {
          if((s-i-j)<=k && (s-i-j)>=0){
            c++;
          }      
       }
    }
    cout<<c<<endl;
     return 0;
}

Measured memory_bytes: 256
n = gets.rstrip.to_i

graph = Hash.new{|h, k| h[k] = {} }
edges = (n-1).times.map{ gets.rstrip.split.map(&:to_i) }

edges.each do | from, to, len |
  graph[from][to] = len
  graph[to][from] = len
end

queue = [[1, 0]]
visited = {}
ans = Array.new(n)

until queue.empty?
  v, dist = queue.shift

  if dist.even?
    ans[v-1] = 0
  else
    ans[v-1] = 1
  end

  next if visited[v]
  visited[v] = true

  graph[v].each do | n, len |
    queue << [n, dist + len]
  end
end

puts ans


Measured memory_bytes: 51196
#include <iostream>
#include <cstdio>                                               //scanf,printf
#include <algorithm>                                            //max,min
#include <string>                                               //string
#include <cstring>                                              //strlen,strcat
#include <cctype>                                               //isalpha,tolower
#include <cmath>                                                //sqrt,sin
#include <stack>                                                //top,push
#include <queue>                                                //front,push
#include <vector>                                               //push_back,sort
#include <set>                                                  //insert,begin
#include <map>                                                  //insert,find
#include <list>                                                 //push_front,begin
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>                                               //pow,powf
#define INF (1<<30)
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1

int main(){
  int n[3];
  cin>>n[0]>>n[1]>>n[2];
  sort(n, n+3);
  
  int ans=0;
  if(n[1]<n[2]){
    ans+=n[2]-n[1];
    if((n[2]-n[0]-ans)%2==0){
      ans+=(n[2]-n[0]-ans)/2;
    }else{
      ans+=(n[2]-n[0]-ans)/2+2;
    }
  }else{
    if((n[2]-n[0])%2==0) ans+=(n[2]-n[0])/2;
    else ans+=(n[2]-n[0])/2+2;
  }
  
  cout<<ans<<en
}



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

int gcd (long long x , long long y){
    if(y>x){
        swap(x,y);
    }
    int z=x%y;
    if(z != 0){
        return(gcd(y,z));
    } else {
        return(y);
    }
}

signed main(){
    long long a , b , c , d , e;
    cin>>a>>b>>c>>d;
    e=c*d/gcd(c,d);
    a = a-1;
    cout<<(b-(b/c+b/d-b/e))-(a-(a/c+a/d-a/e))<<"\n";
    return(0);
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
	if (L > R) {
      cout << "Left" << endl;
    }
	else if (L == R) {
      cout << "Balanced" << endl;
    }
	else if (L < R) {
      cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

X=gets.to_i
ans=0
ans+=(X/500)*1000
ans+=((X%500)/5)*5
puts ans

Measured memory_bytes: 14300