akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef std::pair<int, int> ipair;
const int MAX_V = 100010;
const int MAX_LOG_V = 17;
vector<ipair> G[MAX_V];
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];
vector<int> eulerT;

class TREE {

   public:
      int k = 0;
      ll distance[MAX_V];
      int begin[MAX_V * 2];
      int end[MAX_V * 2];

      // vertex, parent, depth, distance
      void dfs(int v, int p, int d, ll l) {
         parent[0][v] = p;
         depth[v] = d;
         distance[v] = l;
         begin[v] = k;
         eulerT.push_back(v);
         k++;
         for (auto& g : G[v]) {
            if (g.first != p) {
               dfs(g.first, v, d + 1, l + g.second);
               eulerT.push_back(v);
               k++;
            }
         }
         end[v] = k;
      }

      void init(int V, int root) {
         dfs(root, -1, 0, 0);
         for (int k = 0; k + 1 < MAX_LOG_V; k++) {
            for (int v = 0; v < V; v++) {
               if (parent[k][v] < 0) parent[k + 1][v] = -1;
               else parent[k + 1][v] = parent[k][parent[k][v]];
            }
         }
      }

      int lca(int u, int v) {
         if (depth[u] > depth[v]) swap(u, v);
         for (int k = 0; k < MAX_LOG_V; k++) {
            // if k th digit of depth[v] - depth[u] is 1
            if ((depth[v] - depth[u]) >> k & 1) {
               v = parent[k][v];
            }
         }
         if (u == v) return u;
         for (int k = MAX_LOG_V - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
               u = parent[k][u];
               v = parent[k][v];
            }
         }
         return parent[0][u];
      }
};

int main() {
   int N;
   cin >> N;
   int a, b, c;
   for (int i = 0; i < N - 1; i++) {
      cin >> a >> b >> c;
      a--;
      b--;
      G[a].push_back(ipair(b, c));
      G[b].push_back(ipair(a, c));
   }
   int Q, K;
   cin >> Q >> K;
   K--; 
   TREE tree;
   tree.init(N, K);
   
   int u, v;
   for (int q = 0; q < Q; q++) {
      cin >> u >> v;
      u--;
      v--;
      ll ans = 0;
      ans += tree.distance[u] + tree.distance[v];
      cout << ans << endl;
   }
   
   return 0;
}


Measured memory_bytes: 20596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 2e5+5;
const ll mod = 1e9+7;
int pnt[12][12];
int n,d;
bool ch(int i, int j){
    int dis = 0;
    for(int k=0;k<d;k++){
        dis+=(pnt[i][k]-pnt[j][k])*(pnt[i][k]-pnt[j][k]);
    }
    for(int k=0;k<150;k++){
        if(k*k==dis)return true;
    }
    return false;
}
void solve(){
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>pnt[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(ch(i,j))ans++;
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
  //  cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int f = sc.nextInt();
 
		if ((e - a) > f){
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}
    }
}


