akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e7;
const ll MOD = 998244353;

int N;
ll ans=1, fact[MAXN+10], invfact[MAXN+10], twopow[MAXN+10], A;

ll mypow(ll x, ll y)
{
    if(y==0) return 1;
    if(y%2) return mypow(x, y-1)*x%MOD;
    ll t=mypow(x, y/2);
    return t*t%MOD;
}

ll inv(ll x) { return mypow(x, MOD-2); }

ll comb(ll n, ll r) { return fact[n]*invfact[r]%MOD*invfact[n-r]%MOD; }

int main()
{
    int i, j;

    scanf("%lld", &N);
    for(i=1; i<=N; i++) ans=ans*3%MOD;

    twopow[0]=1;
    for(i=1; i<=N; i++) twopow[i]=twopow[i-1]*2%MOD;

    fact[0]=1;
    for(i=1; i<=N; i++) fact[i]=fact[i-1]*i%MOD;
    invfact[N]=inv(fact[N]);
    for(i=N; i>=1; i--) invfact[i-1]=invfact[i]*i%MOD;

    for(i=N/2+1; i<=N; i++) A=(A+comb(N, i)*twopow[N-i]%MOD)%MOD;
    ans-=2*A;
    ans=(ans%MOD+MOD)%MOD;
    printf("%lld", ans);
}


Measured memory_bytes: 234624
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <climits>
#include <numeric>
#include <cstring>
#include <utility>
#include <bitset>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvint;

#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007LL
#define INF 1010101010


int main(){
	int bits[1 << 16];
	for(int S = 1 << 16; S--; ){
		bits[S] = bitset<32>(S).count();
	}

	int n, m, rnum, s, t, a, b, c;
	while(scanf("%d%d%d%d%d", &n, &m, &rnum, &s, &t), n){
		vector<vector<int> > Gorig(n + 1, vector<int>(n + 1, INF));
		for(int i = 0; i <= n; ++i){
			Gorig[i][i] = 0;
		}

		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &a, &b, &c);
			Gorig[a][b] = Gorig[b][a] = c;
		}
		for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j){
			Gorig[i][j] = min(Gorig[i][j], Gorig[i][k] + Gorig[k][j]);
		}
		
		vector<pii> rs(rnum);
		for(int i = 0; i < rnum; ++i){
			scanf("%d%d", &rs[i].first, &rs[i].second);
		}
		sort(ALL(rs));
		
		vector<vector<int> > G(rnum, vector<int>(rnum));
		for(int i = 0; i < rnum; ++i)
		for(int j = 0; j < rnum; ++j){
			G[i][j] = Gorig[rs[i].first][rs[j].first];
		}

		vvint dp(rnum, vector<int>(1 << rnum, INF));
		for(int i = 0; i < rnum; ++i){
			dp[i][1 << i] = Gorig[s][rs[i].first] + rs[i].second;
		}

		int ans = 0;
		for(int S = 1; S < (1 << rnum); ++S){
			for(int i = 0; i < rnum; ++i){
				if(dp[i][S] == INF){ continue; }
				int tret = dp[i][S] + Gorig[rs[i].first][s];
				if(tret <= t){
					ans = max(ans, bits[S]);
				}
				
				for(int j = 0; j < rnum; ++j){
					if(S >> j & 1){ continue; }
					int T = S | 1 << j;
					dp[j][T] = min(dp[j][T], dp[i][S] + G[i][j] + rs[j].second);
				}
			}
		}
		
		printf("%d\n", ans);
	}
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

vector<int> p;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s, t; cin >> s;
    t = s;
    sort(t.begin(), t.end());
	int ans = 0;
    for(int i = 0; i < n; i++){
      if(t[i] == 'W') break;
      if(s[i] != 'R') ans++;
    }
	cout << ans << endl;
} 


Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

bool ok(string in, int st, int fi){
    bool pass=true;
    rep(i, fi-st){
        if(in[st+i]!=in[fi-1-i]) pass=false; //cout<<st+i<<sp<<st<<sp<<fi<<endl;
    }
    return pass;
}

