akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int mo=1000000007;
const int N=200005;
char s[N];
int a[N],tp[N],n;
int main(){
	scanf("%d%s",&n,s+1);
	For(i,1,2*n) a[i]=(s[i]=='B');
	Rep(i,2*n+1,1) a[i]^=a[i-1];
	For(i,1,2*n){
		if (a[i]) tp[i]=0,a[i]^=1;
		else tp[i]=1,a[i+1]^=1;
		//printf("%d ",tp[i]);
	}
	int S=0,ans=1;
	For(i,1,2*n)
		if (tp[i]==0) ++S;
		else ans=1ll*ans*(S--)%mo;
	if (S) ans=0;
	For(i,1,n) ans=1ll*ans*i%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 2048
import java.util.*;
public class Main {
    static int parent[];
  	static int group;
    public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int edge[][] = new int[m][2];
      for(int i=0;i<m;i++){
              edge[i][0] = sc.nextInt();
              edge[i][1] = sc.nextInt();
      }
      group = n-1;
      parent = new int[n+1];
      for(int i=1;i<=n;i++){
          parent[i]=i;
      } 
     
      for(int i=0;i<m;i++){
          int ai = (int)Math.min(edge[i][0],edge[i][1]);
          int bi = (int)Math.max(edge[i][0],edge[i][1]);
          union(ai,bi);
      }
    parent[0] =parent[1];
      System.out.println(group);
    }
public static int find(int v){
        if(v==parent[v])
            return v;
        return parent[v]=find(parent[v]);
    }
    public static void union(int a,int b){
        a = find(a);
        b = find(b);
        if (a != b){
            parent[b] = a;
         	group--; 
        }
    }
}

Measured memory_bytes: 62384
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

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

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  string s;
  cin >> s;
  if (s == "SUN") {
    cout << 7 << endl;
    return 0;
  } else if (s == "MON") {
    cout << 6 << endl;
    return 0;
  } else if (s == "TUE") {
    cout << 5 << endl;
    return 0;
  } else if (s == "WED") {
    cout << 4 << endl;
    return 0;
  } else if (s == "THU") {
    cout << 3 << endl;
    return 0;
  } else if (s == "FRI") {
    cout << 2 << endl;
    return 0;
  } else if (s == "SAT") {
    cout << 1 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String a = sc.next();
  char c = a.charAt(0);
  if(c == 'a'||c=='i'||c=='u'||c=='e'||c=='o')System.out.println("vowel");
  else System.out.println("consonant");
}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n;cin>> n;
  vector<ll> a(n+2);
  a[0] = 0;
  ll sum_all = 0;
  for(ll i=0;i<n;++i) cin >> a[i+1];
  a[n+1] = 0;
  for(ll i=0;i<n+1;++i) {
    sum_all += abs(a[i+1] - a[i]);
  }
  vector<ll> val(n);
  for(ll i=1;i<n+1;++i) {
    val[i-1] = abs(a[i+1] - a[i-1]) - abs(a[i] - a[i-1])- abs(a[i+1] - a[i]);
  }
  for(ll i=0;i<n;++i) {
    cout << sum_all + val[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep3(l,n,h) for(int l = n; l <= h; ++l)

int main() {
    int a,b,k;
    cin >> a >> b >>k;
    int j = 0;
    rep3(i,a,b) {
        if (j < k) {
            cout << i << endl;
        } else if(b - k < i) {
            cout << i << endl;
        }
    j++;
    }
     return 0;
    }


Measured memory_bytes: 256
def main():
    S = str(input())
    A0 = ('SSS')
    A1 = ('RSS','SRS','SSR','RSR')
    A2 = ('RRS','SRR')
    A3 = ('RRR')
    if S in A0:
        print(0)
    elif S in A1:
        print(1)
    elif S in A2:
        print(2)
    elif S in A3:
        print(3)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9052
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
using namespace std;
int main(){
    string s;
    cin >> s;
    int N;
    cin >> N;
    string t="";
    set<string> ans;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<i+5;j++){
            if(j>s.size()-1) break;
            t = t + s[j];
            ans.insert(t);
        }
        t = "";
    }
    auto itr = ans.begin();
    for(int i=0;i<N-1;i++){
        ++itr;
    }
    cout << *itr << endl;
}

Measured memory_bytes: 1664
n = int(input())
place = [tuple(map(int, input().split())) for _ in range(n)]
m = 0
def bitlist(x):
    ret = [0] * 31
    for i in reversed(range(31)):
        if x > 0:
            x -= 1 << i
            ret[i] = 1
        else:
            x += 1 << i
            ret[i] = -1
    return ret
