akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
def ii(): return int(readline())
def mi(): return map(int, readline().rstrip().split())
def li(): return list(readline().rstrip())
def lmi(): return list(map(int, readline().rstrip().split()))
def end(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    s = input().rstrip()
    cnt = 0
    for i in range(N - 2):
        if s[i:i + 3] == "ABC":
            cnt += 1
    print(cnt)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
const int mod=1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
ll fact[100001],factiv[100001];
int finiv(int a,int b,int *x,int *y)
{
    if(a==0)
    {
        *x=0;*y=1;
        return b;
    }
    int x1,y1;
    int gcd=finiv(b%a,a,&x1,&y1);
    *x=y1-(b/a)*x1;
    *y=x1;
    return gcd;
}
int inv(int i)
{
    int x,y;
    finiv(i,mod,&x,&y);
    return x;

}
void factf()
{
    fact[1]=1;factiv[1]=1;factiv[0]=1;
    //invt[1]=1;
    for(int i=2;i<100001;i++)
    {
        fact[i]=fact[i-1]*i%mod;
       // invt[i] =mod - invt[mod % i] * (mod / i) % mod;
        factiv[i]=factiv[i-1]*inv(i)%mod;
    }

}
ll comb(int a,int b)
{
    if(a<b) return 0;
  //  if (a < 0 || b < 0) return 0;
    return fact[a]*(factiv[a-b]*factiv[b]%mod)%mod;
}
int main()
{
    fastio;
   // factf();
    //fopen();
    int h,w,n;
    cin>>h>>w>>n;
    cout<<n/max(h,w)+1*bool(n%max(h,w));

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();
    static PrintWriter out = new PrintWriter(System.out);

    void solve() {
        int n = scanner.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            a[i] = scanner.nextInt();
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int b = scanner.nextInt();

            if (a[i] > b) {
                ans += b;
            } else {
                ans += a[i] + Math.min(a[i + 1], b - a[i]);
                a[i + 1] = Math.max(0, a[i + 1] - b + a[i]);
            }
        }
        out.println(ans);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.close();
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return tokenizer.nextToken();
        }

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

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

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

Measured memory_bytes: 43916
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	int n;
	while (in >> n) {
		if (!n)break;
		int a = 1000 - n,ans=0;
		int c[5] = { 500, 100, 50, 10, 5 };
		REP(i, 5) {
			ans += a / c[i];
			a %= c[i];
		}
		out << ans + a << endl;
	}
	return 0;

}

Measured memory_bytes: 2952
let (n, m) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n m -> (n, m)
let arr = Array.init m @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d %d" @@ fun x y z -> (x - 1, y - 1, z)

let h = (fun tbl -> Array.iter (fun (x, y, _) -> Hashtbl.add tbl x y; Hashtbl.add tbl y x) arr; tbl) (Hashtbl.create n)

let f arr i g =
  let que = Queue.create () in
  Queue.add i que;
  while not (Queue.is_empty que) do
    let i = Queue.pop que in
    arr.(i) <- g;
    List.iter (fun i -> if arr.(i) = -1 then Queue.add i que) @@ Hashtbl.find_all h i;
  done

let () =
  let arr = Array.make n (-1) in
  let ans = ref 0 in
  for i = 0 to n - 1 do
    if arr.(i) = -1 then begin
      f arr i !ans;
      ans := !ans + 1
    end
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 26644
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N;	cin>>N;
	vector<string> S(N);
	for(int i=0;i<N;i++) cin>>S[i];
	sort( S.begin(), S.end() );
	//for( int i=0; i<N; i++ ) cout << "S["<<i<<"]:"<<S[i]<<endl;
	int count=1;
	for( int i=1;i<N;i++ ){
		if( S[i-1]!=S[i] ) count++;
	}
	cout << count << endl;
}



Measured memory_bytes: 7584
x,n = map(int,input().split())
P = [int(i) for i in input().split()]
kouho=[int(i) for i in range(-200,200)]
List = []
ans = 10**9
for i in kouho:
    if i not in P:
        tmp = abs(x-i)
        if tmp<ans:
            ans = tmp
            List = [i]
        elif tmp == ans:
            List.append(i)
List.sort()
print(List[0])

