akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP){ 
    return firstP.second < secondP.second; 
}//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll a,b,c,d,e,f;
double tmp;
Pair ans;
bool dp[10000][10000];

bool dfs(ll s,ll w){
    if(dp[s][w])return false;
    dp[s][w]=true;
    if(s+w*100>f)return false;
    if(s<=w*e)if(chmax(tmp,(double)((double)s/(double)(w*100+s)))){
        ans.first = s; ans.second = w;
    }
    dfs(s+c,w);
    dfs(s+d,w);
    dfs(s,w+a);
    dfs(s,w+b);
    return true;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>a>>b>>c>>d>>e>>f;
    fill(dp,false);
    tmp = 0.0;
    dfs(0,0);
    cout<<ans.first+ans.second*100<<" "<<ans.first<<endl;
    return 0;
}

Measured memory_bytes: 97920
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()


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

int main(){
    string s;
    cin >> s;
    int win = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'o'){
            win++;
        }
    }
    string result = win + (15 - s.length()) >= 8 ? "YES" : "NO";
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    int n, tl;
    cin >> n >> tl;
    int c[n], t[n];
    for (int i=0; i < n; i++){
        cin >> c[i] >> t[i];
    }

    int cmin = 1001;
    for (int i=0; i < n; i++){
        if (c[i] < cmin && t[i] <= tl){
            cmin = c[i];
        }
    }


    if (cmin == 1001){
        cout << "TLE" << endl;
    }
    else {
        cout << cmin << endl;
    }



    return 0;
}




//              g++ -std=c++1z  

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

int main() {
  string S, T;
  cin >> S >> T;
  int S_size = S.size();
  int T_size = T.size();
  int mx_count = -1;

  if(S_size == T_size) {
    int count = 0;
    for(int i = 0; i < S_size; i++)
        if(S[i] == T[i])
            count++;
    mx_count = max(mx_count, count);
  }
  else {
    for(int i = 0; i < S_size - T_size; i++) {
        int count = 0;
        for(int j = 0; j < T_size; j++)
          if(S[j+i] == T[j])
            count++;
        mx_count = max(mx_count, count);
    }
  }

  int ans = T_size - mx_count;
  cout << ans << endl;
}

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

int main() 
{
	string str;
	cin >> str;
	
	int n = str.length(), ans = 0;
	vector <int> a;
	int temp = 1;
	for (int i = 1; i < n; i++)
		if (str[i] == str[i - 1]) temp++;
		else {a.push_back(temp); temp = 1;}
	a.push_back(temp);
	
	for (int i = 1; i < a.size(); i++)
	{
		int x = min(a[i], a[i - 1]);
		ans += 2*x;
		a[i] -= x;
		a[i - 1] -= x;
		if (!a[i] && i < a.size() - 1) a[i + 1] += a[i - 1];
	}
	
	cout << ans;
}

Measured memory_bytes: 1020
a, b, K = gets.split.map(&:to_i)

player, opponent = a, b
K.times do |k|
  if player.odd?
    player -= 1
  end
  player /= 2
  opponent += player
  player, opponent = opponent, player
end
a, b = if K.even?
         [player, opponent]
       else
         [opponent, player]
       end
puts "#{a} #{b}"


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

using namespace std;

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

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  sort(a, a+n);
  
  int s = 0;
  rep(i,n) rep(j0,n-i-1) {
    int j = j0 + i + 1;
    int t = lower_bound(a+j+1, a+n, a[i]+a[j]) - a-j-1;
    s += t;
  }
  
  cout << s << endl;
  return 0;
}

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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string s[8] = {"MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string t;
    cin >> t;
    if (t == "SUN") {
        cout << 7;
        return 0;
    }
    int ans;
    for (int i = 0; i < 8; i++) {
        if (s[i] == t) {
            cout << 6 - i;
            return 0;
        }
    }
}

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

signed main(){
  int A,B;
  cin>>A>>B;
  int ans=0;
  if(A>B)ans=A+A-1;
  if(A==B)ans=A+B;
  if(A<B)ans=B+B-1;
  cout<<ans<<endl;
}

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

