akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e6 + 1;

int ile[MR];

int main()
{
	int N;
	scanf("%d", &N);
	REP(i, N)
	{
		int A;
		scanf("%d", &A);
		ile[A]++;
	}

	if (ile[1])
	{
		if (ile[1] == 1)
			printf("1\n");
		else
			printf("0\n");

		return 0;
	}

	int res = 0;
	FOR(i, 2, MR)
		if (ile[i] == 1)
		{
			int lim = sqrt(i) + 1;
			bool ok = 1;
			FOR(j, 2, lim)
				if (i%j == 0)
				{
					if (ile[j] || ile[i / j])
					{
						ok = 0;
						break;
					}
				}

			if (ok)
				res++;
		}

	printf("%d\n", res);

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 7160
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t A, B, C;
    cin >> A >> B >> C;
    if (A % 2 != 0 && B % 2 != 0 && C % 2 != 0) {
        int64_t min_ = min({A, B, C});
        int64_t max_ = max({A, B, C});
        int64_t middle = A + B + C - min_ - max_;
        cout << middle * min_ << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

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

ll MOD = 1e9 + 7;
int n, a, b;

ll modPow(ll a, ll n, ll p) {
    if (n == 1) return a % p;
    if (n % 2 == 1) return a * modPow(a, n-1, p) % p;
    ll tmp = modPow(a, n/2, p);
    return tmp * tmp % p;
}

ll modFact (ll start, ll end,ll p) {
    ll res = 1;
    for (int i = start; i < end + 1; i++) {
        res = res * i % p;
    }
    return res;
}

ll modComb (ll n, ll a, ll p) {
    ll x = modFact(n - a + 1, n, p);
    ll y = modFact(1, a, p);
    y = modPow(y, MOD-2, p);
    return x * y % MOD; 
}

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

    cout << (modPow(2, n, MOD) - 1 - modComb(n, a, MOD) - modComb(n, b, MOD) + MOD * 3) % MOD << endl;

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


int main(void){
  ll N, K;
  cin >> N >> K;
  vector<ll> cnt(40, 0);
  rep(i, N){
    ll A;
    cin >> A;
    rep(i, 40){
      cnt[i] += A % 2;
      A /= 2;
    }
  }
  reverse(cnt.begin(), cnt.end());
  vector<ll> k(40);
  rep(i, 40){
    k[i] = K % 2;
    K /= 2;
  }
  reverse(k.begin(), k.end());
  ll dp[41][2];
  rep(i, 40)rep(j, 2) dp[i][j] = -INFL;
  dp[0][0] = 0;
  rep(i, 40){
    ll plus = pow_long(2, 40 - i - 1);
    if(k[i] == 1){
      if(dp[i][1] != -INFL)dp[i+1][1] = dp[i][1] + plus * max(cnt[i], N - cnt[i]);
      dp[i+1][1] = max(dp[i+1][1], dp[i][0] + plus * cnt[i]);
      dp[i+1][0] = dp[i][0] + plus * (N - cnt[i]);
    }else{
      if(dp[i][1] != -INFL)dp[i+1][1] = dp[i][1] + plus * max(cnt[i], N - cnt[i]);
      dp[i+1][0] = dp[i][0] + plus * cnt[i];
    }
  }
  cout << max(dp[40][1], dp[40][0]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S, T;
    cin >> S >> T;
    int mi = INT32_MAX, pos = 0;
    rep(i, S.size() - T.size() + 1) {
        int cnt = 0;
        rep(j, T.size()) {
            if (S[i+j] != T[j]) cnt++;
        }
        if (mi > cnt) {
            mi = cnt;
            pos = i;
        }
    }

    cout << mi << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int N;
  cin>>N;
vector<long long int>d(N);
  
  for(long long int i=0;i<N;i++){
    cin>>d.at(i);
  }
  
  sort(d.begin(),d.end());
  
  
  if(N%2==0&&d.at(N/2-1)!=d.at(N/2)){
      cout<<d.at(N/2)-d.at(N/2-1)<<endl;
    }
      
   
    else{
cout<<0<<endl;
    }
  }


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

using namespace std;

int digit(int n){
    int len=0;
    while (n)len++,n/=10;
    return len;
}

int main()
{
    int n; cin>>n;
    int c=0,x;
    for (int i=1;i<=n;){
        x=digit(i);
        if (x&1){c++;i++;}
        else i*=10;
    }
    cout << c <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final long K = sc.nextLong();
			final int Q = sc.nextInt();
			
			long[] points = new long[N];
			Arrays.fill(points, K);
			
			long[] x = new long[N];
			for(int q = 0; q < Q; q++) {
				final int a = sc.nextInt() - 1;
				x[a] += 1;
			}
			
			for(int i = 0; i < N; i++) {
				points[i] -= (Q - x[i]);
			}
			
			for(int i = 0; i < N; i++) {
				System.out.println(points[i] > 0 ? "Yes" : "No");
			}

		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 52460
import java.util.*;

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

		if (S.matches("^A[a-z]+C{1}[a-z]+$")) {
			System.out.println("AC");
		} else {
			System.out.println("WA");
		}

	}
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define maxn 262144
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
struct node{
	int x,id;
}a[maxn];
bool cmp(node x,node y){
	return x.x<y.x;
}
int n,m,k,vis[maxn],c[maxn],d[maxn],b[maxn];
int ans=1e9;
void work(){
	int cnt=0,tot=0;
	for(int i=1,j;i<=n;){
		j=i;while(j<=n&&vis[j]==0)j++;
		cnt=0;for(int t=i;t<j;t++)c[++cnt]=b[t];
		sort(c+1,c+cnt+1);
		for(int t=1;t<=cnt-m+1;t++)d[++tot]=c[t];
		while(j<=n&&vis[j]==1)j++;
		i=j;
	}
	sort(d+1,d+tot+1);
	if(tot<k)return;
	ans=min(ans,d[k]-d[1]);
}
int main(){
	n=read();m=read();k=read();
	for(int i=1;i<=n;i++)a[i].x=b[i]=read(),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		work();vis[a[i].id]=1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4352
import scala.io.{StdIn => in}

object Main extends App {
  val s = in.readLine

  var ans = 1000
  for(i <- 0 until s.size-2) {
    val s2 = s.drop(i).take(3)
    // println(s2)
    ans = math.min(ans, (753 - s2.toInt).abs)
  }

  println(ans)
}

Measured memory_bytes: 27208
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
if S == 'ABC':
    print('ARC')
else:
    print('ABC')



Measured memory_bytes: 10840
def longest_common_subsequence(S, T):
    LS = len(S); LT = len(T)
    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
    return dp
    

def reconstruct_LCS(S, T, dp):
    tmp = []
    i, j = len(S), len(T)
    while i and j:
        if S[i - 1] == T[j - 1]:
            i, j = i - 1, j - 1
            tmp.append(S[i])
        elif dp[i][j] == dp[i - 1][j]:
            i -= 1
        else:
            j -= 1
    return ''.join(reversed(tmp))


s,t=input(), input()
print(reconstruct_LCS(s, t, longest_common_subsequence(s, t)))


Measured memory_bytes: 144688
from sys import exit
n,y=map(int,input().split())
y//=1000
for i in range(y//10+1):
    #k：いくら残ってるか
    #l：何枚使ったか
    k1=y-i*10
    for j in range(k1//5+1):
        k=k1-j*5
        l=i+j
        if k==n-l and i>=0 and j>=0 and k>=0:
            print(str(i)+" "+str(j)+" "+str(k))
            exit()
print("-1 -1 -1")


Measured memory_bytes: 40300
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func rScan() []rune {
	return []rune(Scan())
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := -int(1e+18)
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := int(1e+18)
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bPrint(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp1 int = 1000000007
var lp2 int = 998244353

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp1)
	sc.Split(bufio.ScanWords)
	n := iScan()
	ans := 0
	for i := 1; i <= n; i++ {
		if n%i != 0 {
			ans += n / i
		} else {
			ans += n/i - 1
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1788
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        k: i64,
    }

    let (a, b) = if k <= a {
        (a - k, b)
    } else if k <= a + b {
        (0, b - (k - a))
    } else {
        (0, 0)
    };

    println!("{} {}", a, b);
}


Measured memory_bytes: 2108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        long sum = 0;
        int minimum = BIG_NUM,maximum = -BIG_NUM;
 
        try {
 
            int N = Integer.parseInt(br.readLine());
 
            String first[] = br.readLine().split("[\\s]+");
            int array[] = new int[first.length];
 
            for(int i = 0; i < first.length; i++){
 
                array[i] = Integer.parseInt(first[i]);
                minimum = Math.min(minimum, array[i]);
                maximum = Math.max(maximum, array[i]);
                sum += array[i];
            }
 
            System.out.printf("%d %d %d\n",minimum,maximum,sum);
 
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
}



Measured memory_bytes: 31688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
// #include<cmath>

using namespace std;

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

int abs(int x){
    if (x > 0) return x;
    else return -x;
}

int dp[80][80][12801];
int main(){
    int h, w;
    cin >> h >> w;
    // h = 80;
    // w = 80;
    int a[h][w], b[h][w];
    rep(i, h)rep(j,w) cin >> a[i][j];
    rep(i, h)rep(j,w) cin >> b[i][j];
    // rep(i, h)rep(j,w) a[i][j] = 80;
    // rep(i, h)rep(j,w) b[i][j] = 80;
    int mx = (h + w) * 80;

    rep(i, mx+1){
        if(abs(a[0][0] - b[0][0]) == i){
            dp[0][0][i] = 1;
        }else{
            dp[0][0][i] = 0;
        }
    }
    
    rep(i, h)rep(j, w)rep(k, mx+1){
        int delta1 = abs(k - (a[i][j] - b[i][j]));
        int delta2 = abs(k + (a[i][j] - b[i][j]));
        if(delta1 > mx){
            delta1 = delta2;
        }
        if(delta2 > mx){
            delta2 = delta1;
        }


        if(i > 0 && j > 0){
            if(dp[i-1][j][delta1] == 1 || dp[i][j-1][delta1] == 1 || dp[i-1][j][delta2] == 1 || dp[i][j-1][delta2] == 1){
                dp[i][j][k] = 1;
            }else{
                dp[i][j][k] = 0;
            }
        }else if(i > 0 && j == 0){
            if(dp[i-1][j][delta1] == 1 || dp[i-1][j][delta2] == 1){
                dp[i][j][k] = 1;
            }else{
                dp[i][j][k] = 0;
            }
        }else if(i == 0 && j > 0){
            if(dp[i][j-1][delta1] == 1 || dp[i][j-1][delta2] == 1){
                dp[i][j][k] = 1;
            }else{
                dp[i][j][k] = 0;
            }           
        }
    }
    rep(i, mx+1){
        if(dp[h-1][w-1][i] == 1){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 320384
M,D=map(int,input().split())

d1=0
d2=0
count=0
for m in range(1,M+1):
    for d in range(1,D+1):
        d1=d%10
        d2=d//10
        if d1*d2==m and d2 >= 2 and d1 >= 2:
            count+=1

print(count)

Measured memory_bytes: 3060
s = input()
k = int(input())

def counter(s):
    count = 0
    for i,letter in enumerate(s):
        if i != 0:
            if letter == letter_prev:
                count += 1
                letter_prev = '0'
            else:
                letter_prev = letter
        else:
            letter_prev = letter
    return count    

if s.count(s[0]) == len(s):
    print(len(s)*k//2)
elif s[0] != s[-1]:
    print(counter(s)*k)
else:
    a = 0
    b = 0
    i = 0
    while s[i] == s[0]:
        i += 1
        a += 1
    i = 1
    while s[(-1)*i] == s[0]:
        i += 1
        b += 1
    print(counter(s)*k + (k-1)*((a+b)//2 - a//2 - b//2))

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

using namespace std;

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

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = N-1; j > i; j--) {
      if (A[j] < A[j-1]) {
	swap(A[j], A[j-1]);
	cnt++;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i == N-1) cout << endl;
    else cout << ' ';
  }
  cout << cnt << endl;
  return 0;
}

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

int main(){
	string str;
	while(1){
		getline( cin, str );
		if( str.length()==0 )	break;
		for( int i=0; i<=26; i++ ){
			for( int j=0; j<str.length(); j++ ){
				if( 'a'<=str[j] && str[j]<='z' ){
					str[j]++;
					if( str[j] == 'z'+1 )
						str[j] = 'a';
				}
			}
			if( str.find("the")+str.find("this")+str.find("that") != -3 ){
				cout << str << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import itertools
N, M = map(int, raw_input().split())
data = [map(int, raw_input().split()) for i in range(M)]
p = map(int, raw_input().split())
k = [data[i][0] for i in range(M)]
s = [data[i][1:] for i in range(M)]

candidate = []

def Check(switches):
    for i in range(M):
        if (sum([switches[s[i][j] - 1] for j in range(k[i])]) % 2) != p[i]:
            return 0
    return 1

print sum(Check(switches) for switches in itertools.product([0, 1], repeat=N))


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,temp,x1=0,y1=0,i,j,flag=0,rem,a,b,c,d;
    cin>>n;
    int t[n];
    int x[n];
    int y[n];
    i=0;
    temp=n;
    while(temp--)
    {
        cin>>t[i]>>x[i]>>y[i];
        i++;
    }
    temp=n;
    i=0;
    rem=0;
    while(temp--)
    {
        rem=t[i]-rem;
        d=abs(x1-x[i])+abs(y1-y[i]);
        if(d<=rem)
        {
            if(d%2!=rem%2)
            {
                cout<<"No"<<endl;
                return 0;
            }


        }
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
    rem=t[i];
    x1=x[i];
    y1=y[i];
    i++;


    }


    cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
        String RGB = sc.next();
        int Rcnt = 0;
        int Gcnt = 0;
        int Bcnt = 0;
        for(int i=0; i<N;  i++){
          char chari = RGB.charAt(i);
          if(chari=='R'){
            Rcnt++;
            continue;
          }
          if(chari=='G'){
            Gcnt++;
            continue;
          }
          Bcnt++;
        }
        long cnt = (long) Rcnt*Gcnt*Bcnt;
      	int sp = (int) Math.floor((N-3)/2);
      
        for(int i=0; i<sp+1;  i++){
        	cnt -= detecter(N, i, RGB);
        }
      	System.out.println(cnt);
        return;
	}
  public static long detecter(int N, int NN, String RGB){
        long cnt = (long) 0;
    	NN++;
        for(int i=0; i<N;  i++){
          if(N<=(i+2*NN)){
            return cnt;
          }
          if(RGB.charAt(i)==RGB.charAt(i+NN)){
            continue;
          }
          if(RGB.charAt(i)==RGB.charAt(i+(2*NN))){
            continue;
          }
          if(RGB.charAt(i+NN)==RGB.charAt(i+(2*NN))){
            continue;
          }
          cnt++;
        }
        return cnt;
	}
}


Measured memory_bytes: 36752
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int V[N];
  for(int i = 0; i < N; i++){
    cin >> V[i];
  }
  int C[N];
  for(int i = 0; i < N; i++){
    cin >> C[i];
  }
  int ans = 0;
  for ( int i = 0; i < N ; ++ i ) {
    if ( V [ i ] > C [ i ]) {
      ans += V [ i ] - C [ i ];
    }
  }
  cout << ans << endl ;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<int> a(N);
    int m = inf, M = -1;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        m = min(a[i], m); M = max(a[i], M);
    }
    cout << M - m << endl;
    return 0;
}

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

bool isPassed(int n, int s){
  return (s >> n-1 >> 4) & 1;
}

int addPassed(int n, int s){
  int r = s | (1 << n-1 << 4);
  return (r & 0b111111110000) | n;
}

int getCurrent(int s){
  return s & 0b000000001111;
}

vector<int> moveNext(vector<int> a, vector<int> b, vector<int> state){
  vector<int> nextState;  
  for (int i=0;i<state.size();i++){
    int c = getCurrent(state[i]);
    for (int j=0;j<a.size();j++){
      if (a[j]==c && !isPassed(b[j], state[i])){
        nextState.push_back(addPassed(b[j], state[i]));
      }
    }
    for (int j=0;j<b.size();j++){
      if (b[j]==c && !isPassed(a[j], state[i])){
        nextState.push_back(addPassed(a[j], state[i]));
      }
    }
  }
  return nextState;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
  }

  vector<int> state(1);
  state[0]=addPassed(1, 0);
  for (int i=1;i<n;i++){
    state = moveNext(a,b,state);
  }
  
  cout << state.size() << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int n, k, s; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (), k = read <int> (), s = read <int> ();
	if(s < 1e9)
	{
		for(int i = 1; i <= k; i++)
			printf("%d ", s);
		for(int i = k + 1; i <= n; i++)
			printf("%d ", s + 1);
		puts(""); 
	}
	else
	{
		for(int i = 1; i <= k; i++)
			printf("%d ", s);
		for(int i = k + 1; i <= n; i++)
			printf("%d ", 1);
		puts(""); 
	}
	return 0; 
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N, K; cin >> N >> K;
    vector<ll> X(N, 0);
    REP(i, N) {
        cin >> X[i];
    }
    // print(N, K);
    // print(X);
    ll cost = LINF;
    // vector<pair<int, int>> cands; // (left, right)
    REP(i, N-K+1) {
        ll tmpC = 0;
        // cands.push_back(make_pair(X[i], X[i+K-1]));
        // cout << cands[i].first << ", " <<  cands[i].second << endl;;
        ll left = X[i];
        ll right = X[i+K-1];
        // cout << "(left, right) = ";
        // cout << left << ", " <<  right << endl;;
        if(left*right >= 0) { // same direction
            tmpC = (ll)(max(abs(left), abs(right)));
        } else { // different direction
            if(abs(left) < abs(right)) {
                tmpC = (ll)(2 * abs(left) + abs(right));
            } else {
                tmpC = (ll)(2 * abs(right) + abs(left));
            }

        }
        chmin(cost, tmpC);
    }

    print(cost);
    
    return 0;
}

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

int main() {
    char b;
    cin >> b;
    if(b=='A') cout << 'T' << endl;
    if(b=='C') cout << 'G' << endl;
    if(b=='T') cout << 'A' << endl;
    if(b=='G')cout << 'C' << endl;
    return 0;
}

Measured memory_bytes: 3612
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	for (int i = 1; i <= 5; ++i)
	{
		int x; cin >> x;
		if (x == 0)
		{
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3592
S = input()
count = 0
dic = {}
ans = [0 for i in range(len(S))]
ind = []
for i in range(len(S)-1):
  if S[i]=='R' and S[i+1]=='L':
    ind += [i]
j = 0
k = 0
for i in range(len(S)):
  s = S[i]
  if s=='R':
    while i>ind[j]:
      j+=1
    if (ind[j]-i)%2==0:
      ans[ind[j]]+=1
    else:
      ans[ind[j]+1]+=1
  if s=='L':
    while ind[k]<i:
      k +=1
      if k==len(ind):
        break
    k -= 1
    if (ind[k]-i)%2==0:
      ans[ind[k]]+=1
    else:
      ans[ind[k]+1]+=1
A = [str(i) for i in  ans]
print(' '.join(A))


Measured memory_bytes: 12924
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    long long x;
    while(cin>>x){
        ll p = 100;
        int cnt = 0;
        while(p<x){
            p += p/100;
            ++cnt;
        }
        cout<<cnt<<endl;
    }
    
    return 0;
}

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

using namespace std;

int main() {
    int x;
    cin >> x;
    int h = 0, m = 0, s = 0;
    for(int i = 1; i <= x; i++) {
        s++;
        if(s == 60) {
            m++;
            s = 0;
        }
        if(m == 60) {
            h++;
            m = 0;
        }
    }
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3108
#include<stdio.h>
#include<string.h>

int main(){
  char s[10], t[10]; scanf("%s%s",s,t);
  int a,b; scanf("%d%d",&a,&b);
  char u[10]; scanf("%s",u);
  if (strcmp(s,u)==0) printf("%d %d\n",a-1,b);
  else printf("%d %d\n",a,b-1);
}

Measured memory_bytes: 128
num = gets.to_i
num.times do
  left, right = [], []
  arr = gets.chomp.split(' ').map(&:to_i)
  arr.each do |a|
    if (left.last || 0) < a
      left << a
    elsif (right.last || 0) < a
      right << a
    else
      break
    end
  end
  puts (arr.size == (left.size + right.size)) ? 'YES' : 'NO'
end

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
 
  double w, h, x, y; cin >> w >> h >> x >> y;
  if(x == w / 2 && y == h/2){
    cout << w * h / 2 << " " << "1" << endl;
  }else{
    cout << w * h / 2 << " " << "0" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  set<int> s{};
  for (int i = 1; i <= 100000; i += 2) {
    if (isSosuu(i) && isSosuu((i+1) / 2)) {
      s.emplace(i);
    }
  }
  int Q; cin >> Q;
  for (int _ = 0; _ < Q; ++_) {
    int l, r; cin >> l >> r;
    auto itrL = s.lower_bound(l);
    auto itrR = s.upper_bound(r);
    auto distance = std::distance(itrL, itrR);
    cout << distance << CRLF;
  }

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  
  cin >> N;
  
  vector<int> L(N);
  
  for(int i = 0;i < N;++i){
    cin >> L[i];
  }
  
  sort(L.begin(),L.end());
  
  int a = 0;
  
  for(int i = 0;i < N - 2;++i){
    for(int j = i + 1;j < N - 1;++j){
      int num = L[i] + L[j];
      int num2 = lower_bound(L.begin(),L.end(),num) - L.begin();
      int num3 = num2 - j - 1;
      a = a + num3;
    }
  }
  
  cout << a << endl;
  
}



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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}



//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll N,M;cin>>N>>M;
  ll ans =0;
  ll Mm =M;
  for(ll i=1;i*i<=M;i++){
    if(M%i==0){
      if(M/i>=N)ans =max(ans,i);
      if(i>=N)ans=max(ans,M/i);
    }
  }
  cout<<ans<<endl;
    
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
using namespace std;
using LLI = long long int;


int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<LLI> h(N);
    for (int i=0; i<N; i++) {
        cin >> h[i];
    }

    sort(h.begin(), h.end());

    LLI d = 1e10;
    for (int i=0; i+K-1<N; i++) {
        d = min(d, h[i+K-1]-h[i]);
    }

    cout << d;

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <numeric>
 
int const N = 1000001;
 
int spf[N], u[N], s[17], d, i, j, k;
char const* r = "pairwise";
 
int main() {
    while (++i < N)spf[i] = i;
    for (i = 2; i * i < N; i++)
        for (j = i * i; j < N; j += i)
            if (spf[j] == j) spf[j] = i;
    for (scanf("%*d"); ~scanf("%d", &j); k = 0) {
        d = std::gcd(d, j);
        for (; j > 1; j /= i) {
            if (u[s[k++] = i = spf[j]]) r = "setwise";
        }
        while(k--) u[s[k]] = 1;
    }
    printf("%s coprime\n", d > 1 ? "not" : r);
    return 0;
}


Measured memory_bytes: 9544
#include<bits/stdc++.h>
using namespace std;
typedef long l;
#define FOR(i,s,e) for(int i = (s); i < (e); i++)
long a,b,c;
int main()
{
    l n,t,x,y,k;
    a = b = c = 0;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>t>>x>>y;
        k = abs(a - x) + abs(b - y);

        if(c + k > t ) { cout<<"No"<<'\n'; return 0;}
        if(k%2 != (t - c) % 2){ cout<<"No"<<'\n'; return 0;}

        a = x;
        b = y;
        c = t;

    }
    cout << "Yes"<<'\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
stock = 0
mon = 1000

stock = int(mon / A[0])
mon = mon % A[0]
for i in range(0, n-1):
    if A[i] < A[i+1]:
        stock += mon // A[i]
        mon = mon % A[i]
    else:
        mon += stock * A[i]
        stock = 0
if stock > 0:
    mon += stock * A[n-1]
print(int(mon))

Measured memory_bytes: 9200
use std::cmp::max;
use std::collections::HashMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let mut map = HashMap::new();

    let n: usize = read();
    for _ in 0..n {
        let s: String = read();
        *map.entry(s).or_insert(0) += 1;
    }

    let m: usize = read();
    for _ in 0..m {
        let s: String = read();
        *map.entry(s).or_insert(0) -= 1;
    }

    println!("{}", max(0, *map.iter().max_by_key(|&k| k.1).unwrap().1));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
def power(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        k = power(m, n // 2)
        return k * k % 1000000007
    else:
        k = power(m, (n - 1) // 2)
        return k * k * m % 1000000007


m, n = [int(x) for x in input().split()]
print(power(m, n))



Measured memory_bytes: 5604
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(A, B, C),
    X is A + B + C - max(max(A, B), C),
    writeln(X).


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

vector< vector<int> > to(200005);
vector<int> ans;

void dfs(int c,int p=-1){
  for(int u:to.at(c)){
    if(u==p){
      continue;
    }
    ans.at(u)+=ans.at(c);
    dfs(u,c);
  }
}
int main(){
  int n,q;
  cin >> n >> q;
  //v.resize(N);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  ans.resize(n);
  for(int i=0;i<q;i++){
    int p,x;
    cin >> p >> x;
    p--;
    ans.at(p)+=x;
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 26624
#include<bits/stdc++.h>
using lint=long long;
void cmn(std::string &s,std::string t){if(s>t)s=t;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::string s,t;std::cin>>s>>t;
    lint l=s.length(),m=t.length();
    std::string ans=std::string(l,'z'+1);
    for(lint i=0;i<=l-m;i++){
        std::string now=s;
        for(lint j=0;j<=m;j++){
            if(j==m){
                for(char&c:now){
                    if(c=='?')c='a';
                }
                cmn(ans,now);
                break;
            }
            if(s.at(i+j)!=t.at(j)&&s.at(i+j)!='?')break;
            now.at(i+j)=t.at(j);
        }
    }
    if(ans.front()=='z'+1){
        std::cout<<"UNRESTORABLE"<<'\n';
        return 0;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    s=STR()
    if k>1and k!=n:
        S=s[0:k-1]+s[k-1].lower()+s[k:n]
        print(S)
    elif k==1:
        S=s.capitalize()
        S=S.swapcase()
        print(S)
    else:
        S=s[0:n-1]+s[n-1].lower()
        print(S)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)

using namespace std;

int main() {
	int X;
	int Fx = 0, ans = 0;
	cin >> X;

    int m = X;
	while (m != 0) {
		Fx += m % 10;
		m /= 10;
	}

  	ans = X % Fx;

	if (ans == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    while (true) {
        int n, x;
        scanf("%d %d", &n, &x);
        if (!n && !x) return 0;

        int res=0;
        for (int i=1; i<=n; ++i)
            for (int j=i+1; j<=n; ++j) {
                int k=x-(i+j);
                if (j<k && k<=n)
                    ++res;
            }

        printf("%d\n", res);
    }
}

Measured memory_bytes: 2724
#include<bits/stdc++.h> 
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c) 
  {
     cout<<"Yes"<<endl;
  }
  else 
  {
     cout<<"No"<<endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, a, b;

ll mpow(ll x, ll p) {
  ll result = 1;
  for(; p>0; p >>= 1, x = x * x % mod) {
    if(p & 1) result = result * x % mod;
  }
  return result;
}

ll comb(ll x, ll p) {
  ll c = 1, d = 1;
  REP(i, p) {
    c *= x - i;
    c %= mod;
    d *= i + 1;
    d %= mod;
  }

  return c * mpow(d, mod - 2) % mod;
}

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

  cin >> n >> a >> b;
  ll ans = mpow(2, n);
  ans--;

  ans -= (comb(n, a) + comb(n, b));
  while(ans < 0) ans += mod;
  cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int a, b;
  cin >> a >> b;
  cout << max(a + b, max(a, b) + (max(a, b) - 1)) << '\n'; 
  return 0;
}

Measured memory_bytes: 256