akhauriyash/Code-Regression huggingface dataset:
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

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

int *C;
int *A;
int *B;
int Posb, track;

void print(int p){
    int sum = 0;
    for(int i = 0; i <= p; i++){
        
        if(C[i] == 1){
            sum+=A[i];
            if(sum > B[Posb])break;
        }
    }
        if(sum != B[Posb]){
            track=-1;
    }
    if(sum == B[Posb]){
        track = 1;
        return;
    }
}
void find(int l, int p){
    if (l == p){
        if(C[l] == 0)print(p);
        if(track == 1)return;
        if(C[l] == 1) print(p);
        return;
    }
    if(track == 1)return;
    C[l] = 0;
    find(l+1,p);
    if(track == 1)return;
    C[l] = 1;
    find(l+1,p);
    if(track == 1)return;
}
    
int main(){
    
     
    int n;
    scanf("%d",&n);
    A =(int*)malloc(n * sizeof(int));
    for(int a = 0; a < n; a++){
            scanf("%d",&A[a]);
    }

    int m;
    scanf("%d",&m);
    B = (int*)malloc(m * sizeof(int));
    C = (int*)malloc(m * sizeof(int));
    for(int a = 0; a < m; a++){
        scanf("%d",&B[a]);
        C[a] = 0;
    }

    int l = 0;
    for(Posb = 0; Posb < m; Posb++){
    find(l,n);
    
    if(track == 1)printf("yes\n");
    if(track == -1)printf("no\n");
    track = 0;
    }
    free(B);
    free(A);
    return 0;
}






Measured memory_bytes: 2140
#include<iostream>
#include<string>
using namespace std;
int main () {
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i ++) {
    if (!(i % 2) && S[i] == 'L') {
      cout << "No" << endl;
      return 0;
    }
    if ((i % 2) && S[i] == 'R') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
  

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    A, P = MI()
    print((A*3+P)//2)


if __name__ == '__main__':
    main()


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int max = 0;
  for(int count = 0; count < K; count++) {
      if(A > 0) {
          max += 1;
          A--;
      } else if (B > 0) {
          B--;
      } else if (C > 0) {
          max -= 1;
      }
  }
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <map>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl
using llint = long long int;
//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable, numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<llint> v(n);
    map<long long int,long long int> mp;
    for (auto i = 0; i < n;i++){
        cin >> v[i];
        mp[v[i]]++;
    }
    map<llint, llint> sum;
    llint all_sum=0;
    for(auto x:mp){
        sum[x.first] = ((x.second) * (x.second - 1)) / 2;
        all_sum += sum[x.first];
    }
    REP(i,n){
        cout << all_sum - sum[v[i]] + ((mp[v[i]] - 1) * (mp[v[i]] - 2)) / 2 << endl;
    }



    return 0;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    int N;cin >> N;
    LL s=0;
    if(N==1){
        s=2;
    }
    for(LL i=1;i<=N;i++){
        if(i*(i-1)==2*N){
            s=i;
            break;
        }
    }
    if(s==0){
        puts("No");
        return 0;
    }
    int ans[s][s-1];
    int a=1;
    for (int i = 0; i < s-1; i++) {
        for(int j=i;j<s-1;j++){
            ans[i][j]=a;
            ans[j+1][i]=a++;
        }
    }
    puts("Yes");
    cout << s << endl;
    for (int i = 0; i < s; i++) {
        cout << s-1 << " ";
        for (int j = 0; j < s-1; j++) {
            cout << ans[i][j] << (j==s-2?"\n":" ");
        }
    }
    return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll fac[maxn],inv[maxn],n,m,k;
const ll mod=998244353;

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline ll C(int a,int b){return (fac[a]*inv[b])%mod*inv[a-b]%mod;}

int main()
{
	cin>>n>>m>>k; fac[0]=1; inv[0]=1;
	rep(i,1,n) fac[i]=(fac[i-1]*i)%mod;
	rep(i,1,n) inv[i]=pw(fac[i],mod-2);
	ll ans=0;
	rep(i,0,k) ans=(ans+m*C(n-1,i)%mod*pw(m-1,n-i-1)%mod)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6748
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
n = int(input())
A = prime_factorize(n)
C = Counter(A)

S = []
s = 0
for i in range(1,50):
  s += i  
  S.append(s)
  
def count(n):
  for i in range(50-1):
    if n < S[i]:
      return i    

ans = 0
for k,v in C.items():
  ans += count(v)
  
print(ans)  

Measured memory_bytes: 9476
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

#include <chrono>
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int>A(N);
    cin >> A;
    vector<ll> sums(N + 1);

    REP(i, N) {
        sums[i + 1] = sums[i] + A[i];
    }

    ll ans = 0;
    SORT(sums);
    int cnt = 1;
    ll now = sums[0];
    FOR(i, 1, N + 1) {
        if (now == sums[i])cnt++;
        else {
            ans += (ll)cnt * (cnt - 1) / 2;
            now = sums[i];
            cnt = 1;
        }
    }
    ans += (ll)cnt * (cnt - 1) / 2;
    cout << ans << endl;

    return 0;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T = 1,n,m,k;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // cin >> T;
    while(T--){
        int d = 0;
        int p, q;
        cin >> n;
        int f = 0;
        for(int i=0;i<n;i++){
            int x, y;
            cin >> x >> y;
            if(x==y){
                d++;
            }
            else{
                d=0;
            }
            if(d==3){
                f = 1;
            }
        }
        if(f)
            cout << "Yes\n";
        else
            cout << "No\n";
        
    }

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  deque<int> P;
  P.push_back(MOD);
  rep(i,0,N){
    int A; cin>>A;
    int K=dislow(P,A);
    if(K==0)
      P.push_front(A);
    else
      P[K-1]=A;
  }
  cout<<P.size()-1<<endl;
  }


Measured memory_bytes: 1024
import java.util.Scanner;

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

        char b = sc.next().charAt(0);
        switch(b) {
            case 'A':
            System.out.println('T');
            break;
            case 'C':
            System.out.println('G');
            break;
            case 'G':
            System.out.println('C');
            break;
            case 'T':
            System.out.println('A');
        }

        sc.close();
    }
}

