akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }

        int v;
        int cnt = 0;
        int min;

        for (int i = 0; i < n-1; i++) {
            min = i;
            for (int j = i+1; j < n; j++) {
                if(arr[min] > arr[j]){
                    min = j;
                }
            }
            if(i != min){
                v = arr[i];
                arr[i] = arr[min];
                arr[min] = v;
                cnt++;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if(i != 0){System.out.print(" ");}
            System.out.print(arr[i]);
        }
        System.out.println("\n" + cnt);
    }
}


Measured memory_bytes: 26352
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
int main(){
  double res;
  int T, X;
  rd(T);
  rd(X);
  res = (double)T/X;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// {
//   int T, X;
//   double res;
//   rd(T,X);
//   res = (double)T/X;
//   wt(res);
// }


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse= True)

if A[-1] == 0:
    print(0)
    exit()
    
ans = 1

for i in A:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

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

int main()
{

    int a,b;
    cin >> a >> b;

    int out;
    if(a>9 || b>9){
        out = -1;
    }else{
        out = a*b;
    }

    cout << out << endl;

    return 0;
}


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

#define dfl(i,a,b)   for(int i=a;i>b;i--)
#define fl(i,a,b)    for(int i=a;i<b;i++)
#define ll           long long
#define ld           long double
#define endl         '\n'
#define pb           push_back
#define ff           first
#define ss           second
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define vi           vector<int>
#define vll          vector<long long>
#define all(x)       x.begin(),x.end()
#define mod          1000000007 
#define mx           1000005
#define mii          map<int,int>
#define mumii        multimap<int,int> 
#define mx2          65
#define inf          4e18
#define fast         ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gt           greater<int>()
#define debug(x)     cout<<x<<endl;
#define scan(a,n)    fl(i,0,n)cin>>a[i];

//The ASCII value of the lowercase alphabet is from 97 to 122.
//The ASCII value of the uppercase alphabet is from 65 to 90.

bool isPrime(int n) 
{  
    if (n <= 1) 
        return false;
        
    if (n <= 3) 
        return true; 
 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

void solve()
{
     int x=0;
     string n;
     cin>>n;
     
     fl(i,0,n.size())
     x+=(n[i]-'0');
     
     if(x%9)
     cout<<"No";
     
     else
     cout<<"Yes";
     
}
int main()
{
	fast;
	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

using namespace std;
map<string,int>mp;
int main(){
	int n;
	cin>>n;
	int maxn=0;
	vector<string>v;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
		if(mp[s]>maxn){
			maxn=mp[s];
			v.clear();
			v.push_back(s);
		}
		else if(mp[s]==maxn){
			v.push_back(s);
		}
	}
    sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)cout<<v[i]<<endl; 
	return 0;
}

Measured memory_bytes: 26736
package main

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