int main(void){
    string S;
    cin>>S;
    int N=S.size();
    cout<<((ok(S, 0, N) && ok(S, 0, (N-1)/2) && ok(S, (N+1)/2, N)) ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
  int a,b,d,r;
  double f;

  scanf("%d%d", &a,&b); 
  d=a/b;  r=a%b;
  f=1.00*a/b;
  printf("%d %d %.6lf\n",d,r,f);
 
  return 0;
}

Measured memory_bytes: 1072
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int i,g[1000]={0},num=0;
        string a;
        cin>>a;
        for(i=0;i<4;i++)
                g[a[i]]++;
        for(i=0;i<4;i++)
               if(g[a[i]]!=0)
               {
                       if(g[a[i]]==2)
                       num++;
                       g[a[i]]=0;
               }

        if(num==2)
        cout<<"Yes"<<endl;
        else
                cout<<"No"<<endl;
        return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 1e6 + 69;

ll n,m,k,x,y;

ll A[N];

vector< ll > v;

string s;

int main(){

    ios::sync_with_stdio(0);

    cin>>n>>k;

    x = 0;
    for(int i=0;i<k;i++){
        cin>>y;
        x+=y;
    }

    if(x>=n){
        cout<<"Yes"<<endl;
    } else {
    cout<<"No"<<endl;}

}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

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

	int ans = 0;
	string s; cin >> s;
	int cnt = 0;
	FOR(i, s.size()){
		if(s[i] == 'S'){
			ans = max(ans,cnt);
			cnt = 0;
		}else{
			cnt++;
		}
	}

	ans = max(ans, cnt);

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    int n, ans = 0;
    while (true) {
        S.pop_back(); ans += 1;
        n = S.size();
        if (n % 2 != 0) continue;
        if (S.substr(0, n/2) == S.substr(n/2, n)) break;
    }
    cout << n << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int w, h;
char ch[50][50];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };

int bfs(int y, int x) {
    int res = 0;
    rep(i, 4) {
        int ny = y + dy[i], nx = x + dx[i];
        if (0 > ny or 0 > nx or ny >= h or nx >= w) continue;
        if (ch[ny][nx] == '.') {
            ch[ny][nx] = 'a';
            res += bfs(ny, nx) + 1;
        }
    }
    return res;
}

int main() {
    while (cin >> w >> h and (w or h)) {
        int py = 0, px = 0;
        rep(i, h) rep(j, w) {
            cin >> ch[i][j];
            if (ch[i][j] == '@') {
                py = i, px = j;
                ch[i][j] = 'a';
            }
        }
        cout << bfs(py, px) + 1 << endl;
    }
}

Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#define N 410
#define M 100010
using namespace std;
struct bb{int x, y;}b[M];
int n, m, ans;
bitset<N>set[N];
int main(){
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++)scanf("%d%d", &b[i].x, &b[i].y);
	for(int i=1; i<=n; i++){
		set[i].reset(); set[i][i]=1;
		for(int j=m; j; j--){
			if(set[i][b[j].x]&&set[i][b[j].y]){set[i].reset(); break;}
			if(!set[i][b[j].x]&&!set[i][b[j].y])continue;
			set[i][b[j].x]=set[i][b[j].y]=1;
		}
	}
	ans=0;
	for(int i=1; i<=n; i++)if(set[i].count())
		for(int j=i+1; j<=n; j++)if(set[j].count())
			if(!(set[i]&set[j]).count())ans++;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  if(s=="ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
  return 0;
}

Measured memory_bytes: 3596
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll visit[1000010]={};

int main(){

    
    cin >> N;
    cin >> M;
    if(M==1){
        cout << 1 << " " << 2 << endl;
    }else{
        ll left   = 1;
        ll bet    = M-2;
        ll right  = left +bet+1;

        ll left2  = right+1;
        bet++;
        ll right2 = left2 +bet+1;
        ll mi=0;
        while(mi<M){
            cout << left << " " <<right<< endl;
            left++;
            right--;
            if(left>=right){
                left=left2;
                right=right2;
            }


            mi++;
        }
    }

}

