akhauriyash/Code-Regression huggingface dataset:
import numpy as np
n = int(input())
grid = []
grid.append([0,0,0])
ans = "Yes"
for i in range(1,n+1):
    array = list(map(int,input().split()))
    grid.append(array)
for i in range(n):
    if np.abs(grid[i+1][1]-grid[i][1])+np.abs(grid[i+1][2]-grid[i][2]) > grid[i+1][0]-grid[i][0]:
        ans="No"
    elif (grid[i+1][0] - grid[i][0] - np.abs(grid[i+1][1]-grid[i][1]) - np.abs(grid[i+1][2]-grid[i][2])) % 2 == 1:
        ans="No"
print(ans)

Measured memory_bytes: 36320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<int>> dp(3001,vector<int>(3001,-1));
int lcs(string s,string t,int n,int m,string str)
{
    if(dp[n][m]==-1)
    {
    if(n==0||m==0)
    {
    
    dp[n][m]=0;
    return 0;
    }

    if(s[n-1]==t[m-1])
    {
        str.push_back(s[n - 1]);
        dp[n][m]=lcs(s,t,n-1,m-1,str)+1;
        
    }
    else
    {
        int a=lcs(s,t,n,m-1,str);
        int b=lcs(s,t,n-1,m,str);
        dp[n][m]=max(a,b);
    }
    return dp[n][m];
    }
    return dp[n][m];
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input1.txt", "r", stdin);
//     freopen("output1.txt", "w", stdout);
// #endif
string s,t;
cin>>s>>t;
int n=s.size();
int m=t.size();
//string str;
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    int i;
    for(i=0;i<=m;i++)
    {
        dp[0][i]=0;
    }
    for(i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    int j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else 
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    // for(i=1;i<=n;i++)
    // {
    //     for(j=1;j<=m;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    //cout<<dp[n][m]<<"\n";
    string str="";
    i=n;
    j=m;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            str=str+s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>=dp[i][j-1])
        i--;
        else 
        j--;
    }
    reverse(str.begin(),str.end());
    cout<<str<<"\n";
}

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

int main()
{
    long long x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<long long> p(a), q(b), r(c);
    priority_queue<long long> red, green, white;
    rep(i, a)
    {
        cin >> p.at(i);
        red.push(p.at(i));
    }
    rep(i, b)
    {
        cin >> q.at(i);
        green.push(q.at(i));
    }
    rep(i, c)
    {
        cin >> r.at(i);
        white.push(r.at(i));
    }
    priority_queue<long long> sum;
    rep(i, x)
    {
        sum.push(red.top());
        red.pop();
    }

    rep(i, y)
    {
        sum.push(green.top());
        green.pop();
    }
    rep(i, c)
    {
        sum.push(white.top());
        white.pop();
    }

    long long ans = 0;
    rep(i, x + y)
    {
        ans += sum.top();
        sum.pop();
    }

    cout << ans << endl;
}


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

int main(void){
    ll N;
    cin >> N;
    
    if((N%2)==0){
        cout<< 0.5 << endl;
    }
    else{
       int a= (N+1)/2; 
       int b = N; 
       double f = (double) a/b;
        cout<< f << endl; 
    }
}
    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;

#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
typedef long long ll;
typedef long double ld;
///////////////////

int const N = 1e3 + 41;

int n;
ld xa, ya, xb, yb;
ld x[N], y[N], r[N];
int w[N];
ld d[N];
ld ans;

ld sqr(ld x){
	return x * x;
}

ld getdist(ld x0, ld y0, ld x1, ld y1){
	return sqrt( sqr(x0 - x1) + sqr(y0 - y1) );
}

