akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		// ????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		// ??±???????????? s
		String s = sc.nextLine();
		//??±???????????? ???
		String p = sc.nextLine();
		//
		s = s+s;
		if(s.indexOf(p) != -1){
			//????????°?????§??????
			System.out.println("Yes");
		}else{
			//????????°?????§?????????
			System.out.println("No");
		}
	}
}

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

int main(){
    int n;
    cin>>n;

    vector<int> t(n);
    for(int i=0; i<n; i++){
        cin>>t[i];
    }

    int m;
    cin>>m;

    vector<int> p(m),x(m);
    for(int i=0; i<m; i++){
        cin>>p[i]>>x[i];
    }

    for(int i=0; i<m; i++){
        int sum=0;
        for(int j=0; j<n; j++){
            if(j==p[i]-1){
                sum+=x[i];
                continue;
            }
            sum+=t[j];
        }

        cout<<sum<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    int d,n;
    cin>>d>>n;
    if(n==100){
	if(d==0)cout<<"101"<<endl;
	if(d==1)cout<<"10100"<<endl;
	if(d==2)cout<<"1010000"<<endl;
    }
    else{
    cout<<n;
    for(int i=0;i<2*d;i++)cout<<"0";
    cout<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  if ( N % 111 == 0 )
    cout << N << endl;
  else {
    for ( int i = 0; i < 9; i++ ) {
      int sub = N - 111 * i;
      if ( sub > 0 && sub < 111 ) {
        cout << 111 * ( i + 1 ) << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	
	string s;
	cin>>s;
	sort(all(s));
	if(s[0] == s[1] && s[2] == s[3] && s[1]!=s[2]){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>


int main (void) {

  int N; std::cin >> N;
  std::set<int> s;
  for(int i=0; i<N; i++){
    int a; std::cin >> a;
    s.insert(a);
  }

  std::cout << s.size() << std::endl;

  return 0;
}


Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        n: usize,
    };
    match n % 10{
        0|1|6|8 => println!("pon"),
        3 => println!("bon"),
        _ => println!("hon"),
}
}


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

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 4328
from itertools import product

N,*T = map(int,input().split())
L = [int(input()) for i in range(N)]
ans = 3000

for x in product([0,1,2,3], repeat=N):
    cost = 0
    l = [0]*4
    for i,v in enumerate(x):
        l[v] += L[i]
        if v<3:
            cost += 10

    if 0 in l[:3]:
        continue
    cost -= 30
    for i in range(3):
        cost += abs(l[i]-T[i])
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))



an = [0]
for i in range(n):
    an.append(a[i])       
an.append(0)

ifsums = 0
nal = []

for i in range(0,n+1):
    ifsums = ifsums + abs(an[i + 1]   - an[i])

for i in range(1,n+1):
    nal.append(ifsums - ( abs(an[i] - an[i-1]) + abs(an[i+1] - an[i]) - abs(an[i+1] -  an[i-1])  ))


for i in range(len(nal)):
    print(nal[i])




Measured memory_bytes: 14048
N = int(input())
H = list(map(int, input().split()))

D  = [0 for _ in range(N-1)]
for i in range(N-1):
    if H[i] >= H[i+1]:
        D[i] = 1

from itertools import groupby
DC = [sum(item) for val, item in groupby([1 if x == 1 else 0 for x in D])]
if DC == []:
    print(0)
else:
    print(max(DC))

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

using namespace std;

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

    int res=0;
    if(S=="SUN"){
        res=7;
    }
    if(S=="MON"){
        res=6;
    }
    if(S=="TUE"){
        res=5;
    }
    if(S=="WED"){
        res=4;
    }
    if(S=="THU"){
        res=3;
    }
    if(S=="FRI"){
        res=2;
    }
    if(S=="SAT"){
        res=1;
    }

    cout<<res<<endl;

    return 0;
}

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

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

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

int main()
{
        int a, b, ans;
        cin >> a >> b;
        string s(a, '0' + b);
        string t(b, '0' + a);


        cout << min(s, t) << endl;

        return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = input().split()

ar = int(n[0])
br = int(n[1])

a = []
b = []
for i in range(0, ar):
    a.append(input())

for j in range(0, br):
    b.append(input())

find = False
for i in range(0, ar - br + 1):
    for j in range(0, ar -br + 1):
        if a[i][j] == b[0][0]:
            same = True
            for k in range(0, br):
                for l in range(0, br):
                    if a[i+k][j+l] != b[k][l]:
                        same = False
                        break
            if same:
                find = True
                break
if find:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
s, t = raw_input(), raw_input()
def f(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if f(s[i:i + len(t)],t):
		cand = i

if cand == -1:
	print 'UNRESTORABLE'
else:
	print s[:cand].replace('?', 'a') + t + s[cand+len(t):].replace('?','a')


Measured memory_bytes: 64480
//
//  main.cpp
//  DPo
#include <iostream>
using namespace std;
using ll = long long;
int a[22][22]={}; // 配列の準備 Nは最大21人
int ds[22]={0}; // 各桁の状態　1か0
int dp[2100000]={0};
bool flag[2100000]={false};
const int mod = 1e9+7;
int f(int n){
    if(n==0) return 1;
    ll mx=n;
    int digit=0;
    int d_sum=0; // 1が何個あるか
    while(mx!=0){
        if(mx%2==1){
            ds[digit+1]=1; // その桁は１
            d_sum++;
        }else{
            ds[digit+1]=0; // その桁は０
        }
        mx=mx>>1;
        digit++; // nを2進数で表現したときの桁
    }
    int sum=0;
    for (int i=1; i<=digit; i++) {
        if(ds[i]==1){
            if(flag[n-(1<<(i-1))]==false){
            sum=(sum+a[d_sum][i]*f(n-(1<<(i-1))))%mod;
            }else{
            sum=(sum+a[d_sum][i]*dp[n-(1<<(i-1))])%mod;
            }
        }
    }
    flag[n]=true;
    return dp[n]=sum%mod;
}
int main(int argc, const char * argv[]) {
    int n;
    cin>>n; // 男女の人数

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            cin >> a[i][j]; // 相性のデータを読み込んで
        }
    }
    int mx=(1<<n)-1; // 2のn乗-1
    cout<<f(mx)<<endl;
    return 0;
}


Measured memory_bytes: 13368
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h,j,k;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>j>>k;
    cout<<a+b+c+d+e+f+g+h+j+k<<endl;
   
        return 0;
    
}



Measured memory_bytes: 3104
const main = (input) => {
  var N = input.split('\n')[0]-0;
  var S = input.split('\n')[1].split("");
  var wmap = {};
  S.forEach(function(w){
    wmap[w] = wmap[w]?wmap[w]+1:1;
  });
  var ans = 1;
  Object.keys(wmap).forEach((w)=>{
    ans *= wmap[w]+1;
    ans = ans%1000000007;
  });

  console.log(ans-1);
}

const pow = (a,b) => {
  var ans = 1;
  for(var i=0;i<b;i++){
    ans=ans*a;
    if(ans>=1000000007){
      ans = ans%1000000007;
    }
  }
  return ans;
};

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 22212
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 k = sc.nextInt();
        sc.close();

        int counter = k;
        for (int i = Math.min(a, b); i > 0; i--) {
            if (a % i == 0 && b % i == 0) {
                counter--;
            }
            if (counter == 0) {
                System.out.println(i);
                break;
            }
        }
    }

}