Measured memory_bytes: 9204
public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(a + b >= c ? "Yes" : "No");
    }
}




Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main() {
  char Nc[4];
  int N[4];
  for (int i = 0; i < 4; i++) {
    cin >> Nc[i];
    N[i] = Nc[i] - '0';
  }
  int waAB = N[0]+N[1], saAB =N[0]-N[1], waCD = N[2]+N[3], saCD = N[2]-N[3];
  if (waAB + waCD == 7)
    cout << N[0] << "+" << N[1] << "+" << N[2] << "+" << N[3] << "=7\n";
  else if (waAB + saCD == 7)
    cout << N[0] << "+" << N[1] << "+" << N[2] << "-" << N[3] << "=7\n";
  else if (waAB - waCD == 7)
    cout << N[0] << "+" << N[1] << "-" << N[2] << "-" << N[3] << "=7\n";
  else if (waAB - saCD == 7)
    cout << N[0] << "+" << N[1] << "-" << N[2] << "+" << N[3] << "=7\n";
  else if (saAB + waCD == 7)
    cout << N[0] << "-" << N[1] << "+" << N[2] << "+" << N[3] << "=7\n";
  else if (saAB + saCD == 7)
    cout << N[0] << "-" << N[1] << "+" << N[2] << "-" << N[3] << "=7\n";
  else if (saAB - waAB == 7)
    cout << N[0] << "-" << N[1] << "-" << N[2] << "-" << N[3] << "=7\n";
  else if (saAB - saCD == 7)
    cout << N[0] << "-" << N[1] << "-" << N[2] << "+" << N[3] << "=7\n";
  return 0;
}


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

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
long long lcm(int a, int b) {
	return (long long)a * b / gcd(a, b);
}
int main() {
	int A, B;
	cin >> A >> B;
	cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (k, a, b) = {
        let i = read::<u64>();
        (i[0], i[1], i[2])
    };

    if a >= b || b - a <= 1{
        println!("{}", k + 1);
        return;
    } 

    let ans: u64 = if (k + 1 - a) % 2 == 0 {
        (b - a) * (k + 1 - a) / 2 + a
    } else {
        (b - a) * (k - a) / 2 + a + 1
    };

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


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
using namespace std;
int mass[17][17];
int memo[17][17];

int solve( int x ,int y ,int maxx ,int maxy);
int main(){
  int n ,x ,y;
  int cx ,cy;
  while( true ){
    memset( mass ,0 ,sizeof( mass ) );
    memset( memo ,0 ,sizeof( memo ) );
    cin >> x >> y;
    if( x == 0 && y == 0 ) break;

    mass[y-1][x-1] = 2; // goal地点の指定
    
    cin >> n;
    for( int i=0 ; i<n ; i++ ){ // 行けない地点の指定
      cin >> cx >> cy;
      mass[cy-1][cx-1] = 1;
    }

    cout << solve( 0 ,0 ,x-1 ,y-1 ) << endl; // go 再帰
  }
}


int solve( int x ,int y ,int maxx ,int maxy ){
  if( memo[y][x] != 0 ) return memo[y][x];
  else if( mass[y][x] == 2 ) return 1;      // goal
  else if( x > maxx || y > maxy ) return 0;  // どっか行った
  else if( mass[y][x] == 1 ) return 0; // いけねぇ 
  else return memo[y][x] = (solve( x+1 ,y ,maxx ,maxy ) + solve( x ,y+1 ,maxx ,maxy ) );
}

Measured memory_bytes: 1160
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            int a, b, A, B, C, max;

            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            A = a + b;
            B = a - b;
            C = a * b;

            max = 0;
            if (A >= B && A >= C)
                max += A;
            else if (B > A && B > C)
                max += B;
            else if (C>=A && C>=B)
                max += C;


            Console.WriteLine(max);

            Console.ReadKey();
        }
    }
}


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

