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

int main(){
    int h, w, n, ans;
    cin >> h >> w >> n;

    int sum = 0;
    if(h>w) {
        for(int i=1; i<=w; i++) {
            sum += h;
            if(sum >= n) {
                ans = i;
                break;
            }
        }
    } else {
        for (int i = 1; i <= h; i++) {
            sum += w;
            if (sum >= n) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
typedef long long int lli;

int frag[100];
int num[100];
void fx(int n,int k)
{
    int i,j,f;
    for(i=0;i<n;i++){
        f=frag[i];
        if(f==0){
            frag[i]=1;
            num[n-k]=i+1;
            if(k==1){
                //ここでnumに順列が入っている。
                for(j=0;j<n;j++){
                    printf("%4d",num[j]);
                }
                printf("\n");
            }
            else{
                fx(n,k-1);
            }
            frag[i]=0;
        }
    }

}

int main(void)
{
    int n;
    char s[50][101];
    int t[50];
    char x[101];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %d",s[i],&t[i]);
    }
    scanf("%s",x);
    int sum=0,flg=0;
    for(int i=0;i<n;i++){
        if(flg==1){
            sum+=t[i];
        }
        if(!strcmp(s[i],x)){
            flg=1;
        }
    }
    printf("%d\n",sum);

    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int64_t> a(N),b(N);
  for(int i=0;i<N;++i) cin>>a[i];
  for(int i=0;i<N;++i) cin>>b[i];
  int64_t cnt=0;
  for(int i=0;i<N;++i){
    if(a[i]<b[i]) cnt += (b[i]-a[i])/2;
    else cnt -= (a[i]-b[i]);
  }

  if(cnt>=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int N, A[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    int sm = 0;
    rep(i, 0, N) sm += A[i];

    int d = inf, ans = inf;
    rep(i, 0, N) {
        int dd = abs(sm - A[i] * N);
        if (dd < d) {
            d = dd;
            ans = i;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> a(n);
  int c;
  for(int i=0;i<q;i++){
    cin>>c;
    a.at(c-1)++;
  }
  for(int i=0;i<n;i++){
    if(k+a.at(i)-q>0){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 1024
n = int(input())
a, b, c = [],[],[]
dp = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
    v1, v2, v3 = map(int, input().split())
    a.append(v1)
    b.append(v2)
    c.append(v3)

dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for i in range(1, n):
    # dp[i][0] = max(dp[i-1][1] + a[i-1], dp[i-1][2] + a[i-1])
    # dp[i][1] = max(dp[i-1][0] + b[i-1], dp[i-1][2] + b[i-1])
    # dp[i][2] = max(dp[i-1][0] + c[i-1], dp[i-1][1] + c[i-1])
    dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i])
    dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i])
    dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i])

# print("dpx: " + str(dp[n-1][0]))
# print("dpy: " + str(dp[n-1][1]))
# print("dpz: " + str(dp[n-1][2]))

print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))



Measured memory_bytes: 80348
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> d(n);
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    ll e = d[d.size()/2 - 1];
    ll f = d[d.size()/2];
    cout << f - e << endl;

}

