akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>

const int MOD = 1000000007;

typedef pair<int, int> P;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<tuple<int, int, int>> a(N);
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        a[i] = make_tuple(x, s - x, t - x);
    }
    sort(a.begin(), a.end());

    set<P> s;
    rep(i, Q) {
        int q;
        cin >> q;
        s.insert({q, i});
    }

    vector<int> ans(Q, -1);
    rep(i, N) {
        int x, l, r;
        tie(x, l, r) = a[i];

        auto itr = s.lower_bound(P(l, -1));
        while (itr != s.end()) {
            if (itr->first >= r) break;
            ans[itr->second] = x;
            s.erase(itr++);
        }
    }

    rep(i, Q) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 14336
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {
	int n;
	int dp[100001];
	int pos = 1;

	cin >> n;
	cout << n << ":";
	FOR(i, 2, n) {
		if (pos == 1 && i > sqrt(n)) {
			dp[pos] = n;
			pos++;
			n = 1;
		}
		while (n%i == 0) {
			dp[pos] = i;
			pos++;
			n /= i;
		}
	}
	FOR(i, 1, pos - 1) {
		cout << " " << dp[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int a[100000];



int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int count=0;
  for(int i=0;i<N;i++){
      if(i+1==a[a[i]-1]){
        count++;
      }
  }
  cout << count/2 <<endl;
  return 0;
}
  


Measured memory_bytes: 640
N, M, X = map(int, input().split())
C = []; A = []; T = []
for _ in range(N):
    s = list(map(int, input().split()))
    C.append(s[0])
    A.append(s[1:])

INF = 10**9
ans = INF
# シフトで2^nまで全探索
for s in range(0, 1 << N):
    # 習得度をいれるリストを定義
    smart = [0] * M
    cost_sum = 0
    # sには10進数が入る
    for i in range(N):
        # 買っていない時
        if (s >> i) % 2 == 0: continue
        cost_sum += C[i]
        for j in range(M):
            smart[j] += A[i][j]
    ok = True
    if min(smart) < X:
        ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 85320
s_li = [[] for i in range(3)]
for i in range(3):
    for s in input():
        if s=='a':s_li[i].append(0)
        if s=='b':s_li[i].append(1)
        if s=='c':s_li[i].append(2)

x = s_li[0].pop(0)
while len(s_li[x])!=0:
    x = s_li[x].pop(0)
ans_dic={0:'A',1:'B',2:'C'}
print(ans_dic[x])

Measured memory_bytes: 3064
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    let aryMarch = ["M", "A", "R", "C", "H"]
    var march = [Int](repeating: 0, count: 5)
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    
    for _ in 0..<n {
        let s = readLines()[0]
        for i in 0..<aryMarch.count {
            if  s == aryMarch[i] {
                march[i] += 1
                break
            }
        }
    }
    var ans = 0
    
    for i in 0...2 {
        for j in i + 1...3 {
            for k in j + 1..<march.count {
                ans += march[i] * march[j] * march[k]
            }
        }
    }
    print(ans)
}
main()


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
    a%=M;
    b%=M;
    ll p = (a+b)%M;
    return (p+M)%M;
}

ll mul(ll a,ll b)
{
    a%=M;
    b%=M;
    ll p = (a*b)%M;
    return (p+M)%M;
}

const int NBITS = 61;

ll basis[NBITS]; 

int sz; 

