akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int n,m, x;
vector<vector<int>> A(12, vector<int>(12));
vector<ll> c(12);
ll num[12];
ll ans=100100100100;



int main(){
    fast_io
    
    cin>>n>>m>>x;
    
    vector<ll> sum(m,0);
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>A[i][j];
            sum[j]+=A[i][j];
        }
    }
    for(int i=0;i<m;i++){
        if(sum[i]<x){
            cout<<-1<<endl;
            return 0;
        }
        sum[i]=0;
    }

    for(int bit=0;bit<(1<<n);++bit){
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
        vector<ll> Sum(m,0);
        ll cnt=0;

        //cout << bit << ": {";
        
        //
        for (int i = 0; i < (int)S.size(); ++i) {
            //cout << S[i] << " ";
            for(int k=0;k<m;k++){
                Sum[k]+=A[S[i]][k];
            }
            cnt+=c[S[i]];
        }
        //cout << "}" << endl;
        //総和がxを越えたらansMINをとる
        bool flag=true;
        for(int k=0;k<m;k++){
                if(Sum[k]<x) flag=false;
            }
        if(flag) ans=min(ans, cnt);
        //cout<<cnt<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int K, X;
    cin >> K >> X;
    if (K * 500 >= X) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    cout << ((n * (n - 1)) / 2) + ((m * (m - 1)) / 2);

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  char A[N][N];
  char B[M][M];
  REP(i,N)REP(j,N)cin>>A[i][j];
  REP(i,M)REP(j,M)cin>>B[i][j];
  REP(i,N-M+1)REP(j,N-M+1){
    bool flag=1;
    REP(ii,M)REP(jj,M)if(A[i+ii][j+jj]!=B[ii][jj])flag=0;
    if(flag){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;

int a, b, c, k;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b >> c >> k;
    fore(i, 0, k)
    {
        if (a < b * (1 << i) && b * (1 << i) < c * (1 << (k - i)))
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


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

using namespace std;
using LL = long long int;
const LL mod = 1000000007;

#define int long long

const int MAX_N = 100005;

LL R, C;
int N;
LL X1[MAX_N], Y1[MAX_N], X2[MAX_N], Y2[MAX_N];

using II = pair<int, int>;

vector<II> v1;
vector<II> v2;
vector<II> v3;
vector<II> v4;

void push_vec(int x, int y, int i)
{
    if(y == 0) {
        v1.push_back(II(x, i));
    } else if(y == R) {
        v3.push_back(II(x, i));
    }

    if((x == 0 && y == 0) ||
       (x == C && y == 0) ||
       (x == C && y == R) ||
       (x == 0 && y == R)) {
           return;
    }

    if(x == C) {
        v2.push_back(II(y, i));
    } else if(x == 0) {
        v4.push_back(II(y, i));
    }
}

bool check(int x1, int y1, int x2, int y2) {
    return (0 == x1 || C == x1 || 0 == y1 || R == y1) && 
           (0 == x2 || C == x2 || 0 == y2 || R == y2);
}

signed main()
{
    cin >> R >> C >> N;
    for(int i = 0; i < N; i++) {
        cin >> Y1[i] >> X1[i] >> Y2[i] >> X2[i];
        if(check(X1[i], Y1[i], X2[i], Y2[i])) {
            push_vec(X1[i], Y1[i], i);
            push_vec(X2[i], Y2[i], i);
        }
    }

    sort(begin(v1), end(v1));
    sort(begin(v3), end(v3), greater<II>());
    sort(begin(v2), end(v2));
    sort(begin(v4), end(v4), greater<II>());
    
    vector<int> v;
    for(auto it : v1) {
        v.push_back(it.second);
    }
    for(auto it : v2) {
        v.push_back(it.second);
    }
    for(auto it : v3) {
        v.push_back(it.second);
    }
    for(auto it : v4) {
        v.push_back(it.second);
    }
    
    stack<int> S;
    bool used[MAX_N];
    memset(used, 0, sizeof(used));

    for(int i = 0; i < v.size(); i++) {
        //cerr << v[i] << endl;
        if(!used[v[i]]) {
            used[v[i]] = true;
            S.push(v[i]);
        } else {
            if(S.top() != v[i]) {
                
                cout << "NO" << endl;
                return 0;
            }
            S.pop();
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 10416
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1,n,a,b,m1,d1,m2,d2;
    //cin>>t;
    while(t--){
        cin>>n;
        if(n<100)
            cout<<0;
        else{
            ll temp=n/100;
            if(n<=temp*100+temp*5)
                cout<<1;
            else
                cout<<0;
        }
    }
    return 0;
}



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


ll pla(ll n,ll i)
{
  ll x = pow(10,i + 1),y = pow(10,i);
  return n % x / y;
}

ll keta(ll n)
{
  ll k = 0;
  while(n != 0)
  {
    n /= 10;
    k++;
  }
  return k;
}  


ll all(vector<ll> S)
{
  ll K=S.size();
  if(K==1) {return S.at(0);}
  
  vector<ll> S2=S;
  S2.at(K-2)=S2.at(K-2)*pow(10,keta(S2.at(K-1)))+S2.at(K-1);
  S2.pop_back();
  ll s=S.at(K-1);
  S.pop_back();
  /*cout<<"S=";
  rep(i,K-1)
  {
    cout<<S.at(i)<<",";
  }
  cout<<"  ";
  cout<<"S2=";
  rep(i,K-1)
  {
    cout<<S2.at(i)<<",";
  }
  cout<<"  ";
  cout<<"s="<<s<<endl;*/
  return all(S)+all(S2)+s*pow(2,K-2);
}  



int main() 
{
  ll S; cin>>S;
  ll K=keta(S);
  vector<ll> Svec(K);
  rep(i,K)
  {
    Svec.at(i)=pla(S,K-i-1);
  }
  /*rep(i,K)
  {
    cout<<Svec.at(i)<<" ";
  }
  cout<<endl;*/
  cout<<all(Svec)<<endl;
  return 0;
}

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

LL C[51][51], ans;
int N, n0, n1, P;

int main() {
    C[0][0] = 1;
    for (int k = 1; k <= 50; k++)
        C[0][k] = 0;
    for (int n = 1; n <= 50; n++)
        C[n][0] = 1;

    for (int n = 1; n <= 50; n++)
        for (int k = 1; k <= n; k++)
            C[n][k] = C[n - 1][k] + C[n - 1][k - 1];


    cin >> N >> P;
    n0 = n1 = 0;

    for (int i = 1; i <= N; i++) {
        int x;

        cin >> x;
        if (x % 2 == 0)
            n0++;
        else
            n1++;
    }

    ans = 0;
    for (int gan = P % 2; gan <= n1; gan += 2) {
        for (int gen = 0; gen <= n0; gen++) {
            ans += C[n1][gan] * C[n0][gen];
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
from math import atan,degrees
a,b,x = map(int,input().split())

if x >= a**2*b/2:  # けっっこうおおめ
    print(degrees(atan(2*(a**2*b-x)/a**3) ))
elif x < a**2*b/2:  # すっくねえ
    print(degrees(atan(b**2*a/(2*x))))


Measured memory_bytes: 3064
s = input()
t = input()

def LCS(X,Y):
    XL = len(X)
    YL = len(Y)
    dp = [[0 for j in range(YL+1)] for i in range(XL+1)]
    for i in range(XL):
        for j in range(YL):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    # 以下復元
    idx = dp[XL][YL]-1
    S = [0 for i in range(idx+1)]
    i,j = XL,YL
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i -= 1
            j -= 1
            S[idx] = X[i]
            idx -= 1
    return S

print(''.join(LCS(s,t)))


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

int main() {
    int64_t n, m;
    cin >> n >> m;
    int64_t ans = min(n, m / 2);
    m -= n * 2;
    if (m > 0) ans += m / 4;
    cout << ans << '\n';
    return 0;
}


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


int main(){
	int n, a, b,t=0,r=0,ans=0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		r = i;
		while (r>0) {
			t += r % 10;
			r /= 10;
		}
		if (t >= a && t <= b) { ans += i;}
		t = 0;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

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

struct hc{int c[10];};
hc ina;
//int mm[6][[10];

int calc(hc a, int mc)
{
  int ret=0;
  // rep(j,4-mc) printf("   ");
  // printf("calc called ");
  // rep(j,mc) printf("   ");
  // rep(i,10) {
  //   printf("%d ", a.c[i]);
  // }
  // printf("\n\n");
  if(!mc){
    rep(i,10)
      if(a.c[i]==2)
        ret++;
  }
  else{
    rep(i,10) if(a.c[i]>=3){
      hc tmp=a;tmp.c[i]-=3;
      ret+=calc(tmp,mc-1);
    }
    rep(i,8) if(a.c[i]*a.c[i+1]*a.c[i+2]>0){
      hc tmp=a;
      tmp.c[i]-=1;
      tmp.c[i+1]-=1;
      tmp.c[i+2]-=1;
      ret+=calc(tmp,mc-1);
    }
  }
  // rep(j,4-mc) printf("   ");
  // printf("calc return ");
  // rep(j,mc) printf("   ");
  // printf("%d ", ret);
  // printf("\n\n");
  return ret;
}

int main()
{
  char str[15];
  // int count=0;
  while(scanf(" %s",str)==1 && *str) {
    rep(i,10) ina.c[i]=0;
    rep(i,13) ina.c[str[i]-'0']++;
    // printf("%d:\n",count++);
    // rep(i,10)
    //   printf("%d: %d\n", i, ina.c[i]);
    // printf("\n");
    hc ret; rep(i,10)ret.c[i]=0;
    for(int i=1; i<10; i++)
      if(ina.c[i]<4){
        hc tmp=ina;
        tmp.c[i]+=1;
        ret.c[i]=calc(tmp,4);
      }
    
    string s;
    rep(i,10)
      if(ret.c[i]){
        s+=i+'0';
        s+=" ";
      }
    if(s.size()){
      s.erase(s.end()-1);
      cout << s << endl;
    }else{
      cout << "0" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, d, e, f;
    int h, i, j, k, l, m;
    int x;
    string v;
    
    cin >> a >> b >> c >> d >> e >> f;
    cin >> v;
    
    while(v[x] != '\0'){
        if(v[x] == 'N') {
            h = b;
            i = f;
            j = c;
            k = d;
            l = a;
            m = e;
        }
        
        else if(v[x] == 'E'){
            h = d;
            i = b;
            j = a;
            k = f;
            l = e;
            m = c;
        }
        
        else if(v[x] == 'W'){
            h = c;
            i = b;
            j = f;
            k = a;
            l = e;
            m = d;
        }
        
        else if(v[x] == 'S'){
            h = e;
            i = a;
            j = c;
            k = d;
            l = f;
            m = b;
        }
        
        a = h;
        b = i;
        c = j;
        d = k;
        e = l;
        f = m;
        
        x++;
    }
    
    cout << a << endl;
    
}


Measured memory_bytes: 3220
def main():
        X = int(input())

        ans = 0

        coins = [500,5]
        happy = [1000,5]

        for i in range(2):
                ans += X//coins[i]*happy[i]
                X = X%coins[i]

        print("{}".format(ans))

if __name__=="__main__":
        main()

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
const ll M = 1000000007;
 
vector<ll> fac(3000000); //n!(mod M)
vector<ll> ifac(3000000); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}


ll dfs(bool b, ll k, ll a, ll p, const vvll &e){
    if(sz(e[a]) == 1&&b == false){
        return 1;
    }
    ll t = 1, s = sz(e[a]) - 1;
    if(b){s++;}
    ll n = k-2;
    if(b){n++;}
    t *= comb(n, s)*fac[s];
    t %= M;
    for(auto x: e[a]){
        if(x == p){
            continue;
        }
        t *= dfs(false, k, x, a, e);
        t %= M;
    }
    return  t;
}


int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<3000000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll N, K; cin >> N >> K;
    vvll e(N, vll(0));
    rep(i, 0, N-1){
        ll a, b; cin >> a >> b;
        e[a-1].emplace_back(b-1);
        e[b-1].emplace_back(a-1);
    }
    ll ans = K*dfs(true, K, 0, INF, e)%M;
    prt(ans);
}









Measured memory_bytes: 61224
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	k := getNextInt(scanner)
	s := getNextInt(scanner)

	ans := 0
	for x := 0; x < k+1; x++ {
		for y := 0; y < k+1; y++ {
			if x+y+k < s {
				continue
			}
			if x+y > s {
				continue
			}
			ans++
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


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

bool    CMP(vector<int> &A, vector<int> &B) {
        return A.at(1) < B.at(1);
}

int     main() {
        int N, M;
        cin >>N >>M;
        vector<vector<int>> A(N, vector<int> (2, 0));
        for (int i=0; i<N; i++) {
                cin >>A.at(i).at(1) >>A.at(i).at(0);
        }
        sort(A.begin(), A.end(), CMP);
        priority_queue<int> Q;
        long S=0;
        int j=0;
        for (int i=1; i<=M; i++) {
                while ((j<N)&&(A.at(j).at(1)<=i)) {
                        Q.push(A.at(j).at(0));
                        j++;
                }
                if (!Q.empty()) {
                        S += Q.top();
                        Q.pop();
                }
        }
        cout <<S <<endl;
        return 0;
};

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll d,n;
    cin >> d >> n;
    if(n <= 99){
        cout << pow(100, d) * n << endl;
    }else{
        cout << (int)pow(100, d) * 101 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)

def get_inputs():
    N, M = map(int, input().split())
    
    # グラフgを初期化
    g = [[] for _ in range(N)]
    
    # 辺情報を読み込みgに追加
    for _ in range(M):
        x, y = map(lambda c: int(c) - 1, input().split())
        g[x].append(y)
    
    return N, M, g


def getlp(x):
    global dp, g
    
    if dp[x] != -1:
        return dp[x]
    elif len(g[x]) == 0:
        dp[x] = 0
        return dp[x]
    else:
        dp[x] = max([getlp(y) for y in g[x]]) + 1
        return dp[x]


N, M, g = get_inputs()

dp = [-1] * N
ans = 0
for x in range(N):
    ans = max(ans, getlp(x))

print(ans)


Measured memory_bytes: 109868
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [long(input_raw[0]), long(input_raw[1])]
    S = []
    for i in range(H):
        input_raw = read_func().strip()
        S.append(input_raw)

    move_list = [(0,1),(1,0),(0,-1),(-1,0)]
    is_visited = set([])
    count = 0
    for i in range(H):
        for j in range(W):
            path_list = [(i, j)]
            if (i, j) not in is_visited:
                is_visited.add((i, j))

                q = deque([(i, j)])
                while len(q) > 0:
                    nd = q.popleft()
                    for move in move_list:
                        new_i = nd[0] + move[0]
                        new_j = nd[1] + move[1]
                        if new_i >= 0 and new_j >= 0 and new_i < H and new_j < W:
                            if (new_i, new_j) not in is_visited:
                                if S[nd[0]][nd[1]] != S[new_i][new_j]:
                                    path_list.append((new_i, new_j))
                                    is_visited.add((new_i, new_j))
                                    q.append((new_i, new_j))
            black_num = 0
            white_num = 0
            for path in path_list:
                if S[path[0]][path[1]] == "#":
                    black_num += 1
                else:
                    white_num += 1
            count +=black_num *white_num

    print count



if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  int ret = 0, cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (cnt > 0) {
      cnt--;
      ret++;
    } else {
      cnt++;
    }

    if (S[i] == 'p')
      ret--;
  }
  cout << ret << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL<<40;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> s(n);
    rep(i,n){
        int t, d; 
        cin >> t >> d;
        --t;
        s[t].pb(d);
    }
    for(auto &v : s){
        sort(ALL(v), greater<ll>());
        if(v.empty()) v.push_back(-INF);
    }
    sort(ALL(s),[&](vector<ll> a, vector<ll> b){return a[0] > b[0];});//s[0]を降順に

    ll cur = 0;
    priority_queue<ll> que;//curに入っていないものを全部いれる
    for(int i = 0; i < k; i++){
        cur += s[i][0];
        for(int j = 1; j < s[i].size(); j++) que.push(s[i][j]);
    }
    for(int i = k; i < n; i++) for(int j = 0; j < s[i].size(); j++) que.push(s[i][j]);
    ll res = cur + k * k;
    for(ll x = k - 1; x >= 1; x--){
        ll v = s[x][0];
        ll w = que.top();
        if(v < w){
            que.pop(); cur += w;
            que.push(v);//!!
            cur -= v;
        }
        res = max(res, cur + x * x);//二乗するときintに収まらない可能性に注意
    }
    cout << res << endl;
}

Measured memory_bytes: 11660
#include <stdio.h>

int main(void){

int i,j;
int a[101];
int len, tmp;
int count=0;

scanf("%d",&len);

for(i=1; i<=len; i++){
scanf("%d",&a[i]);
}

for(i=1; i<=len-1; i++){

for(j=len; j >=i+1; j--){

if(a[j] < a[j-1]){

tmp = a[j];
a[j] = a[j-1];
a[j-1] = tmp;
count++;

}

}

}

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

printf("%d",a[i]);
if(i!=len){
printf(" ");

}

}

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

return 0;

}

Measured memory_bytes: 1804
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Matryoshka{
public:
  int h;
  int r; 

  bool operator < ( const Matryoshka &m ) const {
    if( h < m.h  ){
      return true;
    }else{
      return false;
    }
  }
};

typedef vector< Matryoshka > Dolls;

void MaxSubSequenceLength( Dolls &d, vector< int > &ans ){
  ans[0] = 0;
  for(int i = 1; i < d.size(); i++){
    int maxSub = -1, maxj;

    for(int j = i - 1; j >= 0; j--){
      if( d[j].r < d[i].r && d[j].h < d[i].h ){
	if( maxSub < ans[j] ){
	  maxj = j;
	  maxSub = ans[j];
	}
      }
    }

    ans[i] = ans[maxj] + 1;
  }
}

void InputMatryoshka( Dolls &d, int num ){
  for(int i = 0; i < num; i++){
    Matryoshka m;
    
    cin >> m.h;
    cin >> m.r;
    d.push_back( m );
  }
}

int main(void){
  while( 1 ){
    int n, m;
    Dolls dolls;
    Matryoshka matryoBanpei;
    int maxMatryoshkaNum = 0;
    vector<int> ans;

    cin >> n;
    if( n == 0 ){
      break;
    }

    matryoBanpei.h = -1;
    matryoBanpei.r = -1;
    dolls.push_back( matryoBanpei );
    
    InputMatryoshka( dolls, n );

    cin >> m;
    InputMatryoshka( dolls, m );

    sort( dolls.begin(), dolls.end() );
    ans.resize( n+m+1, 0 );

    MaxSubSequenceLength( dolls, ans );

    //output
    for(int i = 0; i < ans.size(); i++){
      maxMatryoshkaNum = max( maxMatryoshkaNum, ans[i] );
    }
    cout << maxMatryoshkaNum << '\n';
  }
  return 0;
}

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

const int N = 100 + 10;
const int R = 5;

int dp[N][R];

void nCr(int n, int r) {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= min(i, r); j++) {
            if (j == 0 or j == i) dp[i][j] = 1;
            else dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
        }
    }
}

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    nCr(110, 2);
    cout << dp[a][2] + dp[b][2];
}

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

using namespace std;
const int maxn = 1005;
map<long long ,long long>times;

int main()
{

    int n;
    scanf("%d",&n);
    times.clear();
    for(int i=0; i<n; i++)
    {
        long long t;
        scanf("%lld",&t);

        times[t]++;
    }
    long long ans = 0;
    for(map<long long,long long>::iterator i = times.begin();i!=times.end();i++)
    {
         int valu = i->second;
         int xiabiao  = i ->first;

        if(valu>xiabiao)
         ans += valu - xiabiao;
        else if(valu< xiabiao )
            ans += valu;
    }
    printf("%lld\n",ans);
return 0;

}


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

using namespace std;

char x[3000 + 50], y[3000 + 50];
int n;
int m;
stack<char> s;
int lcs(){
    int k[n + 1][m + 1];
    int i, j;
    for(i = 0; i <= n; i++){
        for(j = 0; j <= m; j++){
            if(i == 0 || j == 0)
                k[i][j] = 0;
            else if(x[i - 1] == y[j - 1])
                k[i][j] = k[i-1][j-1] + 1;
            else
                k[i][j] = max(k[i - 1][j], k[i][j - 1]);
        }
    }
    i = n;
    j = m;
    while(i > 0 && j > 0){
        if(x[i-1] == y[j-1]){
            s.push(x[i-1]);
            i--; j--;
        }
        else if(k[i-1][j] > k[i][j-1])
            i--;
        else
            j--;
    }
    while(!s.empty()){
        cout <<s.top();
        s.pop();
    }
}

int main(){
    cin >> x >> y;
    n = strlen(x);
    m = strlen(y);
    lcs();
}


Measured memory_bytes: 35456
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

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

  ll r=0, g=0, b=0;
  rep(i,n) {
    if (s[i] == 'R') {
      r++;
    } else if (s[i] == 'G') {
      g++;
    } else {
      b++;
    }
  }

  ll count = r*g*b;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      int k = 2*j - i;
      if (k >= n) continue;
      if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) {
        count--;
      }
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll n,k;
    cin>>n>>k;
    ll h[n];
    rep(i,0,n-1) cin>>h[i];
    sort(h,h+n);
    drep(i,n-1,n-k){
        h[i] = 0;
    }
    ll ans = 0;
    rep(i,0,n-1){
        ans += h[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2424
#include <cstdio>
using namespace std;
int main()
{
	int i,a,b,flag=1;
	char c[12];
	scanf("%d%d",&a,&b);
	getchar();
	for(i=0;i<a+b+1;i++)
		c[i]=getchar();
	for(i=0;i<a+b+1;i++)
	{
		if(i!=a&&(c[i]<'0'||c[i]>'9'))
			flag=0;
	}
	if(c[a]=='-'&&flag==1)
		printf("Yes");
	else	
		printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=100010;
ll n,l[MAXN],r[MAXN];
ll ans,suml,sumr;
priority_queue < ll,vector<ll>,less<ll> > ql;
priority_queue < ll,vector<ll>,greater<ll> > qr;
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d%d",&l[i],&r[i]);
	}
	ql.push(l[1]),qr.push(l[1]);
	for (int i=2;i<=n;i++) {
		suml+=r[i]-l[i],sumr+=r[i-1]-l[i-1];
		ll a=ql.top()-suml,b=qr.top()+sumr;
		//cout << "        " << i << "  " << a << "  " << b << "  " << suml << "  " << sumr << endl; 
		if (l[i]<a) {
			ans+=a-l[i];
			qr.push(a-sumr),ql.push(l[i]+suml),ql.push(l[i]+suml),ql.pop();
		} else if (a<=l[i]&&l[i]<=b) {
			ql.push(l[i]+suml),qr.push(l[i]-sumr);
		} else {
			ans+=l[i]-b;
			ql.push(b+suml),qr.push(l[i]-sumr),qr.push(l[i]-sumr),qr.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3572
n=int(input())
 
count=0
 
if n == 100000:
  count+=90909

if 10000 <= n and n < 100000:
  m=n-9999
  count+=m
  count+=909

if 1000 <= n and n < 10000:
  count+=909

if 100 <=n and n < 1000:
  l=n-99
  count+=l
  count+=9

if 10 <= n and n < 100:
  count +=9

if n < 10:
  count+=n

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

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

	int ans = 0;
	for (int i = 0; i < (int)S.size(); ++i) {
		int tmp = 0;
		for (int j = i; j < (int)S.size(); ++j) {
			if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T')
				tmp++;
			else
				break;
		}
		ans = max(tmp, ans);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int X = sc.nextInt(); // 最小値は2X、最大値は4X
		int Y = sc.nextInt(); 
		
		// 最大値と最小値の間の足の総数は、偶数であれば任意で取り得る
		if(Y > 4*X || Y < 2*X || Y%2==1) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		
	}
}



Measured memory_bytes: 35648
from collections import deque

N = int(input())
A = sorted(list(map(int,input().split())))

p = 0
n = 0

for a in A:
    if a >= 0:
        p += 1
    else:
        n += 1

ans_list = []

if p == N:
    #ans = sum(A[1:]) - A[0]
    res = A[0]
    for i in range(1,N-1):
        ans_list.append((res,A[i]))
        res -= A[i]
    ans_list.append((A[N-1], res))
    res = A[N-1] - res
    ans = res
elif n == N:
    #ans = -sum(A[:-1]) + A[-1]
    res = A[-1]
    for i in range(N-1):
        ans_list.append((res, A[i]))
        res -= A[i]
    ans = res
else:
    #ans = sum([abs(a) for a in A])
    p_list = deque()
    n_list = deque()
    for a in A:
        if a >= 0:
            p_list.append(a)
        else:
            n_list.append(a)
    while len(p_list) != 1:
        np = p_list.pop()
        nn = n_list.pop()
        ans_list.append((nn, np))
        n_list.append(nn-np)
    res = p_list[0]
    for nn in n_list:
        ans_list.append((res, nn))
        res -= nn
    ans = res

print(ans)
for x,y in ans_list:
    print(x,y)

Measured memory_bytes: 20256
//#include "stdafx.h"
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int x, y;
	cin >> x >> y;
	set<int >s1 = { 1,3,5,7,8,10,12 }; set<int >s2 = { 4,6,9,11 }; set<int >s3 = { 2 };
	if ((s1.count(x) == 1) && (s1.count(y) == 1))
		cout << "Yes";
	else if ((s2.count(x)) == 1 && (s2.count(y) == 1))
		cout << "Yes";
	else if ((s3.count(x)) == 1 && (s3.count(y) == 1))
		cout << "Yes";
	else
		cout << "No";
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long A, long long B, long long C, long long K){
    i64 ans = 0;
    ans += min(A, K);
    K -= min(A, K);
    if(K > 0){
        K -= min(B, K);
    }
    if(K > 0){
        ans -= K;
    }
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3688
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<lint> a(N), b(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) cin >> b[i];

	lint res = 0, m = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] <= b[i]) res += (b[i] - a[i]) / 2;
		else m += a[i] - b[i];
	}

	if (res >= m) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

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


Measured memory_bytes: 640
int main(void) {
	int N,D,A[11][11],ans=0,sum=0;
	scanf("%d%d",&N,&D);
	for(int i=0; i<N; i++){
		for(int j=0; j<D; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(int i=0; i<N-1; i++){
		for(int j=i+1; j<N; j++){
			for(int k=0; k<D; k++){
				sum += (A[i][k] - A[j][k])*(A[i][k] - A[j][k]);
			}
			for(int k=0; k*k<=sum; k++){
				if(k*k == sum){
					ans++;
					break;
				}
			}
			sum = 0;
		}	
	}
	printf("%d\n",ans);
}

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

int find(int u,int o,int* a,int x){

    

    if(o<=u+1){return 0;}

    int k = (u+o)/2;
    if(a[k] == x){return 1;}
    else if(a[k] <x){
        return find(k,o,a,x);
    }
    else {
        return find(u,k,a,x);
    }


}

int main(){
    int r[4000],g[4000],b[4000];
    int rlen = 0;
    int glen = 0;
    int blen = 0;
    int N;
    cin >> N;
    for(int i=1;i<=N;i++){
        char c;
        cin >> c;
        if(c=='R'){
            r[rlen]=i;
            rlen +=1;}
        else if(c=='G'){
            g[glen]=i;
            glen+=1;
        }
        else{
            b[blen] = i;
            blen +=1;
        }

    }
    if(rlen ==0 || glen == 0 || blen == 0){cout << 0 << endl;}
    else{
        long long int sum=0;
        for(int i=0;i<rlen;i++){
            for(int j=0;j<glen;j++){
                if( (r[i]+g[j])%2==0){
                    int x=(r[i]+g[j])/2;
                    if(find(-1,blen,&(b[0]),x)==1){sum+=1;}

                }

            }
        }
        for(int i=0;i<rlen;i++){
            for(int j=0;j<blen;j++){
                if( (r[i]+b[j])%2==0){
                    int x=(r[i]+b[j])/2;
                    if(find(-1,glen,&(g[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        for(int i=0;i<blen;i++){
            for(int j=0;j<glen;j++){
                if( (b[i]+g[j])%2==0){
                    int x=(b[i]+g[j])/2;
                    if(find(-1,rlen,&(r[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        cout << (long long int)rlen*glen*blen - sum << endl;
    }


    return 0;
}

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

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

using namespace std;

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

  if(a%b==c){
    cout<<"YES";return 0;
  }
  int result = a;
  rep(i,b){
    result += a;
    if(result%b==c){
      cout<<"YES";return 0;
    }
  }

 cout<<"NO";
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x <<endl; 
#define De(...)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
using namespace std; 

int _; 

int n,q,a[100050],b[100050],c[100050],cnt[100050];
long long sum=0;

int main()
{
	//for(scanf("%d",&_);_;_--)
	for(int i=0;i<100050;i++)
		cnt[i]=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		sum += a[i];
		cnt[a[i]]++;
	} 
	scanf("%d",&q);
	for(int i=0;i<q;i++)
		scanf("%d%d",b+i,c+i);
	for(int i=0;i<q;i++)
	{
		sum += (c[i]-b[i])*cnt[b[i]];
		cnt[c[i]] += cnt[b[i]];
		cnt[b[i]]=0;
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
using ll = int64_t;
using ul = uint64_t;
using namespace std;

void solve() {
  int d, t, s;
  cin >> d >> t >> s;
  debug(d, t * s);
  if (d <= t * s)
    cout << "Yes";
  else
    cout << "No";
}

void wrapper() {
  rep(i, 3) {
    cout << "[TEST " << (i + 1) << "]\n";
    solve();
    cout << "\n";
  }
}

int main() {
  fastIO;
#ifdef _DEBUG
  wrapper();
#else
  solve();
#endif
}


Measured memory_bytes: 3656
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 105
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
ll val;

int main() {
	scanf("%lld %lld", &N, &M);
	unordered_map<ll, ll> mp;
	fi(i, 0, M, 1) {
		scanf("%lld", &C);
		fi(i, 0, C, 1) {
			scanf("%lld", &val);
			mp[val]++;
		}
	}
	ll cnt = 0;
	fei(i, 1, N, 1) {
		if(!mp[i]) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->emplace_back(count,A->at(i));
        count = 1;
      }
    }else{
      R->emplace_back(count,A->at(i));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  int N;
  cin>>N;
  vector<int> p(N);
  rep(i,N){
    cin>>p.at(i);
  }
  int count = 0;
  int ans = 0;
  while(1){
  count=0;
  rep(i,N){

    if(p.at(i)==i+1){
      if(i<N-1)swap(p.at(i),p.at(i+1));
      else swap(p.at(i),p.at(i-1));
      count++;
    }
  }
  ans+=count;
  if(count==0)break;
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    cin >>N;
    vector<int> d(N);
    for(int i=0; i<N; i++)
        cin >> d.at(i);
    int hp = 0;
    for(int j=0; j<(N-1); j++)
        for(int i=j+1; i<N; i++)
            hp+=d.at(i)*d.at(j);
    cout << hp << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0)
                {
                    Console.Write(" "+i);
                }
                else if (i % 10 == 3)
                {
                    Console.Write(" " + i);
                }
                else
                {
                    int k = i;
                    while (true)
                    {
                        k /= 10;
                        if (k < 3) break;
                        if (k % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }

                    }
                }


              }
           
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9324
k = int(input())
c = 0
t = 7%k
a = [t]*(k+1)

if k%2 == 0 or k%5 == 0:
	print('-1')
elif 7%k == 0:
	print('1')
else:
	for i in range(1,k):
		c += 1
		a[i+1] = (10*a[i] + 7)%k
		if a[i+1] == 0:
			break
	print(c + 1)

Measured memory_bytes: 48488
#include <bits/stdc++.h>
#define int long long 
using namespace std;
using Graph = vector<vector<int>>;

signed main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  
  if( N <= K ) cout << 1 << endl;
  else{
    N--;
    K--;
    cout << (N+K-1)/K << endl;
  }
  

}

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

using namespace std;

long long n;
long long m;

int main() {
	scanf("%lld%lld", &n, &m);
	if(n == 1 || m == 1) {
		if(n == m) printf("1\n");
		else printf("%lld\n", n > m ? n - 2 : m - 2);
	}
	else printf("%lld\n", (long long)(n - 2LL) * (m - 2LL));
	return 0;
}

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

int main(){
    long long A,B,K;
    cin >> A >> B >> K;

    if(K<A) cout << A-K << ' '<< B<<endl;
    else if(A<=K && K<A+B) cout << 0 << ' ' << (A+B)-K <<endl;
    else cout << 0 << ' ' << 0 <<endl;
}

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

typedef struct{double x,y;}Point;

void koch(int,Point,Point);

int main(){
	Point a,b;
	int n;
	scanf("%d",&n);
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	return 0;
}

void koch(int n,Point a,Point b){
	if(n==0)return ;
	Point s,t,u;
	double th;
	th=M_PI * 60.0 / 180.0;
	s.x=(2.0*a.x+b.x)/3;
	s.y=(2.0*a.y+b.y)/3;
	t.x=(a.x+2.0*b.x)/3;
	t.y=(a.y+2.0*b.y)/3;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	koch(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(n-1,t,b);
}



Measured memory_bytes: 2052
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t X;
  std::cin >> X;
  int64_t money = 100;
  int64_t year;
  for (int64_t cyear = 0; cyear <= 1000000000LL; ++cyear) {
    if (money >= X) {
      year = cyear;
      break;
    }
    money = static_cast<int64_t>(static_cast<double>(money)*1.01);
  }
  std::cout << year << std::endl;
  return 0;
}


Measured memory_bytes: 3648
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long int
#define pb push_back
#define mk make_pair

using namespace std;


int main(){
   string s;
    cin>>s;
    string k="";
    for(int i=0;i<s.length();i+=2)k+=s[i];
    cout<<k<<endl;
}


Measured memory_bytes: 512
Module _20191029

    Sub Main()
        'https://atcoder.jp/contests/abc144/tasks/abc144_a

        Dim sRead As String = Console.ReadLine()

        Dim iNumber1 As Integer = sRead.Split(" ")(0)
        Dim iNumber2 As Integer = sRead.Split(" ")(1)

        If iNumber1 > 0 AndAlso iNumber1 < 10 AndAlso iNumber2 > 0 AndAlso iNumber2 < 10 Then

            Console.WriteLine(iNumber1 * iNumber2)

        Else

            Console.WriteLine(-1)

        End If

    End Sub

End Module


Measured memory_bytes: 11220
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
using namespace std;

int main(){
	int mitukatta=0;
	string S;
	cin>>S;
	int A,B,C,D;
	A=stoi(S.substr(0,1));
	B=stoi(S.substr(1,1));
	C=stoi(S.substr(2,1));
	D=stoi(S.substr(3,1));
	int num[4]={A,B,C,D};
	string ans;
	for(int bit=0;bit<(1<<4);++bit){
		if(mitukatta==1)break;
		int total=0;
		vector<int> arr;
		vector<int> arr_minus;
		for(int i=0;i<4;++i){
			if(bit&(1<<i)) arr.push_back(i);
			if(!(bit&(1<<i))) arr_minus.push_back(i);
		}
		for(int i=0;i<(int)arr.size();++i){
			total+=num[arr[i]];
		}
		for(int i=0;i<(int)arr_minus.size();++i){
			total-=num[arr_minus[i]];
		}
		int atta=0;
		if(total==7){
			for(int i=0;i<(int)arr.size();++i){
				if (arr[i]==0){
					 atta=1;
				}
			}
			if((atta==0)&&(num[0]!=0))ans+="-";
			ans+=to_string(num[0]);
			atta=0;
			for(int i=0;i<(int)arr.size();++i){
				if (arr[i]==1){
					 ans+="+";
					 atta=1;
				}
			}
			if(atta==0)ans+="-";
			ans+=to_string(num[1]);
			atta=0;
			for(int i=0;i<(int)arr.size();++i){
				if (arr[i]==2){
					 ans+="+";
					 atta=1;
				}
			}
			if(atta==0)ans+="-";
			ans+=to_string(num[2]);
			atta=0;
			for(int i=0;i<(int)arr.size();++i){
				if (arr[i]==3){
					 ans+="+";
					 atta=1;
				}
			}
			if(atta==0)ans+="-";
			ans+=to_string(num[3]);
			ans+="=7";
			mitukatta=1;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())
rgb = []
for i in range(N + 1):
    for j in range(N - i + 1):
        key = i * R + j * G
        key = N - key
        if key % B == 0 and key / B >= 0:
            rgb.append([i, j, key // B])

#print(rgb)
print(len(rgb))


Measured memory_bytes: 540808
/*
 ALLAH is Almighty....
*/
#include <bits/stdc++.h>

#define ll  long long
using namespace std;

const ll mx = 10e5 + 9;
ll n, k;
ll ar[ mx ][ 3 ];
ll dp[ mx ][ 3 ];

void solve( )
{
    cin >> n;
    for ( ll i = 0; i < n; ++i )
        cin >> ar[ i ][ 0 ] >> ar[ i ][ 1 ] >> ar[ i ][ 2 ];

    dp[ 0 ][ 0 ] = ar[ 0 ][ 0 ];
    dp[ 0 ][ 1 ] = ar[ 0 ][ 1 ];
    dp[ 0 ][ 2 ] = ar[ 0 ][ 2 ];

    for ( ll i = 1; i < n; ++i ) {
        dp[ i ][ 0 ] = ar[ i ][ 0 ] + max( dp[ i - 1 ][ 1 ], dp[ i - 1 ][ 2 ] );
        dp[ i ][ 1 ] = ar[ i ][ 1 ] + max( dp[ i - 1 ][ 0 ], dp[ i - 1 ][ 2 ] );
        dp[ i ][ 2 ] = ar[ i ][ 2 ] + max( dp[ i - 1 ][ 1 ], dp[ i - 1 ][ 0 ] );
    }

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

int main()         // Md. Inzamam-ul Haque
{
    solve();
}



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

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

  int res = 0;

  while (true) {
    bool exsit_odd = false;
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) exsit_odd = true;
    }

    if (exsit_odd) break;

    for (int i = 0; i < N; i++) {
      A[i] /= 2;
    }
    res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256