Measured memory_bytes: 1024
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int r, g, b;
  cin >> r >> g >> b;
  cout << ((g * 10 + b) % 4 == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
from itertools import accumulate

def solve():
    N = int(input())
    Ss = input().rstrip()

    Rs, Gs, Bs = [], [], []
    numRs = [0] * N
    numGs = [0] * N
    numBs = [0] * N
    for i in range(N):
        S = Ss[i]
        if S == 'R':
            Rs.append(i)
            numRs[i] = 1
        elif S == 'G':
            Gs.append(i)
            numGs[i] = 1
        else:
            Bs.append(i)
            numBs[i] = 1

    lenR, lenG, lenB = len(Rs), len(Gs), len(Bs)
    setR = set(Rs)
    setG = set(Gs)
    setB = set(Bs)

    accNumRevRs = list(accumulate(numRs[::-1]))[::-1]
    accNumRevGs = list(accumulate(numGs[::-1]))[::-1]
    accNumRevBs = list(accumulate(numBs[::-1]))[::-1]

    ans = 0
    for j in range(N):
        S = Ss[j]
        if S == 'R':
            for i in Gs:
                if i > j:
                    break
                ans += accNumRevBs[j]
                k = 2*j-i
                if k in setB:
                    ans -= 1
            for i in Bs:
                if i > j:
                    break
                ans += accNumRevGs[j]
                k = 2*j-i
                if k in setG:
                    ans -= 1
        elif S == 'G':
            for i in Rs:
                if i > j:
                    break
                ans += accNumRevBs[j]
                k = 2*j-i
                if k in setB:
                    ans -= 1
            for i in Bs:
                if i > j:
                    break
                ans += accNumRevRs[j]
                k = 2*j-i
                if k in setR:
                    ans -= 1
        else:
            for i in Rs:
                if i > j:
                    break
                ans += accNumRevGs[j]
                k = 2*j-i
                if k in setG:
                    ans -= 1
            for i in Gs:
                if i > j:
                    break
                ans += accNumRevRs[j]
                k = 2*j-i
                if k in setR:
                    ans -= 1

    print(ans)


solve()


Measured memory_bytes: 68932
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;



signed main(){
    int a,b,n;
    cin >> a >> b >> n;
    int s,f;
    rep(i,n)
    {
        cin >> s >> f;
        if((a<=s&&s<b)||(a<f&&f<=b)||(s<=a&&b<=f))
        {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3096
import sys
import heapq
from math import ceil

input = sys.stdin.readline

N,M = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]

hq = []
for i in range(N):
    heapq.heappush(hq, -A[i])

for i in range(M):
    m = heapq.heappop(hq)
    heapq.heappush(hq, ceil(m / 2))

print(-sum(hq))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 88;
const int ZERO = MAX*MAX*2;

int H, W;
int A[MAX][MAX], B[MAX][MAX];
bitset<ZERO*2+1> dp[MAX][MAX];

ll solve() {
    dp[1][0].set(ZERO);
    dp[0][1].set(ZERO);
    REP (h, H) REP (w, W) {
        ll diff = abs(A[h][w] - B[h][w]);
        dp[h+1][w+1] |= (dp[h+1][w] << diff);
        dp[h+1][w+1] |= (dp[h+1][w] >> diff);
        dp[h+1][w+1] |= (dp[h][w+1] << diff);
        dp[h+1][w+1] |= (dp[h][w+1] >> diff);
    }
    bitset<ZERO*2+1> res = dp[H][W] >> ZERO;
    REP (i, ZERO) if (res.test(i)) return i;
}

int main() {
    cin >> H >> W;
    REP (h, H) REP (w, W) cin >> A[h][w];
    REP (h, H) REP (w, W) cin >> B[h][w];
    cout << solve() << endl;
}

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

#define MAX 2000001
#define VMAX 10000

int main() {

    int C[VMAX + 1];
    for (int i = 0; i <= VMAX; ++i) C[i] = 0;

    int n;
    cin >> n;
    unsigned short *A, *B;
    A = new unsigned short[n + 1];
    B = new unsigned short[n + 1];
    for (int i = 0; i < n; ++i) {
        cin >> A[i + 1];
        C[A[i + 1]]++;
    }

    for (int i = 1; i <= VMAX; ++i) {
        C[i] = C[i] + C[i - 1];
    }

    for (int i = 1; i <= n; ++i) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }

    for (int i = 1; i <= n; ++i) {
        if (1 < i) cout << " ";
        cout << B[i];
    }
    cout << endl;

    delete[] A;
    delete[] B;
    return 0;
}

Measured memory_bytes: 8788
#!/usr/bin/env python3
INF = float("inf")


def main():
    H, W, K = map(int, input().split())
    x1, y1, x2, y2 = map(lambda x: int(x)-1, input().split())
    c = []
    for i in range(H):
        c.append(input())

    DX = [1, 0, -1,  0]
    DY = [0, 1, 0, -1]

    # 方向付きで、ダイクストラ法を使います。
    dist = [[-1]*W for _ in range(H)]
    dist[x1][y1] = 0
    # ヒープでなくて良い。
    # 高々1しか加わっていかないため、キューに加えられた順で十分昇順になる。
    Q = []
    Q.append((0, x1, y1, 0))
    Q.append((0, x1, y1, 1))
    Q.append((0, x1, y1, 2))
    Q.append((0, x1, y1, 3))
    i = 0
    while i < len(Q):
        curr, x, y, DXY = Q[i]
        dx, dy = DX[DXY], DY[DXY]
        for k in range(1, K+1):
            X, Y = x+k*dx, y+k*dy
            if not (0 <= X < H) or not (0 <= Y < W):
                break
            if 0 < dist[X][Y] < curr+1:
                break
            if dist[X][Y] == curr+1:
                continue
            if c[X][Y] == "@":
                break
            dist[X][Y] = curr+1
            Q.append((curr+1, X, Y, (DXY+1) % 4))
            Q.append((curr+1, X, Y, (DXY-1) % 4))
        else:
            Q.append((curr+1, X, Y, DXY))
        if 0 < dist[x2][y2]:
            print(dist[x2][y2])
            return
        i += 1
    print(-1)
    return


if __name__ == '__main__':
    main()


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

int main(){
  int n,k; cin>>n>>k;
  ll ans =0;
  vector<ll> a(n);
  vector<ll> s1(n+1,0);
  vector<ll> s2(n+1,0);

  for(int i=0; i<n; i++){
    cin>>a[i];
    s1[i+1] = s1[i]+a[i];
    s2[i+1] = s2[i]+ max(a[i],0ll);
  }

  int left,right;
  
  for(int i=0; i<=n-k; i++){
    left = i;
    right = i+k;
    ll comp;
    comp = s2[left]-s2[0]+max(s1[right]-s1[left],0ll)+s2[n]-s2[right];
    ans = max(comp,ans);
  }

  cout<<ans<<endl;

  return 0;
  
}


Measured memory_bytes: 2560
#!/usr/bin/env python3
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    if t[i + 1] - t[i] > T:
        ans += T
    else:
        ans += t[i + 1] - t[i]
ans += T
print(ans)


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

     long long int n,i,j=1,c=0,f=0000000000,l,k,x,y,z,m,b,a;
     string s="",s1;
     char o;
     set <int, greater <int> > st;
     stack<char>sta;
     //int a[5];
    //long long  int arr[n+2][n+2];
     vector<char>ch(27);
     vector<string>str;
     vector<int>vect,vect3;
     map<int,int>mp;
     cin>>n;
     for(i=0;i<n;i++)
     {
         cin>>k;
         vect.push_back(k);
     }
     for(i=0;i<n-2;i++)
     {
         for(j=i+1;j<n-1;j++)
         {
             for(l=j+1;l<n;l++)
             {
                 if(vect[i]!=vect[j]&&vect[j]!=vect[l]&&vect[i]!=vect[l]){
                 if(vect[i]+vect[j]>vect[l]&&vect[i]+vect[l]>vect[j]&&vect[j]+vect[l]>vect[i])
                    {
                        //cout<<vect[i]<<" "<<vect[j]<<" "<<vect[l]<<endl;
                        c++;
                    }
                 }
             }
         }
     }
     cout<<c<<endl;

}



Measured memory_bytes: 3604
#include <cstdio>
int main(){
    int chukan, kimatsu, sai;
    
    while (1){
        scanf("%d%d%d", &chukan, &kimatsu, &sai);
        if (chukan == -1 && kimatsu == -1 && sai == -1){
            break;
        }
        if (chukan == -1 || kimatsu == -1){
            printf("F\n");
        }
        else if (chukan + kimatsu >= 80){
            printf("A\n");
        }
        else if (chukan + kimatsu >= 65){
            printf("B\n");
        }
        else if (chukan + kimatsu >= 50){
            printf("C\n");
        }
        else if (chukan + kimatsu >= 30){
            if (sai >= 50){
                printf("C\n");
            }
            else {
                printf("D\n");
            }
        }
        else {
            printf("F\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
    vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
  int A = 0, B = 0;
    for (int i = 0; i < (N + 1) / 2; i++) {
      A = A + vec.at(2 * i);
     if (2 * i + 1 <  N) {
      B = B + vec.at(2 * i + 1);
     }
    }
  if (A > B) {
    cout << A - B << endl;
  }
  else {
    cout << B - A << endl;
  }
}
      

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

char a[10],b[10];
int ia,ib;
int n;
int ta,tb;
char ans[10];

void transa(){
  ia = 0;
  for(int i = ta-1 ; i >= 0 ; i--){
    if(a[i] == 'i'){ 
      if(i == 0) ia += 1;
      else{
	if( atoi(&a[i-1]) != 0 ){
	  ia += atoi(&a[i-1]);
	}else{
	  ia += 1;
	}
      }
    }else if(a[i] == 'x'){   
      if(i == 0) ia += 10;
      else{
	if( atoi(&a[i-1]) != 0 ){
	  ia += atoi(&a[i-1]) * 10;
	}else{
	  ia += 10;
	}
      }
    }else if(a[i] == 'c'){
      if(i == 0) ia += 100;
      else{
	if( atoi(&a[i-1]) != 0 ){
	  ia += atoi(&a[i-1]) * 100;
	}else{
	  ia += 100;
	}
      }
    }else if(a[i] == 'm'){
      if(i == 0) ia += 1000;
      else{
	if( atoi(&a[i-1]) != 0 ){
	  ia += atoi(&a[i-1]) * 1000;
	}else{
	  ia += 1000;
	}
      }
    }
  }
  return;
}


void transb(){
  ib = 0;
  for(int i = tb-1 ; i >= 0 ; i--){
    if(b[i] == 'i'){ 
      if(i == 0) ib += 1;
      else{
	if( atoi(&b[i-1]) != 0 ){
	  ib += atoi(&b[i-1]);
	}else{
	  ib += 1;
	}
      }
    }else if(b[i] == 'x'){   
      if(i == 0) ib += 10;
      else{
	if( atoi(&b[i-1]) != 0 ){
	  ib += atoi(&b[i-1]) * 10;
	}else{
	  ib += 10;
	}
      }
    }else if(b[i] == 'c'){
      if(i == 0) ib += 100;
      else{
	if( atoi(&b[i-1]) != 0 ){
	  ia += atoi(&b[i-1]) * 100;
	}else{
	  ib += 100;
	}
      }
    }else if(b[i] == 'm'){
      if(i == 0) ib += 1000;
      else{
	if( atoi(&b[i-1]) != 0 ){
	  ib += atoi(&b[i-1]) * 1000;
	}else{
	  ib += 1000;
	}
      }
    }
  }
  return;
}

void inv(){

  int j = 0,n = ia + ib;

  if( n / 1000 != 0){
    if(n/1000 != 1){
      cout << n/1000;
    }
    cout << 'm';
    n = n % 1000;
  }
  if( n / 100 != 0){
    if(n/100 != 1){
      cout << n/100;
    }
    cout << 'c';
    n = n % 100;
  }
  if( n / 10 != 0){
    if(n/10 != 1){
      cout << n/10;
    }
    cout << 'x';
    n = n % 10;
  }
  if( n != 0){
    if(n != 1){
      cout << n;
    }
    cout << 'i';
  }
  cout << endl;

  return;
}

int main(){

  cin >> n;
  while(n){

    cin >> a >> b;

    int i;
    for(i = 0 ; a[i] != '\0' ;i++){}
    ta = i;
    for(i = 0 ; b[i] != '\0' ;i++){}
    tb = i;
    transa();
    transb();
    inv();
    n--;
  }
  return 0;

}

Measured memory_bytes: 1176
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

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

    int numR = 0;
    rep(i, S.size()) {
        if(S[i] != 'R') {
            continue;
        }
        numR++;
        if(S[i+1] == 'R') {
            continue;
        }
        ret[i] = (numR + 2 - 1) / 2;
        ret[i+1] = (numR / 2);
        numR = 0;
    }

    int numL = 0;
    for(int i = S.size() - 1; i >= 0; --i) { 
        if(S[i] != 'L') {
            continue;
        }
        numL++;
        if(S[i-1] == 'L') {
            continue;
        }
        ret[i]   += (numL + 2 -1) / 2;
        ret[i-1] += (numL / 2);
        numL = 0;
    }

    rep(i, S.size()) {
        cout << ret[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in [0]*q]

    que = [[1]]
    for _ in range(n):
        que2 = []
        for qq in que:
            i = qq[-1]
            for j in range(i, m+1):
                que2.append(qq+[j])
        que = que2

    ans = 0
    for q in que:
        temp = 0
        for a, b, c, d in abcd:
            if q[b]-q[a] == c:
                temp += d
        ans = max(ans, temp)
    print(ans)


main()


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

int main() {
	string s;
	int x[2];
	cin >> s >> x[0] >> x[1];
	vector<int> v;
	int k = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'F') {
			k++;
		} else {
			v.push_back(k);
			k = 0;
		}
	}
	v.push_back(k);

	/*
	for (auto e : v) {
		cout << e << " ";
	}
	cout << endl;
	*/

	x[0] -= v[0];
	vector<int> u[2];
	for (int i = 1; i < v.size(); i++) {
		u[i % 2].push_back(v[i]);
	}
	bool r = true;
	for (int i = 0; i < 2; i++) {
		set<int> a;
		a.insert(0);
		for (auto e : u[i]) {
			set<int> b;
			for (auto f : a) {
				b.insert(f - e);
				b.insert(f + e);
			}
			a = b;
		}
		r &= a.count(x[i]);
		if (!r) {
			break;
		}
	}
	cout << (r ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int a[3][3], n;
bool bingo[3][3];

int main() {
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    cin >> n;

    rep(i, n) {
        int b; cin >> b;
        rep(j, 3) rep(k, 3) {
            if (a[j][k] == b) bingo[j][k] = true;
        }
    }

    bool ok = false;
    rep(i, 3) {
        if (bingo[i][0] && bingo[i][1] && bingo[i][2]) ok = true;
    }
    rep(j, 3) {
        if (bingo[0][j] && bingo[1][j] && bingo[2][j]) ok = true;
    }
    if (bingo[0][0] && bingo[1][1] && bingo[2][2]) ok = true;
    if (bingo[0][2] && bingo[1][1] && bingo[2][0]) ok = true;

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  vector<bool> color(8);
  int free = 0;
  rep(i,n) {
    int a;
    cin >> a;
    rep(j,8) {
      if (400*j <= a && a < 400*(j+1)) {
        color[j] = true;
        break;
      }
    }
    if (a >= 3200) free++;
  }

  int mi = 0, ma;
  rep(i,8) {
    if (color[i]) mi++;
  }
  ma = mi + free;
  if (mi == 0) {
    mi = 1;
    ma = free;
  }
  cout << mi SP ma << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  int ac=0,wa=0,tle=0,re=0;
  for(int i=0;i<N;i++){
    string s;cin>>s;
    if(s=="AC")ac++;
    if(s=="WA")wa++;
    if(s=="TLE")tle++;
    if(s=="RE")re++;
    
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3628
/***
    Range Minimum/Maximum Query 
    Segment Tree
    length of sequence is N
    manipulates a sequence A = { a0, a1,... ,a(N-1) } with the following operations
    $ find(x,y) : report the minimum element in a(x), a(x+1),... ,a(y)
    $ update(x,y) : change a(x) to y
    time complexity of each queries are O(logN)
 */
#include<bits/stdc++.h>

using namespace std;

const int IINF = INT_MAX;

class RMQ{
private:
  int limit,N;
  vector<int> dat;
public:
  void init(int n_){
    N = n_;
    limit = 1;
    while(limit<n_) limit*=2;
    dat.clear();
    dat.resize(2*limit,IINF);
  }
  
  int _build(int cur,int L,int R,const vector<int> &buf){
    if( !( 0 <= cur && cur < 2*limit ) ) return IINF;
    if( L == R-1 ) {
      if( L >= N ) return IINF;
      dat[cur] = buf[L];
    } else {
      int vl = _build(cur*2+1,L,(L+R)/2,buf);
      int vr = _build(cur*2+2,(L+R)/2,R,buf);
      dat[cur] = min(vl,vr);
    }
    return dat[cur];
  }

  void build(const vector<int> &buf){ _build(0,0,limit,buf); };

  void update(int k,int a){
    k += limit-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = min(dat[k*2+1],dat[k*2+2]);
    }
  }
 
  int _query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return IINF;
    else if(a<=l && r<=b)return dat[k];
    int vl = _query(a,b,k*2+1,l,(l+r)/2);
    int vr = _query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }

  int query(int a,int b){ return _query(a,b,0,0,limit); }
};

int main(){
  int N,Q;
  cin >> N >> Q; // length of sequence, the number of query

  RMQ rmq;
  rmq.init(N); // initialy, all elements are 2^31-1
  /* 
    vector<int> init;
    // input initial values to initi
    rmq.build(init);
   */
  for(int i=0;i<Q;i++) {
    int opr,x,y;
    cin >> opr >> x >> y;
    if( opr == 0 ) rmq.update(x,y); // update
    else if( opr == 1 ) printf("%d\n",rmq.query(x,y+1)); // find
  }
  return 0;
}

Measured memory_bytes: 2052
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int g[100][100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			g[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			g[u - 1][v - 1] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j > 0) {
				cout << " ";
			}
			cout << g[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main() {
	int n, k, s; cin >> n >> k >> s;
	for (int i = 0; i < k; ++i) {
		if (i) cout << " ";
		cout << s;
	}
	for (int i = k; i < n; ++i) {
		if (i) cout << " ";
		if (s < 3) cout << s + 1;
		else cout << s - 1;
	}
	cout << endl;

	return 0;
}

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

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

typedef long long ll;

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

  int min = 0;
  int max = n;

  for(int i=0; i<m; i++){
    int l,r;
    cin >> l >> r;
    if(l > min) {
      min = l;
    }
    if(r < max) {
      max = r;
    }
  }

  if(min > max) cout << "0" << endl;
  else cout << max - min + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
if x>=(1/2)*a*a*b:
  y=2*(b-x/(a*a))
  print(math.degrees(math.atan2(y,a)))
else:
  y=2*x/(a*b)
  print(math.degrees(math.atan2(b,y)))

Measured memory_bytes: 9440
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
	float n;
    cin>>n;
    float x,x2;
    x=n/1.08;
    x2=(int)x;
    
    if((int)(x2*1.08)==n) cout<<x2<<endl;
    else if((int)((x2+1)*1.08)==n) cout<<x2+1<<endl;
    else cout<<":("<<endl;
 
	return 0;
}

Measured memory_bytes: 256
import sys 
input = sys.stdin.readline
yes = "YES"
no = "NO"
s=input()
t=input()
ls=[0]
lt=[0]
p=0
for c in s:
    if c == "A":p += 1
    else:p-= 1
    ls.append(p)
p=0
for c in t:
    if c == "A":p += 1
    else:p-= 1
    lt.append(p)

q=int(input())
for _ in range(q):
    a,b,c,d = map(int,input().split())
    if (ls[b]-ls[a-1])%3 == (lt[d]-lt[c-1])%3:print(yes)
    else:print(no)

Measured memory_bytes: 56796
N = int(input())
count = 0
max_count = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        count += 1
        max_count = max(max_count, count) 
    else:
        count = 0
print('Yes' if max_count > 2 else 'No')

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
 int a,b;
 cin>>a>>b;
 double i=1;
 while (true)
 {
     /* code */
     int ai=i*0.08;
     int bi=i*0.1;
     if (ai==a&&bi==b)
     {
         /* code */
         cout<<i<<endl;
         break;
     }
     if (i>1000)
     {
         /* code */
         cout<<-1<<endl;
         break;
     }
     
     i++;
 
     
 }
 
 
}

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

using namespace std;

typedef pair<int, int> P;

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

    int N;
    while(cin>>N,N){
        vector<P> v(N);
        v[0]=P(0,0);
        for(int i=1;i<N;i++){
            int n,d;cin>>n>>d;
            int f=v[n].first,s=v[n].second;
            if(d==0) f--;
            else if(d==1) s--;
            else if(d==2) f++;
            else s++;
            v[i]=P(f,s);
        }
        int xmax=0,xmin=0,ymax=0,ymin=0;
        for(int i=0;i<N;i++){
            xmax=max(xmax,v[i].first);
            xmin=min(xmin,v[i].first);
            ymax=max(ymax,v[i].second);
            ymin=min(ymin,v[i].second);
        }
        cout<<xmax-xmin+1<<" "<<ymax-ymin+1<<endl;
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.sync_with_stdio(0); cout.tie(0);
#define Bye return 0
const int MAX = 1e6+1;
#define int long long

void solve() {
    int n;
    cin>>n;

    int a[n], b[n], c[n];
    for (int i=0; i<n; i++)
        cin>>a[i]>>b[i]>>c[i];

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i = 1; i<n; i++){
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
    }

    cout<<max({dp[n-1][0],dp[n-1][1], dp[n-1][2]})<<endl;
}

int32_t main() {
    IOS;
    solve();
    Bye;
}


Measured memory_bytes: 8308
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX; //1LL << 62;
/* テンプレートここまで */

int main() {
  ll N, K; cin >> N >> K;
  vector<ll> x(N), y(N), xx(N), yy(N);
  REP(i, N){
    cin >> x[i] >> y[i];
    xx[i] = x[i];
    yy[i] = y[i];
  }
  sort(ALL(x)); sort(ALL(y));

  ll ans = INF;
  REP(i, N-1) FOR(j, i+1, N) REP(k, N-1) FOR(l, k+1, N){
    ll cnt = 0;
    REP(p, N) {
      if(xx[p] >= x[i] && xx[p] <= x[j] && yy[p] >= y[k] && yy[p] <= y[l]) cnt++;
    }
    ll s = (x[j] - x[i]) * (y[l] -y[k]);
    if(cnt>=K && ans > s) ans = s; 
  }  
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
print(3*n*n)

Measured memory_bytes: 12528
// 全探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 20;
const int MAX_N_2 = 10000000;
const int MAX_Q = 200;

// 入力値を保持するバッファ
int input_buffer[MAX_N + 1];
// 組み合わせの管理用バッファ
int comb_buffer[MAX_N + 1];
// 組み合わせから求めた和を格納する配列
int pos = 0;
int add_buffer[MAX_N_2];

void combinations(int n, int r);
void comb_sub(int n, int r, int m);
void add_combination(int m);

int main(void)
{
    int n, q, Q[MAX_Q + 1];

    scanf("%d", &n);

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

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &Q[i]);
    }

    for(int i = 0; i < n; i++)
    {
        combinations(n, i);
    }

    for(int i = 0; i < q; i++)
    {
        bool judge = false;

        for(int j = 0; j < pos; j++)
        {
            if( add_buffer[j] == Q[i] )
            {
                judge = true;
                break;
            }
        }

        if( judge )
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 組み合わせを生成する関数の入り口
void combinations(int n, int r)
{
	if (r > 0 && r <= MAX_N)
	{
		comb_sub(n, r, 0);
	}
}

// 組み合わせを生成する関数
// n : 選択する数値の範囲 ( 1〜 n )
// r : 選ぶ数値の個数
// m : 選んだ数値の個数
void comb_sub(int n, int r, int m)
{
	if ( r == 0 )
	{
        // r が 0 になったので、組み合わせを一つ生成できた
		add_combination(m);
	}
	else if ( n == r )
	{
		for (int i = r; i > 0; i--)
		{
			// n が r と等しくなったならば、残りの数字 (1 から r まで) を全て選択
			comb_buffer[m++] = i;
		}

		add_combination(m);
	}
	else
	{
		// nを選ばない場合
		// 残りの数字の中から r 個の数字を選びます。
		comb_sub(n - 1, r, m);

		// nを選ぶ場合
		// 数字 n を comb_buffer に追加して、残りの数字の中から r - 1 個を選びます。
		comb_buffer[m] = n;
		comb_sub(n - 1, r - 1, m + 1);
	}

    return;
}

// 入力数値の和を求める
void add_combination(int m)
{
    // 配列の初期化
    add_buffer[pos] = 0;

    for(int i = 0; i < m; i++)
    {
    	// 入力された数列の和を順番に求める
        add_buffer[pos] += input_buffer[comb_buffer[i] - 1];
    }

    // 要素を進める
    pos++;

    return;
}



Measured memory_bytes: 7236
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	int n;
	int k;
	HashMap<Integer,Integer> a;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		a = new HashMap<Integer,Integer>();
		for(int i=0;i<n;i++){
			int num = sc.nextInt();
			if(a.containsKey(num)) {
				a.replace(num, a.get(num)+1);
			} else {
				a.put(num, 1);
			}
		}
	}
	void solve(){
		int ans = 0;
		if(a.size()>k){
			LinkedList<Integer> l = new LinkedList<Integer>(a.values());
			Collections.sort(l);
			while(l.size()>k){
				ans += l.remove();
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 102856
import sys
from collections import defaultdict
dic1 = defaultdict(int)
dic2 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)
n = int(readline())
zero = 0
for i in range(n):
    a,b= map(int,readline().split())
    if a == b == 0:
        zero += 1
        continue
    plamai = 1 if a*b > 0 else 0
    a,b = to_standard_form(a,b)
    if b <= 0:
        dic2[(a,b)] += 1
    else:
        dic1[(b,-a)] += 1
        dic2[(b,-a)] += 0

ans = zero
k = 1
for key,cnt in dic2.items():
    cnt2 = dic1[key]
    x = pow(2,cnt)+pow(2,cnt2)
    k = k*(x-1)%mod
print((ans+k-1)%mod)

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

int h,w;
int dp[101][101][2][2];

int main(){
	while(cin>>w>>h,w||h){
		memset(dp,0,sizeof(dp));
		dp[1][0][0][0]=1;
		dp[0][1][1][0]=1;
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				for(int i=0;i<2;i++){
					for(int j=0;j<2;j++){
						dp[y][x][i][j] %= 100000;
						int a = dp[y][x][i][j];
						//printf("%d %d %d %d %d\n",y,x,i,j,a);
						if(j==1){
							if(i==0){
								dp[y+1][x][0][0] += a;
							}
							else{
								dp[y][x+1][1][0] += a;
							}
						}
						else{
							if(i==0){
								dp[y+1][x][0][0] += a;
								dp[y][x+1][1][1] += a;
							}
							else{
								dp[y][x+1][1][0] += a;
								dp[y+1][x][0][1] += a;
							}
						}
					}
				}
			}
		}
		int (&ans)[2][2] = dp[h-1][w-1];
		cout<<(ans[0][0]+ans[0][1]+ans[1][0]+ans[1][1])%100000<<endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    
    string S;
    cin >> S;
    int N = int(S.length());
    rep(i,N) reps(j,i,N){
        string a = S.substr(0,i);
        a += S.substr(j,N-j);
        if(a == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    
    cout << "NO" << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> a(N+1);
  for(int i=1;i<=N;i++)cin>>a[i];
  int cnt=0;
  for(int i=1;i<=N;i++){
    if(a[a[i]]==i)cnt++;
  }
  cout<<cnt/2<<endl;
}

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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 250;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(cin >> n >> m) {
    for(int i = 0; i < n; ++i) {
      cin >> ps[i].first >> ps[i].second;
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; cin >> s >> t >> u >> v;
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1316
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	int K, S;
	cin >> K >> S;
	int t = 0;
	int d = 0;
	int s = 0;

	for (int i = 0; i <= K; i++) {
		for (int j = i + 1; j <= K; j++) {
			for (int k = j + 1; k <= K; k++) {
				if (i + j + k == S) {
					t++;
					break;
				}
			}
		}
	}
	t *= 6;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (i == j)
				continue;
			if (i + i + j == S) {
				d++;
				break;
			}
		}
	}
	d *= 3;
	for (int i = 0; i <= K; i++) {
		if (i + i + i == S) {
			s++;
			break;
		}
	}

	cout << t + d + s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    vector<ll> num(4);
    for(int i = 0; i < 4; i++) cin >> num[i];
    ll n;
    cin >> n;
    ll ans = (n*4)*num[0];
    ans = min((n*2)*num[1],ans);
    ans = min(ans,n*num[2]);
    if(n%2 == 1){
        ans = min(ans,(n/2)*num[3]+min(num[0]*4,min(num[1]*2,num[2])));
    }else ans = min(ans,(n/2)*num[3]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

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

int change(int panel[10][10], int y, int x, int c){
	int sum=1;
	int color=panel[y][x];
	panel[y][x]=c;
	for(int i=0; i<4; i++)
		if(panel[y+dy[i]][x+dx[i]] == color){
			sum+=change(panel, y+dy[i], x+dx[i], c);
		}
	return sum;
}

int solve(int panel[10][10], int depth, int c){
	if(depth >= 5) {
		if(panel[1][1] != c) return 0;
		else return change(panel, 1, 1, 0);
	}
	int ans=0;
	for(int i=1; i<=6; i++){
		int tmp[10][10];
		if(panel[1][1]==i) continue;
		for(int j=0; j<10; j++){
			for(int k=0; k<10; k++){
				tmp[j][k] = panel[j][k];
			}
		}
		change(tmp, 1, 1, i);
		ans = max(ans, solve(tmp, depth+1, c));
	}
	return ans;
}

int main(){
	while(1){
		int h, w, c; cin >>h>>w>>c;
		if(!h && !w) break;

		int panel[10][10]={0};
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin>>panel[i][j];
			}
		}
		cout<<solve(panel, 0, c)<<endl;
	}
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
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; }

int main() {
    double A, B, P, Q, R;

    cin >> A >> B >> P >> Q >> R;

    printf("%.10f\n", B + (B * P - (B - A) * Q) / (Q + R));

    return (0);
}



Measured memory_bytes: 3216
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    scanf ("%d%d", &n, &m);
    if (n == 1 && m == 1) printf ("1");
    else if (n == 1) printf ("%d", m - 2);
    else if (m == 1) printf ("%d", n - 2);
    else printf ("%lld", 1ll * n * m - 2ll * (n - 1) - 2ll * (m - 1));
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=998244353;
#define N 3000000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    string s;
    cin>>s;
    int w;
    cin>>w;
    for(int i=0;i<s.size();i+=w){
        cout<<s[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long n,k;cin>>n>>k;
    long long ans=0;
    for(long long i=1;i<=n;i++){
        if(i>k){
            long long x,rest;
            x=n/i;
            rest=n%i;
            ans+=x*(i-k);
            if(rest-k+1>0&&rest>0)ans+=rest-k+1;
        }
    }
    if(k==0)ans=n*n;
    cout<<ans<<endl;
    return 0;
}

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

int main(){

  	long int H;
  	long int count = 1;
  	long int solution = 0;
	cin >> H;
  
  	while(H>1){
    	H = H /2;
    	count++;}
  
  
  	for(long int i = 0; i < count; i++){
    	solution += pow(2,i);}
  
  
  	cout << solution;
  	

}


Measured memory_bytes: 256
import math
mod = 10**9 + 7
n,a,b=map(int,input().split())
k=a
modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans
d=binomial_coefficients(n, a)
k=b

modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans
e=binomial_coefficients(n, b)
c = pow(2,n%(10**9+7), 10**9+7)
print((c-d-e-1)%(10**9+7))

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll n; cin >> n;
  ll cur = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll a; cin >> a;
    if (a < cur) {
      ans += cur - a;
    }else {
      cur = a;
    }
  }
  cout << ans << endl;
  return 0;

}



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

int main(void){
    string tCard,hCard;
    int n,tScore=0,hScore=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>tCard>>hCard;
        if(tCard==hCard){
            tScore++;hScore++;
        }else if(tCard>hCard){
            tScore+=3;
        }else{
            hScore+=3;
        }
    }
    cout<<tScore<<" "<<hScore<<endl;
    return 0;
}

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

int H, W, D;

int abs(int a) noexcept;
int mdist(pair<int, int>a, pair<int, int>b);

int main(){
    cin >> H >> W >> D;
    vector<pair<int, int>>A(H*W*2, make_pair(1000, 1000));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int tmp;
            cin >> tmp;
            A[tmp-1] = make_pair(i, j);
        }
    }
    vector<vector<int>>Dists(D, vector<int>((H*W)/D + 1, 0));
    for(int k=0; k<D; k++){
        pair<int, int>prevP = A[k];
        Dists[k][0]=0;
        for(int i=1; i<(H*W)/D +1; i++){
            pair<int, int>tmpP = A[k+D*i];
            Dists[k][i]=Dists[k][i-1]+mdist(tmpP, prevP);
            prevP = tmpP;
        }
    }
    int Q;
    cin >> Q;
    vector<pair<int, int>>T(Q); //L, R
    for(int i=0; i<Q; i++){
        cin >> T[i].first >> T[i].second;
        T[i].first--;
        T[i].second--;
    }
    for(int i=0; i<Q; i++){
        int surp=T[i].first % D;
        int ln=T[i].first/D, rn=T[i].second/D;
        cout << Dists[surp][rn] - Dists[surp][ln] << '\n';
    }
    return 0;
}

int abs(int a) noexcept{
    return (a>0 ? a : -a);
}

int mdist(pair<int, int>a, pair<int, int>b){
    return abs(b.first-a.first)+abs(b.second-a.second);
}


Measured memory_bytes: 7552
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <map>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}

vector<pair<ll, int>> prime_factorize(ll n) {
    vector < pair < ll, int >> res;
    int num = 0;
    while (n % 2 == 0) {
        num++;
        n /= 2;
    }
    if (num != 0) res.emplace_back(make_pair( 2, num ));

    for (ll p = 3; p * p <= n; p += 2) {
        num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        if (num != 0) res.emplace_back(make_pair(p, num));
    }
    if (n != 1)res.emplace_back(make_pair(n, 1));
    return res;
}


struct Room {
    int id, mark, step;
    vector<int> vicinities;
};

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int> As(N + 1);
    vector<int> steps(N + 1, -1);
    for (int i = 1; i <= N; i++) cin >> As[i];
    
    int step = 0, now=1, loop=1;
    steps[1] = step;
    while(true){
        now = As[now];
        step++;

        if (steps[now] == -1) {
            steps[now] = step;
            
        }
        else {
            loop = step - steps[now];
            step -= loop;
            break;
        }
    }

    if(K-step>0) K = step + (K - step) % loop;
    now = 1;
    for (ll t = 0; t < K; t++) {
        now = As[now];
    }
    print(now);
}



Measured memory_bytes: 4800