void solve(){
	fi(0, n){
		d[i] = max((ld)0, getdist(xa, ya, x[i], y[i]) - r[i]);
	}
	while(1){
		int id = -1;
		fi(0, n){
			if(!w[i] && (id == -1 || d[id] > d[i])){
				id = i;
			}
		}
		if(id == -1) break;
		w[id] = 1;
		fi(0, n){
			if(w[i]) continue;
			if(i == id) continue;
			ld d0 = d[id] + max((ld)0, getdist(x[i], y[i], x[id], y[id]) - r[id] - r[i]);
			d[i] = min(d[i], d0);
		}
	}
	ans = getdist(xa, ya, xb, yb);
	fi(0, n){
		ld pans = d[i] + max((ld)0, getdist(xb, yb, x[i], y[i]) - r[i]);
		ans = min(ans, pans);
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%Lf %Lf %Lf %Lf",&xa,&ya,&xb,&yb);
	scanf("%d",&n);
	fi(0, n) scanf("%Lf %Lf %Lf",&x[i],&y[i],&r[i]);
	
	solve();

	printf("%.15Lf\n",ans);

	return 0;
}

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

using namespace std;


int main() {

  int n,m;

  vector<int> board,dice;
  int pos;
  int turn;
  int move;


  while(cin >> n >> m) {

    if(n==0 && m==0) break;

    board.clear();

    for(int i=0;i<n;i++) {

      int tmp;

      cin >> tmp;

      board.push_back(tmp);

    }

    //for(int i=0;i<n;i++) cout << board[i] << " ";

    dice.clear();

    for(int i=0;i<m;i++) {

      int tmp;

      cin >> tmp;

      dice.push_back(tmp);

    }

    pos=1;

    for(turn=1;turn<=m;turn++) {

      move=dice[turn-1];

      pos+=move;

      if(pos>=n) break;

      pos+=board[pos-1];
    
      if(pos>=n) break;

    }

    cout << turn << endl;

  }

  return 0;

}

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

using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  vector<vector<int>> to_lef(32 - __builtin_clz(n)), to_rig(32 - __builtin_clz(n));
  vector<vector<long long>> sum_lef(32 - __builtin_clz(n)), sum_rig(32 - __builtin_clz(n));
  for (int i = 0, j = -1; i < n; ++i) {
    while (j + 1 < n && x[i] - x[j + 1] >= k) ++j;
    to_lef[0].push_back(j); 
    sum_lef[0].push_back(i);
  }
  for (int i = 0, j = 0; i < n; ++i) {
    while (j < n && x[j] - x[i] < k) ++j;
    to_rig[0].push_back(j);
    sum_rig[0].push_back(i-1);
  }
  for (int i = 0; i + 1 < (int)to_lef.size(); ++i) {
    to_lef[i+1].resize(n);
    sum_lef[i+1].resize(n);
    for (int j = 0; j < n; ++j) {
      int now = to_lef[i][j];
      long long sum = sum_lef[i][j];
      if (now != -1) {
        sum += sum_lef[i][now];
        now = to_lef[i][now];
      }
      to_lef[i+1][j] = now;
      sum_lef[i+1][j] = sum;
    }
  }
  for (int i = 0; i + 1 < (int)to_rig.size(); ++i) {
    to_rig[i+1].resize(n);
    sum_rig[i+1].resize(n);
    for (int j = 0; j < n; ++j) {
      int now = to_rig[i][j];
      long long sum = sum_rig[i][j];
      if (now < n) {
        sum += sum_rig[i][now];
        now = to_rig[i][now];
      }
      to_rig[i+1][j] = now;
      sum_rig[i+1][j] = sum;
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    --l, --r;
    long long ans = 0;
    int now = r;
    for (int i = (int) to_lef.size()-1; i >= 0; --i) {
      if (to_lef[i][now] >= l) {
        ans += sum_lef[i][now];
        now = to_lef[i][now];
      }
    }
    ans += now;
    now = l;
    for (int i = (int) to_rig.size()-1; i >= 0; --i) {
      if (to_rig[i][now] <= r) {
        ans -= sum_rig[i][now];
        now = to_rig[i][now];
      }
    }
    ans -= now - 1;
    printf("%lld\n", ans);
  }
  return 0;
}


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

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

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <utility>
using namespace std;
#define ll long long
#define mod 1000000007
#define MAX 101000
ll factorial[MAX];
ll factorial2[MAX];
vector<pair<ll, ll> > soinsuu;

ll two (ll x, ll y) {
  if (y == 1) {
    return x % mod;  
  }  
  if (y % 2 == 0) {
    ll sub = two(x, y / 2);
    return ((sub % mod) * (sub % mod)) % mod;    
  }
  return ((two(x, y - 1) % mod) * (x % mod)) % mod;
}

void init (ll m) {
  ll now = 1;
  for (ll i = 0; i <= MAX; i++) {
    if (i == 0 || i == 1) {
      factorial[i] = 1;  
    }  
    else {
      factorial[i] = 
      ((factorial[i - 1] % mod) * (i % mod)) % mod;
    }
  } 
       
  now = 1;
  //
  for (ll i = 0; i <= MAX; i++) {
    if (i == 0 || i == 1) {
      factorial2[i] = 1;  
    }  
    else {
      factorial2[i] = two(factorial[i], mod - 2);    
    }
  }

  // 次にnを素因数分解する.
  ll sub = m;
  for (ll i = 2; i <= sqrt(m); i++) {
    int now = 0;
    while (sub % i == 0) {
      sub = sub / i;
      now++;    
    }  
    if (now != 0) {
      soinsuu.push_back(make_pair(now, i));  
    }
  }
  if (sub != 1) {
    soinsuu.push_back(make_pair(1, sub));  
  }
}

int main () {
  ll n, m;
  cin >> n >> m;
  init(m); 
  ll ans = 1; 
  for (ll i = 0; i < soinsuu.size(); i++) {
    ll num = soinsuu[i].first;
    // num + n - 1 C num
    ll change = 1;
    change = ((change % mod) * (factorial[num + n - 1] % mod)) % mod;
    change = ((change % mod) * (factorial2[num] % mod)) % mod;
    change = ((change % mod) * (factorial2[n - 1] % mod)) % mod;
    ans = ((ans % mod) * (change % mod)) % mod;
  }
  cout << ans % mod << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
  int id;
  int k;
  struct Node *p;
  struct Node *c;
}node;

int getdepth(node);
char* gettype(node);
void drowchildren(node);

int main(){

  int i,j;
  int a,n;
  int id,k;

  //input
  scanf("%d",&n);
  node tree[n];
  for(i=0;i<n;i++){
    tree[i].p=NULL;
  }
  for(i=0;i<n;i++){
    //scanf("%d%d",&tree[i].id,&tree[i].k);
    scanf("%d%d",&id,&k);
    tree[id].id=id;
    tree[id].k=k;
    
    tree[id].c=(node*)malloc(tree[id].k*sizeof(node));
    for(j=0;j<tree[id].k;j++){
      scanf("%d",&tree[id].c[j].id);
      tree[tree[id].c[j].id].p=&tree[id];
    }
  }
  //output
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    if(tree[i].p==NULL) printf("parent = -1, ");
    else printf("parent = %d, ",tree[i].p->id);
    printf("depth = %d, ",getdepth(tree[i]));
    printf("%s, ",gettype(tree[i]));
    drowchildren(tree[i]);
  }
  
  //free 
  for(i=0;i<n;i++){
    free(tree[i].c);
  }
  return 0;
}