pre = (place[0][0] + place[0][1] + 1) % 2
for x, y in place:
    if (x + y + 1) % 2 != pre:
        print(-1)
        exit()
print(31 + pre)
if pre:
    print(1, end = ' ')
for i in reversed(range(31)):
    print(1 << i, end = ' ')
print()
for x, y in place:
    u = x + y
    v = x - y
    if pre:
        u -= 1
        v -= 1
    ubit = bitlist(u)
    vbit = bitlist(v)
    if pre:
        print('R', end = '')
    for i in reversed(range(31)):
        if ubit[i] == 1 and vbit[i] == 1:
            print('R', end = '')
        elif ubit[i] == 1 and vbit[i] == -1:
            print('U', end = '')
        elif ubit[i] == -1 and vbit[i] == -1:
            print('L', end = '')
        else:
            print('D', end = '')
    print()


Measured memory_bytes: 4596
n = int(input())
a = list(map(int, input().split()))
l = [(x,i) for i,x in enumerate(a)]
l.sort(reverse=True)
l += [(0,n)]
g = [0]*n
m = n
for i in range(n):
  s = l[i][1]
  if m > s: m = s
  g[m] += (l[i][0]-l[i+1][0])*(i+1)
for x in g: print(x)

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

if N % 10 == 3:
 print('bon')
elif N % 10 == 0:
 print('pon')
elif N % 10 == 1:
 print('pon')
elif N % 10 == 6:
 print('pon')
elif N % 10 == 8:
 print('pon')
else:
 print('hon')


