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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	vector<vector<int>> st;
	int N, M, Q;
	
	cin>>N>>M>>Q;
	
	st.resize(N+1);
	
	for(int i = 0; i < M; i++){
		int L, R;
		
		cin>>L>>R;
		
		st[L].push_back(R);
	}
	
	for(int i = 1; i <= N; i++){
		sort(st[i].begin(), st[i].end());
	}
	
	for(int i = 0; i < Q; i++){
		int p, q;
		int ans = 0;
		
		cin>>p>>q;
		
		for(int j = p; j <= q; j++){
			ans += upper_bound(st[j].begin(), st[j].end(), q) - st[j].begin();
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3456
//
// Created by rajshah9914 on 29/03/20.
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int lcs[s.length()+2][t.length()+2];
//    for(int i=0;i<s.length();i++)
//        lcs[i][0]=0;
//    for(int i=0;i<t.length();i++)
//        lcs[0][i]=0;
//    cout<<s.length()<<" "<<t.length()<<endl;
memset(lcs,0,sizeof(lcs));
    for(int i=0;i<s.length()+1;i++)
    {
        for(int j=0;j<t.length()+1;j++)
        {
            if(i==0 || j==0)
            {
                lcs[i][j]=0;
//                cout<<"hi";
            }
            else if(s[i-1]==t[j-1])
            {
//                cout<<s[i-1]<<" "<<t[j-1]<<endl;
                lcs[i][j]=lcs[i-1][j-1]+1;
            }
            else
            {
//                cout<<s[i-1]<<" "<<t[j-1]<<endl;
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
            }
        }
    }
//int m=s.length();
////int n=t.length();
////int L[m+1][n+1];
////    for (int i=0; i<=m; i++)
////    {
////        for (int j=0; j<=n; j++)
////        {
////            if (i == 0 || j == 0)
////                L[i][j] = 0;
////            else if (s[i-1] == t[j-1])
////                L[i][j] = L[i-1][j-1] + 1;
////            else
////                L[i][j] = max(L[i-1][j], L[i][j-1]);
////        }
////    }
//    for(int i=0;i<s.length()+1;i++)
//    {
//        for(int j=0;j<t.length()+1;j++)
//            cout<<lcs[i][j]<<" ";
//        cout<<endl;
//    }
//    cout<<L[s.length()][t.length()];
    int ind=lcs[s.length()][t.length()];
    string ans;
    int i=s.length();
    int j=t.length();
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans.push_back(s[i-1]);
            i--;
            j--;
            ind--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
//    cout<<lcs[s.length()][t.length()]<<endl;
}

Measured memory_bytes: 35456
n, m = [int(x) for x in input().split()]

foods = list()
for _ in range(n):
    foods.append([int(x) for x in input().split()])

foods.sort(reverse = True)
foods = [f[1:] for f in foods]

count = 0
for f in foods[0]:
    if all(map(lambda l: f in l, foods[1:])):
        count += 1

print(count)

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

int main() {
  int N,M;
  cin >> N >> M;
  if(N%2==1){
  for(int i=1;i<=M;i++){
    cout << i << " " << 2*M+1-i << endl;
  }
  }
  else{
    int p;
    if(N/4>M){
      p=M;
    }
    else{
      p=N/4;
    }
    for(int i=0;i<p;i++){
      cout << M-i << " " << M+1+i << endl;
    }
    for(int i=p;i<M;i++){
      cout << M-i << " " << M+2+i << endl;
    }
  }
}


  

  

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

int main() {
  long long n, m; cin >> n >> m;
  vector<long long> h(n);
  for(int i = 0; i < n; i++) cin >> h.at(i);
  vector<vector<int>> p(n, vector<int>());
  for(int i = 0; i < m; i++){
    long long tmpa, tmpb; cin >> tmpa >> tmpb;
    tmpa--; tmpb--;
    p.at(tmpa).push_back(tmpb);
    p.at(tmpb).push_back(tmpa);
  }
  long long out = 0;
  for(int i = 0; i < n; i++){
    if(p.at(i).size() == 0){
      out++;
      continue;
    }
    long long ha = h.at(i);
    for(int j = 0; j < p.at(i).size(); j++){
      if(ha <= h.at(p.at(i).at(j))) break;
      if(j == p.at(i).size() - 1) out++;
    }
  }
  cout << out;
}

Measured memory_bytes: 9068
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    string s;
    cin >> s;
    int n=s.size();
    if(s=="keyence"){
        puts("YES");
        return 0;
    }
    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            string t;
            for(int k=0; k<n; k++){
                if(i<=k && k<=j){
                    continue;
                }else{
                    t+=s[k];
                }
            }
            if(t=="keyence"){
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

    long double ans;
    if(a * a * b / 2.0 <= x) {
        ans = atan(2 * (a * a * b - x) / (a * a * a));
    } else {
        ans = PI / 2 - atan(2 * x / (a * b * b));
    }
    
    ans = ans * 180.0 / PI;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

k = [0] * m
s = [[] for i in range(m)]
for i in range(m):
    ary = list(map(int,input().split()))
    k[i] = ary[0]
    s[i] = ary[1:]

p = list(map(int,input().split()))

ans = 0
for bit in range(2 ** n):
    on_light_cnt = 0
    for i in range(m):
        on_switch_cnt = 0
        for j in s[i]:
            if (bit >> (j - 1)) & 1 == 1:
                on_switch_cnt += 1

        if on_switch_cnt % 2 == p[i]: 
            on_light_cnt += 1
    if on_light_cnt == m: ans += 1

print(ans)

Measured memory_bytes: 41200
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  1 18:53:11 2019

@author: Yamazaki Kenichi
"""

N = int(input())
mod = 10**9+7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
#        print(t)
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'AGCT':
#        print(last3 + c)
#        print(ok(last3 + c))
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
    memo[cur][last3] = ret
    return ret

print(dfs(0,'TTT'))

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

#define rep(i, n)    for(int i = 0; i < n;i++)

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = min(A, B); i >= 1;i--){
        if(A % i == 0 && B % i == 0){
            K--;
            if(K == 0){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
X, Y, Z, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

maxn = A[0] * B[0] * C[0]

from heapq import *

h = []


heappush(h, (-A[-1] - B[-1] - C[-1], len(A) - 1, len(B) - 1, len(C) - 1))

used = {}

for i in range(min(K, X * Y * Z)):
    v, ix, iy, iz = heappop(h)
    print(-v)
    def push(x, y, z):
        if x >= 0 and y >= 0 and z >= 0 and (x, y, z) not in used:
            heappush(h, (-A[x] - B[y] - C[z], x, y, z))
            used[x, y, z] = 1
    push(ix - 1, iy, iz)
    push(ix, iy - 1, iz)
    push(ix, iy, iz - 1)



Measured memory_bytes: 4916
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
        t: chars,
    }
    for i in 0..s.len() {
        let s = {
            let mut tmp = s.iter().skip(i).map(|c| *c).collect::<Vec<_>>();
            tmp.append(&mut s.iter().take(i).map(|c| *c).collect::<Vec<_>>());
            tmp
        };
        if s == t {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int p[10];
  int q[10];
  for(int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> q[i];
  }
  int a = 0, b = 0;
  for(int i = n - 2, k = 1; i >= 0; i--, k *= n - i - 1) {
    for(int j = n - 1; j > i; j--) {
      if(p[i] > p[j]) {
        a += k;
      }
      if(q[i] > q[j]) {
        b += k;
      }
    }
  }
  cout << abs(a - b) << endl;
  return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

S = F.readline().rstrip()
N = int(len(S) - 1)
sum = 0
l = [0]

# pdb.set_trace()
for bit in range(1<<N):
    for i in range(N):
        if bit & (1<<i):
            l.append(i+1)

    l.append(int(N+1))
    l_length = len(l)
    for j in range(l_length):
        if j == 0:
            continue
        ss = S[(l[j-1]):(l[j])]

        sum += int(ss)

    l = [0]


print(sum)


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,k,i,j,l,m;
	cin>>n>>k;
	ll arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	l=0;
	for(i=0;i<n-k;i++)
		l+=arr[i];
	cout<<l<<"\n";
	return 0;
}


Measured memory_bytes: 5208
#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++)
typedef long long ll;
#define mod 1000000007

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int x;
            cin >> x;
            a[x-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(a[i]==0) ans++;
    }
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int a, b;
	cin >> a;
	if (a < 9) {
		cout << "No" << endl;
		return 0;
	}
	if (a >= 90) {
		cout << "Yes" << endl;
		return 0;
	}
	b = a - 9;
	if (b % 10 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

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

int main(){
	while(1){
		int n,m;
		cin >> n >> m;
		if(n==0) break;
		
		vector<int> a(m, 0);
		for(int i=0; i<n; i++){
			int d,v;
			cin >> d >> v;
			d--;
			a[d] = max(a[d], v);
		}
		
		int ans = 0;
		for(int i=0; i<m; i++){
			ans += a[i];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3032
#include <stdio.h>

#define LENGTH 256

int payment(int num) {
  int result, r;
  r = num % 1000;
  if(r == 0) {
    result = 0;
  } else {
    result = 1000 - r;
  }
  return result;
}

int main() {
  char input[LENGTH];
  int a, b;
  fgets(input, LENGTH, stdin);
  sscanf(input, "%d", &a);
  b = payment(a);
  printf("%d \n", b);
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=LINF,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

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

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n>>a;
      rep(i,n){
        cin>>b>>c;
        if(c<=a)ans=min(ans,b);
      }
      if(ans==LINF)Cout("TLE");
      else Cout(ans);
    
       
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);

		   String d = scanner.next();
		   String n = scanner.next();
		   int D = Integer.parseInt(d);
		   int N = Integer.parseInt(n);
		  
		   if(D == 0)
		   {
			   if(N == 100) 
			   {
				   System.out.println(101);
			   }
			   else 
			   {
				   System.out.println(N);
			   }
		   }
		   if(D == 1) 
		   {
			   if(N == 100) 
			   {
				   System.out.println(10100);
			   }
			   else 
			   {
				   System.out.println(N * 100);
			   }
		   }
		   if(D == 2) 
		   {
			   if(N == 100) 
			   {
				   System.out.println(1010000);
			   }
			   else 
			   {
				   System.out.println(N * 10000);
			   }
		   }
        	scanner.close();}
		  }

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    string s,t;
    cin >> n >> s >> t;
    for(int i = n;i >= 0;i--) {
        if(s.substr(n - i,i) == t.substr(0,i)) {
            cout << 2 * n - i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n; cin >> n;
    vector<int> a(n+1);
    REP(i,n) cin >> a[i+1];

    vector<int> b(n+1);

    for(int i = n; i >=1; --i) {
        int sum = 0;
        for(int j = i + i; j <=n; j += i) {
            sum ^= b[j];
        }
        b[i] = sum ^ a[i];
    }
    vector<int> ans;

    for(int i = 1; i <= n; ++i) {
        if(b[i]) ans.push_back(i);
    }

    cout << ans.size() << endl;
    for(auto v : ans) {
        cout << v << " ";
    }
    cout << endl;

    return 0;
}

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

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    long double PI = acos(-1);
    long double m_theta = 2.0*PI*m/60.0; 
    long double h_theta = 2.0*PI*h/12.0 + PI/6.0*m/60.0;
    cout << fixed << setprecision(20) << sqrtl(a*a + b*b - 2*a*b*cosl(h_theta-m_theta)) << endl;
    return 0;

}

Measured memory_bytes: 4164
#include"iostream"

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int max=0;
    if (a + b > a - b) {
        max = a + b;
    }
    else {
        max = a - b;
    }
    if (max < a*b) {
        max = a * b;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b<c)
    {
        d=b/a;
        if(d>c)
        {
            printf("%d",c);
        }
        else
        {
            printf("%d",d);
        }
    }
    else
    {
        printf("0");
    }
}


Measured memory_bytes: 128
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:k:h)=minimum$zipWith(-)hs ss where
 hh=sort h
 ss=take(n-k+1)hh
 hs=drop(k-1)hh

Measured memory_bytes: 16764
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <cstring>
#define INF 1000001
typedef long long llong;
using namespace std;



int main() {

	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if ((i + j) % 2 == 0)cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}




Measured memory_bytes: 3104
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
    string ans = "No";
    int n;
    string s;
    cin >> n >> s;
    if(n%2==1) ans = "No";
    else{
        string s1 = s.substr(0,n/2);
        string s2 = s.substr(n/2,n/2);
        if(s1==s2) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, M;
bitset<300>b[300];
bool f[300];

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1)a = a*x%mod998;
		x = x*x%mod998;
		y /= 2;
	}
	return a;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			bool a;
			cin >> a;
			b[i][j] = a;
		}
	}
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			if (f[j])continue;
			if (b[j][i]) {
				f[j] = true;
				for (int k = 0; k < N; k++) {
					if (!f[k] && b[k][i]) {
						b[k] ^= b[j];
					}
				}
				break;
			}
		}
	}
	int c = 0;
	for (int i = 0; i < N; i++) {
		if (!f[i])c++;
	}
	cout << (pw(2, N + M - 1) + mod998 - pw(2, c + M - 1)) % mod998 << endl;
}

Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int main() {
	int m, d;
	cin >> m >> d;
	int ans = 0;
	for (int i = 1; i <= m; ++i) {
		for (int q = 10; q <= d; ++q) {
			if (q % 10 >= 2) {
				if (q / 10 >= 2) {
					if ((q % 10) * (q / 10) == i) {
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

int gcd(int a,int b){ return b ? gcd(b,a % b) : a; }
int lcm(int a,int b){ return a / gcd(a,b) * b; }

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	priority_queue<int> que;
	int a,b,c;
	cin >> a >> b >> c;
	que.emplace(a);
	que.emplace(b);
	que.emplace(c);
	int k;
	cin >> k;
	for(int i = k;k > 0;--k){
		int x = que.top();
		x *= 2;
		que.pop();
		que.emplace(x);
	}
	int sum = 0;
	while(!que.empty()){
		sum += que.top();
		que.pop();
	}
	cout << sum << '\n';
	return 0;	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }
  int ans = 0;
  rep(i, N-1) {
    if(p[i] == (i+1)) {
      ++ans;
      swap(p[i],p[i+1]);
    }
  }
  if(p[N-1] == N) {
    ++ans;
  }
  cout << ans << endl;
}

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

typedef long long ll;
#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

#define Q (1000000000 + 7)

ll modpow2(ll n, ll m){
    ll ret = 1;

    if( n == 1 ){
        return 2%m;
    }

    ll r = modpow2(n/2, m);
    if( n%2 == 1 ){
        return (r*r*2)%m;
    }else{
        return (r*r)%m;
    }
}

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll n, a, b;

    cin >> n >> a >> b;
    ll ans = 1;

    ans *= modpow2(n,Q);

    ans--; // must choose 1

    ll nCa = 1;
    ll nCa2 = 1;
    ll n1 = n;
    REP(i,a){
        nCa = (nCa * n1)%Q;
        n1--;
        nCa2 = (nCa2*(a-i))%Q;
    }
    nCa2 = modinv(nCa2, Q);
    ans = ans - (nCa2*nCa)%Q;

    ll nCb = 1;
    ll nCb2 = 1;
    ll n2 = n;
    REP(i,b){
        nCb = (nCb * n2)%Q;
        n2--;
        nCb2 = (nCb2*(b-i))%Q;
    }
    nCb2 = modinv(nCb2, Q);
    ans = ans - (nCb2*nCb)%Q;


    cout << (ans%Q+Q)%Q << endl;
}


Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << "(";
    os << P.first;
    os << " ";
    os << P.second;
    os << ")";

    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vector<pair<ll,ll>> A;
    ll a,b;
    REP(i,N) cin >> a >> b, A.emplace_back(a,b);
    sort(ALL(A));
    
    ll ans=INF;
    ll x,y;
    for(int i=0;i<N;i++){
        for(int j=i+K-1;j<N;j++){
            // cout << "i:" << i << " j:" << j << "-----------"<<endl;
            vector<pair<ll,ll>> B;
            for(int k=i;k<=j;k++){
                B.emplace_back(A[k].second,A[k].first);
            }
            sort(ALL(B));
            // cout << "::::" << (A[j].first-A[i].first)*(B[K-1].first-B[0].first) << endl;
            // debug(j-i-K)
            for(int l=0;l<=j-i-K+1;l++){
                int r = l+K-1;
                ll bot=INF,top=-INF;
                REP(idx,K){
                    chmin(bot, B[l+idx].second);
                    chmax(top, B[l+idx].second);
                }
                // debug(j)
                // debug(B)
                // debug((top-bot)*(B[l+K-1].first-B[l].first))
                // cout << l << " " << K << endl;
                // cout << top << " " << bot << " (" << B[l+K-1].first <<","<< l+K-1 << ") " << B[l].first << endl;
                chmin(ans, (top-bot)*(B[l+K-1].first-B[l].first));
            }
            // cout << B;
        }
    }
    // debug(INF)

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    N = int(input())

    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            x = math.gcd(i, j)
            for k in range(1, N + 1):
                ans += math.gcd(x, k)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int tmp;
		if(a > b) {
			tmp = a;
			a = b;
			b = tmp;
		}
		if(b > c) {
			tmp = b;
			b = c;
			c = tmp;
		}
		if(a > b) {
			tmp = a;
			a = b;
			b = tmp;
		}
		System.out.printf("%d %d %d\n", a, b , c);
	}

}



Measured memory_bytes: 26436
import sys

sys.setrecursionlimit(100000)

n = int(input())
edgeList0 = [list(map(int, input().split())) for i in range(n-1)]
cList = list(map(int,input().split()))
cList.sort(reverse=True)
print(sum(cList[1:]))
edgeList = []
for _ in range(n):
  edgeList.append([])
for i in edgeList0:
  edgeList[i[0]-1].append(i[1]-1)
  edgeList[i[1]-1].append(i[0]-1)

def edgefunc(j):
  numList.append((j,cList.pop(0)))
  if len(edgeList[j]) != 0:
    for k in edgeList[j]:
      edgeList[k].remove(j)
      edgefunc(k)

numList = []
edgefunc(0)
numList.sort()
answer2 = ""
for l in numList:
  answer2 += str(l[1]) + " "
print(answer2[:-1])

Measured memory_bytes: 16852
N , L = (map(int , input().split()))
aji = [i+L for i in range(N)]
ajisum = sum(aji)
mi = []
for i in aji:
    mi.append(abs(i))
if ajisum > 0:
    print(ajisum - min(mi))
else:
    print(ajisum + min(mi))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
 
int main()
{
    int n; 
    int money = 100000;
    cin >> n;
    for (int i = 0; i < n; i++) {
        money *= 1.05;
        if (money % 1000 != 0) {
            money += 1000 - money % 1000;
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

struct UnionFind
{
    vector<long long> d;
    UnionFind(long long n = 0) : d(n, -1)
    {
    }

    //root : -size, not root: root
    long long root(long long x){
        if(d[x] < 0){
            return x; 
        }
        return d[x] = root(d[x]);
    }

    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x == y){
            return false;
        }
        if(d[x] > d[y]){
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    long long size(long long x){
        return -d[root(x)];
    }

    bool issame(long long a, long long b){
        return root(a) == root(b);
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m;
    cin >> n >> m;

    vector<pair<ll,ll>> vec(m);

    rep(i,m){
        cin >> vec[i].first >> vec[i].second;
        vec[i].first--;
        vec[i].second--;
    }

    ll ans = 0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(j != i){
                uf.unite(vec[j].first, vec[j].second); 
            }         
        }

        if(uf.size(0) != n){
            ans++;
        }
        
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    int N, M, X;
cin >> N >> M >> X;
int C[N], A[N][M];
for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
        cin >> A[i][j];
    }
}

int ans = INT32_MAX;
for (int i = 1; i < (1<<N); i++) {
    int a[M]{};
    int v = 0;
    for (int j = 0; j < N; j++) {
        if (i & (1<<j)) {
            v += C[j];
            for (int k = 0; k < M; k++) {
                a[k] += A[j][k];
            }
        }
    }
    for (int j = 0; j < M; j++) {
       if (a[j] < X) break;
       if (j == M - 1) {
           ans = min(ans, v);
       }
    }
}
if (ans != INT32_MAX) {
    cout << ans << "\n";
} else {
    cout << "-1\n";
}
}


Measured memory_bytes: 3644
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<city> list = new ArrayList<>();
		for(int i = 1; i < M + 1; i++) {
			list.add(new city(i, sc.nextInt(), sc.nextLong()));
		}
		int[] count = new int[N + 1];
		for(int i = 1; i < N + 1; i++) {
			count[i] = 1;
		}
		list.sort(Comparator.comparing(city::getYear));
		for(city e : list) {
			e.setOrder(count[e.getPre()]);
			count[e.getPre()]++;
		}
		list.sort(Comparator.comparing(city::getNum));
		for(city e : list) {
			System.out.println(e.getId());
		}
	}

}

class city {
	private int num;
	private int pre;
	private long year;
	private int order;

	protected city(int num, int pre, long year) {
		super();
		this.num = num;
		this.pre = pre;
		this.year = year;
	}

	public String getId() {
		String p = String.valueOf(this.pre);
		String q = String.valueOf(this.order);
		while(p.length() < 6) {
			p = "0" + p;
		}
		while(q.length() < 6) {
			q = "0" + q;
		}
		return p + q;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getPre() {
		return pre;
	}

	public void setPre(int pre) {
		this.pre = pre;
	}

	public long getYear() {
		return year;
	}

	public void setYear(long year) {
		this.year = year;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int mx = 0;
    rep(i, n) mx = max(mx, a[i]);
    int l = 0, h = mx + 1;
    while (l+1<h) {
        ll c = (l + h) / 2, toc = c;
        rep(i, n) toc = a[i] - toc;
        if (toc < c) h = c;
        else l = c;
    }
    vi ans(n);
    rep(i, n) {
        ans[i] = l * 2;
        l = a[i] - l;
    }
    rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 3956
N = int(input())
h = list(map(int, input().split()))
DP = [float('inf')]*N
DP[0] = 0
DP[1] = abs(h[1]-h[0])
for i in range(N-1):
  DP[i+1] = abs(h[i+1]-h[i])+DP[i]
  if i > 0:
    DP[i+1] = min(abs(h[i+1]-h[i])+DP[i], abs(h[i+1]-h[i-1])+DP[i-1])
print(DP[N-1])


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli b,f,r,v,n;
  lli num[10][3][4] = {0};

  cin>>n;
  rep(i,n){
    cin>>b>>f>>r>>v;
    num[r-1][f-1][b-1] +=v;
  }

  rep(i,4){
    rep(j,3){
      rep(k,10){
	cout<<" "<<num[k][j][i];
      }
      cout<<endl;
    }
    if(i!=3)cout<<"####################"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3068
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let mut line = read_as_vec::<u32>();

    line.sort();
    line.reverse();

    println!("{}", line[0]*10+line[1]+line[2]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int x,ans;
  cin>>x;
  ans=(x/11)*2;
  if(x%11>0) ans+=1;
  if(x%11>=7) ans+=1;
  if(x<=11&&x>=7) ans=2;
  else if(x<=6) ans=1;
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d) cout << "Left" << endl;
    else if(a+b<c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 

int main() {
  float D, T, S;
  cin >> D >> T >> S;
  
  if(D/S <= T){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
     

}

Measured memory_bytes: 3716
from itertools import product


def main():
    N = int(input())
    result = 0
    numbers = ["3", "5", "7"]
    for i in range(3, len(str(N)) + 1):
        for p in product(numbers, repeat=i):
            flag = True
            tmp = "".join(p)
            for n in numbers:
                if n in tmp:
                    continue
                else:
                    flag = False
            if flag:
                if int(tmp) <= N:
                    result += 1
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
int  S[100005],T[100005];
using namespace std;
int main(int argc, char* argv[])
{
	string s,t;
	cin>>s;
	cin>>t;
	int i;
	S[0]=0;
	for (i=1;i<=s.length();i++){
		S[i] = S[i-1] + s[i-1]-'A'+1;
	}
	T[0]=0;
	for (i=1;i<=t.length();i++){
		T[i] = T[i-1] + t[i-1]-'A'+1;
	}
	int q;
	cin>>q;
	int a,b,c,d;
	long long A1,A2;
	for (i=0;i<q;i++){	
		cin>>a>>b>>c>>d;
		A1=S[b]-S[a-1];
		A2=T[d]-T[c-1];
		if (A1%3==A2%3){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:], i8[:])', cache=True)
def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, open(0).read().split())
    s = int64(s)
    x = int64(([*range(26)] * 15)[:d])
    M = func(s, x)
    while time() - start < 1.5:
        y = x.copy()
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i=randint(0, d - 16)
            j=randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    print(*x + 1, sep='\n')

main()

Measured memory_bytes: 107584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, ans = 0, ba = 0, a = 0, b = 0;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    rep(i, s.size() - 1) if(s[i] == 'A' && s[i + 1] == 'B') ans++;
    if(s[0] == 'B' && s.back() == 'A')
      ba++;
    else if(s[0] == 'B')
      b++;
    else if(s.back() == 'A')
      a++;
  }
  if(ba > 0) {
    ans += ba - 1;
    if(a > 0) {
      a--;
      ans++;
    }
    if(b > 0) {
      b--;
      ans++;
    }
  }
  ans += min(a, b);
  cout << ans << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vl a(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  vl y(n);
  ll a2n_1 = 0;
  for (int i = 1; i < n - 1; i += 2) {
    a2n_1 += a[i];
  }
  y[0] = sum - 2 * a2n_1;
  for (int i = 1; i < n; i++) {
    y[i] = 2 * a[i - 1] - y[i - 1];
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", y[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2944
n, m = map(int, input().split())
ps = []
for i in range(m):
    ps.append(list(map(str, input().split())))

ac = 0
wa = 0
AC = [0]*n
WA = [0]*n

for i in range(m):
    if ps[i][1] == "AC" and AC[int(ps[i][0]) - 1] == 0:
        # ac += 1
        AC[int(ps[i][0]) - 1] = 1
    
    if ps[i][1] == "WA" and AC[int(ps[i][0]) - 1] == 0:
        # wa += 1
        WA[int(ps[i][0]) - 1] += 1

for i in range(n):
    if AC[i] == 1:
        wa += WA[i]
ac = sum(AC)

print(str(ac) + " " + str(wa))


Measured memory_bytes: 70104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	int a,b,c;
	scanf("%i %i %i",&a,&b,&c);
	int ans=0;
	if(c) c--,ans++;
	int eat=min(b,c);
	ans+=eat*2;
	b-=eat;
	c-=eat;
	if(c>0)
	{
		eat=min(a,c);
		ans+=eat;
	}
	if(b>0) ans+=b;
	printf("%i\n",ans);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

int ans = 0;

void dfs(int pos, vector<vector<int>>& G, vector<bool>& visited){
    if(visited[pos]) return;
    visited[pos] = true;
    for(int v: G[pos]) dfs(v, G, visited);
    REP(i, G.size()){
        if(!visited[i]){
            visited[pos] = false;
            return;
        }
    }
    visited[pos] = false;
    ++ans;
    return;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> visited(N, false);
    dfs(0, G, visited);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		cs: Chars,
	}

	let mut ans = 0isize;
	for i in 0..4 {
		if cs[i] == '+' {
			ans += 1;
		}
		else {
			ans -= 1;
		}
	}

	println!("{}", ans);
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int x,y;
} a[200009];
int n,m,len,d[200009],b[200009],c[200009],v[200009],flag=1,num=0,ans[200009],k=0;
vector<int>w[200009];
map<pair<int,int>,int>ma;
int cmp(node a,node b)
{
    return a.x<b.x;
}
int dfs(int x)
{
    v[x]=1;
    int res=c[x];
    for(int i=0;i<w[x].size();i++)
    {
        if(!v[w[x][i]]&&dfs(w[x][i]))
        {
            res^=1;
            ans[k++]=ma[make_pair(x,w[x][i])];
        }
    }
    return res;
}
int main()
{
    memset(v,0,sizeof(v));
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%d%d",&a[i].x,&a[i].y),d[i]=a[i].x;
    sort(a+1,a+n+1,cmp),sort(d+1,d+n+1);
    a[n+1].y=0;
    a[0].y=0;
    for(int i=1; i<=n+1; i++)
        c[i]=a[i].y^a[i-1].y;
    for(int i=1; i<=m; i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        l=lower_bound(d+1,d+n+1,l)-d;
        r=upper_bound(d+1,d+n+1,r)-d;
        ma[make_pair(l,r)]=i,ma[make_pair(r,l)]=i;
        w[l].push_back(r),w[r].push_back(l);
    }
    for(int i=1; i<=n+1; i++)
    {
        if(!v[i]&&dfs(i))
        {
            printf("-1");
            return 0;
        }
    }
    sort(ans,ans+k);
    printf("%d\n",k);
    for(int i=0;i<k;i++)
        printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 47616
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;

const int INF = 100100100;

using ll = long long;

int main()
{

    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    ll a1 = a * pow(2, (k)) + b + c;
    ll b1 = b * pow(2, (k)) + a + c;
    ll c1 = c * pow(2, (k)) + b + a;

    cout << max(max(a1, b1), c1) << endl;

    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int k;
	cin >> k;

	ll ans = 0;
	for(int i = 1; i <= k; i++)
		for(int j = 1; j <= k; j++)
			for(int kk = 1; kk <= k; kk++){
		ans += gcd(i, gcd(j, kk));
	}

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;


int ar[ms]={0};

int main()
{
    idfc;
    ll x,y;
    cin>>x>>y;
    ll ans=min(x%y,y-(x%y));
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
#define ll long long int
#include<bits/stdc++.h>
int main(){
  ll a,b;
  cin>>a>>b;
  ll lim=b*10,i;
  for(i=0;i<10;i++){
    ll c=(lim+i)*(0.08);
    if(c==a)
      break;
  }
  if(i==10)
    cout<<"-1";
  else
    cout<<lim+i;
  
  return 0;
}

Measured memory_bytes: 256