Measured memory_bytes: 21972
#include<stdio.h>

int main(){
  int i, j, n, tmp, flug=1, cnt=0;
  int A[100];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  while(flug){
    flug = 0;
    for(j=n-1; j>0; j--){
      if(A[j] < A[j-1]){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	cnt++;
	flug = 1;
      }
    }
  }
  
  for(i=0; i<n-1; i++){
    printf("%d ", A[i]);
  } printf("%d\n", A[i]);
  printf("%d\n", cnt);
  return 0;
}


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

int main(){
        int n, m, l;
        int arr_a[100][100] = {0};
        int arr_b[100][100] = {0};
        long long arr_sum[100][100] = {0};
        cin >> n >> m >> l;

        for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                        cin >> arr_a[i][j];
                }
        }
        for(int i = 0; i < m; i++){
                for(int j = 0; j < l; j++){
                        cin >> arr_b[i][j];
                }
        }
        for(int i = 0; i < n; i++){
                for(int j = 0; j < l; j++){
                        for(int k = 0; k < m; k++){
                        arr_sum[i][j] += arr_a[i][k] * arr_b[k][j];
                        }
                cout << arr_sum[i][j];
                if(j < l -1) cout << " ";
                }cout << endl;
        }


}


Measured memory_bytes: 3252
import copy
n=int(input())
A=list(map(int,input().split()))
def solve(a,f):
  # print(f,a)
  ans=0
  for i in range(n):
    if i!=0: a[i]+=a[i-1]
    if not f:
      if a[i]>=0:
        ans+=a[i]+1
        a[i]=-1
    else:
      if a[i]<=0:
        ans+=a[i]*-1+1
        a[i]=1
    # print(a,ans,f)
    f^=True
  return ans