func main() {
	N, C := ReadInt(), ReadInt()
	x := make([]int, N+1)
	v := make([]int, N+1)
	vSum := make([]int, N+1)
	for i := 1; i <= N; i++ {
		x[i], v[i] = ReadInt(), ReadInt()
		vSum[i] = vSum[i-1] + v[i]
	}

	// s1[i] = 時計回りにi個以下を食べる場合の最適値
	s1 := make([]int, N+1)
	for i := 1; i <= N; i++ {
		s1[i] = Max(s1[i-1], vSum[i]-x[i])
	}
	// s2[i] = 反時計回りにi個以下を食べる場合の最適値
	s2 := make([]int, N+1)
	for i := 1; i <= N; i++ {
		idx := N + 1 - i
		s2[i] = Max(s2[i-1], vSum[N]-vSum[idx-1]-(C-x[idx]))
	}

	ans := Max(Max(s1...), Max(s2...))
	for i := 1; i < N; i++ {
		// 時計回りにi個食べてからスタートに戻って、反時計周りにN-i個食べる場合の最適値
		localAns := vSum[i] - 2*x[i] + s2[N-i]
		ans = Max(ans, localAns)
	}
	for i := 1; i < N; i++ {
		// 反時計回りにi個食べてからスタートに戻って、時計回りにN-i個食べる場合の最適値
		idx := N + 1 - i
		localAns := vSum[N] - vSum[idx-1] - 2*(C-x[idx]) + s1[N-i]
		ans = Max(ans, localAns)
	}

	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 8500
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	eFOR(i, 1, 9) {
		if (N%i == 0) {
			if (N / i <= 9) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;

	return 0;
}



Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	fmt.Println(N / 3)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
flag = False
for i in range(n-2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        flag = True
if flag:
    print("Yes")
else:
    print("No")

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

int main() {
	for (int i=1;i<=9;++i) {
		for (int j=1;j<=9;++j) {
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
}

Measured memory_bytes: 1096
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int H = sc.nextInt();
				int W = sc.nextInt();
				if(H == 0 && W == 0) break;
				for(int i=0; i < H; i++) {
					for(int j=0; j < W; j++) {
						System.out.print((i+j)%2==0?"#":".");
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}



Measured memory_bytes: 34748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){

  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  int flag=0;
  if(b-a>k){
    flag++;
  }
  if(c-a>k){
    flag++;
  }
  if(d-a>k){
    flag++;
  }
  if(e-a>k){
    flag++;
  }
  if(c-b>k){
    flag++;
  }
  if(d-b>k){
    flag++;
  }
  if(e-b>k){
    flag++;
  }
  if(d-c>k){
    flag++;
  }
  if(e-d>k){
    flag++;
  }
  if(e-c>k){
    flag++;
  }

  if(flag==0){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
#define MAX 2020
const ll MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll N,K;cin>>N>>K;
  COMinit();
  ll ans=0;
  //赤の間からi箇所選ぶ
  for(ll i=1;i<=K;++i){
    cout << COM(N-K+1,i)*COM(K-1,i-1)%MOD << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int d[100005];
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	memset(d,0,sizeof(d));
	for(int i=1;i<=c;i++){
		int x;
		cin>>x;
		d[x]++; 
	}
	for(int i=1;i<=a;i++){
		if(b-c+d[i]<=0)
		cout<<"No"<<endl;
		else
		cout<<"Yes"<<endl;
	}
	
	
	
	
	return 0;
}

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

int main() {

  char c;
  cin >> c;
  
  if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
  	cout << "vowel" << endl;
  }
  else{
  	cout << "consonant" << endl;
  }
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;
		vector<int> a( N+1 );
		for( int i = 1; i <= N; ++i ) { cin >> a[i]; }

		int ans = 0;
		for( int i = 1; i <= N; ++i ) {
			ans += (i&1) && (a[i]&1);
		}
		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin>>h[i];
	}
	int ans=0;
	for (int i = 0; i < n; i++) {
		if (h[i]>=k) {
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <deque>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)

using namespace std;

int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


int gcd(int i,int j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

int SaB(){

	string s;

	cin >> s;

	if(s.find("A") != -1 && s.find("B") != -1)
		printf("Yes");
	else
		printf("No");

	return 0;

}

int CB(){
	LL N,A,B;

	cin >> N >> A >> B;

	LL answer = A * (N/(A+B));

	if(N%(A+B) >= A)
		answer += A;
	else
		answer += N%(A+B);

	loutp(answer);

	return 0;
}

int TI(){
	LL A,B;

	cin >> A >> B;

	double minx = max(100.0*A/8.0,100.0*B/10.0);
	double maxx = min(100.0*(A+1)/8.0, 100.0*(B+1)/10.0);

	for(LL x = (LL)minx; x <= maxx; x++){
		if((8*x)/100 == A && (10*x)/100 == B){
			loutp(x);
			return 0;
		}

	}

	loutp(-1);

	return 0;
}

struct Query{
	LL T = 0;
	LL F = 0;
	char C;
};

int SF(){


	deque<char> S;
	LL Q;
	string s;

	cin >> s >> Q;

	rep(i , 0 ,s.length())
		S.push_back(s[i]);


	Query query[Q];

//	rep(i,0,Q){
//		cin >> query[i].T;
//
//		if(query[i].T == 1)
//			reverse(S.begin(), S.end());
//		if(query[i].T == 2){
//			cin >> query[i].F >> query[i].C;
//			if(query[i].F == 1)
//				S = query[i].C + S;
//			if(query[i].F == 2)
//				S = S + query[i].C;
//		}
//	}

	rep(i,0,Q){
			cin >> query[i].T;
			if(query[i].T == 2){
				cin >> query[i].F >> query[i].C;
			}
	}

	int flug = 0;

	rep(i,0,Q){

		if(query[i].T == 1)
			flug = 1 - flug;

		if(query[i].T == 2){
			if((query[i].F == 1 && flug == 0) ||
					(query[i].F == 2 && flug == 1)){
				S.push_front(query[i].C);
			}else{
				S.push_back(query[i].C);
			}
		}
	}
	while(!S.empty()){
		if(flug == 1){
			cout << S.back();
			S.pop_back();
		}
		else{
			cout << S.front();
			S.pop_front();
		}

	}
	cout << endl;

	return 0;


}

signed main() {

	// SaB();
	//CB();
	//TI();
	SF();
	return 0;
}



Measured memory_bytes: 5632
if __name__ == '__main__':
    N = int(input())
    D,X = map(int,input().split())
    A_L = [int(input()) for i in range(N)]
    eat_L = [int((D-1)/A_L[k])+1 for k in range(N)]
    
    print(sum(eat_L)+X)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  char s[1000];
  int i=0;
  
  scanf("%s",s);
  
  while(s[i] != NULL)
    i++;
  
  if(s[i-1] == 's')
    printf("%ses",s);
  else
    printf("%ss",s);
  
  return 0;
}


Measured memory_bytes: 1732
from collections import defaultdict

def prime_factors(n):
    d = defaultdict(int)
    while n%2 == 0:
        d[2] += 1
        n //= 2
    i = 3
    while i*i <= n:
        while n%i == 0:
            d[i] += 1
            n //= i
        i += 2
    if n > 2:
        d[n] += 1
    return d

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
G = defaultdict(int)
for a in A:
    pf = prime_factors(a)
    for k,v in pf.items():
        G[k] = max(G[k], v)
lcm = 1
for k,v in G.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD
ans = 0
for a in A:
    ans += lcm * pow(a, MOD-2, MOD) % MOD
    ans %= MOD
print(ans)

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

fullstr = raw_input()

sf = ['','','']

sf[0] = fullstr[0]
num = 1

for i in range(len(fullstr)):
  if (fullstr[i] == ' '):
    sf[num] = fullstr[i+1]
    num += 1

print '%s%s%s' % (sf[0].upper(), sf[1].upper(), sf[2].upper())


Measured memory_bytes: 2568
s = gets.chomp.to_i

h = Hash.new(0)

a = s
i = 0
h[a] += 1

while 1
  if a.odd?
    a = 3*a + 1
  else
    a = a/2
  end
  h[a] += 1
  i += 1

  if h[a] == 2
    p i+1
    exit
  end
end


Measured memory_bytes: 1788
#include <stdio.h>

int main() {

  int v, i, j, n, a[1000];
  
  scanf("%d", &n);
  for(i = 0;i < n; i++) scanf("%d", &a[i]);

  for(i = 1;i <= n;i++) {
    for(j = 0;j < n; j++) {
      printf("%d",a[j]);
      if(j + 1 != n) printf(" ");
    }
    printf("\n");
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
  }

  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 3e5 + 5;
ll sum[maxn<<2];
int lz[maxn<<2];
ll p[maxn];
ll p1[maxn][10];
void pull(int x,int l,int r,int mid) {
    sum[x] = (sum[x<<1] * p[r - mid] + sum[x<<1|1])% mod;
}
void push(int x,int l,int r,int mid) {
    if (!lz[x]) {
        return;
    }
    lz[x<<1] = lz[x<<1|1] = lz[x];
    sum[x<<1] = p1[mid - l + 1][lz[x]];
    sum[x<<1|1] = p1[r - mid][lz[x]];
    lz[x] = 0;
}
void update(int x,int l,int r,int ql,int qr,int v) {
    //cout << x <<' '<<l<<' '<<r<<endl;
    if (ql <= l && qr >= r) {
        sum[x] = p1[r - l + 1][v];
        lz[x] = v;
        return;
    }
    int mid = (l + r) >> 1;
    push(x,l,r,mid);
    if (ql <= mid) {
        update(x<<1,l,mid,ql,qr,v);
    }
    if (qr > mid) {
        update(x<<1|1,mid+1,r,ql,qr,v);
    }
    pull(x,l,r,mid);
} 

void go() {
    int n, k;
    cin >> n >> k;
    p[0] = 1;
    f1(n) {
        p[i] = p[i - 1] * 10 % mod;
    }
    f1(9) {
        fr(j,1,n+1) {
            p1[j][i] = (p1[j - 1][i] * 10 + i) % mod;
        }
    }
    update(1,1,n,1,n,1);
    f(k) {
        int l, r, d;
        cin >> l >> r >> d;
        update(1,1,n,l,r,d);
        cout << sum[1] << '\n';
    }
    
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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 dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
ll N, A, B, C;
Vi L;

ll dfs(ll cur, ll a, ll b, ll c){
   if(cur == N){
      return (min({a, b, c}) > 0ll) ? abs(a - A) + abs(b - B) + abs(c - C) - 30 : INF;
   }
   else{
      ll ret0 = dfs(cur + 1, a, b, c);
      ll ret1 = dfs(cur + 1, a + L[cur], b, c) + 10;
      ll ret2 = dfs(cur + 1, a, b + L[cur], c) + 10;
      ll ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10;
      return min({ret0, ret1, ret2, ret3});
   }
}

int main(){
   cin >> N >> A >> B >> C;
   REP(i, N){
      ll li ; cin >> li;
      L.pb(li);
   }
   cout << dfs(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
const double E = 1e-7;
const ll INF = 1e17;
#define forn(i, s, f) for (int i = s; i < f; ++i)
#define ft first                                                 
#define sec second
#define fora(i, n) for (auto i : n)
#define sz(a) (int)(a).size()
#define sort_(a) sort(a.begin(), a.end())
#define pb push_back
#define mp make_pair
#define rsort_(a) sort(a.begin(), a.end()); reverse(a.begin(), a.end())
#define fast_ cin.tie(0), ios_base::sync_with_stdio(false)
// ____________________________________________________________
#define cina(a) forn(i,0,sz(a)) cin >> a[i]
#define cinpr(a) cin >> a.ft >> a.sec 
//--------------------------------------------------------------

const int MAXN = 3 * 1e5;


int main() {
    int a, b, c; cin >> a >> b >> c;
    
    swap(a,b); swap(a,c);    
    cout << a<<  " "<<  b << " "<< c << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0; i<=(int)s.size()-(int)t.size(); i++){
        int now = 0;
        for(int j=0; j<(int)t.size(); j++){
            if(s[i+j]==t[j])
                now++;
        }
        ans = max(now,ans);
    }
    cout << (int)t.size()-ans << endl;
    return 0;
}

Measured memory_bytes: 3628
until (w = gets.to_i) == -1
  tmp = case w
  when 0..10
    0
  when 11..20
    (w - 10) * 125
  when 21..30
    1250 + (w - 20) * 140
  else
    2650 + (w - 30) * 160
  end
  
  puts 3130 - tmp
end

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

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

    pre_t, pre_x, pre_y = 0, 0, 0
    for i in range(N):
        t, x, y = list(map(int, input().split()))
        diff = abs(x-pre_x) + abs(y-pre_y)
        amari = (t-pre_t) - diff
        if amari < 0:
            # 遠すぎて到達不可能
            print("No")
            exit()
        elif amari == 0:
            continue
        elif amari%2 == 0:
            # 余りが偶数なら目的地に戻れる
            continue
        else:
            print("No")
            exit()
    print("Yes")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        Console.WriteLine(Math.Pow(N,3));
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int h,w,n;
    cin>>h>>w>>n;
    int sr,sc;
    cin>>sr>>sc;
    string s,t;
    cin>>s>>t;
    int du=sr,dd=h-sr+1,dl=sc,dr=w-sc+1;
    rep(i,n){
        int cnt=0;
        if(s[i]=='U'){
            while(i<n){
                if(s[i]=='U')++cnt;
                if(cnt==du){
                    cout<<"NO\n";
                    return;
                }
                if(t[i]=='D')--cnt;
                ++i;
            }
        }
        if(t[i]=='D')du=min(du+1,h);
    }

    rep(i,n){
        int cnt=0;
        if(s[i]=='D'){
            while(i<n){
                if(s[i]=='D')++cnt;
                if(cnt==dd){
                    cout<<"NO\n";
                    return;
                }
                if(t[i]=='U')--cnt;
                ++i;
            }
        }
        if(t[i]=='U')dd=min(dd+1,h);
    }

    rep(i,n){
        int cnt=0;
        if(s[i]=='L'){
            while(i<n){
                if(s[i]=='L')++cnt;
                if(cnt==dl){
                    cout<<"NO\n";
                    return;
                }
                if(t[i]=='R')--cnt;
                ++i;
            }
        }
        if(t[i]=='R')dl=min(dl+1,w);
    }

    rep(i,n){
        int cnt=0;
        if(s[i]=='R'){
            while(i<n){
                if(s[i]=='R')++cnt;
                if(cnt==dr){
                    cout<<"NO\n";
                    return;
                }
                if(t[i]=='L')--cnt;
                ++i;
            }
        }
        if(t[i]=='L')dr=min(dr+1,w);
    }

    cout<<"YES\n";
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    numbers = list(map(int, list(input())))
    result = '=7'
    a = numbers[0]
    b = numbers[1]
    c = numbers[2]
    d = numbers[3]
    total = 7

    # FIME: More smartly.
    if a + b + c + d == total:
        print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + result)
    elif a + b + c - d == total:
        print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + result)
    elif a + b - c + d == total:
        print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + result)
    elif a + b - c - d == total:
        print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + result)
    elif a - b + c + d == total:
        print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + result)
    elif a - b + c - d == total:
        print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + result)
    elif a - b - c + d == total:
        print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + result)
    elif a - b - c - d == total:
        print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + result)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int nks[21][11][156];

void br(){
	int s, t;
	for(int i=1; i<=20; i++){
		for(int j=0; j < (1<<i);j++){
			s = 0;
			t = 0;
			for(int k=0; k < i;k++){
				if(j&(1<<k)){
					s+=(k+1);
					t++;
				}
			}
			if(s<=155 && t<=10) nks[i][t][s]++;
		}
	}
}

int main(){
	int i, j, n, k, s;
	br();
	while(1){
		cin >> n >> k >> s;
		if(!n)break;
		cout << nks[n][k][s] << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
import copy
N = int(input())
C = input().split()
D = copy.copy(C)
for i in range(N):
    for j in range(i+1,N):
        k = N-j+i
        if int(C[k][1]) < int(C[k-1][1]):
            dummy = C[k]
            C[k] = C[k-1]
            C[k-1] = dummy

for i in range(N-1):
    print(f"{C[i]}",end =" ")
print(f"{C[N-1]}\nStable")
for i in range(N):
    minj = i
    for j in range(i,N):
        if int(D[j][1]) < int(D[minj][1]):
            minj = j
    dummy = D[i]
    D[i] = D[minj]
    D[minj] = dummy
for i in range(N-1):
    print(f"{D[i]}",end =" ")
flag = 0
for i in range(N):
    if C[i] != D[i]:
        flag = 1
        print(f"{D[N-1]}\nNot stable")
        break
if flag == 0:
    print(f"{D[N-1]}\nStable")


Measured memory_bytes: 6356
#include<iostream>
using namespace std;
int s[400005];
int freq[4005][3]; //0:R 1:G 2:B
string A;
int main(){
  int N;
  cin>>N;
  cin>>A;
  for(int i=0; i<N; i++){
    if(A[i]=='R') s[i]=0;
    else if(A[i]=='G') s[i]=1;
    else s[i]=2;
  }
  for(int i=0; i<N; i++){
    freq[i+1][0]=freq[i][0];
    freq[i+1][1]=freq[i][1];
    freq[i+1][2]=freq[i][2];
    freq[i+1][s[i]]++;
  }
  long long int res=0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(s[i]==s[j]) continue;
      int cur_color;
      if(s[i]==0){
        if(s[j]==1) cur_color=2;
        else cur_color=1;
      }
      else if(s[i]==1){
        if(s[j]==0) cur_color=2;
        else cur_color=0;
      }
      else if(s[i]==2){
        if(s[j]==0) cur_color=1;
        else cur_color=0;
      }
      res+=freq[N][cur_color]-freq[j+1][cur_color];
      if(j+j-i<N && s[j+(j-i)]!=s[i] && s[j+(j-i)]!=s[j]) res--;
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

unordered_map<ll, bool> ma;
unordered_map<ll,bool> visited;
int dx[3] = {-1,0,1};
int dy[3] = {-1,0,1};
int h, w;
const ll MOD = 1e9 + 7;

ll hsh(ii x)
{
	ll r = MOD*ll(x.fi)+ll(x.se);
	return r;
}

bool isvalid(ii x)
{
	if(x.fi >= 2 && x.fi <= h - 1 && x.se >= 2 && x.se <= w - 1) return true;
	return false;
}

ll ans[10];

int test(ii x)
{
	int cnt = 0;
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(ma[hsh(ii(dx[i]+x.fi, dy[j]+x.se))]) cnt++;
		}
	}
	return cnt;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>h>>w>>n;
	vector<ii> color;
	for(int i = 0; i < n; i++)
	{
		int u, v; cin >> u >> v;
		ma[hsh(ii(u,v))] = true; color.pb(ii(u,v));
	}
	
	ans[0] = ll(h-2)*ll(w-2);
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				ii tmp = ii(color[i].fi+dx[j], color[i].se+dy[k]);
				ll h = hsh(tmp);
				//cout << "TMP : " << tmp.fi << ' ' << tmp.se << ' ' << test(tmp) << ' ' << isvalid(tmp) << ' ' << visited[tmp] << '\n';
				if(isvalid(tmp) && !visited[h])
				{
					int q = test(tmp);
					ans[q]++;
					visited[h] = true;
				}
			}
		}
	}
	for(int i = 1; i <= 9; i++)
	{
		ans[0] -= ans[i];
	}
	for(int i = 0; i <= 9; i++)
	{
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 151240
def resolve():
    X, K, D = map(int, input().split())
    X = abs(X)
    q, mod = divmod(X, D)
    # K>qのとき一番小さくなる。
    # D/2より小さい時は引いて絶対値が最小
    if q>=K:
        # 届かないとき。
        answer = X - K*D
    else:
        # 届くとき
        positive_abs_min = X-q*D
        negative_abs_min = D - positive_abs_min
        # positive_abs_minのあとに偶数回残っていればpositive_abs_min
        rest_k = K - q
        if rest_k%2 == 0:
            answer = positive_abs_min
        else:
            answer = negative_abs_min
    print(answer)
resolve()

Measured memory_bytes: 61728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = 0;

        for (int i = n; i > 0; i--) {
            int a = sc.nextInt();
            s = s + a;
        }
        System.out.println(s - n);

    }
}