void insertVector(ll mask)
{
    for (ll i = 0; i < NBITS; i++)
    {
        if ((mask & (1LL << i)) == 0) continue; 
        if (!basis[i]) 
        { 
            basis[i] = mask;
            ++sz;
            return;
        }

        mask ^= basis[i];
    }
}

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        memset(basis, 0, sizeof(basis));
        ll n,a[1000],i;
        cin>>n;
        for(i=0;i<n;i++)
            cin>>a[i];
        string str;
        cin>>str;
        ll ans=0;
        for(i=n-1;i>=0;i--)
        {
            ll cur = sz;
            insertVector(a[i]);
            if((sz>cur)&&(str[i]=='1'))
            {
                ans=1;
                break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}





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

int N;

int main() {
    scanf("%d", &N);

    int Xor = 0;
    for(int i = 0; i < N; i++) {
        int a, k; scanf("%d %d", &a, &k);

        if(k <= 100000) {
            int t;
            while(1) {
                int q = a / k;
                int r = a % k;
                if(r == 0) {
                    t = q;
                    break;
                }
                a -= q + 1;
            }
            Xor ^= t;
        }
        else {
            int t;
            int q = a / k;
            int r = a % k;
            while(1) {
                if(r % (q + 1) == 0) {
                    t = q;
                    break;
                }
                r %= (q + 1);
                r = k - q + r - 1;
                q = q - 1;
            }
            Xor ^= t;
        }
    }

    if(Xor) printf("Takahashi");
    else printf("Aoki");
}


Measured memory_bytes: 256
s = input()
t = input()
s_lis = []
t_lis = []
for i in range(len(s)):
    s_lis.append(s[i])
for i in range(len(t)):
    t_lis.append(t[i])
s_lis.sort()
t_lis.sort(reverse = True)

s1 = ""
t1 = ""
for i in range(len(s_lis)):
    s1 += s_lis[i] 
for i in range(len(t_lis)):
    t1 += t_lis[i]
#print(s1, t1)
if s1 < t1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
const int inf = 1e9;

int main(){
	int n,k,q;
	cin >> n >> k >> q;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	
	vector<pair<int, int> > ord(n);
	for(int i=0; i<n; i++){
		ord[i] = make_pair(a[i], i);
	}
	sort(ord.begin(), ord.end());
	
	int ans = inf;
	for(int i=0; i<n; i++){
		vector<int> t;
		int s=0;
		for(int j=0; j<n; j++){
			if(a[j] < ord[i].first || j==n-1){
				if(j==n-1) j++;
				int diff = j-s;
				if(diff >= k){
					vector<int> tmp;
					for(int k=s; k<j; k++){
						tmp.push_back(a[k]);
					}
					sort(tmp.begin(), tmp.end());
					t.insert(t.end(), tmp.begin(), tmp.begin()+ diff-k+1);
				}
				s=j+1;
			}
		}
		//cout << t.size() << endl;
		sort(t.begin(), t.end());
		if((int)t.size() < q) break;
		ans = min(ans, t[q-1] - t[0]);
	}
	cout << ans << endl;
	return 0;
}

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

const int inf = 1000000000 + 1;
int cnt = 0;

void merge(std::vector<int> &s, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    std::vector<int> L(n1+1);
    std::vector<int> R(n2+1);

    for (int i = 0; i < n1; i++) {
        L[i] = s[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = s[mid + i];
    }
    L[n1] = inf;
    R[n2] = inf;

    // std::cout << "==== merge ====" << std::endl;
    // for (int i = 0; i < n1; i++) {
    //     std::cout << L[i] << " ";
    // }
    // std::cout << std::endl;
    // for (int i = 0; i < n2; i++) {
    //     std::cout << R[i] << " ";
    // }
    // std::cout << std::endl;
    // std::cout << "||" << std::endl;
    // std::cout << "\\/" << std::endl;


    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            s[k] = L[i];
            i++;
        }
        else {
            s[k] = R[j];
            j++;
        }
        cnt++;
    }

    // for (int i = left; i < right; i++) {
    //     std::cout << s[i] << " ";
    // }
    // std::cout << std::endl;
}

void mergesort(std::vector<int> &s, int left, int right)
{
    if (left + 1 < right) {
        int mid = left + (right - left) / 2;
        mergesort(s, left, mid);
        mergesort(s, mid, right);
        merge(s, left, mid, right);
    }
}

int main(int argc, char const *argv[])
{
    int n;
    std::cin >> n;
    std::vector<int> s(n);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }

    mergesort(s, 0, n);

    for (int i = 0; i < n - 1; i++) {
        std::cout << s[i] << " ";
    }
    std::cout << s[n - 1] << std::endl;

    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 5060
#include<stdio.h>
#include<stdlib.h>

