akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    ll X;
    cin >> X;
    ll num = 100;
    ll ans = 0;
    while (num < X)
    {
        ans += 1;

        num *= 1.01;
    }
    cout << ans << endl;
}


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


int main(){
    int n;cin >> n;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        LL x,y;
        cin >> x >> y;
        v.pb(P(x+y,x-y));
    }
    for (int i = 0; i < n-1; i++) {
        if(abs(v[i+1].fs)%2!=abs(v[i].fs)%2){
            puts("-1");
            return 0;
        }
    }
    int m;
    vector<LL> d;
    if(v[0].fs%2){
        m = 31;
        cout << m << endl;
        for (int i = 0; i < m; i++) {
            cout << (1LL<<i) << " ";
            d.pb(1LL<<i);
        }
        puts("");
    }
    else{
        m = 32;
        cout << m << endl;
        cout << 1 << " ";
        d.pb(1);
        for (int i = 0; i < m-1; i++) {
            cout << (1LL<<i) << " ";
            d.pb(1LL<<i);
        }
        puts("");
    }
    for (int i = 0; i < n; i++) {
        vector<bool> x(m),y(m);
        LL s = abs(v[i].fs),t=abs(v[i].sc);
        LL ssum=0,tsum=0;
        for (int j = m-1; j >= 0; j--) {
            if(ssum - s <= 0){
                ssum += d[j];
                x[j] = true;
            }
            else{
                ssum -= d[j];
                x[j] = false;
            }
            if(tsum - t <= 0){
                tsum += d[j];
                y[j] = true;
            }
            else{
                tsum -= d[j];
                y[j] =false;
            }
        }
        LL a=0,b=0;
        for (int j = 0; j < m; j++) {
            if(v[i].fs<0) x[j]=x[j]^1;
            if(v[i].sc<0) y[j]=y[j]^1;
            if(x[j]&&y[j]) cout << "R";
            else if(x[j]&&!y[j]) cout << "U";
            else if(!x[j]&&y[j]) cout << "D"; 
            else cout << "L";
            a+=(x[j]?1:-1)*d[j];
            b+=(y[j]?1:-1)*d[j];
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 256
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int a,b,c;
    cin>>a>>b>>c;

    if((a-b)>=c){
        cout<<0;
    }else{
        cout<<c-(a-b);
    }

    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

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

	ll n, k; cin >> n >> k;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];
	ll s = 1;
	rep(i, 0, k) s += a[i];

	rep(i, k, n) {
		ll now = s + a[i] - a[i - k];
		if (now > s) cout << "Yes" << '\n';
		else cout << "No" << "\n";
		s = now;
	}

	return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin>>n>>m, n+m) {
    int p[n];
    REP(i,n) 
      cin >> p[i];
    vector<int> v(n*n);
    REP(i,n)
      REP(j,n)
      v[i*n + j] = p[i] + p[j];
    v.push_back(0);
    REP(i,n)
      v.push_back(p[i]);
    sort(ALL(v));
    // FOR(it, v)
    //   cout << *it << " ";
    // cout << endl;
    int res = 0; 
    REP(i,v.size()) {
      vector<int>::iterator it = upper_bound(ALL(v), m-v[i]);
      int tmp;
      if (it == v.begin()) {
        break;
      } else {
        it--;
        tmp = v[i] + *it;
      }
      res = max(res, tmp);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 6548
#include <iostream>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    if(y%2==0)
    {
        y=y/2;
        int a=y-x;
        if(a>=0 && a<=x)
        cout<<"Yes";
        else 
        cout<<"No";
    }
    else 
    cout<<"No";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
map<ll, ll> mp;
int main(){
    string s; cin >> s;
    int n = s.size();
    vi t(n); rep(i,n)t[i] = s[i] - '0';

    ll sum = 0, pow_10 = 1;
    repr(i,n){
        //cout << sum << " ";
        //cout << pow_10 * t[i] << " ";

        sum += pow_10 * t[i];
        //cout << sum << endl;

        pow_10 = (pow_10 * 10) % 2019;
        sum %= 2019;
        mp[sum]++;
    }
    //cout << endl;
    ll ans = 0;
    for(map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++){
        //cout << it->first << " " << it->second << endl;
        if(it == mp.begin() && it->first == 0)ans += it->second;
        ans += it->second * (it->second - 1) / 2;
    }
    cout << ans << endl;

    return 0;
}  

Measured memory_bytes: 4336
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,k,n,x,point[15][2],order[15];
char team[15];

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int main(){
	while(scanf("%d",&n)*n){
		for(i=0;i<n;i++){
			scanf("\n%c",&team[i]);
			order[i]=i;
			point[i][0]=0;
			point[i][1]=0;
			for(j=1;j<n;j++){
				scanf("%d",&x);
				if(x<2)point[i][x]++;
			}
			for(j=i;j>0;j--){
				if(point[i][0]>point[order[j-1]][0] || (point[i][0]==point[order[j-1]][0] && point[i][1]<point[order[j-1]][1])){
					swap(&order[j],&order[j-1]);
				}
				else break;
			}
		}
		for(i=0;i<n;i++)printf("%c\n",team[order[i]]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int x,a;
    for(;;){
        scanf("%d",&x);
        if(x == 0)break;
        for(int i = 0;i < 9; i++){
            scanf("%d",&a);
            x -= a;
        }
        printf("%d\n",x);
    }
    return 0;
}

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

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
    
    struct node *se = nil -> next;
    
    while(se != nil && se -> key != key){
        se = se -> next;
    }
    return se;
}

void init(){
    nil = malloc(sizeof(struct node));
    nil -> next = nil;
    nil -> prev = nil;
}

void printList(){
    NodePointer cur = nil -> next;
    
    int isf = 1;
    
    while(1){
        if(cur == nil) break;
        if(isf == 0) printf(" ");
        printf("%d",cur -> key);
        cur = cur -> next;
        isf = 0;
    }
    printf("\n");
}

void deleteNode(NodePointer t){
    
    if(t == nil) return;
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
    
}

void deleteFirst(){
    NodePointer t = nil -> next;
    if(t == nil) return;
    deleteNode(t);
}

void deleteLast(){
    
    deleteNode(nil -> prev);
}

void delete(int key){
    
    deleteNode(listSearch(key));
}


void insert(int key){
    NodePointer x;
    
    x = malloc(sizeof(struct node));
    x -> key = key;
    x -> next = nil -> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
    
}

int main(){
    int key,n,i;
    
    int size = 0;
    char com[20];
    int np = 0,nd = 0;
    
    scanf("%d",&n);
    
    init();
    
    for(i = 0;i < n;i++){
        scanf("%s%d",com,&key);
        
        if(com[0] == 'i'){insert(key);np++;size++;}
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }
            else{
                delete(key);
                nd++;
            }
            size--;
        }
    }
    
    printList();
    return 0;
}


Measured memory_bytes: 33040
import collections
def main():
  N, K = map(int, input().split())
  A =list(map(int, input().split()))
  LA = list(collections.Counter(A).values())
  LA.sort(reverse = True)
  Ans = N-sum(LA[0:K])
  if Ans > 0:
    print(Ans)
  else:
    print(0)

main()

Measured memory_bytes: 32564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N, M, X;
int C[20];
int A[20][20];
int ans = INF;

int main() {
    cin >> N >> M >> X;
    rep(i, N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }
    rep(i, beki(2, N)) {
        //bitでOnOffみる
        int tmp = 0;
        int a[20] = {};
        rep(j, N) {
            //bit調べる
            if (i >> j & 1) {
                tmp += C[j];
                rep(k, M) {
                    //立ってたらお金と能力加算
                    a[k] += A[j][k];
                }
            }
        }
        rep(j, M) {
            //能力足りてるかみる
            if (a[j] < X) break;
            if (j == M - 1) {
                ans = min(ans, tmp);
            }
        }
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, f, ans[310];
vector<ll> r, b;

bool solve(int key) { //条件判定
	cout << "?";
	FOR(i, key, key + n) {
		cout << " " << i + 1;
	}
	cout << endl;
	string res;
	ll a = 0;
	cin >> res;
	if (res == "Blue")a = 1;
	return (f != a);
}

int nibutan() { //めぐる式

	int ng = 0; //最大値ならs.size()
	int ok = n; // 最大値なら0

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (solve(mid)) ok = mid;
		else ng = mid;
	}
	return ok; //満たさない最大ならng
}

int main() {
	cin >> n;
	cout << "?";
	REPO(i, n) {
		cout << " " << i;
	}
	cout << endl;
	string res;
	cin >> res;
	if (res == "Blue")f = 1;
	ll st = nibutan();
	REP(i, n * 2) {
		if (i < st or st + n - 1 <= i) {
			cout << "?";
			cout << " " << i + 1;
			FOR(j, st, st + n - 1) {
				cout << " " << j + 1;
			}
			cout << endl;
			cin >> res;
			if (res == "Blue") {
				ans[i] = 1;
				b.push_back(i);
			}
			else {
				r.push_back(i);
			}
		}
	}
	FOR(i, st, st + n - 1) {
		cout << "?";
		cout << " " << i + 1;
		REP(i, n / 2)cout << " " << r[i] + 1;
		REP(i, n / 2)cout << " " << b[i] + 1;
		cout << endl;
		cin >> res;
		if (res == "Blue") {
			ans[i] = 1;
		}
	}
	cout << "! ";
	REP(i, 2 * n) {
		if (ans[i] == 0)cout << "R";
		else cout << "B";
	}
	cout << endl;
}


Measured memory_bytes: 724
N = int(input())
i = 0
cou = 0
flag = 0
list1 = list(map(int,input().split()))
while True:
 for i in range(0,N):
  if int(list1[i]) % 2 == 0:
   flag += 1
 if flag == N:
  cou += 1
  list1  = list(map(lambda num:int(num/2) , list1))
  flag = 0
 else:
  break
print(cou)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

void bubbleSort(vector<int> data) {
  int n = data.size();
  int cnt = 0;
  for (int i = 0; i < n; i++) { // i: 未ソート部分の先頭
    for (int j = n-1; j > i; j--) {
      if (data[j] < data[j-1]) {
        std::swap(data[j], data[j-1]);
        cnt++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << data[i] << (i == n-1 ? "\n" : " ");
  }
  cout << cnt << endl;
}

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

  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }

  bubbleSort(data);

  return 0;
}



Measured memory_bytes: 3164
#include<iostream>
using namespace std;
int main()
{
    int x,y,sum=0;
    cin>>x>>y;
    while(y--){
        int temp;
        cin>>temp;
        sum+=temp;
    }
    if(sum>=x) cout<< "Yes\n";
    else cout<< "No\n";

    return 0;
}


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


string S, T;

int main(){
	cin >> S >> T;
	int len = S.length();
	
	string SS = S + S;
	
	vector<bool> valid_char(26);
	vector<int> addpos[26];  // 現在位置posで次の文字がcの場合、次の位置は pos+addpos[c][pos]
	
	for ( int c = 0; c < 26; c++ ){
		addpos[c].resize(len);
		int lastpos = 0;
		for ( int i = 0; i < len*2; i++ ){
			if ( SS[i]-'a' == c ){
				valid_char[c] = true;
				
				for ( int j = lastpos; j < i; j++ ){
					addpos[c][j%len] = (i-j+(len-1))%len+1;
				}
				lastpos = i;
				if ( i >= len )
					break;
			}
		}
		//if ( valid_char[c] ){
		//	cout << c << endl;
		//	for ( auto it : addpos[c] )
		//		cout << it << " ";
		//	cout << endl;
		//}
	}
	
	ll ct = -1;
	ll pos = len-1;
	
	for ( size_t j = 0; j < T.length(); j++ ){
		int c = T[j]-'a';
		if ( valid_char[c] ){
			pos += addpos[c][pos];
			if ( pos >= len ){
				pos -= len;
				ct++;
			}
		}
		else {
			cout << "-1" << endl;
			return 0;
		}
	}
	

	cout << (ct*len+pos+1) << endl;
	
	return 0;
}



Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define N 10001
#define M 501
using namespace std;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
typedef long long ll;
string A,B,C;

ll calc(ll idx1,ll sameA,ll sameB){
  static int mem[N][2][2],used[N][2][2]={};
  if(idx1 == (int)A.size()) return 1;
  if(used[idx1][sameA][sameB]++) return mem[idx1][sameA][sameB];
  ll res = 0;
  for(ll i='0';i<='9';i++){
    if(sameA && i < A[idx1]) continue;
    if(sameB && i > B[idx1]) continue;
    ll nidx1 = idx1+1;
    ll nA = sameA & (i == A[idx1]);
    ll nB = sameB & (i == B[idx1]);      
    res = (res + calc(nidx1,nA,nB))%mod;
  }
  return mem[idx1][sameA][sameB] = res;
}

typedef pair<int,int> P;
typedef pair<P,P> PP;
map<PP,int> mem[N];
ll dfs(ll idx1,ll idx2,ll sameA,ll sameB,ll ok){
  PP p = PP(P(idx2,sameA),P(sameB,ok));
  if(idx1 == (int)A.size()) return 0;
  if(mem[idx1].count(p)) return mem[idx1][p];

  ll res = 0;
  for(ll i='0';i<='9';i++){
    if(sameA && i < A[idx1]) continue;
    if(sameB && i > B[idx1]) continue;
    if(idx2 && C[idx2] != i) continue;
    ll nidx1 = idx1+1;
    ll nidx2 = C[idx2] == i? idx2+1:0;
    ll nA = sameA & (i == A[idx1]);
    ll nB = sameB & (i == B[idx1]);      
    ll nok = ok | (i != '0');
    if(nidx2 == (int)C.size()) res = (res + nok*calc(nidx1,nA,nB)) % mod;
    else res = (res + dfs(nidx1,nidx2,nA,nB,nok))%mod;
    if(nidx2 == 1) res = (res + dfs(nidx1,0,nA,nB,nok))%mod;
  }
  if(idx2 <= 1) mem[idx1][p] = res % mod;
  return res % mod;
}

signed main(){
  cin>>A>>B>>C;
  A = string(B.size()-A.size(),'0') + A;
  cout<<(dfs(0,0,1,1,0) + (A == string(A.size(),'0') && C == "0"))%mod<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T.at(i);
  }
  
  int ret = 0, tmp_ret = 0;
  string tmp_str;
  for (int i = 0; i < S.size(); i++) {
    tmp_ret = 0;
    tmp_str = S.at(i);
    for (int j = 0; j < S.size(); j++) {
      if (tmp_str == S.at(j)) {
        tmp_ret++;
      }
    }
    for (int j = 0; j < T.size(); j++) {
      if (tmp_str == T.at(j)) {
        tmp_ret--;
      }
    }
    ret = max(ret, tmp_ret);
  }
  cout << ret << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define int long long
#define maxn 200000
#define inf 1000000000000
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;
vector<vector<bool>> s(10, vector <bool>(1000));

int h, w, k;

int check(vector <vector<int>> val){
	int n = val.size(), m = val[0].size();
	int ans = 0;
	vector <vector<int>> sum(n, vector <int> (m));

	for(int j = 0; j < m; j++){
		bool ok = 1;
		for(int i = 0; i < n; i++){
			if(val[i][j] > k) return inf;
			sum[i][j] = (j? sum[i][j - 1] + val[i][j]: val[i][j]);
			ok &= (sum[i][j] <= k);
		}

		if(!ok){
			ans++;
			for(int i = 0; i < n; i++) sum[i][j] = val[i][j];
		}
	}

	return ans;
}
signed main()
{
	//FILEIO
	FLASH
	cin>>h>>w>>k;

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char c;
			cin>>c;
			s[i][j] = (c == '1');
		}
	}
	int ans = inf;
	
	for(int i = 0; i < 1<<(h - 1); i++){
		int mask = i;
		vector<vector<int>> pref;
		vector<int> temp(w);
		for(int x = 0; x < h; x++){
			for(int y = 0; y < w; y++)
				temp[y] += s[x][y];
			
			if(mask>>x&1){
				pref.push_back(temp);
				temp.clear();
				temp.resize(w, 0);
			}
		}
		pref.push_back(temp);

		int t = check(pref) + (__builtin_popcount(mask));
		ans = min(ans, t);
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 548
#include <cstdio>


int W, H;
char Maps[120][120];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
void dfs(int x, int y);
int ans;

int main(void) {
    while (scanf("%d %d", &H, &W)!=EOF) {
        getchar();
        if (H*W==0) break;
        
        for (int i = 0; i<H; i++)
            scanf("%s", Maps[i]);
        
        for (int i = 0; i<H; i++)
            for (int j = 0; j<W; j++)
                if (Maps[i][j]!=' ') {
                    dfs(i, j);
                    ans++;
                }
        
        printf("%d\n", ans);
        ans = 0;
    }
    return 0;
}

void dfs(int x, int y) {
    char tmp = Maps[x][y];
    Maps[x][y] = ' ';
    for (int i = 0; i<4; i++) {
        int nx = x+dx[i], ny = y+dy[i];
        if (nx>=0 && nx<H && ny>=0 && ny<W && Maps[nx][ny]==tmp) dfs(nx, ny);
    }
}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define pb push_back
#define gcd __gcd
#define vii vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
typedef long long  ll;
typedef pair<int,int> pii;
 
ll bpow(ll a, ll b) {
	a=a; ll res = 1;
    while(b){
        if (b & 1)
        res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
int32_t main()
{	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	ll test=1;
//	cin>>test;
	while(test--)
	{
		ll n; cin>>n;
		ll a[n]; 
		f(i,0,n) cin>>a[i];
		sort(a,a+n,greater<ll>());
		ll ans=0;
		ans+=a[0];
		int j=1;
		for(int i=2;i<n;i+=2)
		{	
			ans+=a[j];
			if(i+1<n)
			ans+=a[j];
			
			j++;
		}
		cout<<ans<<nl;
		
	}
return 0;
}

Measured memory_bytes: 5168
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    int N;
    cin >> N;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    map<char, int> mp;
    vector<char> a(N);
    rep(i, 0, N) {
        char a;
        cin >> a;
        mp[a]++;
    }
    if (mp.size() == 3) {
    cout << "Three" << endl;
    } else {
    cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

ll A[200010];

int main(){
    ll N;
    cin >> N;
    map<ll,ll> mp1,mp2;
    rep(i,N){
        cin >> A[i];
        mp1[A[i] - i]++;
    }
    ll ans = 0;
    rep(i,N){
        mp1[A[i]-1]--;
        ans += mp1[-A[i]-i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 38020
/*
  Contest 087
  A - Buying Sweets
  Rakesh Kumar --> 18/09/2020
 */

#include <bits/stdc++.h>

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

    int x = 0, a = 0, b = 0;
    std::cin >> x >> a >> b;
    std::cout << x - a - (b * ((x - a) / b)) << std::endl;

    return 0;
}


Measured memory_bytes: 3592
import sys
from bisect import bisect_left, insort_right

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    colors = []
    for a in A:
        idx = bisect_left(colors, a)
        if idx != 0:
            colors.pop(idx - 1)
        insort_right(colors, a)

    ans = len(colors)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13616
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
int k,n,a[N*2];

int main(){
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) a[n+i]=a[i];
	int ans=a[n]-a[1];
	for(int i=2;i<n;i++){
		int len1=k-a[i]+a[i-1];
		int len2=a[i]+k-a[i+1];
		ans=min(ans,min(len1,len2));
	}
	printf("%d\n",ans);
	return 0;
}

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


int main() {
    int N;
    cin >> N;
    while (true) {
        if (N%111 == 0) {
            break;
        }
        N++;
    }
    cout << N << endl;
}



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

main(){
  int n,i,j,ans=0;
  cin >> n;
  int d[n];
  for(i=0;i<n;i++) cin >> d[i];
  
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      ans += d[i]*d[j];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
/* ex6_2
   moka223711 */

#include <stdio.h>
#include <string.h>
#define SIZE 101 // 文字数制限が100なので配列の大きさは100+1

int main(void){
    char str[SIZE];
    int len;
    scanf("%s", str);
    // strlen()は文字列の長さを返す
    len = strlen(str);
    
    // 文字列の最初の文字 str[0]
    // 文字列の長さから最初の文字と最後の文字を抜いた len-2
    // 文字列の最後の文字 str[len-1]  をそれぞれ出力
    printf("%c%d%c", str[0], len-2, str[len-1]);
    return 0;
}


Measured memory_bytes: 128
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

type job struct {
	duration int
	limit    int
}
type jobs []job

func (a jobs) Len() int           { return len(a) }
func (a jobs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a jobs) Less(i, j int) bool { return a[i].limit < a[j].limit }

func canFinish(js jobs) bool {
	sort.Sort(js)
	passed := 0
	for _, j := range js {
		passed += j.duration
		if passed > j.limit {
			return false
		}
	}
	return true
}

func main() {
	n := nextInt()
	jobs := make(jobs, n)
	for i := 0; i < n; i++ {
		jobs[i] = job{nextInt(), nextInt()}
	}
	if canFinish(jobs) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main() {
	string S; cin >> S;
	int s=0;
	for(char k : S){
		string K = "";
		K += k;
		s += stoi(K);
	}
	if(stoi(S)%s == 0){
		cout << "Yes" << endl;
	} else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
n,a,b,c,d = gets.split.map(&:to_i)
s = gets.chomp

ans = 'No'
if c<d
  if !s[(a-1)..(c-1)].match(/\#\#/) && !s[(b-1)..(d-1)].match(/\#\#/)
    ans = 'Yes'
  end
else
  if s[(b-2)..d].match(/\.\.\./) && !s[(a-1)..(c-1)].match(/\#\#/)
    ans = 'Yes'
  end
end

puts ans

Measured memory_bytes: 2428
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, H, W; cin >> N >> H >> W;
	cout << (N - H + 1)*(N - W + 1) << endl;
	cin >> N;
}

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

using namespace std;

#define inf 1000000000

int n,m;
int C[101][101];
int T[101][101];

class S{
	public:
	int iti,now;
	S(){}
	S(int a,int b){iti=a;now=b;}
	bool operator < (const S &a)const{
		return now>a.now;
	}
};
int dike(int st,int en,int va){
	priority_queue<S> state;
	int sima[101];
	int visit[101]={0};
	for(int i=0;i<101;i++){
		sima[i]=inf;
		visit[i]=0;
	}
	state.push(S(st,0));
	sima[st]=0;
	while(1){
		S u;
		u=state.top();
		state.pop();
		visit[u.iti]=1;
		if(u.iti==en){
			return u.now;
		}
		
		for(int i=1;i<=m;i++){
			if(C[u.iti][i]==inf||visit[i]==1){
				continue;
			}
				int cost=C[u.iti][i];
				if(va==1){
					cost=T[u.iti][i];
				}
			if(sima[u.iti]+cost < sima[i]){
				sima[i]=sima[u.iti]+cost;
				state.push(S(i,sima[i]));
			}
		}
	}
}

int main(){
	while(1){
		cin>>n>>m;
		if(n==0)break;
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				C[i][j]=inf;
				T[i][j]=inf;
			}
		}
		for(int i=0;i<n;i++){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			C[a][b]=C[b][a]=c;
			T[a][b]=T[b][a]=d;
		}
		
		int l;
		cin>>l;
		for(int i=0;i<l;i++){
			int a,b,c;
			cin>>a>>b>>c;
			printf("%d\n",dike(a,b,c));
		}
	}
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define outi(a) printf("%lld\n",(a))
using namespace std;
ll read()
{
  char c = getchar();
  while((c < '0' || c > '9') && c != '-')
  c = getchar();
  ll isk = 1;
  if(c == '-') isk = -1,c = getchar();
  ll sum = 0;
  while(c >= '0' && c <= '9')
  sum = sum*10 + c - '0', c = getchar();
  return sum*isk;
}
int cnt = 0;

void distance(int *arr, int *arr2, int dim)
{
  double sum = 0;
  rep(i,dim) sum += pow(abs(arr[i]-arr2[i]), 2);
  double root = sqrt(sum);
  if(root == floor(root))
  cnt++;
}

int lrr[99999999] = {0};
int main()
{
  //freopen("input.txt", "r", stdin);
  int a = read(), dim = read();
  int arr[a][dim];
  rep(i,a) rep(j,dim) arr[i][j] = read();
  rep(i,a) FOR(j, i+1, a)
  {
    distance(arr[i],arr[j], dim);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int d,n;
	cin>>d>>n;
	if(d==2&&n==100) cout<<1010000;
	else if(d==1&&n==100) cout<<10100;
	else if(d==0&&n==100) cout<<101;
	else 
	{
		cout<<n;
		if(d) for(int i=1;i<=(1<<d);i++) cout<<0;
	}


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder
{
	public class Program
	{
		// ABC109-C
		static void Main(string[] args)
		{
			string[] vs = Console.ReadLine().Split();
			int N = int.Parse(vs[0]);   // 個数
			int X = int.Parse(vs[1]);   // 開始位置
			int[] d = new int[N];       // 各都市絶対距離
			int dMin = int.MaxValue;
			vs = Console.ReadLine().Split();
			for (int i = 0; i < N; i++) {
				d[i] = Math.Abs(int.Parse(vs[i]) - X);
				dMin = Math.Min(dMin, d[i]);
			}
			for (int i = dMin; i > 0; i--) {
				bool f = true;
				foreach (var j in d) {
					if (j % i !=0) {
						f = false;
						break;
					}
				}
				if (f) {
					Console.WriteLine(i);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 18400
h, w, m = gets.split.map(&:to_i)
rows = Array.new(h+1, 0)
cols = Array.new(w+1, 0)
nodes = []
m.times do
  nh, nw = gets.split.map(&:to_i)
  nodes << [nh, nw]
  rows[nh] += 1
  cols[nw] += 1
end
rmax = rows.max
rcount = rows.count(rmax)
cmax = cols.max
ccount = cols.count(cmax)

if rcount * ccount > nodes.count{ rows[_1] == rmax && cols[_2] == cmax }
  puts rmax + cmax
else
  puts rmax + cmax - 1
end


Measured memory_bytes: 40356
# coding:UTF-8

cnt = int(input())
musics = {}
titles = []
seconds = []

for i in range(0, cnt):
    title, second = input().split()
    second = int(second)
    titles.append(title)
    seconds.append(second)
    musics[title] = second

ind = titles.index(input())
print(sum(seconds[ind + 1:]))


Measured memory_bytes: 3060
#!/usr/bin/env python
import sys
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())

    #N, Q = map(int, input().split())

    N = int(input())

    print(N*(N-1)//2)


if __name__ == '__main__':
    main()


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

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a < c&&c < b)puts("Yes");
	else if (b < c&&c < a)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 n, k;
vector<int> a, f;

//誤読に注意

//最大値の最小値だからにぶたんじゃん！！

bool check(int x) {
    //全てx以下にすることが可能か？
    vector<int> c(n);
    rep(i, n) {
        c[i] = x / f[i];
        //食べ物のコストは変化しない
    }
    //必要な修行回数がk回以下かをみればok
    int cnt = 0;
    rep(i, n) {
        if(a[i] <= c[i]) continue;
        else {
            cnt += a[i] - c[i];
        }
    }
    if(cnt <= k) {
        return true;
    } else {
        return false;
    }
}

void solve() {
	cin >> n >> k;
    a.resize(n);
    f.resize(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> f[i];
    }
    sort(all(f));
    reverse(all(f));
    sort(all(a));
    int ok = INF, ng = -1;
    while(ok - ng > 1) {
        int mid = (ok + ng) / 2;
        if(check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 4992
using System.Collections.Generic;
using static System.Console;

namespace AtCoder.BeginnersSelections
{
    class C_EnergyDrinkCollector
    {
        static void Main(string[] args)
        {
            WriteLine(Solve());
        }

        static long Solve()
        {
            var s = ReadLine();
            var queue = new Queue<char>();
            for (int i = 0; i < s.Length; i++)
            {
                if (queue.Count > 0 && queue.Peek() != s[i])
                    queue.Dequeue();
                else
                    queue.Enqueue(s[i]);
            }
            return s.Length - queue.Count;
        }
    }
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	char mp[128];
	rep(i, 'A', 'Z' + 1) mp[i] = 5;
	mp['M'] = 0, mp['A'] = 1, mp['R'] = 2, mp['C'] = 3, mp['H'] = 4;
	int cnt[6] = {0, 0, 0, 0, 0, 0};

	int n; cin >> n;
	rep(i, 0, n) {
		string s; cin >> s;
		cnt[mp[s[0]]]++;
	}
	ll ans = 0;
	rep(i, 0, 5) rep(j, i + 1, 5) rep(k, j + 1, 5) ans += 1ll * cnt[i] * cnt[j] * cnt[k];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int n; cin >> n;
    string s; cin >> s;
    if (s.substr(0, n/2) == s.substr(n/2)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,d,p,taxa,taxb;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
	//printf("%d %d %d %d %d\n",a,b,c,d,p);
	taxa=a*p;
	if(c>=p){
		taxb=b;
	}else if(c<p){
		taxb=b+(p-c)*d;
	}
	if(taxa<=taxb){
		printf("%d\n",taxa);
	}else{
		printf("%d\n",taxb);
	}
	return 0;
}

Measured memory_bytes: 1024
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    vector<bool> furui(555551, true);
    // 前の方を先に埋めておくと劇的に早くなるはず。
    furui[0] = false;
    furui[1] = false;
    for (int i = 2; i < furui.size(); i++) {
        if (furui[i]) {
            for (int j = 2 * i; j < furui.size(); j += i) {
                furui[j] = false;
            }
        }
    }
    vector<int> primes;
    for (int i = 2; i < furui.size(); i++) {
        if (furui[i] && i % 5 == 1) {
            primes.push_back(i);
        }
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cout << primes[i];
        if (i < N - 1) {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 1016
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int INF = INT_MAX;

struct Edge {
  int to;
  int cap;
  int rev;

  Edge(int to = -1, int cap = -1, int rev = -1) {
    this->to = to;
    this->cap = cap;
    this->rev = rev;
  }
};

const int MAX_V = 20000;
bool used[MAX_V];
int H, W;
vector <Edge> G[MAX_V];

void add_edge(int from, int to, int cap) {
  int D = H * W;
  if (from == to) {
    to += D;
  } else {
    from += D;
  }
  G[from].push_back(Edge(to, cap, G[to].size()));
  G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

int dfs(int v, int t, int f) {
  if (v == t) return f;

  used[v] = true;

  for (int i = 0; i < G[v].size(); ++i) {
    Edge *e = &G[v][i];

    if (!used[e->to] && e->cap > 0) {
      int d = dfs(e->to, t, min(f, e->cap));
      if (d > 0) {
        e->cap -= d;
        G[e->to][e->rev].cap += d;
        return d;
      }
    }
  }

  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    memset(used, false, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

int main() {
  cin >> H >> W;
  char grid[H][W];
  int sy, sx, ty, tx;

  char c;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      cin >> c;

      if (c == 'S') {
        sy = y;
        sx = x;
      }

      if (c == 'T') {
        ty = y;
        tx = x;
      }

      grid[y][x] = c;
    }
  }

  if (sy == ty || sx == tx) {
    cout << -1 << endl;
    return 0;
  }

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      if (grid[y][x] == '.') continue;
      // if (grid[y][x] == 'T') continue;

      int v = y * W + x;
      add_edge(v, v, 1);

      for (int y2 = 0; y2 < H; ++y2) {
        int u = y2 * W + x;

        if (v == u) continue;
        if (grid[y2][x] == '.') continue;

        add_edge(v, u, 1);
      }

      for (int x2 = 0; x2 < W; ++x2) {
        int u = y * W + x2;

        if (v == u) continue;
        if (grid[y][x2] == '.') continue;

        add_edge(v, u, 1);
      }
    }
  }

  int D = H * W;
  fprintf(stderr, "(%d, %d) -> (%d, %d)\n", sy, sx, ty, tx);
  cout << max_flow(sy * W + sx + D, ty * W + tx) << endl;

  return 0;
}


Measured memory_bytes: 64000
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==1 && b==2 || a==2 && b==1)
        printf("3\n");
    else if(a==2 && b==3 || a==3 && b==2)
        printf("1\n");
        else
            printf("2\n");

    return 0;
}


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

using ll = long long;

int const N = 200005;

int main() {
	int n;
	std::cin >> n;
	std::vector<std::pair<int, int> > a(n);
	std::vector<int> tot;
	for(int i = 0; i < n; ++i) {
		std::cin >> a[i].first >> a[i].second;
		tot.push_back(a[i].first);
		tot.push_back(a[i].second);
	}
	ll sum1 = 0, sum2 = 0;
	for(auto k : a) {
		sum1 += k.first;
		sum2 += k.second;
	}
	ll ans = std::min(sum1, sum2);
	std::sort(tot.begin(), tot.end());
	ll sum = 0;
	for(int i = 0; i < n; ++i) 
		sum += tot[i];
	for(int i = 0; i < n; ++i) {
		int mx = std::max(a[i].first, a[i].second);
		int mi = std::min(a[i].first, a[i].second);
		if(mi > tot[n - 1] || mx < tot[n - 1]) {
			std::cout << sum << '\n';
			return 0;
		}

		ll tmp = sum;
		tmp += mx - tot[n - 1] + std::max(0, mi - tot[n - 2]);
		ans = std::min(ans, tmp);
	}
	std::cout << ans << '\n';
	return 0;
}


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

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

    set<string> prize;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        prize.insert(s);
    }

    cout << prize.size() << endl;
    return 0;
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
const int maxn=3e3+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	x*=f;
}
string s1,s2;
int f[maxn][maxn];
bool book[maxn][maxn][3];
string goal;
void search(int x,int y){
	if(x==0 || y==0) return;
	if(s1[x]==s2[y]){
		goal+=s1[x];
	}
	for(re int k=0;k<3;k++){
		if(book[x][y][k] && k==0) search(x-1,y-1); 
		if(book[x][y][k] && k==1) search(x-1,y); 
		if(book[x][y][k] && k==2) search(x,y-1); 
	}
} 
int main(){
	cin>>s1>>s2;
	s1=' '+s1;
	s2=' '+s2;
	for(re int i=1;i<s1.size();i++){
		for(re int j=1;j<s2.size();j++){
			if(s1[i]==s2[j]){
				f[i][j]=f[i-1][j-1]+1;
				book[i][j][0]=true;
			}
			else if(f[i-1][j]>f[i][j-1]){
				f[i][j]=f[i-1][j];
				book[i][j][1]=true;
			}
			else{
				f[i][j]=f[i][j-1];
				book[i][j][2]=true;
			}
		}
	}
	/*for(re int i=1;i<s1.size();i++){
		for(re int j=1;j<s2.size();j++){
			cout<<f[i][j]<<" ";
		} 
		cout<<endl;
	}*/
	search(s1.size()-1,s2.size()-1); 
	for(re int i=goal.size()-1;i>=0;i--){
		cout<<goal[i];
	}
	cout<<endl;
	return 0;

}

Measured memory_bytes: 62336
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/12.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> numList = new ArrayList<>();
        while (true) {
            int i = scanner.nextInt();
            if (i == 0) {
                break;
            } else {
                numList.add(i);
            }
        }
        for (int i = 0; i < numList.size(); i++) {
            System.out.println("Case " + (i + 1) + ": " + numList.get(i));
        }
    }
}

Measured memory_bytes: 43944
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll sm1 = 0;
    ll sm2 = 0;
    ll res1 = 0;
    ll res2 = 0;
    rep(i, n) {
        sm1 += a[i];
        sm2 += a[i];
        if (i % 2 == 0) {
            if (sm1 <= 0) {
                res1 += -sm1 + 1;
                sm1 = 1;
            }
            if (sm2 >= 0) {
                res2 += sm2 + 1;
                sm2 = -1;
            }
        } else {
            if (sm1 >= 0) {
                res1 += sm1 + 1;
                sm1 = -1;
            }
            if (sm2 <= 0) {
                res2 += -sm2 + 1;
                sm2 = 1;
            }
        }
    }
    cout << min(res1, res2) << endl;
}


Measured memory_bytes: 1024
N, Y = map(int, input().split())

for i in range(N+1):
    for j in range(N-i+1):
        if i*10000 + 5000*j + (N-i-j)*1000 == Y:
            print(i, j, N-i-j)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
from collections import defaultdict

N=int(input())
*A,=map(int,input().split())
mod = 10**9+7

count = defaultdict(int)
count[0] = 3

ans = 1
for i in range(N):
  ans *= count[A[i]]
  ans %= mod
  count[A[i]] -= 1
  count[A[i]+1] += 1
  
print(ans)

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

int main(){
  string x,y;
  cin >> x >> y;
  int w = stoi(x+y);
  cerr << w << endl;
  
  bool flg = false;
  for(int i = sqrt(w); i <= sqrt(w)+w; i++){
    if ( i * i == w){
      flg = true;
      break;
    }
  }
  if(flg){
    cout << "Yes" << endl;
  } else { 
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	string s, t;
	cin >> s >> t;

	string st;
	rep(i, n){
		st += s[i];
		st += t[i];
	}
	co(st);

	return 0;
}


Measured memory_bytes: 256