Measured memory_bytes: 27848
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  int N;
  cin >> N;
  ll A[N];
  ll cum[N];
  ll sum = 0;
  rep(i,N) {
	cin >> A[i];
	A[i] %= mod;
  }
  rep(i,N-1) {
	sum += A[N-i-1];
	sum %= mod;
	cum[N-i-2] = sum;
  }
  ll ans = 0;
  rep(i,N-1) {
	ans += A[i] * cum[i];
	ans %= mod;
  }
  cout << ans << endl;
}



Measured memory_bytes: 6320
H = int(input())
W = int(input())
N = int(input())
h_num = 0
if N % H == 0:
    h_num = N // H
else:
    h_num = N // H + 1
w_num = 0
if N % W == 0:
    w_num = N // W
else:
    w_num = N // W + 1
print(min(h_num, w_num))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long 
#define pi 3.1415926536
using namespace std;
const ll N=1e5+5;
void solve()
{ll n,k,m,l,h,r,x,z,w,mini,maxi=INT_MAX,prev;
  cin>>n>>k;
  if(k>=n)
  {
  	cout<<min(n,k-n);
  	
  }
  else
  {
  	n=n%k;
  	cout<<min(n,k-n);
  }
}
  
int main()
{
  fast
  //fact();
  //chk();
ll t=1;
//cin>>t;
//SieveOfEratosthenes();
//cout<<"ok";
while(t--)
{ //cout<<"ok";

solve();
 //cout<<ma<<endl;
}
return 0;}

