akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

int par[100000];
void init(int n){
	rep(i,n){
		par[i]=i;
	}
}

int root(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x] = root(par[x]);
	}
}

void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y)return;
	par[x]=y;
}



struct a{
	ll a;
	int num;
	int par;
	bool use;
};

bool operator< (const a& left,const a& right){
        return left.a < right.a;
}



int main(void){
	int n,m;
	cin>>n>>m;
	a aa[n];
	rep(i,n){
		cin>>aa[i].a;
		aa[i].num=i;
	}
	int x,y;
	init(n);
	rep(i,m){
		cin>>x>>y;
		unite(x,y);
	}

	rep(i,m){
		aa[i].par = root(aa[i].num);
		aa[i].use = true;
	}

	sort(aa,aa+n);
	/*(i,n){
		cout<<root(aa[i].num)<<"a"<<endl;
	}*/
	ll ans=0;
	int d=0;
	int u=1;

	int use[n];
	int counting[n];
	rep(i,n){
		use[i]=1;
		counting[i]=1;
	}
	int counter = 0;
	int nodes=0;
	rep(i,n){
		if(counting[root(i)]==1){
			counting[root(i)]=0;
			nodes++;
		}
	}
	if(nodes==1){
		cout<<0<<endl;
		return 0;
	}
	rep(i,n){
		if(use[root(aa[i].num)]==1){
			ans += aa[i].a;
			use[root(aa[i].num)]=0;
		}else{
			if(counter<nodes-2){
				counter++;
				ans += aa[i].a;
			}
			
		}
	}
	rep(i,n){
		if(counter!=nodes-2){
			cout<<"Impossible"<<endl;
			return 0;
		}
	}
	/*while(u<n){
		if(root(aa[d].num)!=root(aa[u].num)){
			ans += (ll)aa[d].a + (ll)aa[u].a;
			aa[d].use=false;
			aa[u].use=false;
			unite(aa[d].num,aa[u].num);
			d++;
			while(aa[d].use==false){
				d++;
			}
			u=max(u+1,d+1);
		}else{
			u++;
		}
	}

	rep(i,n){
		//cout<<root(aa[i].num)<<endl;
	}

	rep(i,n){
		if(root(aa[0].num)!=root(aa[i].num)){
			cout<<"Impossible"<<endl;
			return 0;
		}
	}*/
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>
#include <bitset>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    constexpr uint f_max{3000};
    constexpr uint suger_max{f_max / 2};

    uint A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    bitset<suger_max + 1> dp_s;
    for (auto &&c: irange(0U, suger_max / C + 1)) {
        for (auto &&d: irange(0U, suger_max / D + 1)) {
            if (c * C + d * D <= suger_max)dp_s.set(c * C + d * D);
        }
    }

//    for (auto &&i: irange(0U, 100U)) {
//        cout << dp_s[i];
//    }
//    cout << endl;

    uint water_max = F / 100 + 1;
    vector<bool> dp_w(water_max, false);
    for (auto &&a: irange(0U, F / A / 100 + 1)) {
        for (auto &&b: irange(0U, F / B / 100 + 1)) {
            if (a * A + b * B < water_max)dp_w.at(a * A + b * B) = true;
        }
    }
    uint suger_index{0};
    vector<uint> suger_max_for_each_water(water_max, 0);
    for (auto &&i: irange(0U, water_max)) {
        if (dp_w.at(i)) {
            uint suger_max_local = i * E;
//            cout << "suger_max_local: ";
//            cout << i * 100 << " " << suger_max_local << endl;
            if (i != 0) {
                suger_max_for_each_water.at(i) = suger_max_for_each_water.at(i - 1);
            }
            while (suger_index <= min(suger_max_local, suger_max)) {
                if (dp_s[suger_index] && i*100 + suger_index <= F) suger_max_for_each_water.at(i) = suger_index;
                suger_index++;
            }
        }
    }

//    for (auto &&i: irange(0U, water_max)) {
//        cout << "suger_max_for_each_water: " << i * 100 << " " << suger_max_for_each_water.at(i) << endl;
//    }


    vector<pair<uint, uint>> suger_max_paired{};
    for (auto &&i: irange(1U, water_max)) {
        if (dp_w.at(i)) {
            suger_max_paired.emplace_back(make_pair(i, suger_max_for_each_water.at(i)));
        }
    }
    sort(suger_max_paired.begin(), suger_max_paired.end(), [](pair<uint, uint> a, pair<uint, uint> b) {
        return a.first * b.second < a.second * b.first;
    });

//    for (auto &&i: irange(0U, (uint)suger_max_paired.size())){
//        cout << "debug" << suger_max_paired.at(i).first << " " << suger_max_paired.at(i).second <<  "debug"<< endl;
//    }


    for (auto &&i: irange(0U, (uint)suger_max_paired.size())) {
        uint suger_and_water = suger_max_paired.at(i).first*100 + suger_max_paired.at(i).second;
        if (suger_and_water <= F){
            cout << suger_and_water << " " << suger_max_paired.at(i).second << endl;
            return 0;
        }
    }
    cout << dp_w.at(27) << endl;
    cout << dp_s[183] << endl;
    cout << A*100 <<  " " << A*100 <<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

N,x = map(int,input().split())

a = list(map(int,input().split()))
a.sort()

s = 0
for i in range(N):
    s += a[i]

    if s == x:
        print (i + 1)
        sys.exit()

    elif s > x:
        print (i)
        sys.exit()

print (N-1)



Measured memory_bytes: 38256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

import heapq


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

X = inputI()

a = 100
count = 0

while a<X:
  a = int(a*1.01)
  count += 1
    
print(count)

Measured memory_bytes: 73008
import java.util.*;
import java.util.function.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    long[] A = new long[N];
    for (int i = 0; i < N; i++) A[i] = sc.nextLong();
    sc.close();

    long mod = 1000000007L;
    long ans = 0;
    Arrays.sort(A);
    long[] cmb = modCmb(N, K, mod);
    for (int i = 0; i < N - K + 1; i++) {
      ans = modAdd(ans, A[N - 1 - i] * cmb[N - K - i], mod);
      ans = modSub(ans, A[i] * cmb[N - K - i], mod);
    }

    System.out.println(ans);
  }

  private static long modAdd(long a, long b, long mod) {
    return ((a % mod) + (b % mod)) % mod;
  }

  private static long modSub(long a, long b, long mod) {
    long ans = ((a % mod) - (b % mod)) % mod;
    return ans < 0 ? ans + mod : ans;
  }

  private static long modDiv(long a, long b, long mod) {
    return (a % mod) * modInv(b, mod) % mod;
  }

  private static long modInv(long x, long mod) {
    return modPow(x, mod - 2, mod);
  }

  private static long modPow(long b, long e, long mod) {
    long ans = 1;
    long x = b % mod;
    for (long y = e; y != 0; y >>= 1) {
      if ((y & 1) == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
    }
    return ans;
  }

  private static long[] modCmb(int n, int k, long mod) {
    long[] cmb = new long[n - k + 1];
    cmb[0] = 1;
    for (int i = 1; i <= n - k; i++)
      cmb[i] = modDiv(cmb[i - 1] * (k + i - 1), i, mod);
    return cmb;
  }
}