x=A.copy()
print(min(solve(A,True),solve(x,False)))

Measured memory_bytes: 15160
#include <bits/stdc++.h>
#define REP(type, i, a, b) for( type i = a; i <= b; i++ )
using namespace std;

int main(){
    int k,a,b,s;
    cin >> k >> a >> b;

  	for(int i = a/k; i*k <= b; i++ ){
        if(i*k>=a && i*k<=b){
            printf("OK");
            return 0;
        }
    }
    printf("NG");
}


Measured memory_bytes: 3764
n = int(input())

k = int(input())

keta = len(str(n))

dp = [[[0 for j in range(k+2)] for _ in range(2)]  for i in range(keta)]

s = str(n)

#dp[何桁目か][未満フラグ 0 = 未満][ゼロ以外のの個数]

x = int(s[0])
if x == 1:
    dp[0][1][0] = 1
else:
    dp[0][1][0] += 1
    dp[0][0][0] += x - 1


for index, c in enumerate(s[1:]):
    i = index + 1
    x = int(c)
    dp[i][0][0] += 9
    for j in range(k+1):
        dp[i][0][j] += dp[i - 1][0][j]
        if x == 0:
            dp[i][1][j] += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
        elif x:
            dp[i][1][j + 1] += dp[i - 1][1][j]
            dp[i][0][j]     += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
            dp[i][0][j + 1] += dp[i - 1][1][j] * (x - 1)
    # print(sum(dp[i][0]) + sum(dp[i][1]))
    # print(s[:index + 2])
    # print(dp)




print(dp[-1][0][k-1] + dp[-1][1][k-1])


