akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,x=1,y,c=0;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    while(1){
        y=a[x-1];
        if(y==2){
            break;
        }
        x=y;
        c++;
        if(c>=100000){
            cout << -1;
            return 0;
        }
    }
    cout << c+1;
}

Measured memory_bytes: 640
#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 dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;

typedef long long LL;

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

    return os;
}

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

    int N, Q; cin >> N >> Q;
    string S; cin >> S;

    vector<int> C(N, 0);

    REP (i, N - 1) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            C[i + 1] = C[i] + 1;
        } else {
            C[i + 1] = C[i];
        }
    }

    REP (i, Q) {
        int l, r; cin >> l >> r;

        cout << C[r - 1] - C[l - 1] << endl;
    }
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
int main(){
  int f=0,s=0,sr=0,b;
  for(int i=0;i<10;i++){
    cin>>b;
    if(f<b){
      sr=s;
      s=f;
      f=b;
    }else if(s<b){
      sr=s;
      s=b;
    }else if(sr<b){
      sr=b;
    }
  }
  cout<<f<<endl<<s<<endl<<sr<<endl;
  return(0);
}



Measured memory_bytes: 3088
import sys

N = int(raw_input())

A = [0 for i in range(N)]

sum = 0
for i in range(N):
	A[i] = int(raw_input())
	sum += A[i]

A.sort()

if sum % 10 == 0:
	for i in A:
		if i % 10 != 0:
			print sum - i
			sys.exit()
	print 0
else:
	print sum

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

namespace AtCoder {
	class Program {
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static long cln(long D = -1) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return long.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion

		static void Main(string[] args) {
			var L = cins();
			int N = L[0], M = L[1], K = L[2];
			var aim = N * M - K;
			var res = false;
			for (int b = 0; b <= N; b++) {
				for (int a = 0; a <= M; a++) {
					if (aim == a * N + b * M - 2 * a * b) res = true;
				}
			}
			print(res?"Yes":"No");
			read();
		}
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=500005;
int n,q,d[maxn],a[maxn],b[maxn];
int main(){
	read(n);read(a[0]);
	rep(i,1,n){
		read(d[i]);
		a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	}
	per(i,n,1)b[i]=(b[i+1]>=d[i]/2)*d[i]+b[i+1];
	read(q);
	while(q--){
		int x;read(x);
		if(b[x+1]>=a[x-1])puts("NO");
		else puts("YES");
	}
	return 0;
}


Measured memory_bytes: 7808
N,M=map(int,input().split())
L=[[]for i in range(N+1)]
for i in range(M):
    s,t,d=map(int,input().split())
    L[s].append([t,d])

D=[{}for i in range(N+1)]
D[0][(0,0)]=0
#print(D)


for i in range(1,N+1):
    for k,v in D[i-1].items():
        P,dist=k
        for to,d in L[P]:
            Ndist=dist|1<<to
            if Ndist!=dist:
                if (to,Ndist) not in D[i]:
                    D[i][(to,Ndist)]=v+d
                else:
                    D[i][(to,Ndist)]=min(v+d,D[i][(to,Ndist)])
#print(D)
if len(D[-1])==0:
    print(-1)
else:
    for k,v in D[-1].items():
        if k[0]==0:
            print(v)
            exit()
    print(-1)


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

// THINK: INT vs LONG LONG?

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] != a[j]) {
				for (int k = j + 1; k < n; ++k) {
					if (a[k] != a[j] && a[k] != a[i]) {
						vector<int> cur = {a[i], a[j], a[k]};
						sort(cur.begin(), cur.end());
						if ((long long) cur[0] + cur[1] > cur[2]) {
							ans++;
						}
						// long long s = a[i] + a[j] + a[k];
						// if (s > (long long) 2 * max(a[i], max(a[j], a[k]))) {
						// 	ans++;
						// }
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3644
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var n = Console.ReadLine().ToInt32();
        var an = Console.ReadLine().SplittedStringToInt32List();
        var ls = new List<KeyValuePair<int, int>>();
        var dic = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            var ai = an[i];
            var ani = an[ai - 1]; //  || x.Value == Math.Max(i + 1, ai)
            if (i + 1 == ani && i + 1 != ai && !dic.ContainsKey(Math.Min(i + 1, ai)))
            {
                dic.Add(Math.Min(i+1,ai), Math.Max(i+1,ai));
            }
        }
        Console.WriteLine(dic.Count);
        Console.ReadLine();
    }

    #region ライブラリ

    #region 文字列処理

    public static int ToInt32(this string str)
    {
        
return int.Parse(str);
    }
    public static List<string> SplittedStringToList(this string str)
    {
        return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
            .ToList();
    }
    public static List<int> SplittedStringToInt32List(this string str)
    {
        return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    }
    #endregion
    #region DeepClone
    public static T DeepClone<T>(this T src)
    {
        using (var memoryStream = new MemoryStream())
        {
            var binaryFormatter
              = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, src);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return (T)binaryFormatter.Deserialize(memoryStream);
        }
    }
    #endregion

    public static int Gcd(int a,int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    #endregion
}


