akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

bool isOk(string s) {
  if (s.size() % 2 == 1){ 
    return false;
  }
  string pre = s.substr(0, s.size() / 2);
  string suf = s.substr(s.size() / 2, s.size() / 2);
  return pre == suf;
}
int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> mp;

  for (ll i = 0; i < M; i++)
  {
    ll ai, bi;
    cin >> ai >> bi;
    mp[ai] += 1;
    mp[bi] += 1;
  }
  for (ll i = 1; i <= N; i++)
  {
    cout << mp[i] << endl;
  }
  
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int main() {
	int n, m, a, b, c, d, e;
	string s, t, r;
	cin >> n;
	int minn = 1e9;
  int cnt = 0;
  for (int i=0 ; i<n ; i++) {
    int x;
    cin >>x;
    if (x<minn) {
      minn = x;
      cnt++;
    }
  }
  cout <<cnt<<endl;
	return 0;
}	

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    ll sol = 0, now;
    int A[100010], B[100010];
    for (int i = 0;i < N;i++) {
    	cin >> A[i] >> B[i];
    }
    for (int i = 0;i < N;i++) {
    	if ((A[i] | K) == K) sol += B[i];
    }
    for (int i = 0;i < 30;i++) {
    	int num = (1 << i);
    	if (K & num) {
    		int q = K - num;
    		q = (q | (num - 1));
    		now = 0;
    		for (int j = 0;j < N;j++) {
    			if ((A[j] | q) == q) {
    				now += B[j];
    			}
    		}
    		sol = max(sol, now);
    	}
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 1024
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n').map(function(n){return +n;});

var n;
while (n = lines.shift()) {
    if (n == 0) break;

    var s = []
    for (var i = 0; i < n; i++) {
        s.push(lines.shift());
    }

    s.sort(function(a, b){return a - b;});
    s.shift();
    s.pop();

    var sum = s.reduce(function(p,n){return p + n;});

    console.log(Math.floor(sum / s.length));
}

Measured memory_bytes: 8796
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  if(s.size()>=4&&s.substr(0,4)=="YAKI") pr("Yes");
  else pr("No");

}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

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

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		String S = sc.next();
      	String T = sc.next();
      int count = 0;
      	for(int i = 0; i < S.length(); i++){
        	if (S.charAt(i) != T.charAt(i)) count++;
        }
      System.out.println(count);
    }
    
}


Measured memory_bytes: 41032
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<60;
vector<pair<int,ll>> E[100050];
vector<ll> dist(100050,inf);
void dfs(int u){
    for(auto v : E[u]){
        if(dist[v.first] > dist[u] + v.second){
            dist[v.first] = dist[u] + v.second;
            dfs(v.first);
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n-1;++i){
        int a,b;ll c;
        cin>>a>>b>>c;
        a--;
        b--;
        E[a].push_back({b,c});
        E[b].push_back({a,c});
    }
    int q,k;
    cin>>q>>k;
    k--;
    dist[k] = 0;
    dfs(k);
    for(int i=0;i<q;++i){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}



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

using namespace std;
#define int long long int
int32_t main() {
    int n,x,t;
    cin>>n>>x>>t;
    double p=(double)n/((double)x);
    int a=ceil(p);
    a=a*t;
    cout<<a;    
    return 0;
}

Measured memory_bytes: 3712
n,m = map(int,input().split())
p_s = [input().split() for _ in range(m)]
problem = [0]*n
pena = [0]*n
penalty = 0
for i in range(m):
    if p_s[i][1] == 'WA':
        if problem[int(p_s[i][0])-1] == 0:
            pena[int(p_s[i][0])-1] += 1
    elif p_s[i][1] == 'AC':
        problem[int(p_s[i][0])-1] = 1
        penalty += pena[int(p_s[i][0])-1]
        pena[int(p_s[i][0])-1] = 0
print(sum(problem), penalty)

Measured memory_bytes: 33696
_input1 = input()
_input2 = input()
N, X = tuple([int(a) for a in _input1.split(' ')])
l_list = [int(a) for a in _input2.split(' ')]

length = 0
cnt = 0

for l in l_list:
    if length > X:
        break
    length += l
    cnt += 1

if length <= X:
    cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+7, LINF = 1e18;


int main()
{
    string s;
    cin>>s;
    yn(s.find("AC")!=string::npos);

    return 0;
}

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

typedef long long ll;
ll n, s;
int main()
{
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    s = n / 11 * 2;
    if (n % 11 == 0) s += 0;
    else if (n % 11 <= 6 - n / 11 % 2) s++;
    else s += 2;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned uint;
typedef long long Int;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }

int main()
{
	int n, k;
	while (cin >> n >> k, n && k){
		string card[20];
		vector <string> a;
		for (int i = 0; i < n; i++){
			cin >> card[i];
		}
		if (k == 2){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					if (i != j) {
						// cout << i << " " << j << endl;
						a.push_back(card[i] + card[j]);
					}
				}
			}
		}
		if (k == 3){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						if (i != j && j != k && i != k) a.push_back(card[i] + card[j] + card[k]);
					}
				}
			}
		}
		if (k == 4){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						for (int l = 0; l < n; l++){
							if (i != j && i != k && i != l && j != k && j != l && k != l) a.push_back(card[i] + card[j] + card[k] + card[l]);
						}
					}
				}
			}
		}
		a.push_back("9999999999");
		sort(a.begin(), a.end());
		int ret = 0;
		for (int i = 0; i < a.size()-1; i++){
			if (a[i] != a[i + 1]) ret++;
		}
		// puts("s");
		cout << ret << endl;
	}

    return 0;
}