Measured memory_bytes: 59380
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int x;

int fun(int cur)
{
    int cnt = cur/5;
    if (cur%5) cnt++;
    return cnt;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> x;
    int tmp1 = x%100;
    int tmp2 = x/100;
    if (tmp2 >= fun(tmp1)) cout << 1;
    else cout << 0;
    //system("pause");
    return 0;
}

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

string s;

int main(){
	cin>>s;
	int n=s.size();
	int sum=0;
	for(int i=0;i<n;i++){
		if(i%2==0&&s[i]=='0') sum++;
		if(i%2==1&&s[i]=='1') sum++;
	}
	int ans=sum;
	sum=0;
	for(int i=0;i<n;i++){
		if(i%2==0&&s[i]=='1') sum++;
		if(i%2==1&&s[i]=='0') sum++;
	}
	ans=min(sum,ans);
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int x=0, max=0;
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; ++i) {
    if(s[i] == 'I') {
      ++x;
    } else {
      --x;
    }
    if(max<x) max=x;
  }
  cout << max << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,x,y;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=0,d=0,e=1,f=0,g=0,h=0;
  cin >>a;
  cout <<a*a<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  105

string s;
ll k;
ll dp[105][105][2];
vector<int> v;

ll add(ll a,ll b,ll mod)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a,ll b,ll mod)
{
	return ((a%mod)+(b%mod)+mod)%mod;
}
ll mul(ll a,ll b,ll mod)
{
	return ((a%mod)*(b%mod))%mod;
}

ll rec(ll i, ll cnt, ll t){
	if(i==s.size()){
		if(cnt==k)
			return 1;
		return 0;
	}
	ll &res=dp[i][cnt][t];
	if(res!=-1)
		return res;
	int l=t?9:v[i];
	ll ans=0;
	for(int j=0; j<=l; j++){
		ll temp=cnt;
		if(j!=0)
			temp++;
		int temp2=t;
		if(j<v[i])
			temp2=1;
		ans+=rec(i+1,temp,temp2);
	}
	dp[i][cnt][t]=ans;
	return res=dp[i][cnt][t];
}