Measured memory_bytes: 20320
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
  a=int(input())
  t[a-1].append(i)
def dfs(v):
  if not t[v]:
    return 0
  l=[dfs(i)+1 for i in t[v]]
  l.sort()
  for i in range(len(t[v])-1):
    l[i+1]=max(l[i+1],l[i]+1)
  return l[-1]
print(dfs(0))

Measured memory_bytes: 227992
#include<bits/stdc++.h>
//#include<my.h>
#define ll long long
#define UP(a,b,i) for(int i=(a);i<=(b);i++)
#define DOWN(a,b,i) for(int i=(a);i>=(b);i--)
#define rep(a,b,i) UP(a,b-1,i)
#define MEM(a,b) memset(a,b,sizeof(a))
#define Enter() printf("\n");
#define DEBUG printf("Passing [%s] in LINE %d...\n",__FUNCTION__,__LINE__)
using namespace std;
int ma=0x80000000;
int mi=0x7fffffff;
const ll zfc=0xffffffff;
const ll mod=1e9+7;
char x,y;
int main()
{
	cin>>x>>y;
	if(x>y)puts(">");
	if(x==y)puts("=");
	if(x<y)puts("<");
    return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
if N % 2 == 0:
    N -= 1
print(N//2)


Measured memory_bytes: 7876
import sys
  
n = [[0]*4001, [0]*4001, [0]*4001, [0]*4001]
n[0][:1001] = [1]*1001

for i in range(1, 4):
    for j in range(1000*(i+1)+1):
        x = max(0,j-1000*(i+1))
        y = min(j+1,1001)
        for k in range(x,y):
            n[i][j] += n[i-1][j-k]

for i in sys.stdin:
    print(n[3][int(i)])


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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint fanc[500010];
vector<int>to[200010];

mint choose(int n, int k){
  return fanc[n]/(fanc[n-k]*fanc[k]);
}

struct DP{
  mint dp;
  int t;
  DP(mint dp=1, int t=0):dp(dp),t(t){}
  DP& operator+=(const DP& a){
    dp*=a.dp;
    dp*=choose(t+a.t,t);
    t+=a.t;
    return *this;
  }
  DP operator-(const DP& a) const {
    DP res(*this);
    res.t-=a.t;
    res.dp/=choose(res.t+a.t,res.t);
    res.dp/=a.dp;
    return res;
  }
  DP addRoot() const {
    DP res(*this);
    res.t++;
    return res;
  }
};

DP dp[200010];

void dfs(int v, int p=-1){
  for(int u:to[v]){
    if(u==p)continue;
    dfs(u,v);
    dp[v]+=dp[u].addRoot();
  }
}

void bfs(int v, int p=-1){
  for(int u:to[v]){
    if(u==p)continue;
    DP d=dp[v]-dp[u].addRoot();
    dp[u]+=d.addRoot();
    bfs(u,v);
  }
}

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

  fanc[0]=1;
  for(int i=1; i<500010; ++i)fanc[i]=fanc[i-1]*i;

  dfs(0);
  bfs(0);
  rep(i,n)cout<<dp[i].addRoot().dp<<endl;
}

Measured memory_bytes: 23924
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int xPlusYMax = Integer.MIN_VALUE;
    int xPlusYMin = Integer.MAX_VALUE;
    int xMinusYMax = Integer.MIN_VALUE;
    int xMinusYMin = Integer.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      xPlusYMax = Math.max(xPlusYMax, x + y);
      xPlusYMin = Math.min(xPlusYMin, x + y);
      xMinusYMax = Math.max(xMinusYMax, x - y);
      xMinusYMin = Math.min(xMinusYMin, x - y);
    }
    int ans = Math.max(xPlusYMax - xPlusYMin, xMinusYMax - xMinusYMin);
    System.out.println(ans);
  }
}