Measured memory_bytes: 1356
N = int(input())
A = map(int, input().split())
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisf = 0
former = 20

for a in A:
    satisf += B[a-1]
    if a - 1 == former:
        satisf += C[a-2]
    former = a

print(satisf)

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    n = getN()
    ans = 0
    runruns = [[str(i) for i in range(10)]]
    for digit in range(9):
        tmp = []
        for i in range(10):
            stri = str(i)
            for run in runruns[-1]:
                if abs(i - int(run[0])) <= 1:
                    tmp.append(stri + run)

        tmp.sort()
        runruns.append(tmp)
    runruns = [[r for r in run if r[0] != "0"] for run in runruns]
    # print(sum([len(run) for run in runruns]))
    # print(runruns[-2])
    ans = []
    for run in runruns:
        ans = ans + run

    print(ans[n-1])
    # print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 75380
def smaller(x, y):
	if x < y:
		return x
	return y

def div2(n):
	cnt = 0
	m = n
	while m % 2 == 0:
		cnt += 1
		m //= 2
	return cnt

N = int(input())
A = list(map(int, input().split()))
min = 5000000000000000
for i in range(0, N):
	min = smaller(min, div2(A[i]))
print(min)

Measured memory_bytes: 38512
N,M = map(int, input().split())

"""考え方
端から端まで、で一致するパターンがないか全探索
"""

## 1.INPUTの取得
A = []
for n in range(N):
  A.append(input())
B = []
for m in range(M):
  B.append(input())


## 2.全探索
ans = 'No'
for i in range(N-M+1): ## Aの行
  for j in range(N-M+1): ## Aの列 
    ## 2-1.M,Nの一番上の行を比較
    if B[0] == A[i][j:j+M]:
      ## 下の行も比較
      for x in range(1,M):
        if B[x] != A[i+x][j:j+M]:
          break
      else:
        ans = 'Yes'
  

print(ans)

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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int a,b,c;

int main(){
    INIT;
    cin >> a; cin >> b; cin >> c;
    if(a > b) swap(a,b);
    if(a <= c && c <= b) { OUT("Yes") }
    else { OUT("No") }
    NL;
}

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

const ll MOD = ll(1e9 + 7);
const int K = 2333;

int n, k;
ll f[K];

ll pw(ll a, ll b) {
    ll r = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) {
            r = r * a % MOD;
        }
        a = a * a % MOD;
    }
    return r;
}

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

    vector<int> divs;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            divs.push_back(i);
            if (i * i < n) {
                divs.push_back(n / i);
            }
        }
    }
    sort(divs.begin(), divs.end());
    assert(int(divs.size()) < K);

    ll ans = 0;
    for (int i = 0; i < int(divs.size()); i++) {
        int d = divs[i];
        f[i] = pw(k, (d + 1) / 2);
        for (int j = 0; j < i; j++) {
            if (d % divs[j] == 0) {
                f[i] = (f[i] - f[j] + MOD) % MOD;
            }
        }

        ll coef = (d % 2 == 0 ? d / 2 : d);
        ans = (ans + coef * f[i]) % MOD;
    }

    cout << ans << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int end = n % 10;
  if(end == 3) puts("bon");
  else if(end == 0 || end == 1 || end == 6 || end == 8) puts("pon");
  else puts("hon");
  return 0;
}