Measured memory_bytes: 21844
/*
  _    _ _      _ _      _ _      
 | |__| | | _ _| | | _ _| | | ___
 | '_ \_  _| ' \_  _| ' \_  _(_-< 
 |_.__/ |_||_||_||_||_||_||_|/__/

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define db(x) cout << #x << "=" << x << '\n'
#define rep(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(x) printf("%s\n", x)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define F first
#define S second
#define pb push_back
#define ll long long

#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))


typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef complex<double> point;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const int mod = 1000000007;
const int N = 3e5 + 7, M = N, OO = 1e9 + 7;
const ll LLOO = 1e18 + 7;

//=======================

vi g[N];
int n,a[N];

void solve()
{
	string str;
	cin >> str;
	
	int n = str.size();
	if (str[n-1] == 's')
	{
		str += "es";
	}else str += "s";
	ps(str.c_str());
}

int main()
{
    // uncomment if file :
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    int t = 1;
    // si(t); // uncomment if testcases
    while (t--)
        solve();
    return 0;
}


// btw i use arch


Measured memory_bytes: 10660
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	ll X, Y;cin >> X >> Y;

	for(int i = 0; i <= X; i++){
		if(4 * i + 2 * (X-i) == Y){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

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

int main(){
  int A, B, result;
  cin >> A >> B;
  
  if(A > 12){
    result = B;
  }else if(A > 5){
    result = B/2;
  }else{
    result = 0;
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
//typedef pair<int, int> P;
//vector<long long> a(max_n);
//map<int, int> m;
static const int max_n = 2e5+2, max_m = 1e8;
static const ll  INF = 1000000000;
const long long mod = 1e18;
int ci;

int main(){
    int n;
    vector<int> a(max_n);
    cin >> n;
    for(int i=0; i<n; ++i) cin >> a[i];
//    sort(a.begin(), a.end(), greater<int>());
    sort(a.rbegin(), a.rend());
    ll ans=0;
    int j=0;
    for(int i=0; i<n-1; ++i){
        if(i==0){
            ans+=a[j];
            ++j;
            continue;
        }
        if(i%2!=0) ans+=a[j];
        else{
            ans+=a[j];
            ++j;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3856
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                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; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	int n = s.nextInt();
    	int v = (int)(n+Math.pow(n, 2)+Math.pow(n, 3));
    	System.out.println(v);
    	
    }	
}

Measured memory_bytes: 32744
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll n,k;cin >> n >> k;
  ll x = n % k;
  ll y = - ( x - k);
  cout << min(x, y) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n;
//ld ;
// string s,t;
 
int main() {
  cin >> n;
  vector<string> s1(n);
  ll t1[n];
  ll pasttime = 0;
  for(ll i = 0; i < n; i++){
    string s;
    ll t;
    cin >> s >> t;
    s1[i] = s;
    pasttime += t;
    t1[i] = pasttime;
  }
  string x;
  cin >> x;
  ll mark;
  for(ll j = 0; j<n;j++){
    if(s1[j] == x){
      mark = j;
    }
  }
  cout << pasttime -t1[mark] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define ti tuple<int, int, int>

int main() {

    ll N, K;
    cin >> N >> K;

    vector<int> P;
    int p;
    for (int i = 0; i < N; i++) {
        cin >> p;
        P.push_back(p);
    }

    vector<double> E(1010);
    E[0] = 0;
    for (int i = 1; i < 1005; i++) {
        E[i] = (E[i-1] * (i-1) + i) / i;
    }

    double ans;
    double sum = 0;
    for (int i = 0; i < K; i++) {
        sum += E[P[i]];
    }
    ans = sum;

    for (int i = K; i < N; i++) {
        sum += E[P[i]];
        sum -= E[P[i-K]];
        if (sum > ans) ans = sum;
    }

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    int N,total=0;cin>>N;
    vector<int> A(N),B(31,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=0;j<31;j++){
            if(A[i]&(1<<j)){ B[j]++;
            break;
            }
        }
        total=total^A[i];
    }

    int ans=0;

    for(int j=30;j>=0;j--){
        if(total&(1<<j)){
            if(B[j]){
                ans++;
                total=(total^(1<<j))^((1<<j)-1);
            }else ans-=1000;
        }
    }

    if(ans>=0) cout<<ans<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 998244353
ll n,m,arr[sz],brr[sz],k,l,crr[sz],t,i,j,hi,lo,mi,drr[sz];
int main()
{
 scanf("%lld %lld %lld",&n,&m,&k);
 for(i=1;i<=n;i++)
 {
     scanf("%lld",&arr[i]);
     brr[i]=brr[i-1]+arr[i];
 }
 for(i=1;i<=m;i++)
 {
     scanf("%lld",&crr[i]);
     drr[i]=drr[i-1]+crr[i];
 }
 hi=0;
 for(i=0;i<=n && brr[i]<=k;i++)
 {
     l=k-brr[i];
     j=upper_bound(drr+1,drr+m+1,l)-(drr+1);
  //   printf("%lld %lld %lld\n",j,l,k);
    // while(j>m || drr[j]>l)
      //  j--;
   hi=max(hi,i+j);
 }

printf("%lld\n",hi);
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

long long gcd(long long aaa,long long bbb){
    if(bbb==0){
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
 
long long lcm(long long aaa,long long bbb){
    long long g = gcd(aaa,bbb);
    return aaa/g * bbb;
}

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

      
      cin>>n;
      cin>>pos;
      rep(i,n-1){
        cin>>a;
        pos=lcm(pos,a);
      }
      Cout(pos);
     

       
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
using std::ceil;
typedef long long ll;
int main()
{
	ll n,a,b,c,d;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	ll l1 = ceil((double)((n-1) * c - (b - a))/(c+d));
	ll r1 = ((double)(n-1)*d-(b-a))/(c+d);
	ll l2=0;
	ll r2=n-1;
	//printf("%lld %lld %lld %lld\n",l1,r1,l2,r2);
	if (l1 > r1 || r1 < l2 || r2 < l1) printf("NO\n");
	else printf("YES\n");
}

Measured memory_bytes: 128
H, W = map(int,input().split())
a = []

for i in range(H):
    a.append(input())

row = [i for i in range(H)]
column = [i for i in range(W)]

row_delete = []
column_delete = []

for i in range(H):
    flag_delete = True
    for j in range(W):
        if a[i][j] == "#":
            flag_delete = False
            break
    if flag_delete == True:
        row_delete.append(i)

for i in range(W):
    flag_delete = True
    for j in range(H):
        if a[j][i] == "#":
            flag_delete = False
            break
    if flag_delete == True:
        column_delete.append(i)

# 行
for i in row_delete:
    row.remove(i)
# 列
for i in column_delete:
    column.remove(i)

ans = [["" for _ in range(len(column))] for _ in range(len(row))]

count_row = 0
for i in row:
    count_column = 0
    for j in column:
        ans[count_row][count_column] = a[i][j]
        count_column += 1
    count_row += 1

for i in range(len(ans)):
    print("".join(ans[i]))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX / 2)

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    int x;
    cin>>x;
    vector<bool> table(x+1);
    table[1]=true;
    for(ll b=2;b<=x;++b){
        ll v=b*b;
        while(v<=x){
            table[v]=1;
            v*=b;
        }
    }
    for(ll i=x;i>0;--i){
        if(table[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}
/*

*/