void solve()
{
	cin>>s;
	cin>>k;
	rep(i,0,s.size()){
		v.pb(s[i]-'0');
	}
	memset(dp,-1,sizeof dp);
	cout<<rec(0,0,0);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<bool>>data(H,vector<bool>(W,true));
  for(int i=0;i<N;i++){
    int x, y, a;
    cin >> x >> y >> a;
    if(a==1){
      for(int j=0;j<H;j++){
        for(int k=0;k<x;k++){
          data.at(j).at(k)=false;
        }
      }
    }
    if(a==2){
      for(int j=0;j<H;j++){
        for(int k=x;k<W;k++){
          data.at(j).at(k)=false;
        }
      }
    }
    if(a==3){
      for(int j=0;j<y;j++){
        for(int k=0;k<W;k++){
          data.at(j).at(k)=false;
        }
      }
    }
    if(a==4){
      for(int j=y;j<H;j++){
        for(int k=0;k<W;k++){
          data.at(j).at(k)=false;
        }
      }
    }
  }
  int count=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data.at(i).at(j)) count++;
    }
  }
  cout << count << endl;
}


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

int main(){
    int n;
    cin >> n;
    double sum = 0;
    for (int i = 0; i < n; ++i) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "BTC") sum += 380000.0 * x;
        else sum += x;
    }

    cout << sum;

    return 0;
}


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