Measured memory_bytes: 3576
#include <stdio.h>
int main (){
    int n,k;
    char s[11];
    char tmp;
    int i=0;

    scanf("%d",&n);
    scanf("%s",s);
    scanf("%d",&k);
    tmp = s[k-1];
    for(i=0; i <n ; i++){
        if (s[i] != tmp) {
            s[i] = '*';
        }
        printf("%c",s[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {

	int num = 0;
	int count = 0;

	cin >> num;

	int a = num/100;

	if (a >= 1) {
		++count;
		num -= 100;
	}
	int b = num / 10;

	if (b >= 1) {
		++count;
		num -= 10;
	}
	int c = num;

	if (c >= 1) {
		++count;
	}
		

	cout << count;

	return 0;
}

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


int main(){
    // input
    int D, G;
    cin >> D >> G;
    vector<ll> p(D), c(D);
    for (int i = 0; i < D; i++)
    {
        cin >> p[i] >> c[i];
    }
    

    // bit全探索
    int ans = 1000;
    for (int bit = 1; bit < (1 << D); bit++)
    {
        vector<int> solved;
        for (int i = 0; i < D; i++)
        {
            if (bit & (1 << i)){
                solved.push_back(i); //0-indexed
            }
        }

        // フラグ立ってる問題を全部解いた場合
        ll max_score = 0;
        int tmp_ans = 0;
        for (int i = 0; i < solved.size(); i++)
        {
            max_score += (100 * (solved[i] + 1) * p[solved[i]]) + c[solved[i]];
            tmp_ans += p[solved[i]];
        }
        if (max_score < G)
        {
            continue;
        }
        if (ans > tmp_ans)
        {
            ans = tmp_ans;
        }
        

        // 特定の点数の問題を減らしていく
        for (int i = 0; i < solved.size(); i++)
        {
            ll tmp_score = max_score;
            int tmp_tmp_ans = tmp_ans;
            tmp_score -= c[solved[i]];
            for (int j = 0; j < p[solved[i]]; j++)
            {
                tmp_score -= 100 * (solved[i] + 1);
                tmp_tmp_ans--;
                if (tmp_score < G)
                {
                    break;
                }
                if (ans > tmp_tmp_ans)
                {
                    ans = tmp_tmp_ans;
                }
            }            
        }
    }

    cout << ans << endl;
    return 0;
}


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

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

    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            StringBuffer sb1 = new StringBuffer();
            StringBuffer sb2 = new StringBuffer();
            if(h == 0 && w == 0){
                break;
            }
            for(int i =0;i<w;i++){
                if(i%2==0){
                    sb1.append("#");
                    sb2.append(".");
                }else{
                    sb1.append(".");
                    sb2.append("#");            
                }
            }
            for(int j=0;j<h;j++){
                if(j%2==0){
                    System.out.println(sb1.toString());
                }else{
                    System.out.println(sb2.toString());
                }
            }
            System.out.println();
        }
    }
}




Measured memory_bytes: 27632
n, k = map(int, input().split())

highs = [int(input()) for i in range(n)]
highs = sorted(highs)

minimum = 1000000000
for i in range(n - k + 1):
    val = highs[i + k - 1] - highs[i]
    if val < minimum:
        minimum = val

print(minimum)

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

int main()
{
    ll n;
    ll k;
    cin >> n >> k;
    vector<ll> x(100001, 0);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        x[a] += b;
    }
    ll sum = 0;
    rep(i, 100001) {
        sum += x[i];
        if(sum >= k) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4048
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,r){function t(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){for(var r=t(e[0].split(" ").map(function(e){return Number(e)}),2),n=r[0],o=r[1]/1e3,u=0;u<=n;u++)for(var i=0;i<=n-u;i++){if(10*u+5*i+(n-u-i)==o)return void console.log(`${u} ${i} ${n-u-i}`)}console.log("-1 -1 -1")}},function(e,r){e.exports=require("fs")}]);

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> S(M*2);
  vector<int> C(N);
  
  for(int i=0;i<M*2;i++) {
    cin >> S.at(i);
    
    for(int j=0;j<N;j++) {
      if(S.at(i)==j+1) C.at(j)++;
    }
    
  }
  
  for(int i=0;i<N;i++) cout << C.at(i) << endl;

}





Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int M = 1010;
int n,m;
int dp[M][(1<<12)];
int a[M],b[M],c[M][13];
int full=0;
int solve(int id,int msk){
  if(msk==full)return 0;
  if(id==m+1)return 1e9;
  int &x = dp[id][msk];
    if(x!=-1)return x;
    x=solve(id + 1,msk);
    
    int nmsk = msk;
    for(int j=1;j<=b[id];j++){
      nmsk|=(1<<c[id][j]);
    }
    x = min(x,a[id] + solve(id+1,nmsk));
    return x;
}

