akhauriyash/Code-Regression huggingface dataset:
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars
    };

    if *s.last().unwrap() == 's' {
        for i in s.iter() {
            print!("{}", i);
        }
        print!("es")
    } else {
        for i in s.iter() {
            print!("{}", i);
        }
        print!("s")
    }
}


Measured memory_bytes: 2176
n = int(input())
v = list(map(int, input().split()))

odd = v[::2]
even = v[1::2]

def makeRank(items):
	rank = {}
	for i in items:
		if i in rank.keys():
			rank[i] += 1
		else:
			rank[i] = 1
	return sorted(rank.items(), key=lambda x: -x[1])

rankOdd = makeRank(odd)
rankEven = makeRank(even)

O1 = rankOdd[0]
E1 = rankEven[0]

if len(rankOdd) == 1 and len(rankEven) == 1:
	if O1[0] == E1[0]:
		print(n // 2)
	else:
		print(0)
elif len(rankOdd) == 1:
	E2 = rankEven[1]
	if O1[0] == E1[0]:
		print(n // 2 - E2[1])
	else:
		print(n // 2 - E1[1])
elif len(rankEven) == 1:
	O2 = rankOdd[1]
	if O1[0] == E1[0]:
		print(n // 2 - O2[1])
	else:
		print(n // 2 - O1[1])
else:
	E2 = rankEven[1]
	O2 = rankOdd[1]
	if O1[0] == E1[0]:
		print(n - O1[1] - max(O2[1], E2[1]))
	else:
		print(n - O1[1] - E1[1])


Measured memory_bytes: 20700
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
    int n, k, d[51][51];
    ll x[50], y[50], u=-1;
    P v[50], w[50], p[50];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        v[i]=P(x[i], i);
        w[i]=P(y[i], i);
    }
    sort(x, x+n);
    sort(y, y+n);
    sort(v, v+n);
    sort(w, w+n);
    for(int i=0;i<n;i++){
        p[v[i].second].first=i;
        p[w[i].second].second=i;
    }
    for(int i=0;i<=n;i++){
        fill(d[i], d[i]+n+1, 0);
    }
    for(int i=0;i<n;i++){
        d[p[i].first+1][p[i].second+1]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[i][j]+=d[i][j-1];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[j][i]+=d[j-1][i];
        }
    }
    //cout<<d[n][n]<<endl;
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            for(int a=i+1;a<=n;a++){
                for(int b=j+1;b<=n;b++){
                    int c=d[a][b]-d[a][j-1]-d[i-1][b]+d[i-1][j-1];
if(c>=k){
    ll z=(x[a-1]-x[i-1])*(y[b-1]-y[j-1]);
    if(u==-1||u>z)u=z;
    
}
                }
            }
        }
    }
    cout<<u<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long ans = 0;
		for(int mask = 0 ; mask < (1<<s.length() - 1) ; mask++) {
			String formura = "";
			for(int i = 0 ; i < s.length() ; i++) {
				if((mask&(1<<i)) >= 1) formura += String.valueOf(s.charAt(i)) + "+";
				else formura += String.valueOf(s.charAt(i));
			}
			String[] split = formura.split("\\+");
			for(int i = 0 ; i < split.length ; i++) {
				if(!split[i].isEmpty()) {
					ans += Long.valueOf(split[i]);
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

inline int mul(int a, int b){
    return ((ll)a * b) % mod;
}

inline int add(int a, int b){
    int ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans; 
}

// credits : codeforces :https://codeforces.com/blog/entry/54396
bool isprime(ll n){
    if(n<2) return false;
    for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false;
    for(int it=0;it<1e2;++it){
        ll i = rand()%(n-1)+1;
        if(__gcd(i,n)!=1) return false;
        // if(mpow(i,n-1,n)!=1) return false;
    }
    return true;
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector< pair<pii, ll> > v(n);
    for(int j = 0; j < n; j++) cin >> v[j].F.F >> v[j].F.S >> v[j].S;
    sort(v.begin(), v.end(), [](const pair<pii, int>& p1, const pair<pii, int>& p2){
        int f1 = p1.F.F <= p2.F.S;
        int f2 = p2.F.F <= p1.F.S;
        if(f1 && f2){
            // equal
            return (int)(p1.F.S-p2.F.F < p2.F.S-p1.F.F);
        } 
        if(f1) return 1;
        if(f2) return 0;
        // no matter what to put first. So, equal
        // return 0;
        return (int)(p1.F.S*p2.F.F > p2.F.S*p1.F.F); 
    });
    // for(auto i : v) cout << "(" << i.F.F << " " << i.F.S << " " << i.S << ") "; cout << endl;

    vector<ll> dp(20005, 0);
    for(int j = 0; j < n; j++){
        ll w = v[j].F.F, s = v[j].F.S, val = v[j].S;
        for(int j = s; j >= 0; j--)
            dp[j+w] = max(dp[j+w], val+dp[j]);
    }
    ll ans = 0;
    for(auto i : dp) ans = max(ans, i);
    cout << ans << '\n';
    return 0;
}


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

int main(){
   int n;
   cin>>n;
   ll ac=0,wa=0,tle=0,re=0;
   rep(i,n){
       string tmp;
       cin>>tmp;
       if(tmp=="AC")ac+=1;
       else if(tmp=="WA")wa+=1;
       else if(tmp=="TLE")tle+=1;
       else if(tmp=="RE")re+=1;
    }
   cout<<"AC x "<<ac<<endl;
   cout<<"WA x "<<wa<<endl;
   cout<<"TLE x "<<tle<<endl;
   cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3636
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, k, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    int res = 0;
    FOR(i,1,k) res += a[i];
    cout << res;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n,ans=0;
	cin>>n;
	vector<int> c,v,a;
	c.resize(n);
	a.resize(n);
	v.resize(n);
	REP(i,n){
		cin >> v[i];
	}
	REP(i,n){
		cin >> c[i];
		a[i] = v[i] -c[i];
	}
	sort(a.begin(),a.end());
	for(int i=n-1; i>=0; i--){
		//cout << a[i];
		if(a[i]<=0)break;
		ans+=a[i];
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
H,W,K = map(int, input().split())
S = [input() for _ in range(H)]

L = [[0]*(W) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "1":
            L[i][j] = 1
        
ans = H*W
for i in range(2**(H-1)):
    cnt = 0
    used = [0]*W
    memo = []
    for j in range(H-1):
        if i & (1<<j):
            cnt += 1
            memo.append(j+1)
    memo.append(H)
    num = [0]*(cnt+1)
    for j in range(W):
        idx = 0
        for k in range(H):
            if memo[idx] == k:
                idx += 1
            num[idx] += L[k][j]
        f = False
        for k in range(len(num)):
            if num[k] > K:
                f = True
                break
        if f:
            if j == 0 or used[j-1] == 1:
                cnt = H*W
                break
            used[j-1] = 1
            cnt += 1
            num = [0]*len(num)
            idx = 0
            for k in range(H):
                if memo[idx] == k:
                    idx += 1
                num[idx] += L[k][j]
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 46172
#include <iostream>
#include <stdio.h>
#include <string>
#define llint long long

using namespace std;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint ans = 0, a;
	for(int i = 1; i <= n; i++){
		cin >> a;
		ans += a;
	}
	ans -= (n+1)*n/2;
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

int main(void) {
	int n,k,c[28]={};
	string s;
	cin>>n>>s>>k;

	c[s[k-1]-'a']++;

	for (int i = 0; i < n; i++) {
		if(c[s[i]-'a']==0)s[i]='*';
	}

	cout<<s<<"\n";


	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split("");

		long k = Long.parseLong(br.readLine());

		long one = 0;
		for (int i = 0; i < str.length; i++) {
			if (str[i].equals("1")) {
				one++;
			} else {
				break;
			}
		}

		if (one >= k) {
			System.out.println("1");
		} else {
			System.out.println(str[(int) one]);
		}
	}
}


Measured memory_bytes: 21332
#include <iostream>
using namespace std;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	long long n,m,a,t=1,mx=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a;
		int g=gcd(a,t);
		if(mx==0){
			mx=1;
			while(!bool(a&(1<<mx-1))) mx++;
		} else {
			if(!(bool(a&(1<<mx-1)))||bool(a&(1<<(mx-1)-1))){
				cout<<"0\n";
				return 0;
			}
		}
		t=t/g*a;
		if(t>2*m){
			cout<<"0\n";
			return 0;
		}
	}
	cout<<(m+t/2)/t<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<iomanip>
using namespace std;
typedef long long  ll;
const int INF=0x3f3f3f;
ll dp[10000005];
ll a[10000005];
int main()
{
	int n,k;
	cin>>n>>k;
	memset(dp,INF,sizeof(dp));
	for(int i=1;i<=n;i++)
	cin>>a[i];
	dp[0]=0,dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		if(i>j)
		dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	}
	cout<<dp[n];
}

Measured memory_bytes: 82528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);
		int q = Integer.parseInt(str[2]);

		int a[] = new int[n];
		Arrays.fill(a, k - q);

		for (int i = 0; i < q; i++) {
			int id = Integer.parseInt(br.readLine());
			a[id-1]++;
		}
		for (int j = 0; j < n; j++) {
			if (a[j] <= 0) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
	}
}

Measured memory_bytes: 61448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<pair<ll, ll>> VPI;
typedef pair<ll, ll> PLL;
typedef map<ll, ll> MLL;
#define EPS 1e-9
#define pb push_back
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

ll max(ll a, ll b, ll c)
{
    ll max = (a > b && a > c) ? a : (b > c) ? b : c;
    return max;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, W;
    cin >> n >> W;
    vector<int> w(n + 1), v(n + 1);
    FOR(i, 1, n + 1)
    {
        cin >> w[i] >> v[i];
    }
    ll dp[n + 1][2];
    ll k[n + 1][W + 1];
    FOR(i, 0, n + 1)
    {
        FOR(j, 0, W + 1)
        {
            if (i == 0 || j == 0)
            {
                k[i][j] = 0;
            }
            else if (w[i] <= j)
            {
                k[i][j] = max(v[i] + k[i - 1][j - w[i]], k[i - 1][j]);
            }
            else
            {
                k[i][j] = k[i - 1][j];
            }
        }
    }
    cout << k[n][W];
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,s2;
    cin>>s;
    bool arr[26]={0};
    int cnt=0;
    for(int i=0;i<s.size();i++){
        arr[s[i]-'a']=1;
    }
    int mn=1e6;
    for(int i=0;i<26;i++){
        s2=s;
        char x=i+'a';
        if(arr[i]){
            cnt=0;
            for(int j=0;j<s2.size();j++){
                cnt+=(s[j]==x);
            }
            while(cnt!=s2.size()){
                string s3;
                cnt=0;
                for(int j=0;j<s2.size()-1;j++){
                    if(s2[j]==x || s2[j+1]==x){
                        s3+=x;
                        cnt++;
                    }
                    else{
                        s3+=s2[j];
                    }
                }
                s2=s3;
            }
        mn=min((int)(s.size()-s2.size()),mn);
        }
    }
    cout<<mn<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL a(N), b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    LL ans = 0;

    for(int i = 0; i <= 30; i++) //i bit
    //for(int i = 0; i <= 4; i++) //i bit
    {
        LL Tn = 1LL << (i+1);
        VL xs,ys;
        REP(j,N){
            xs.pb(a[j] % Tn);
            ys.pb(b[j] % Tn);
        }
        sort(xs.begin(),xs.end());
        sort(ys.begin(),ys.end());
        LL cnt = 0;
        //cout << printVector(xs) << endl;
        //cout << printVector(ys) << endl;

        for(LL x : xs)  {
            int idx = lower_bound(ys.begin(),ys.end(), 4 * (1LL << (i))-x) - lower_bound(ys.begin(),ys.end(), 3 * (1LL << (i))-x) + 1;

            int idx1 = lower_bound(ys.begin(),ys.end(), 2 * (1LL << (i))-x) - lower_bound(ys.begin(),ys.end(), (1LL << (i))-x) + 1;

            cnt += idx + idx1;
        }
        if((cnt)%2 == 1) {
            ans += (1 << i);
        }

    }
    cout << ans << endl;

}

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <utility>
#define MAXN 100010
#define ll unsigned long long
using namespace std;
ll dist[MAXN];
vector <pair <int, ll> > adj[MAXN];
void dfs(int u, int pa) {
	for (auto v : adj[u]) {
		if (v.first == pa) continue;
		dist[v.first] = dist[u] + v.second;
		dfs(v.first, u);
	}
}
int main() {
	int N; cin>>N;
	for (int i = 0, a, b; i < N - 1; i++) {
		ll c; cin>>a>>b>>c;
		adj[a].push_back({b, c});
		adj[b].push_back({a, c});
	}
	int Q, K; cin>>Q>>K;
	dist[K] = 0;
	dfs(K, -1);
	for (int i = 0, a, b; i < Q; i++) {
		cin>>a>>b;
		//cout<<a<<" "<<b<<"\n";
		cout<<dist[a] + dist[b]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 14336
n,a,b=map(int,input().split())

mod=10**9+7

ans=pow(2,n,mod)-1

na=1
nb=1

ansa=1
ansb=1

for i in range(1,a+1):
  na*=i
  na%=mod
  
for i in range(n,n-a,-1):
  ansa*=i
  ansa%=mod
  
ansa*=pow(na,mod-2,mod)

for i in range(1,b+1):
  nb*=i
  nb%=mod
  
for i in range(n,n-b,-1):
  ansb*=i
  ansb%=mod
  
ansb*=pow(nb,mod-2,mod)

ans-=ansa
ans-=ansb

ans%=mod


print(ans)


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

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    vector<vector<int>> A(2, vector<int> (N));

    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    
    int row = 0; int maxsum = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for(int j = 0; j < N; j++) {
            if(i == j) {
                sum += A[0][j];
                row = 1;
            }
            sum += A[row][j];
        }
        row = 0;
        maxsum = max(sum, maxsum);
    }
    cout << maxsum<< endl;
    return 0;
}


Measured memory_bytes: 256
#####
 
import numpy as np
from numpy import int32, int8
from collections import defaultdict

#####
 
def getIntList(inp):
	return [int(_) for _ in inp]
 
 
from sys import stdin
import sys
sys.setrecursionlimit(10**6) 
def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs
 
 
def dfs(node, depths, d, connected, parent):
	depths[node-1]=d
	for child in connected[node]:
		if child==parent: continue
		dfs(child, depths, not d, connected, node)
		
 
def main(inputs):
	n=int(inputs[0][0])
	
	edge=defaultdict(list)
	for i in range(n-1):
		a,b=getIntList(inputs[1+i])
		edge[a].append(b)
		edge[b].append(a)
	
# 	for v0 in sorted(edge): print(v0, sorted(edge[v0]))
	
	depths=np.empty(n, np.bool)
	dfs(1, depths, 0, edge, -1)
# 	for i in range(n):print(i+1,depths[i])
# 	depths%=2
	
	m=n%3
	if m==0: remainingMod=[n//3,n//3,n//3]
	elif m==1: remainingMod=[n//3,n//3+1,n//3]
	elif m==2: remainingMod=[n//3,n//3+1,n//3+1]
# 	print(remainingMod)
	
	values=np.empty(n, int32)
	sum0=(depths==0).sum()
	sum1=(depths==1).sum()
	
# 	global counts
	
	if sum0<=remainingMod[0]:
# 		counts[0]+=1
		values[depths==0]=0
		remainingMod[0]-=sum0
		remaining=np.concatenate([v*np.ones(remainingMod[v], int32) for v in range(3)])
		values[depths==1]=remaining
	
	elif sum1<=remainingMod[0]:
# 		counts[1]+=1
		values[depths==1]=0
		remainingMod[0]-=sum1
		remaining=np.concatenate([v*np.ones(remainingMod[v], int32) for v in range(3)])
		values[depths==0]=remaining
		
	else:
# 		counts[2]+=1
		remaining=np.concatenate([1*np.ones(remainingMod[1], int32), np.zeros(sum0-remainingMod[1])])
		values[depths==0]=remaining
		remaining=np.concatenate([2*np.ones(remainingMod[2], int32), np.zeros(sum1-remainingMod[2])])
		values[depths==1]=remaining
	
	values[values==0]=np.arange((values==0).sum())*3+3
	values[values==1]=np.arange((values==1).sum())*3+1
	values[values==2]=np.arange((values==2).sum())*3+2
	print(" ".join(map(str,values)))
	
# 	v3=defaultdict(list)
# 	for i in range(1,n+1):
# 		visited=set([i])
# 		prev=[i]
# 		for count in range(3):
# 			next=[]
# 			for node in prev:
# 				for child in edge[node]:
# 					if child in visited: continue
# 					next.append(child)
# 			visited.update(next)
# 			prev=next
# # 			print(i, next)
# 		v3[i]=next
# 	
# # 	for v0 in sorted(v3):
# # 		print(v0, sorted(v3[v0]))
# 	
# # 	print("testing")
# 	ok=True
# 	for v0 in v3:
# 		for v1 in v3[v0]:
# 			val0=values[v0-1]
# 			val1=values[v1-1]
# 			if (val0+val1)%3==0 or (val0*val1)%3==0:
# 				pass
# # 				print(v0, val0%3, v1, val1%3, "ok")
# 			else:
# # 				print(v0, val0%3, v1, val1%3, "NG")
# 				ok=False
# 	assert ok
 
 
if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int k, x; cin >> k >> x;

    for(int i = x - k + 1; i < x; i++){
        cout << i << " ";
    }
    for(int i = x; i < k + x; i++){
        if(k + x == i) cout << i << endl;
        else cout << i << " ";
    }

    return 0;
}


Measured memory_bytes: 3604
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include <fstream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define pb push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define MAX 100000 
using namespace std;
typedef long long int lli;
typedef unsigned long long ULL;
typedef long double LD;

int main(){
    lli n;
    cin >> n;
    lli a[100007];
    lli negatives = 0;
    vector<lli> arr;
    lli ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] < 0){
            negatives++;
        }
        arr.pb(abs(a[i]));

        ans+= abs(a[i]);
    }
    sort(arr.begin(), arr.end());
    if(negatives%2 != 0){
        ans-=(2*arr[0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;

void skip(int p, int s);
void decrement(int p);

int n;
string st;

int main()
{
    while (cin >> n, n) {
        vector<int> data(n);
        rep(i, n) {
            cin >> data[i];
        }
        cin >> st;
        for (int i = 0, j = 0; i < st.length(); i++, j++) {
            if (j == n) {
                j = 0;
            }
            skip(i, data[j]);
        }
        cout << st << endl;
    }
    return 0;
}

void skip(int p, int s)
{
    rep(i, s) {
        decrement(p);
    }
}

void decrement(int p)
{
    if (st[p] == 'A') {
        st[p] = 'z';
    } else if (st[p] == 'a') {
        st[p] = 'Z';
    } else {
        st[p]--;
    }
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll a,b;
    cin>>a>>b;
    if( a == b ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

warshallFloyd1 :: Int -> U.Vector (Int, Int, Int) -> V.Vector (U.Vector Int)
warshallFloyd1 !n !edges = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  U.forM_ edges $ \(a,b,c) -> do
    UM.write (arr V.! a) b c
    UM.write (arr V.! b) a c
  forM_ [0..n-1] $ \a -> do
    UM.write (arr V.! a) a 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.read (arr V.! i) k
        a_kj <- UM.read (arr V.! k) j
        UM.modify (arr V.! i) (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

warshallFloyd2 :: Int -> Int -> V.Vector (U.Vector Int) -> V.Vector (U.Vector Int)
warshallFloyd2 !n !l !graph = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  forM_ [0..n-1] $ \a -> do
    forM_ [0..n-1] $ \b -> do
      let v = graph V.! a U.! b
      when (v <= fromIntegral l) $ do
        UM.write (arr V.! a) b 1
    UM.write (arr V.! a) a 0
  forM_ [0..n-1] $ \k -> do
    forM_ [0..n-1] $ \i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.read (arr V.! i) k
        a_kj <- UM.read (arr V.! k) j
        UM.modify (arr V.! i) (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

main = do
  [n,m,l] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,c)
  let !w1 = warshallFloyd1 n edges
      !w2 = warshallFloyd2 n l w1
  q <- readLn
  queries <- U.replicateM q $ do
    [s,t] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (s,t)
  U.forM_ queries $ \(s,t) -> do
    let d = w2 V.! (s-1) U.! (t-1)
    print $ if d > 10^9 then -1 else d - 1


Measured memory_bytes: 7292
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int a,b,ans=0; cin>>a>>b; 
    if (a<b) swap(a,b);
    if (a-b<=1) {
    	if (a-b==1){
    		ans = a;
    		while (a>1 and b>0){
    			a--;
    			ans = (ans*a*b)%1000000007;
    			b--;
    		}
    	}
    	else {
    		ans = a+b; 
    		while (a>1){
    			ans = (ans*b)%1000000007;
    			b--,a--;
    			ans = (ans*a)%1000000007;
    		}
    	}
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3612
# https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_2_A
# 内積で判別すれば良い


from math import sqrt, isclose


def euclid_norm(x, y):
    return sqrt(pow(x, 2) + pow(y, 2))


def is_parallel(x0, y0, x1, y1, x2, y2, x3, y3):
    x_v1 = x1 - x0
    y_v1 = y1 - y0
    x_v2 = x3 - x2
    y_v2 = y3 - y2
    dot = (x_v1 * x_v2 + y_v1 * y_v2) / \
        (euclid_norm(x_v1, y_v1) * euclid_norm(x_v2, y_v2))
    # print(dot)
    if isclose(dot, 1, rel_tol=1e-10) or isclose(dot, -1, rel_tol=1e-10):
        return True
    return False


def is_orhogonal(x0, y0, x1, y1, x2, y2, x3, y3):
    x_v1 = x1 - x0
    y_v1 = y1 - y0
    x_v2 = x3 - x2
    y_v2 = y3 - y2
    dot = (x_v1 * x_v2 + y_v1 * y_v2) / \
        (euclid_norm(x_v1, y_v1) * euclid_norm(x_v2, y_v2))
    # print(dot)
    if isclose(dot, 0, rel_tol=1e-10):
        return True
    return False


# load data
N = int(input())
for i in range(N):
    tmp = list(map(int, input().split()))
    if is_parallel(*tmp):
        print(2)
    elif is_orhogonal(*tmp):
        print(1)
    else:
        print(0)



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

int d1[100000], d2[100000];
int c1[100000], c2[100000];
vector<int>E[100000];
void bfs(int*d,int*c, int s) {
	queue<int>que;
	d[s] = 0; que.push(s);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		c[d[p]]++;
		for (int v : E[p]) {
			if (d[v] == -1) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, s, t; scanf("%d%d%d%d", &n, &m, &s, &t); s--; t--;
	rep(i, m) {
		int x, y; scanf("%d%d", &x, &y); x--; y--;
		E[x].push_back(y); E[y].push_back(x);
	}
	memset(d1, -1, sizeof(d1));
	memset(d2, -1, sizeof(d2));
	bfs(d1, c1, s); bfs(d2, c2, t);
	ll ans = 0;
	for (int i = 0; i <= d1[t] - 2; i++) {
		ans += (ll)c1[i] * c2[d1[t] - 2 - i];
	}
	printf("%lld\n", ans);
}

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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}
int N, T;
vector<int> c, t;

void init()
{
	cin >> N >> T;
	c.resize(N);
	t.resize(N);
	rep(i, N) cin >> c[i] >> t[i];
}

void solve()
{
	int res = 100000;
	rep(i, N) {
		if (t[i] <= T) {
			res = min(res, c[i]);
		}
	}
	if (res == 100000) {
		cout << "TLE" << endl;
	}
	else {
		cout << res << endl;
	}
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

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

func main() {
	sc.Split(bufio.ScanWords)
	a, b := next(), next()
	if a == b {
		fmt.Println("H")
	} else {
		fmt.Println("D")
	}
}


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

int main() {
string r,b;

cin>>r>>b;

int x,y;

 cin>>x>>y;
 

string f;

cin >>f;

if (f==r)
x-=1;
else if(f==b)
y-=1;

cout <<x<<' '<<y;


    return 0;
}

Measured memory_bytes: 256
// author - shreyanshjn (Shreyansh Jain)
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
/* #define input 1 */
#define INF 100000000000000000
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define rep(a,b,c) for(int a=b; a<c; a++)
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
const int mod = 1e9 + 7;
int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
string trim(const string& str) {
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() { 
    #ifdef input
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(15);
    int n, w; cin >> n >> w;
    vector<pair<int,int>> items(n + 1); 
    for(int i = 1; i <= n; i++) {
        cin >> items[i].ff >> items[i].ss;
    }
    ll dp[n + 1][w + 1];
    fori(0, n + 1) {
        dp[i][0] = 0;
    }
    fori(0, w + 1) {
        dp[0][i] = 0;
    }
    for(int i = 1; i <= n; i++) {
        for(int p = 1; p <= w; p++) {
            if(p - items[i].ff >= 0)
                dp[i][p] = max(items[i].ss + dp[i - 1][p - items[i].ff], dp[i - 1][p]);
            else 
                dp[i][p] = dp[i - 1][p];
        }
    }
    cout << dp[n][w] << endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 82588
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

void	reverse(string &S)
{
	int i = 0, j = S.size() - 1;

	while (i < S.size() / 2)
	{
		swap(S[i], S[j]);
		i++;
		j--;
	}
}

int		main(void)
{
	string S;

	cin >> S;
	string A, B;
	int h = S.size() / 2;

	A = S.substr(0, h);
	if (S.size() % 2 == 0)
		B = S.substr(h, h);
	else
		B = S.substr(h + 1, h);
	reverse(B);
	int cnt = 0;

	for (int i = 0; i < S.size() / 2; i++)
	{
		if (A[i] != B[i])
			cnt++;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = sorted(list(input()))
t = sorted(list(input()),reverse = True)
print('Yes' if s < t else 'No')


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

class RollingHash {
 public:
  explicit RollingHash(const std::string &s) {
    mod = std::vector<ll>{999999937LL, 1000000007LL};
    base = 9973;
    n = s.size();
    for (int i = 0; i < MS; i++) {
      hs[i].assign(n+1, 0);
      pw[i].assign(n+1, 0);
      hs[i][0] = 0;
      pw[i][0] = 1;
      for (int j = 0; j < n; j++) {
        pw[i][j+1] = pw[i][j]*base%mod[i];
        hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
      }
    }
  }
  bool match(int l1, int r1, int l2, int r2) {
    bool ret = 1;
    for (int i = 0; i < MS; i++)
      ret &= hash(l1, r1, i) == hash(l2, r2, i);
    return ret;
  }

  std::vector<ll> get_hash(int l, int r) {
    std::vector <ll> res(MS);
    for (int i = 0; i < MS; i++)
      res[i] = hash(l, r, i);
    return res;
  }

 private:
  static const int MAX = 500000, MS = 2;
  std::vector<ll> mod;
  ll base;
  int n;
  std::vector<ll> hs[MS], pw[MS];
  ll hash(int l, int r, int i) {
    return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i];
  }

  bool match(int l, int r, ll h[]) {
    bool ret = 1;
    for (int i = 0; i < MS; i++)
      ret &= hash(l, r, i) == h[i];
    return ret;
  }
};

signed main() {
  ll N;
  string s;
  cin >> N >> s;
  RollingHash rh(s);
  ll ng = 2501, ok = 0;
  while (ok + 1 < ng) {
    ll m = (ok+ng)/2;
    // cout << m << endl;
    bool t = false;

    map<vector<ll>, ll> mp; // mp[hash value] = index
    rep(i,N) {
      if (i+m > N)
        continue;

      auto h = rh.get_hash(i, i+m);
      auto it = mp.find(h);
      if (it == mp.end()) {
        mp[h] = i;
      } else {
        // hash find
        if (it->second + m <= i) {
          t = true;
          break;
        }
      }
    }

    if (t) {
      ok = m;
    } else {
      ng = m;
    }
  }

  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N+1),B(N+1);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[i+1]=A[i]+a;
  }
  for(int i=0;i<N;i++)cin>>B[i];
  for(int i=N-1;i>=0;i--)B[i]+=B[i+1];
  int ans=0;
  for(int i=0;i<N;i++)ans=max(ans,A[i+1]+B[i]);
  cout<<ans<<endl;
}

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

struct Mod
{
    static const auto P = int(1e9+7);
    int k;

    Mod() = default;
    Mod(const int k) : k(k%P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod& operator+=(Mod& a, const Mod b) { return a = a+b; }

int main()
{
    const auto log = 63;
    long long N; cin >> N;
    const auto digits = bitset<log>(N);

    auto dp = new Mod[log][2][2]{};
    auto seen = new bool[log][2][2]{};
    const function<Mod(int, bool, bool)> f = [&](const int i, const bool tight, const bool carry)
    {
        if (i < 0) return Mod(!carry);

        auto& result = dp[i][tight][carry];
        if (seen[i][tight][carry]) return result;
        else seen[i][tight][carry] = true;

        auto seen2 = array<array<bool, 2>, 2>{};
        for (const auto a : {0, 1}) for (const auto b : {0, 1}) for (const auto c : {0, 1})
        {
            const auto sum = a + b + c;
            if (sum >> 1 != carry) continue;
            if (tight && sum % 2 > digits[i]) continue;

            if (seen2[sum%2][a^b]) continue;
            else seen2[sum%2][a^b] = true;

            result += f(i-1, tight && digits[i] == sum % 2, c);
        }
        return result;
    };
    cout << f(log-1, true, false).k << endl;
}


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

int main(){
  int n, m, c, a, correct=0;
  cin >> n >> m >> c;
  vector<int> b(m);
  
  for(int i=0;i<m;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<m;j++){
      cin >> a;
      sum += a*b.at(j);
    }
    if(sum+c>0){
      correct++;
    }
  }
  cout << correct << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k, a[2008], c[2008], ans[2008], all[2008];
string str;

int main(){
	cin >> n >> k;
	for(ll i = 1; i <= n; i++){cin >> a[i];}
	
	memset(c, 0, sizeof(c));
	memset(ans, 0, sizeof(ans));
	for(ll i = 1; i <= n; i++){
		for(ll j = 2000; j > a[i]; j--){
			ans[i] += c[j];
		}
		c[a[i]]++;
		all[i] = ans[i];
	}
	
	memset(c, 0, sizeof(c));
	for(ll i = n; i >= 0; i--){
		for(ll j = 2000; j > a[i]; j--){
			all[i] += c[j];
		}
		c[a[i]]++;
	}
	
	ll MOD = 1e9+7;
	ll summ = 0;
	for(ll i = 1; i <= n; i++){
		ll buf = k*(k-1)/2;
		buf %= MOD;
		buf *= all[i];
		buf %= MOD;
		summ += buf;
		summ %= MOD;
		summ += k*ans[i];
		summ %= MOD;
	}

	cout << summ << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)	((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
  
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    cout.setf(ios::fixed); cout.precision(9);    
    solve();               	
    return 0;
} 

const int MOD = 998244353, MAXN = 100 + 10, INF = 1e9 + 10;
 
void solve() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) {
        a--;
    }   
    else {
        b--;
    }

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


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

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; ++i) {
		if (n % i == 0) {
			if (n / i <= 9) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
s = input().strip()
t = input().strip()


def get_patten(l):
    pattern = []
    d = dict()
    i = ord('a')
    for c in l:
        if c not in d:
            d[c] = chr(i)
            i += 1
        pattern.append(d[c])
    return pattern


ps = get_patten(s)
pt = get_patten(t)

if ps == pt:
    print('Yes')
else:
    print('No')


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

namespace ABC061_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = aaa[0];
            var M = aaa[1];
            var point = new List<int>();
            for(var i=0;i<M;i++)
            {
                var road = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                point.Add(road[0]);
                point.Add(road[1]);
            }
            for(var i=1;i<=N;i++)
            {
                Console.WriteLine(point.Count(x => x == i));
            }
        }
    }
}


Measured memory_bytes: 13268
import numpy as np

N, K, Q = map(int, input().split())

A_list = []

for i in range(Q):
  A=int(input())
  A_list.append(A)

Get_point_list = [0] * N
  
for i in range(len(A_list)):
  idx = A_list[i] - 1
  Get_point_list[idx] += 1
  
Minus_list = [K-Q] * N

ans_list = np.array(Get_point_list) + np.array(Minus_list)

ans_list2 = []

for i in range(len(ans_list)):
  if ans_list[i] > 0:
    ans_list2.append("Yes")
  else:
    ans_list2.append("No")

print(*ans_list2)

Measured memory_bytes: 21548
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

class A {
public:
	A(int **p) : p_(p) { }

	int operator()(int i, int j) {

		return p_[i][j];
	}
private:
	int **p_;
};

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

	// lcs[i][j]: s[0:i+1]とt[0:j+1]のlcsの長さ
	static int lcs[3010][3010];
	
	const auto n = s.length();
	const auto m = t.length();

	for(int y = 0; y < n; y++) {
		for(int x = 0; x < m; x++) {
			if(x == 0 || y == 0) {
				lcs[y][x] = (s[y] == t[x]) ? 1 : 0;
				if(x == 0 && y != 0) {
					lcs[y][x] = max(lcs[y][x], lcs[y - 1][x]);
				} else if(y == 0 && x != 0) {
					lcs[y][x] = max(lcs[y][x], lcs[y][x - 1]);
				}
			} else {
				if(s[y] == t[x]) {
					lcs[y][x] = lcs[y - 1][x - 1] + 1;
				} else {
					lcs[y][x] = max(lcs[y - 1][x], lcs[y][x - 1]);
				}
			}
		}
	}

	string result = "";
	int y = n - 1;
	int x = m - 1;
	while(y >= 0 && x >= 0) {
		if(s[y] == t[x]) {
			result += s[y];
			y--;
			x--;
		} else if(x == 0) {
			y--;
		} else if(y == 0) {
			x--;
		} else if(lcs[y - 1][x] > lcs[y][x - 1]) {
			y--;
		} else {
			x--;
		}
	}
	
	reverse(result.begin(), result.end());

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 38888
import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)

def main(d):
    res = ''
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    j = str(j)
                    if j in d:
                        res += j
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l
    print(res)

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

Measured memory_bytes: 3772
#include<stdio.h>

int main(){
    int i=0,n,data[10000];
    while(scanf("%d",&n)!=EOF){
       if(n!=0){
            data[i]=n;
            i++;
       }
        else {
        i--;
        printf("%d\n",data[i]);
        }
    }
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int a, b;
	string s;

	bool ok = true;
	cin >> a >> b >> s;

	for (int i = 0; i < a; i++)
	{
		if (!(s[i] >= 48 && s[i] <= 57)) ok = false;
	}

	if (s[a] != '-') ok = false;

	for (int i = 0; i < b; i++)
	{
		if (!(s[i + a + 1] >= 48 && s[i + a + 1] <= 57)) ok = false;

	}

	if (ok) cout << "Yes" << endl;
	else cout << "No" << 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 ret = 0;
		for (int i = 1; i < n + 1; i++) {
			ret += i;
		}
		System.out.println(ret);
	}

}


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

int r,c;
int o[10][10000];

int rec(int n){
  int res,cnt;
  if(n == r){
    res = 0;
    for(int i=0;i<c;i++){
      cnt = 0;
      for(int j=0;j<r;j++){
	if(o[j][i])cnt++;
      }
      if(cnt <= r/2)cnt = r - cnt;
      res += cnt;
    }
    return res;
  }else{
    res = rec(n+1);
    for(int i=0;i<c;i++)o[n][i] = 1 - o[n][i];
    res = max(res,rec(n+1));
    for(int i=0;i<c;i++)o[n][i] = 1 - o[n][i];
    
    return res;
  }
}

int main(){
  int ans;

  while(1){
    cin >> r >> c;
    if(!r  && !c)break;

    for(int i=0;i<r;i++){
      for(int j=0;j<c;j++)cin >> o[i][j];
    }

    ans = rec(0);

    cout << ans << endl;
  }
}

Measured memory_bytes: 1252