int main() {
    int page,paper;

    cin >> page;

    if(page % 2 == 0){
         cout << page / 2 << endl;
    }
    else{
        cout << (page / 2) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 888
judge :: Bool -> (String,String) -> String
judge f (ts,fs) = case f of
  True -> ts
  False -> fs

func :: Int -> Bool
func n = case ret of
  [] -> False
  otherwise -> True
  where
  ret =
    filter (== n) 
    $ concatMap (\y -> map (+ y) 
    $ takeWhile (\z -> y + z <= n) [0,7..]) 
    $ takeWhile (\x -> x <= n) [0,4..]

main = do
  line <- getLine
  let
    n = read line :: Int
    ret = func n
  putStrLn $ judge ret ("Yes", "No")


Measured memory_bytes: 508
#include<stdio.h>
int main (void) {
  
  int N,A[100];
  double B[100];
  
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  
  double a = 0.0;
  for (int i = 0; i < N; i++) {
    B[i] = 1 / (double)A[i];
    a += B[i];
  }
  
  double b = 1 / a;
  
  printf("%f", b);
  
  return 0;
}

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

int main(){
    unsigned int A,B,K;
    unsigned int C;
    cin >> A >> B >> K;
    unsigned int CK[K];
    C=A;
    if(A>B) C=B;
    for(unsigned int i=1;i<=C;i++){
        if(A%i==0&&B%i==0){
            for(unsigned int j=0;j<K-1;j++){
                CK[j] = CK[j+1];
            }
            CK[K-1] = i;
        }
    }
    sort(CK,CK+K,greater<uint>());
    cout << CK[K-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double num1=0,num2=0,ans=0,sum=0;
  double Threshold=0;
  cin>>num1>>num2;
  vector<double> v; 
  for(int i=0;i<num1;i++){
    double tmp;
    cin>>tmp;
    v.push_back(tmp);
    sum+=tmp;
  }
  Threshold=sum/(4*num2);
  for(int i=0;i<num1;i++){
    if(v[i]>=Threshold){
      ans++;
    }
  }
  if(ans>=num2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
	cin>>a>>b;
	if(a>0&&b>0)
	cout<<"Positive"<<endl;
	if(a==0 or b==0)
	cout<<"Zero"<<endl;
	if(a>0&&b<0 or a<0&&b>0)
	cout<<"Zero"<<endl;
	if(a<0&&b<0)
	{
	if((abs(a+b))%2==0)
	cout<<"Negative"<<endl;
	else
	cout<<"Positive"<<endl;
	}
	return 0;
}

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

typedef long long LL;
typedef pair<LL,LL> PII;

LL MOD = 1000000007;
const int MAXN = 310;
LL comb[MAXN][MAXN];

void init() {
	for(int i=0; i<MAXN; i++) {
		comb[i][i] = comb[i][0] = 1;
	}
	for(int i=2; i<MAXN; i++) {
		for(int j=1; j<i; j++) {
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
			comb[i][j] %= MOD;
		}
	}
	
}
//	LL dp[MAXN][MAXN];
//	LL A[MAXN][MAXN];

// LL K[MAXN][MAXN][MAXN];
LL dp[MAXN][MAXN][MAXN];

int main() {
	init();
	int N, M ;
	cin >> N >> M;
	
	dp[1][0][0] = 1;
	for(int j=0; j<=M; j++) {
		for(int i=1; i<=N; i++) {
			for(int k=0; k<=N; k++) {
				LL base = dp[i][j][k];
				dp[i][j+1][k] += base * (LL)k ;
				if(i+k < MAXN)
	 				dp[i+k][j+1][0] += base * (LL)i ;
 				dp[i][j+1][k+1] += base * (LL)(N - i - k);
				
				dp[i][j+1][k] %= MOD;
				if(i+k < MAXN)
					dp[i+k][j+1][0] %= MOD;
				dp[i][j+1][k+1] %= MOD;
			}
		}
		
	}
	cout << dp[N][M][0] << endl;
	
	
	// 変な方針で解こうとしたらO(N^4)になった
	//
	
	/*
	for(int j=0; j<MAXN; j++)
	for(int i=0; i<MAXN; i++) {
		dp[j][i] = 0;
		A[j][i] = 0;
	}
	A[1][0] = 1;
	dp[0][0] = 1;
	for(int i=1; i<=N; i++) {
		for(int j=1; j<=M; j++) {
			
			for(int prev = 0; prev<j; prev++) {
				dp[i][j] += dp[i-1][prev] * comb[j][prev];
				dp[i][j] %= MOD;
			}
			
			
		}
	}
	vector<LL> x;
	x.push_back(1);
	for(LL i=0; i<=M; i++) {
		x.push_back( (LL)x.back() * (LL)N % MOD);
		cout << x.back() << endl;
	}
	
	
	for(int p=1; p<=N; p++) {
		for(int q=1; q<=M; q++) {
			A[p][q] += A[p][q-1] * (LL)p;
			A[p][q] %= MOD;
		}
		
		for(int q=0; q<=M; q++) {
			for(int i=1; i+p<=N; i++) {
				for(int j=1; j+q<=M; j++) {
				//ここのオーダーが落ちない！！！！！ってなってた。
					A[p+i][q+j] += A[p][q] * comb[N-p][i] % MOD * dp[i][j-1] % MOD * (LL) p % MOD;
					A[p+i][q+j] %= MOD;
				}
			}
		}
	}
	for(int i=0; i<=N; i++, cout << endl)
		for(int j=0; j<=M; j++) {
			cout << A[i][j] << " ";
		}
	
	cout << A[N][M] << endl;
	*/
	
	return 0;
}



Measured memory_bytes: 227456
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        else if(x<=y){
        cout<<x<<" "<<y<<endl;
        }
        else if(x>y){
        cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3068
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates


int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), c(n);
    rep(i, n) {
        cin >> p[i]; --p[i];
    }
    rep(i, n) {
        cin >> c[i];
    }

    vector<ll> lv(n, 0), lc(n, 0);
    rep(i, n) {
        ll j = p[i];
        while (true) {
            lv[i] += c[j];
            ++lc[i];
            if (j == i) {
                break;
            }
            j = p[j];
        }
    }

    ll result = -INF;
    rep(i, n) {
        if (lv[i] >= 0 && lc[i] <= k) {
            ll cnt = k / lc[i] - 1;
            if (cnt == 0) {
                ++cnt;
            }
            ll v = lv[i] * cnt;
            ll cc = k - lc[i] * cnt;
            result = max(result, v);
            for (ll j = i, l = 0; l < cc; ++l, j = p[j]) {
                v += c[p[j]];
                result = max(result, v);
            }
        }
        {
            ll v = 0;
            ll cc = min(k, lc[i] + 1);
            for (ll j = i, l = 0; l < cc; ++l, j = p[j]) {
                v += c[p[j]];
                result = max(result, v);
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3288
/*  ****************************

        Author: Devanshu Chaudhari  

        Institution: Indian Institute of Technology Roorkee
    
    ********************************/  
        #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int x,y;
    	cin>>x>>y;
    	cout<<(x==y?"Yes":"No");
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,m,n,xx,cnt;
	char s[21];
	int player[1007];
	while(cin>>m>>n&&m&&n) {

		for(i=1;i<=m;i++) player[i]=1;
		
		cnt=m;
		xx=1;
		for(i=1;i<=n;i++) {
			cin>>s;
			if(cnt==1) continue;
			while(1) {
				if(player[xx]==1)break;
				xx++;xx=xx%(m+1);
	
			}
			if(i%15==0){
				if(strcmp(s,"FizzBuzz")!=0) player[xx]=0,cnt--;
			}
			else if(i%3==0) {
				if(strcmp(s,"Fizz")!=0) player[xx]=0,cnt--;
			}
			else if(i%5==0) {
				if(strcmp(s,"Buzz")!=0) player[xx]=0,cnt--;
			}
			else if(i!=atoi(s)) player[xx]=0,cnt--;
			xx++;xx=xx%(m+1);
		}
		xx=1;
		while(player[xx]==0) xx++,xx%(m+1);
		cout<<xx;
		for(i=xx+1;i<=m;i++) {
			if(player[i]==1) {
				cout<<" "<<i;
			}
		}
		cout<<endl;
	}
}
	

Measured memory_bytes: 3084
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var hArray = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var sol = new Solve(hArray, N);
            Console.WriteLine(sol.Execute());
        }
    }

    class Solve
    {
        public int[] hArray { get; set; }
        public int[] dp { get; set; }
        public int N { get; set; }

        public Solve(int[] hArray, int N)
        {
            this.hArray = hArray;
            this.N = N;
            dp = new int[N + 10];
        }

        public int Execute()
        {
            dp[2] = Math.Abs(hArray[1] - hArray[0]);

            for (var i = 3; i <= N; i++)
            {
                dp[i] = Math.Min(dp[i - 1] + Math.Abs(hArray[i - 1] - hArray[i - 2]),
                                 dp[i - 2] + Math.Abs(hArray[i - 1] - hArray[i - 3]));
            }
            return dp[N];
        }
    }
}

Measured memory_bytes: 19808
//テンプレ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//
signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   int N,K;
   cin >> N >> K;
   cout << ((((N % 2 == 0) ? N/2  : N/2 +1 ) >= K) ? "YES" : "NO")<< endl;
}


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

typedef long long ll;
const int mod = 1000000007;

int main() {
  int N;
  cin >> N;
  
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll sum = 0;
  // 各桁について調べる。「0の個数」×「1の個数」に桁分を乗じた数を足していく
  for (ll d = 0; d < 60; d++) {
    ll count0 = 0;
    ll count1 = 0;
    for (ll i = 0; i < N; i++) {
      if((A[i] >> d) & 1LL) {
        count1++;
      } else {
        count0++;
      }
    }
    sum = (sum + (count0 * count1 % mod) * ((1LL << d) % mod) % mod) % mod;
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2560
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

n=int(input())
arr=[int(i) for i in input().split()]
sum=0
for i in range(n):
    sum+=arr[i]
sum//=2
ans=0
for x in range(0,1):
    ex=0
    i=x
    while(True):
        ex+=arr[i]
        i+=2
        i%=n
        if (i+1)%n==x:
            ex+=arr[i]
            break

    ans=((ex-sum))
io=0
while(io!=n):
    print(ans*2,end=" ")
    ans=arr[(io)%n]-ans
    io+=1


Measured memory_bytes: 14024
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
A=list(map(int,input().split()))
lst=[]
for i in range(0,N,2):
    lst.append(A[i]^A[i+1])

z=0
for l in lst:
    z^=l

rlst=[]

for i in range(N):
    rlst.append(z^lst[i//2]^A[i+(1 if (i&1==0) else -1)])
    #print(i//2,i+(1 if (i&1==0) else -1))
print(" ".join([str(i) for i in rlst]))


Measured memory_bytes: 135172
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, A;
    cin >> N;
    ll num4 = 0, num2 = 0, num = 0;
    rep(0, i, N)
    {
        cin >> A;
        if (A % 4 == 0)
        {
            num4++;
        }
        else if (A % 2 == 0)
        {
            num2++;
        }
        else
        {
            num++;
        }
    }
    if (num2 < 2)
    {
        if (num4 + 1 >= num + num2)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        if (num4 >= num)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
N = int(input())

dict = {}

for i in range(N):
    s = input()
#     print(s)
    temp = [s[j] for j in range(len(s))]
    temp.sort()
    s2 = temp[0]
    for j in range(len(s)):
        if j == 0: continue
        s2 += temp[j]
    if s2 in dict:
        dict[s2] += 1
    else:
        dict[s2] = 1

ret = 0
for key in dict.keys():
    n = dict[key]
    ret += (n - 1) * n / 2
print(int(ret))


Measured memory_bytes: 17892
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int ans=0;
  for(int i=0;i<5;i++){
    int x; cin >> x;
    if(x==0) ans = i+1;
  }
  cout << ans << endl;
}

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

int main() {
    int K;

    string S;

    cin >> K;

    cin >> S;

    if (int(S.length()) <= K) {
        cout << S << endl;
    } else {
        for (int i = 0; i < K; i++) {
            cout << S[i];
        }

        cout << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3620
A, B, C, D, E, F = map(int, input().split())

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = -1
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return max(max_con, mem[(water_sum, suger_sum)])
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        con = dps(mem, water_sum + w, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum + w, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Measured memory_bytes: 4484
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define ll long long



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

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    ans+=100*a;
    ans+=10*b;
    ans+=c;
    if(ans%4)NO;
    else YES;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
 	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
N = int(input())
hoge = []
for i in range(1,N+1):
    s, p = input().split()
    p = int(p)
    hoge.append((s,100-p,i))
a = sorted(hoge, key=lambda x:(x[0],x[1]))
for b in a:
    print(b[2])

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    int a, b, c;
    a = x * y;
    b = x - y;
    c = x + y;
    if (a == 0 && b == 0 && c == 0)
        cout << 0;
    else if (a > b&& a >= c)
        cout << a;
    else if (b > a&& b >= c)
        cout << b;
    else if (c > a&& c >= b)
        cout << c;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976
#define MAX_N 100010
class UnionFind{
public:
	int par[MAX_N],rank[MAX_N],sum[MAX_N];
	lint ans;

	void init(int n){
		rep(i,n){ par[i]=i;rank[i]=0;sum[i]=1; }
	}

	UnionFind(int n){
		init(n);
	}

	UnionFind(){

	}

	int root(int x){
		if(par[x]==x)return x;
		else return par[x]=root(par[x]);
	}

	bool same(int x,int y){
		return this->root(x)==this->root(y);
	}

	void unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y)return;
		ans-=sum[x]*sum[y];
		if(rank[x]<rank[y])par[x]=y,sum[y]+=sum[x];
		else{
			par[x]=y;
			sum[y]+=sum[x];
			if(rank[x]==rank[y])++rank[x];
		}
	}
};

int main(){
	lint n,m;cin>>n>>m;
	vector<pair<lint,lint> > e(m);
	vector<lint>a;
	rep(i,m)cin>>e[i].first>>e[i].second,--e[i].first,--e[i].second;
	UnionFind t(n);
	t.ans=n*(n-1)/2;
	for(int i=m-1;i>=0;--i){
		a.push_back(t.ans);
		t.unite(e[i].first,e[i].second);
	}
	for(int i=m-1;i>=0;--i)cout<<a[i]<<endl;
}

Measured memory_bytes: 4980
#include "bits/stdc++.h"
using namespace std;
int main(){
    int K,S,count = 0,sum;
    cin >> K >> S;
    int i,j,k;
    for(i=0;i<=K;i++){
        if(i>S) break;
        for(j=0;j<=K;j++){
            if(i+j>S) break;
            if(S-i-j>=0 && S-i-j<=K) count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
package main

/*
#cgo CFLAGS: -Wno-unused-result
#include <stdio.h>
long long nextInt(){
	long long int a;
	scanf("%lld", &a);
	return a;
}
*/
import "C"
import "fmt"

func cNextInt() int {
	return int(C.nextInt())
}

func mini(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var ans, i int
	var a [100000]int

	N := cNextInt()
	x := cNextInt()
	for i = 0; i < N; i++ {
		a[i] = cNextInt()
	}

	for i = 1; i < N; i++ {
		diff := a[i-1] + a[i] - x
		if diff > 0 {
			ans += diff
			min := mini(diff, a[i])
			a[i] -= min
			diff -= min
			if diff > 0 {
				a[i-1] -= diff
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1408
h,w = map(int,input().split())
g = [['.'] * (w+2) for i in range(h+2)]
for i in range(h):
  g[i+1][1:-1] = input()
for i in range(h):
  for j in range(w):
    if g[i+1][j+1] == '#':
      f = 1
      for a,b in [[1,0],[0,1],[-1,0],[0,-1]]:
        if g[i+a+1][j+b+1] == '#':
          f = 0
          break
      if f:
        print('No')
        exit()
print('Yes')

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

#define rep(i,s,e) for(int i = (s);i <= (e);i++)

typedef long long i64;

i64 q,h,s,d;
i64 n;

int main()
{
    cin >> q >> h >> s >> d;
    cin >> n;
    i64 result = 0;
    n *= 4;
    {
        priority_queue<i64,vector<i64>,greater<i64>> que;
        que.push(q * 8);
        que.push(h * 4);
        que.push(s * 2);
        que.push(d);
        i64 mi = que.top();
        int cou = n / 8;
        result += cou * mi;
        n = n % 8;

    }
    {
        priority_queue<i64,vector<i64>,greater<i64>> que;
        que.push(q * 4);
        que.push(h * 2);
        que.push(s * 1);
        i64 mi = que.top();
        int cou = n / 4;
        result += cou * mi;
        n = n % 4;
    }
    {
        priority_queue<i64,vector<i64>,greater<i64>> que;
        que.push(q * 2);
        que.push(h * 1);
        i64 mi = que.top();
        int cou = n / 2;
        result += cou * mi;
        n = n % 2;
    }
    {
        priority_queue<i64,vector<i64>,greater<i64>> que;
        que.push(q);
        i64 mi = que.top();
        int cou = n / 1;
        result += cou * mi;
        n = n % 1;
    }

    cout << result << endl;


}

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

int main(void){
  int a,b,c,cnt;
  cnt = 0;
  cin >> a >> b >> c;
  for(int i=a; i<=b; i++){
    if(c%i==0) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}



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

int main() { 
  int n,x,y=0,sum;

  cin>>n>>x;
  if(n-2*x>0)y=n-2*x;

  
  cout<<y;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  string s;
  string tmp;
  cin >> s;
  int n = s.size();
  tmp = s;
  reverse(ALL(tmp));
  if(s == tmp) {
    string sub = s.substr(0, ((s.size()-1)/2));
    tmp = sub;
    reverse(ALL(tmp));
    if(sub == tmp) {
      string sub2 = s.substr(((s.size()+3)/2)-1, ((s.size()-1)/2));
      tmp = sub2;
      reverse(ALL(tmp));
      if(sub2 == tmp) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main() {
    int N, a, ans = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a);
        int c = 0;
        while (a % 2 == 0) {
            c++;
            a /= 2;
        }
        ans += c;
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int x;

    if((a + b) % 2 == 0) x = (a + b) / 2;
    else x = (a + b + 1) / 2;

    cout << x << endl;
}

Measured memory_bytes: 256
import math
def main():
  n=int(input())
  t,a = list(map(int,input().split()))
  h = list(map(int,input().split()))
  ans = abs(a-(t-h[0]*0.006))
  ansid=0
  for i in range(1,n):
    if abs(a-(t-h[i]*0.006)) < ans :
      ans=abs(a-(t-h[i]*0.006))
      ansid=i
  print(ansid+1)
main()

Measured memory_bytes: 9208
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

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

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

int main() {

   long long int N, M;
   cin >> N >> M;
   string S, T;
   cin >> S >> T;
  
   if (N < M) {
      long long int tmp = N;
      N = M;
      M = tmp;
      string stmp = S;
      S = T;
      T = stmp;
   }
   long long int length = lcm(N, M);
   long long int length2 = lcm(length/N, length/M);
   long long int length3 = length/length2;
   
   for (long long int i = 0; i < length3; i++) {
      if (S[N / length3 * i] != T[M / length3 * i]) {
         cout << "-1" << endl;
         return 0;
      }
   }
   cout << length << endl;
   return 0;
}


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

int A[85][85], B[85][85];
bool f[85][85][18000];

int main() {
	int H, W;
	cin >> H >> W;
	for(int i=0; i<H; ++i){
		for(int j=0; j<W; ++j){
			cin >> A[i][j];
		}
	}
	for(int i=0; i<H; ++i){
		for(int j=0; j<W; ++j){
			cin >> B[i][j];
		}
	}
	f[1][0][0]=1;
	for(int i=0; i<H; ++i){
		for(int j=0; j<W; ++j){
			int s=abs(A[i][j]-B[i][j]);
			for(int k=0; k+s<18000; ++k){
				if(f[i][j+1][k] || f[i+1][j][k]){
					f[i+1][j+1][k+s]=f[i+1][j+1][abs(k-s)]=1;
				}
			}
		}
	}
	int ans=0;
	while(!f[H][W][ans]) ++ans;
	cout << ans << endl;
	return 0;
}

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

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
    int count(){
        int c = 0;
        rep(i, data.size()){
            if (data[i] < 0) c++;
        }
        return c;
    }
};

int main()
{
    int h, w;
    while (h = in(), w = in(), w || h){
        vector<string> field;
        rep(i, h){
            string s;
            cin >> s;
            field.push_back(s);
        }
        UnionFind uf(h * w);
        rep(i, h){
            rep(j, w){
                if (i + 1 < h && field[i][j] == field[i + 1][j]){
                    uf.unionSet(i * w + j, i * w + j + w);
                }
                if (j + 1 < w && field[i][j] == field[i][j + 1]){
                    uf.unionSet(i * w + j, i * w + j + 1);
                }
                if (i - 1 >= 0 && field[i][j] == field[i - 1][j]){
                    uf.unionSet(i * w + j, i * w + j - w);
                }
                if (j - 1 >= 0 && field[i][j] == field[i][j - 1]){
                    uf.unionSet(i * w + j, i * w + j - 1);
                }
            }
        }
        printf("%d\n", uf.count());
    }
    return (0);
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

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

  ll sum = 0, triSum = 0;
  rep(i,N) {
    sum += A[i];
    sum %= MOD;
    triSum += sum * A[i];
    triSum %= MOD;
  }
  sum *= sum;
  sum %= MOD;
  ll ans = sum + MOD - triSum;
  ans %= MOD;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4828
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local MOD = math.floor(10^9)+7

local tmp = read.l():totable()
local S = {}
for i=1,#tmp do
    if tmp[i] == '?' then
        S[i] = '?'
    else
        S[i] = tonumber(tmp[i])
    end
end

local map_newm = {}
local map_oldm = {}
for nd=0,9 do
    for oldm=0,12 do
        local x = oldm * 10 + nd
        local y = (oldm * 10 + nd) % 13
        --print(nd, oldm, x, y)
        map_newm[x] = y
        map_oldm[x] = oldm
    end
end
local N = #S
local tbl = array(2, 0)
tbl[0][0] = 1
for i=1,N do
    local tio = tbl[i-1]
    local ti = tbl[i]
    if S[i] == '?' then
        for x=0,129 do
            local newm = map_newm[x]
            local oldm = map_oldm[x]
            ti[newm] = (ti[newm] + tio[oldm]) % MOD
        end
    else
        for oldm=0,12 do
            local newm = (oldm * 10 + S[i]) % 13
            ti[newm] = tio[oldm]
        end
    end
end
print(tbl[N][5])

Measured memory_bytes: 45332
#include<stdio.h>
 
#define MAX 500000
 
int count = 0;
 
void Merge(int a[],int left,int mid,int right);
void MergeSort(int a[],int left,int right);
 
int main(){
  int a[MAX],n,i;
 
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
 
  MergeSort(a,0,n);
 
  for(i = 0; i < n; i++){
 
    if(i == n-1){
      printf("%d\n",a[i]);
      printf("%d\n",count);
      break;
    }
    printf("%d ",a[i]);
  }
 
  return 0;
}
 
 
 
void Merge(int a[],int left,int mid,int right){
 
  int n1 = mid-left, n2 = right-mid, l[n1],r[n2],i,j,k;
 
 
  for(i = 0; i < n1; i++){
    l[i] = a[left+i];
  }
 
  for(i = 0; i < n2; i++){
    r[i] = a[mid+i];
  }
 
  l[n1] = 1000000000;
  r[n2] = 1000000000;
 
  i = 0;
  j = 0;
 
  for(k = left; k < right ;k++){
    if(l[i] <= r[j]){
      a[k] = l[i];
      i++;
      count++;
    }
 
    else{
      a[k] = r[j];
      j++;
      count++;
    }
 
  }
}
 
 
 
void MergeSort(int a[],int left,int right){
 
  int mid;
 
   
  if(left+1 < right){
    mid = (left+right)/2;
    MergeSort(a,left,mid);
    MergeSort(a,mid,right);
    Merge(a,left,mid,right);
  }
 
}


Measured memory_bytes: 5620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

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

    cin >> X;

    ans += (X / 500) * 1000;
    X = X % 500;
    ans += (X / 5) * 5;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int h[100100];
int dp[100100];
int cost(int i,int j){
	return abs(h[i]-h[j]);
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	dp[1]=0;
	dp[2]=cost(1,2);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+cost(i,i-1),dp[i-2]+cost(i,i-2));
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <bitset>
#include <utility>
#include <queue>

using namespace std;

bool cmp( const pair<int,int>& lhs, const pair<int,int>& rhs ){
    return  ( lhs.second != rhs.second ) ? ( lhs.second < rhs.second ) : ( lhs.first < rhs.first ); 
}

int main(){

    int N, M;
    cin >> N >> M;

    vector<pair<int,int>> q;
    int a,b;
    
    for(int i=0;i<M;++i){
        cin >> a >> b;
        q.emplace_back( make_pair(a,b));
    }

    sort( q.begin(), q.end(), cmp );

    int ans(0);
    int ca(0);
    for(auto e:q){
        if( e.first <= ca ) continue;
        ca = e.second - 1;
        ++ans;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int h = sc.nextInt();
                int w = sc.nextInt();
                String[] s = new String[h];
                for(int i = 0 ; i < h ; i++){
                        s[i] = sc.next();
                        System.out.println(s[i]);
                        System.out.println(s[i]);
                }
        }
}
//ここに一言添えます

Measured memory_bytes: 37152
h,w = map(int,input().split())
if w == 1:
    print(int(1))
elif h == 1:
    print(int(1))
else:
    if h %2 == 0:
        print(int(h*w /2))
    else:
        tmp = (h+1)/2#多いほうの行けるマス数
        tmp1 = (h-1)/2#少ないほうの行けるマス数
        if w %2 == 0:
            print(int(h*w/2))
        else:
            print(int(h*(w-1)/2 +tmp))

Measured memory_bytes: 3064