Measured memory_bytes: 38384
p = list(map(int, input().split()))
n = int(input())
eff = [p[0], p[1] / 2, p[2] / 4, p[3] / 8]
g = [0.25, 0.5, 1, 2]
total = 0
ans = 0
def calc(i):
    global total, ans
    k = eff.index(min(eff[: i + 1]))
    ans += int((n - total) // g[k] * p[k])
    total += (n - total) // g[k] * g[k]


while total != n:
    if n - total >= 2:
        calc(3)
    elif n - total >= 1:
        calc(2)
    elif n - total >= 0.5:
        calc(1)
    else:
        total += 0.25
        ans += p[0]
print(ans)

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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            //var ls=RL2IE();
            var x = RL();
            var ret = "A";
            if (x.ToLower() == x)
            {
                ret = "a";
            }
            Console.WriteLine(ret);
            Console.ReadLine();

        }

        static IEnumerable<Int64> RL2IE() { return spr(RL()).Select(x => c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}

Measured memory_bytes: 26052
N = int(input())
coordinate = []
ans = -1
for _ in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        continue
    coordinate.append([x, y, h])
N = len(coordinate)
for cx in range(101):
    for cy in range(101):
        x1, y1, h1 = coordinate[0]
        H1 = h1 + abs(cx-x1) + abs(cy-y1)
        f = 1
        if N == 1:
            f = 2
            Cx = x1
            Cy = y1
            ans = h1
            break
        for n in range(1, N):
            x, y, h = coordinate[n]
            H = h + abs(cx-x) + abs(cy-y)
            if H == H1:
                f *= 1
            else:
                f *= 0
            if f and n == N-1:
                break
        if f == 1:
            Cx = cx
            Cy = cy
            ans = H1
            break
    if f:
        break
        
print(Cx, Cy, ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

map<int, map<long long, map<long long, long long>>> memo;

long long solve(int L, long long i, long long j)
{
	if (L == 0) {
		return 1;
	}
	if (memo.count(L) && memo[L].count(i) && memo[L][i].count(j)) {
		return memo[L][i][j];
	}
	long long ans = 0;
	long long len = (1LL << (L + 2)) - 3;
	//cout << "level " << L << ": " << len << "(" << i << "," << j << ")" << endl;

	if (i < len / 2) {
		if (j < 1) {

		}
		else if (j < len / 2) {
			ans += solve(L - 1, 0, j - 1);
		}
		else if (j > len / 2) {
			ans += solve(L - 1, 0, len / 2 - 1);
			ans += 1;
			ans += solve(L - 1, 0, j - len / 2 - 1);
		}
		else {
			ans += 1;
			ans += solve(L - 1, 0, j - 1);
		}
	}
	else if (i > len / 2) {
		ans += solve(L - 1, i - len / 2 - 1, j - len / 2 - 1);
	}
	else {
		if (i < j) {
			ans += solve(L - 1, 0, j - i - 1);
		}
	}
	return memo[L][i][j] = ans;
}

int main()
{
	int N;
	long long X;
	cin >> N >> X;

	memo.clear();
	long long ans = solve(N, 0, X - 1);
	cout << ans << endl;
}


Measured memory_bytes: 384
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

void solve(){
	int k,a,b,s=0;
	cin >> k >> a >> b ;
	while (11){
		s = s+k;
		if (s>= a && s<=b){
			cout << "OK" << endl ; 
			return;
		}
		if (s>b) break;
	}
    cout <<  "NG" << endl ;
}

signed main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
int main(){
	int count=0;
	string a;
	while(cin>>a){
		bool t=true;
		for(int i=0;i<a.size();i++){
			if(a[i]!=a[a.size()-i-1])
				t=false;
		}
		if(t==true)
			count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1184
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n := nextInt()
	h := nextInts(n)

	dp := make([]int, n)
	dp[0] = 0
	dp[1] = abs(h[0] - h[1])
	for i := 2; i < n; i++ {
		dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
	}

	fmt.Println(dp[n-1])

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-
func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


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

int main()
{
    long long n,w;
    cin >> n >> w;
    vector<vector<long long>> dp(105,vector<long long>(100005,1000000000000000000)),x(n+1,vector<long long>(2));
    for(int i = 1 ; i <= n ; i += 1){
        cin >> x[i][0] >> x[i][1];
    }
    for(int i = 0 ; i <= n ; i += 1){
        dp[i][0] = 0;
    }
    long long max_sum = n * 1000,ans=0;
    for(int i = 1 ; i <= n ; i += 1){
        for(long long v = 0 ; v <= max_sum ; v += 1){
            dp[i][v] = dp[i-1][v];
            if(v - x[i][1] >= 0){
                dp[i][v] = min(dp[i][v],dp[i-1][v-x[i][1]] + x[i][0]);
            }
            if(dp[i][v] <= w){
                ans = max(ans,v);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 83328
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int x, a, b;
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x >> a >> b;
    if(max(x-a,a-x) < max(x-b,b-x)) {
        cout << "A" << endl;
    }
    else {
        cout << "B" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1001001001;

long long pow2[60];
void init_pow2(){
    pow2[0] = 1;
    for(int i=1; i<60; i++){
        pow2[i]  = 2*pow2[i-1];
        pow2[i] %= MOD;
    }
    return;
}

int main(){
    init_pow2();
    
    int n;cin>>n;
    vector<long long> a(n);
    vector<long long> count(60, 0);
    
    long long s = 0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        s += a[i];
        s %= MOD;
        for(int j=0; j<60; j++){
            if((a[i]>>j)&1)count[j]++;
        }
    }
    
    s *= n-1;
    s %= MOD;
    
    for(int j=0; j<60; j++){
        long long t=1;
        t *= count[j]*(count[j]-1)/2;
        t %= MOD;
        t *= 2 * pow2[j];
        t %= MOD;
        s += MOD - t;
        s %= MOD;
    }
    
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 5572
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <set>

typedef long long ll;

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    set<pair<int, int>> s;
    multiset<int> m;
    for (int i = 0; i < W; ++i) {
        s.insert({i, i});
        m.insert(0);
    }

    for (int i = 1; i <= H; ++i) {
        int A, B;
        cin >> A >> B;
        --A;
        --B;

        if (B == W - 1) {
            auto it = s.lower_bound({A, -1});
            for (; it != s.end() && it->first <= B;) {
                m.erase(m.find(it->first - it->second));
                s.erase(it++);
            }
        }
        else {
            int last_start_point = -1;
            auto it = s.lower_bound({A, -1});
            for (; it != s.end() && it->first <= B;) {
                last_start_point = it->second;
                m.erase(m.find(it->first - it->second));
                s.erase(it++);
            }
            if (last_start_point != - 1 && (it == s.end() || it->first != B + 1)) {
                m.insert(B + 1 - last_start_point);
                s.insert({B + 1, last_start_point});
            }
        }

        cout << (m.empty() ? -1 : (*m.begin() + i)) << endl;
    }
    return 0;
}

Measured memory_bytes: 22360
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    string s;
    cin >> s;
    int Ans=0;
    int N=s.size();
    REP(j,N){
        REP(i,j+1){
            //cout << i << " " <<  j << endl;
            bool f=true;
            for(int k=i;k<=j;k++){
                if(s[k]!='A'&&s[k]!='T'&&s[k]!='G'&&s[k]!='C'){
                    f=false;
                }
            }
            if(f){
                Ans=max(Ans,j-i+1);
            }
        }
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

    if(s <= "2019/04/30"){
        printf("Heisei\n");
    }else{
        printf("TBD\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
    long n, m, d;
	cin >> n >> m >> d;
	int cnt=0;
	if(d!=0){
	    cnt = max(n-d,(long)0);
	}else{
		cnt=n;
	}
	//cout << cnt << endl;
	long double pr;
	if (cnt == n)
	{
		pr = cnt / (long double)(n * n);
	}
	else
	{
		pr = cnt*2 / (long double)(n*n);
	}
	//cout<<pr<<endl;
	cout << setprecision(9) << pr * (m - 1) << endl;
}


Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
score=0
prev=0
se=set()
for i in range(d):
    lis=[]
    if i//26>prev:
        se=set()
        prev=i//26
    for j in range(26):
        lis.append((s[i][j],j))
    lis.sort(reverse=True)
    for j in range(26):
        if lis[j][1] not in se:
            se.add(lis[j][1])
            print(lis[j][1]+1)
            break


Measured memory_bytes: 9388
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}
 
const int N=2e5+3,M=5e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;
 
int n,m,k,tc,ans,a[N],cnt;
 
char s[N];

int main(){
    scanf("%d",&n);
    scanf("%s",s);
    for(int i = 0 ; s[i] ; i++)
        cnt += s[i] == 'R';
    for(int i = 0 ; i < cnt ; i++)
        ans += s[i] == 'W';
    printf("%d\n", ans);
}

Measured memory_bytes: 3940
program ABC112B
    implicit none
    integer(8)::i
    integer(8)::N,T,ci,ti
    integer(8)::result=1100

    read(5,*)N,T

    do i=1,N
        read(5,*)ci,ti
        if(ci<result .and. ti<=T)then
            result=ci
        end if
    end do

    if(result<=1000)then
        print'(i0)',result
    else
        print'(A)',"TLE"
    end if
    
end program ABC112B

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

int main()
{
   ll n;
   cin>>n;

   ll arr[n],i,ma=0,ans=0;
   for(i=0;i<n;i++)
    cin>>arr[i];

   for(i=0;i<n;i++)
   {
       if(arr[i]>ma)
       ma=arr[i];
       else
        ans=ans+ma-arr[i];
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;
const ll mod = 1000000007;

int main()
{
  ll n,m; cin>>n>>m;
  vector<bool> st(n, false);
  vector<bool> ed(n, false);
  rep(i, m) {
    ll a,b; cin>>a>>b; a--; b--;
    if (a == 0) st[b] = true;
    if (b == n-1) ed[a] = true;
  }

  bool flg = false;
  rep(i, n) {
    if (st[i] && ed[i]) flg = true;
  }

  if (flg) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 3644
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
Lmax = max(L)
Rmin = min(R)
if Lmax>Rmin:
    print(0)
else:
    print(Rmin-Lmax+1)

Measured memory_bytes: 11020
#include <atcoder/all>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll digitcal(ll x){
  ll n=0;
  while(x>0){
    x/=10;
    n++;
  }
  return n;
}

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main() {
  ll n;
  cin>>n;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  vector<ll> memo;
  ll temp=n;
  for(int i=2;i<=sqrt(n);i++){
    ll cnt=1;
    while(temp%i==0){
      temp/=i;
      cnt*=i;
    }
    if(i==2) cnt*=i;
    if(cnt>1){
      memo.push_back(cnt);
    }
  }
  if(temp>1){
    memo.push_back(temp);
  }
  int s=memo.size();
  ll ans=n;
  for(int i=0;(1<<s)>i;i++){
    ll kari=1;
    for(int j=0;j<s;j++){
      if((i>>j)&1) kari*=memo[j];
    }
    ll aite=2*n/kari;
    ll x,y;
    ll d=extGCD(kari,-aite,x,y);
    if(x==0) continue;
    if(y*aite==0) continue;
    ans=min(ans,y*aite);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
using namespace std;
int main(void){
    int d, n;
    cin >> d >> n;
    int ans = 1;
    for(int i = 0; i < d; i++){
        ans = ans*100;
    }
    if(n == 100) n = 101;
    ans *= n;
    cout << ans << endl;
    return 0;
}

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

const int MAXN = 1e5 + 10;

int n, ans;
struct Node { int cnt, val; } a[MAXN], b[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        if (i & 1) ++a[x].cnt, a[x].val = x;
        else ++b[x].cnt, b[x].val = x;
    }
    std::sort(a + 1, a + MAXN, [](Node a, Node b) { return a.cnt > b.cnt; });
    std::sort(b + 1, b + MAXN, [](Node a, Node b) { return a.cnt > b.cnt; });
    if (a[1].val == b[1].val) ans = n - std::max(a[1].cnt + b[2].cnt, a[2].cnt + b[1].cnt);
    else ans = n - a[1].cnt - b[1].cnt;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

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

    return 0;
}


Measured memory_bytes: 2704
###<ABC.171>
#<A>ac(3)
##n = input()
##if n.islower():
##    print("a")
##else:
##    print("A")

#<B>
n, k = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
p = p[:k]
print(sum(p))


Measured memory_bytes: 62104
import sys
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]
ln1 = []
ln2 = []
for i in p:
    if i[0] == 1:
        ln1.append(i[1])
for j in p:
    if j[1] == n:
        ln2.append(j[0])

if len(set(ln1) & set(ln2)) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')


Measured memory_bytes: 54448
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.append(0)
    C = Counter(D)
    if C[0] > 1 or C[12] > 1:
        return 0
    

    K = []
    F = []
    for k in C:
        if C[k] > 2:
            return 0
        elif C[k] == 2:
            F.append(24-k)
            F.append(k)
        else:
            K.append(k)
    M = len(K)
    ans = 0
    for S in product([1, -1], repeat=M):
        tmp = []
        for s, v in zip(S, K):
            tmp.append(s*v)
        tmp.extend(F)
        tmp.sort()
        cand = INF
        for i in range(len(tmp)):
            d = abs(tmp[i] - tmp[i-1])
            cand = min(cand, min(24-d, d))

        ans = max(ans, cand)

    return ans

def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()


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

int main(){
    int N;
    cin >> N;
    map<int, int> T;
    int a;
    for(int i = 1; i <= N; i++){
        cin >> a;
        T[a] = i;
    }

    for(int i = 1; i <= N; i++){
        pair<int, int> target = *T.find(i);
        cout << target.second ;
        if(i != N){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5504
var
  n:string;
begin
  readln(n);
  if n[1]=n[length(n)] then
    begin
      if odd(length(n)) then writeln('Second')
        else writeln('First');
    end
    else
      begin
        if odd(length(n)) then writeln('First')
         else writeln('Second');
      end;
end.

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

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

  if (s[2] == s[3] and s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

K = I()

d = defaultdict(int)
digit = 1
val = 7%K
while True:
    if val == 0:
        print(digit)
        exit()
    else:
        if d[val]:
            print(-1)
            exit()
        d[val] += 1
        digit += 1
        val = 10*val+7
        val %= K

Measured memory_bytes: 168320
#include <stdio.h>

int main(){
    int i, n;
    int arr[100];
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf(" %d", &arr[i]);
    }
    for(i=0;i<n;i++){
        if(i)printf(" ");
        printf("%d", arr[n-i-1]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
from collections import deque

n,m = map(int,input().split())
INF = 114514191981036436433-4

r = [[] for _ in range(n)]
aa,bb = [] , []

for i in range(m):
    a,b = map(int,input().split())
    aa.append(a-1)
    bb.append(b-1)
    r[a-1].append(b-1)
    r[b-1].append(a-1)
    
q = deque()
q.append(0)
d = [INF]*n
d[0] = 0

while q:
    p = q.popleft()
    for i in r[p]:
        if d[i] == INF:
            q.append(i)
            
        d[i] = min(d[p] + 1 , d[i])
    
ans = [0]*n
for i in range(m):
    if d[aa[i]] - d[bb[i]] == 1:
        ans[aa[i]] = bb[i] + 1
    elif d[bb[i]] - d[aa[i]] == 1:
        ans[bb[i]] = aa[i] + 1
        
print("Yes")
for i in ans[1:]:
    print(i)

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

using namespace std;

int n,meeting,c;
vector<vector<int> > g(100002);
int visited[100002];
vector<int> path;
vector<int> rpath;

void findpath(int s)
{
    visited[s]=1;
    path.push_back(s);
    if(s==n)
    {
        for(int i=0;i<path.size();i++) rpath.push_back(path[i]);
        return ;
    }
    for(int i=0;i<g[s].size();i++)
    {
        int v=g[s][i];
        if(!visited[v]) findpath(v),path.pop_back();
    }
}

void dfs(int s)
{
    visited[s]=1;
    for(int i=0;i<g[s].size();i++)
    {
        int v=g[s][i];
        if(!visited[v] && v!=meeting) c++,dfs(v);
    }
}

int main()
{
    cin >> n;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    memset(visited,0,sizeof(visited));
    findpath(1);
    if(rpath.size()%2==0) meeting = ((rpath.size())/2)-1;
    else meeting = (rpath.size())/2;
    meeting = rpath[meeting];
    memset(visited,0,sizeof(visited));
    c=0;
    dfs(n);
    int cw=c;
    c=0;
    meeting = -100;
    dfs(1);
    int cb=c;
    if(cb>cw) cout << "Fennec";
    else cout << "Snuke";
    return 0;
}



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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int fl=0;


int32_t main()
{   fastio;
    int n , m , x;
    cin>>n>>m>>x;
    int cost[n];
    int price[n][m];
    for(int i=0; i<n; i++)
    {
        cin>>cost[i];
        for(int j=0; j<m; j++)
            cin>>price[i][j];
    }

    int ans=1e13;
    for(int i=0; i < (1ll<<n); i++)
    {
        int sum=0;
        vector<int>vp(m , 0);
        for(int j=0; j<n; j++)
        {
            if((1ll<<j)&i) {
                sum += cost[j];
                for(int k=0; k<m; k++)
                {
                    vp[k] += price[j][k];
                }
            }
        }
        int kl=0;
        for(int k=0; k<m; k++)
        {
            if(vp[k]<x)kl=1;
        }
        if(!kl) {
            ans=min(ans , sum);
        }
        //cout<<sum<<endl;
    }
    if(ans == 1e13)cout<<"-1\n";
    else cout<<ans<<"\n";


}

Measured memory_bytes: 3656
S = input()
a = 0
b = 0
c = 0
p = 1
mod = 1000000000+7
for C in S:
    if C == "?":
        c = 3*c+b
        b = 3*b+a
        a = 3*a+p
        p *= 3
    elif C == "A":
        a += p
    elif C == "B":
        b += a
    elif C == "C":
        c += b
    a %= mod
    b %= mod
    c %= mod
    p %= mod
print(c)


Measured memory_bytes: 3188
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

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



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

int n, m;
main() {
  file("threesum");
  ios;
  cin >> n >> m;
  cout << (n - 1) * n / 2 + m * (m - 1) / 2;
  return 0;
}
/**

*/


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))

if h==1 or w==1:
    print(1)
    import sys
    sys.exit()

r_odd = w//2 + w%2
r_even = w//2

r_odd_cnt = h//2 + h%2
r_even_cnt = h//2

print(r_odd * r_odd_cnt + r_even * r_even_cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		int cost[105][105]; int time[105][105];
		REP(i, m)REP(j, m)
		{
			cost[i][j] = (i == j ? 0 : INF);
			time[i][j] = (i == j ? 0 : INF);
		}
		int a, b, c, d;
		REP(i, n)
		{
			cin >> a >> b >> c >> d;
			a--; b--;
			cost[a][b] = cost[b][a] = c;
			time[a][b] = time[b][a] = d;
		}
		int k; cin >> k;
		int p, q, r;
		REP(i, k)
		{
			cin >> p >> q >> r;
			p--; q--;
			int d[105];
			fill(d, d + m, INF);
			d[p] = 0;
			bool used[105] = {};
			while (1)
			{
				int v = -1;
				REP(i, m) if (!used[i] && (v == -1 || d[i] < d[v])) v = i;
				if (v == -1) break;
				used[v] = true;
				REP(i, m) d[i] = min(d[i], d[v] + (r ? time[v][i] : cost[v][i]));
			}

			cout << d[q] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 1000
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

int cnt[55][33], n, in[33];
char str[111];

int main () {
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		scanf("%s",str);
		for(int j=0;j<strlen(str);j++)	cnt[i][str[j]-'a']++;
	}
	for(int i=0;i<26;i++) {
		in[i] = INF;
		for(int j=0;j<n;j++)	in[i] = min(in[i], cnt[j][i]);	
	}
	for(int i=0;i<26;i++)	{
		for(int j=0;j<in[i];j++)	printf("%c",'a'+i);
	}
	printf("\n");
}

Measured memory_bytes: 256
#include <stdio.h>

int main()

{
    int A, B, C, D, X, Y, sum;

    scanf("%d %d %d %d", &A, &B, &C, &D);

    if (1 <= A <= 1000 && 1 <= B <= 1000 && 1 <= C <= 1000 && 1 <= D <= 1000) {

        if (A < B) {

            X = A;
        }

        else {

            X = B;
        }

        if (C < D) {

            Y = C;
        }

        else {

         Y= D;
        }

        sum = X + Y;

        printf("%d", sum);


    }

    return 0;
}


Measured memory_bytes: 128
x,y=map(int, input().split())
if x == y:
  print("Yes")
elif x in [4,6,9,11] and y in [4,6,9,11]: 
  print("Yes")
elif x in [1,3,5,7,8,10,12] and y in [1,3,5,7,8,10,12]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
import java.util.*;
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();
        System.out.println((c>=a&&a+b>=c)?"YES":"NO");
	}
}


Measured memory_bytes: 21844
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, c;
    cin >> n >> c;

    vector<vector<int>> d(c+1, vector<int>(c+1));
    rep(i, c){
        rep(j, c){
            cin >> d[i+1][j+1];
        }
    }
    vector<vector<int>> cc(n+1, vector<int>(n+1));
    rep(i, n){
        rep(j, n){
            cin >> cc[i+1][j+1];
        }
    }

    vector<vector<int>> t(3, vector<int>(c+1));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            t[(i+j)%3][cc[i][j]]++;
        }
    }

    int ans = INF;
    for(int i = 1; i <= c; i++){
        for(int j = 1; j <= c; j++){
            for(int k = 1; k <= c; k++){
                if(i == j || j == k || k == i){
                    continue;
                }

                int tmp = 0;
                for(int x = 1; x <= c; x++){
                    tmp += d[x][i] * t[0][x];
                    tmp += d[x][j] * t[1][x];
                    tmp += d[x][k] * t[2][x];
                }
                if(ans > tmp){
                    ans = tmp;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176