Measured memory_bytes: 21588
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head

ll x, k, d;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> x >> k >> d;

  if(x < 0) x = -x;

  ll rr = x%d;
  ll gg = (x-rr)/d;

  if(k <= gg) {
    cout << x-k*d << endl;
    return 0;
  }

  k -= gg;
  x = rr;
  if(k&1) {
    cout << abs(d-x) << endl;
  }
  else {
    cout << x << endl;
  }
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;
int main(){
	
    int day;
    while( cin >> day ){
	
		if( day == 1)
		cout << "fri\n";
		
		else if( day == 2)
		cout << "sat\n";
		
		else if( day == 3)
		cout << "sun\n";
		
		else
		switch( (day - 3) % 7 ) {
			
			case 1:
			cout << "mon\n";
			break;
			
			case 2:
			cout << "tue\n";
			break;
			
			case 3:
			cout << "wed\n";
			break;
			
			case 4:
			cout << "thu\n";
			break;
			
			case 5:
			cout << "fri\n";
			break;
			
			case 6:
			cout << "sat\n";
			break;
			
			default :
			cout << "sun\n";
			break;
		}
 }
    return 0;
}


Measured memory_bytes: 3012
#include<cstdio>
#include<algorithm>
#include<vector>
#define pii pair<int,int>
using namespace std;
int n, w[51];
vector<pii>V;
int main() {
	int i, M = -1, pv;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		if (M < abs(w[i]))M = abs(w[i]), pv = i;
	}
	for (i = 1; i <= n; i++) {
		if (i != pv) {
			V.push_back({ pv, i });
			w[i] += w[pv];
		}
	}
	if (w[pv] > 0) {
		for (i = 1; i < n; i++)V.push_back({ i,i + 1 });
	}
	else {
		for (i = n; i > 1; i--)V.push_back({ i,i - 1 });
	}
	printf("%d\n", V.size());
	for (auto &t : V)printf("%d %d\n", t.first, t.second);
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int x,a,b;
    cin >> x >> a >> b;
    if (abs(x-a) < abs(x-b)) {
        cout << "A" << endl;
    }
    else {
        cout << "B" << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int a, b, c;

    int d = 0, e = 0;

    while (~scanf("%d,%d,%d", &a, &b, &c)) {
        if (a * a + b * b == c * c) d++;
        if (a == b) e++;
    }

    cout << d << "\n" << e << endl;
}

