akhauriyash/Code-Regression huggingface dataset:
//
//  ALDS_12_A.cpp
//  
//
//  Created by 杵鞭俊 on 2018/07/24.
//

#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
    
    for(int i=0;i<n;i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
    d[0]=0;
    while (1) {
        minv=INFTY;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if (u==-1) break;
        color[u]=BLACK;
        for (int v=0; v<n; v++) {
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    
    int sum=0;
    for (int i=0; i<n; i++) {
        if(p[i]!=-1) sum+=M[i][p[i]];
    }
    return sum;
}


int main(){
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int e; cin>> e;
            M[i][j]=(e==-1)?INFTY:e;
        }
    }
    
    cout << prim()<<endl;
    return 0;
}



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

string name, tmp;

string slice(string str, int start, int gap, int num){
  string res = "";
  for(int i = start;i < str.size() && num--;i += gap){
    res += str[i];
  }
  return res;
}

int main(){
  int res = 0, n;
  cin >> n;
  cin >> name;
  for(int i = 0;i < n;i++){
    cin >> tmp;
    bool x = true;
    for(int i = 0;i < tmp.size() && x;i++){
      for(int j = 1;j < tmp.size();j++){
	if(name == slice(tmp, i, j, name.size())){
	  x = false;
	  res++;
	  break;
	} 
      }
    }
  }
  cout << res << endl;
    
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main() {
    long long ans =0;
    long long l0 = 2;
    long long l1 =1;
    int n;cin>>n;
    if(n==1){
        cout<<l1; return 0;
    }
    for(int i=2;i<=n;i++){
        ans = l1+l0;
        l0 = l1;
        l1 = ans;
    }
    cout<<ans;
}


Measured memory_bytes: 256
N,H = list(map(int,input().split()))
a_max = 0
B = []
for i in range(N):
  a,b = list(map(int,input().split()))
  a_max = max(a_max,a)
  B.append(b)

B = sorted(B,key = lambda x:-x)
cnt = 0
for idx,b in enumerate(B):
  if b < a_max:
    break
  H -= b 
  cnt += 1
  if H <= 0:
    print(cnt)
    break

if H > 0 :
  
  print(cnt + (H-1)//a_max +1 )

Measured memory_bytes: 62808
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define F(x) for(int i=1;i<=(x);i++)
#define fer(i,n) for(int i=1;i<=(n);i++)
#define FIN  {freopen("1.in","r",stdin);}
#define FOUT {freopen("1.out","w",stdout);}
#define OUT(x)  {cout<<"#x"<<" : "<<x<<endl;}
#define ERR(x)  {cout<<"#error:"<<x;while(1);}
typedef long long ll;
typedef unsigned long long ull;
#define se second
#define fi first
#define make_pair mkp
#define mid ((l+r)>>1)
const int MaxInt = -1u>>1;
const int Max_ = 0x3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1);
using namespace std;
inline int read()
{
    char ch=getchar();int f=1,g=0;
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar()) g=g*10+(ch^48);
    return g*f;
}
const int N = 1e5;
int n,m;
int a[N],b[N],t[N];
int main()
{
    n=read(),m=read();
    int fl=0;
    F(m) {
        a[i]=read();
        if(a[i]%2==1) t[++fl]=i;
        if(fl>2) {cout<<"Impossible";return 0;}
    }
    if(fl>=1) swap(a[1],a[t[1]]);
    if(fl>=2) swap(a[m],a[t[2]]);
    if(m==1&&a[1]==1) {cout<<1<<endl<<1<<endl<<1;return 0;}
    F(m) cout<<a[i]<<" ";cout<<endl;
    if(m==1) {cout<<2<<endl<<1<<" "<<a[1]-1;return 0;}
    cout<<(a[m]>1?m:m-1)<<endl<<a[1]+1<<" "; 
    F(m-2) cout<<a[i+1]<<" ";if(a[m]>1)cout<<a[m]-1;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	lint t1,t2,a1,a2,b1,b2;
	cin>>t1>>t2;cin>>a1>>a2;cin>>b1>>b2;
	if(t1*a1+t2*a2==t1*b1+t2*b2){
		cout<<"infinity"<<endl;return 0;
	}
	if(t1*a1+t2*a2<t1*b1+t2*b2) swap(a1,b1),swap(a2,b2);
	if(a1>b1){
		cout<<0<<endl;return 0;
	}
	lint x=t1*a1+t2*a2-(t1*b1+t2*b2),y=t1*(b1-a1);
	if(y%x==0){
		cout<<y/x*2<<endl;return 0;
	}
	cout<<(y/x)*2+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin>>x;
  if(x>=1800){
    cout<<1<<endl;
  }
  else if(x>=1600){
    cout<<2<<endl;
  }
   else if(x>=1400){
    cout<<3<<endl;
  }
   else if(x>=1200){
    cout<<4<<endl;
  }
   else if(x>=1000){
    cout<<5<<endl;
  }
   else if(x>=800){
    cout<<6<<endl;
  }
   else if(x>=600){
    cout<<7<<endl;
  }
   else if(x>=400){
    cout<<8<<endl;
  }
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
    char tmp[1000000];
    //??°?????\????????°?????\???
    fgets(tmp,sizeof(tmp),stdin);
    int loop=atoi(tmp);
    
    //?¶??????°????????\???
    fgets(tmp,sizeof(tmp),stdin);
    int num[10001];
    //???????????????
    num[0]=atoi(strtok(tmp," "));
    //?????????????¨????????°????????????§??????num[0]???
    long sum=num[0];
    int min=num[0];
    int max=num[0];
    //??\?????°?????????
    int i;
    for(i=1;i<loop;i++){
        num[i]=atoi(strtok(NULL," "));
        //????¨??????????
        sum+=num[i];
        //?????¨????????§????????????????????°max?????\??????????°?????????????????????°min?????\??????
        if(max<num[i]){
            max=num[i];
        }else if(min>num[i]){
            min=num[i];
        }
    }
    //??\?????°???????????????
    printf("%d %d %ld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 616
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=int(input())
a=s//100
b=s%100
if 0<a<13:
    if 0<b<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0<b<13:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 77504
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,cnt=0;
	cin>>a;
	int b[a],e[a];
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	int c[a];
	for(int i=0;i<a;i++){
		cin>>c[i];
	}
	for(int i=0;i<a;i++){
		e[i]=b[i]-c[i];
		if(e[i]>0)
			cnt+=e[i];
	}
	cout<<cnt;
}
//FELAROSSO 2019

Measured memory_bytes: 256
def main():
  n, w = [int(e) for e in input().split()]
  t = [-1 for i in range(w + 1)]
  t[w] = 0
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(nw, w + 1):
      if t[i] == -1:
        continue
      if t[i - nw] < t[i] + nv:
        t[i - nw] = t[i] + nv
  print(max(t))
main()

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    string S;cin>>S;
    int N=S.size();
    int dp[N+1][13];
    REP(i,N+1)REP(j,13)dp[i][j]=0;
    REP(i,N){
        int d=(S[i]!='?'?S[i]-'0':-1);
        if(i==0){
            if(d!=-1) dp[1][d]=1;
            else REP(j,10)dp[1][j]=1;
        }
        else{
            if(d!=-1){
                REP(j,13)dp[i+1][(j*10+d)%13]=dp[i][j]%MOD;
            }
            else {
                REP(e,10)REP(j,13){
                  	dp[i+1][(j*10+e)%13]+=dp[i][j];
                  	dp[i+1][(j*10+e)%13]%=MOD;
                }
            }
        }
    }
    cout<<dp[N][5]%MOD<<endl;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

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

ll n, k;
string s;
bool chg[102];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    cin >> k;
    ll ans = 0;
    for(int i = 1; i < s.size(); ++i)
        if(chg[i-1])
            continue;
        else
            if(s[i] == s[i-1])
                ++ans, chg[i] = 1;
    if(s[s.size()-1] != s[0])
        cout << ans * k << '\n';
    else
    {
        if(chg[s.size()-1])
            cout << ans * k << '\n';
        else
        {
            if(k == 1)
                cout << ans << '\n';
            else
            {
                memset(chg, 0, sizeof(chg));
                chg[0] = 1;
                ll a2 = 0;
                for(int i = 1; i < s.size(); ++i)
                    if(chg[i-1])
                        continue;
                    else
                        if(s[i] == s[i-1])
                            ++a2, chg[i] = 1;
                if(!chg[s.size()-1])
                    cout << ans + (k-1) + (k-1) * a2 << '\n';
                else
                {
                    cout << ans * (k/2 + k%2) + a2 * (k/2) + (k/2) << '\n';
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
void main() {
    string[] ab = readln.split;
    int n = (ab[0] ~ ab[1]).to!int;
    int m = n.to!double.sqrt.to!int;
    writeln(n == m * m ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
  long D;
  cin >> D;
  
  //減点量の入力
  long c[27];
  for(int i=1; i<26+1; i++){
    cin >> c[i];
  }
  
  //加点量の入力
  long s[D+1][26+1];
  for(int i=1; i<D+1; i++){
  for(int j=1; j<26+1; j++){
    cin >> s[i][j];
  }}

  //過去の最終開催日を保持する配列
  long past[26+1] = {0};
  
  //日々の処理
  
  for(int day=1; day<D+1; day++){
    
    //仮の満足度を保持する配列
    long tempPoint[26+1] = {0};
    for(int tt=1; tt<26+1; tt++){

      //満足度の加点計算
      tempPoint[tt] = s[day][tt];

      //満足度の減点計算
      for(int num=1; num<26+1; num++){
        tempPoint[tt] -= ( c[num] * (day - past[num]) );
      }
    }
    
    //それぞれの選択に対する満足度の変化量を表示
    //for(int i=1; i<26+1; i++){
    //  cout << i << " : " << tempPoint[i] << endl;
    //}
    
    //仮の満足度から一番高い満足度の選択を出力
    int choice=1;
    for(int i=1; i<26+1; i++){
      if(tempPoint[choice] < tempPoint[i]) choice = i;
    }
    //cout << "choice " << choice << endl;
    if(day!=D){
      cout << choice << endl;
    }else{
      cout << choice;
    }
    
    //実行したテストを記録
    past[choice] = day;
  }

  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
typedef long long ll;
 
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 main(){
  //無限大の値
  const ll INF = 1LL << 60;
  
  //DP配列
  int N;
  cin >> N;
  ll dp[N+5];
  
  //初期化
  for(int i = 0;i<N+5;++i) dp[i] = INF;
  
  //初期条件
  dp[0] = 0;
  
  //コスト配列の入力
  int h[N+5];
  for(int i = 0; i<N;++i)  cin >> h[i];
  
  //ループ
  for(int i = 0; i<N;++i){
    chmin(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));    
  }
  
  //解を出力
  cout << dp[N-1];
}

Measured memory_bytes: 1408
#!/usr/bin/env python
# coding: utf-8
#

def main(input_str):
    a, b, k = list(map(int, input_str.split(' ')))
    li = []
    for i in range(a, a + k):
        if i <= b:
            li.append(i)
    for i in range(b + 1 - k, b + 1):
        if a <= i:
            li.append(i)
    set_li = sorted(list(set(li)))
    for i in set_li:
        print(i)
    
    

if __name__ == '__main__':
    try:
        main(input().strip())
    except EOFError:
        pass


Measured memory_bytes: 3060
n, k = gets.split.map(&:to_i)

# n+1個からk個以上を選んだ和
# k個
# (10^100+a) + (10^100+b) + ... = k*10^100 + (a + b + ...)
# k+1個
# (10^100+a) + (10^100+b) + ... = (k+1)*10^100 + (a + b + ...)
# -> k個とk+1個だと絶対に和は被らない
# a,b,...の部分で、0+1+4+5 = 0+2+3+5のような被りはある。
#
# 0+1+2+...+(k-2)+(k-1)
#       ...
# 0+1+2+...+(k-2)+  n   n-(k-1)+1=n-k+2通り
# 0+1+2+...+(k-1)+  n
#       ...
# 0+1+2+...+(n-1)+  n   (n-1)-(k-1)+1=n-k+1通り
#       ...
# 1+(n-k+2)+...+(n-1)+n
#       ...
# (n-k+1)+.......+  n   (n-k+1)-1+1 = n-k+1通り
#
# 0+1+2+3
# 0+1+2+4
# 0+1+2+5
# 0+1+2+6 6-4+2=4
# 0+1+3+6
# 0+1+4+6
# 0+1+5+6 6-4+1=3
# 0+2+5+6
# 0+3+5+6
# 0+4+5+6 6-4+1=3
# 1+4+5+6
# 2+4+5+6
# 3+4+5+6 6-4+1=3
# 
# n-k+2 + (n-k+1)(k-1)

total = 1
(k..n).each do |i|
  total += (n-i+2) + (n-i+1)*(i-1)
end

puts total % (10**9+7)


Measured memory_bytes: 14304
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 20;
int n, d[N], cost[N][N];
bool used[N];

void dijkstra(int);

int main(void){
    rep(i, N) fill(cost[i], cost[i] + N, INF);

    char sp;
    int m; cin >> n >> m;
    while(m--){
        int a, b, c1, c2; cin >> a >> sp >> b >> sp >> c1 >> sp >> c2;
        a--, b--;
        cost[a][b] = c1;
        cost[b][a] = c2;
    }
    int x1, x2, y1, y2; cin >> x1 >> sp >> x2 >> sp >> y1 >> sp >> y2;
    int res = y1 - y2;

    x1--, x2--;
    dijkstra(x1), res -= d[x2];
    dijkstra(x2), res -= d[x1];

    cout << res << endl;

    return 0;
}

void dijkstra(int s){
    fill(used, used + N, false);
    fill(d, d + N, INF);

    d[s] = 0;

    while(1){
        int v = -1;
        rep(u, n){
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        if(v == -1) break;
        used[v] = true;

        rep(u, n){
            d[u] = min(d[u], d[v] + cost[v][u]);
        }
    }
}

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

const int MAXN = 3000, MOD = 1000 * 1000 * 1000 + 7;
int dp[MAXN + 1][MAXN + 1], pr[MAXN + 1], ls[MAXN + 1];

void add(int& x, int y) {
    x += y;
    if(x >= MOD)
        x -= MOD;
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    s = "#" + s;
    for(int i = 1; i <= n; i++) {
        ls[i] = i;
        pr[i] = pr[i - 1] + s[i] - '0';
    }
    for(int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        for(int j = l; j <= r; j++)
            ls[j] = max(ls[j], r);
    }
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        int b = ls[i + 1];
        for(int j = 0; j <= i + 1; j++) {
            if(j < pr[b])
                add(dp[i + 1][j + 1], dp[i][j]);
            if((i - j) < b - pr[b])
                add(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[n][pr[n]] << endl;
    return 0;
}

Measured memory_bytes: 27904
X, K, D = map(int, input().split())
now = 0
if abs(X) - abs(D)*K >= 0:
    now = abs(X) - abs(D)*K
    print(now)
else:
    t = abs(X) // abs(D)
    remain = K - t
    now = abs(X) % abs(D)
    if remain % 2 == 0:
        print(now)
    else:
        print(abs(now - abs(D)))

Measured memory_bytes: 61616
def c_dubious_document_2(S, T):
    # S:鍵の文字列のいくつかを'?'で置き換えたもの
    # T:Sの中に含まれている可能性のある文字列
    tmp = ''  # 文字列の候補があれば、それが格納される
    for i in range(len(S) - len(T) + 1):
        # Sの中にTを置く場所がないままTがSの末尾をはみ出すなら、復元不可能が確定
        for j in range(len(T)):
            if S[i + j] == '?' or S[i + j] == T[j]:
                # Sのi文字目以降にTを埋め込める可能性がある
                continue
            break  # if文が成り立たないなら、埋め込めない
        else:
            # TをSのi文字目以降に埋め込める。候補が複数あれば、最も右に埋め込む。
            tmp = S[:i] + T + S[i + len(T):]
    # 候補があれば、辞書順最小にするために'?'を'a'で置換する
    ans = tmp.replace('?', 'a') if tmp else 'UNRESTORABLE'
    return ans

S = input()
T = input()
print(c_dubious_document_2(S, T))

Measured memory_bytes: 3060
x=input().split()
n=int(x[0])
k=int(x[1])
x=input().split()
h=[]
for i in range(len(x)):
  h.append(int(x[i]))
h=sorted(h)
if k<=n:
  print(sum(h[0:n-k]))
else:
  print(0)
  

Measured memory_bytes: 28092
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x=>x).ToList();

            Console.WriteLine(a.Last() - a.First());
        }
    }
}


Measured memory_bytes: 11348
import kotlin.math.min

fun main() {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    var wC = s.count { it == '.' }
    var bC = 0
    var count = bC + wC
    0.until(n).forEach {
        when (s[it]) {
            '.' -> wC--
            '#' -> bC++
        }
        count = min(count, bC + wC)
    }
    println(count.toString())
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int count =1;
    while (n / k > 0)
    {
        n /= k;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vi> f(vector<vi> a,vector<vi> b){
   int n=a.size();
   vector<vi>ans(n,vi(n,0));
   for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
         for(int k=0;k<n;k++){
            ans[i][j]=(ans[i][j]+a[i][k]*b[k][j])%mod;
         }
      }
   }
   return ans;
}
vector<vi> power(vector<vi>v,int k){
   if(k==1)
   return v;
   auto vv=power(v,k/2);
   if(k&1)
   vv=f(v,f(vv,vv));
   else vv=f(vv,vv);
   return vv;

}
int32_t main(){
int n,k;cin>>n>>k;
vector<vi>v(n,vi(n));
for(int i=0;i<n;i++){
   for(int j=0;j<n;j++)cin>>v[i][j];
}
auto ans=power(v,k);
int s=0;
for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){s+=ans[i][j];
   s%=mod;
   }
}
cout<<s<<endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> X(N);
    cin >> X;
    int ans = inf;
    for (int i = 0; i <= 100; i++) {
        int temp = 0;
        for (int j = 0; j < N; j++) {
            temp += (X[j] - i) * (X[j] - i);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    int sum = accumulate(T.begin(), T.end(), 0);
    int M; cin >> M;
    for (int i = 0; i < M; i++) {
        int p, x; cin >> p >> x;
        p--;
        cout << sum - T[p] + x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def INT():
    return int(input())

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

def LI():
    return list(map(int, input().split()))

from collections import deque
n = INT()
a = LI()
b = deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
        
if (-1)**n == -1:
    b.reverse()
    
print(*b)

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

int main()
{
  int n, w;
  cin >> n >> w;
  vector<int> wt(n), v(n);
  const int inf = 1e9 + 9;
  vector<long long int> dp(vector<long long int>(100005, inf));

  // dp[i][j] : min wt such that a value of v is made from first i
  for (int i = 0; i < n; ++i)
    cin >> wt[i] >> v[i];
  dp[v[0]] = wt[0];
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int vv = 100000; vv >= v[i]; --vv) {
      dp[vv] = min(dp[vv], wt[i] + dp[vv - v[i]]);
    }
  }

  long long int res = 0;
  for (int i = 100000; i >= 0; --i) {
    if (dp[i] <= w) {
      res = i ;
      break;
    }
  }

  cout << res <<'\n';


  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            int[] i = new int[N];
            int[] add = new int[N-1];
            int[] ans = new int[N-1];
            var A = 0;
            var C = 0;

            for (int k = 0; k < N; ++k) {
                var M = cin.ReadInt;
                i[k] = M;
                A = A + M;
            }
            
            for (int j = 0; j < N-1; ++j) {
                C = C + i[j];
                add[j] = A - C;
                ans[j] = Math.Abs(add[j] - C);
            }
            Array.Sort(ans);
            Write(ans[0]);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


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

using namespace std;
int main() {
  int n;
  cin >> n;
  int result = 0;
  for (int i = 111; i < 1000;) {
    if (n <= i) {
      result = i;
      break;
    }
    i += 111;
  }
  cout << result << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i = 1; i <= 9; i++) {
    if (N <= 111 * i) {
      cout << 111 * i << endl;
      return 0;
    }
  }
  
  return -1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str[4]={"maerd","remaerd","resare","esare"};
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	bool a=true;
	for(int i=0;i<s.size();)
	{
		bool b=false;
		for(int j=0;j<4;j++)
		{   
		    string d=str[j];
			if(s.substr(i,d.size())==d){
				b=true;i+=d.size();
			}
		}
		if(!b){
			a=false;break;
		}
	}
	if(a)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
} 

Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  k,x = readline() |> split |> parseArray

  a=x-k+1
  b=x+k-1
  print(a)
  for i in a+1:b
    print(" ")
    print(i)
  end
  println()
end

main()


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

int main(void){
	string str;
	int num,count = 1;
	cin >> num >> str;
	for(int i = 1; i != str.size(); i++)if(str[i] != str[i - 1])count++;
	cout << count << endl;
	return 0;
}

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

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  for(int i = 0; i < K; ++i){
    if(A >= B) B *= 2;
    else C *= 2;
  }
  if(A < B and B < C) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 3584
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a := nextInt()
	b := nextInt()
	A := strings.Repeat(strconv.Itoa(a), b)
	B := strings.Repeat(strconv.Itoa(b), a)

	if A > B {
		fmt.Printf("%s", B)
	} else {
		fmt.Printf("%s", A)
	}
}


Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b; long long x[100009], dp[100009]; vector<int> G[100009];
bool solve(int pos, int pre) {
	if (G[pos].size() == 1) {
		dp[pos] = x[pos];
		return true;
	}
	long long sum = 0, m = 0, cnt = 0;
	for (int i : G[pos]) {
		if (i == pre) continue;
		if (!solve(i, pos)) return false;
		sum += dp[i];
		m = max(m, dp[i]);
		cnt++;
	}
	if (cnt == 1) {
		for (int i : G[pos]) {
			if (i != pre) {
				if (dp[i] != x[pos]) return false;
				dp[pos] = dp[i];
				return true;
			}
		}
	}
	long long R = min(sum / 2, sum - m);
	if (0 <= sum - x[pos] && sum - x[pos] <= R) {
		dp[pos] = 2 * x[pos] - sum;
		if (dp[pos] < 0) return false;
		return true;
	}
	return false;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i];
	if (n == 2) {
		cout << (x[0] == x[1] ? "YES" : "NO") << endl;
		return 0;
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int root = -1;
	for (int i = 0; i < n; i++) {
		if (G[i].size() >= 2) {
			root = i;
			break;
		}
	}
	bool ret = solve(root, -1);
	if (dp[root] != 0) ret = false;
	cout << (ret ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define rint register int
#define inf 0x3f3f3f3f
#define MAXN 101
using namespace std;
inline int read(){
	int sum=0;
	char c;
	while(!(c>='0' && c<='9'))c=getchar();
	while(c>='0' && c<='9')sum=sum*10+c-'0',c=getchar();
	return sum;
}
string sa,sb;
int main(){
    getline(cin,sa),getline(cin,sb);
    sort(sa.begin(),sa.end());
    sort(sb.begin(),sb.end(),greater<char>());
    if(sa<sb)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

void testCase() {    
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum > n) {
        cout << -1 << "\n";
    } else {
        cout << n-sum << "\n";
    }
}
















Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B;
    cin >> A >> B;
    vector<vector<char>> ans(100, vector<char>(100, '#'));

    rep(i, 50) {
        rep(j, 100) ans[i][j] = '.';
    }

    A--;
    B--;
    for (int i = 51; i < 100; i += 2) {
        for (int j = 0; j < 100; j += 2) {
            if (A == 0) break;
            ans[i][j] = '.';
            A--;
        }
        if (A == 0) break;
    }

    for (int i = 1; i < 50; i += 2) {
        for (int j = 0; j < 100; j += 2) {
            if (B == 0) break;
            ans[i][j] = '#';
            B--;
        }
    }

    cout << 100 << " " << 100 << endl;
    rep(i, 100) {
        rep(j, 100) {
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n;
  vector<int> a(n);
  int l = 0, r = 0, ans = inf;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    r += a[i];
  }
  for (int i = 0; i < n; ++i) {
    l += a[i];
    r -= a[i];
    ans = min(ans, abs(r - l));
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,M;
int X[100100],Y[100100],Z[100100];
int used[100100];
vector<int> g[100100];
void dfs(int v){
	used[v]=true;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(used[u])continue;
		dfs(u);
	}
}
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> X[i] >> Y[i] >> Z[i];
		X[i]--;Y[i]--;
		g[X[i]].pb(Y[i]);
		g[Y[i]].pb(X[i]);
	}
	memset(used,false,sizeof(used));
	int ans = 0;
	for(int i=0;i<N;i++){
		if(!used[i]){
			ans++;
			dfs(i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10368
#include <stdio.h>

#define N 100

int main(){
	
  int a[N];
  int i,j,n,cout=0,tmp,minj;
	
  scanf("%d",&n);
	
  for(i=0;i<n;i++) scanf("%d",&a[i]);
	
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]) {
	minj=j;
      }
    }
    if(i!=minj){
    tmp=a[i];
      a[i]=a[minj];
      a[minj]=tmp;
      cout++;
    }
  }
			
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",cout);
				
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  int num = 1;
  int t = -1, p = a[0];
  while (true) {

    if (p == 2) {
      cout << num << endl;
      return 0;
    }
    
    if (num+2 > n) {
      cout << -1 << endl;
      return 0;
    }
    t = p;
    p = a[t - 1];


    num += 1;
  }
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int n,m,i,j;
    scanf("%d %d",&n,&m);
    int A[100][100];
    int b[100];
    int c[100]={0};
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]=c[i]+(A[i][j]*b[j]);
        }
        printf("%d\n",c[i]);
    }
    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,M;
    ll goukei = 0;
    cin >> N;
    vector<ll> T(N);
    for(int i = 0;i < N;i++)
        cin >> T.at(i);
    
    cin >> M;

    vector<int> P(M);
    vector<ll> X(M);

    for(int i = 0;i < M;i++){
        cin >> P.at(i) >> X.at(i);
    }

    for(int i = 0;i < M;i++){
        goukei = 0;
        for(int j = 0;j < N;j++){
            if(j == P.at(i) - 1)
                goukei += X.at(i);
            else
            {
                goukei += T.at(j);
            }
            
        }
        cout << goukei << endl;
    }

    return 0;
    
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  rep(i, n) if(s[i] != s[k-1]) s[i] = '*';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    var ans = 0
    repeat(n) {
        val x = sc.nextInt()
        ans += Math.min(Math.abs(k - x) * 2, x * 2)
    }
    println(ans)
}

Measured memory_bytes: 31012
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MXN = 1e6 + 1;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	bool vis[MXN];
	memset(vis, 0, sizeof(vis));
	map<int,int> cnt;
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		cnt[x]++;
	}
	int ans = 0;
	for (auto it : cnt) {
		int cur = it.first;
		if (!vis[cur]) {
			if (it.second == 1) ans++;
			for (int j=cur; j<MXN; j+=cur) {
				vis[j] = true;
			}
		}
	}
	cout << ans << '\n';
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < S.size(); i++)
    {
        int count = S.at(i) - 'A';
        count += N;
        count %= 26;
        char ans = 'A' + count;
        cout << ans;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[34];
int main(){
    int m ,n ,x ,y;
    cin >> m >> n;
    for(int i=0;i<m;i++) {
        cin>>x;
        for(int j=0;j<x;j++)  {
            cin>>y;
            a[y]++;
        }
        
    }
    int ans=0;
    for(int i=1;i<=30;i++) {
        if(a[i]==m)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc104/tasks/abc104_b
// ---------------------------------------------
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	check := func() bool {
		ctUpper := 0
		for i := range s {
			if 'A' <= s[i] && s[i] <= 'Z' {
				ctUpper++
			}
		}
		return s[0] == 'A' && strings.Contains(s[2:len(s)-1], "C") && ctUpper == 2
	}

	if check() {
		fmt.Println("AC")
	} else {
		fmt.Println("WA")
	}
}


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

const int N = 1e5+5;
long long n, cntr = 0, ans = 0;
string s[N], temp;
vector<long long> v;

int main() {
	
	cin >> n;
	for(int i = 0 ; i < n ; ++i){
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	
	sort(s, s+n);
	temp = s[0];
	cntr = 0;
	for(int i = 0 ; i < n ; ++i){
		if(s[i] != temp){
			v.push_back(cntr);
			cntr = 0;
			temp = s[i];
		}
		cntr++;
	}
	v.push_back(cntr);
	
	for(int i = 0 ; i < v.size() ; ++i){
		
		if(v[i] == 2)	ans += 1;
		else if(v[i] == 3)	ans += 3;
		else if(v[i] > 3){ ans += v[i]*(v[i]-1)/2;}
		
		// cout << v[i] << " " << ans << endl;
	}
	cout << ans << endl;
	// for(int i = 0 ; i < n ; ++i)	cout << s[i] << " ";
	// puts("");
	// for(int i = 0 ; i < v.size() ; ++i)	cout << v[i] <<  " ";
	
	return 0;
}

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

const int N = 1e5 + 10;

vector <int> G[N];
int used[N];
deque <int> dq;

void dfs1(int x){
	used[x] = 1;
	for (int i = 0; i < G[x].size(); i++){
		if (!used[G[x][i]]){
			dq.push_back(G[x][i]);
			dfs1(G[x][i]);
			break;
		}
	}
}

void dfs2(int x){
	used[x] = 1;
	for (int i = 0; i < G[x].size(); i++){
		if (!used[G[x][i]]){
			dq.push_front(G[x][i]);
			dfs2(G[x][i]);
			break;
		}
	}
}

int main(){
	int n, m, u, v;
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= m; i++){
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	memset(used, 0, sizeof(used));
	dq.push_back(1);
	dfs1(1);
	dfs2(1);
	printf("%d\n", (int)dq.size());
	while (!dq.empty()){
		printf("%d", dq.front());
		dq.pop_front();
		if (!dq.empty()) printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {
    int X, A;
    cin >> X >> A;

    if (X < A) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int v[n+1];
	map<int,int>odd;
	map<int,int>even;
	for(int i=0; i<n; i++){
		cin>>v[i];
		if(i%2==0){odd[v[i]]++;}
		else even[v[i]]++;
	}
	vector<pair<int,int>>x;
	vector<pair<int,int>>y;
	for(auto p:odd){
		x.push_back(make_pair(p.second,p.first));
	}
	x.push_back(make_pair(0,0));
	for(auto p:even){
		y.push_back(make_pair(p.second,p.first));
	}
	y.push_back(make_pair(0,0));
	sort(x.rbegin(),x.rend());
	sort(y.rbegin(),y.rend());
	if(x[0].second!=y[0].second){
		cout<<n-x[0].first-y[0].first<<endl; 
	}
	else{
		int a=n-x[0].first-y[1].first;
		int b=n-x[1].first-y[0].first;
		cout<<min(a,b)<<endl;
	}
}


Measured memory_bytes: 6520
#include<stdio.h>
int main()
{
	int dp[101][3][3]={},N,K,A,B,i,j,k,l,a[101]={},MOD=10000;
	for(scanf("%d%d",&N,&K);K--;)
	{
		scanf("%d%d",&A,&B);
		a[A]=B;
	}
	if(a[1])dp[1][a[1]-1][1]=1;
	else for(i=0;i<3;++i)dp[1][i][1]=1;
	for(i=2;i<=N;++i)
	{
		if(a[i])
		{
			for(j=0;j<2;++j)for(k=0;k<3;++k)
			{
					int&r=dp[i][a[i]-1][1];
					r=(r+dp[i-1][(a[i]+j)%3][k])%MOD;
			}
			for(k=0;k<2;++k)
			{
				int&r=dp[i][a[i]-1][k+1];
				r=(r+dp[i-1][a[i]-1][k])%MOD;
			}
		}
		else
		{
			for(j=0;j<3;++j)for(k=0;k<3;++k)
			{
				if(k)
				{
					int&r=dp[i][j][k];
					r=(r+dp[i-1][j][k-1])%MOD;
				}
				int&r=dp[i][j][1];
				for(l=1;l<3;++l)r=(r+dp[i-1][(j+l)%3][k])%MOD;
			}
		}
	}
	int res=0;
	for(j=0;j<3;++j)for(k=0;k<3;++k)res+=dp[N][j][k];
	printf("%d\n",res%MOD);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

bool isreachable(int s, int t, queue<int> &cnt) {
    vector<bool> v(16003);
    v[s + 8000] = true;
    while (!cnt.empty()) {
        int i = cnt.front();
        cnt.pop();
        vector<bool> vtmp(16003);
        for (int j = 0; j <= 16000; ++j) {
            if (j - i >= 0)
                vtmp[j] = v[j - i];
            if (j + i <= 16000)
                vtmp[j] = vtmp[j] | v[j + i];
        }
        swap(v, vtmp);
    }
    return v[t + 8000];
}

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

    string s;
    int x, y;
    cin >> s >> x >> y;

    bool h = true;
    int cnt = 0;
    queue<int> hcnt, vcnt;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'T') {
            (h ? hcnt : vcnt).push(cnt);
            h ^= 1;
            cnt = 0;
            continue;
        }
        cnt++;
    }
    if (cnt > 0)
        (h ? hcnt : vcnt).push(cnt);

    int ix = hcnt.front(), iy = 0;
    hcnt.pop();

    bool isok = isreachable(ix, x, hcnt) & isreachable(iy, y, vcnt);
    cout << (isok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>

using namespace std;

// 考えられる数列
deque<deque<int>> samples;

void calc_all_samples(int n, int m, int crt_roop, int crt_val,
                      deque<int> crt_sample) {
  if (crt_roop == n) {
    samples.push_back(crt_sample);

    return;
  }

  for (int i = crt_val; i <= m; i++) {
    deque<int> sample;
    sample = crt_sample;
    sample.push_back(i);
    calc_all_samples(n, m, crt_roop + 1, i, sample);
  }
}

int main() {
  int n, m, q;
  deque<deque<int>> items;

  cin >> n >> m >> q;

  // 入力
  for (int i = 0; i < q; i++) {
    deque<int> tmp_deque;

    for (int j = 0; j < 4; j++) {
      int tmp_val;
      cin >> tmp_val;
      tmp_deque.push_back(tmp_val);
    }

    items.push_back(tmp_deque);
  }

  // 考えられる数列全てを列挙する
  for (int i = 1; i <= m; i++) {
    deque<int> sample;
    sample.push_back(i);
    calc_all_samples(n, m, 1, i, sample);
  }

  // 考えられる数列を出力
  // for (int i = 0; i < samples.size(); i++) {
  //   for (int j = 0; j < samples[i].size(); j++) {
  //     cout << samples[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int max = 0;

  // それぞれの数列について得点を計算
  for (int i = 0; i < samples.size(); i++) {
    deque<int> sample = samples[i];
    int sum = 0;

    for (int j = 0; j < items.size(); j++) {
      deque<int> item = items[j];

      if (sample[item[1] - 1] - sample[item[0] - 1] == item[2]) {
        sum += item[3];
      }
    }

    if (sum > max) {
      max = sum;
    }
  }

  cout << max << endl;

  return 0;
}

Measured memory_bytes: 381508
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var x = ReadLong();
            var count = x / 11 * 2;
            var mod = x % 11;
            if (0 < mod)
            {
                if (mod <= 6)
                {
                    count++;
                }
                else
                {
                    count += 2;
                }
            }
            Console.WriteLine(count);
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  vll a(n);
  REP(i, n)
    cin >> a[i];

  ll ans = 0;
  REP(i, n){
    for(int j = i; j < n; j++)
      ans = max(ans, abs(a[i] - a[j]));
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 256
import math
X = int(input())
max = 0
bRange = math.floor(math.sqrt(X))
pRange = math.floor(math.log(X,2))
for b in range(bRange + 1):
    for p in range(pRange + 1):
        # print(b**p)
        if(max < b**p <= X):
            max = b**p
print(max)

Measured memory_bytes: 3060