Measured memory_bytes: 3660
import collections
#定数
n = int(input())
S = input()

#ここの計算量は？
#R,G,Bそれぞれの出現回数
C = collections.Counter(S)
r = C['R']
g = C['G']
b = C['B']
#条件1
ans = r * g * b

#最大O(n^2)
for j in range(1, n-1):
    sj = S[j] 
    if j > n-1-j:
        a = n-1-j
    else:
        a = j
    for d in range(1, a+1):
        si = S[j-d]
        sk = S[j+d]
        if si != sj and si != sk and sj != sk:
            #条件2を満たさないが条件1を満たすもの
            ans -= 1
        else:
            pass
print(ans)







Measured memory_bytes: 9456
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int main(void) {
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
template<class T> void verr(const vector<T>& v){ for(auto& a : v) cout << a << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N), B(N);
    rep(i, N) cin >> A[i];
    ll sum = accumulate(all(A), 0ll);
    if(sum%(N*(N+1)/2)){
        cout << "NO" << endl;
        return 0;
    }

    ll cnt = sum / (N * (N + 1) / 2);
    rep(i, N - 1) B[i] = A[i + 1] - A[i];
    B[N - 1] = A[0] - A[N-1];
    rep(i, N) B[i] -= cnt;

    bool isok = true;
    ll dcnt = 0;
    rep(i,N){
        if (B[i] % N){
            // err(i);
            isok = false;
        }
        else
            dcnt += abs(B[i] / N);
    }
    // err(cnt, dcnt, isok);
    cout << (dcnt == cnt and isok ? "YES" : "NO") << endl;
}

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

int hoge[33][101010];
int ans = 0;