int main(){

  int i, j, k, n, *A, key;

  scanf("%d",&n);
  A = (int *)malloc(n * sizeof(int *));
  for(i = 0; i < n; i++) scanf("%d",&A[i]);
  
  for(i = 0; i < n-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n",A[i]);
  
  for(i = 1; i < n; i++){
    key = A[i];  /*insert A[i] into the sorted sequence A[0,...,j-1]*/
    j = i - 1;
    while(j >=0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
  
    A[j+1] = key;
    for(k = 0; k < n-1; k++){
      printf("%d ", A[k]);
    }
    printf("%d\n",A[k]);
    }

  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(){
  int n,i,max,in,out,c;
  scanf("%d %d",&n,&c);
  max=1;
  if(c)max=c;
  for(i=0;i<n;i++){
    scanf("%d %d",&in,&out);
    c+=in;
    c-=out;
    if(c<0)max=0;
    if(max&&max<c)max=c;
  }
  printf("%d\n",max);
  return 0;
}
      

Measured memory_bytes: 1024
"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const args_lines = arg_str.split('\n')
const n = args_lines[0]

const a_array = args_lines[1].split(' ')
const a_array_invert = a_array.map(x=>1/parseInt(x))
const sum = a_array_invert.reduce((a, b)=>a + b)

console.log(1/sum)

Measured memory_bytes: 21064
h,w,n=map(int,input().split())
l=[list(map(int,input().split()))  for _ in range (n)]
ans=[0 for i in range(10)]
ans[0]=(w-2)*(h-2)
d=dict()
for j0,i0 in l:
    for i in range(i0,i0-3,-1):
        if i<1 or w-2<i:continue
        for j in range(j0,j0-3,-1):
            if j<1 or h-2<j:continue

            if "{},{}".format(i,j) in d:
                d["{},{}".format(i,j)]+=1
            else:
                d["{},{}".format(i,j)]=1
for i in list(d.values()):
    ans[i]+=1
    ans[0]-=1
for i in ans:
    print(i)

    

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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  vector<int> A;
  cin >> N;
  A.resize(N);

  rep(i, N) cin >> A[i];

  vector<ll> acc(N, 0);
  rep(i, N) {
    if (i-1>=0) acc[i] = acc[i-1];
    acc[i] += A[i];
  }

  ll ans = INFLL;
  REP(d, 1, N) {
    ll x = acc[d-1];
    ll y = acc[N-1] - x;
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	s := nextString()
	m := map[string]int{}

	for i := 0; i < len(s); i++ {
		m[string(s[i])]++
	}

	flag := true
	if len(m) != 2 {
		flag = false
	}
	for k := range m {
		if m[k] != 2 {
			flag = false
		}
	}

	if flag == true {
		_, _ = fmt.Fprint(writer, "Yes")
	} else {
		_, _ = fmt.Fprint(writer, "No")
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

const ll MOD = 1e6+3;
const int II = 1e6+5;
 
ll addMod(ll a,ll b){
      return ((a%MOD)+(b%MOD))%MOD;
}
 
ll mulMod(ll a,ll b){
      return ((a%MOD)*(b%MOD))%MOD;
}
 
ll powMod(ll a,ll b){
      if(b==0) return 1;
      else if(b%2==0){
            ll ret=powMod(a,b/2);
            return ((ret%MOD)*(ret%MOD))%MOD;
      }
      else return ((powMod(a,b-1)%MOD)*(a%MOD))%MOD;
}
ll divMod(ll a,ll b){
      return ((a%MOD)*(powMod(b,MOD-2)%MOD))%MOD;
}
 
ll frac[II+1];
ll invfrac[II+1];

void calc(){ //main関数内にcalc();を入れること
      frac[0]=1;
      invfrac[0]=1;
      rep0(i,II){
            frac[i+1]=mulMod(frac[i],i+1);
            invfrac[i+1]=divMod(1,frac[i+1]);
      }
}


int main(){
      ll q;
      cin>>q;
      calc();
      while(q--){
            ll x,d,n;
            cin>>x>>d>>n;
            ll ans=0;
            if(d==0){
                  ans=powMod(x,n);
            }
            else{
                  ll a=divMod(x,d);
                  if(a+n-1>=MOD){
                        ans=0;
                  }
                  else{
                        ans=powMod(d,n);
                        ans=mulMod(ans,frac[a+n-1]);
                        ans=mulMod(ans,invfrac[a-1]);
                  }
            }
            cout<<ans<<endl;
      }

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  vector<int> l2r(S.size());
  vector<int> r2l(S.size());

  int distance = 0;
  for(int i = 0; i < S.size(); ++i) {
    if(S[i] == 'R') {
      distance = 0;
    } else {
      distance++;
    }
    l2r[i] = distance;
  }
  distance = 0;
  for(int i = S.size() - 1; i >= 0; --i) {
    if(S[i] == 'L') {
      distance = 0;
    } else {
      distance++;
    }
    r2l[i] = distance;
  }
  vector<int> ans(S.size(), 0);
  for(int i = 0; i < S.size(); ++i) {
    if(S[i] == 'L') {
      auto pos = i - l2r[i] + l2r[i] % 2;
      ans[pos]++;
    } else {
      auto pos = i + r2l[i] - r2l[i] % 2;
      ans[pos]++;
    }
  }
  for(auto p : ans) {
    cout << p << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1792
house = [[[0] * 10 for _ in range(3)] for __ in range(4)]

n = int(input())

while n:
    b, f, r, v = map(int, input().split())
    house[b - 1][f - 1][r - 1] += v
    n -= 1

for i, b in enumerate(house):
    for f in b:
        print(' ', end='')
        print(*f)
    if i < 3:
        print('#' * 20)

Measured memory_bytes: 7736
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  map<char,int> mp;
  int n; cin >>n;
  string s; cin >>s;
  rep(i,n){
    mp[s[i]]++;
  }
  li ans=1;
  for(pair<char,int> x:mp){
    (ans*=x.second+1)%=MOD;
  }
  print(ans-1);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--) 
  
long long fact(long long a, long long b){
    int r= max(a, b);
    int v= min(a, b);
    int l=1;
    // if(v==0)
    for(int i=r+1; i<=a+b; i++){
        l*=i;
    }
    for(int i=v; i>=2; i--){
        l/=i;
    }
    return l;
}

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

int powr(int a) { 
    int var=1;
    for(int i=0; i<a; i++){
        var*=2;
    }
    return var;
}

signed main(){    
    fast;
    int x, y;
    cin >> x>> y;
    if(y%2!=0 || y>4*x || y<2*x){
        cout << "No";
        return 0;
    }
    cout << "Yes";
}

Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
    long long int n,k,a;
    scanf("%lld%lld",&n,&k);
    if(n>k){
        if(n%k>k-n%k) n=k-n%k;
        else n=n%k;
    }else if(n<k){
        if(n>k-n) n=k-n;
    }else{
        n=0;
    }
    printf("%lld",n);
    return 0;
}

Measured memory_bytes: 1712
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for _ in range(n)]

a = a1 + a2 + a3

for i in range(9):
    for j in range(n):
        if a[i] == b[j]:
            a[i] = 0

if (a[0] == 0) and (a[1] == 0) and (a[2] == 0):
    print('Yes')
elif (a[3] == 0) and (a[4] == 0) and (a[5] == 0):
    print('Yes')  
elif (a[6] == 0) and (a[7] == 0) and (a[8] == 0):
    print('Yes')
elif (a[0] == 0) and (a[3] == 0) and (a[6] == 0):
    print('Yes')
elif (a[1] == 0) and (a[4] == 0) and (a[7] == 0): 
    print('Yes')
elif (a[2] == 0) and (a[5] == 0) and (a[8] == 0):
    print('Yes')
elif (a[0] == 0) and (a[4] == 0) and (a[8] == 0): 
    print('Yes')
elif (a[2] == 0) and (a[4] == 0) and (a[6] == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    K = input_number()
    A, B = input_number_list()
    a = -(-A // K)
    b = B // K
    isOK = A <= a*K <= b*K <= B
    print(['NG', 'OK'][isOK])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
//package Graph;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Main
{
    static void addEdge(ArrayList<ArrayList<Integer>>graph, int edge1, int edge2)
    {
        graph.get(edge1).add(edge2);
        graph.get(edge2).add(edge1);
    }

    static void DFS_Recursive(ArrayList<ArrayList<Integer>>graph, int source, boolean[] visited)
    {
        visited[source] = true;

        for (int i : graph.get(source)) if (!visited[i]) DFS_Recursive(graph,i,visited);
    }

    static int DFS(ArrayList<ArrayList<Integer>>graph, int vertices)
    {
        boolean[] visited = new boolean[vertices+1];
        int count = 0;

        for (int i=1;i<=vertices;i++)
        {
            if (!visited[i])
            {
                count++;
                DFS_Recursive(graph,i,visited);
            }
        }

        return count;
    }

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

        int vertices = fr.nextInt();
        int edges = fr.nextInt();

        ArrayList<ArrayList<Integer>>graph = new ArrayList<>();
        for (int i=0;i<vertices+1;i++) graph.add(new ArrayList<>());

//        addEdge(graph,0,1);
//
//        addEdge(graph,2,4);
//        addEdge(graph,2,3);
//
//        addEdge(graph,5,5);

        for(int i=1;i<=edges;i++) addEdge(graph,fr.nextInt(),fr.nextInt());

        System.out.print(DFS(graph,vertices)-1);
    }
}


Measured memory_bytes: 76288
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=(int) 1e5;
static const int MOD=(int) 1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
int N;
ll A[MAX+2],d;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N >> A[0];
    int ans=0,status=0;
    //status==0:0が続いてわからない
    for(int i=1;i<N;i++){
        cin >> A[i];
        d = A[i] - A[i-1];
        if(d>0){
            if(status==-1) {ans++;status=0;}
            else status=1;
        }else if(d<0){
            if(status==1) {ans++; status=0;}
            else status=-1;
        }
    }
    cout << ans+1 <<"\n";
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    ll e;
    while ((cin >> e), e != 0)
    {
        ll ans = e;
        for (ll i = 0; i * i * i <= e; i++)
        {
            for (ll j = 0; j * j <= e; j++)
            {
                if (i * i * i + j * j > e)
                {
                    break;
                }
                ll k = e - (i * i * i + j * j);
                ans = min(ans, i + j + k);
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 2980
#include <iostream>  
#include <cstdio>  
#include <stack>  
#include <vector>  
#include <algorithm>  
using namespace std;  
  
int main(){  
  stack<int> S1;  
  stack<pair<int, int> > S2;  
  char ch;  
  int sum = 0;  
  for(int i = 1;cin >> ch; i++){  
    if(ch == '\\')S1.push(i);  
    else if(ch == '/' && S1.size() > 0){  
      int j = S1.top();S1.pop();  
      sum += i - j;  
      int a = i - j;  
      while(S2.size() > 0 && S2.top().first > j){  
        a += S2.top().second;S2.pop();  
      }  
      S2.push(make_pair(j, a));  
    }  
  }  
  vector<int> ans;  
  while(S2.size() > 0){ans.push_back(S2.top().second);S2.pop();}  
  reverse(ans.begin(),ans.end());  
  cout<< sum << endl;  
  cout<< ans.size();  
  for( int i = 0; i < ans.size(); i++){  
    cout<< " ";  
    cout<< ans[i];  
  }  
  cout << endl;  
  return 0;  
}  

Measured memory_bytes: 3228
def main():
  S = input()
  Q = int(input())
  Queries = [input().split() for i in range(Q)]
  #print(Queries)
  is_reversed = False
  prefix = ''
  suffix = ''
  for Query in Queries:
    if Query[0] == '1':
      is_reversed = not is_reversed
    else:
      if (Query[1] == '1') ^ is_reversed:
        prefix = Query[2] + prefix
      else:
        suffix += Query[2]
  ans = prefix + S + suffix
  if not is_reversed:
    print(ans)
  else:
    print(''.join(list(reversed(ans))))

main()


Measured memory_bytes: 42416
import java.util.*;
class Main{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        String tmpStr;
        int tmpNum = 0;
        int[] alphaNum = new int[26];
        char alphaC = 'A';
            
        while (scan.hasNext()){
            tmpStr = scan.next().toLowerCase();
            for(int i=0; i<tmpStr.length(); i++){
                tmpNum=tmpStr.charAt(i)-'a';
                if(0<=tmpNum && tmpNum<='z'-'a')
                    alphaNum[tmpNum]++;
            }
        }
        
        for(int i=0; i<26; i++)
            System.out.println((char)('a'+i)+" : "+alphaNum[i]);
    }
}



Measured memory_bytes: 26208
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <numeric>
#include <cstdio>
#include <queue>
 
 
using namespace std;
 
int main() {
 
    int N, M;
    cin >> N >> M ;
 
    priority_queue<int> L;
    int l;
    for (int i = 0; i < N; i++) {
        scanf("%d", &l);
        L.push(l);
    }
 
    for (int i = 0; i < M; i++) {
        int max_L = L.top();
        L.pop();
        if (max_L == 0) {
            break;
        }
        max_L /= 2;
        L.push(max_L);
    }
 
    long long ans = 0;
    while (!L.empty()) {
        ans += L.top();
        L.pop();
    }
 
    cout << ans << '\n';
 
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    char s; std::cin >> s;

    if( std::isupper(s) ){
        std::cout << "A" << "\n";
    }else{
        std::cout << "a" << "\n";
    }
    return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
int a[N], n;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	int cnt = 0;
	// odd - even of a stack drop by 1 after each turn
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		cnt += a[i] % 2;
	}
	if(cnt > 0) return cout << "first", 0;
	else return cout << "second", 0;
}

Measured memory_bytes: 640
while True:
    n = map(int, raw_input ().split())
    if n[0] == 0 and n[1] == 0 :
        break
    if n[0] > n[1]  :
        temp = n[0]
        n[0] = n[1]
        n[1] = temp
    print "%d %d" %(n[0], n[1])
    

Measured memory_bytes: 6436
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <deque>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

 
ll dp[2020][2020];
ll sum[2020][2020];

int main(void){
	int n;
	cin>>n;
	vector<ll>x(n),y(n);
	for(int i=0;i<n;i++){
		ll X,Y;
		cin>>X>>Y;
		x[i]=X+Y;
		y[i]=X-Y;
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	cout<<max(x[n-1]-x[0],y[n-1]-y[0])<<endl;
	return 0;
}

Measured memory_bytes: 6424
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n;

/* add your algorithm here */

int main() {
  cin >> n;

  ll ans = 0;
  for (int i = 1; i <= n; i += 2) {
    ll c = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) {
        c++;
      }
    }

    if (c == 8) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict
from bisect import bisect_left

S = input().rstrip()
T = input().rstrip()

LS = len(S)

index = defaultdict(list) # alphabet to indices

for i,s in enumerate(S):
    index[s].append(i)

index

x = -1 # 今見た場所。次はx+1以上からとる。
for t in T:
    arr = index[t]
    if len(arr) == 0:
        x = -2
        break
    y = (x+1)%LS
    i = bisect_left(arr,y)
    if i < len(arr):
        next_x = (x+1) + arr[i] - y
    else:
        next_x = (x+1) + arr[0] - y + LS
    x = next_x

answer = x+1
print(answer)

Measured memory_bytes: 7864
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

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

int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(m); readint(d);
        int ret = 0;
        forr(i,1,m) {
            for(int j=10; j <= d; ++j) {
                int d1 = j%10;
                int d10 = j/10;
                ret += ((i==d1*d10) && (d1>=2) && (d10>=2));
            }
        }
        
        cout << ret << endl;
    }
    return 0;
}


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

int main() {
  int x, y,  fx;
  cin >> x;
  y = x;
  fx = 0;
  while (y > 0){
    fx += y % 10;
    y /= 10;
  }
  if (x % fx == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int dp[11][1001], v[10];
void dfs(int a, int b) {
	int i;
	dp[a][b]++;
	for (i = 0; i < 10; i++)
		if (!v[i]) {
			v[i] = 1;
			dfs(a + 1, b + i*(a + 1));
			v[i] = 0;
		}
}
int main() {
	dfs(0, 0);
	int a, b;
	for (; ~fscanf(stdin, "%d%d", &a, &b); P(d, (a>10||b>330)?0:dp[a][b]));
	return 0;
}

Measured memory_bytes: 644
#include<iostream>
using namespace std;
int main(){
    int a,b,c,f = 0 ;
    cin >> a >> b >> c;
    
    for(int x = a; x <= b; x++ ){
        if ( c % x == 0 ) f++;
    }
    
    cout << f << endl;
            
return 0;
        }

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)
	{
		a=a^b;
		b=a^b;
		a=a^b;
	}
	if(b>c)
	{
		c=c^b;
		b=c^b;
		c=c^b;
	}
	if(a>b)
	{
		a=a^b;
		b=a^b;
		a=a^b;
	}
	int s=(b-a)+(c-b);
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
/*
dp[i][j]表示到达(i,j)的方法
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 3;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
char mp[MAXN][MAXN];
int dp[MAXN][MAXN];

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> mp[i][j];
    dp[1][1] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            for (int k = 1; k <= 2; k++)
            {
                int tx = i - (k % 2);
                int ty = j - ((k + 1) % 2);
                if (tx < 1 || tx > n || ty < 1 || ty > m || mp[tx][ty] == '#')
                    continue;
                dp[i][j] += dp[tx][ty];
                dp[i][j] %= mod;
            }
        }
    cout << dp[n][m];
    return 0;
}

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

int main() {
    int n;
    string s[100000];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];

    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == "AC") ac++;
        else if (s[i] == "WA") wa++;
        else if (s[i] == "TLE") tle++;
        else if (s[i] == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

ll in[20];
int main() {
	ll N, i;
	scanf("%lld", &N);

	for (i = 0; N; i++, N /= 10) in[i] = N % 10;

	ll ans = 0;
	ll s = 0;
	for (i = 17; i >= 0; i--) {
		if (!in[i]) continue;

		ans = max(ans, s + (in[i] - 1) + i * 9);
		s += in[i];
	}
	ans = max(ans, s);
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
    // 配列の最大値を取得
    int max = *max_element(vec.begin(), vec.end());
    // 配列の最大値のイテレータを取得
    vector<int>::iterator maxIt = max_element(vec.begin(), vec.end());
    // 配列の最大値までの距離を取得
    int maxIndex = distance(vec.begin(), maxIt);
    // 隣り合う重複要素を削除し、末尾のゴミを削除
    // (uniqueは、重複を取り除いた範囲の末尾の次を指すイテレータを返す)
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
*/

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

    int cnt = 0;
    for (int i=0; i<S.size(); ++i) {
        if (S[i] == '+') cnt++;
        else cnt--;
    }
    cout << cnt;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    unordered_map<string,int> m;
    m.insert(pair<string, int>("AC", 0));
    m.insert(pair<string, int>("WA", 0));
    m.insert(pair<string, int>("TLE", 0));
    m.insert(pair<string, int>("RE", 0));
    int n;
    string s;
    cin>>n;
    
    while( cin >> s ) m[s]++;   

    cout<<"AC x "<<m["AC"]<<endl;
  	cout<<"WA x "<<m["WA"]<<endl;
  	cout<<"TLE x "<<m["TLE"]<<endl;
  	cout<<"RE x "<<m["RE"]<<endl;
  	return 0;
}

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

list<long long>res;

int main(void)
{
	long long T;
	cin >> T;
	list<long long>::iterator it = res.end();
	while (T--) 
	{
		int op;
		cin >> op;
		if (op == 0)
		{
			long long x;
			cin >> x;
			it=res.insert(it, x);
		}
		else if (op == 1)
		{
			long long rank;
			cin >> rank;
			if (rank > 0)
				for (int i = 0; i < rank; i++)it++;
			else
			{
				rank *= -1;
				for (int i = 0; i < rank; i++)it--;
			}
		}
		else if (op == 2)
		{
			res.erase(it++);
		}
	}
	for (it = res.begin(); it != res.end(); it++)
		cout << *it << endl;
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  string s[n];
  for (int i=0; i<n; i++) cin>>s[i];
  map<char, long long> m;
  for (int i=0; i<n; i++) {
    ++m[s[i][0]];
  }
  char c[5] = {'M', 'A', 'R', 'C', 'H'};
  long long ans = 0;
  for (int i=0; i<5; i++) {
    for (int j=i+1; j<5; j++) {
      for (int k=j+1; k<5; k++) {
        if (i == j || j == k || k == i) {
          continue;
        }
        ans += m[c[i]] * m[c[j]] * m[c[k]];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u){
            a--;
    }
    else{
            b--;
    }
    cout<< a << " " << b <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i <= (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  //vector<int> p = prime((int)(sqrt(N))+1);
  vector<int> y(N+1, 0);
  
  int ans = 0;
  rep_(i, 1, N) {
    for(int j=1; j*i<=N; j++) {
      y[j*i]++;
    }
  }
  rep(i, N+1) ans += i*y[i];
  cout << ans << endl;

}

Measured memory_bytes: 81344
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main()
{
	double a, b, c, s, C;
	double S, L, h; 
	
	scanf("%lf%lf%lf", &a, &b, &C);
	c = sqrt(a*a + b*b - 2*a*b*cos(C*PI/180));
	L = a+b+c;
	s = L/2;
	S = sqrt(s*(s-a)*(s-b)*(s-c));
	h = 2*S/a;
	printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
	return 0;
}



Measured memory_bytes: 2104
n = gets.to_i

t,a = gets.split.map(&:to_i)

harray = gets.split.map(&:to_i)

min = 10**20
ans = -1
i = 0

n.times{
    
    key = (t-0.006*harray[i]-a).abs
    
    
    
    if key<min
    min = [min,key].min
    ans = i
    end
    i+=1
}



p ans+1


Measured memory_bytes: 1788
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def f(m, num_list):
    return_num = 0
    for num in num_list:
        return_num += m % num
    return return_num

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    n = i_input()
    num_list = i_list()

    lcm_num = lcm_list(num_list)

    print(f(lcm_num-1,num_list))
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 78620
from collections import Counter

N = int(input())
S = input()
count = Counter(S)
min_ = count['E'] if S[0]=='W' else count['E']-1
total = min_
for i in range(1,N):
    plus = 1 if S[i-1]=='W' else 0
    plus += -1 if S[i]=='E' else 0
    total += plus
    if total < min_:
        min_ = total
print(min_)

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N;
    cin >> N;
    map<int,int> dm;
    rep(i,N){
        int d; cin>>d;
        dm[d]++;
    }
    int M;
    cin >> M;
    rep(i,M){
        int t; cin>>t;
        dm[t]--;
        if(dm[t]<0){NO; return 0;}
    }
    YES;
    
    
    return 0;
}


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

main(){
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 1;
  for ( int i = 1; i < n; i++ ){
    if ( s[i-1] == 'x' && s[i] == 'x' ) break;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3276
#include <iostream>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int a, b, c;
    int wake = 0;
    int sum = 0;
    cin >> a >> b >> c;
    for (int i = 0; i < 100; i++) {
        int next = wake + a;
        if (wake <= c && c <= next) {
            cout << sum + c - wake<< endl;
            return 0;
        }
        wake = (next + b) % 60;
        sum += a + b;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3112
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int n,m;
struct drink
{
    ll p,x;
};
int main() {
    cin>>n;
    vector<ll>t(n+1);
    ll ans=0;
    for(int i=1;i<=n;i++)
        cin>>t[i],ans+=t[i];
    cin>>m;
    vector<drink> d(m+1);
    for(int i=1;i<=m;i++)
    {
        cin>>d[i].p>>d[i].x;
        cout<<ans-t[d[i].p]+d[i].x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int h = sc.nextInt();
	int a =sc.nextInt();
	int x = 0;
	int y = 0;
	int z =0;
	if(a>h) {
		x =1;
		System.out.println(x);
	}else if (h%a==0) {
		z=h/a;
		System.out.println(z);
	}else if (h%a!=0) {
		y = h/a +1;
		System.out.println(y);
	}
	sc.close();

	

}
}


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

int main(){
    int n, r;
    while(cin >> n >> r, n+r){
        int arr[n];
        for(int i = 0; i < n; i++)  arr[i] = n-i;
        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            int next[n], pos = 0;
            for(int j = p-1; j < p-1+c; j++)  next[pos++] = arr[j];
            for(int j = 0; j < p-1; j++)    next[pos++] = arr[j];
            for(int j = p-1+c; j < n; j++)    next[pos++] = arr[j];
            copy(next, next+n, arr);
        }
        cout << arr[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3068