int main(){
    int n;
    cin >> n;
    int ans;
    ans=n%1000;
    if(ans==0){
        cout << 0 << endl;
    }
    else{
        cout << 1000-ans << endl;
    }
    

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  ll h,w;
  cin>>h>>w;
  vector<string> s(h);
  cin>>s;

  constexpr ll dx[]={1,0,-1,0};
  constexpr ll dy[]={0,1,0,-1};
  using T3 = tuple<ll,ll,ll>;
  queue<T3> que;
  que.emplace(1,0,0);
  vector<vector<ll>> dist(h,vector<ll>(w,INF));
  while(!que.empty()){
    ll c,y,x;
    tie(c,y,x) = que.front();
    que.pop();
    if( chmin(dist[y][x],c) ){
      rep(i,4){
        ll ny,nx,nc;
        ny = y+dy[i];
        nx = x+dx[i];
        nc = c+1;
        if(ny==-1||nx==-1||ny==h||nx==w)continue;
        if(s[ny][nx]=='#')continue;
        que.emplace(nc,ny,nx);
      }
    }
  }
  ll white = 0;
  rep(i,h)rep(j,w)if(s[i][j]=='.')white++;

  if(dist[h-1][w-1]==INF)cout<<-1<<endl;
  else cout<< white-dist[h-1][w-1] <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
bool comp(ll a, ll b)
{
   return a>b;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t, u;
    cin>>s>>t;
    ll a, b;
    cin>>a>>b;
    cin>>u;
    if(u==s)
        a--;
    else
        b--;
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
  
typedef struct _card {
  int number;
  char suit;
} CARD;
  
CARD A[100000], I[100000];
char inputs[1000000];
char *ptr = inputs;
  
void exchange(CARD *a, CARD *b);
int Partition(CARD A[], int p, int r);
void Quicksort(CARD A[], int p, int r);
  
int nextInt(void) {
  int v = 0;
  while (*ptr < '0' || *ptr > '9') ++ptr;
  while (*ptr >= '0' && *ptr <= '9') {
    v = v * 10 + (int)(*ptr - '0');
    ++ptr;
  }
  return v;
}
  
char nextSuit(void) {
  while (*ptr < 'A' || *ptr > 'Z') ++ptr;
  return *ptr;
}
  
int main(){
  int n;
  int stable = 1;
  int i, j, c, d;
      
  fread(inputs, sizeof(char), 1000000, stdin);
      
  n = nextInt();
      
  for (i = 0; i < n; ++i) {
    A[i].suit = nextSuit();
    A[i].number = nextInt();
    I[i] = A[i];
  }
      
  Quicksort(A, 0, n - 1);
      
  for (i = 0; i < n; ++i) {
    if (i == 0) {
      c = 0;
    } else if (A[i].number != A[i - 1].number) {
      c = 0;
    } else {
      ++c;
    }
    d = 0;
    for (j = 0; j < n; ++j) {
      if (I[j].number == A[i].number) {
	if (c == d) {
	  if (I[j].suit != A[i].suit) {
	    stable = 0;
	  }
	  break;
	}
	++d;
      }
    }
    if (stable == 0) {
      break;
    }
  }
      
  if (stable == 1) {
    puts("Stable");
  } else {
    puts("Not stable");
  }
      
  for (i = 0; i < n; ++i) {
    printf("%c %d\n", A[i].suit, A[i].number);
  }
      
  return 0;
}
  
void exchange(CARD *a, CARD *b) {
  CARD t = *a;
  *a = *b;
  *b = t;
}
  
int Partition(CARD A[], int p, int r) {
  CARD x = A[r];
  int i = p - 1;
  int j;
  for (j = p; j < r; ++j) {
    if (A[j].number <= x.number) {
      ++i;
      exchange(&A[i], &A[j]);
    }
  }
  exchange(&A[i + 1], &A[r]);
  return i + 1;
}
  
void Quicksort(CARD A[], int p, int r) {
  int q;
  if (p < r) {
    q = Partition(A, p, r);
    Quicksort(A, p, q - 1);
    Quicksort(A, q + 1, r);
  }
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int L,R,d;
  cin >> L >> R >> d;
  int score=0;
  for(int i=L; i<=R; ++i){
    if(i%d == 0)
      ++score;
  }
  cout << score << endl;
  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int n,cnt1[220000],cnt2[220000],ans=1e9;
string s;
int main()
{
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i==0)
		{
			cnt1[i]=(s[i]=='.');
			cnt2[i]=(s[i]=='#');
		}
		else
		{
			cnt1[i]=cnt1[i-1]+(s[i]=='.');
			cnt2[i]=cnt2[i-1]+(s[i]=='#');
		}
	}
	for(int i=0;i<s.size();i++)
	{
		if(i==0)
		{
			ans=min(ans,min(cnt1[s.size()-1],cnt2[s.size()-1]));
		}
		else
		{
			ans=min(ans,cnt2[i-1]+cnt1[s.size()-1]-cnt1[i-1]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2180
# coding: utf-8

def is_possible(q, mod):

    for i in range((mod//5)+1):
        if 5 * i > mod:
            break
        for j in range((mod//4)+1):
            if (5 * i) + (4 * j) > mod:
                break
            for k in range((mod//3)+1):
                if (5 * i) + (4 * j) + (3 * k) > mod:
                    break
                for l in range((mod//2)+1):
                    if (q - (i + j + k + l)) > mod - ((5 * i) + (4 * j) + (3 * k) + (2 * l)):
                        return True
                    elif (5 * i) + (4 * j) + (3 * k) + (2 * l) > mod:
                        break

    return False


X = int(input())

for i in range(6):
    if X % (100+i) == 0:
        print(1)
        exit(0)

q, mod = divmod(X, 100)

if is_possible(q, mod):
    print(1)
else:
    print(0)

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

int v[100];
double r[100];

double calc(int M)
{
	double sum = 0;
	for(int i=0; i<M; i++) sum += r[i];
	for(int i=0; i<M; i++) r[i] /= sum;

	double res = 0;
	for(int i=0; i<M; i++)
		res += r[i] * v[i];

	return res;
}

int main()
{
	int T;
	double mx=0;
	cin >> T; T++;
	while(T--) {
		int N,M;
		cin >> N >> M;
		for(int i=0; i<M; i++)
			cin >> v[i] >> r[i];

		if(T!=0) {
			mx = max(mx, calc(M));
		}
		else {
			cout << (mx > calc(M) ? "YES":"NO") << endl;
		}

	}
	
}

Measured memory_bytes: 0
N = int(input()) - 1
k = 26
n = 1
while N >= k:
    N -= k
    k *= 26
    n += 1
ans = []
for i in range(n):
    ans.append(chr((N % 26) + ord('a')))
    N //= 26
print(''.join(ans[::-1]))


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

int main() {
  int n, m, i, a;
  cin >> n >> m;
  
  vector<int> x(n);
  for(i = 0; i < 2 * m; i++){
    cin >> a;
    x.at(a - 1)++;
  }
  
  for(i = 0; i < n; i++){
    cout << x.at(i) << endl;;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
}


Measured memory_bytes: 256
n_str = list(input())
n = [int(i) for i in n_str]
l = len(n)-1
for i in range(2 ** l):
    sum = n[0]
    op_list = []
    for j in range(l):
        if (i >> j) & 1:
            sum += n[j+1]
            op_list.append('+')
        else:
            sum -= n[j+1]
            op_list.append('-')
    #print(sum, op_list)
    if sum == 7:
        print(n_str[0]+op_list[0]+n_str[1]+op_list[1]+n_str[2]+op_list[2]+n_str[3]+'=7')
        exit()


Measured memory_bytes: 8968
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000LL
#define M 1000000007
typedef long long ll;
using namespace std;
const int N = 105001;

ll a , b;
map<ll,int> freq;
vector<ll> dv;
map<ll,int>::iterator it;
signed main(){
    cin >> a >> b;
    for(ll i = 1 ; i*i <=a ; i++){
        if(a%i)continue;
        freq[i]|=1;
        freq[a/i]|=1;
    }
    for(ll i = 1 ; i*i <=b ; i++){
        if(b%i)continue;
        freq[i]|=2;
        freq[b/i]|=2;
    }
    for(it = freq.begin() ; it!=freq.end() ; it++){
        if(it->S!=3)continue;
        dv.push_back(it->F);
    }

    int ans = 0;
    for(int i = 1 ; i < dv.size() ; i++){
        if(!dv[i])continue;
        for(int j = i+1 ; j < dv.size() ; j++){
            if(dv[j]%dv[i])continue;
            dv[j]=0;
        }
    }
    for(int i = 0 ; i < dv.size() ; i++){
        ans+=dv[i]!=0;
    }
    cout << ans << endl;



    return 0;
}


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

//typedef long long signed int ll
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

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

	int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string N;
	cin>>N;
	REP(i,3){
	    if(N[i]==N[i+1]){
	        cout<<"Bad"<<endl;
	        return 0;
	    }
	}
	cout<<"Good"<<endl;
		return 0;
}

Measured memory_bytes: 256
O=input()
E=input()
T=""
if len(O)-len(E)==0:
  for i in range(len(O)):
    T += O[i]+ E[i]
  print(T)
else:
  for i in range(len(E)):
    T += O[i]+ E[i]
  T+=O[-1]
  print(T)

Measured memory_bytes: 3060
n,a,b,c = map(int, input().split())
d = {}
d["A"] = a
d["B"] = b
d["C"] = c

pl = [input() for _ in range(n)]

res = []
for i in range(n):
    p = pl[i]
    if d[p[0]]==d[p[1]]==0:
        print("No")
        exit()
    elif d[p[0]]==0:
        res.append(p[0])
        d[p[0]] += 1
        d[p[1]] -= 1
    elif d[p[1]]==0:
        res.append(p[1])
        d[p[0]] -= 1
        d[p[1]] += 1
    elif i==n-1:
        res.append(p[0])
    elif p[0] in pl[i+1]:
        res.append(p[0])
        d[p[0]] += 1
        d[p[1]] -= 1
    else:
        res.append(p[1])
        d[p[0]] -= 1
        d[p[1]] += 1

    



print("Yes")
for p in res:
    print(p)


Measured memory_bytes: 17092
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;



void mymain(){
    int a,b;
    cin >> a >> b;
    if(a<=9 && b<=9)
        cout << a*b <<endl;
    else
        cout << -1 <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int A, B;
    cin >> A >> B;
    for(int x = 1; x <= 1250; x++){
        if(int(x * 0.08) == A and int(x * 0.1) == B){
            cout << x << endl;
            return 0;
        }
    }
    puts("-1");
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define oo 1000000010
const int N = 1000010;
int n;
string s;
char tmpread[N];
int cur[N];

inline int nck(int n,int k){
	if(k > n) return 0;
	if(k == n) return 1;
	return (cur[n] > cur[k] + cur[n - k] ? 0 : 1);
}

int get(string &s){
	int res = 0;
	for(int i = 0 ;i < (int)s.size();i++){
		if(s[i] == '0') continue;
		res ^= nck((int)s.size() - 1 , i);
	}
	return res;
}



int main(){
	for(int i = 2;i < N;i *= 2){
		for(int j = i ;j < N;j += i) cur[j]++;
	}
	for(int i = 2;i < N;i++) cur[i] += cur[i - 1];
	scanf("%d",&n);
	scanf("%s",tmpread);
	s = (string)tmpread;
	bool one = false, two = false;
	for(int i = 0 ;i < n;i++){
		s[i]--;
		if(s[i] == '1') one = true;
		if(s[i] == '2') two = true;
	}
	if(one && two){
		for(int i = 0 ;i < n;i++) if(s[i] == '2') s[i] = '0';
		two = false;
	}
	if(one){
		printf("%d\n",get(s));
	}
	else{
		printf("%d\n",get(s) * 2);
	}
	return 0;
}

Measured memory_bytes: 6144
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<assert.h>
#include<ctime>
using namespace std;
#define LL long long
const int maxn = 1e5+10;
const int maxm = 1e5+10;
double pi = acos(-1.0);

//struct edge{
//    int from, to, cost, next;
//}e[maxn*2];
//int head[maxn], tot;
//inline void add(int a, int b, int c) {
//    e[tot].from = a, e[tot].to = b, e[tot].cost = c, e[tot].next = head[a], head[a] = tot++;
//}
//namespace fastIO {
//    #define BUF_SIZE 100000
//    //fread -> read
//    bool IOerror = 0;
//    inline char nc() {
//        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
//        if(p1 == pend) {
//            p1 = buf;
//            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
//            if(pend == p1) {
//                IOerror = 1;
//                return -1;
//            }
//        }
//        return *p1++;
//    }
//    inline bool blank(char ch) {
//        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
//    }
//    inline void read(int &x) {
//        char ch;
//        while(blank(ch = nc()));
//        if(IOerror)
//            return;
//        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
//    }
//    #undef BUF_SIZE
//};
//using namespace fastIO;
int a[maxn]; int cnt[maxn];
int main(){
    int n;
    while(~scanf("%d", &n)) {
        memset(cnt, 0, sizeof(cnt));
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            a[i]++;
            cnt[a[i]]++;
            cnt[a[i]+1]++;
            cnt[a[i]-1]++;
        }
        int maxv = 0;
        for(int i = 0; i <= 100001; i++){
            maxv = max(maxv, cnt[i]);
        }
        printf("%d\n", maxv);
    }
}


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

using namespace std;

class Prime {
// n以下の素数を列挙する
public:
  const int n;
  vector<bool> is_prime;
  vector<int> primes;
  Prime(int size) : n(size), is_prime(n+1, true) {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
      if (!is_prime[i]) continue;
      primes.push_back(i);
      int tmp = 2*i;
      while (tmp <= n) {
        is_prime[tmp] = false;
        tmp += i;
      }
    }
  }

  bool check(int x) { return is_prime[x]; }
};

int main() {
  Prime prime(1000001);
  int n;
  while (cin >> n) {
      int ans = 0;
      for (int p : prime.primes) {
          if (p > n) break;
          ++ans;
      }
      cout << ans << endl;
  }
}



Measured memory_bytes: 3344
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;
ll comp(const void *a,const void *b)
{
  return *(ll *)b-*(ll *)a;
}
int main(void)
{
  double l,ans;
  scanf("%lf",&l);
  ans=l*l*l/27.0;
  printf("%.9lf",ans);

  return 0;
}

Measured memory_bytes: 128
S=input()
T=input()
n=len(S)
s,t=[],[]
for i in range(n):
  s.append(S[i])
  t.append(T[i])
for i in range(n):
  p=s[0]
  for j in range(1,n):
    s[j-1]=s[j]
  s[n-1]=p
  if s==t:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 9080
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int > X(N);
  std::map<int, int > mp;
  for (int i=0; i<N; i++) {
    std::cin >> X[i];
    mp[X[i]]++;
  }
  int ans = 0;
  std::vector<int > unpaird(M+4, 0), paird(M+4, 0);
  for (auto entry : mp) {
    ans += entry.second/2;
    unpaird[entry.first%M] += entry.second%2;
    paird[entry.first%M] += entry.second/2;
  }
  //printf("ans1=%d\n", ans);
  ans += unpaird[0]/2;
  unpaird[0] = unpaird[0]%2;
  if (M%2==0) {
    ans += unpaird[M/2]/2;
    unpaird[M/2] = unpaird[M/2]%2;
  }
  for (int i=1; i<=(M-1)/2; i++) {
    int num1 = unpaird[i];
    int num2 = unpaird[M-i];
    int add = std::min(num1, num2);
    ans += add;
    unpaird[i] -= add;
    unpaird[M-i] -= add;
  }
  //printf("ans2=%d\n", ans);
  for (int i=1; i<M; i++) {
    if (M%2==0 && i==M/2) continue;
    //printf("i=%d\n", i);
    int num1 = paird[i];
    int num2 = unpaird[M-i];
    //printf("num1=%d, num2=%d\n", num1, num2);
    if (num1>=1 && num2>=2) {
      int add = std::min(num1, num2/2);
      //printf("add=%d\n", add);
      ans += add;
      paird[i] -= add;
      unpaird[M-i] -= add*2;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

vector<ll> hoge{1};
map<ll, ll> memo;

ll dfs(ll x) {
    if(x == 0) return memo[x] = 0;
    if(x < 0) return memo[x] = numeric_limits<ll>::max() / 2;
    ll res = numeric_limits<ll>::max() / 2;
    iter(i, hoge) {
        ll key = x - i;
        if(memo.count(key) == 0) res = min(res, dfs(key) + 1);
        else res = min(res, memo[key] + 1);
    }
    return memo[x] = res;
}

int main(void) {
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 6;i <= N;i *= 6) hoge.push_back(i);
    for(ll i = 9;i <= N;i *= 9) hoge.push_back(i);
    sort(hoge.rbegin(), hoge.rend());
    cout << dfs(N) << endl;
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

const int N = 1234;
const int mod = 1e9+7;

vector<int> primes;
bool isnotprime[N];

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	primes.push_back(2);
	for (int i = 0; i < N; i+=2) {
		isnotprime[i] = 1;
	}
	for (int i = 3; i*i < N; i+=2) {
		if (isnotprime[i]) continue;
		for (int j = i*i; j < N; j+=i) {
			isnotprime[j] = 1;
		}
	}
	for (int i = 3; i < N; i+=2) {
		if (isnotprime[i]) continue;
		primes.push_back(i);
	}
}

int h[N];

void solve() {
	int n; scanf("%d", &n);
	long long ans = 1;
	for (int i = 2; i <= n; ++i) {
		int m = i;
		for (int p: primes) {
			while (m > 0 && m % p == 0) {
				m /= p;
				++h[p];
			}
			if (m <= 0) break;
		}
	}
	for (int p: primes) {
		ans = (ans * ++h[p]) % mod;
	}
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for h in range(H)]

for i in range(10):
  for j in range(10):
    for k in range(10):
      c[j][k] = min(c[j][k], c[j][i] + c[i][k])

ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] >= 0:
      ans += c[A[h][w]][1]
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;

int n,a[maxn],f[maxn];
ll k,le,ri;

bool check(ll x){
    ll cnt=k;
    for(int i=0;i<n;++i){
        if(1LL*a[i]*f[i]<=x) continue;
        ll need=1LL*a[i]-x/f[i];
        if(cnt>=need) cnt-=need;
        else return false;
    }
    return true;
}

int main(){
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    for(int i=0;i<n;++i) scanf("%d",&f[i]);
    sort(a,a+n);
    sort(f,f+n,greater<int>());
    le=-1;
    for(int i=0;i<n;++i){
        ri+=1LL*a[i]*f[i];
    }
    while(le+1<ri){
        ll mid=(le+ri)>>1;
        if(check(mid)) ri=mid;
        else le=mid;
    }
    printf("%lld\n",ri);
    return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;


int main() {
  int n, d, x , ans = 0, input , temp ;
  scanf("%d %d %d", &n, &d, &x) ;

  for(int i = 0 ;i<n ;i++){
    scanf("%d", &input) ;
    temp = d/input ;
    ans+=(d%input == 0?temp:temp+1) ;
  }

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace AtCoder
{
    class Abc162F
    {

        public static void Main()
        {
            var input = Console.ReadLine().Split(' ');

            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            //var n = int.Parse(Console.ReadLine());

            //var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            if (a < b)
                Console.Write("0");
            else
                Console.Write("10");

            Console.WriteLine();

        }


    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;


int main()
{   int N;
	cin >> N;
	vector<int>A(N), B(N);
	rep(i, N-1) cin >> B.at(i);
	A.at(0) = B.at(0);
	A.at(N-1) = B.at(N-2);
	for (int i = 1; i < N-1; ++i) {
		A.at(i) = min(B.at(i-1), B.at(i));
	}
	int count = 0;
	rep(i, N) count += A.at(i);
	cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#define MAX 1000
using namespace std;

typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n!=0) {
    int u[MAX];
    priority_queue< P, vector<P>, greater<P> > que;
    for(int i=0; i<n; i++) {
      int id,a,q;
      cin >> id;
      cin >> u[id] >> a >> q;
      a=-a*1000000+q;
      que.push(P(a,id));
    }
    int d[MAX];
    for(int i=0; i<MAX; i++) d[i]=0;
    vector<int> ans;
    while(!que.empty()) {
      P p=que.top();
      que.pop();
      int a=p.first,ID=p.second;
      if(ans.size()<10 && d[u[ID]]<3) ans.push_back(ID);
      else if(ans.size()<20 && d[u[ID]]<2) ans.push_back(ID);
      else if(ans.size()<26 && d[u[ID]]<1) ans.push_back(ID);
      d[u[ID]]++;
      if(ans.size()>25) break;
    }
    for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;
  }
  return 0;
}


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

int main(){
  int N;
  int A[30];

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

  int ans = 1;
  int hi = A[0];

  for(int i=1; i<N; i++){
    if(hi<=A[i]){
      ans += 1;
      hi = A[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long INF = 1e15+7;
int main(){
  long N;
  long minN = INF;
  cin >> N;
  for(long i=1;i<=sqrt(N);++i){
    if(N%i)
      continue;
    long num = i + N/i -2;
    minN = min(minN,num);
  }
  cout << minN;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>

using namespace std;
void func(string str, int *au, int *al, int i);
int yakubun(int a, int b);

int main()
{
	string str;
	while(1){
		cin >> str;
		if(str == "#") break;
		int l = str.length(), i;
		int ans_upper = 0, ans_lower = 1;
		if(str[l - 1] == 'h'){
			ans_upper = 0;
			i = l - 6;
		}
		else if(str[l - 1] == 't'){
			ans_upper = 90;
			i = l - 5;
		}
		func(str, &ans_upper, &ans_lower, i);
		int gcd = yakubun(ans_upper, ans_lower);
		ans_upper = ans_upper / gcd;
		ans_lower = ans_lower / gcd;
		if(ans_lower == 1) cout << ans_upper << endl;
		else cout << ans_upper << '/' << ans_lower << endl;
	}
	return 0;
}

void func(string str, int *au, int *al, int i)
{
	if(i < 0) return;
	else if(str[i] == 'h'){
		*al = *al * 2;
		*au = *au * 2 - 90;
		func(str, au, al, i - 5);
	} else if(str[i] == 't'){
		*al = *al * 2;
		*au = *au * 2 + 90;
		func(str, au, al, i - 4);
	}
	return;
}

int yakubun(int a, int b)
{
	if(b == 0) return a;
	else {
		int r = a % b;
		return yakubun(b, r);
	}
}

Measured memory_bytes: 1200
#include <stdio.h>

int main()
{
    while(1) {

            int i, j, h, w;

            scanf("%d %d", &h, &w);

            if(h == 0 && w == 0) {

                break;
            }

            for(i = 1; i <= h; i++) {

                for(j = 1; j <= w; j++) {

                    if(i != 1 && i != h && j != 1 && j != w) {
                        printf(".");
                    }

                    else {

                        printf("#");
                    }
                }

                printf("\n");
            }

            printf("\n");
    }

    return 0;
}




Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
//const ll mod=1e9+7;
const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,s;
  cin >> n >> s;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  mat dp(n+1,vec(3001));
  for(ll i=0;i<=n;i++) {
    dp[i][0]=i+1;
  }
  for(ll i=0;i<n;i++) {
    for(ll j=3000;j>0;j--) {
      dp[i+1][j]=dp[i][j];
      if(j-a[i]>-1) {
        dp[i+1][j]=(dp[i+1][j]+dp[i][j-a[i]])%mod;
      }
    }
  }
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    ans=(ans+dp[i][s])%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)  for(int i=a;i<=b;i++)
using namespace std;

int ans=0;
using namespace std;
void solve()
{
    string s,t;
    cin>>s>>t;
    fr(i,0,s.length()-1)
    {
        if(s[i]==t[i])
            ans++;
    }

    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;

    //cin>>t;

    while(t--){
        solve();

    }

    return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <set>
#include <iostream>
#include <functional>

using namespace std;

using Graph = vector<vector<int>>;

set<int> find(const Graph& G) {
    const auto N = G.size();
    vector<bool> seen(G.size(), false);
    vector<int> prenum(N);
    vector<int> parent(N);
    vector<int> lowest(N);

    int timer = 1;
    function<void(int, int)> visit;
    visit = [&](int cur, int prev) {
        prenum[cur] = lowest[cur] = timer++;
        if (seen[cur])
            return;

        seen[cur] = true;
        for (auto next : G[cur]) {
            if (!seen[next]) {
                parent[next] = cur;
                visit(next, cur);
                lowest[cur] = min(lowest[cur], lowest[next]);
            } else if (next != prev) {
                lowest[cur] = min(lowest[cur], prenum[next]);
            }
        }
    };
    visit(0, -1);

    set<int> ap;
    int np = 0;
    for (int i = 1; i < N; ++i) {
        auto p = parent[i];
        if (p == 0) {
            ++np;
        } else if (prenum[p] <= lowest[i]) {
            ap.insert(p);
        }
    }
    if (np > 1) {
        ap.insert(0);
    }
    return std::move(ap);
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    for (int i = 0; i < E; ++i) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    for (auto x : find(G)) {
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 4804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first < b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<ll>A;
    rep(i,N){
        ll a;
        cin>>a;
        A.pb(a);
    }
    vector<Pi>BC(M);
    rep(i,M){
        ll b,c;
        cin>>b>>c;
        BC[i]=mp(b,c);
    }

    sort(all(A));
    reverse(all(A));
    sort(all(BC),compare);

    ll ans = 0;
    ll cntA=0,cntB=0;
    rep(i,N){
        ll a,b;
        if(cntA<N){
            a=A[cntA];
        }else{
            a=0;
        }
        if(cntB<M){
           b=BC[cntB].second;
        }else{
            b=0;
        }
 
        if(a>b){
            ans+=a;
            cntA++;
        }else{
            ans+=b;
            if(BC[cntB].first==1){
                cntB++;
            }else{
                BC[cntB].first--;
            }
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 100000
using namespace std;
ll v[LIM];
int main() {
  ll a, b, h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [False] * (k + 1)

    for i in range(k + 1):
        if dp[i]:
            continue
        for a in A:
            if i + a <= k:
                dp[i + a] = True

    print("First" if dp[k] else "Second")
resolve()

Measured memory_bytes: 40048
def main():

    string = input()
    commands_count = int(input())
    commands = [input().split() for i in range(commands_count)]

    for command in commands:
        a, b = int(command[1]), int(command[2])
        if len(command) == 4:
            string = string[0:a] + command[3] + string[b+1:]
        else:
            if command[0] == 'print':
                print(string[a:b+1])
            else:
                string = string[0:a] + ''.join(list(reversed(string[a:b+1]))) + string[b+1:]

main()

Measured memory_bytes: 7808
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<stdio.h>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl

using namespace std;


const int MAX_V=16;
const int MAX_E=(1<<MAX_V);
const int INF=1<<28;

int V,E;
int G[MAX_V][MAX_V];
int dp[MAX_E][MAX_V];

int dfs(int v,int visit){
	if(dp[visit][v] != -1) return dp[visit][v];
	if(visit == (1<<V)-1) return G[v][0];
	dp[visit][v]=INF;
	rep(i,V){
		if(visit & (1<<i))continue;//??¢????¨????????????????
		dp[visit][v] = min(dfs(i,(visit | (1<<i)))+G[v][i],dp[visit][v]);
	}

	return dp[visit][v];
}

int main(){
	cin >> V >> E;
	fill_n((int *)dp,sizeof(dp)/sizeof(int),-1);
	fill_n((int *)G,sizeof(G)/sizeof(int),INF);
	rep(i,E){
		int s,t,d;
		cin >> s >> t >> d;
		G[s][t]=d;
	}
	int visit=0;
	int ans=dfs(0,(visit|1));

	if(ans==INF) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5260
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void) {
	long n, k;
	scanf("%ld %ld", &n, &k);
	long mod;
	if (n == 0) {
		mod = k;
	}
	else {
		mod = n % k;
	}
	if (mod > k) {
		printf("%ld", mod < mod - k ? mod : mod - k);
	}
	else {
		printf("%ld", mod < k - mod ? mod : k - mod);
	}


	return 0;
}

Measured memory_bytes: 128
# require 'pry'
N = gets.to_i
li = []
5.times do
  li << gets.to_i
end
# p li

ans = (N.to_f / li[0]).ceil
pre = li[0]
# binding.pry
1.upto(4) do |i|
  if li[i] < pre
    ans = i + (N.to_f / li[i]).ceil
    pre = li[i]
  else
    ans += 1
  end
end
puts ans


Measured memory_bytes: 1788