// long long ? ?
int32_t main(){
  fastio;
  int n;
  cin>>n;
  vector<pii> v;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    v.pb(pii(x,i));
  }
  sort(v.begin(),v.end());
  for(auto it : v){
    cout<<it.ss + 1<<" ";
  }
  cout<<endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a >= 13){
        ans = b;
    } else if( a >= 6 && a <= 12){
        ans = b/2;
    } else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int arr(long long a,long long b)
{
    if((a==1)&&(b==1))
    {
        cout<<1<<endl;
        return 0;
    }
    if((a==1)&&(b!=1))
    {
        cout<<b-2<<endl;return 0;
    }
    if((a!=1)&&(b==1))
    {
        cout<<a-2<<endl;return 0;
    }
    cout<<(a-2)*(b-2)<<endl;
}
int main()
{
    long long a,b;
    cin>>a>>b;
    arr(a,b);
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> cake(h, vector<char>(w));
    vector<vector<int32>> berry(h);
    REP(i,h)REP(j,w){
        cin >> cake[i][j];
        if(cake[i][j] == '#'){
            berry[i].pb(j);
        }
    }
    int32 prev = -1;
    vector<vector<int32>> ans(h, vector<int32>(w,-1));
    REP(i,h){
        if(berry[i].size() == 0){
            continue;
        }else if(berry[i].size() == 1){
            FORR(y,i,prev+1){
                REP(x,w){
                    ans[y][x] = k;
                }
            }
            k--;
            prev = i;
        }else{
            REP(x,berry[i][1]){
                FORR(y,i,prev+1){
                    ans[y][x] = k;
                }
            }
            k--;
            FOR(j,1,(signed)berry[i].size()){
                FORR(y,i,prev+1){
                    if(j == (signed)berry[i].size() - 1){
                        FOR(x,berry[i][j],w){
                            ans[y][x] = k;
                        }
                    }else{
                        FOR(x,berry[i][j], berry[i][j+1]){
                            ans[y][x] = k;
                        }
                    }
                }
                k--;
            }
            prev = i;
        }
    }
    FOR(y,prev+1,h){
        REP(x,w){
            ans[y][x] = ans[y-1][x];
        }
    }
    REP(i,h){
        REP(j,w){
            if(j != 0)cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2816
// Comment
// graph component divide

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

int N, M, Nr[MAX_N];
vector<int> Ed[MAX_N];
int main() {
	cin >> N >> M;
	for(int i=1; i<=N; i++) scanf("%d", &Nr[i]);
	for(int i=0; i<M; i++) {
		int x, y; scanf("%d%d", &x, &y);
		Ed[x].push_back(y);
		Ed[y].push_back(x);
	}
	vector<int> vis(N+1, 0);
	int cnt = 0;
	int ans = 0;
	for(int i=1; i<=N; i++) if(vis[i] == 0) {
		int st = i;
		cnt++;
		queue<int> q;
		q.push(st); vis[st] = cnt;
		vector<int> list;
		while(!q.empty()) {
			int v = q.front(); q.pop();
			list.push_back(v);
			for(int w: Ed[v]) if(vis[w] == 0) {
				q.push(w); vis[w] = cnt;
			}
		}
		int now = 0;
		for(int v: list) if(vis[Nr[v]] == cnt) {
			now++;
		}
		ans += now;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 10148
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[2])cout << "Yes";
    else if(S[0]==S[2] && S[1]==S[3] && S[0]!=S[1])cout << "Yes";
    else if(S[0]==S[3] && S[1]==S[2] && S[0]!=S[1])cout << "Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
# 参考 : https://atcoder.jp/contests/abc166/submissions/16829140
n = int(input())
a = list(map(int,input().split()))
# 参加者 i,j が取引する場合、 j - i = A_i + A_j が成り立つ。
# 変形すると -i - A_i = -j + A_j, i + A_i = j - A_j になる。
# l = i + A_i, r = j - A_j
l = [i + a[i] for i in range(n)]
r = [i - a[i] for i in range(n)]
# 連想配列(辞書)を使う。
x = {}
y = {}
# 辞書にキーを追加する。
for i in range(n):
    x[l[i]] = 0
    y[l[i]] = 0
    y[r[i]] = 0
# キーの値を人数分増やす。
for i in range(n):
    x[l[i]] += 1
    y[r[i]] += 1
ans = 0
# x のキーで取引する人数を調べる。
for i in set(x.keys()):
    ans += x[i] * y[i]
print(ans)

Measured memory_bytes: 78652
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  long long N, M;
  cin >> N >> M;

  if (M % 2 == 1) M -= 1;

  if (M == 0) {
    cout << 0 << endl;
  } else if (M >= 2*N) {
    long long v = M - (2 * N);
    cout << (v / 4) + N << endl;
  } else {
    cout << M / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int pt[256],n;char dk[10];
	rep(i,8)pt['2'+i]=2+i;
	pt['A']=11,pt['T']=pt['J']=pt['Q']=pt['K']=10;
	cin>>n;while(n--){
		rep(i,10)cin>>dk[i];
		int sc=pt[dk[0]]+pt[dk[1]],bigA=dk[0]=='A'||dk[1]=='A';
		if(sc==21){
			cout<<"blackjack"<<endl;continue;
		}
		if(sc>21)sc-=10;
		for(int cur=2;sc<17||sc==17&&bigA;cur++){
			sc+=pt[dk[cur]];bigA+=dk[cur]=='A';
			if(sc>21&&bigA)sc-=10,bigA--;
		}
		if(sc>21)cout<<"bust"<<endl;
		else cout<<sc<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n,m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(m)]
p= list(map(int, input().split()))
a=2**n
on=0
cnt=0
light=True
s = [bin(i)[2:] for i in range(a)]
for i in range(a):
    s[i]='0'*(n-len(s[i]))+s[i]
    s[i]=s[i][::-1]
for i in range(a):
    for j in range(m):
        for l in range(1,k[j][0]+1):
            #print(s[i][k[j][l]-1], i,j,l)
            if s[i][k[j][l]-1]=='1':
                on+=1
        if on%2!=p[j]:
            light=False
        #print(i,light,j,on)
        on=0
    if light:
        cnt+=1
    light=True
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
int main()
{
	int N,K,X,Y;
	scanf(" %d %d %d %d",&N,&K,&X,&Y);
	if(N>K)printf("%d\n",K*X+(N-K)*Y);
	else printf("%d\n",N*X);
	return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
input=lambda :sys.stdin.readline().rstrip()
inputs= sys.stdin.buffer.readlines
INF=float("inf")
MOD=10**9+7
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(2147483647)
#rstrip().decode('utf-8')
#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#map(int,input().split())


def main():
	n=int(input())
	s=input()
	ans="Yes"
	if n%2==1 or s[:n//2]!=s[n//2:]:
		ans="No"
	print(ans)



if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    long long N;
    long long travel[5];
    cin >> N;
    for (int i = 0; i < 5; i++){
        cin >> travel[i];
    }
    sort(travel, travel + 5);
    cout << 4 + (N + travel[0] - 1)/ travel[0] << endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
    int N;
    int i;
    
    scanf("%d", &N);
    
    int Array[N];
    
    for (i = 0; i < N; i++){
        scanf("%d", &Array[i]);
    }
    
    int default_sum = 0;
    
    default_sum += (abs(Array[0]) + abs(Array[N - 1]));
    for (i = 0; i < N - 1; i++){
        default_sum += abs(Array[i] - Array[i + 1]);
    }
    
    printf("%d\n", default_sum - abs(Array[0]) - abs(Array[0] - Array[1]) + abs(Array[1]));
    for (i = 1; i < N - 1; i++){
        printf("%d\n", default_sum - abs(Array[i] - Array[i - 1]) - abs(Array[i] - Array[i + 1]) + abs(Array[i - 1] - Array[i + 1]));
    }
    printf("%d\n", default_sum - abs(Array[N - 1]) - abs(Array[N - 1] - Array[N - 2]) + abs(Array[N - 2]));
    
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,d,x;
    vector<int> A;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }
    int ans=x;
    for(int i=0;i<n;i++){
        int j=0;
        while(j*A[i]+1<=d){
            ans++;
            j++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    long long n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        long long sun=0;
        if (n==1&&m==1) sun=1;
        else if (n==1||m==1) sun=max(n,m)-2;
        else if (n==2||m==2) sun=0;
        else sun=(n-2)*(m-2);
        printf("%lld\n",sun);
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
S_rev = S[::-1]
#one_modは元のビットが立ってるとき zero_modは逆
one_mod = 0
zero_mod = 0
#Nが大きすぎるため下の桁から順に計算
for i in range(N):
    if S_rev[i] == '1' and one_cnt - 1 != 0:
        one_mod += pow(2,i,one_cnt - 1)
        one_mod %= (one_cnt - 1)
        zero_mod += pow(2,i,one_cnt + 1)
        zero_mod %= (one_cnt + 1)

cnt = [0]*(one_cnt+1)
pop_cnt = [0]* (one_cnt+1)
for i in range(1,one_cnt+1):
    pop_cnt[i] = pop_cnt[i//2] + i%2
    j = i % pop_cnt[i]
    cnt[i] = 1 + cnt[j] 

one_pow2 = [1]*(N+1)
zero_pow2 = [1]*(N+1)
for i in range(1,N):
    if one_cnt-1 != 0:
        one_pow2[i+1] = one_pow2[i]*2 % (one_cnt - 1)
    zero_pow2[i+1] = zero_pow2[i]*2 % (one_cnt + 1)

for i in range(N):
    if S[i] == '1':
        if one_cnt-1 == 0:
            print(0)
        else:
            nxt = one_mod
            nxt -= one_pow2[N-i]
            nxt %= (one_cnt - 1)
            print(1+cnt[nxt])
    else:
        nxt = zero_mod
        nxt += zero_pow2[N-i]
        nxt %= (one_cnt + 1)
        print(1+cnt[nxt])

Measured memory_bytes: 26992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i=0; i<ty-sy; i++){
    cout << 'U';
  }
  for(int i=0; i<tx-sx; i++){
    cout << 'R';
  }
  for(int i=0; i<ty-sy; i++){
    cout << 'D';
  }
  for(int i=0; i<tx-sx; i++){
    cout << 'L';
  }
//2
  cout << 'L';
  for(int i=0; i<ty-sy+1; i++){
    cout << 'U';
  }
  for(int i=0; i<tx-sx+1; i++){
    cout << 'R';
  }  
  cout << 'D'<< 'R';  
  for(int i=0; i<ty-sy+1; i++){
    cout << 'D';
  }  
  for(int i=0; i<tx-sx+1; i++){
    cout << 'L';
  }  
  cout << 'U' << endl;  
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String [] args){
		Scanner in = new Scanner(System.in);
		double l = in.nextInt();
		double a  = l/3;
		l = l-a;
		double b = l/2;
		double c = (l-b);
		System.out.print(a*b*c);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	ll n, m;
	cin >> n >> m;
	vector<PAIR> t;
	t.reserve(n + m);
	REP(_, n) {
		ll a;
		cin >> a;
		t.emplace_back(a, 1);
	}
	REP(_, m) {
		ll a, b;
		cin >> a >> b;
		t.emplace_back(b, a);
	}
	sort(ALL(t), [](cauto a, cauto b) {return a.first > b.first; });


	ll ans = 0;
	REPC(p, t) {
		dump(n, p);
		if (p.second > n) {
			ans += n * p.first;
			break;
		}
		ans += p.first * p.second;
		n -= p.second;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stack
{
    int data[105];
    int top;
};
void stack_init(struct stack *s)
{
    s->top = 0;
}
void stack_push(struct stack *s, int d)
{
    s->data[s->top++] = d;
}
int stack_pop(struct stack *s)
{
    return s->data[--s->top];
}
int main()
{
    struct stack s;
    char ch[10];
    int a, b;
    stack_init(&s);
    while (scanf("%s", ch) != EOF)
    {
        if (!strcmp(ch, "+"))
        {
            b = stack_pop(&s);
            a = stack_pop(&s);
            stack_push(&s, a + b);
        }
        else if (!strcmp(ch, "-"))
        {
            b = stack_pop(&s);
            a = stack_pop(&s);
            stack_push(&s, a - b);
        }
        else if (!strcmp(ch, "*"))
        {
            b = stack_pop(&s);
            a = stack_pop(&s);
            stack_push(&s, a * b);
        }
        else
            stack_push(&s, atoi(ch));
    }
    printf("%d\n", stack_pop(&s));
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mian(){
	int n,k;
	cin>>n>>k;
	bool a[n+1];
	for(int i=1;i<=n;++i)
		a[i]=true;
	for(int i=1;i<=k;++i){
		int x;
		cin>>x;
		int y;
		while(x--){
			cin>>y;
			a[y]=false;
		}
	}
	int tot=0;
	for(int i=1;i<=n;++i)
		tot+=a[i];
	cout<<tot<<endl;
	return 0;
}
signed main(){
	int t=1;
//	cin>>t;
	while(t--)
		mian();
	return 0;
}

Measured memory_bytes: 3624
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int n;
	cin>>n;
	vi a(n+1);
	for1(i,n) cin>>a[i];
	ll plus=0,s=0;
	for1(i,n){
		s += a[i];
		if(i%2){
			if(s<=0){
				plus += 1-s;
				s = 1;
				}
			}
		else{
			if(s>=0){
				plus += s+1;
				s = -1;
				}
			}
		}
	ll minus=0;
	s=0;
	for1(i,n){
		s += a[i];
		if(i%2){
			if(s>=0){
				minus += s+1;
				s = -1;
				}
			}
		else{
			if(s<=0){
				minus += 1-s;
				s=1;
				}
			}
		}
	//cout<<plus<<" "<<minus<<nw;
	ll ans = min(plus,minus);
	cout<<ans<<nw;
	return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
int main() {
	int n;;
	while (cin >> n, n) {
		vector<long long> a(n);
		for (long long &x : a)cin >> x;
		sort(a.begin(), a.end());
		long long sum = 0,sum1=0;
		for (long long &x : a)sum1+=sum,sum+=x;
		//sum = 0;
		//for (long long &x : a)x = (sum += x);
		cout << sum1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W;
  cin>>H>>W;
  map<char, int> amap;
  vector<char> arr;
  char tmp;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>tmp;
      if(amap[tmp]==0) arr.push_back(tmp);
      amap[tmp]++;
    }
  }
  bool can = true;
  int onenum=0, twonum=0;
  if(H%2==0 && W%2==0) {
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%4!=0) can = false;
    }
  }
  if(H%2==1 && W%2==0) {
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%2!=0) can = false;
      if(amap[arr[i]]%4==2) twonum++;
    }
    if(twonum>W/2) can = false;
  }
  if(H%2==0 && W%2==1) {
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%2!=0) can = false;
      if(amap[arr[i]]%4==2) twonum++;
    }
    if(twonum>H/2) can = false;
  }
  if(H%2==1 && W%2==1) {
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%2==1) onenum++;
      if(amap[arr[i]]%4==2) twonum++;
    }
    if(onenum!=1) can = false;
    if(twonum>H/2+W/2) can = false;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//ctoiは自分で実装できる
int ctoi(char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
    string s;
    cin >> s;
    int ans = 999;
    int n = s.size()-2;
    for(int i=0; i<n; i++){
        int temp = 100*(ctoi(s[i]))+10*(ctoi(s[i+1]))+(ctoi(s[i+2]));
        ans = min(ans, abs(753-temp));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3564
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()

info = [na() for i in range(n)]
ix, iy, ih = 0, 1, 2

si = -1
for i in range(n):
	if info[i][2] > 0:
		si = i

ans = [-1, -1, -1]
for cx in range(101):
	for cy in range(101):
		x = abs(cx - info[si][ix])
		y = abs(cy - info[si][iy])
		h = info[si][ih] + x + y
		ok = True
		for i in range(n):
			if info[i][ih] > 0 and h - info[i][ih] != abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
			if info[i][ih] == 0 and h > abs(cx - info[i][ix]) + abs(cy - info[i][iy]):
				ok = False
		if ok is True:
			ans[ix], ans[iy], ans[ih] = cx, cy, h

print(ans[ix], ans[iy], ans[ih])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)

typedef vector<int> vi;
typedef map<int, int> mii;

int const score[] = { 0, 0, 60, 70, 80 };
int eval(int n){
    int s = 0;
    rep(i,5){
        s+=score[n&0b111];
        n>>=3;
    }
    return s;
}

int flip(int n,int f){
    f<<=2;
    int r=0;
    rep(i,5){
        int t=n>>(i*3)&0b111;
        if(t){
            int c=(f>>(i*2)&0b11)+(f>>(i*2+2)&0b11);
            t=((t-1+c)&0b11)+1;
        }
        r|=t<<(i*3);
    }
    return r;
}

int solve(vi const& v){
    mii prev,next;
    prev[v[0]]=eval(v[0]);
    rep(i,4){
        next.clear();
        each(e,prev){
            int bef=eval(e.first);
            rep(f,1<<8){
                int x=flip(e.first,f),y=flip(v[i+1],f);
                int t=e.second-bef+eval(x)+eval(y);
                next[y]=max(next[y],t);
            }
        }
        swap(prev,next);
    }
    int ans=0;
    each(e,prev)ans=max(e.second,ans);
    return ans;
}

int main(){
    int n;cin>>n;
    rep(x,n){
        vi v(5);
        rep(i,5)rep(j,5){
            int t;cin>>t;
            v[i]<<=3;
            v[i]|=t;
        }
        cout<<solve(v)<<endl;
    }
}

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

int main(){
	int n;
	long long k;
	std::cin>>n;
	std::cin>>k;

	std::vector<long long> aList(n);
	std::vector<long long> fList(n);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	for(int i=0; i<n; i++)
		std::cin>>fList[i];

	std::sort(aList.begin(), aList.end(), [](long long x, long long y){return x<y;});
	std::sort(fList.begin(), fList.end(), [](long long x, long long y){return x>y;});

	std::vector<long long> product(n);

	for(int i=0; i<n; i++)
		product[i]= aList[i]* fList[i];

	long long left= -1;
	long long right= 0;

	for(int i=0; i<n; i++)
		right+= product[i];

	while(right-left> 1){
		long long center= (left+right)/2;
		long long sum= 0;

		for(int i=0; i<n; i++){
			long long newA= center/fList[i];
			sum+= (aList[i] > newA)? (aList[i] - newA) : 0;
		}

		if(sum<= k)
			right= center;
		else
			left= center;
	}

	std::cout<<right<<std::endl;

	return 0;
}

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

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define ll long long;

int main() {
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  int i=0;
  while(s[i]!="") {
    char c = s[i][0];
    s[i].erase(s[i].begin());
    if(c=='a') {
      i=0;
    } else if(c=='b') {
      i=1;
    } else {
      i=2;
    }
  }
  string ans;
  if(i==0) {
    ans = 'A';
  } else if(i==1) {
    ans = 'B';
  } else {
    ans = 'C';
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3588
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	mapString := make(map[string]int)

	result := "yes"
	for i := 0; i < len(s); i++ {
		mapString[string(s[i])]++
		if mapString[string(s[i])] > 1 {
			result = "no"
			break
		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 512
from collections import defaultdict

n, m = map(int, input().split())
ab = defaultdict(int)
for _ in range(n):
    a, b = map(int, input().split())
    ab[a] += b

ans = 0
remain = m
for k in sorted(ab.keys()):
    if remain <= ab[k]:
        ans += k * remain
        break
    ans += k * ab[k]
    remain -= ab[k]
print(ans)


Measured memory_bytes: 18140
from fractions import Fraction


a,b = map(int,input().split(" "))
total = 0

for i in range(1,a+1):
    j = 0
    still = True
    while still:
        if b <= i * (2 ** j):
            still = False
        else:
            j = j+1
    total += Fraction(1,a)*Fraction(1,2 ** j)

print(float(total))

Measured memory_bytes: 5688
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,p;
	cin>>n>>p;
	unsigned long long a,cnt=0,ans=0;
	rep(i,n){
		cin>>a;
		cnt+=a%2?1:0;
	}
	unsigned long long nCr[cnt+1][cnt+1];
	rep(i,cnt+1){
		rep(j,cnt+1){
			if(i<j)nCr[i][j]=0;
			else if(i==0||j==0)nCr[i][j]=1;
			else nCr[i][j]=nCr[i-1][j]+nCr[i-1][j-1];
		}
	}
	if(p==1){
		if(cnt>0){
			for(int i=1;i<=cnt;i+=2){
				ans+=nCr[cnt][i]*pow(2,n-cnt);
			}
		}
	}else{
		for(int i=0;i<=cnt;i+=2){
			ans+=nCr[cnt][i]*pow(2,n-cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int min = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    int sum = 0;
    for (int j =0;; j++) {
      if (x % 2 == 0) {
        sum += 1;
        x /= 2;
      }
      else {
        break;
      }
    }
    if (i == 0) {
      min = sum;
    }
    if (sum < min) {
      min = sum;
    }
  } 
  cout << min << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;

#define MP make_pair
typedef long long ll;

ll powll(ll powllnum,ll powlljou){
    if(powlljou==1){
        return powllnum;
    }else if(powlljou==0){
        return 1;
    }else if(powlljou%2==0){
        ll powlltmp=powll(powllnum,powlljou/2);
        return powlltmp*powlltmp;
    }else{
        ll powlltmp=powll(powllnum,powlljou-1);
        return powlltmp*powllnum;
    }
}


const ll INF = powll(2,31)-1;

template <typename T>
class SegmentTree {
  ll n;
  vector<T> node;
  function<T(T, T)> fun, fun2;
  bool customChange;
  T outValue, initValue;
public:
  void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) {
    // changeFunction: (input, beforevalue) => newvalue
    fun = resultFunction;
    fun2 = changeFunction;
    customChange = changeFunction != NULL;
    n = 1;
    while (n < num) n *= 2;
    node.resize(2 * n - 1);
    fill(node.begin(), node.end(), init);
    outValue = out;
    initValue = init;
  }
  void valueChange(ll num, T value) {
    num += n-1;
    if (customChange) node[num] = fun2(value, node[num]);
    else node[num] = value;
    while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
  }
  T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
    if (r == -1) r = n;
    if (a <= l && r <= b) return node[k];
    if (b <= l || r <= a) return outValue;
    ll mid = (l + r) / 2;
    return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
  }
};



int fndmin(int a,int b){
    return min(a,b);
}






int main(void) {

    int n,q,com,x,y;

    cin>>n>>q;

    SegmentTree<int> sgt;


    sgt.init(n,fndmin,INF,INF);

    for (int i = 0; i < q; i++) {
        cin>>com>>x>>y;

        if(com==0)sgt.valueChange(x,y);
        else {
           cout<<sgt.rangeQuery(x,y+1)<<"\n";

        }
    }

    
    
    return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    pair<pair<string, int>, int> p[110];
    string name;
    int score;
    rep(i, n) {
        cin >> name >> score;
        p[i] = make_pair(make_pair(name, -score), i + 1);
    }

    sort(p, p + n);
    rep(i, n) { cout << p[i].second << endl; }
}

Measured memory_bytes: 3652