Measured memory_bytes: 1212
n,k=map(int,input().split())
ar=list(map(int,input().split()))
vis=[0 for i in range(n+1)]
x=1
seq=[1]
go=0
rep=0
ct=1
while (vis[x]==0):
    vis[x]=ct
    seq.append(ar[x-1])
    x=ar[x-1]
    ct+=1
    if vis[x]!=0:
        rep=ct-vis[x]
        go=vis[x]
if k<=go:
    print(seq[k])
else:
    print(seq[go+(k-go)%rep])


Measured memory_bytes: 107320
n,m = (int(x) for x in input().split())

foods = []
for a in range(m):
	foods.append(0)

for i in range(n):
	answer = [int(x) for x in input().split()]
	for x in range(1,answer[0]+1):
		foods[answer[x]-1] += 1

print(foods.count(n))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

#define int long long

using namespace std;

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

	vector<int>a(n, 0);
	map<int, int>x;
	vector<int>kind;
	int piece = 0;
	rep(i, n) {
		cin >> a[i];
		if (x[a[i]] == 0) {
			kind.push_back(a[i]);
			piece++;
		}
		x[a[i]]++;
	}

	int temp = 0;
	rep(i, piece) {
		temp += (x[kind[i]]) * (x[kind[i]] - 1) / 2;
	}

	int ans = 0;
	rep(k, n) {
		int h = a[k];
		int sem = (x[h]) * (x[h] - 1) / 2;
		x[h]--;
		int rem = (x[h]) * (x[h] - 1) / 2;
		ans = temp - sem + rem;
		cout << ans << endl;
		x[h]++;
		ans = 0;
	}

	return 0;
}

Measured memory_bytes: 12020
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
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; }