int main(void){
    string s;
    int i;
    int even;
    string s1, s2;
    bool flug = false;
    
    cin >> s;
    
    even = (s.length() % 2 == 0) ? 1 : 0;
    
    if(even){
        for(i = s.length() - 2; i > 0; i -= 2){
            s1 = s.substr(0, i / 2);
            s2 = s.substr(i / 2, i / 2);
            if(s1 == s2){
                flug = true;
                break;
            }
        }
    }
    else{
        for(i = s.length() - 1; i > 0; i -= 2){
            s1 = s.substr(0, i / 2);
            s2 = s.substr(i / 2, i / 2);
            if(s1 == s2){
                flug = true;
                break;
            }
        }
    }
    
    if(flug)        cout << i << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int H, W;
  char c[31][31];
  int max = 0;

  cin >> H >> W;

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> c[i][j];
    }   
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(c[i][j] == 'B') {
        for(int k = 0; k < H; k++) {
          for(int l = 0; l < W; l++){
            if(c[k][l] == 'B') {
              int temp = abs(i - k) + abs(j - l);
	      if(temp > max) max = temp;
            }
          }
        }
      }
    }
  }
  cout << max << endl;
  return 0;
}



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

int n, ans;
int main() {
	cin>>n;
	if(n <= 9) ans = n;
	else if(n <= 99) ans = 9;
	else if(n <= 999) ans = n-99 + 9;
	else if(n <= 9999) ans = 909;
	else if(n <= 99999) ans = n-9999 + 909;
	else ans = 90909;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N,K;
int A[51];

signed main(){
	int sum=0;
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	int ans=-INF;
	vector<int> V;
	REP(k,K+1){
		REP(i,N+1){
			REP(j,N+1){//左からi個、右からj個とる
				int num=0;
				if(i+j<(k+1)/2)continue;
				if(i+j>k)continue;
				V.clear();
				if(i+j>N){
					REP(l,N){
						V.push_back(A[l]);
					}
				}
				else{
					REP(l,i){
						V.push_back(A[l]);
					}
					REP(l,j){
						V.push_back(A[N-1-l]);
					}
				}
				REP(l,V.size()){
					num+=V[l];
				}
				sort(V.begin(),V.end());
				int p=k-i-j;
				REP(l,p){
					num-=V[l];
				}
				ans=max(ans,num);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	map<int,bool> memo;
	int a;
	int i=1;

	cin >> a;
	do{
		memo[a]=true;
		if(a%2==0){
			a=a/2;
		}else{
			a=3*a+1;
		}
		i++;
	}while(!memo[a]);

	cout << i << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;

int a[110][110];

void prt(int row,int color,int count)
{
    for(int i=row; i<row+50; i+=2)
        for(int j=0; j<100; j+=2)
        {
            if(count)
            {
                a[i][j] = color;
                count--;
            }
            else
                return;
        }
    return ;
}

int main()
{
    IO;
    cout<<"100 100"<<endl;
    int aa,bb;
    cin>>aa>>bb;
    --aa,--bb;
    for(int i=50; i<100; i++)
        for(int j=0; j<100; j++)
            a[i][j] = 1;
    prt(0,1,aa);
    prt(51,0,bb);
    for(int i=0; i<100; i++)
    {
        for(int j=0; j<100; j++)
            if(!a[i][j])
                cout<<"#";
            else
                cout<<".";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
int main(void){
    int n,k;cin>>n>>k;
    int tmp;
    int cnt = 0;
    rep(i,n){cin>>tmp;if(tmp>=k)cnt++;}
    co(cnt);
}



Measured memory_bytes: 256
//  __/\\\\____________/\\\\______/\\\\\\\\\______/\\\________/\\\___/\\\\\\\\/\\____/\\\\\\\\\\_|
//   _\/\\\\\\________/\\\\\\____/\\\\\\\\\\\\\___\/\\\________/\\\__\/\\\____\/\\\__\////\\\///__|
//    _\/\\\//\\\____/\\\//\\\___/\\\/////////\\\__\/\\\________/\\\__\/\\\____\/\\\\____\/\\\_____|
//     _\/\\\\///\\\/\\\/_\/\\\__\/\\\_______\/\\\__\/\\\\\\\\\\\\\\\__\/\\\____\/\\\\____\/\\\_____|
//      _\/\\\__\///\\\/___\/\\\__\/\\\\\\\\\\\\\\\__\/\\\/////////\\\__\/\\\____\/\\\\____\/\\\_____|
//       _\/\\\____\///_____\/\\\__\/\\\/////////\\\__\/\\\_______\/\\\__\/\\\____\/\\\_____\/\\\_____|
//        _\/\\\_____________\/\\\__\/\\\_______\/\\\__\/\\\_______\/\\\__\/\\\___/\\\\______\/\\\_____|
//         _\/\\\_____________\/\\\__\/\\\_______\/\\\__\/\\\_______\/\\\__\/\\\\\\/\\_____/\\\\\\\\\\__|
//          _\///______________\///___\///________\///___\///________\///___\/////////_____\//////////___|
#include<bits/stdc++.h>
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< string > vs;
typedef vector< long long > vl;
#define hurry ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define setp setprecision
#define popp pop_back()
#define pb push_back
#define mp make_pair
#define beg begin()
#define end end()
#define sc second
#define sz size()
#define fr first
#define endl '\n'
//=======================================================================================================================
//GLOBAL
ll dp[100002];
ll ans;
//=======================================================================================================================
//FUNCTIONS
//=======================================================================================================================
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min((dp[i-2]+abs(h[i]-h[i-2])),(dp[i-1]+abs(h[i]-h[i-1])));
    }
    cout<<dp[n];
}
//========================================================================================================================


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define EPS (1e-10)
using namespace std;
int main(){
    int n;
    vector<int> p;
    for(int i = 6; i < 300000; i+=5){
        for(int k = 0; k < 2; k++){
            if(k==1)
                i+=2;
            bool f=false;
            //int lim=(int)(sqrt((double)p.size())+EPS);
            for(int j = 0; j <=(int)(sqrt((double)i)+EPS)&&j<p.size(); j++){
                if(i%p[j]==0){
                    f=true;
                    break;
                }
            }
            if(!f){
                p.push_back(i);
            }
        }
    }
    while(cin>>n&&n!=1){
        vector<int> v;
        for(int i = 0; i < p.size(); i++){
            if(n%p[i]==0)
                v.push_back(p[i]);
        }
        cout<<n<<": ";
        for(int i = 0; i < v.size(); i++){
            cout<<v[i];
            if(i==v.size()-1)
                cout<<endl;
            else
                cout<<" ";
        }
    }

    return 0;
}

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

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
        cout << "No" << endl;
    } else if ((s[0] == s[1]) && (s[2] == s[3])) {
        cout << "Yes" << endl;
    } else if ((s[0] == s[2]) && (s[1] == s[3])) {
        cout << "Yes" << endl;
    } else if ((s[0] == s[3]) && (s[1] == s[2])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,i,j,k;
	cin>>n;
	int h[n];
	for(i=0;i<n;i++)cin>>h[i];
	int place=0,ans=0;
	for(i=0;i<n-1;i++){
		if(h[i]<=0)continue;
		for(k=0;k<h[i];k++){
			ans++;
			j=i+1;
			while(1){
				h[j]--;
				if(h[j]<0)break;
				j++;
			}
		}
//		cout<<ans<<endl;
	}
	if(h[n-1]>0)ans+=h[n-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end());
//    l.erase(unique(l.begin(), l.end()), l.end());
//    n = l.size();
    ll ans = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = i + 1; j < n; j++) {
            for(ll k = j + 1; k < n; k++) {
                if(l[i] == l[j]) continue;
                if(l[j] == l[k]) continue;
                if(l[i] + l[j] <= l[k]) continue;
//                cout << l[i] << l[j] << l[k] << endl;
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

using namespace std;

#define INF 1e9

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

    int n;
    cin>>n;

    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a.begin(),a.end());

    long long ans=0;

    for(int i=0;i<n;i++){
        ans+=abs(a[i]-a[n/2]);
    }

    cout<<ans<<endl;
  
}

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

int main(){
	int N,inputs[101],min,sum,X,answer;
	answer = sum = 0;
	min = 10000000;
	
	cin >> N >> X;
	for(int i=0;i<N;i++){
		cin >> inputs[i];
		sum += inputs[i];
		if(inputs[i]<min){
			min = inputs[i];
		}
	}
	
	X -= sum;
	answer += N;
	
	answer += X/min;
	
	cout << answer << endl;;
	
	
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
vector<int>prime;
int main(){
    int ask;
    prime.push_back(1);
    prime.push_back(2);
    for(int i=3;i<10001;i++){
        int t=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                t=0;
                break;
            }
        }
        
        if(t)
            prime.push_back(i);
    }
    while(true){
        cin>>ask;
        if(ask==0)
            break;
        for(int i=ask;i>1;i--){
            if(find(prime.begin(),prime.end(),i)!=prime.end()&&find(prime.begin(),prime.end(),i-2)!=prime.end()){
                cout<<i-2<<" "<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {
    long long A, B, K;
    cin >> A >> B >> K;
    long long a1 = A;
    long long a2 = B;
    long long z = 0;
    a1 = max(z, A-K);
    K = max(z,K-A);
    a2 = max(z, B-K);
    cout << a1 << " " << a2;
}

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<char> > A(N, vector<char>(N));
  vector<vector<char> > B(M, vector<char>(M));
  string tmp;

  for (int i=0; i<N; i++){
    cin >> tmp;
    for (int j=0; j<N; j++){
      A[i][j] = tmp[j];
    }
  }
  for (int i=0; i<M; i++){
    cin >> tmp;
    for (int j=0; j<M; j++){
      B[i][j] = tmp[j];
    }
  }

  int count = 0;
  string flag = "No";
  for (int i=0; i<N-M+1; i++){
    for (int j=0; j<N-M+1; j++){
      count = 0;
      for (int k=0; k<M; k++){
        for (int l=0; l<M; l++){
          if (A[i+k][j+l] == B[k][l]){
            count++;
          }
        }
      }
      if (count == M*M){
        flag = "Yes";
      }
    }
  }
  cout << flag << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef struct{
  char A;
  int value;
}T;

void swap(T *, T *);

int main(){
  int i,j,minj,N;
  int count = 0;
  T C[36],B[36];

  scanf("%d",&N);

  for(i = 0; i < N; i++){
    scanf(" %c%d",&C[i].A,&C[i].value);
    B[i] = C[i];
  }

  for(i = 0; i < N-1; i++){
    for(j = N-1; j > i; j--){
      if(C[j].value < C[j-1].value) swap(&C[j],&C[j-1]);
    }
  }

  for(i = 0; i < N; i++){
    printf("%c%d",C[i].A,C[i].value);
    if(i == N-1) break;
    printf(" ");
  }

  printf("\nStable\n");

  for(i = 0; i < N-1; i++){
    minj = i;
    for(j = i+1; j < N; j++){
      if(B[j].value < B[minj].value) minj = j;
    }
    if(minj != i) swap(&B[i],&B[minj]);
  }

  for(i = 0; i < N; i++){
    printf("%c%d",B[i].A,B[i].value);
    if(B[i].A != C[i].A) count++;
    if(i == N-1) break;
    printf(" ");
  }

  if(count > 0) printf("\nNot stable\n");
  else printf("\nStable\n");

  return 0;

}

void swap(T *X, T *Y){
  T cal;

  cal = *X;
  *X = *Y;
  *Y = cal;
}



Measured memory_bytes: 2048
def dfs(fld, check, n, m, depth)
  n.times do |r|
    m.times do |c|
      if check[r][c] == depth && fld[r][c] == '*'
        q = []
        mem = n.times.map{ [] }
        check[r][c] = depth + 1
        q << [r, c]
        mem[r] << c
        until q.empty?
          r, c = q.shift
          (-1..1).each do |yy|
            (-1..1).each do |xx|
              next if yy == 0 && xx == 0
              y = r + yy; x = c + xx
              if check[y][x] != depth + 1 && fld[y][x] == '*'
                check[y][x] = depth + 1
                q << [y, x]
                mem[y] << x
              end
            end
          end
        end
        a = 0; h = -1
        mem.each_with_index do |m, i|
          if m.size > 2
            a += m.size
            h == -1 ? h = i : h = i - h + 1
          elsif m.size == 2
            m[0], m[1] = m[1], m[0] if m[0] > m[1]
            (m[0]+1...m[1]).each{ |k| check[i][k] = depth + 2 }
          end
        end
        s = a * h / 2
        $ret[s] ||= 0
        $ret[s] += 1
        dfs(fld, check, n, m, depth + 2)
      end
    end
  end
end

l = false
while n = gets.to_i
  break if n == 0
  if l
    10.times{ print '-' }
    puts
  end
  l = true
  fld = n.times.map{ gets.chomp.split('').unshift(' ').push(' ') }
  m = fld.map{ |f| f.size }.max
  fld.each{ |f| (m - f.size).times{ f.push(' ') } }
  fld = [ [' '] * m, *fld, [' '] * m ]
  $ret = {}
  check = (n+2).times.map{ [0] * m }
  dfs(fld, check, n+2, m, 0)
  $ret.sort.each{ |k, v| puts "#{k} #{v}" }
end

Measured memory_bytes: 10200
X = int(input())
dp = [1]+[0]*X
for i in range(X):
  if i+1 < 100: dp[i+1] = 0
  elif i+1 <=105: dp[i+1] = 1
  elif sum([dp[i+1-(100+j)] for j in range(6)])>0: dp[i+1] = 1
  else: dp[i+1] = 0
print(dp[-1])

Measured memory_bytes: 4596
n, m = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(n)]
check = [tuple(map(int, input().split())) for _ in range(m)]

for x, y in student:
    tmp = 10 ** 10
    for i, C in enumerate(check):
        cx, cy = C[0], C[1]
        man = abs(x-cx)+abs(y-cy)
        if tmp > man:
            tmp = man
            ans = i
    print(ans + 1)

Measured memory_bytes: 3064
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
vector<int>sosuu2(100001, 0);
vector<int>sosuu3(100001, 0);
vector<int>sosuu;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	unsigned long long N, M; cin >> N >> M;
	if (abs((int)N - (int)M) >= 2)
	{
		cout << 0 << "\n";
		return 0;
	}
	unsigned long long count = 1;
	unsigned long long const a = 1000000007;
	if (N == M)
	{
		count *= 2;
		for (int i = 1; i <= N; i++)
		{
			count *= i;
			if (count > a)
			{
				count %= a;
			}
		}
		for (int i = 1; i <= M; i++)
		{
			count *= i;
			if (count > a)
			{
				count %= a;
			}
		}
		cout << count << "\n";
	}
	else
	{
		for (int i = 1; i <= N; i++)
		{
			count *= i;
			if (count > a)
			{
				count %= a;
			}
		}
		for (int i = 1; i <= M; i++)
		{
			count *= i;
			if (count > a)
			{
				count %= a;
			}
		}
		cout << count << "\n";
	}

}

Measured memory_bytes: 1024
k = int(input())
alist = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(alist[k-1])

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
# define MAXN 100 

int main(){
  int n, a[MAXN],sum;
  cin >> n;
  for (int i(0);i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  int kouho_1 = sum / n, kouho_2 = sum / n + 1, kouho_3 = sum / n - 1;
  int sum_1(0),sum_2(0),sum_3(0);

  for (int i(0);i < n; i++){
    sum_1 += (kouho_1 - a[i]) * (kouho_1 - a[i]);
    sum_2 += (kouho_2 - a[i]) * (kouho_2 - a[i]);
    sum_3 += (kouho_3 - a[i]) * (kouho_3 - a[i]);
  }
  cout << min(sum_1,min(sum_2,sum_3));
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a,b;
signed main(){
	scanf("%lld",&n);
	while(n--){
		scanf("%lld %lld",&a,&b);
		ll ans=sqrt(a*b);
		if(ans*(ans+1)<a*b) ans=ans*2-1;
		else if(ans*ans==a*b&&a!=b) ans=2*(ans-1)-1;
		else ans=2*(ans-1);
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h){
        cin >> s[i];
    }
    int res = 1e9;
    for(int i = 0;i<(1<<h);i++){
        vector<int> dp(h);
        vector<int> v(h);
        int cnt = 0;
        for(int j = 1;j<h;j++){
            if(i&(1<<j) && (i&(1<<(j-1)))==0){
                cnt++;
            }
            else if ((i & (1 << j))==0 && i & (1 << (j - 1))){
                cnt++;
            }
            v[j]=cnt;
        }
        int ans = cnt;
        for(int j = 0;j<w;j++){
            for(int l = 0;l<h;l++){
                dp[v[l]]+=(s[l][j]-'0');
            }
            bool flag = false;
            for(int l = 0;l<h;l++){
                if(dp[l]>k){
                    flag = true;
                }
            }
            if(flag){
                for (int l = 0; l < h; l++)
                {
                    dp[l] = 0;
                }
                for (int l = 0; l < h; l++)
                {
                    dp[v[l]] += s[l][j] - '0';
                }
                ans++;
            }
        }
        bool flag = false;
        for (int l = 0; l < h; l++)
        {
            if (dp[l] > k)
            {
                flag = true;
            }
        }
        if(flag==false){
            res = min(res, ans);
        }
    }
    cout <<res << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (A, B, T) = readLine()!!.split(" ").map { it.toInt() }

    var t = 1
    var count = 0
    while ( t < T + 0.5) {
        if (t.mod(A) == 0) {
            count += B
        }
        t++
    }


    println(count)
}


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

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

  int sameCount = 0;
  rep(i,n){
     int d1, d2;
     cin >> d1 >> d2;
     if(d1 == d2){
       sameCount++;
       if(sameCount >= 3){
         cout << "Yes" << endl;
         return 0;
       }
     } else {
       sameCount = 0;
     }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, l = 0;
	long long N, K, a[100001]={0};
	cin >> N >> K;
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (i = 0; i < N; i++) {
		if (a[i] == 1) {
			ans += i / (K-1);
			if (i % (K-1)) ans++;
			break;
		}
	}
	
  if(a[i+1]){
  if(i%(K-1)){
	ans += (N - 1-(i+(K-1-i % (K - 1)))) / (K - 1);
    if ((N - 1 -(i+(K-1-i % (K - 1)))) % (K-1)) ans++;
  }
  else{
    ans+=(N-1-i)/(K-1);
	if((N-1-i)%(K-1))ans++;
  }
  }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int f=0;
  string a;
  cin >> a;
  string b;
  int c=0;
  for(int i=0;i<a.size();i++){
    if(f==0&&a[i]=='A'){
      f=1;
    }
    if(f==1&&a[i]=='Z'){
      c++;
      f=0;
    }
  }
  if(c==0)cout << -1 << endl;
  else{
    for(int i=0;i<c;i++){
      cout << "AZ" ;
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3204
#include<stdio.h>

#define N 100000
#define CLEAR 1
#define NOT 0

int num1[N],num2[N];

int search(int , int);

int main(){
  int n1,n2,i,j,count=0;

  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&num1[i]);
  }

  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&num2[i]);
  }

  for(i=0;i<n2;i++){
    if(search(n1,num2[i])==1) count++;
  }
  printf("%d\n",count);
      return 0;
}

int search(int right,int n){
  int left=0,mid;
  
  while (left<right){
    mid=(left+right)/2;

    if (num1[mid]==n) return CLEAR;
    else if(n<num1[mid]) right = mid;
    else left = mid +1;
  }
  
  return NOT;
}

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

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

const int MAXN=1e5+10;
int n,k;
int a[MAXN],ans=0;
int main()
{
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='L')
            a[i]=0;
        else
            a[i]=1;
    }
    int cnt=0,sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=1&&a[i]!=a[i-1])
        {
            ans+=sum-1;
            sum=0;
            cnt++;
        }
        sum++;
    }
    ans+=sum-1;
    cnt++;
    if(k>=cnt/2)
    {
        cout<<n-1<<endl;
        return 0;
    }
    if(a[1]==a[n])
    {
        ans+=min(cnt/2,k)*2;
    }
    else
    {
        ans+=min(cnt/2-1,k)*2;
        if(k>(cnt/2-1))
            ans+=(k-(cnt/2-1));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	vll n = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	ll N;
	std::cin >> N;
	std::cout << n[N - 1] << endl;

	return 0;

}


Measured memory_bytes: 256
n, x, m = map(int, input().split())

lst, num, flag = set(), [], False
for i in range(1, n + 1):
    lst.add(x), num.append(x)
    x = x ** 2 % m
    if x in lst:
        flag = True
        break

ans = sum(num)
if flag:
    cnt, idx = i, num.index(x)
    div, mod = divmod(n - cnt, len(num) - idx)
    ans += sum(num[idx:idx + mod])
    ans += sum(num[idx:]) * div
print(ans)


Measured memory_bytes: 76796
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,s[]={0,1,2,3,4,5},x,count;
    vector<ll>b;
    cin>>n;
    count=floor(log(n)+1);
    if(n>2000){
        cout<<1<<endl;
    }else{
        if(n>1000){
            x=n/100;
            if(x*5>=n%100){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }else{
            x=n/100;
            if(x*5>=n%100){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define Nmax 500005
using namespace std;

ll n, A, B, x, P;

ll comb(ll n, ll m){
    ll ans = 1;
    for (ll i=max(m,n-m) + 1;i<=n;i++) ans *= i;
    for (ll i=2;i<=min(m,n-m);i++) ans /= i;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> P;
    for (int i=1;i<=n;i++){
        cin >> x;
        if (x % 2) A++;
        else B++;
    }
    ll ans = 0;
    for (int i=0;i<=A;i+=2){
        ans = ans + comb(A, i) * (1LL<<B);
    }

    if (P == 1) ans = (1LL<<n) - ans;
    cout << ans << '\n';
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(to); x++) // for簡略表記
#define DUMP(ar) for(unsigned int i=0; i<ar.size(); i++) cout << "[" << i << "]:" << ar[i] << endl // 配列一覧表示
#define DUMPL(ar) for(unsigned int i=0; i<ar.size(); i++) { cout << ar[i]; if(i<ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    string s;
    cin >> s;
    vector<int> ans(s.size() + 1);

    int counter = 0;
    int tmp_counter=0, k;
    for(int i=0; i<(int)s.size(); i++){
        if(s[i] == '<'){
            ans[i] = counter;
            counter++;
        }else{
            if(tmp_counter > 0){
                ans[i] = counter;
                counter--;
                tmp_counter--;
            }else{
                tmp_counter = 0;
                k = i;
                while(k != s.size() && s[k] == '>'){
                    tmp_counter++;
                    k++;
                }
                if(tmp_counter > counter) ans[i] = tmp_counter;
                else ans[i] = counter;
                counter = tmp_counter-1;
                tmp_counter--;
            }
        }
    }
    ans.back() = counter;

    // DUMP(ans);
    lint a = 0;
    FOR(i, ans.size()){
        a += ans[i];
    }
    COUT(a);

    return 0;
}

Measured memory_bytes: 2844
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut b: Vec<usize> = vec![];
    for _ in 0..(n - 1) {
        b.push(iter.next().unwrap().parse().unwrap());
    }

    let mut a: Vec<usize> = vec![];

    for i in 0..n {
        if i == 0 {
            a.push(b[0]);
            continue;
        } else if i == n - 1 {
            a.push(b[i - 1]);
            break;
        }
        a.push(std::cmp::min(b[i], b[i - 1]));
    }

    let mut ans = 0;
    for a in a.into_iter() {
        ans += a;
    }

    // let sum = a.iter().fold(0, |sum, a| sum + a.count);

    println!("{}", ans);
}


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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c ,n, sum, A[500010], B[500000],rui[500000],  dp[5000];
str S,T,U;bool check = true;	vector<ll> v;



int main() {
	//Code Line
cin >> a >> b >> c;
if(a == b)n++;
if(b == c)n++;
if(a == c)n++;

if(n == 1)cout << " Yes" << endl;
else cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    char cur = 'A';
    char cup_a, cup_b, d;
    while (cin >> cup_a >> d >> cup_b) {
        if (cur == cup_a) {
            cur = cup_b;
        } else if (cur == cup_b) {
            cur = cup_a;
        }
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;
ll bit[400010],a[200010],b[200010],p[100010],x[100010],y[100010],n,q,inv[300010],m;
vector<ll> v;
map<ll,ll> mp;
ll sum(ll i){
	ll s = 0;
	while(i>0){
		s += bit[i];
		i -= i&-i;
	}
	return s;
}

void add(ll i, ll x){
	while(i<=m){
		bit[i] += x;
		i += i&-i;
	}
}
int main(){
	ll z,ans=0,i;
	cin >> n >> q;
	for(i=0;i<2*n;i++){
		cin >> a[i];
	}
	for(i=0;i<2*n;i++){
		cin >> b[i];
	}
	for(i=1;i<2*n-1;i++){
		v.push_back(a[i]-b[i]);
	}
	for(i=0;i<q;i++){
		cin >> p[i] ;
		p[i]--;
		cin>> x[i] >> y[i];
		if(p[i]!=0 && p[i]!=2*n-1){
			v.push_back(x[i]-y[i]);
		}
	}
	v.push_back(0);
	sort(v.begin(),v.end());
	m = v.size()+1;
	int now = 1;
	mp[v[0]] = 1;
	inv[1] = v[0];
	if(v[0]==0){
		z = 1;
	}
	for(i=1;i<v.size();i++){
		if(v[i]>v[i-1]){
			now++;
		}
		mp[v[i]] = now;
		inv[now] = v[i];
		if(v[i]==0){
			z = now;
		}
	}
	now++;
	ll cnt = 0;
	for(i=1;i<2*n-1;i++){
		add(mp[a[i]-b[i]],1);
		if(a[i]>=b[i]){
			ans += a[i];
			cnt += 1;
		}else{
			ans += b[i];
		}
	}
	ans += a[0]+a[2*n-1];
	for(i=0;i<q;i++){
		if(p[i]==0 || p[i]==2*n-1){
			ans -= a[p[i]];
			ans += x[i];
			a[p[i]] = x[i];
			b[p[i]] = y[i];
		}else{
			ans -= max(a[p[i]],b[p[i]]);
			ans += max(x[i],y[i]);
			add(mp[a[p[i]] - b[p[i]]],-1);
			add(mp[x[i] - y[i]],1);
			if(a[p[i]]-b[p[i]]>0 ^ x[i]-y[i]>0){
				cnt++;
			}
			a[p[i]] = x[i];
			b[p[i]] = y[i];
		}
		if(cnt%2==0){
			cout << ans << endl;
		}else{
			long long l=0,r=now,mid;
			int s = sum(z);
			while(r - l>1){
				mid = (l+r)/2;
				if(sum(mid)>=s+1){
					r = mid;
				}else{
					l = mid;
				}
			}
			long long m1 = inv[r];
			l=0,r=now;
			while(r - l>1){
				mid = (l+r)/2;
				if(sum(mid)<s){
					l = mid;
				}else{
					r = mid;
				}
			}
			long long m2 = inv[r];
			cout << max(ans - m1,ans + m2) << endl;
		}
	}
}


Measured memory_bytes: 31084
// D - Friend Suggestions
// UnionFinde version (with rank)
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

class UnionFind{//union-find class (rank)
	vector<int> parent;//parent number
	vector<int> rank;//rank
	public:
	UnionFind(int n){
		parent.resize(n);
		rank.resize(n);
		for(int v=0; v<parent.size(); ++v){
			parent[v] = v;
			rank[v] = 0;
		}
	}
	int root(int v){//get root
		if(parent[v]==v) return v;//root
		return parent[v] = root(parent[v]);//path compression
	}
	void unite(int v, int u){
		v = root(v); u = root(u);
		if(v==u) return;
		//concat low rank to high rank (but rank is no compress)
		if(rank[v]<rank[u]) parent[v] = u;
		else{
			parent[u] = v;
			if(rank[v]==rank[u]) rank[v]++;//fix rank when same rank concat
		}
	}
	bool same(int v, int u){return root(v)==root(u);}//v & u the same set
};

int main(){
	int N,M,K; cin>>N>>M>>K;
	UnionFind uf(N);
	vi C(N);
	int s,t;
	rp(i,0,M){
		cin>>s>>t; s--; t--;
		uf.unite(s,t);
		C[s]++; C[t]++;
	}
	rp(i,0,K){
		cin>>s>>t; s--; t--;
		if(uf.same(s,t)) C[s]++, C[t]++;
	}
	vi cnt(N);rp(i,0,N) cnt[uf.root(i)]++;
	rp(i,0,N) cout<< cnt[uf.root(i)]-C[i]-1 <<" ";
}

Measured memory_bytes: 2432
/* Accepted. */
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
#define MAXN 10
int n , m;
int A[MAXN];
int main() {
	cin >> n;
	puts((n==3||n==5||n==7)?"YES":"NO");
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(void)
{
	int c,a,n,q,c2,c3,a2;
	int i,j,k,mn;
	int cnt,max;
	
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%d %d %d",&c,&a,&n);
		max=0;
		for(j=0;j<=c/3;j++)	{
			c2=c-j*3;
			for(k=0;k<=c2/2;k++)	{
				c3=c2-k*2;
				a2=a-k;
				mn=c3;
				if(mn>a2)	mn=a2;
				if(mn>n)	mn=n;
				if(max<j+k+mn)	max=j+k+mn;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

}

#define sz 10000007

vector<long long> arr(sz);

int main()
{

    textIO();
    fastIO();

    long long n, total = 0;
    cin >> n;
    unordered_map<long long, long long> ump;

    for(int i=0;i<n;i++){
        long long a;
        cin >> a;
        ump[a]++;
        total+=a;
    }

    cin >> n;
    while(n--){
        long long p, n;
        cin >> p >> n;
        total-=(ump[p]*p);
        total+=(ump[p]*n);
        ump[n]+=ump[p];
        ump[p] = 0;
        cout << total << '\n';

    }

    return 0;
}


Measured memory_bytes: 85300
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s=="abc"){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	int H, W;
	cin >> H >> W;

	string C[102];
	REP(i, H) {
		cin >> C[i];
	}

	REP(i, H) {
		cout << C[i] << endl << C[i] << endl;
	}

	//cout << N << endl;
	return 0;
}

Measured memory_bytes: 256
I=N=9**9
P,M,L,R,U,*D='x+y,','x-y,',[],[],[]
for t in[*open(0)][1:]:*z,u=t.split();exec(u+'+=[*map(int,z)],')
for*A,S in(D,U,'x,y,'),(L,R,'y,x,'),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 n=p=-I
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in P)'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

Measured memory_bytes: 71532
def typical_stairs():
    n, m = map(int, input().split())
    dangerous = set(int(input()) for _ in range(m))
    mod = 1000000007
    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in dangerous:
        dp[1] = 1
    for i in range(2, n + 1):
        if i not in dangerous:
            dp[i] = dp[i - 2] + dp[i - 1]
    print(dp[-1] % mod)


if __name__ == '__main__':
    typical_stairs()


Measured memory_bytes: 471288
#include <iostream>

using namespace std;

int main()
{
    int n,m,c;
    cin >> n>>m>>c;
    int b[m],a[n][m];
    int ans=0;
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        int co=c;
        for(int j=0;j<m;j++){
            cin>> a[i][j];
            co+=b[j]*a[i][j];
        }
        if(co>0)ans++;
    }
    cout << ans<< endl;
    return 0;

}


Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	s, t := next(), next()

	l := lcm(n, m)
	for si, ti := 0, 0; si < n && ti < m; si, ti = si+l/m, ti+l/n {
		if s[si] != t[ti] {
			puts(-1)
			return
		}
	}

	puts(l)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

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

  reps(i, 100000){
    if((int)(i * 0.1) == b && (int)(i * 0.08) == a){
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 256