Measured memory_bytes: 256
#include"bits/stdc++.h" 
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
vector<int>u;
vector<int>w;
vector<int>::iterator it;
priority_queue<int>pq;
const int N=1e5+10;
/*--------------------------hbp16@hbp16-Inspiron-3543:-$------------------------------*/
int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;

	double x,y;
	x = ceil(a/0.08);
	y = ceil(b/0.1);

	if(x > y)
	{
		y = x;
	}
	else
	{
		x = y;
	}

	if((int)(x*0.08) == a and (int)(y*0.1) == b)
	{
		cout<<x;
		return 0;
	}
	cout<<"-1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    int ans = 0;
    char c = 'A';
    
    rep(i,s.size())
    {
        if(s[i]<=c) ++ans;
        c = s[i];
    }

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

Measured memory_bytes: 3176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main() {
        Scanner cin = new Scanner();
        int N = cin.Int();
        var A = cin.ArrayLong(N);

        if(N % 2 != 0) {
            long[] cnt = new long[N];
            foreach (var x in A) {
                cnt[x]++;
            }

            bool flag = true;
            if (cnt[0] != 1) flag = false;
            for (int i = 2; i <= N - 1; i += 2) {
                if (cnt[i] != 2) flag = false;
            }

            if (flag) {
                long ans = 1;
                for(int i = 1; i <= N / 2; i++) {
                    ans = ans * 2 % 1000000007;
                }
                Console.WriteLine(ans);
            }
            else {
                Console.WriteLine(0);
            }
        }
        else {
            long[] cnt = new long[N];
            foreach (var x in A) {
                cnt[x]++;
            }

            bool flag = true;
            for(int i = 1; i <= N - 1; i += 2) {
                if (cnt[i] != 2) flag = false;
            }

            if (flag) {
                long ans = 1;
                for (int i = 1; i <= N / 2; i++) {
                    ans = ans * 2 % 1000000007;
                }
                Console.WriteLine(ans);
            }
            else {
                Console.WriteLine(0);
            }
        }
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 20064
#include<iostream>
#include<algorithm>
using namespace std;
long long N,X;
long long dp[55],sum=0;
long long len[55];
int main(){
    int a[7]={0,0,1,2,3,3,3};
    dp[1]=3;len[1]=5;
    for(int i=2;i<=50;i++)
        dp[i]=dp[i-1]*2+1;
    for(int i=2;i<=50;i++)
        len[i]=len[i-1]*2+3;
    scanf("%lld %lld",&N,&X);
    while(1){
        if(N==1||X==0)
            break;
        long long temp=len[N]/2;
        if(X*2>len[N]){
            bool f=0;
            if(X==len[N])
                f=1;
            sum+=dp[N-1]+1;
            X-=len[N]/2+1;
            X-=f;
        }
        else
            X--;
        N--;

    }
    if(N==1){
        sum+=a[X];
    }
    printf("%lld\n",sum);


}


Measured memory_bytes: 256
def main():
    q, h, s, d = map(int, input().split())
    n = int(input())

    two = [8 * q, 4 * h, 2 * s, d]
    two.sort()
    one = [4 * q, 2 * h, s]
    one.sort()

    t, o = divmod(n, 2)
    ans = t * two[0] + o * one[0]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int dp[105][105];
int a[105][105];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin >> c;
			if(c=='#') a[i][j]=1;
		}
	}
	dp[1][1]=a[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i!=1||j!=1) dp[i][j]=1e9;
			if(i-1) dp[i][j]=dp[i-1][j]+(a[i][j]&&!a[i-1][j]);
			if(j-1) dp[i][j]=min(dp[i][j],dp[i][j-1]+(a[i][j]&&!a[i][j-1]));
		}
	}
	cout << dp[n][m];
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  sort(all(a));
  sort(rall(f));

  ll ok = 1LL << 60;
  ll ng = -1;

  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    bool flg = true;
    ll k = K;
    rep(i, N) {
      ll n = ceil((long double)(f[i] * a[i] - mid) / f[i]);
      if (n >= 0) k -= n;
      if (k < 0) flg = false;
    }

    (flg ? ok : ng) = mid;
  }

  cout << ok << endl;
}


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