int getdepth(node tree){

  int count=0;
  node *q;
  
  if(tree.p==NULL) return 0;
  q=&tree;
  while(q->p!=NULL){
    q=q->p;
    count++;
  }
  return count;
}
char* gettype(node tree){
  if(tree.p==NULL) return "root";
  if(tree.k>=1) return "internal node";
  else return "leaf";
}
void drowchildren(node tree){

  int i;
 
  if(tree.k==0){
    printf("[]\n");
  }
  else{
    printf("[");
    for(i=0;i<tree.k;i++){
      if(i==tree.k-1) printf("%d]\n",tree.c[i].id);
      else printf("%d, ",tree.c[i].id);
    }
  }
}



Measured memory_bytes: 9352
#include <stdio.h>
#include <inttypes.h>

int N,A;
int x[60];

/* 高々2**N通りだから、N<=50なら64ビットでOK */
uint64_t memo[60][60][50*60]; /* [位置][カウント][合計] */

uint64_t search(int pos, int count, int sum) {
	uint64_t ret = 0;
	if (pos>=N) return count>0 && A*count==sum;
	if (memo[pos][count][sum])return ~memo[pos][count][sum];
	/* 使う */
	ret+=search(pos+1,count+1,sum+x[pos]);
	/* 使わない */
	ret+=search(pos+1,count,sum);

	return ~(memo[pos][count][sum] = ~ret);
}

int main(void) {
	int i;
	if (scanf("%d%d",&N,&A)!=2) return 1;
	for(i=0;i<N;i++) {
		if (scanf("%d",&x[i])!=1)return 1;
	}
	printf("%"PRIu64"\n", search(0, 0, 0));
	return 0;
}


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

int main() {
    int t;
    scanf ("%d", &t);
    
    int n, d;
    while (t--) {
        scanf ("%d %d", &n, &d);
        printf ("%d\n", 127 * (n-1) + (n & 1 ? d : 127^d));
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MOD = 1e9+7;

int main(){
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;

    if(s == u) cout << a - 1 << " " << b << endl;
    else cout << a << " " << b - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    present_count = int(input())
    present = []
    total_count = 0
    for n in range(present_count):
        p_price = int(input())
        present.append(p_price)

    max_price_index = present.index(max(present))
    present[max_price_index] = present[max_price_index] / 2

    for price in present:
        total_count += price

    print(int(total_count))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;

ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n%2) r=r*base%mod;
        base=base*base%mod;
        n/=2;
    }
    return r;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ans=power(10,n);
    ll temp=power(9,n);
    ll temp3=power(8,n);
    temp*=2;
    temp%=mod;
    ll ans2=ans-temp;
    ans2+=temp3;
    ans2%=mod;
    ans2+=mod;
    ans2%=mod;
    cout<<ans2<<'\n';


}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;

int N, M, R;
long long INF = 100000000000000;
long long A, B, C;

long long dist[205][205];