Measured memory_bytes: 3596
//{{{
#include <bits/stdc++.h>
using namespace std;
//types
typedef long long ll;
typedef pair<int,int> pii;
//input
bool SR(int &_x){return scanf("%d",&_x)==1;}bool SR(ll &_x){return scanf("%lld",&_x)==1;}
bool SR(double &_x){return scanf("%lf",&_x)==1;}bool SR(char *_s){return scanf("%s",_s)==1;}
bool RI(){return true;}
template<typename I,typename... T>bool RI(I &_x,T&... _tail){return SR(_x) && RI(_tail...);}
//output
void SP(const int _x){printf("%d",_x);}void SP(const ll _x){printf("%lld",_x);}
void SP(const double _x){printf("%.16lf",_x);}void SP(const char *s){printf("%s",s);}
void PL(){puts("");}
template<typename I,typename... T>void PL(const I _x,const T... _tail)
{SP(_x);if(sizeof...(_tail)) putchar(' ');PL(_tail...);}
//macro
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=int(b);i--)
#define pb push_back
#define mkp make_pair
#define F first
#define S second
//debug
#ifdef darry140
template<typename A,typename B>
ostream& operator <<(ostream&_s, const pair<A,B> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It>
ostream& _OUTC(ostream &_s,It _b,It _e)//container
{
    _s<<"{";
    for(auto _it=_b;_it!=_e;_it++) _s<<(_it==_b?"":" ")<<*_it;
    _s<<"}";
    return _s;
}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const map<A,B> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const set<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const vector<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename I>
void _DOING(const char *_s,I&& _x){cerr<<_s<<"="<<_x<<endl;}//without ','
template<typename I,typename... T>
void _DOING(const char *_s,I&& _x,T&&... _tail)//with ','
{
    int _c=0;
    static const char _bra[]="({[";
    static const char _ket[]=")}]";
    while(*_s!=',' || _c!=0)//eg. mkp(a,b)
    {
        if(strchr(_bra,*_s)) _c++;
        if(strchr(_ket,*_s)) _c--;
        cerr<<*_s++;
    }
    cerr<<"="<<_x<<", ";
    _DOING(_s+1,_tail...);
}
#define debug(...) do{\
    fprintf(stderr,"%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__,__VA_ARGS__);\
}while(0)
#else
#define debug(...)
#endif
//}}}
const int maxn=1e5+5;
int n;ll a[maxn];
void read()
{
    RI(n);
    REP1(i,1,n) RI(a[i]);
}
ll k;
void build()
{
    ll sum=accumulate(a+1,a+n+1,0LL);
    if(sum%(1LL*n*(n+1)/2)!=0){PL("NO");exit(0);}
    k=sum*2/n/(n+1);
    a[0]=a[n];
    PER1(i,n,1) a[i]=a[i]-a[i-1];
}
void sol()
{
    ll cnt=0;
    REP1(i,1,n) 
    {
        if(a[i]>k || (k-a[i])%n){PL("NO");exit(0);}
        cnt+=(k-a[i])/n;
    }
    if(cnt!=k) PL("NO");
    else PL("YES");
}
int main()
{
    read();
    build();
    sol();
    return 0;
}




































/*End Of File*/




Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  vector<int> times(N);
  for(int i=0;i<N;i++){cin >> times.at(i);}
  int M;
  cin >> M ;
  for(int i=0;i<M;i++){
    int p,x;
    cin >> p >> x;
    int count = 0;
    for(int j=0;j<N;j++){
      if(j+1==p){
        count += x;
      } else{
        
        count += times.at(j);
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		try{
			int w=Integer.parseInt(br.readLine());
			int n=Integer.parseInt(br.readLine());
			int rep;
			int[] line=new int[w+1];
			for(int i=1;i<=w;i++){	//line[]に1〜wを代入
				line[i]=i;
			}
			int a,b;
			String[] str=new String[2];
			for(int i=0;i<n;i++){
				str=br.readLine().split(",");
				a=Integer.parseInt(str[0]);
				b=Integer.parseInt(str[1]);
				rep=line[a];	//line[a]とline[b]を入換
				line[a]=line[b];
				line[b]=rep;
			}
			for(int i=1;i<=w;i++){
				System.out.println(line[i]);
			}
		}catch(Exception e){
		}
	}
}

Measured memory_bytes: 16936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}

void solve() {
  int q; cin >> q;
  while (q--) {
    ll a, b; cin >> a >> b;
    if (a > b) swap(a, b);

    if (b-a <= 1) {
      cout << (a-1) * 2 << endl;
    } else {
      ll rt = sqrtl(a*b - 1);
      if (rt*(rt+1) < a*b) {
        cout << rt*2 - 1 << endl;
      } else {
        cout << rt*2 - 2 << endl;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

typedef long long li;
using namespace std;

int main(){
    li N,Sum=0;
    cin >> N;

    for(int i=1;i<=N;i++){
        if(i%3 != 0 && i%5 != 0){
            Sum += i;
        }
    }

    cout << Sum << endl;
    return 0;
}


Measured memory_bytes: 3624
N, Y = map(int, input().split(" "))
yukichi = -1 # 10000円札の枚数
higuchi = -1 # 5000円札の枚数
noguchi = -1 # 1000円札の枚数
for x in range(N + 1):
	for y in range(N + 1):
		z = N - x - y
		if z >= 0:
			sum = x * 10000 + y * 5000 + z * 1000
			if sum == Y and x + y + z == N:
				yukichi = x
				higuchi = y
				noguchi = z

print(yukichi, higuchi, noguchi)   

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
#define REP(i, x, n) for(ll (i)=(x); (i)<(n); (i)++)
#define RREP(i, x, n) for(ll (i)=(n)-1; (i)>=x; (i)--)
#define FOR(i, n) for(ll (i)=0; (i)<(n); (i)++)
#define RFOR(i, n) for(ll (i)=(n)-1; (i)>=0; (i)--)

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

        ll N, S, ans = 0;
        const ll mod = 998244353;
        cin >> N >> S;
        vector<ll> A(N);
        FOR(i, N) cin >> A[i];
        vector<vector<ll> > dp(N+1, vector<ll>(S+1, 0));
        dp[0][0] = 1;
        FOR(i, N) {
                FOR(w, S+1) {
                        dp[i+1][w] += 2 * dp[i][w];
                        dp[i+1][w] %= mod;
                        if (w + A[i] <= S) {
                                dp[i+1][w + A[i]] += dp[i][w];
                                dp[i+1][w + A[i]] %= mod;
                        }
                }
        }
        cout << dp[N][S] << endl;

        return 0;
}

Measured memory_bytes: 73596
#include "bits/stdc++.h"
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define endl "\n"
#define umap unordered_map<int, int>
#define uset unordered_set<int>
#define MOD 1000000007
using namespace std;

int main()
{
	FAST_IO;
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n)
	{
		cin>>a[i];
	}
	ll temp[n];
	temp[0] = a[0];
	rep(i,1,n)
	{
		temp[i] = max(temp[i-1], a[i]);
	}
	ll ans = 0;
	rep(i,0,n)
	{
		ans += (temp[i] - a[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 6728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] abt = sc.nextLine().split(" ");
        int R = Integer.parseInt(abt[0]);
        int G = Integer.parseInt(abt[1]);
        int B = Integer.parseInt(abt[2]);
        int N = Integer.parseInt(abt[3]);

        int pattern = 0;
        for (int i = 0; i * R <= N; i++) {
            long x = i * R;
            for (int j = 0; x + j * G <= N; j++) {
                long y = j * G;
                if ((N - x - y) % B == 0) {
                    pattern++;
                }

            }
        }
        System.out.println(pattern);
    }
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200)
    pr(s);
  else
    pr("red");
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
template<typename T>void read(T &x){
	x=0;int f(1);char c(getchar());
	for(;!isdigit(c);c=getchar())if(c=='-')f=-f;
	for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)write(x/10),x%=10;
	putchar(x+'0');
}
int main(){
	long long x;read(x);
	long long no=100;int day=0;
	while(no<x){
		++day,no=no+no/100;
	}
	write(day);
	return 0;
}


Measured memory_bytes: 3636
/***************************************************************
	File name: B.cpp
	Author: ljfcnyali
	Create time: 2019年08月04日 星期日 19时57分57秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

int main()
{
    int n, ans = 0; scanf("%d", &n);
    REP(i, 1, n)
    {
        int x = i, sum = 0;
        while ( x > 0 ) { x /= 10; ++ sum; }  
        if ( sum % 2 == 1 ) ++ ans;
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }

const long long INF = 1LL << 60;

bool dp[100100];

int main () {
    string A,B;
    cin >> A >> B;

    if(A.size() > B.size())cout << "GREATER" << endl;
    else if(A.size() < B.size()) cout << "LESS" << endl;
    else{
        for(int i =0;i<A.size();i++){
            if(A[i]>B[i]){
                cout << "GREATER" << endl;
                return 0;;
            }
            else if(A[i]<B[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout<< "EQUAL" << endl;

    }
    
}



Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 100111;
int n;
ll X;
ll b[maxn], l[maxn], r[maxn];
ll sum[maxn], L;
vector<pair<ll,int> > v;
ll get(int x, int ban)
{
	return sum[x]-(ban<x?v[ban].FF:0);
}
int search(ll dlt, int ban)
{
	int l = 0, r = n;
	while (l<=r)
	{
		int m = l+r>>1;
		if (get(m, ban)+dlt<=L) l = m+1;
		else r = m-1;
	}
	return r;
}
int main()
{
	getii(n, X);
	for (int i=1; i<=n; i++)
	{
		geti(b[i]);
		getii(l[i], r[i]);
		v.PB(MP(1ll*l[i]*b[i]+1ll*r[i]*(X-b[i]), i));
		L += l[i]*b[i];
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	sum[0] = 0;
	for (int i=1; i<=n; i++) sum[i] = sum[i-1]+v[i-1].FF;
	ll ans = 1e18;
	for (int t=0; t<v.size(); t++)
	{
		{
			int it = search(0, t);
			ll cur = L-get(it, t);
			int i = v[t].SS;
			if (cur<=l[i]*b[i]) ans = min(ans, 1ll*(it-(t<it))*X+(cur+l[i]-1)/l[i]);
		}
		{
			int i = v[t].SS;
			int it = search(l[i]*b[i], t);
			ll cur = L-get(it, t)-l[i]*b[i];
			if (cur<=r[i]*(X-b[i])) ans = min(ans, 1ll*(it-(t<it))*X+b[i]+(cur+r[i]-1)/r[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=55;
int n,m,a[N];
ll f[N][N*N][N];
int main(){
//	freopen("b.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0][0][0]=1;
	for(int i=1;i<=n;i++){
		for(int k=i;k>=0;k--){
			for(int j=n*m+1;j>=0;j--){
				f[i][j][k]+=f[i-1][j][k];
				if(k>=1 && j>=a[i]) f[i][j][k]+=f[i-1][j-a[i]][k-1];
			}
		}	
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans+=f[n][m*i][i];
	printf("%lld\n",ans);
	return 0;
} 

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

using namespace std;
#define ll long long
ll mod = 1000000007 ;

int main()
{
 ll s,c;
 cin >> s >> c;
 ll ans = 0;
 if(s*2<=c)
 {
     ans += s ;
     c -= s*2;
     ans += c/4 ;
     cout << ans << endl;
 }
 else
 {
   ll d = c/2;
   ans += min(s,d);
   c-=d*2;
   ans += c/4 ;
   cout << ans << endl;
 }






}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL x(n),y(n),z(n),sum(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	VL sign = {1,-1};
	LL ans = 0;
	for (int i = 0; i < (1<<3); i++) {
		for (int j = 0; j < n; j++) {
			sum[j] = x[j]*sign[i%2] + y[j]*sign[(i>>1)%2] + z[j]*sign[(i>>2)%2];
		}
		sort(RALL(sum));
		LL tmp = 0;
		for (int i = 0; i < m; i++) {
			tmp += sum[i];
		}
		ans = max(ans,tmp);
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
# coding: utf-8
N = int(input())
d = {}
for i in range(N):
    s = input()
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1
ans = []
v = max(d.values())
for k in d.keys():
    if d[k] == v:
        ans.append(k)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 32096
s=input()
t=input()
ls=len(s)
lt=len(t)
ans=10000000
for i in range(ls-lt+1):
    temp=s[i:i+lt]
    cnt=0
    for j in range(lt):
        if temp[j]!=t[j]:
            cnt+=1
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector <vector <ll> > a(n, vector <ll> (n)), b;
    vector <vector <int> > prv(n, vector <int> (n, -1));
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < n; ++ j) {
            cin >> a[i][j];
        }
    }
    b = a;
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
                if (b[i][j] == b[i][k] + b[k][j] && k != i && k != j) {
                    prv[i][j] = k;
                }
            }
        }
    }
    for (int i = 0; i < n; ++ i) {
        if (a[i][i] != 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < n; ++ j) {
            if (a[i][j] != b[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < i; ++ j) {
            if (!~prv[i][j]) ans += a[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}


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


using ll = long long int;

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    
    cin >> n >> m;
    
    string ans = "No";
    if (n == m)
        ans = "Yes";
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
if abs(n - m) > 1:
    print(0)
else:
    ret1 = 1
    for i in range(1, n + 1):
        ret1 = (ret1 * i) % 1000000007
    ret2 = 1
    for i in range(1, m + 1):
        ret2 = (ret2 * i) % 1000000007
    print((ret1 * ret2 * (2 if n == m else 1)) % 1000000007)


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

int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i)) {
      count ++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
vector<int> bfs(const vector<vector<int>> &g, int s){
    int n = (int) g.size();
    vector<int> dist(n, 1<<30);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while(q.size()){
        int v = q.front();
        q.pop();
        for(int x : g[v]){
            if(dist[x]!=1<<30)continue;
            dist[x] = dist[v] + 1;
            q.push(x);
        }
    }
    return dist;
}
int A[1000][1000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>>g(n);
    vector<vector<int>>rg(n);
    
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        rg[b].push_back(a);
        A[a][b] = 1;
    }
    int s = -1;
    int len = 1<<30;
    int U = -1, V = -1;
    rep(u,n){
        auto dist = bfs(g, u);
        show(u,dist);
        rep(v,n){
            if(A[v][u]){
                if(len > dist[v] + 1){
                    len = dist[v] + 1;
                    U = u;
                    V = v;
                }
            }
        }
    }
    show(len);
    if(len == 1<<30){
        cout << - 1 << endl;
        return 0;
    }
    cout << len << endl;
    set<int>st;
    auto dist = bfs(g, U);
    auto dist2 = bfs(rg, V);
    st.insert(U);
    st.insert(V);
    int now = U;
    show(dist);
    show(dist2);
    while(st.size()< len){
        for(int x : g[now]){
            show(now,x);
            if(dist[now] + dist2[x] + 1 == dist[V]){
                now = x;
                st.insert(x);
                break;
            }
        }
    }
    for(auto  x : st){
        cout << x + 1 << "\n";
    }
}

Measured memory_bytes: 3840
N = int(input())
a = [int(i) for i in input().split()]
 
def pura(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] <= 0:
        ans += 1 + abs(A[0])
        A[0] = 1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] >= 0:
                ans += abs(A[i] + 1 + check)
                A[i] = -1 - check
        else:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 - check))
                A[i] = 1 - check
        check += A[i]
    return ans
 
def mai(a):
    A = a[:]
    ans = 0
    check = 0
    if A[0] >= 0:
        ans +=1 + abs(A[0])
        A[0] = -1
        
    check += A[0]
    
    for i in range(1, N):
        if i % 2 != 0:
            if check + A[i] <= 0:
                ans += abs(A[i] - (1 - check))
                A[i] = 1 - check
        else:
            if check + A[i] >= 0:
                ans += abs(A[i] +( 1 + check))
                A[i] = -1 - check
        check += A[i]
    return ans
print(min(pura(a), mai(a)))

Measured memory_bytes: 14644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#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())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

int lis(vector<int>& v) {
    vi dp(1, v[0]);
    for(int i = 1; i < v.size(); i++) {
        if(v[i] > dp[dp.size() - 1]) {
            dp.push_back(v[i]);
        } else {
            int pos = distance(lower_bound(dp.begin(), dp.end(), v[i]), dp.begin());
            dp[pos] = v[i];
        }
    }
    return (int)dp.size();
}

int conlis(vector<int>& v) {
    vi dp(v.size() + 1, 0);
    int ans = 0;
    for(int i = 0; i < v.size(); i++) {
        dp[v[i]] = dp[v[i] - 1] + 1;
        ans = max(ans, dp[v[i]]);
    }
    return ans;
}


int main(void) {

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];

    fin(n-conlis(v));

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int q; cin >> q;
    deque<int> dq;
    rep(i,q){
        int com; cin >> com;
        int d, p;
        if(com == 0 || com == 2)cin >> d;
        if(com == 0 || com == 1)cin >> p;
        if(com == 0){
            if(d == 0)dq.push_front(p);
            else dq.push_back(p);
        }else if(com == 1)cout << dq[p] << endl;
        else {
            if(d == 0)dq.pop_front();
            else dq.pop_back();
        }
    }
    return 0;
} 


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


namespace Test1 {

    


    class ClassMain {


        

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = int.Parse(line);
                int n = ints[0]; int m = ints[1];
                if (n == 0) { break; }
                int[] prices = new int[n];
                
                for (int i = 0; i < n; i++) {
                    prices[i]=int.Parse(Console.ReadLine());
                }
                int[] votes = new int[n];

                for (int i = 0; i < m; i++) {
                    int rank = int.Parse(Console.ReadLine());
                    for (int priceInd = 0; priceInd < n; priceInd++) {
                        if (rank >= prices[priceInd]) {
                            votes[priceInd]++;
                            break;
                        }
                    } 
                }
                int max = -1;
                int maxKyougi = -1;
                for (int i = 0; i < n; i++) {
                    if (max < votes[i]) { max = votes[i]; maxKyougi = i; }
                }
                Console.WriteLine(maxKyougi + 1);
                break;
            }
            
        }

        
    }

    

    
}

Measured memory_bytes: 5968
N,C=map(int,input().split())
xv=[(0,0)]
xv_=[]
for i in range(N):
    x,v=map(int,input().split())
    xv.append((x,v))
    xv_.append((x,v))
xv_.append((C,0))
xv_.reverse()
r=[0]*(N+1)
r_=[0]*(N+1)
for i in range(N):
    r[i+1]=r[i]-(xv[i+1][0]-xv[i][0])+xv[i+1][1]
    r_[i+1]=max(r_[i],r[i+1]-xv[i+1][0])
l=[0]*(N+1)
l_=[0]*(N+1)
for i in range(N):
    l[i+1]=l[i]-abs(xv_[i+1][0]-xv_[i][0])+xv_[i+1][1]
    l_[i+1]=max(l_[i],l[i+1]-(C-xv_[i+1][0]))
ans=0
for i in range(1,N+1):
    ans=max(r[i]+l_[N-i],ans)
    ans=max(l[i]+r_[N-i],ans)
print(ans)


Measured memory_bytes: 72024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    ll a;
    map<ll, ll> mp;
    REP(i, n){
        cin >> a;
        mp[a]++;
    }
    ll flg = 1;
    if(n % 2){
        if(mp[0] != 1) flg = 0;
        REP(i, n / 2){
            if(mp[2 * i + 2] != 2) flg = 0;
        }
    }
    else{
        REP(i, n / 2){
            if(mp[2 * i + 1] != 2) flg = 0;
        }
    }
    ll res = 1, mod = 1e9 + 7;
    REP(i, n / 2){
        res *= 2;
        res %= mod;
    }
    if(flg) cout << res << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 5376