const int N = 5e5 + 10;
char s[N];
int n, q;

struct Node{
	int l, r;
	int v;
}t[26][N << 2];

void pushup(Node tr[], int u) {
	tr[u].v = tr[u << 1].v + tr[u << 1 | 1].v;
}

void build(int i, Node tr[], int u, int l, int r) {
	tr[u] = {l, r, 0};
	if(l == r) {
		tr[u].v = (s[l] - 'a' == i);
		return ;
	} 
	
	int mid = l + r >> 1;
	build(i, tr, u << 1, l, mid), build(i, tr, u << 1 | 1, mid + 1, r);
	pushup(tr, u);
}

void modify(int i, Node tr[], int u, int x, int d) {
	if(tr[u].l == x && tr[u].r == x) {
		tr[u].v = d;
		return ;
	}
	
	int mid = tr[u].l + tr[u].r >> 1;
	if(x <= mid) modify(i, tr, u << 1, x, d);
	else modify(i, tr, u << 1 | 1, x, d);
	pushup(tr, u);
} 

int query(int i, Node tr[], int u, int l, int r) {
	if(l <= tr[u].l && r >= tr[u].r) return tr[u].v;
	
	int mid = tr[u].l + tr[u].r >> 1;
	
	int res = 0;
	if(l <= mid) res += query(i, tr, u << 1, l, r);
	if(r > mid) res += query(i, tr, u << 1 | 1, l, r);
	
	return res;
}