Measured memory_bytes: 49052
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, k;

int tree[MAXN];
int arr[MAXN];
void upd(int a, int val){
    for(; a < MAXN; a += (a & -a)){
        tree[a]+= val;
    }
}

int get(int b){
    ll sum = 0;
    for(; b > 0; b -= (b & -b))
        sum += tree[b];
    return sum;
}
int up[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>k;

    for(int i = 0; i < n; i++){
        cin>>arr[i];
        arr[i]++;
    }
    int invNum = 0;
    for(int i = 0; i < k; i++){
       up[i] = get(n) - get(arr[i] - 1);
       invNum += up[i];
       upd(arr[i], 1);
    }
    int ans = 0;
    bool zerCnt = 0;
    ans++;
    if(!invNum){
        zerCnt = 1;
    }
    for(int i = k; i < n; i++){
        int cur = get(n) - get(arr[i]);
        invNum -= get(arr[i - k] - 1);
        upd(arr[i - k], -1);
        invNum += cur;
        up[i] = cur;
        upd(arr[i], 1);
        //cout<<cur<<" "<<up[i - k]<<" "<<invNum<<endl;
        if(invNum == 0 && !zerCnt){
            //cout<<"ali"<<endl;
            ans++;
            zerCnt = 1;
            continue;
        }
        //cout<<cur<<endl;
        if(cur){
            ans++;
        }else{
            if(get(arr[i - k] - 1) && invNum){
                //cout<<i<<endl;
                ans++;
            }
        }
    }

    cout<<ans<<endl;
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
  int n,m,a,b;
  scanf("%d %d %d",&n,&m,&a);
  a=abs(m-a);
  while(--n){
    scanf("%d",&b);
    a=gcd(abs(m-b),a);
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 128
import math
A, B, H, M =map(int, input().split())
Hs = H*30 + M*0.5
Ms = 6*M
shita = Hs-Ms
shita = abs(shita)
if  shita >= 180:
    shita = 360 - shita
shita = math.radians(shita)
C = A*A + B*B - 2*A*B*(math.cos(shita))
print (math.sqrt(C))

Measured memory_bytes: 9444
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>



int ASCttenannoryaku(const void *a,const void *b) {
	return *(int *)a - *(int *)b;
}
int main(void)
{
	int n, x[110],  ans = 0, a = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
		a += 2 * x[i];
	}
	ans = (double)a /(double) (2 * n) + 0.5;
	a = 0;
	for (size_t i = 0; i < n; i++)
	{
		a += pow((x[i] - ans),2);
	}
	printf("%d",a);
	return 0;
}


Measured memory_bytes: 128
ABC = list(map(int,input().split()))
ans = 0
for i in range(3):
  add = (max(ABC)-ABC[i])//2
  ans += add
  ABC[i] += add*2
ABC.sort()
if ABC[0] == ABC[2]:
  print(ans)
elif ABC[2] == ABC[1]:
  print(ans + 2)
else:
  print(ans + 1)


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

using namespace std;

int n;

bool ok(int x) {
	if(x == 1) return false;
	int tt = n;
	while(tt % x == 0) tt /= x;
	return tt % x == 1;
}

signed main() 
{
	cin >> n;	
	int ans = 0;
	for(int i = 1 ; i * i <= n ; i++ ) {
		if(n % i == 0)  {
			ans += ok(i);
			if(i*i != n) ans += ok(n/i);
		}
	}
	int nn = n - 1;
	for(int i = 1 ; i * i <= nn ; i++ ) {
		if(nn % i == 0)  {
			ans += ok(i);
			if(i*i != nn) ans += ok(nn/i);
		}
	}
	cout << ans << endl;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vector<pll> a(n);
    rep(i,n){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(rall(a));

    vvl dp(n+1, vl(n+1));
    rep(i,n){
        ll ai = a[i].fi, pos = a[i].se;
        rep(j,i+1){
            dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + ai * abs(pos-j));
            dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + ai * abs(pos-(n-1-(i-j))));
        }
    }
    ll ans = 0;
    rep(i,n+1){
        ans = max(ans, dp[i][n-i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int period = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 512).readLine());
		int val = 100;//壱百千円
		for (; 0 < period; period--) {
			val = val * 105 % 100 == 0 ? (int) (val * 1.05) : (int) (val * 1.05) + 1;
		}
		System.out.println(val * 1000);
	}
}

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

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '1'){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3420
#include "bits/stdc++.h"
using namespace std;
int Array[205];

int main(){
    int N , l , i , Sum = 0;
    scanf( "%d%d" , &N , &l );

    for( i = 1 ; i <= N ; ++i ){
        Array[i] = l + i - 1;
        Sum += ( l + i - 1 );
    }

    int Ans , Temp , diff;
    Ans = Sum - Array[1];
    diff = abs( Sum - Ans );

    for( i = 2 ; i <= N ; ++i ){
        Temp = Sum - Array[i];

        if( abs( Sum - Temp ) < diff ){
            diff = abs( Sum - Temp );
            Ans = Temp;
        }
    }

    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 256
s=0
while True:
    n,k = map(int, input().split())
    list = [int(input()) for i in range(n)]
    if n==0 and k==0:
        break
    a=sum(list[0:k])
    b=[a]
    for i in range(n-k):
        a += list[i+k]-list[i]
        b.append(a)
    print(max(b))


Measured memory_bytes: 11744
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
#pragma endregion
#pragma endregion


int main() {
	ld n, m, d; cin >> n >> m >> d;
	if (d == 0) printf("%.15Lf\n", (1 / n) * (m - 1));
	else printf("%.15Lf\n", ((2 * n - 2 * d) / (n * n)) * (m - 1));

	return 0;
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
long dp[55][55][55*50];
main(){
  long n,v;
  cin>>n>>v;
  long x[n];
  for(int i=0;i<n;++i)cin>>x[i];
  
  dp[0][0][0]=1;
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      for(int k=0;k<55*50;++k){
        dp[i+1][j][k]+=dp[i][j][k];
        dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
      }
    }
  }
  
  long ans=0;
  for(int i=1;i<=n;++i)
    ans+=dp[n][i][i*v];
  cout<<ans<<endl;
}


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

#define INF 1000000000000


signed main()
 {
    int n,i;
    cin>>n>>i;
    cout<<n-i+1;
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

struct UnionFind{
    const int V;
    vector<int> par;
    vector<int> sz;
    UnionFind(const int V):V(V){
        par.resize(V+1);
        for(int i=0;i<=V;i++) par[i]=i;
        sz.resize(V+1,1);
    }
    bool unite(int x,int y){
        x=root(x),y=root(y);
        if(same(x,y)) return false;
        if(y<x) swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
        return true;
    }
    int root(int x){
    	if(par[x]==x) return x; // xはroot
    	return (par[x]=root(par[x])); // xの親のroot
    }
    bool same(int x,int y){
    	return (root(x)==root(y));
    }
    int size(int x){
        return sz[root(x)];
    }
};
int main(){
    int n,q; cin>>n>>q;
    UnionFind uf(n);
    while(q--){
        int com,x,y; cin>>com>>x>>y;
        if(com==0) uf.unite(x,y);
        else cout<<(uf.same(x,y)?1:0)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;


template<std::uint_fast64_t Mod> class modint {
    using uint = std::uint_fast64_t;
public:
    uint a;
    modint() noexcept : a(0) {}
    constexpr modint(const uint x) noexcept : a(x% Mod) {}
    constexpr uint& value() noexcept { return a; }
    constexpr const uint& value() const noexcept { return a; }
    constexpr modint operator +(modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator -(modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator *(modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator /(modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint& operator +=(modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
    constexpr modint& operator -=(modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
    constexpr modint& operator *=(modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
    constexpr modint& operator /=(modint rhs) noexcept {
        for (uint exp = Mod - 2; exp; exp /= 2, rhs *= rhs) if (exp % 2) *this *= rhs;
        return *this;
    }
};
template<std::uint_fast64_t Mod, typename T> constexpr modint<Mod> pow(modint<Mod> base, T exp) noexcept {
    modint<Mod> y(1); for (; exp; exp /= 2, base *= base) if (exp % 2) y *= base;
    return y;
}
template<std::uint_fast64_t Mod> std::istream& operator >>(std::istream& lhs, modint<Mod>& rhs) { return lhs >> rhs.a; }
template<std::uint_fast64_t Mod> std::ostream& operator <<(std::ostream& lhs, modint<Mod> rhs) { return lhs << rhs.a; }
using mint = modint<MOD>;

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

    int E = C - A, F = D - B;
    vv<mint> dp = vvec(E + 1, F + 1, mint(0));
    dp[0][0] = 1;

    rep(i, E) {
        mint s = 0;
        rep(j, F + 1) {
            dp[i + 1][j] += s + dp[i][j] * (B + j);
            s += dp[i][j];
            s *= A + i;
        }
    }

    mint ans = 0;
    rep(j, F + 1) {
        ans += dp[E][j] * pow(mint(C), F - j);
    }
    write(ans);
}


Measured memory_bytes: 73576
#C Bugged
import numpy as np
a = int(input())
k   = []
k10 = []
s = 0

for j in range(a):
    i = int(input())
    if i % 10 == 0:
        k10.append(i)
        s += i
    else:
        k.append(i)
k.sort()
c = np.array(k)
l = c.sum()
if l%10==0 and len(k) !=0:
    l = l - c[0]
    s = s + l
elif len(k) == 0:
    s = 0
else:
    s = s + l
print(s)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int h,w,k;
    cin>>h>>w>>k;
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    if (w==1){
        cout<<1<<endl;
        return 0;
    }
    dp[0][1]=1;
    for (int i=1;i<h+1;i++){
        for (int j=0;j<(1<<(w-1));j++){
            bitset<7> s(j);
            int b=1;
            for (int l=0;l<w-2;l++){
                if (s.test(l) && s.test(l+1)){
                    b=0;
                    break;
                }
            }
            if (b==1){
                for(int l=1;l<w+1;l++){
                    if (l==1){
                        if (s.test(0))dp[i][l]+=dp[i-1][l+1];
                        else dp[i][l]+=dp[i-1][l];
                    }
                    else if (l==w){
                        if (s.test(w-2))dp[i][l]+=dp[i-1][l-1];
                        else dp[i][l]+=dp[i-1][l];
                    }
                    else{
                        if (s.test(l-2))dp[i][l]+=dp[i-1][l-1];
                        else if (s.test(l-1))dp[i][l]+=dp[i-1][l+1];
                        else dp[i][l]+=dp[i-1][l];
                    }
                    dp[i][l]%=MOD;
                }
            }
        }
    }
    cout<<dp[h][k]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll h[30],n;
const ll inf=1e18;
ll solve(int l,int r,ll a,ll b) {
    if(r-l<=1)return 0;
    ll ans=inf;
    for(int i=l+1;i<=r-1;i++) {
        ans=min(ans,solve(l,i,a,a+b)+solve(i,r,a+b,b)+h[i]*(a+b));
    }
    return ans;
    
}
int main() {
    cin>>n;for(int i=1;i<=n;i++)cin>>h[i];
    cout<<solve(1,n,1,1)+h[1]+h[n];
    return 0;
}

Measured memory_bytes: 3684
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

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

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  cout << n/3 << endl;
  
  
}

Measured memory_bytes: 3520
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
       Scanner scan = new Scanner(System.in);
       int k = scan.nextInt();
       int x = scan.nextInt();
       int bmin, bmax;
       bmin = x-(k-1);
       bmax = x+(k-1);
       for (int i = bmin;i <= bmax ;i++ ) {
           System.out.println(i);
       }
    }
    
}


Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int N, D;
    cin >> N >> D;
    if(N % (2*D+1) != 0)
    {
        cout << N / (2*D+1) + 1 << endl;
    }
    else 
    {
        cout << N / (2*D+1) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((r<=x&&x<=W-r)&&(r<=y&&y<=H-r)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{

    int n=D();
    set<int>st;
    while(n--){
        int a=D();
        st.insert(a);
    }
    cout<<st.size()<<endl;
}



Measured memory_bytes: 256
while True:
  n,x = map(int, input().split())

  if n == 0 & x == 0: 
    break

  ans = 0
  
  for i in range(1,n+1):
    for j in range(1, i):
      for k in range(1, j):
        if i + j + k == x:
          ans += 1

  print(ans)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n, m;
    cin >> n >> m;

    vector<vector<int>> G(n+1, vector<int>());
    rep(i, m){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> ans(n+1), dist(n+1, INF);
    queue<int> que;
    que.push(1);
    dist[1] = 0;
    while(que.size() != 0){
        int v = que.front();
        que.pop();
        for(auto nv: G[v]){
            if(dist[nv] > dist[v]+1){
                que.push(nv);
                dist[nv] = dist[v] + 1;
                ans[nv] = v;
            }
        }
    }

    cout << "Yes" << endl;
    for(int i=2; i<=n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if (a*b % 2 == 1){
    cout << "Odd" << endl;
  }
  if (a*b % 2 == 0){
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],w[N];
int main(){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&a[i]),w[a[i]]++;
	for (int i=1;i<=n;i++) if (w[i]>w[i-1]||w[i]>3){puts("0");return 0;}
	int mx1=-1,mx2=-1,mx3=-1,ans=1;
	for (int i=1;i<=n;i++){
		int cnt=(mx1+1==a[i])+(mx2+1==a[i])+(mx3+1==a[i]);
		ans=1ll*ans*cnt%1000000007;
		if (mx1+1==a[i]) mx1++;
		else if (mx2+1==a[i]) mx2++;
		else mx3++;
	}
	printf ("%d",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define d double
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;

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

    int n, k;
    cin >> n >> k;

    if( n % k ) cout << 1 << endl;
    else        cout << 0 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please



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


	int N, K;
	cin >> N >> K;
	int A[100];
	rep(i, N) cin >> A[i];

	ll mod = 1e9 + 7;
	ll dp[101][100000] = {};
	dp[0][K] = 1;

	rep(i, N) {
		ll B[100002] = {};
		rep(j, K + 1) {
			B[j + 1] += (mod - dp[i][j]) % mod;
			B[j + 1] %= mod;
			int kari = max(0, j - A[i]);
			B[kari] += dp[i][j];
			B[kari] %= mod;
		}
		dp[i + 1][0] = B[0];
		rep1(j, K) {
			dp[i + 1][j] = (dp[i + 1][j - 1] + B[j]) % mod;
		}
	}

	co(dp[N][0]);

	Would you please return 0;
}

Measured memory_bytes: 80000
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
long long w[maxn], d[maxn];
int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    for(int e = 0; e < n; e++)
        scanf("%lld %lld", w + e, d + e);
    long long lo = 1, hi = ((long long)2e18) + 7, ans = -1;
    while(lo <= hi){
        long long mid = (lo + hi)>>1;
        long long cnt = 0;
        for(int e = 0; e < n; e++){
            if(w[e] <= mid){
                cnt += (mid - w[e] + d[e]) / d[e];
            }
        }
        if(cnt >= k) ans = mid, hi = mid - 1;
        else lo = mid + 1;
    }
    assert(ans != -1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
c = [0] * (n-1)
s = [0] * (n-1)
f = [0] * (n-1)
ans = [0] * n
for i in range(n-1):
    c[i],s[i],f[i] = map(int, input().split())
for i in range(n-1):
    for j in range(i,n-1):
        s2 = s[j]

        while s2 < ans[i]:
            s2 += f[j]
        ans[i] = c[j] + s2
#print(ans)
for i in range(n):
    print(ans[i])

Measured memory_bytes: 42204
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))

for b in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0

flag = False
if A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0:
    flag = True
if A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0:
    flag = True
if A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0:
    flag = True
if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0:
    flag = True
if A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0:
    flag = True
if A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0:
    flag = True
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    flag = True
if A[0][2] == 0 and A[1][1] == 0 and A[0][2] == 0:
    flag = True

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,a[110],sum=0;

int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	rep(i,n-1) sum+=a[i];
	puts((sum>a[n-1]) ? "Yes":"No");
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=0;
  ll N;

  cin>>N;

  ll t[N];
  ll x[N];
  ll y[N];
  FOR(i,0,N-1){
    cin>>t[i]>>x[i]>>y[i];
  }
  ll nx=0;
  ll ny=0;
  ll nt=0;
  ll flag=0;

  FOR(i,0,N-1){
    ll kyori =abs(x[i]-nx)+abs(y[i]-ny);
    if(kyori>(t[i]-nt)){
      flag=1;
    }
    if(kyori%2 != (t[i]-nt)%2){
      flag=1;
    }
  }


  if(flag==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
//cout<<ans<<endl;
return 0;

}
 


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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int n; cin >> n;
  if (n / 1000 == n / 100 % 10 && n / 100 % 10 == n / 10 % 10 || n / 100 % 10 == n / 10 % 10 && n / 10 % 10 == n % 10)
  cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        Boolean[] a = new bool[1000000];
        for(int i = 2; i < a.Length; i++)
        {
            a[i] = IsPrime(i);
        }
        while (true)
        {
            string str = Console.ReadLine();
            if (str == null) { break; }
            int ans = 0;
            for(int i = 2; i <= int.Parse(str); i++)
            {
                if (a[i]) { ans++; }
            }
            Console.WriteLine(ans); 
        }
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // ??¶??°????????????????????????

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // ?´???°??§?????????
                return false;
            }
        }

        // ?´???°??§??????_
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 9920
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product

# input = sys.stdin.readline

L, R, d = map(int, input().split())
if L % d == 0:
    print(R//d-L//d+1)
else:
    print(R//d-L//d)




















Measured memory_bytes: 27096
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
  string s;
  string x;
  cin >> s;
  cin >> x;
  for(int i = 0; i < s.size(); i++){
    char tempC = s[0];
    for(int j = 1; j < s.size(); j++){
      s[j-1] = s[j];
    }
    s[s.size()-1] = tempC;
    if(s == x){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//
// Created by Myabu on 2020/01/25.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int s;
    cin>>s;

    vector<int> a;
    a.push_back(s);
    for (int i = 1; i <= 1000000; ++i) {
        if(a[i-1]%2==0){
            a.push_back(a[i-1]/2);
        }else{
            a.push_back(a[i-1] * 3 + 1);
        }
    }

    for (int i = 0; i < 1000000; ++i) {
        for (int k = i+1; k < 1000000; ++k) {
            if(a[i] == a[k]){
                cout<<k+1<<endl;
                return 0;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 6512
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N -1)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

def dfs(n):
  INF = 10 ** 10
  dist = [INF] * (N + 1)

  stack = [n]
  dist[n] = 0
  while stack:
    s = stack.pop()
    for g in graph[s]:
      if dist[s] + 1 < dist[g]:
        stack.append(g)
        dist[g] = dist[s] + 1
  return dist

dist_f = dfs(1)
dist_a = dfs(N)
D = dist_f[N]
#print("dist_f:", dist_f)
#print("dist_a:", dist_a)

f_cnt = 0
a_cnt = 0

color = [0] * (N + 1)
color[1] = 1
color[N] = -1

for i in range(1, N + 1):
  if dist_f[i] <= D // 2:
    if color[i] == 0:
      f_cnt += 1
      color[i] = 1
  if dist_a [i] <= (D - 1) // 2:
    if color[i] == 0:
      a_cnt += 1
      color[i] = -1
#print("color:", color)
#print("f_cnt, a_cnt:", f_cnt, a_cnt)

def paint(n):
  cnt = 0
  for i in range(1, N + 1):
    if color[i] == n:
      stack = [i]
      while stack:
        s = stack.pop()
        for g in graph[s]:
          if color[g] == 0:
            stack.append(g)
            color[g] = n
            cnt += 1
  return cnt

f_cnt += paint(1)
a_cnt += paint(-1)

if f_cnt >= a_cnt + 1:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 43348
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 1e9 + 5; 
void max_self(ll &a,ll b){
	a=max(a,b);
}
int main(){
	int n,w;
scanf("%d%d", &n,&w);
vector<ll>dp(w+1);

for(int i=0;i<n;i++){
	int weight,value;
	cin>>weight>>value;
	
	for(int already=w-weight;already>=0;already--){
		max_self(dp[already+weight],dp[already]+value);
		
	}	
}
ll ans=0;
for(int i=0;i<=w;i++){
	max_self(ans,dp[i]);}
	
cout<<ans;
}
	
	


Measured memory_bytes: 1024