void solve(std::vector<long long> x){
    REP(i, x.size()){
        if(x[i] == 0) {
            cout<<i+1<<endl;
            return;
        }
    }
}
int main(){
    std::vector<long long> x(5);
    for(int i = 0 ; i < 5 ; i++){
        scanf("%lld",&x[i]);
    }
    solve(std::move(x));
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, n, k;
    cin >> a >> b;
    if (13 <= a)
    {
        cout << b << endl;
    }
    else if (6 <= a && a <= 12)
    {
        cout << b / 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b) {
  ll v0 = a, v1 = b, v2 = v0%v1;
  while(v2>0) {
    v0 = v1;
    v1 = v2;
    v2 = v0%v1;
  }
  return v1;
}

int main() {
  int N;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  ll ans = gcd(A[0], A[1]);
  for(int i=2;i<N;++i) ans = gcd(ans, A[i]);
  cout<<ans<<endl;
}



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

ans = 0
for i in range(111, 1000):
    str_i = str(i)
    if str_i.count('0') != 0:
        continue

    for j in range(n+1, 10):
        if str_i.count(str(j)) != 0:
            break
    else:
        ans += 1

print(ans)


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

int main(void) {
    string odd, even;
    cin >> odd >> even; //odd -> 奇数

    string ans = "";
    for (int i = 0; i < even.size(); i++)
    {
        ans = ans + odd[i] + even[i];
    }
    if (odd.size() > even.size())
        ans += odd[odd.size() - 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val A = Array(M) {0}
    val B = Array(M) {0}

    for (i in A.indices) {
        val (a, b) = readLine()!!.split(" ").map{it.toInt()}
        A[i] = a - 1
        B[i] = b - 1
    }

    val uf = UnionFind(N)
    val res = ArrayList<Long>()
    res.add(N * (N - 1L) / 2)

    for (i in A.indices.reversed()) {
        if (uf.same(A[i], B[i])) {
            res.add(res.last())
        } else {
            res.add(res.last() - uf.getCardinalityOf(A[i]) * uf.getCardinalityOf(B[i]))
            uf.unite(A[i], B[i])
        }
    }

    res.removeAt(res.size - 1)
    res.reverse()
    for (v in res) {
        println(v)
    }
}

private class UnionFind(n: Int) {
    val size = n

    private val parent: Array<Int>
    private val cardinality: Array<Long>

    init {
        parent = Array(size) { -1 }
        cardinality = Array(size) { 1L }
    }

    /**
     * Find a root element of a set `x` belongs to.
     */
    fun find(x: Int): Int {
        return if (parent[x] == -1) {
            x
        } else {
            parent[x] = find(parent[x])
            parent[x]
        }
    }

    /**
     * Unite sets contain two elements `x` and `y`.
     * If `x` and `y` already belong to a same set, nothing happens.
     *
     * @return If `x` and `y` belong to a same set, return false.
     */
    fun unite(x: Int, y: Int): Boolean {
        val u = find(x)
        val v = find(y)
        if (u == v) {
            return false
        }

        val newSize = cardinality[v] + cardinality[u]

        if (cardinality[u] < cardinality[v]) {
            parent[u] = v
            cardinality[v] = newSize
        } else {
            parent[v] = u
            cardinality[u] = newSize
        }

        return true
    }

    /**
     * Check whether `x` and `y` belongs to a same set.
     *
     * @return `true` if `x` and `y` are in a same set.
     */
    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    /**
     * Get a size of a set `x` belongs to.
     */
    fun getCardinalityOf(x: Int): Long {
        return cardinality[find(x)]
    }
}


Measured memory_bytes: 81904
//此题23333333333
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,i,j,t[290],x,ans,p;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>t[i];
		ans+=t[i];
	}
	cin>>m;
	for(i=1;i<=m;i++)
	{
		cin>>p>>x;
		cout<<ans-t[p]+x<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,T=0;
  char S[100];
  scanf("%d\n%s", &N, S);
  for(int i=0;i<N-2;i++){
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') T++;
  }
  printf("%d\n", T);
  return 0;
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    string s,t;
    cin>>s>>t;
    int ans = 0;
    REP(i,3)ans += s[i]==t[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ele int
using namespace std;
#define maxn 100010
ele n,h,a[maxn],b[maxn];
inline ele ceil(ele a,ele b){
	return (a%b)?(a/b+1):a/b;
}
int main(){
	scanf("%d%d",&n,&h);
	for (int i=0; i<n; ++i) scanf("%d%d",a+i,b+i);
	sort(a,a+n); sort(b,b+n);
	ele ans=1e9,tmp=h;
	for (int i=0; i<=n; ++i){
		ans=min(ans,i+ceil(tmp,a[n-1]));
		if (i<n) tmp-=b[n-1-i],tmp=max(tmp,0);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
def partition(a, p, r):
    x = int(a[r].split()[1])
    i = p-1
    for j in range(p, r):
        if int(a[j].split()[1]) <= x:
          i = i+1
          a[i], a[j] = a[j], a[i]
    a[i+1], a[r] = a[r], a[i+1]
    return i+1

def quick_sort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quick_sort(a, p, q - 1)
        quick_sort(a, q + 1, r)


n = int(input())
cards = [input() for i in range(n)]
stable = sorted(cards, key=lambda x: int(x.split()[1]))
quick_sort(cards, 0, n - 1)

print("Stable" if stable == cards else "Not stable")

for card in cards:
    print(card)


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    vi ans(n);
    vector<pair<pii, int>> rl;
    bool isr = true;
    pii cnt = { 0, 0 };
    rep(i, n) {
        if (!isr && s[i]=='R') {
            isr = true;
            rl.emplace_back(cnt, i);
            cnt = { 0, 0 };
        }
        if (s[i]=='R') ++cnt.first;
        else {
            ++cnt.second;
            isr = false;
        }
    }
    rl.emplace_back(cnt, n);
    rep(i, sz(rl)) {
        int ri = rl[i].second - rl[i].first.second - 1, li = ri+1;
        ans[ri] = (rl[i].first.first+1)/2 + (rl[i].first.second)/2;
        ans[li] = (rl[i].first.second+1)/2 + (rl[i].first.first)/2;
    }
    rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


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

int main() {
  int nurinuri = 0;
  string tile;
  cin >> tile;
  //初め0の時塗り替え
  if(tile.at(0) == '0'){//0101…
    for(int i = 0; i < tile.size(); i++){
      if(i % 2 == 0 && tile.at(i) != '0'){//配列の偶数番目1のタイルを0に塗り替え、文字列ゆえ''
        nurinuri++;
      }else if(i % 2 == 1 && tile.at(i) != '1'){//奇数番目0のタイルを1に塗り替え
        nurinuri++;
      }
    }
  }
  if(tile.at(0) == '1'){//1010…
    for(int i = 0; i < tile.size(); i++){
      if(i % 2 == 0 && tile.at(i) != '1'){//1のタイルを0に塗り替え
        nurinuri++;
      }else if(i % 2 == 1 && tile.at(i) != '0'){//0のタイルを1に塗り替え
        nurinuri++;
      }
    }
  }
  cout << nurinuri << endl;
}


Measured memory_bytes: 512
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if L[i]==L[j]:
            continue
        for k in range(j+1, N):
            if L[j]==L[k]:
                continue
            if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[i]+L[k]>L[j]:
                cnt+=1
print(cnt)

Measured memory_bytes: 67888
#include <stdio.h>
#include <ctype.h>
 
int from_mcxi(const char* mcxi) {
    const char* nowp=mcxi;
    int num=1;
    int result=0;
    for(;*nowp;nowp++) {
        switch(*nowp) {
            case 'm':
                result+=1000*num;
                num=1;
                break;
            case 'c':
                result+=100*num;
                num=1;
                break;
            case 'x':
                result+=10*num;
                num=1;
                break;
            case 'i':
                result+=1*num;
                num=1;
                break;
            default:
                if(isdigit(*nowp))num=*nowp-'0';
        }
    }
    return result;
}
 
void to_mcxi(char* mcxi,int num) {
    if(num>=1000) {
        if(num>=2000)*(mcxi++)=(num/1000)+'0';
        *(mcxi++)='m';
        num%=1000;
    }
    if(num>=100) {
        if(num>=200)*(mcxi++)=(num/100)+'0';
        *(mcxi++)='c';
        num%=100;
    }
    if(num>=10) {
        if(num>=20)*(mcxi++)=(num/10)+'0';
        *(mcxi++)='x';
        num%=10;
    }
    if(num>=1) {
        if(num>=2)*(mcxi++)=(num/1)+'0';
        *(mcxi++)='i';
        num%=1;
    }
    *mcxi=0;
}
 
int main(void) {
    int data_num,now_data;
    char q1[100],q2[100],ans[100];
    scanf("%d",&data_num);
    for(now_data=0;now_data<data_num;now_data++) {
        scanf("%s%s",q1,q2);
        to_mcxi(ans,from_mcxi(q1)+from_mcxi(q2));
        puts(ans);
    }
    return 0;
}

Measured memory_bytes: 584
PROGRAM piyo
      IMPLICIT NONE
      character(3) :: s
      integer :: i
      
      read*,s(1:3)
      
      do i = 1,3
        if( s(i:i)=='7' )then
          print*,'Yes'
          stop
        end if
      end do
      
      print*,'No'
      
      
      
      
      END PROGRAM

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

*/
int main(){
  ll X; cin>>X;
  X-=400;
  ll ans = 8;
  while(X>=200){
    ans--;
    X-=200;
  }
  if (ans<1) ans=1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.io.*;

class Main {
	private static int score = 0;
    private static int outCount = 0;
    private static boolean runner[] = new boolean[3];
	
	public static void main(String[] args) {
    	try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            StringBuilder stringBuilder = new StringBuilder();
            
            //??\???????????????????????????????????°???????????????
            int dataSet = Integer.parseInt(br.readLine());
            for(int i=0; i<dataSet; i++){
	            String line;
	            while ((line = br.readLine()) != null) {
	            	switch (line) {
					case "HIT":
						hit(runner);
						break;
					
					case "HOMERUN":
						homeRun();
						break;
					
					case "OUT":
						out();
						break;
					
					default:
						break;
					}
	            	if(outCount==3){
	            		runner = new boolean[3];
	            		outCount=0;
	            		break;
	            	}
	            }
	            stringBuilder.append(score + "\n");
	            score = 0;
            }
            System.out.print(stringBuilder);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void hit(boolean[] runner) {
    	//????????????3???
    	if(runner[2]){
    		++score;
    	}else{
    		//????????????????¬?????????????????????????
    		runner[2] = runner[1];
    		runner[1] = runner[0];
    		runner[0] = true;
    	}
    }
    
    public static void homeRun() {
    	//??????1????????\???
    	++score;
    	for(int j=0; j<runner.length;j++){
    		if(runner[j]){
    			++score;
    			runner[j] = false;
    		}
    	}
    }
    
    public static int out() {
		if(outCount==3){
    		return 0;
    	}
		return ++outCount;
    }
}

Measured memory_bytes: 24208
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, sz[MAX], c[MAX];
vector<int> G[MAX];
map<int, int> mp[MAX];
lint ans[MAX];

int sz_dfs(int v, int pv){
    sz[v] = 1;
    for(auto nv: G[v])if(nv != pv){
        sz[v] += sz_dfs(nv, v);
    }
    return sz[v];
}

void dfs(int v, int pv){
    int max_id = -1;
    rep(i, G[v].size())if(G[v][i] != pv){
        int nv = G[v][i];
        dfs(nv, v);

        lint tmp = sz[nv] + mp[nv][c[v]];
        ans[c[v]] -= (lint)tmp*(tmp-1)/2 + tmp;

        if(max_id < 0 || mp[nv].size() > mp[G[v][max_id]].size()){
            max_id = i;
        }
    }

    if(max_id >= 0){
        swap(mp[v], mp[G[v][max_id]]);
        rep(i, G[v].size())if(i != max_id && G[v][i] != pv){
            int nv = G[v][i];
            for(auto p: mp[nv]) mp[v][p.fi] += p.se;
            mp[nv].clear();
        }
    }
    mp[v][c[v]] = -sz[v];
}

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%d", &c[i]), --c[i];
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    sz_dfs(0, -1);
    fill(ans, ans+n, (lint)n*(n-1)/2 + n);
    dfs(0, -1);
    rep(i, n){
        lint tmp = n + mp[0][i];
        ans[i] -= (lint)tmp*(tmp-1)/2 + tmp;
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 67780
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
int main(){
    int a = 0;
    int S_size;
    string S;
    cin >> S;
    rep(i,S.size()){
        if((S[i] - i)%2){
            a++;
        }
    }
    S_size = S.size();
    cout << min(a,S_size - a) << endl;
}


Measured memory_bytes: 512
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin>>N>>M;
  int A[M];
  int sum=0;
  rep(i,M){
    cin>>A[i];
    sum+=A[i];
  }
  if(sum>N)
    cout<<-1<<endl;
  else
    cout<<N-sum<<endl;

}

Measured memory_bytes: 3680
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	int N, W;
	cin >> N >> W;
	vector<int>w(N), v(N);
	rep(i, N)cin >> w[i] >> v[i];
	vector<vector<int>>dp(N + 1, vector<int>(W + 1));
	rep(j, W + 1)dp[0][j] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < W + 1; j++) {
			if (j - w[i] >= 0)dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			else dp[i + 1][j] = dp[i][j];
		}
	}
	cout << dp[N][W];
}

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


int main(){
  ull n;
  cin >> n;
  vector<ull> vec(n);
  map<ull,ull> a;//ボールの番号ごとの個数
  for(int i=0;i<n;i++){
	ull num;
    cin >> num;
    vec.at(i) = num;
    a[num]++;
  }

  ull sum=0;
  for( auto p : a ){
    ull k = p.first;//ボールに書かれた数字
    ull v = p.second;//数字がkのボールの個数
    if( v < 2 ) continue;
    sum += v*(v-1)/2;
  }
  for(int i=0;i<n;i++){
    ull num = a[vec.at(i)];
    if( num >= 2 ){
      cout << sum-(num-1) << endl;
    }else{
      cout << sum << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 11008
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=405;
int h,w;
string s[M];
int vis[M][M];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int chk(int x,int y)
{
    if(x<0 || x>=h || y<0 || y>=w)return false;
    if(vis[x][y])return false;
    return true;
}
int cw=0,cb=0;
int dfs(int i,int j)
{
    vis[i][j]=1;
    if(s[i][j]=='#')cb++;
    else cw++;
    for(int k=0;k<4;k++)
    {
        int x=dx[k]+i;
        int y=dy[k]+j;
        if(!chk(x,y))continue;
        if(s[i][j]==s[x][y])continue;
        dfs(x,y);
    }
}
 main()

{
    fast
    cin>>h>>w;
    f(i,0,h-1)
    {
        cin>>s[i];
    }
    int ses=0;
    f(i,0,h-1)
    {
        f(j,0,w-1)
        {
            if(vis[i][j])continue;
            else
            {
                cb=cw=0;
                dfs(i,j);
                ses+=(cb*cw);
            }
        }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 14208
#include <stdio.h>

 int main(void)
{

 int H,W,h,w,s;

  scanf("%d%d" ,&H, &W);

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

 s=(H*W)-((w*H)+(h*W)-(w*h));

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

 return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define cin fi
using namespace std;
ifstream fi("input.in");

const int NMAX = 100005;

int n;
char x[NMAX];
char curr[NMAX];
char f[] = {'S', 'W'};

bool ok(int unu, int doi, int trei)
{
    if ((x[doi] == 'o' && curr[doi] == 'S') || (x[doi] == 'x' && curr[doi] == 'W'))
        return curr[trei] == curr[unu];
    return curr[trei] != curr[unu];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> x + 1;

    for (int a = 0; a <= 1; a++)
        for (int b = 0; b <= 1; b++)
        {
            curr[1] = f[a];
            curr[2] = f[b];

            for (int i = 3; i <= n; i++)
            {
                if ((x[i - 1] == 'o' && curr[i - 1] == 'S') || (x[i - 1] == 'x' && curr[i - 1] == 'W'))
                {
                    curr[i] = curr[i - 2];
                }
                else
                    curr[i - 2] == 'S' ? curr[i] = 'W' : curr[i] = 'S';
            }
            if (ok(n - 1, n, 1) && ok(n, 1, 2))
            {
                for (int j = 1; j <= n; j++)
                    cout << curr[j];
                return 0;
            }
        }
    cout << -1;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
	int n,x,t;
	scanf("%d %d %d",&n,&x,&t);
	if(n%x){
		printf("%d",t*(n-n%x)/x+t);
	}else{
		printf("%d",t*(n-n%x)/x);
	}
	
}

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

void dfs(string s, char x, int n) {
    if (s.size() == n) {
        cout << s << endl;
    } else {
        for (char c = 'a'; c <= x; c++) {
            if (c == x) {
                dfs(s + c, x + 1, n);
            } else {
                dfs(s + c, x, n);
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    dfs("", 'a', n);
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  vector<Int> v(4);
  for(Int i=0;i<4;i++) cin>>v[i];
  sort(v.begin(),v.end());
  
  if(v[0]==1&&v[1]==4&&v[2]==7&&v[3]==9) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T, bool directed>
struct Dinic {
    struct edge {
        int to;
        T cap;   // capacity of the edge
        int rev; // index for to->from edge
        edge() {}
        edge(int to_, T cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {}
    };
    T inf;
    vector<vector<edge>> G;
    vector<int> level, iter;
    Dinic(int n, T inf_ = INF) : inf(inf_), G(n), level(n), iter(n) {}

    void addEdge(int from, int to, int cap) {
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, directed ? 0 : cap, G[from].size() - 1);
    }
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.emplace(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (edge &e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.emplace(e.to);
                }
            }
        }
    }
    T dfs(int v, int t, T f) {
        if (v == t)
            return f;
        for (int i = iter[v]; i < int(G[v].size()); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d == 0)
                    continue;
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }
    T flow(int s, int t, T lim) {
        T fl = 0;
        while (true) {
            bfs(s);
            if (level[t] < 0 || lim == 0)
                break;
            fill(iter.begin(), iter.end(), 0);
            while (true) {
                T f = dfs(s, t, lim);
                if (f == 0)
                    break;
                fl += f;
                lim -= f;
            }
        }
        return fl;
    }
    T flow(int s, int t) { return flow(s, t, inf); }
};

int main() {
    int n;
    cin >> n;
    vi a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i] >> d[i];
    }
    // 0 to n-1 : red
    // n to 2n-1 : blue
    // 2n : start
    // 2n+1 : end
    Dinic<int, true> di(2 * n + 2);
    for (int i = 0; i < n; ++i) {
        di.addEdge(2 * n, i, 1);
        di.addEdge(n + i, 2 * n + 1, 1);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i] < c[j] && b[i] < d[j]) {
                di.addEdge(i, n + j, 1);
            }
        }
    }
    cout << di.flow(2 * n, 2 * n + 1) << "\n";
    return 0;
}

Measured memory_bytes: 384
n = gets.chomp.to_i
k = gets.chomp
a = []
n.times do |i|
	a[i] = gets.chomp
end
ans=0
a.each do |e|
	catch(:br) do
		msp = (e.size - k.size) / (k.size - 1)
		for sp in 0..msp
			for st in 0..(sp+1)
				str = []
				st.step(e.size-1, sp+1) do |i|
					str.push(e[i])
				end
				if str.join.include?(k)
					ans += 1
					throw :br
				end
			end
		end
	end
end
puts ans

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

int rn,cn;
bool map[55][55];
bool check(int r, int c) {
	if (r>0 && map[r-1][c])
		return 1;
	if (c>0 && map[r][c-1])
		return 1;
	if (r+1<rn && map[r+1][c])
		return 1;
	if (c+1<cn && map[r][c+1])
		return 1;
	return 0;
}
int main() {
	memset(map, 0, sizeof(map));
	cin>>rn>>cn;
	for (int i=0; i<rn; i++) {
		string ss;
		cin>>ss;
		for (int j=0; j<cn; j++)
			if (ss[j]=='#')
				map[i][j]=1;
	}
	for (int i=0; i<rn; i++)
		for (int j=0; j<cn; j++)
			if (map[i][j] && check(i,j)==false) {
				cout<<"No"<<endl;
				return 0;
			}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
//AtCoder ABC108 B - Ruined Square
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
struct vec2{
    vec2(){}
	vec2(ll ix, ll iy) : x(ix), y(iy) {}
	ll x=0;
	ll y=0;
	vec2 operator-(const vec2& obj) {
		return vec2(this->x-obj.x,this->y-obj.y);
	}
    vec2 operator+(const vec2& obj){
        return vec2(this->x+obj.x,this->y+obj.y);
    }
};
int main() {
    vec2 p[4];
    cin>>p[0].x>>p[0].y;
    cin>>p[1].x>>p[1].y;
    vec2 d=p[1]-p[0];
    vec2 r=vec2(-d.y,d.x);
    p[2]=p[1]+r;
    p[3]=p[0]+r;
    cout<<p[2].x<<" "<<p[2].y<<" "<<p[3].x<<" "<<p[3].y<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count = 700;
  if(s.at(0) == 'o') count += 100;
  if(s.at(1) == 'o') count += 100;
  if(s.at(2) == 'o') count += 100;
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    char A[100];
    int i, answer = 0;
    scanf("%s", A);
    for(i = 0; A[i] != '\0'; i++);
    
    int b = i / 2, c;
    for(int j = 0; j < b; j++){
        c = i - j - 1;
        if(A[j] != A[c]) answer += 1;
    }
    
    printf("%d", answer);
    
    return 0;

}

Measured memory_bytes: 128