int main()
{
	scanf("%d%s%d", &n, s + 1, &q);
	for(int i = 0; i < 26; i++) build(i, t[i], 1, 1, n);
	
	while(q--) {
		int op, x, y; char ch[2];
		scanf("%d", &op);
		
		if(op == 1) {
			scanf("%d%s", &x, ch);
			char c2 = s[x];
			
			if(c2 == ch[0]) continue;
			else {
				s[x] = ch[0];
				int t1 = ch[0] - 'a';
				int t2 = c2 - 'a';
				modify(t1, t[t1], 1, x, 1);
				modify(t2, t[t2], 1, x, 0);
			}	
		}
		
		else {
			
			//printf("debug:%s\n", s + 1);
			
			scanf("%d%d", &x, &y);
			int ans = 0;
			for(int i = 0; i < 26; i++) { 
				//if(i < 5) printf("%c:%d\n", i + 'a', query(i, t[i], 1, x, y)); 
				if(query(i, t[i], 1, x, y)) ans++;
			} 
			//printf("b:%d\n", query(1, t[1], 1, 1, 1));
			
			printf("%d\n", ans);
		}
	}
	
	return 0;
}

Measured memory_bytes: 373504
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int pre[n+5];
    pre[0]=a[0];
    int suf[n+5];
    suf[n-1]=a[n-1];
    for(int i=1;i<n;i++){
        pre[i]=a[i]+pre[i-1];
    }
    for(int i=n-2;i>=0;i--){
        suf[i]=a[i]+suf[i+1];
    }
    int ans=1e18;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=min(ans,abs(a[i]-suf[i+1]));
        }else if(i==n-1){
            ans=min(ans,abs(a[i]-pre[i-1]));
        }else{
            ans=min(ans,abs(pre[i]-suf[i+1]));
        }
    }
    cout<<ans<<endl;
    
    return 0;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int N,W;
