akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int l=sc.nextInt();
        int k=sc.nextInt();
        long[][]dp=new long[2][l+1];
        dp[0][0]=1;
        for(int i=1;i<=l;++i){
            dp[0][i]+=dp[1][i-1];
            dp[1][i]+=dp[0][i-1];
            if(i>=k)
                dp[1][i]+=dp[0][i-k];
        }
        long ans=0;
        for(int i=1;i<=l;++i)
            ans+=dp[1][i];
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 24504
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    string s;
    cin>>s;
    int a=10*(s[0]-'0')+(s[1]-'0');
    int b=10*(s[2]-'0')+(s[3]-'0');
    int aa=0,bb=0;
    if(a>0&&a<=12){aa=1;}
    if(b>0&&b<=12){bb=1;}
    //cout<<a<<" "<<b<<" "<<aa<<" "<<bb<<endl;
    if(aa==0&&bb==0){cout<<"NA";}
    else if(aa==1&&bb==1){cout<<"AMBIGUOUS";}
    else if(aa==1&&bb==0){cout<<"MMYY";}
    else{cout<<"YYMM";}

    return (0);
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
     
    using namespace std;
    typedef long long ll;
    ll mod = 1e9+7;
     
    int main(void)
    {
      ll N;cin>>N;
      vector<ll> X(N);
      for(ll i=0;i<N;i++)cin>>X[i];
      ll res=1e9;
      for(ll i=1;i<100;i++){
        ll sum=0;
        for(ll j=0;j<N;j++){
          sum+= (X[j]-i)*(X[j]-i);
        }
        if(res>sum){
          res=sum;
        }
      }
      cout<<res<<endl;

    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define long long int 
signed main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int ap = a * d;
    int bp = b * e;
    int abpa = 2 * c * d;
    int abpb = 2 * c * e;
    if(d >= e)
    cout << min({ap + bp,abpa,abpb + a * (d - e)}) << endl;
    else
    cout << min({ap+bp,abpb,abpa + b * (e - d)}) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
using namespace std;
int main(){
    char s[100];
    int i;
    for(i=0;i<100;i++)
    {
    	s[i]='A'+i%26;
	}
	int n;
	scanf("%d",&n);
	char t[20000];
	scanf("%s",t);
	int l=strlen(t);
	for(i=0;i<l;i++)
	{
		printf("%c",s[t[i]-'A'+n]);
	}
	printf("\n");
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int a,b; char op; cin >> a >> op >> b;
    if(op=='+') cout << a+b << endl;
    else cout << a-b << endl;
    return 0;
}

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

int main(void){
  while(1){
    int N,M,r,q;
    cin >> N;
    cin >> M;
    if(N == 0){return 0;}

    cin >> r;

    int t[r];
    int n[r];
    int m[r];
    int s[r];
    for(int i = 0 ; i < r; i++){
      cin >> t[i];
      cin >> n[i];
      cin >> m[i];
      cin >> s[i];
    }

    cin >> q;
    int ts[q];
    int te[q];
    int qm[q];
    for(int i = 0 ; i < q ; i++){
      cin >> ts[i];
      cin >> te[i];
      cin >> qm[i];
    }

    for(int qnum = 0 ; qnum < q ; qnum++){
      int ans = 0;

      bool login[1261];
      for(int ptr = 0 ; ptr < 1261 ; ptr++){
        login[ptr] = false;
      }

      int  minstart;
      int  usepc;
      int  minend;
      for(int i = 0 ; i < r ; i++){

        if(m[i] == qm[qnum] && s[i] == 1){
          minstart = t[i];

          bool flg = true;

          for(int j = i+1 ; j <= r && flg ; j++){
            if(n[i] == n[j] && m[i] == m[j] && s[j] == 0){
              flg = false;
              minend = t[j];
            }
          }

          for(int ptr = minstart ; ptr < minend ; ptr++){
            login[ptr] = true;
          }
//          cout << minstart << "??????" << minend << "?????§" << endl;
        }

      }

      for(int ptr = ts[qnum] ; ptr < te[qnum] ; ptr++){
        if(login[ptr]){
//          cout << ptr << "????????£?????????" << endl;
          ans++;
        }
      }
      cout << ans << endl;

    }


  }
}

Measured memory_bytes: 3084
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, c, d = MAP()
if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27148
package main

import (
	"fmt"
	"math"
)

func main(){
	var s string
	fmt.Scan(&s)

	renzoku  := 0
	ans := 0
	for _, c := range s {
		if c == 'R' {
			renzoku++
			ans = int(math.Max(float64(ans), float64(renzoku)))
		}else{
			renzoku = 0
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int h,w,a,b; cin >> h >> w >> a >> b;
    rep(i,b) {
        rep(j,w) {
            if (j < a) cout << '0';
            else cout << '1';
        }
        cout << endl;
    }
    FOR(i,b,h-1) {
        rep(j,w) {
            if (j < a) cout << '1';
            else cout << '0';
        }
        cout << endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
  long long a,b,k;
  cin >> a >> b >> k;

  if(a + b <= k) cout << 0 << " " <<  0 << endl;
  else if(a < k) cout << 0 << " " << a + b - k << endl;
  else cout << a - k << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=400005;
int n,tp;ll a[N],b[N],c[N],ans;
struct P{ll x,y;}stk[N];
inline P operator+(const P&a,const P&b){return (P){a.x+b.x,a.y+b.y};}
inline P operator-(const P&a,const P&b){return (P){a.x-b.x,a.y-b.y};}
inline ll operator*(const P&a,const P&b){return a.x*b.y-a.y*b.x;}
int main()
{
	n=rd();tp=0;
	rep(i,1,n)a[i]=rd(),a[n+i]=a[i];
	rep(i,1,n)b[i]=rd(),b[n+i]=b[i];
	int p=1;rep(i,1,n)if(a[i]>a[p])p=i;
	rep(i,1,n)a[i]=a[i+p-1],b[i]=b[i+p-1];
	a[n+1]=a[1];b[n+1]=b[1];
	rep(i,3,n+1)c[i]=2*(c[i-1]+b[i-1])-c[i-2];
	rep(i,1,n+1)
	{
		P x=(P){i,a[i]-c[i]};
		while(tp>=2&&(stk[tp]-stk[tp-1])*(x-stk[tp])>=0)tp--;
		stk[++tp]=x;ans+=2*c[i];
	}
	rep(i,2,tp)ans+=(stk[i-1].y+stk[i].y)*(stk[i].x-stk[i-1].x);
	ans+=stk[1].y+stk[tp].y-2*a[1];
	printf("%.12lf\n",1.0*ans/(2*n));return 0;
}


Measured memory_bytes: 14512
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
#include <bits/stdc++.h>
using namespace std;
//fold
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
//using ll = long long;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#define push_back pb
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
int main(){
    speed;
	s ss;
	cin>>ss;
	int a,z;
	int n=(int)ss.size();
	for(int i=0;i<n;i++){
        if(ss[i]=='A'){
        a=i;
        break;
        }
	}
	for(int i=n-1;i>=0;i--){
        if(ss[i]=='Z'){
        z=i;
        break;
        }
	}
	s y="";
	y=ss.substr(a,(z-a)+1);
	cout<<y.size()<<endl;












































return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/




Measured memory_bytes: 788
import string

stg = input()
res = "None"
lets = {stg[0]}
if len(stg)>1:
  for i in range(1,len(stg)):
    lets.add(stg[i])
alpha = list(string.ascii_lowercase)
for i in alpha:
  if i not in lets:
    res = i
    break
print(res)

Measured memory_bytes: 3832
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3588
using System;

class Program
{
 static void Main(string[] args) 
 {
   String totalNumStr;
   String[] numsStr;
   int totalNum;
   int cnt;
   int evenCnt = 0;
   bool bkFlg = false;
   
   totalNumStr = Console.ReadLine();
   totalNum = int.Parse(totalNumStr);

   int[] nums = new int[totalNum];
   
   numsStr = Console.ReadLine().Split(' ');
   for( cnt = 0; cnt < totalNum; cnt++ )
   {
     nums[cnt] = int.Parse(numsStr[cnt]);
   }
   
   while(true)
   {
    for( cnt = 0; cnt < totalNum; cnt++ )
    {
      if( ( nums[cnt] % 2 ) != 0 )
      {
        bkFlg = true;
        break;
      }
      
      nums[cnt] = nums[cnt]/2;
    }
     
     if(bkFlg)
     {
       break;
     }
     else
     {
       evenCnt++;
     }
   }
   
   Console.WriteLine(evenCnt);
 }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
using namespace std;

 //int dp[1001][1001];
 /*
vector < int > tree(400005);

void buildtree (vector < int > v,int node,int start,int fin)
  {
      if(start==fin)
      {
          tree[node]=v[start];
          return;
      }
      int mid=(start+fin)/2;
      buildtree(v,2*node,start,mid);
      buildtree(v,2*node+1,mid+1,fin);
      tree[node]=tree[2*node]+tree[2*node+1];
  }

 int sum (int node,int tl,int tr,int l , int r)
   {
       if(l>r) return 0;
       if(l==tl and r==tr) return tree[node];
       int mid=(tl+tr)/2;
       return sum(2*node,tl,mid,l,min(r,mid))+sum(2*node+1,mid+1,tr,max(l,mid+1),r);
   }

  void update(int node,int tl , int tr,int pos,int val)
    {
        if(tl==tr) {tree[node]=val; return;}
        int mid=(tl+tr)/2;
        if(pos<=mid)
              update(2*node,tl,mid,pos,val);
        else
            update(2*node+1,mid+1,tr,pos,val);
        tree[node]=tree[2*node]+tree[2*node+1];

    }
string findSum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();

    // Reverse both of strings
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    int carry = 0;
    for (int i=0; i<n1; i++)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');

        // Calculate carry for next step
        carry = sum/10;
    }

    // Add remaining digits of larger number
    for (int i=n1; i<n2; i++)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
*/


void solve()
{
    ll int i,j=0,r=200,p,q,k,d,y=0,h,flag=1,n,m=0,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l;
   cin>>n;
   vi va(n),vb(n),vc(n);
   rep(i,0,n) cin>>va[i];
   rep(i,0,n) cin>>vb[i];
   rep(i,0,n-1) cin>>vc[i];
   rep(i,0,n)
     {
         y+=vb[va[i]-1]; //cout<<y<<" ";
         if(i<n and va[i+1]==va[i]+1) y+=vc[va[i]-1];
          //cout<<y<<" "<<endl;
     }
     cout<<y;

}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
     solve();
}


Measured memory_bytes: 256
if __name__ == "__main__":
	N = int(input())
	y = int(N / 1.08)
	ans = None
	for i in range(y, y + 10):
		if int(i * 1.08) == N:
			ans = i
			break
	if ans is not None:
		print(ans)
	else:
		print(":(")

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        int total = 500 * a + 100 * b + 50 * c;
        if (total == X) res++;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
/*输入A，B。

请找到一个最小的大于等于A的B的倍数K,输出K-A **(数据保证：1<=A,B<=100)*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=6;i>=0;i--)
    {
    	if(pow(2,i)<=n)
		{
            cout<<pow(2,i)<<endl;
            return 0;
        }	
	}
}

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

#define MAX 1000000

int main() {
    int num,L,result[MAX]={};
    while(cin>>num>>L, (num||L)){
        int i=0, at = num, t[6];
        for(int i=0 ; i<MAX ; i++) result[i] = -1;
        while(result[at] == -1){
            result[at] = i;
            for(int j=0 ; j < L ; j++){
                t[j] = at % 10;
                at = at / 10;
            }
            sort(t,t+L);
            int max_num=0, min_num=0, mul=1;
            for(int j=0; j < L ; j++){
                max_num += t[j] * mul;
                min_num += t[L-j-1] * mul;
                mul *= 10;
            }
            at = max_num - min_num;
            i++;
        }
        cout << result[at] << " " << at << " " << i-result[at] << endl;
    }
    return 0;
}

Measured memory_bytes: 6928
# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import deque

def bfs(graph, start, query, n):
    queue = deque([])
    acc = query[start] if start in query else 0
    queue.append([start, acc])
    ans = [-1] * n
    ans[start] = acc

    while queue:
        idx, acc = queue.popleft()
        for child in graph[idx].keys():
            if ans[child] >= 0:
                continue
            ans[child] = acc
            if child in query:
                ans[child] += query[child]
            queue.append([child, ans[child]])
    
    print(' '.join(map(str, ans)))

n,q = map(int, input().split())
tree = {}
start = 0
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if a not in tree:
        tree[a] = {}
    tree[a][b] = 1
    if b not in tree:
        tree[b] = {}
    tree[b][a] = 1

query = {}
for _ in range(q):
    p, x = map(int,input().split())
    p -= 1
    if p not in query:
        query[p] = x
    else:
        query[p] += x
bfs(tree, start, query, n)


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

using namespace std;

bool lexicographicalSmaller(vector<int> a, vector<int> b)
{
    int n = a.size();
    int m = b.size();
    for(int i = 0; i < n && i < m; i++)
    {
        if(a[i] < b[i]) return true;
        else if(b[i] < a[i])    return false;
        return i == n && i < m;
    }
}

int ans[20005];

set<int> s;

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin >> x;
		s.insert(x);
		auto it = s.begin();
		if(x == *it)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
 } 

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fcout cout << fixed << setprecision(18)

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

  double n, m, d;
  cin >> n >> m >> d;
  double ans = 2 * (n - d) * (m - 1.0) / n / n;
  if (d == 0) ans /= 2;
  fcout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
txy = [[0]*3] + $<.map{|s|
  s.split.map &:to_i
}
puts txy.each_cons(2).all?{|(t1, x1, y1), (t2, x2, y2)|
  t = t2 - t1
  dist = (x1-x2).abs + (y1-y2).abs
  dist <= t && t - dist & 1 < 1
} ? :Yes : :No

Measured memory_bytes: 12436
//copied
#include<cstdio>
#include<cstring>
#include<algorithm>
const int M=1e5+7;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,k,mx,s[M],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++) k=read(),s[k]++,mx=std::max(mx,k);
	for(int i=0;i<=mx;i++) ans=std::max(ans,s[i-1]+s[i]+s[i+1]);
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

int main() {
    int ans = 0;
    string s, t;

    cin >> s >> t;
    for (int i=0; i<s.size(); ++i) {
        if (s[i]!=t[i]) ++ans;
    }

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


Measured memory_bytes: 3796
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>


using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;


int N, M, L, Q;
map<int, int> m[512];


#define PI 3.141592653589
int A[200001], F[200001];

int is_ok(ll y, const int N, const ll K){
    ll cnt = 0;
    //fprintf(stderr, "y = %d\n", y);
    for (int i = 0; i < N; i++){
        //fprintf(stderr, "%d, %d, %d,, %d\n", 
        //    A[i], F[i], y, A[i] - y / F[i]);
        if (A[i] - y / F[i] > 0){
            cnt += A[i] - y / F[i];
            //fprintf(stderr, "%d, %d, %d\n", i, A[i] - y / F[i], cnt);
        }
        //cnt += max(0, A[i] - y / F[i]);
    }
    if (cnt <= K){
        return 1;
    } else {
        return 0;
    }
}

int main()
{
    int N;
    ll K;
    cin >> N >> K;
    ll max_val = 0LL;
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    for (int i = 0; i < N; i++){
        cin >> F[i];
        if (max_val < A[i] * F[i]){
            max_val = A[i] * F[i];
        }
    }
    sort(A, A+ N, greater<int>());
    sort(F, F+ N);
    
    ll lb = -1, ub = 1e18; //max_val;
    
    while (ub - lb > 1){
        ll mid = (ub + lb) /2;
        if (is_ok(mid, N, K)){
            ub = mid;
        } else {
            lb = mid;
        }
    }
    cout << ub << endl;
    return 0;    
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n;
 cin>>n;
 long long int sum=((n*(n+1))/2);
 long long int a3=n/3;
 long long int a5=n/5;
 long long int a15=n/15;
 long long int h=sum-(3*((a3*(a3+1))/2))-(5*((a5*(a5+1))/2))+15*((a15*(a15+1))/2);
 cout<<h;}

Measured memory_bytes: 3636
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.Ratio
import Data.Bits
import Control.Monad

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

toBit :: Int -> Int -> [Int]
toBit n l 
    | l == 0 = [] 
    | otherwise = toBit (shiftR n 1) (l - 1) ++ [n .&. 1]

solve :: Int -> [(Int, Int)] -> Int -> Int
solve len pcs goal = minimum $ map step [0..(2^len)-1]
    where
        step :: Int -> Int
        step bit = 
                    case compare r 0 of 
                        LT -> n
                        EQ -> n
                        GT -> 
                            case null fs of
                                True -> 10^9
                                False -> 
                                    let 
                                        ((i,_),(p',_)) = last fs
                                        need = ceiling $ r % (i * 100)
                                    in
                                        case compare need p' of
                                            LT -> n + need
                                            EQ -> 10^9
                                            GT -> 10^9
            where
                zs = zip (zip [1..len] (toBit bit len)) pcs
                (n,r) = foldl inner (0, goal) zs
                inner (acc, rest) ((i,b),(p,c))
                    | b == 1 = (acc + p, rest - (i * 100 * p + c))
                    | otherwise = (acc, rest)
                fs = filter (\((_,b), (_,_)) -> b == 0) zs

main = do
    [d,g] <- map read . words <$> getLine :: IO [Int]
    pcs <- replicateM d (toTuple <$> B.getLine)
    print $ solve d pcs g

Measured memory_bytes: 1020
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define N_ 101000
#define pii pair<int,int>
using namespace std;
int n, Q;
struct point {
	int a, b;
	bool operator<(const point &p)const {
		return a < p.a;
	}
}w[N_];
int p[N_];
int X[3*N_], CX, S[3*N_];
struct Range {
	int b, e;
}V[N_];
int CV, vis[N_];
vector<int>G[3 * N_], F[3 * N_];
int BIT[3 * N_], Res[3 * N_];
void Add(int a, int b) {
	while (a <= CX) {
		BIT[a] += b;
		a += (a&-a);
	}
}
int Sum(int a) {
	int r = 0;
	while (a) {
		r += BIT[a];
		a -= (a&-a);
	}
	return r;
}
int Calc(int a) {
	int t = lower_bound(X + 1, X + CX + 1, a) - X;
	return Res[t - 1];
}
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d",&w[i].a,&w[i].b);
		X[++CX] = w[i].a;
		X[++CX] = w[i].b;
	}
	for (i = 1; i <= n+1; i++) {
		scanf("%d", &p[i]);
		X[++CX] = p[i];
	}
	sort(X + 1, X + CX + 1);
	for (i = 1; i <= n; i++) {
		w[i].a = lower_bound(X + 1, X + CX + 1, w[i].a) - X;
		w[i].b = lower_bound(X + 1, X + CX + 1, w[i].b) - X;
		S[w[i].a]++;
		if (w[i].b < w[i].a) {
			G[w[i].a - 1].push_back(CV);
			F[w[i].b].push_back(CV);
			V[CV++] = { w[i].b,w[i].a - 1 };
		}
	}
	for (i = 1; i <= n + 1; i++) {
		p[i] = lower_bound(X + 1, X + CX + 1, p[i]) - X;
		S[p[i]]--;
	}
	int s = 0;
	for (i = 1; i <= CX; i++) {
		s += S[i];
		Add(i, S[i]);
	}
	scanf("%d", &Q);
	priority_queue<pii>PQ;
	int chk = 0, res = n;
	for (i = CX; i >= 1; i--) {
		for (auto &t : G[i]) {
			PQ.push({ -V[t].b, t });
		}
		while (Sum(i) < -1) {
			if (PQ.empty()) {
				chk = 1;
				break;
			}
			int x = PQ.top().second;
			Add(V[x].b, 1);
			Add(V[x].e + 1, -1);
			vis[x] = 1;
			res--;
			PQ.pop();
		}
	}
	Res[0] = res;
	while (!PQ.empty())PQ.pop();
	for (i = 1; i <= CX; i++) {
		for (auto &t : F[i]) {
			if (vis[t])continue;
			PQ.push({ V[t].e, t });
		}
		while (Sum(i) < 0) {
			if (PQ.empty()) {
				if (!chk)chk = i + 1;
				break;
			}
			int x = PQ.top().second;
			Add(V[x].b, 1);
			Add(V[x].e + 1, -1);
			res--;
			PQ.pop();
		}
		Res[i] = res;
	}
	for (i = chk - 1; i <= CX; i++)Res[i] = -1e9;
	while (Q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		printf("%d\n",max(max(Calc(a) + 1, Calc(b)),-1));
		
	}
	return 0;
}

Measured memory_bytes: 29304
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<tapu, Vtapu, greater<tapu> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p =   998244353;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
ut N, M, K, L, Q, D, H, W,R;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
int A[SIZE],B[SIZE];string s[SIZE];

LL solve(){
	cin >> N;
	REP(i,N) cin >> A[i];
	if(A[0]) return 0;
	VI v;
	EFOR(i,1,N-1){
		v.pb(A[i]);
	}
	sort(ALL(v));
	LL ans=1;
	B[0]++;
	REP(i,N-1){
//		cout << v[i] << endl;
		if(v[i]==0) return 0;
		B[v[i]]++;
		ans*=B[v[i]-1];
		ans%=p;
	}
	return ans;
}

signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	string s;
	cout << solve() << endl;
 
 
	//cin >> N;
	return 0;
 
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

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

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool cmp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    CIN(N,K);
    int ans=0;
    vi  x(N);
    rep(i,N)cin>>x[i];
    rep(i,N){
        if(x[i]*2>(K-x[i])*2) ans+=(K-x[i])*2;
        else ans+=x[i]*2;
    }
    printf("%d\n",ans);    

    return 0;
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int x,y,s;
    cin>>x>>y>>s;
    x--;y--;
    G[x].emplace_back(y,s);
    G[y].emplace_back(x,s);
  }
  
  {
    Int flg=1;
    vector<Int> val(n),used(n,0);
    queue<Int> q;
    val[0]=0;used[0]=1;
    q.emplace(0);
    while(!q.empty()){
      Int v=q.front();q.pop();
      for(auto p:G[v]){
	Int u,s;
	tie(u,s)=p;
	if(used[u]){
	  flg&=used[v]!=used[u];
	  flg&=val[v]+val[u]==s;
	  continue;
	}
	val[u]=s-val[v];
	used[u]=used[v]^2;
	q.emplace(u);
      }
    }

    if(flg){
      Int l=1e15,r=1e15;
      for(Int i=0;i<n;i++){
	if(used[i]==1) chmin(l,val[i]);
	else chmin(r,val[i]);
      }
      //cout<<l<<" "<<r<<endl;
      Int ans=r+l-1;
      chmax(ans,0);
      cout<<ans<<endl;
      return 0;
    }
  }
  Int ans=1;
  vector<vector<Int> > used(2,vector<Int>(n,0));
  vector<vector<Int> > dp(2,vector<Int>(n));
  queue<P> q;
  used[0][0]=1;
  dp[0][0]=0;  
  q.emplace(0,0);
  while(!q.empty()){
    Int t,v;
    tie(t,v)=q.front();q.pop();
    for(auto p:G[v]){
      Int u,s;
      tie(u,s)=p;
      Int nt=!t;
      if(used[nt][u]){
	ans&=dp[t][v]+dp[nt][u]==s;
	continue;
      }
      used[nt][u]=1;
      dp[nt][u]=s-dp[t][v];
      q.emplace(nt,u);
    }
  }
  
  Int v=dp[1][0]/2;
  for(Int i=0;i<n;i++){
    ans&=dp[0][i]+v==dp[1][i]-v;
    ans&=1<=dp[0][i]+v;
  }
  cout<<ans<<endl;
  return 0;
}


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

class DisjointSet
{
    public:
      vector<int> rank, p;

      DisjointSet() {}
      DisjointSet(int size)
      {
          rank.resize(size, 0);
          p.resize(size, 0);
          for (int i = 0; i < size; i++) makeSet(i);
      }

      void makeSet(int x)
      {
          p[x] = x;
          rank[x] = 0;
      }

      bool same(int x, int y)
      {
          return findSet(x) == findSet(y);
      }

      void unite(int x, int y)
      {
          link(findSet(x), findSet(y));
      }

      void link(int x, int y)
      {
          if (rank[x] > rank[y])
          {
              p[y] = x;
          }
          else
          {
              p[x] = y;
              if (rank[x] == rank[y])
              {
                  rank[y]++;
              }
          }
      }

      int findSet(int x)
      {
          if (x != p[x])
          {
              p[x] = findSet(p[x]);
          }
          return p[x];
      }
};

int main()
{
    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for (int i = 0; i < q; i++)
    {
        cin >> t >> a >> b;
        if (t == 0) ds.unite(a, b);
        else if (t == 1)
        {
            if (ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3152
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	VI x(n);
	REP(i, n) { scanf("%d", &x[i]); }
	int sum = 0;
	REP(i, n) { sum += x[i]; }
	int avg = sum / n;
	int result = INF;
	sum = 0;
	REP(i, n) { sum += square(x[i] - avg); }
	result = sum;
	sum = 0;
	REP(i, n) { sum += square(x[i] - (avg + 1)); }
	chmin(result, sum);
	printf("%d\n", result);
	return 0;
}

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

ok = [True]*1000005

a.sort()
ans=0
for i in range(n):
    if i<n-1 and a[i]!=a[i+1] and ok[a[i]]:
        ans+=1
    elif i==n-1 and ok[a[i]]:
        ans+=1
    if ok[a[i]]:
        for j in range(a[i],1000004,a[i]):
            ok[j]=False

print(ans)

    


Measured memory_bytes: 97028
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int n, x, y;
void vc(vector<int> array){
    for ( int i : array ) {
       std::cout << i << std::endl;
    }
    return;
}
int bfs(int m[],int base, int cur, int cost){
    if(cur < 0 || cur == n){
        return 0;
    }
    if(cost < m[cur]){
        m[cur] = cost;
    }else{
        return 0;
    }

    if(cur == x){
        bfs(m, base, y, cost + 1);
    }
    bfs(m, base, cur + 1, cost + 1);
    bfs(m, base, cur - 1, cost + 1);
}
int main(){
    cin >> n >> x >> y;
    x = x - 1;
    y = y - 1;
    vector<int> ans(n, 0);

    rep(i, n-1){
        int m[10000];
        fill_n(m, 10000, 10000);
        bfs(m, i, i, 0);
        for(int j=i+1;j<n;j++){
            ans[m[j]]++;
        }
    }
    rep(i, n-1){
        cout << ans[i + 1] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
queue<int>q[1003];
int b[1003];//b[i]表明时间  每天一次
int main(){
	int n;
	cin>>n;
	
	for(int i=1,tmp;i<=n;i++){
		for(int j=1;j<n;j++){
	   cin>>tmp;
	   q[i].push(tmp);
  }
}
  int flag=0;
	while(1){
		flag=0;
		for(int i=1;i<=n;i++){
			if(q[i].empty()) continue;//一有两个都有
			if(q[q[i].front()].front()==i){
				b[i]=b[q[i].front()]=max(b[i],b[q[i].front()])+1;
		  	q[q[i].front()].pop();
			  q[i].pop();
		  	flag=1;
		  }
		}
		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=q[i].size();
		}
		if(!sum) break;
		if(!flag) break;
	}
	if(!flag) cout<<-1<<'\n';
	else{
		int ans=0;
		for(int i=1;i<=n;i++) ans=max(ans,b[i]);
		cout<<ans;
	}
}

Measured memory_bytes: 4736
# -*- coding: utf-8 -*-
N, P = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

f0, f1 = 0, 0
for a in A:
    if a % 2 == 0:
        f0 += 1
    else:
        f1 += 1

ans = 0
n = 2 ** f0
for i in range(P, f1+1, 2):
    m = 1
    for j in range(i):
        m *= f1 - j
    for i in range(i):
        m /= i + 1

    ans += m * n

print(int(ans))


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    String str;
    int s;
   
   
    str = scan.next();   
    s = str.length();
   for(int i= s-1 ; i>=0 ;i--){
       char c = str.charAt(i);
       System.out.print(c);
   }
   
   System.out.println();
    }
}

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

int ary[1000001];

int main()
{
	int n, q;
	priority_queue<pair<int, int>> que;

	cin >> n >> q;
	for (int i = 0; i < q; i++)
	{
		int a, b;
		cin >> a >> b;
		ary[a] += b;
		que.push(pair<int, int>(ary[a], -a));

		while (!que.empty())
		{
			pair<int, int> p = que.top();
			if (p.first == ary[-(p.second)])
			{
				cout << -(p.second) << ' ' << p.first << endl;
				break;
			}
			que.pop();
		}
	}

	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
const long long inf = 1e18;
const long long mod = 1e9 + 7;

long long d0[N], d1[N];
long long w0[N], w1[N];
vector<pair<int, int>> edge[N];

void dijkstra(int start, long long* dp, long long* ways) {
  fill(dp, dp + N, inf);
  memset(ways, 0, sizeof(ways));
  dp[start] = 0;
  ways[start] = 1;
  priority_queue<pair<long long, int>> pq;
  pq.emplace(dp[start], start);
  while (!pq.empty()) {
    long long cost; int now;
    tie(cost, now) = pq.top();
    pq.pop();
    cost = -cost;
    if (cost != dp[now]) continue;
    for (auto it : edge[now]) {
      int near = it.first;
      long long ncos = cost + it.second;
      if (dp[near] > ncos) {
        dp[near] = ncos;
        ways[near] = ways[now];
        pq.emplace(-dp[near], near);
      } else if (dp[near] == ncos) {
        ways[near] = (ways[near] + ways[now]) % mod;
      }
    }
  }
}

int main() {
  int n, m, s, t;
  scanf("%d %d %d %d", &n, &m, &s, &t);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    edge[u].emplace_back(v, w);
    edge[v].emplace_back(u, w);
  }
  dijkstra(s, d0, w0);
  dijkstra(t, d1, w1);
  long long distance = d0[t];
  //cout << distance << endl;
  long long ans = w0[t] * w1[s] % mod;
  //printf("%lld %lld\n", w0[t], w1[s]);
  for (int i = 1; i <= n; i++) {
    if (2 * d0[i] == distance) {
      //printf("titik %d\n", i);
      long long subs = w0[i] * w1[i] % mod;
      subs = subs * subs % mod;
      ans -= subs;
      ans %= mod;
      if (ans < 0) ans += mod;
    }
  }
  //for (int i = 1; i <= n; i++) printf("%lld ", w0[i]); printf("\n");
  //for (int i = 1; i <= n; i++) printf("%lld ", w1[i]); printf("\n");
  for (int i = 1; i <= n; i++) {
    for (auto it : edge[i]) {
      int to = it.first;
      if (d0[i] * 2 < distance && d0[to] > distance / 2 && d0[i] + it.second + d1[to] == distance) {
        //printf("%d %d\n", i, to);
        long long subs = w0[i] * w1[to] % mod;
        subs = subs * subs % mod;
        ans -= subs;
        ans %= mod;
        if (ans < 0) ans += mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

long long a[100005];

int main()
{
    long long n, k;
    cin >> n >> k;///LL
    for(long long i = 0; i < n; ++i){
        cin >> a[i];
    }

    long long x = 0;
    for(long long i = 62; i >= 0; --i){
        long long ones = 0;
        for(long long j = 0; j < n; ++j){
            if(a[j] & (1LL << i)){
                ones++;
            }
        }
        if(ones <= n / 2){
            if(x + (1LL << i) <= k){
                x += (1LL << i);
            }
        }
    }

    long long sum = 0;
    for(long long i = 0; i < n; ++i){
        sum += (a[i] ^ x);
    }

    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<ll> result;
vector<pii> stones;

int find_tar(int pos){
  int cur = -stones[pos].second;
  for (int i = pos + 1; i < N; i++){
    int tmp = -stones[i].second;
    if (tmp < cur){
      return i;
    }
  }
  return -1;
}
ll rest;
int main() {
  cin >> N;
  result.resize(N);
  stones.resize(N);
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    stones[i] = mp(x, -i);
    rest += x;
  }
  sort(stones.rbegin(), stones.rend());
  ll pos,tar;
  pos = tar = 0;
  ll pos_cnt,tar_cnt;
  ll pos_val;
  while (true){
    tar = find_tar(pos);
    if (tar == -1)break;
    pos_cnt = stones[pos].first;
    tar_cnt = stones[tar].first;

    pos_val = -stones[pos].second;
    ll sum = 0;
    sum += pos * (pos_cnt - tar_cnt);

    for (int i = pos; i < tar; i++){
      sum += (stones[i].first - tar_cnt);
    }
    result[pos_val] = sum;
    rest -= sum;
    pos = tar;
  }
  pos_val = -stones[pos].second;
  result[pos_val] += rest;
  for(int i = 0; i < N; i++){
    cout << result[i] << endl;
  }
  return 0;
}


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

int main()
{
	int a, b, n, i, nout, faa;
	cin >> n >> a >> b;
	nout = 0;
	for (i = 0; i < n+1; i++) {
		faa = i % 10 + (i / 10) % 10 + (i / 100) % 10 + (i / 1000) % 10 + (i / 10000) % 10;
		if (faa >= a && faa <= b) nout += i;
	}
	cout << nout;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
//	freopen("SNOOKER.inp","r",stdin);
//	freopen("SNOOKER.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
/*----------------------------------------------------------------------
2
3 4
2 4 2
3 3
3 3 3
-----------------------------------------------------------------------*/
using ll =  long long;
#define endl "\n"
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define what_is(x)  cerr << #x << " is :" << (x) << endl
#define what_are(x,y) cerr << #x <<" is : " << (x) <<" ; " << #y <<" is: " <<y << endl
#define pii pair<int,int>
#define fs first
#define sc second
const int MOD =  1e9+7;
const int inf = INT_MAX;
const int MAX_N = 1e5 + 7;


int n, w, s = 0;
int wei[107], v[107];
int dp[107][100007];
void solve()
{
	for(int i = 0; i<= n; i++)
	fill(dp[i],dp[i] + 100007, MOD);
	dp[0][0] = 0;
	
	cin >> n >> w;
	for(int i = 1; i<= n; i++)
	{
		cin >> wei[i] >> v[i];
		s += v[i];
	
	}

	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= s; j++)
		{
			
			dp[i][j] = dp[i-1][j];
			if(j >= v[i])
			{
				dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + wei[i]);
			}
			
		}
	}
	for(int i = s; i > 0; i--) 
	{
		if(dp[n][i] <= w)
		{
			cout << i;
			return ;
		}
	}
	
	
	
}


Measured memory_bytes: 41216