int main(){
    
    int N, C;
    cin >> N >> C;
    for(int i = 0; i < N; i++){
        int s, t, c;
        cin >> s >> t >> c;
        for(int j = s; j <= t; j++){
            hoge[c][j] = 1;
        }
    }
    for(int i = 1; i <= 101000; i++){
        int cnt = 0;
        for(int j = 0; j <= C; j++)cnt += hoge[j][i];
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

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

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

    vector< vector<int> > s(n);
    int p[10];

    for(int i = 0;i < m;i++){
        int k;
        cin >> k;
        for(int j = 0;j < k;j++){
            int si;
            cin >> si;
            si--;
            s[si].push_back(i);
        }
    }
    for(int i = 0;i < m;i++){
        cin >> p[i];
    }

    int a = pow(2,n);
    int ret = 0;
    for(int i = 0;i < a;i++){
        int cur = i;
        vector<int> num(m);
        for(int j = 0;j < n;j++){
            if(cur%2 == 1){
                for(int k = 0;k < s[j].size();k++){
                    num[s[j][k]]++;
                }
            }
            cur /= 2;
        }
        bool check = true;
        for(int j = 0;j < m;j++){
            if(num[j] % 2 != p[j]){
                check = false;
            }
        }
        if(check){
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 512
SA = list(input())
SB = list(input())
SC = list(input())
turn = 'a'

for i in range(301):
    if turn == 'a':
        
        if len(SA) == 0:
            print('A')
            break
        
        else:
            turn = SA[0]
            del SA[0]
    
    if turn == 'b':
        
        if len(SB) == 0:
            print('B')
            break
        
        else:
            turn =SB[0]
            del SB[0]
        
    if turn == 'c':
        if len(SC) == 0:
            print('C')
            break
        else:
            turn = SC[0]
            del SC[0]

Measured memory_bytes: 3064
// AOJ 1564: String Compression
// 2017.10.24 bal4u@uu

#include <stdio.h>
#include <string.h>

char s[102], *p;
int f['z'+1];

int main() 
{
	int i, j, w, ans;

	scanf("%s", s); 
	p = s; while (*p) f[*p++]++;
	w = p - s; p = s;
	do {
		j = 0;
		for (i = '0'; i <= '9'; i++) if (f[i] > 0) j = 1, *p++ = i, f[i]--;
	} while (j);
	do {
		j = 0;
		for (i = 'a'; i <= 'z'; i++) if (f[i] > 0) j = 1, *p++ = i, f[i]--;
	} while (j);

	ans = w;
	for (i = 0; i < w; i = j) {
		for (j = i+1; s[j] == s[j-1]+1; j++);
		if (j - i > 3) ans -= j-i-3;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
char s[100005],t[100005];
int nsA[100005],nsB[100005],ntA[100005],ntB[100005];
int main(){
    int a,b,c,d,q,i;
    scanf("%s%s",s+1,t+1);
    int len=strlen(s+1);//printf("{%d}",len);
    nsA[0]=0;nsB[0]=0;
    for(i=1;i<=len;i++){
        if(s[i]=='A'){
            nsA[i]=nsA[i-1]+1;
            nsB[i]=nsB[i-1];
        }
        else{
            nsA[i]=nsA[i-1];
            nsB[i]=nsB[i-1]+1;
        }
        //printf("%d %d\n",nsA[i],nsB[i]);
    }
    int let=strlen(t+1);
    ntA[0]=0;ntB[0]=0;
    for(i=1;i<=let;i++){
        if(t[i]=='A'){
            ntA[i]=ntA[i-1]+1;
            ntB[i]=ntB[i-1];
        }
        else{
            ntA[i]=ntA[i-1];
            ntB[i]=ntB[i-1]+1;
        }
    }
    scanf("%d",&q);
    int ps,pt;
    for(i=0;i<q;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int asn=nsA[b]-nsA[a-1],bsn=nsB[b]-nsB[a-1],atn=ntA[d]-ntA[c-1],btn=ntB[d]-ntB[c-1];
        //printf("(%d %d %d %d)\n",asn,bsn,atn,btn);
        if(asn<bsn){
            int x=(bsn-asn)%3;
            if(x==0)    ps=0;
            else if(x==1)   ps=2;
            else    ps=1;
        }
        else{
            int x=(asn-bsn)%3;
            if(x==0)    ps=0;
            else if(x==1)   ps=1;
            else    ps=2;
        }
        if(atn<btn){
            int x=(btn-atn)%3;
            if(x==0)    pt=0;
            else if(x==1)   pt=2;
            else    pt=1;
        }
        else{
            int x=(atn-btn)%3;
            if(x==0)    pt=0;
            else if(x==1)   pt=1;
            else    pt=2;
        }
        if(pt==ps){
            printf("YES\n",ps,pt);
        }
        else{
            printf("NO\n",ps,pt);
        }
    }
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ref(i,n) for(int i=0;i<n;i++)
using namespace std;
#define INF 1111111111

int n,m;
int a[1001],b[1001],c[1000],d[1000],e[1000],f[1000];
int U[4000][4000], L[4000][4000];
typedef pair<int,int> P;
vector<vector<bool>>vis;
typedef long long ll ;


int id(vector<ll>h,ll a){
    return lower_bound(h.begin(),h.end(),a)-h.begin();
}

int main(){

    cin>>n>>m;
    vector<ll> h,w;
    ref(i,n){
        cin>>a[i]>>b[i]>>c[i];
        h.push_back(a[i]);
        h.push_back(b[i]);
        w.push_back(c[i]);
    }
    ref(i,m) {
        cin>>d[i]>>e[i]>>f[i];
        h.push_back(d[i]);
        w.push_back(f[i]);
        w.push_back(e[i]);
    }
    h.push_back(INF);
    h.push_back(-INF);
    w.push_back(INF);
    w.push_back(-INF);
    h.push_back(0);
    w.push_back(0);
    sort(h.begin(),h.end());
	sort(w.begin(),w.end());
	h.erase(unique(h.begin(),h.end()),h.end());
	w.erase(unique(w.begin(),w.end()),w.end());



	vis=vector<vector<bool>>(h.size(),vector<bool>(w.size(),false));


	ref(i,n){
		L[id(h,a[i])][id(w,c[i])]++;
		L[id(h,b[i])][id(w,c[i])]--;
	}
	ref(i,m){
		U[id(h,d[i])][id(w,e[i])]++;
		U[id(h,d[i])][id(w,f[i])]--;
	}
	for(int i=1;i<h.size();i++){
		for(int j=1;j<w.size();j++){
			L[i][j]+=L[i-1][j];
			U[i][j]+=U[i][j-1];
		}
	}


	queue<P>q;
	q.push({id(h,0),id(w,0)});
	ll ans=0;
	while(!q.empty()){
        P p=q.front();
        q.pop();
        int x=p.first,y=p.second;
        if(!x||!y||x==h.size()-1||y==w.size()-1){
            cout<<"INF";
            return 0;
        }
        if(!vis[x][y]){
            vis[x][y]=1;
            ans+=(h[x+1]-h[x])*(w[y+1]-w[y]);
			if(!U[x][y])q.push({x-1,y});
			if(!L[x][y])q.push({x,y-1});
			if(!U[x+1][y])q.push({x+1,y});
			if(!L[x][y+1])q.push({x,y+1});
        }


	}
	cout<<ans;
	return 0;
}


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

#define int long long

#define inf (int)1000000007
#define mod (int)1000000007

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rtrep(i, n) for(int i = (n); i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)

bool dd[514][514];

bool md[514];

signed main() {
	int dn;
	cin >> dn;
	bool cnt = true;
	rep(i, dn) {
		string s;
		cin >> s;
		rep(j, dn) {
			if(s[j] == '.') {
				dd[i][j] = false;
			}
			else {
				dd[i][j] = true;
				cnt = false;
			}
		}
	}
	if(cnt) {
		cout << -1 << endl;
		return 0;
	}
	rep(i, dn) {
		md[i] = false;
		rep(j, dn) {
			if(dd[j][i]) {
				md[i] = true;
				break;
			}
		}
	}
	int ans = inf;
	rep(i, dn) {
		int w = 0;
		rep(j, dn) {
			if(!dd[i][j]) {
				w++;
			}
		}
		if(!dd[i][i]) {
			if(!md[i]) {
				w++;
			}
		}
		ans = min(ans, w);
	}
	rep(i, dn) {
		bool ok = true;
		rep(j, dn) {
			if(!dd[j][i]) {
				ok = false;
			}
		}
		if(!ok) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int bfs( string str )
{
	const int N = str.size();

	queue< pair< string, int > > que;
	que.push( MP( str, 0 ) );

	set< string > visited;
	visited.insert( str );

	set< char > chars;
	chars.insert( 'r' );
	chars.insert( 'g' );
	chars.insert( 'b' );

	while ( !que.empty() )
	{
		auto cur = que.front().fst;
		auto time = que.front().snd;
		que.pop();

		if ( set<char>( ALL( cur ) ).size() == 1 )
		{
			return time;
		}

		REP( i, 0, N - 1 )
		{
			if ( cur[i] == cur[ i + 1 ] )
			{
				continue;
			}

			auto c = chars;
			c.erase( cur[i] );
			c.erase( cur[ i + 1 ] );

			auto next = cur;
			next[i] = next[ i + 1 ] = *c.begin();

			if ( EXIST( visited, next ) )
			{
				continue;
			}

			que.push( MP( next, time + 1 ) );
			visited.insert( next );
		}
	}

	return -1;
}			

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

	while ( true )
	{
		string str;
		cin >> str;

		if ( str == "0" )
		{
			break;
		}

		int res = bfs( str );

		if ( res == -1 )
		{
			cout << "NA";
		}
		else
		{
			cout << res;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

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

    int lE = 0;
    int lW = 0;
    int rE = 0;
    int rW = 0;

    for(int i = 1; i < n; i++){
        if(s[i] == 'E'){rE++;}
        else{rW++;}
    }
    int cnt = lW + rE;
    for(int i = 0; i < n-1; i++){
        int k;
        if(s[i] == 'W'){lW++;}
        else{lE++;}
        if(s[i+1] == 'W'){rW--;}
        else{rE--;}
        k = lW + rE;
        if(cnt > k){cnt = k;}
    }

    cout << cnt << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




int a[300][300], used[300];
signed main(){
  int n, m;
  scanf("%lld%lld", &n, &m);
  rep(i,n)rep(j,m){scanf("%lld", &a[i][j]);a[i][j]--;}
  int ans = INF, cnt = m;
  rep(i,300)used[i] = 1;
  while(cnt){
    int idx = -1, mx = 0, f[300] = {};
    rep(i,n){
      rep(j,m)if(used[a[i][j]]){
        f[a[i][j]]++;
        if(mx < f[a[i][j]]){
          mx = f[a[i][j]];
          idx = a[i][j];
        }
        break;
      }
    }
    chmin(ans, mx);
    used[idx] = 0;cnt--;
  }
  printf("%lld\n", ans);
	return 0;
}







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

int main(){
    int n, i, t, a = 0;
    vector<int> v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> t;
        v.push_back(t);
    }
    for(i = 0; i < n; i++){
        cin >> t;
        if(t < v[i]){
            a += v[i] - t;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

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; }

using namespace std;
typedef long long ll;
const int INF = 10000000;

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

    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int n, a, b, x[200099];
int main() {
	cin >> n;
	while(n--) {
		cin >> a >> b;
		x[a + b]++;
	}
	for(int i = 0; i <= 200029; i++) {
		x[i + 1] += x[i] / 2; x[i] %= 2;
		if(x[i] == 1) cout << i << ' ' << 0 << endl;
	}
}

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

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

Measured memory_bytes: 83052
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	var A int
	for i := 0; i < n; i++ {
		fmt.Scan(&A)
		a[i] = A - 1
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&c[i])
	}
	ans := 0
	for i := 0; i < n; i++ {
		ans += b[a[i]]
		if i > 0 {
			if a[i-1]+1 == a[i] {
				ans += c[a[i-1]]
				// log.Println("get c points", a[i-1], a[i], "bonus=", c[a[i-1]])
			}
		}
		// log.Println(b[a[i]], ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int max1 = 0, max2 = 0;
	int maxindex = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a > max1){
			max1 = a;
			maxindex = i;
		} else if(a > max2){
			max2 = a;
		}
	}

	for(int i = 0; i < n; i++){
		if(i == maxindex) cout << max2 << endl;
		else cout << max1 << endl;
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <algorithm>
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;}

const ll INF = 1000000000;
const int MAX_N = 1000;

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

    vector<pair<int, string>> w_list;
    string s[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }

    sort(s, s+n);

    int cnt = 1;
    int m = 0;
    for(int i = 1; i < n; i++){
        if(s[i] == s[i-1]){
            cnt++;
            if(i == n-1){
                w_list.push_back(make_pair(cnt, s[i-1]));
                m++;
            }
            continue;
        }
        w_list.push_back(make_pair(cnt, s[i-1]));
        cnt = 1;
        m++;
        if(i == n-1){
                w_list.push_back(make_pair(cnt, s[i]));
                m++;
        }
    }

    sort(w_list.begin(), w_list.end());
    // for(int i = 0; i < m; i++){
    //     cout <<  w_list[i].first << w_list[i].second << endl;
    // }

    int max_cnt = w_list[m-1].first;
    vector<string> ans_list;
    for(int i = m-1; i >= 0; i--){
        if(w_list[i].first != max_cnt) break;
        ans_list.push_back(w_list[i].second);
    }

    sort(ans_list.begin(), ans_list.end());

    for(int i = 0; i < ans_list.size(); i++){
        cout << ans_list[i] << endl;
    }
    
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A+B > C+D){
    cout << "Left" << endl;
  }
  else if (A+B==C+D){
    cout << "Balanced" << endl;
  } 
  else{
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
nums = [list(map(int,input().split())) for i in range(n)]


first = True
record = {}
target = None
for x, y, h in nums:
    if h != 0:
        target = x, y, h

if target is not None:
    x, y, h = target
    for i in range(0,101):
        for j in range(0, 101):
            if abs(x - i) + abs(x - j) + h >= 1:
                record[(i,j)] = abs(x - i) + abs(y - j) + h
    
    for x, y, h in nums:
        for (i, j) in list(record.keys()):
            if max(record[(i, j)] - abs(x-i) - abs(y-j), 0) != h:
                record.pop((i,j))
    key = list(record.keys())[0]

    print(key[0],key[1], record[key])
else:
    for x, y, h in nums:
        record[(x,y)] = True
    ndone = True
    for i in range(101):
        for j in range(101):
            if (i, j) not in record and ndone:
                print(i, j, 1)
                ndone = False


Measured memory_bytes: 4468
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int N, V[20], C[20];
    cin >> N;
    
    //V[i]に代入
    for(int i=0; i<N; i++){
        cin >> V[i];
    }
    
    //C[i]に代入
    for(int i=0; i<N; i++){
        cin >> C[i];
    }
    
    
    int mouke=0;
    
    for(int i=0; i<N; i++){
        if(V[i] > C[i]){
            mouke += V[i] - C[i];
        }
    }
    
    cout << mouke << "\n";
    
}

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

int main(){
	int n;
	cin>>n;
	vector<int> x(n);


	for (size_t i = 0; i < n; i++)
	{
		cin>>x.at(i);
	}

	sort(x.begin(),x.end());
	vector<int> all(x.at(n-1));

	for (size_t i = 1; i <= x.at(n-1); i++)
	{
		for (size_t ij = 0; ij < n; ij++)
		{
			all.at(i-1) += (x.at(ij)-i)*(x.at(ij)-i);
		}
		
		
	}
	
	sort(all.begin(),all.end());
	cout<<all.at(0);
	
}

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

int main(){

    int D, N;
    cin >> D >> N;
    
    int ans = 0;
    
    if(N <= 99){
        ans = pow(100, D) * N;
    }
    if(N == 100){
        ans = pow(100, D) * 101;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int N = 100005;
  const int INF = 1e16;
  const double PI = acos(-1);

int dp[N];

int modexp(int x, int y)
{
    int res = 1;
    x = (x % mod + mod) % mod;
    while(y)
    {
        if(y & 1)
            res = (res*x) % mod;
        y >>= 1;
        x = (x*x) % mod;
    }
    return res%mod; 
}

int32_t main()
{

    int n,k;
    cin >> n >> k;

    dp[k] = 1;

    for(int i = k - 1; i >= 1; i--)
    {
      dp[i] = modexp((k/i),n)%mod;

      for(int j = 2*i; j <= k; j += i)
      {
        dp[i] -= dp[j];
        dp[i] += mod;
        dp[i] %= mod;
      }
    }

    int ans = 0;

    for(int i = 1; i <= k ;i++)
    {
      ans += ((dp[i]%mod)*(i%mod))%mod;
      ans %= mod;
    }

    cout << ans%mod ;
    return 0;
}

Measured memory_bytes: 4356
#include<iostream>
using namespace std;
char s[1005];
char t[1005];
int n;
int x =1,y=1;
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> s[i];
	for(int i = 1; i <= n; i++)
		cin >> t[i];
	for(int i = 1; i <=2* n; i++){
		if(i % 2 != 0)
			cout << s[x++];
		else cout << t[y++];
	}
	cout << endl;


}

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

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= n; j++) {
    		for (int k = 1; k <= n; k++) {
    			int g = __gcd(i, k);
    			g = __gcd(g, j);
    			ans += g;
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll n;cin>>n;
  if(n%2){
    cout<<0<<endl;return 0;
  }else{
    n=n/10;
    ll ans=n;
    while(n!=0){
      n=n/5;ans+=n;
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,ans;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (ll i=sqrt(n);i>=1;--i)
	{
		if (n%i==0)
		{
			ans=ans+i-1;
			ans=ans+n/i-1;
			cout<<ans;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
Di=[input() for i in range(N)]
count=0
n=0
D=[]
a=[]
A=0
for i in range(N):
    D.append(Di[i].split())

for i in range(N):
    if D[i][0]==D[i][1]:
        count+=1
    else:
        a.append(count)
        count=0
if len(a)==0:
    A=0
else:
    A=max(a)

if A>count:
    n+=A
else:
    n+=count
if n>=3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9168
#include <iostream>
#include <string>

using namespace std;

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

	string S;
	cin >> S;

	bool a_flg = false;
	bool b_flg = false;
	bool c_flg = false;

	bool ans = true;

	for (int i = 0; i < 3; i++) {
		switch (S[i]) {
		case 'a':
			if (a_flg) {
				ans = false;
			}
			a_flg = true;
			break;
		case 'b':
			if (b_flg) {
				ans = false;
			}
			b_flg = true;
			break;
		case 'c':
			if (c_flg) {
				ans = false;
			}
			c_flg = true;
			break;
		default:
			ans = false;
			break;
		}
	}
	if (ans) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
cookie = input().split()
A,B,C = int(cookie[0]),int(cookie[1]),int(cookie[2])
kaisuu = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    A,B,C = (B+C)/2,(A+C)/2,(A+B)/2
    if A == B and B == C and A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        kaisuu = -1
        break
    else:
        kaisuu += 1
print(kaisuu)

Measured memory_bytes: 3064
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
using namespace std;
int main(){
	
	bool p[5000000]={false};
	
	p[2]=true;
	
	for(int i=3;i<=5000000;i+=2){
		bool f=false;
		for(int j=3;j<=sqrt(i);j+=2){
			if(i%j==0){
				f=true;
				break;
			}
		}
		if(!f)
			p[i]=true;
	}
	long long n;
	
	while(cin>>n,n!=0){
		long long count=0;
		for(int i=n+1;i<=n*2;i++){
			if(p[i])
				count++;
		}
		cout<<count<<endl;
	}
	



}

Measured memory_bytes: 6048
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    ls = []
    for i in range(n):
        if i + 1 != p[i]:
            if cnt != 0:
                ls.append(cnt)
                cnt = 0
        else:
            cnt += 1
    if cnt != 0:
        ls.append(cnt)
        cnt = 0
    cnt = 0
    for v in ls:
        cnt += v // 2 if v % 2 == 0 else (v + 1) // 2
    print(cnt)


if __name__ == '__main__':
    solve()


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

arr = [map(int,raw_input().split()) for i in range(n)]

def ceil(n,d):
 if n%d==0:
  return n/d
 else:
  return n/d+1

a = 1
b = 1
for i in range(n):
	x, y = arr[i]
	t = max(ceil(a,x), ceil(b,y))

	a = x*t; b = y*t

print a+b

Measured memory_bytes: 2692
from collections import deque


def remove(adj, a):
    for nxt in adj[a]:
        adj[nxt].remove(a)


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a].add(b)
        adj[b].add(a)
    ans = deque([a, b])
    remove(adj, b)
    remove(adj, a)
    first = a
    last = b
    while len(adj[first]):
        nxt = list(adj[first])[0]
        ans.appendleft(nxt)
        remove(adj, nxt)
        first = nxt
    remove(adj, first)
    for a in ans:
        if a in adj[last]:
            adj[last].remove(a)
    while len(adj[last]):
        nxt = list(adj[last])[0]
        ans.append(nxt)
        remove(adj, nxt)
        last = nxt
    print(len(ans))
    print(*ans)


if __name__ == "__main__":
    main()


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


long long n,i,a[10];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(i=0; i<n; i++){
		cin>>a[0]>>a[1]>>a[2];
		sort(a,a+3);
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]){
			cout<<"YES"<<'\n';
		}else
			cout<<"NO"<<'\n';
	}
	
	
	
return 0;
}

Measured memory_bytes: 3248
#include<stdio.h>
int main(){
	
	int i,c=0,joi=0,ioi=0;
	char str[10004] = { 0 };
		
	while(scanf("%c",&str[c])!=EOF){
		c++;
		if(str[c-1]=='\n'){
			for(i=0;i<c;i++){
				if(str[i] == 'J' && str[i+1] == 'O' && str[i+2] == 'I')joi++;
				if(str[i] == 'I' && str[i+1] == 'O' && str[i+2] == 'I')ioi++;
		
			}
		printf("%d\n",joi);
		printf("%d\n",ioi);
		c=0;
		joi=0;
		ioi=0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

int main()
{
	int r;
	cin>>r;
	cout<<3*r*r<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

        int start[] = new int[n+1];
        int finish[] = new int[n+1];

		for (int i=0; i < m; i++){
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			if (c1 == 1){
			    start[c2] = 1;
			}
			if (c2 == n){
			    finish[c1] = 1;
			}
		}
 
		boolean flg=false;
        for(int i=0; i<n; i++) {
            if (start[i] == 1) {
                if (finish[i] == 1) {
                    flg = true;
                    break;
                } 
            }
        }
        
		if(flg){
			System.out.println("POSSIBLE");
		}else{
			System.out.println("IMPOSSIBLE");
		}
 
	}
}

Measured memory_bytes: 96136