P data[101];

int dp[110][10010];
// DP配列のサイズミスってただけか…！？

int main(){
	cin>>N>>W;
	for(int i=1;i<=N;i++){
		cin>> data[i].first >> data[i].second;
	}

	memset(dp,0,sizeof(dp));

	for(int i=1;i<=N;i++){
		int val=data[i].first, weight=data[i].second;

		for(int j=1;j<=W;j++){

			if(j-weight>=0){
				dp[i][j]=max(dp[i-1][j], dp[i-1][j-weight]+val);
			}else dp[i][j]=dp[i-1][j];
		}
	}

	cout<<dp[N][W]<<endl;
	return 0;
}



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

int main()
{
    int N;
    char S[10001];
    scanf("%d %s", &N, S);
    int len=strlen(S);
    for (int i=0; i<len; i++ ) {
        int temp;
        temp=S[i]-'A';
        temp=(temp+N)%26;
        putchar('A'+temp);
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<string.h>
typedef long long int ll;
using namespace std;
int main()
{
    ll s,n,lp=1,m1,n1,n2,nl,m,i,j,k,sum;
    cin >> n >> k >> s;
    for (int i = 1; i <= k; ++i)
        {
             cout << s << ' ';
    }    if (s == 1e9) {
            for (int i = 1; i <= n - k; ++i)
        cout << "1" << ' ';
         }
          else
            {
                  for (int i = 1; i <= n - k; ++i)
                     cout << s + 1 << ' ';
          }


     return 0;
}


Measured memory_bytes: 1280
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD


K = int(input())
S = input()
MOD = 10 ** 9 + 7

N = K + len(S)
M = len(S)
com = comb(N + 1, MOD)

p25 = [1]
p26 = [1]
for i in range(K + 1):
  p25.append(p25[-1] * 25 % MOD)
  p26.append(p26[-1] * 26 % MOD)

ans = 0

for i in range(K + 1):
  ans = (ans + p25[i] * com.com(M + i  - 1, M - 1) * p26[K - i]) % MOD

print(ans)


Measured memory_bytes: 244160