int main() {

  for(int i = 0; i < 205; i++) {
    for(int j = 0; j < 205; j++) {
      if(i == j) dist[i][j] = 0;
      else dist[i][j] = INF;
    }
  }
  
  
  cin >> N >> M >> R;
  vector<long long> r(R);
  for(int i = 0; i < R; i++) {
    cin >> r[i];
  }
  for(int i = 0; i < M; i++) {
    cin >> A >> B >> C;
    dist[A][B] = dist[B][A] = C;
  }

  for(int k = 0; k < 205; k++) {
    for(int i = 0; i < 205; i++) {
      for(int j = 0; j < 205; j++) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  long long ans = INF;
  sort(r.begin(), r.end());
  do {
    long long cost = 0;
    for(int i = 1; i < R; i++) {
      cost += dist[r[i - 1]][r[i]];
    }
    ans = min(ans, cost);
  } while(next_permutation(r.begin(), r.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

int main() {
    ll n; cin >> n;
    Vp vp(n);
    rep(i, 0, n) cin >> vp[i].fi >> vp[i].se;

    sort(ALL(vp));
    ll cnt = 0;
    rep(i, 0, n){
        rep(j, 0, n){
            ll ct = 0;
            ll dx = vp[j].fi-vp[i].fi, dy = vp[j].se-vp[i].se;
            rep(k, 0, n){
                rep(l, 0, n){
                    if(k == l) continue;
                    if(vp[k].fi-vp[l].fi == dx && vp[k].se-vp[l].se == dy) ct++;
                }
            }
            chmax(cnt, ct);
        }
    }
    co(n-cnt);

    return 0;
}


Measured memory_bytes: 256
// AOJ ALDS1_4_C Dictionary
// 2018.4.27 bal4u
 
#include <stdio.h>
 
// バッファを経ずstdinから数値を得る
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
int  tr['T'+1];
char f[33554432];
 
int main()
{
    int n, k, c;
 
    tr['A'] = 0, tr['C'] = 1, tr['G'] = 2, tr['T'] = 3;
    n = in();
    while (n--) {
        if (gc() == 'i') {
            k = 7; while (--k) gc();
            k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
            f[k] = 1;
        } else {
            k = 5; while (--k) gc();
            k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
            if (f[k]) pc('y'), pc('e'), pc('s');
            else      pc('n'), pc('o');
            pc('\n');
        }
    }
    return 0;
}


Measured memory_bytes: 3000
def main():

    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        temp = [x, y, z, x+y+z, x+y-z, x-y+z, -x+y+z, x-y-z, -x+y-z, -x-y+z, -x-y-z]
        A.append(temp)

    ans = 0
    for i in range(3, 11):
        A.sort(key = lambda x: x[i])
        tot1, tot2, tot3 = 0, 0, 0
        for i in range(M):
            tot1 += A[i][0]
            tot2 += A[i][1]
            tot3 += A[i][2]
        ans = max(ans, abs(tot1)+abs(tot2)+abs(tot3))
        tot1, tot2, tot3 = 0, 0, 0
        for i in range(M):
            tot1 += A[M-1-i][0]
            tot2 += A[M-1-i][1]
            tot3 += A[M-1-i][2]
        ans = max(ans, abs(tot1)+abs(tot2)+abs(tot3))

    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3572
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int p = sc.nextInt();

        int Xprice; int Yprice;
        //X
        Xprice=a*p;
        //Y
        if(p>c){ Yprice=b+d*(p-c); }
        else{ Yprice=b; }

        if(Xprice<=Yprice){ System.out.println(Xprice); }
        else{ System.out.println(Yprice); }
    }
}


Measured memory_bytes: 26420
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    h,w=INTM()
    a=[]
    wd=[]
    for i in range(h):
        temp=STR()
        if temp!='.'*w:
            a.append(temp)
    h=len(a)
    for i in range(w):
        flg=1
        for j in range(h):
            if a[j][i]=='#':
                flg=0
        if flg==1:
            wd.append(i)
    wd=sorted(wd,reverse=True)
    for i in wd:
        for j in range(h):
            #print(i,j)
            a[j]=a[j][:i]+a[j][i+1:]
    for i in range(h):
        print(a[i],sep='')
        
    
if __name__ == '__main__':
    do()

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

int main() {
  int w,h,x,y,r;
  cin >>w>>h>>x>>y>>r;
  if(w>=x+r && h>=y+r && x>=r && y>=r){

    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
  return 0;
}

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

using namespace std;

int main()
{
    string s;
    char now;
    int ans = 0;

    cin >> s;

    now = s[0];

    for (int i = 1; i < (int)s.size(); i++) {
        if (now != s[i]) {
            ans++;
            now = s[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M,S,T;
//i->jに、a円、bスヌークで到達できるとき、
//集合adj[i]は(j,a,b)を含む
vector<vector<tuple<LL,LL,LL>>> adj;

LL ans[100000];

void solve(){
    //pair(円,頂点番号)
    priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,greater<pair<LL,LL>>> q;
    q.push(pair<LL,LL>(0,S));
    //円だけを使ってSからiまで行くとき、コストの最小値をyen_cost[i]とする
    vector<LL> yen_cost(N+1,INF);
    yen_cost[S] = 0;
    while(!q.empty()){
        LL now_yen = q.top().first;
        LL now_node = q.top().second;
        q.pop();
        for(auto next:adj[now_node]){
            LL next_yen = now_yen + get<1>(next);
            LL next_node = get<0>(next);
            if(yen_cost[next_node]>next_yen){
                yen_cost[next_node] = next_yen;
                q.push(pair<LL,LL>(next_yen,next_node));
            }
        }
    }

    //pair(スヌーク,頂点番号)
    //priority_queue<tuple<LL,LL>,vector<tuple<LL,LL>>,greater<tuple<LL,LL>>> q;
    q.push(pair<LL,LL>(0,T));
    //スヌークを使ってTからiまで行くとき、コストの最小値をsunuke_cost[i]とする
    vector<LL> sunuke_cost(N+1,INF);
    sunuke_cost[T] = 0;
    while(!q.empty()){
        LL now_sunuke = q.top().first;
        LL now_node = q.top().second;
        q.pop();
        for(auto next:adj[now_node]){
            LL next_sunuke = now_sunuke + get<2>(next);
            LL next_node = get<0>(next);
            if(sunuke_cost[next_node]>next_sunuke){
                sunuke_cost[next_node] = next_sunuke;
                q.push(pair<LL,LL>(next_sunuke,next_node));
            }
        }
    }

    ans[N-1] = yen_cost[N]+sunuke_cost[N];
    for(int i=N-2;i>=0;i--){
        ans[i] = min(ans[i+1],yen_cost[i+1]+sunuke_cost[i+1]);
    }

    for(int i=0;i<N;i++) ans[i] = 1e15 - ans[i];
}
 
int main(){
	cin >> N >> M >> S >> T;
    adj = vector<vector<tuple<LL,LL,LL>>>(N+1);
    for(int i=0;i<M;i++){
        LL u,v,a,b;
        cin >> u >> v >> a >> b;
        adj[u].push_back(tuple<LL,LL,LL>(v,a,b));
        adj[v].push_back(tuple<LL,LL,LL>(u,a,b));
    }
 
    solve();

	for(int i=0;i<N;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 14568
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2002;

int main()
{
	string s;
	cin >> s;
	for(int i = 0; i < 4; i++)
		cout << s[i];
	cout << " ";
	for(int i = 4; i < s.size(); i++)
		cout << s[i];
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int N,i;
  cin >> N;
  vector<int> p(N);
  for(i=0; i<N; i++) cin >> p[i];
  int k = 0;
  for(i = 0;i < N; i++){ 
    if (p[i]!=i+1) k++;
  }

  if (k<=2){
      cout << "YES" << endl;
      return 0;
    }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

//constexpr long long MOD = (ll) 1e9+7;
constexpr long long MOD = 998244353;

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;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

//約数
void divisor(ll n, vector<ll>& ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
}

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

ll pow2(ll x, ll n) { //x^n 計算量O(logn)
	ll ans = 1ll;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

void solve() {
	ll n;
	cin >> n;

	Array ret;
	divisor(n, ret);
	ll ans = 0;
	for (auto k : ret) {
		if (k == 1) continue;
		ll x = n;
		while (x % k == 0) x /= k;
		if ((x - 1) % k == 0) {
			ans++;
		}
	}
	Array ret2;
	divisor(n-1, ret2);
	

	cout << ans+ret2.size()-1 << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    final long mod = 1000000007;
    long ans = 0;
    int limit = Math.min(k, n - k + 1);
    for(int i = 1; i <= limit; i++) {
      ans = nCk(n - k + 1, i, mod) * nCk(k - 1, i - 1, mod) % mod;
      System.out.println(ans);
    }
    for(int i = 0; i < k - limit; i++) {
      System.out.println(0);
    }
  }

  public static long nCk(int n, int k, long p) {
    long factorial = 1;
    k = Math.min(k, n - k);
    //k!(mod p)の逆元をmodPowを用いて計算
    for(int i = 2; i <= k; i++) {
      factorial = (factorial * i) % p;
    }
    factorial = modPow(factorial, p-2, p);
    //n(n-1)...(n-k+1) (mod p)の計算
    for(int i = n - k + 1; i <= n; i++) {
      factorial = (factorial * i) % p;
    }
    return factorial;
  }

  public static long modPow(long a, long b, long p) {
    long power = 1;
    while(b > 0) {
      if((1 & b) == 1) power = (power * a) % p;
      a = (a * a) % p;
      b = b >> 1;
    }
    return power;
  }
}


Measured memory_bytes: 22484
N=int(input())
AN=list(map(int,input().split()[:N]))
ANsort=sorted(AN,reverse=True)

alice=0
bob=0
for i in range(N):
    if i%2==0:
        alice+=ANsort[i]
    else:
        bob+=ANsort[i]
print(alice-bob)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int d = b - a;
    int s = 0;
    for(int i = 1; i < d; i++) {
      s += i;
    }
    System.out.println(s - a);
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];
int H[MAX];

void print(int u){
  int i, c, deg=0;
  printf("node %d: parent = %d, ", u, T[u].p);
  printf("sibling = ");
  if(T[u].p==NIL) printf("%d, ",NIL);
  else if(T[T[u].p].l != u && T[T[u].p].l != NIL) printf("%d, ",T[T[u].p].l);
  else if(T[T[u].p].r != u && T[T[u].p].r != NIL) printf("%d, ",T[T[u].p].r);
  else printf("%d, ",NIL);
  if(T[u].l!=NIL) deg++;
  if(T[u].r!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, height = %d, ",D[u],H[u]);

  if(T[u].p==NIL) printf("root\n");
  else if(T[u].l==NIL&&T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");

}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
  if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
}

int calcHeight(int u){
  int a=0,b=0;
  if(T[u].l!=NIL){
    a=calcHeight(T[u].l)+1;
  }
  if(T[u].r!=NIL){
    b=calcHeight(T[u].r)+1;
  }
  if(a>b){
    H[u]=a;
    return H[u];
  }
  else{
    H[u]=b;
    return H[u];
  }
}

int main(){
  int i, j, k;
  int n;
  int id, child1,  child2;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d %d", &child1,&child2);
      T[id].l = child1;
      T[id].r = child2;
      if(child1!=NIL) T[child1].p = id; //idの一番左の子 (the most left child of id)
      if(child2!=NIL) T[child2].p = id; //左の兄弟に繋げる (connect to left sibling)
      //sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);
  calcHeight(root);

  //出力 (output)
  for(i=0; i<n; i++) print(i);

  return 0;
}



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

using std::cerr;
using std::endl;

inline int rd() {
  int x; scanf("%d", &x);
  return x;
}

const int N = 1e5 + 233;

int n, m, val[N], size;
std::vector<int> G[N];
int sum[N];
int stk[N], top;
long long ans;
std::vector<int> cir;

void dfs1(int x, int fa, int c) {
  val[x] = sum[x] = c;
  if (!cir.size())
    stk[++top] = x;
  for (int y : G[x]) if (y != fa) {
    if (val[y]) {
      if (cir.size())
        continue;
      for (int z; y != z; --top) {
        z = stk[top];
        cir.push_back(z);
      }
    } else {
      dfs1(y, x, -c);
      sum[x] += sum[y];
    }
  }
  if (!cir.size())
    --top;
}

int vis[N], rt;

void dfs2(int x, int fa) {
  vis[x] = 1;
  for (int y : G[x]) if (y != fa) {
    if (vis[y]) {
      if (!rt)
        rt = x;
    } else {
      dfs2(y, x);
    }
  }
}

int main() {
  // freopen("data", "r", stdin);
  n = rd(), m = rd();
  if (n & 1)
    return puts("-1"), 0;
  for (int i = 1; i <= m; ++i) {
    int x = rd(), y = rd();
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs2(1, 0);
  if (!rt) rt = 1;
  dfs1(rt, 0, 1);
  if (m == n - 1) {
    if (sum[rt])
      return puts("-1"), 0;
  } else {
    size = cir.size();
    if (size & 1) {
      if (sum[rt] & 1)
        return puts("-1"), 0;
      int v = sum[rt] >> 1;
      for (int x : cir)
        sum[x] -= v;
    } else {
      if (sum[rt])
        return puts("-1"), 0;
      std::sort(cir.begin(), cir.end(), [&](int x, int y)
        { return sum[x] < sum[y]; });
      int v = sum[cir[size / 2 - 1]];
      for (int x : cir)
        sum[x] -= v;
    }
  }
  for (int i = 1; i <= n; ++i)
    ans += std::abs(sum[i]);
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 17276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;

    vector<int> a(n);

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

    int spawn = 0;
    for (int i = 0; i < n; i++) {
        spawn = a.at(spawn) - 1;

        if (spawn == 1) {
            cout << i + 1 << endl;
            break;
        }

        if (i >= n - 1) {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  
int n;
  
cin >> n;
  
//cout << n << endl;
  
int a[n];
  
for(int i = 0;i < n;i++){

  cin >> a[i];
  
}
  int tmp;
  
    /* 数値を昇順にソート */
  for (int i=0; i<n; ++i) {
    for (int j=i+1; j<n; ++j) {
      if (a[i] > a[j]) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }

  
for(int i = 0;i < n;i++){

  // cout << a[i] << endl;
  
}  
  
   cout << a[n-1]-a[0] << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>

#define maxn 200010
typedef long long ll;
int a[maxn];
ll f[maxn];
 
int open()
{
    freopen("datain.txt","r",stdin);
    freopen("dataout.txt","w",stdout);
}
int main(void)
{
    //open();
    ll mi,s;
    int i,n;
    scanf("%d",&n);
        memset(a,0,sizeof(a));
        memset(f,0,sizeof(f));
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(i=0,s=0;i<n;i++)
        {
            s+=a[i];
            f[i+1]=s;
        }
        for(i=2,mi=labs(s-2*f[1]);i<n;i++)
            if(mi>labs(s-2*f[i])) mi=labs(s-2*f[i]);
        std::cout<<mi<<std::endl;

    return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int cnt = 0;
      for(int i = 0;i < n;i++){
      	int a = sc.nextInt();
        while(a%2==0){
        	cnt++;
            a/=2;
        }
      }
      System.out.println(cnt);
    }
}

Measured memory_bytes: 36036
#include "bits/stdc++.h"
 
using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define Cout(str) cout << str << endl

int main(){
	int N,K;

	cin >> N >> K;

	if(N%K == 0) Cout(0);
	else Cout(1);

	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

const ll MXN=5e3;
vector<int> a(MXN);
int n,k;

bool hitsuyo(int x){
    vector<vector<bool>> B(n+1,vector<bool>(k+1,false));
    B[0][0]=true;
    FOR(i,1,n+1){
        rep(j,k+1){
          	if(B[i-1][j]){
            	B[i][j]=true;
                if(k-a[x]<=j&&j<k){
                    return true;
                }
            }
            if(j>=a[i-1]&&i-1!=x){
            	if(B[i-1][j-a[i-1]]){
                	B[i][j]=true;
                	if(k-a[x]<=j&&j<k){
                    	return true;
                	}
                }
            }
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    a.resize(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int unneed=-1,need=n;
    while(abs(unneed-need)>1){
        int mid=(unneed+need)/2;
        if(hitsuyo(mid)){
            need=mid;
        }
        else{
            unneed=mid;
        }
    }
    cout << unneed+1 << '\n';
}

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

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

    int k;
    cin >> k;
    int s = 0;

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int x = 1; x <= k; x++) {
                int gcd = __gcd(i, j);
                gcd = __gcd(gcd, x);
                s += gcd;
            }
        }
    }

    cout << s;

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
	int G,L,a,b,c,t1,t2;
	while(scanf("%d%d",&a,&b)!=EOF){
		G=1;
		L=1;
		t1=a;
		t2=b;
		for(;;){
			if(t1%2==0&&t2%2==0){
				t1/=2;
				t2/=2;
				G*=2;
			} else {break;}
		}
		if(b>a){
			c=b;
			b=a;
			a=c;
		}
		for(c=3;c<=b;c+=2){
			for(;;){
				if(t1%c==0&&t2%c==0){
					t1/=c;
					t2/=c;
					G*=c;
				}else {break;}
			}
		}
		L=G*t1*t2;
		printf("%d %d\n",G,L);
	}
	return 0;
}

Measured memory_bytes: 408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	int N; cin >> N;
	vi A(N); rep(i, N) cin >> A[i];
	map<int, int> c;
	rep(i, N) c[A[i]]++;
	int ans = 0;
	each(ci, c) {
		if (ci.second > 1) {
			ans += ci.second * (ci.second - 1) / 2;
		}
	}
	rep(i, N) {
		int sabun = 0;
		if (c[A[i]] > 1) {
			sabun = (c[A[i]] - 2) * (c[A[i]] - 1) / 2
			- (c[A[i]] - 1) * c[A[i]] / 2;
		}
		cout << ans + sabun << endl;
	}

	/*--------------------------*/
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 11136
fl = input()
sl = input()

koma_num, pos_num = [int (x) for x in fl.split(" ")]
poses = [int(x) for x in sl.split(" ")]
poses.sort()

if koma_num >= pos_num:
    print("0")
    exit()

dists = []
total = 0
for n in range(pos_num-1):
    dist = poses[n+1] - poses[n]
    dists.append(dist)
    total += dist

dists.sort()
dists.reverse()

if(len(dists) == 0):
    print("0")
    exit()

for n in range(koma_num-1):
    total -= dists[n]

print(total)


Measured memory_bytes: 14468
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

// snuke[n][k]
int snuke[200][200];

int main(){
	int n; cin >> n; 
	int k; cin >> k;
	for( int i = 0; i < k; ++i ){
		int cnt; cin >> cnt;
		while( cnt-- ){
			int temp; cin >> temp;
			++snuke[temp-1][i];
		}
	}
	int ans = 0;
	for( int i = 0; i < n; ++i ){
		int cnt = 0;
		for( int j = 0; j < k; ++j ){
			if( snuke[i][j] != 0 ) ++cnt;
		}
		if( cnt == 0 ) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3692
var
	c,x:array[1..100000]of Longint;
	G1,G2:array[1..100000]of array of Longint;
	used:array[1..100000]of Boolean;
	n,m,i,l,r,d:Longint;
function dfs(u,p:Longint):Boolean;
var i:Longint;
begin
	used[u]:=True;
	for i:=0 to c[u]-1 do begin
		if G1[u,i]=p then continue;
		if used[G1[u,i]]and(x[G1[u,i]]<>x[u]+G2[u,i])then begin
			dfs:=False;
			exit;
		end;
		if not used[G1[u,i]]then begin
			x[G1[u,i]]:=x[u]+G2[u,i];
			if not dfs(G1[u,i],u)then begin
				dfs:=False;
				exit;
			end;
		end;
	end;
	dfs:=True;
end;
begin
	read(n,m);
	for i:=1 to m do begin
		read(l,r,d);
		inc(c[l]);inc(c[r]);
		setlength(G1[l],c[l]);
		setlength(G2[l],c[l]);
		setlength(G1[r],c[r]);
		setlength(G2[r],c[r]);
		G1[l,c[l]-1]:=r;
		G2[l,c[l]-1]:=d;
		G1[r,c[r]-1]:=l;
		G2[r,c[r]-1]:=-d;
	end;
	for i:=1 to n do begin
		if not used[i]then begin
			x[i]:=0;
			if not dfs(i,0)then begin
				writeln('No');
				exit;
			end;
		end;
	end;
	writeln('Yes');
end.


Measured memory_bytes: 23552
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

ll s(ll x) {
  ll r = 0;
  while(x) {
    r+=x%10;
    x/=10;
  }
  return r;
}
ll llcmp(ll a, ll b) {
  // a/s(a) > b/s(b)
  return a*s(b) < b*s(a);
}

ll getNext(ll n) {
  vector<ll> cand;
  cand.push_back(++n);
  ll mod = 10;
  while(n%mod != n) {
    cand.push_back(n - (n%mod) + mod - 1);
    mod *= 10;
  }
  sort(cand.begin(), cand.end(), llcmp);
  return cand[0];
}

void solve() {
  int n;
  cin >> n;
  cout << "1\n";
  ll curr = 1;
  while(--n) {
    curr = getNext(curr);
    cout << curr << "\n";
  }
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 4000;
const int MOD = 1000000007;

int dp[1 + MAXN][1 + MAXN], sum[1 + MAXN][1 + MAXN];

void Count(int ones, int digits, int base) {
    for (int i = 0; i <= min(ones, base - 1); i++) {
        dp[0][i] = 1;
        sum[0][i] = i + 1;
    }
    for (int i = base; i <= ones; i++)
        sum[0][i] = sum[0][i - 1];
    for (int i = 1; i < digits; i++)
        for (int j = 0; j <= ones; j++) {
            dp[i][j] += sum[i - 1][j];
            if (dp[i][j] >= MOD)
                dp[i][j] -= MOD;
            int k = j - min(base - 1, j) - 1;
            if (k >= 0) {
                dp[i][j] -= sum[i - 1][k];
                if (dp[i][j] < 0)
                    dp[i][j] += MOD;
            }
            sum[i][j] = dp[i][j];
            if (j) {
                sum[i][j] += sum[i][j - 1];
                if (sum[i][j] >= MOD)
                    sum[i][j] -= MOD;
            }
        }
}

int main() {
    int n, m, k, answer = 0;
    cin >> n >> m >> k;
    Count(m, (n + m - 1) / (k - 1), k);
    while (m > 0) {
        answer += dp[(n + m - 1) / (k - 1) - 1][m];
        if (answer >= MOD)
            answer -= MOD;
        m -= (k - 1);
    }
    cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 94720
// Problem: I - Coins
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_i
// Parsed on: 2020-09-07 11:36:13
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<double> p(n);
    for (auto &e : p) cin >> e;
    vector<vector<double>> dp(n+1, vector<double>(n+1));

    dp[0][0] = 0;
    dp[0][1] = 1 - p[0];
    dp[1][0] = p[0];

    for (int a = 0; a < n+1; a++) {
        for (int b = 0; b < n+1; b++) {
            if (a + b > n || a + b < 2) continue;
            dp[a][b] = ((a ? dp[a - 1][b] : 0) * p[a + b - 1]) +
                       ((b ? dp[a][b - 1] : 0) * (1 - p[a + b - 1]));
        }
    }

    double ans = 0;
    for (int a = 0; a < n+1; a++)
        for (int b = 0; b < n+1; b++) {
            if (a + b == n && a > b) ans += dp[a][b];
        }

    cout << fixed << setprecision(10) << ans;
    return 0;
}


Measured memory_bytes: 73404
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,k = readints()
a = readints()

mod = 10**9+7

ans = 1
if n==k:
    for x in a:
        ans *= x
        ans %= mod
else:
    plus = []
    minus = []
    for x in a:
        if x>=0:
            plus.append(x)
        elif x<0:
            minus.append(x)
    if len(minus)==n and k%2==1:
        minus.sort(reverse=1)
        for i in range(k):
            ans*=minus[i]
            ans %= mod
    else:
        plus.sort(reverse=1)
        minus.sort()
        i = 0
        j = 0
        if k%2==1:
            ans *= plus[0]
            i+=1
            k-=1
        lp = len(plus)
        lm = len(minus)
        while k>0:
            if i+1<lp and j+1<lm:
                if plus[i]*plus[i+1] > minus[j]*minus[j+1]:
                    ans *= plus[i]*plus[i+1]
                    i+=2
                else:
                    ans *= minus[j]*minus[j+1]
                    j+=2
            elif i+1<lp:
                ans *= plus[i]*plus[i+1]
                i+=2
            else:
                ans *= minus[j]*minus[j+1]
                j+=2
            ans %= mod
            k-=2
print(ans)



        











Measured memory_bytes: 104708
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool equals(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double abs(Vector2 v){
    return sqrt(norm(v));
}

double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

Vector2 project(Line l, Vector2 p){
    Vector2 base = l.second - l.first;
    double r = dot(p - l.first, base) / norm(base);
    return l.first + base * r;
}

pair<Vector2, Vector2> crossPoints(Circle c, Line l){
    Vector2 pr = project(l, c.c);
    Vector2 e = (l.second - l.first) / abs(l.second - l.first);
    double base = sqrt(c.r * c.r - norm(pr - c.c));
    return make_pair(pr + e * base, pr - e * base);
}

int main(){

    int cx, cy, r;
    cin >> cx >> cy >> r;
    Circle c(Vector2(cx, cy), r);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x0, y0, x1, y1;
        cin >> x0 >> y0 >> x1 >> y1;
        Line l(Vector2(x0, y0), Vector2(x1, y1));
        
        auto ans = crossPoints(c, l);
        Vector2 ansMin, ansMax;
        if(equals(ans.first.X, ans.second.X)){
            if(ans.first.Y < ans.second.Y){
                ansMin = ans.first;
                ansMax = ans.second;
            }
            else{
                ansMin = ans.second;
                ansMax = ans.first;
            }
        }
        else{
            if(ans.first.X < ans.second.X){
                ansMin = ans.first;
                ansMax = ans.second;
            }
            else{
                ansMin = ans.second;
                ansMax = ans.first;
            }
        }

        cout << fixed << setprecision(8) << ansMin.X << " " << ansMin.Y << " " << ansMax.X << " " << ansMax.Y << endl;
    }

    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];

  ll res = 0LL;
  REP(i,N) {
    res += A[i] / 2;
    A[i] = A[i] % 2;
    if(A[i] == 1 && i + 1 < N && A[i + 1] >= 1) {
      A[i]--;
      A[i + 1]--;
      res++;
    }
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 640