Measured memory_bytes: 9168
#include "bits/stdc++.h"
using namespace std;
int A,B,K;
int main()
{
	cin>>A>>B>>K;
	for(int i=100;i>=1;i--)
	{
		if(A%i==0&&B%i==0)
		{
			K--;
			if(K==0)
			{
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}
/*
100 100 1
Output:100

75 35 2
Output:1
*/

Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n int64
  var a []int64 = make([]int64,5)
  var m,t,k int64
  fmt.Scan(&n,&a[0],&a[1],&a[2],&a[3],&a[4])
  m = ceil(n,a[0])
  for i:=1;i<5;i++ {
    if a[i] >= a[i-1] {
      m++
      a[i] = a[i-1]
      continue
    }
    t = ceil(n,a[i-1])
    k = n-(t-1)*a[i]
    m += ceil(k,a[i])
  }
  fmt.Println(m)
}
func ceil(n int64,m int64) int64 {
  if n%m == 0 { return n/m }
  return n/m + 1
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val line = readLine()
    val a = line?.split(" ")!!.get(0)
    val b = line?.split(" ")!!.get(1)
    var ret = false
    if (a.toInt() <= 8 && b.toInt() <= 8) {
        ret = true
    }
    println( if (ret) "Yay!" else ":(")
}


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

int N,K,D[10];

bool search(int x){
    while(x!=0){
        int now=x%10;
        for(int i=0;i<K;i++){
            if(now==D[i])return false;
        }
        x/=10;
    }
    return true;
}

int main(){
    cin>>N>>K;
    for(int i=0;i<K;i++){
        cin>>D[i];
    }
    int i=N;
    while(1){
        if(search(i)){
            cout<<i<<endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 256
s=input()
count=0
if s[0]=='A':
    for i in range(2,len(s)-1):
        if s[i]=='C':
            count+=1
            index=i

    
    if count==1:
        x=s[1:index]+s[index+1:]
        if x.islower():
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
            
else:
    print('WA')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;
const ll inf = static_cast<ll>(1e10) + 7;

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

    vector<ll> A(AN), B(BN), C(CN);
    for (auto& x : A) { cin >> x; }
    for (auto& x : B) { cin >> x; }
    for (auto& x : C) { cin >> x; }

    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    ll ai = X - 1, bi = Y - 1, ci = 0;
    ll ans = 0;

    while (ai >= 0 || bi >= 0)
    {
        const ll a = ai >= 0 ? A[ai] : inf;
        const ll b = bi >= 0 ? B[bi] : inf;
        const ll c = ci < CN ? C[ci] : -1;

        if (a < b)
        {
            if (a < c)
            {
                ans += c;
                ++ci;
            }
            else
            {
                ans += a;
            }

            --ai;
        }
        else
        {
            if (b < c)
            {
                ans += c;
                ++ci;
            }
            else
            {
                ans += b;
            }

            --bi;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
/* わたしのプログラムみても何も良い事ないですよ？　*/
/* すっごくさむい。トランプしたいな。おこめたべたい　*/

#include<stdio.h>
#include<string.h>

#define M 999997/* ちがうきがする　*/
#define L 14

char H[M][L]; /* hashed potato */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value *//* 整数形に変えてくれるのね */
/*どういう計算しているのかわけわからないっす*//*だからできないのか*/
long long getKey(char str[]){  /* long2つかかれても*/
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
    return key%M;//ジョナサン
}
int h2(int key){
    return key%(M-1)+1;
}



int find(char str[]){
    int i=0,j;
    long long sum;
    sum=getKey(str);
        while(1){
        
            j=(h1(sum)+i*h2(sum))%M;
        
            if(H[j][0] =='\0' || i == M )return 0;
        
            if( strcmp(H[j],str)==0 )return 1;
            
            else i=i+1;
        
        
    }
}

void insert(char str[]){
    int i=0,j;
    long long sum;
    
    sum=getKey(str);
    while(i != M){
        j=(h1(sum)+i*h2(sum))%M; //例のあれ
        if (H[j][0] == '\0'){
            strcpy(H[j],str);
            break;
            }
        else {
            i=i+1;
        }
        
    }
    

}

int main(int argc ,char *argv[]){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){/* 1が戻ってくれば良いんだね！ */
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner in = new Scanner(System.in);
        int variety = in.nextInt();
        int[] num = new int[variety];
        int[] addpoint = new int[variety];
        
        int sumpoint = 0;
        for (int i = 0;i < variety;i++){
            num[i] = in.nextInt() - 1; 
        }
        for (int i = 0;i < variety;i++){
            sumpoint += in.nextInt(); 
        }        
        for (int i = 0;i < variety - 1;i++){
            addpoint[i] = in.nextInt(); 
        }
        
        int memdish = -1;
        for (int i = 0;i < variety;i++){
            if (memdish  == num[i]){
                sumpoint += addpoint[num[i] - 1];
            }
            memdish = num[i] + 1;
        } 
        System.out.println(sumpoint);

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll,int> mp;
  REP(i, N){
    cin >> A[i];
    mp[A[i]]++;
  }
  
  sort(ALL(A));
  int cnt = 0;
  vector<bool> vec(A[N-1]+10,true);
  REP(i,N){
    if(vec.at(A[i])==true){
      if(mp[A[i]]==1){
        cnt++;
      }
      for(int j = 2*A[i];j<=A[N-1];j+=A[i]){
        vec.at(j)=false;
      }
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 17340
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = float("inf")
dp = [INF]*n
dp[0] = 0
for i, hh in enumerate(h):
    for j in range(1, k+1):
        try:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
        except:
            pass
print(dp[-1])


Measured memory_bytes: 55648
import sys
input = sys.stdin.readline


n = int(input())
ans = [0]*(n-1)
edges = [[]for _ in range(n)]
used = [0]*n

for i in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append([b-1, i])

for node in range(n):
    unable = used[node]
    color = 1

    for to, id in edges[node]:
        if color == unable:
            color += 1
        ans[id] = color
        used[to] = color
        color += 1

print(max(used))
for color in ans:
    print(color)


Measured memory_bytes: 30872
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b;
    std::cin >> a>>b;
    int d=b-a,dd=0;
    rep(i,d){
        dd+=i;
    }
    std::cout << dd-a << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int X = N;

		int fx = 0;


		while(N>=10) {

			fx += N%10;

			N /= 10;

		}

		fx += N;

		if(X%fx == 0) System.out.println("Yes");

		else System.out.println("No");
	}

}


Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            int x;
 
            for(int i = 1; i <= N; i++)
            {
                if(i%3 == 0){
                    System.out.printf(" %d",i);
                }else{
                    x = i;
                    do{
                        if(x%10 == 3){
                            System.out.printf(" %d",i);
                            break;
                        }
                        x /=10;
                    }while(x != 0);
                }
            }
            System.out.printf("\n");
 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n[3],mx[3];
    int kk;
    for(int i = 0; i < 3; i++)
    {
        cin>>n[i];
    }
    cin>>kk;
    vector<ll> v[3];
    for(int i = 0; i < 3; i++)
    {
        v[i].resize(n[i]);
        for(int j = 0; j < n[i]; j++)
        {
            cin>>v[i][j];
        }
        sort(all(v[i]));
        reverse(all(v[i]));

    }

    vector<ll> ans;
    for(int i = 0; i < n[0]; i++)
    {
        for(int j = 0; j < n[1]; j++)
        {
            for(int k = 0; k < n[2]; k++)
            {
                if(i*j*k<kk)
                {
                    ans.push_back(v[0][i]+v[1][j]+v[2][k]);
                }
                else break;
            }
            
        }
        
    }
    sort(all(ans));
    reverse(all(ans));
    for(int i = 0; i < kk; i++)
    {
        cout<<ans[i]<<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 35048
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt() - 1
	}

	i := 0
	answer := 0
	can := false
	for {
		i = slice[i]
		answer++
		if i == 1 {
			can = true
			break
		}

		if answer == n-1 {
			break
		}

	}

	if can {
		fmt.Println(answer)
	} else {
		fmt.Println(-1)
	}

}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int get_rand(int a, int b) {  // [a, b]
    return uniform_int_distribution<int>(a, b)(rng);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d = 365, n = 26;
    vector<int> c(n);
    vector<vector<int>> s(d, vector<int>(n));
    if (true) {
        cin >> d;
        for (int i = 0; i < n; i++) {
            cin >> c[i];
        }
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                cin >> s[i][j];
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            c[i] = get_rand(0, 100);
        }
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                s[i][j] = get_rand(0, 20000);
            }
        }
    }
    int wid = 20;
    vector<vector<int>> que(wid);
    auto get = [&](int id) {
        int res = 0;
        vector<int> last(n, -1);
        for (int i = 0; i < que[id].size(); i++) {
            res += s[i][que[id][i]];
            int x = i - last[que[id][i]] - 1;
            res -= c[que[id][i]] * x * (x + 1) / 2;
            last[que[id][i]] = i;
        }
        for (int i = 0; i < n; i++) {
            int x = que.size() - last[i] - 1;
            res -= c[i] * x * (x + 1) / 2;
        }
        return res;
    };
    for (int i = 0; i < d; i++) {
        vector<pair<int, vector<int>>> nxt(wid + 1);
        for (int j = 0; j < wid; j++) {
            nxt[j].first = -1e9;
            que[j].emplace_back(-1);
        }
        for (int j = 0; j < wid; j++) {
            if (i == 0 && j != 0) {
                break;
            }
            for (int l = 0; l < n; l++) {
                que[j].back() = l;
                nxt[wid] = make_pair(get(j), que[j]);
                for (int k = wid - 1; k >= 0; k--) {
                    if (nxt[k].first < nxt[k + 1].first) {
                        swap(nxt[k], nxt[k + 1]);
                    } else {
                        break;
                    }
                }
            }
        }
        for (int i = 0; i < wid; i++) {
            que[i] = nxt[i].second;
        }
    }
    for (int i = 0; i < d; i++) {
        cout << que[0][i] + 1 << '\n';
    }
    cerr << get(0) << '\n';
    return 0;
}


Measured memory_bytes: 4152
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    string str;
    cin >> str;

    int len = str.length();

    for(int i = 0; i < len; i ++)
    	cout << "x";
}

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

int main()
{
	int n, x, data[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		data[i] = x;
	}
	for (int i = n-1; i >= 0; i--) {
		cout << data[i];
		if (i > 0)
			cout << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cmath>


using namespace std;

int N, T, A;

double temp(int x){
    return T - x * 0.006;
}

int main(){
    cin >> N >> T >> A;
    int H[N];
    int proper_index = 0;
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    int index = 1;

    for(; index <= N - 1; index++){
        if(abs(double(A) - temp(H[proper_index])) > abs(double(A) - temp(H[index])) ){
            proper_index = index;
        }
    }
    cout << proper_index + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll=long long;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i,N) cin >> h[i];
    int ans = 0;
    REP(i,N){
        while(h[i] > 0){
            ans++;
            h[i]--;
            FOR(j, i+1, N){
                if(h[j] <= 0) break;
                h[j]--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int num[200010];
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
		if(i>=k)
		{
			if(num[i]>num[i-k])	
				cout<<"Yes"<<endl;
			else
				cout<<"No"<<endl;
		}		
	}
	return 0;
}

Measured memory_bytes: 4344
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()
struct FastIO
{
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0); 
  }
}fastio;

signed main() {
	int n,k;
	std::cin >> n >> k;
	if(k>(n-1)*(n-2)/2) {
		print(-1);
		return 0;
	}
	int diff = (n-1)*(n-2)/2-k;
	int m = n-1+diff;
	print(m);
	rep(i,n-1) std::cout << 1 << ' ' << i+2 << ENDL;
	int count = 0;
	if(diff == 0) return 0;
	for(int i = 2;i<n;i++) {
		for(int j=i+1;j<=n;j++) {
			std::cout << i << ' ' << j << ENDL;
			count++;
			if(count>=diff) return 0;
		}
	}
  return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(1,n+1):
    if i not in d:
        d[i] = 0

for i in range(len(a)):
    d[a[i]] += 1

for i in range(1,n+1):
    print(d[i])

Measured memory_bytes: 38708
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

void test(priority_queue<pair<ll,ll>> que){
  while(!que.empty()){
    cout<<que.top().first<<" "<<que.top().second<<endl;
    que.pop();
  }
}

int main(){
  VI x(5);
  REP(i,5){cin>>x[i];if(x[i]==0){cout<<i+1<<endl;}}

}

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

using namespace std;

typedef long long int ll;



int T, n, a[100100];


int main(){

	while(scanf("%d", &n)!=EOF){
		for(int i=0; i<n; i++){
			scanf("%d", &a[i]);
		}
		int pos=0, ans=0;
		while(pos<n){
			while((pos+1<n) && a[pos+1]==a[pos]){
				pos++;
			}
			if((pos+1<n) && a[pos+1]<a[pos]){
				while((pos+1)<n && a[pos+1]<=a[pos]){
					pos++;
				}
			}
			else if((pos+1<n) && a[pos+1]>a[pos]){
				while((pos+1)<n && a[pos+1]>=a[pos]){
					pos++;
				}
			}
			ans++;
			pos++;
		}
		printf("%d\n", ans);
	}
	return 0;

}



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

const int N = int(1e5 + 10);
int a[N];

int main() {
    long long x, k;
    
    scanf("%lld %lld", &x, &k);
    
    x -= (x / k) * k;
    
    printf("%lld\n", min(x, k - x));
    
	return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
a = []
for _ in range(N):
    a.append(list(map(int,input().split())))

b = []
for i in range(N-1):
    for j in range(i+1,N):
        b.append(math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2))

c = sum(b)
d = c * (N-1) / (N*(N-1)/2)
print(d)

Measured memory_bytes: 38336
def examA():
    L = LI(); L.sort()
    ans = L[0]*L[1]//2
    print(ans)
    return

def examB():
    def fun(s):
        if s%2==0:
            return s//2
        else:
            return s*3+1
    S = I()
    d = defaultdict(bool)
    d[S] = True; cur = 1
    while(True):
        cur +=1
        S = fun(S)
        if d[S]:
            break
        d[S] = True
    print(cur)
    return

def examC():
    N = I()
    H = LI()
    cur = 0
    ans =0
    for i in range(N):
        if cur<H[i]:
            ans += H[i]-cur
        cur = H[i]
    print(ans)
    return

def examD():
    N, K = LI()
    TS = [LI() for _ in range(N)]
    choice = []
    keep = []
    d = defaultdict(int)
    TS.sort(key=lambda x:x[1],reverse=True)
    for i,(t,s) in enumerate(TS):
        if d[t]==0:
            if i < K:
                d[t] = -1
                choice.append(s)
            else:
                d[t] = s
        else:
            if i<K:
                keep.append(s)
    keep.sort()
    D = sorted(d.values(),reverse=True)
#    print(choice); print(keep); print(D)
    cur = len(choice)
    now = cur**2 +sum(choice)+sum(keep)
    ans = copy.deepcopy(now)
    for i,k in enumerate(keep):
        if D[i]<0:
            break
        now += ((cur+i)*2+1) + (D[i]-k)
        ans = max(ans,now)
#        print(now)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 1e-9
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examD()


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

int main(){
	int n;
	int all[101];
	all[0] = 100000;
	for(int i=1; i<=100; i++){
		all[i] = all[i-1]*1.05;
		if(all[i]%1000){
			all[i] -= (all[i]%1000);
			all[i] += 1000;
		}
		//cout<<all[i]<<endl;
	}
	while(cin>>n){
		cout<<all[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, m
for i in range(n + 1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

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

int main() {
  int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << 0.5 <<endl;
  }
  else {
    printf("%.10lf", (N / 2 + 1.0) / N);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int maxn=100;
char s[maxn]={0};
int k,n;
int main() {
	hh;
	cin>>n;
	cin>>s;
	cin>>k;
	for(int i=0;i<n;i++){
		if(s[i]!=s[k-1]){
			s[i]='*';
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#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;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

int main(){
    string S;
    cin >> S;

    switch(S[0]){
        case('S'):
            cout << "Cloudy" << endl;
            break;
        case('C'):
            cout << "Rainy" << endl;
            break;
        case('R'):
            cout << "Sunny" << endl;
            break;
    }
    return 0;
}

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

using namespace std;

#define int long long 
#define rep(i, N) for (int i = 0; i < N; i++)
#define vi vector<int>

signed main()
{
    int n;
    cin >> n;
    vi data(n);
    rep(i, n) {
        cin >> data[i];
    }

    set<int> pr;
    rep(i, n) {
        int tmp = data[i];
        for (int i = 2; i * i <= tmp; i++) {
            if (tmp % i == 0) {
                while (tmp % i == 0) {
                    tmp /= i;
                }
                pr.insert(i);
            }
        }
        if (tmp >= 2) pr.insert(tmp);
    }

    int ans = 0;
    for (auto i : pr) {
        int p = i, tmp = 0;
        //cout << p << endl;
        rep(j, n) {
            if (data[j] % p == 0) {
                tmp += data[j];
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String word = sc.nextLine();
        int n = sc.nextInt();
        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String[] ops = sc.nextLine().split(" ");
            int v1 = Integer.parseInt(ops[1]);
            int v2 = Integer.parseInt(ops[2]);
            String k = word.substring(v1, v2 + 1);
            if ("print".equals(ops[0])) {
                System.out.println(k);
            } else if ("reverse".equals(ops[0])) {
                word = word.substring(0, v1) + new StringBuilder(k).reverse().toString() + word.substring(v2 + 1);
            } else if ("replace".equals(ops[0])) {
                word = word.substring(0, v1) + ops[3] + word.substring(v2 + 1);
            }
            // System.out.println(word);
        }
    }
}

Measured memory_bytes: 24320
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 7;


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

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

	int ma = INF, mb = INF;
	vector<int> as(n), bs(m);
	for (int& v : as) {
		cin >> v;
		ma = min(ma, v);
	}
	for (int& v : bs) {
		cin >> v;
		mb = min(mb, v);
	}
	int res = ma + mb;

	for (int j = 0; j < k; ++j) {
		int x, y, c;
		cin >> x >> y >> c;
		int off = as[x-1] + bs[y-1] - c;
		res = min(res, off);
	}
	cout << res << '\n';
}


Measured memory_bytes: 1024
use std::io;

fn main() {
    let (n, m) = input_size();
    let m1 = input(n, m);
    let m2 = input(m, 1);

    for i in 0..n {
        let c: i32 = m1[i].iter().enumerate().map(|(k, &v)| v * m2[k][0]).sum();
        println!("{}", c);
    }
}

fn input_size() -> (usize, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    (n, m)
}

fn input(n: usize, m: usize) -> Vec<Vec<i32>> {
    let mut mat: Vec<Vec<i32>> = vec![];
    for i in 0..n {
        let mut s = String::new();
        io::stdin().read_line(&mut s).expect("");
        let mut iter = s.trim().split_whitespace();

        let mut v = vec![];
        for _ in 0..m {
            v.push(iter.next().unwrap().parse().unwrap());
        }
        mat.push(v);
    }
    mat
}


Measured memory_bytes: 5052
import java.io.*;

public class Main {
   public static void main(String[] args) {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      try {
         String line = reader.readLine();
         int count = 0;
         for (int i = 0; i < 3; i++) {
            char a = line.charAt(i);
            if (a == 'a') {
               count ++;
            }
         }
         if (count == 1) {
            count = 0;
            for (int j = 0; j < 3; j++) {
            char b = line.charAt(j);
               if (b == 'b') {
                  count ++;
               }
            }
            if (count == 1) {
               count = 0;
               for (int s = 0; s < 3; s++) {
               char c = line.charAt(s);
                  if (c == 'c') {
                     count ++;
                  }
               }
               if (count == 1){
                     System.out.println("Yes");
               }
               else {
                  System.out.println("No");
               }
            }
            else {
               System.out.println("No");
            }
         }
         else {
            System.out.println("No");
         }  
      } catch (IOException e) {
         System.out.println(e);
      }
   }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
#define ull unsigned  long long
using namespace std;
const int INF =1e9+10;
const int N = 1e3 + 10;
int n,d1,d2,cnt;
int a[N][N];
void solve(int x){
    int tmp=0;
    while(x%4==0){
        x/=4;
        tmp++;
    }
    if(x&1){
        rep(i,0,n*2-1){
            rep(j,0,n*2-1){
                if(((i>>tmp)+(j>>tmp))&1){
                    a[i][j]=1;
                }
            }
        }
    }else{
        rep(i,0,n*2-1){
            rep(j,0,n*2-1){
                if(((i>>tmp))&1){
                    a[i][j]=1;
                }
            }
        }
    }
}
signed main() {
    si(n);
    si(d1);
    si(d2);
    solve(d1);
    solve(d2);
    rep(i,0,n*2-1){
        rep(j,0,n*2-1){
            if(cnt<n*n&&!a[i][j]){
                printf("%d %d\n",i,j);
                cnt++;
            }
        }
    }
    return 0;
}


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

int main(){
  string s,t,u;
  int a,b;cin>>s>>t>>a>>b>>u;
  if(s==u) a--;
  else b--;

  cout<<a<<" "<<b<<endl;
}

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

class Dice:

    def __init__(self, diceList):
        self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList

    def diceRoll(self, r):
        if(r == 'N'):
            self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5

        elif(r == 'E'):
            self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3

        elif(r == 'W'):
            self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4

        elif(r == 'S'):
            self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2


def main():

    orderList = ['N', 'E', 'W', 'S']
    inputDiceList1 = list(map(int, input().split()))
    inputDiceList2 = list(map(int, input().split()))

    dice1 = Dice(inputDiceList1)
    dice2 = Dice(inputDiceList2)

    cmd = "N" * 4 + ("W" + "N" * 4) * 3 + "NE" + "N" * 4 + "EE" + "N" * 4

    for i in cmd:
        if(dice1.d1 == dice2.d1 and dice1.d2 == dice2.d2 and dice1.d3 == dice2.d3 and dice1.d4 == dice2.d4 and dice1.d5 == dice2.d5 and dice1.d6 == dice2.d6):
            print('Yes')
            return 0
        else:
            dice2.diceRoll(i)

    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i=0;
  long long K,A;
  cin>>K;
  A=100;
  while(true){
    A*=1.01;
    i++;
    if(A>=K)
      break;
  }
  cout<<i<<endl;
}
      
 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 3e3+7;
string s,t,ans;
int n,m;
int dp[N][N];
pi to[N][N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> s >> t;

    n = s.size();
    m = t.size();

    // dp[i][j] = LCS of preifx i from s and prefix j from t

    dp[0][0] = (s[0] == t[0]);
    to[0][0] = {-1,0};
    if (s[0] == t[0]) to[0][0] = {-1,-1};
    REP(j,1,m-1)
    {
        dp[0][j] = dp[0][j-1];
        if (s[0] == t[j]) {dp[0][j] = 1;to[0][j] = {-1,j-1};}
        else to[0][j] = {0,j-1};
    }
    REP(i,1,n-1)
    {
        dp[i][0] = dp[i-1][0];
        if (s[i] == t[0]) {dp[i][0] = 1;to[i][0] = {i-1,-1};}
        else to[i][0] = {i-1,0};
    }

    REP(i,1,n-1)
    {
        REP(j,1,m-1)
        {
            dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            if (s[i] == t[j]) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);

            if (dp[i][j] == dp[i][j-1]) to[i][j] = {i,j-1};
            else if (dp[i][j] == dp[i-1][j]) to[i][j] = {i-1,j};
            else if (dp[i][j] == dp[i-1][j-1]+1) to[i][j] = {i-1,j-1};
        }
    }

    //cerr << dp[n-1][m-1] << endl;
    pi cur = {n-1,m-1};
    while(cur.F != -1 && cur.S != -1)
    {
       // cout << cur.F << ' ' << cur.S << endl;
        pi tmp = to[cur.F][cur.S];
        if (cur.F-1 == tmp.F && cur.S-1 == tmp.S) {ans.PB(s[cur.F]);}
        cur = tmp;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 106112
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

ll func(ll n, vector<ll>& p) {
	if (n == 0)return 0;
	if (p[n] != 0) return p[n];
	ll temp = n, ones = 0;
	while (temp) {
		if (temp % 2 == 1)ones++;
		temp /= 2;
	}
	p[n] = func(n % ones, p) + 1;
	return p[n];
}

int main() {
	int N; cin >> N;
	string x; cin >> x;
	ll ones = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (x[i] == '1') ones++;
	}

	if (ones == 0)for (int i = 0; i < N; i++) cout << 1 << endl;
	else if (ones == 1) {
		for (int i = 0; i < N; i++) {
			if (x[i] == '1')cout << 0 << endl;
			else {
				if (i != N - 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		}
	}
	else {
		vector<ll> bi0(N, 1), bi1(N, 1);
		ll m0 = 0, m1 = 0;
		for (int i = N - 1; i >= 0; i--) {
			bi0[i] = ((i == N - 1 ? 1 : bi0[i + 1] * 2)) % (ones + 1);
			bi1[i] = ((i == N - 1 ? 1 : bi1[i + 1] * 2)) % (ones - 1);
			if (x[i] == '1') {
				m0 = (m0 + bi0[i]) % (ones + 1);
				m1 = (m1 + bi1[i]) % (ones - 1);
			}
		}
		vector<ll> p(TE);
		for (int i = 0; i < N; i++) {
			ll n;
			if (x[i] == '0') {
				ll temp = m0 + bi0[i];
				n = temp % (ones + 1);
			}
			else {
				ll temp = m1 - bi1[i];
				n = (temp + (ones - 1)) % (ones - 1);
			}
			cout << func(n, p) + 1 << endl;
		}
	}
}


Measured memory_bytes: 8416
let n, x = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let d = ref 0
let _ = Array.iteri (fun i l -> if !d <= x then d := !d + l else (Printf.printf "%d\n" i; exit 0)) ls; Printf.printf "%d\n" @@ if !d <= x then n + 1 else n

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

// 顺序存储实现栈， 求逆波兰表达式
 
//const int MAX = 100;
//typedef struct Stack{
//	int top;
//	int data[MAX];
//}Stack; 
//
//InitialStack(Stack &s){
//	s.top = 0; // 初始化 , 规定第一个位置没有元素 
//}
//
//bool isFull(Stack &s){  // 判满 
//	return s.top == MAX-1; 
//}
//
//bool isEmpty(Stack &s){
//	return s.top == 0;
//}

int top, S[1000];

int pop(){
//	if(isEmpty(s))
//		return -1;  // 下溢 
	top--; 
	return S[top+1];
}

void push(int x){
//	if(isFull(s))  
//		return;  // 上溢 
	// 如果是符号
	S[++top] = x;
} 


int main(){
	top = 0; 
	int a,b;
	char c[100];
	while(scanf("%s", c) != EOF){  // 循环输入 
		if(c[0] == '+'){
		 	a = pop();
		 	b = pop();
		 	push(b+a);
		}else if(c[0] == '-'){
			a = pop();
			b = pop();
			push(b-a);
		}else if(c[0] == '*'){
			a = pop();
			b = pop();
			push(b*a);
		}else{
			push(atoi(c)); // atoi把string类型的字符串数字，转换为int类型的数字 
		}
	}
	printf("%d\n", pop());
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 100000000000000
#define endl '\n'
ll power(ll a,ll b,ll m){ll ans=1;while(b){if(b&1) ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
int main()
{
	fastio;
	#ifdef gdb_18
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	string s,t;
	getline(cin,s);
	getline(cin,t);
	ll ans=inf;
	for(ll i=0;i<s.length();i++)
	{
		ll cur=0;
		if(i+t.length()>s.length())
			break;
		for(ll j=i;j<i+t.length();j++)
		{
			if(s[j]!=t[j-i])
				cur++;
		}
		ans=min(ans,cur);
	}
	cout<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n,k,c=0;
    cin >> n >> k;
    int a [n];

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i]<=k/2) c+=a[i]*2;
        else c+=(k-a[i])*2;
    }
    cout << c << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, M, C, count=0;
  cin >> N >> M >> C;
  vector <int> A(M+1);
  vector <int> B(M+1);
  int cal;
  for (int i=1; i<=M; i++)
  {
    cin >> B.at(i);
  }
  
  for (int i=1; i<=N; i++)
  {
    for (int j=1; j<=M; j++)
    {
      cin >> A.at(j);
    }
    cal=C;
    for (int j=1; j<=M; j++)
    {
      cal += A.at(j) * B.at(j);
    }
    if (cal>0)
    {
      count++;
    }
  }
  cout << count << endl;
}

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

signed main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  
  vector<int> B(N);
  vector<int> ans;
  for( int i = N-1; i >= 0; i-- ){
    int sum = 0;
    for( int j = (i+1)*2; j <= N; j +=(i+1) ){
      sum += B.at(j-1);
    }
    if( A.at(i) != sum%2 ){
      B.at(i)++;
      ans.push_back(i+1);
    }
  }
  
  cout << ans.size() << endl;
  for( int i = 0; i < ans.size(); i++ ) cout << ans.at(i) << " ";
  cout << endl;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll n,m;

int main(void){
	scanf("%lld%lld",&n,&m);
	if(n==1LL){
		printf("%lld\n",(m+1LL)%MOD);
		return 0;
	}
	ll d_max=m/(n-1LL);
	ll val2=(((m+1LL)%MOD)*(d_max%MOD))%MOD;
	val2=val2*2LL%MOD;
	ll val3=d_max%MOD;
	ll val4=(n-1LL)%MOD;
	ll val5=(n-1LL)%MOD*(d_max%MOD)%MOD;
	ll val6=(val4+val5)%MOD;
	ll res=(val2-val3*val6%MOD+MOD)%MOD;
	res+=(m+1LL)%MOD;
	res%=MOD;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 3212