akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<998244353>;

int cnt[101010];
int v[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int mx_dist = 0;
    rep(i,n) {
        int t;cin>>t;
        v[i] = t;
    }
    rep(i,n){
        cnt[v[i]]++; 
    }
    rep(i,n){
        mx_dist = max(mx_dist, v[i]);
    }
    if(v[0] != 0 || cnt[0]!=1){
        cout<<'0'<<endl;
        return 0;
    }
    mint ans = 1;
    for(int i=1; i<=mx_dist; i++){
        if(cnt[i] == 0) {
            ans=0;
            break;
        }
        // ans *= modpow((ll)cnt[i-1], (ll)cnt[i], MOD)%MOD;
        ans *= modpow(mint(cnt[i-1]), cnt[i]);
        // for(int j=0; j<cnt[i]; j++) ans = ans * cnt[i-1] % MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
/**
 *      ABC 44 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-20 07:25:19
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, K; cin >> N >> K;
    int X, Y; cin >> X >> Y;
    if (K >= N){
        cout << N * X << endl;
    }
    else {
        cout << K * X + (N - K) * Y << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n;
	cin >> n;
	map<int, int> mapa;
	map<int, int>::iterator it;
	
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		mapa.insert(mp(x, i));
	}
	
	for(it = mapa.begin(); it != mapa.end(); it++){
		cout << it->second << " ";
	}
	
	
	
	
	
	
	
	return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define INF 1000000000000000000
#define PI 3.14159265358979323846
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<piii> viii;

const int MAXN = 100100;

int n, d;
int points[25][15];
bool sqr[20000];

int getDist (int a, int b) {
    int ret = 0;
    FOR(i, 0, d-1) {
        ret += (points[a][i]-points[b][i])*(points[a][i]-points[b][i]);
    }
    return ret;
}

int main()
{
    FAST_IO;

    for (int i = 0; i*i < 20000; i++) {
        sqr[i*i] = true;
    }

    cin >> n >> d;
    FOR(i, 0, n-1) FOR(j, 0, d-1) cin >> points[i][j];

    int cnt = 0;
    FOR(i, 0, n-1) FOR(j, i+1, n-1) {
        int dist = getDist(i,j);
        if (sqr[dist]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
    return b != 0 ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

int main(void)
{
    long long a,b,c,d;
    cin >>a >>b >>c >>d;

    long long e = lcm(c, d);

    long long divideC = b / c - (a-1) / c;
    long long divideD = b / d - (a-1) / d;
    long long divideLcm = b / e - (a-1) / e;

    printf("%lld\n", b -a+1 - (divideC+divideD-divideLcm));


    return 0;
}

Measured memory_bytes: 256
#include<regex>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  string s;
  cin>>s;
  cout<<(regex_match(s,regex("A?KIHA?BA?RA?"))?"YES":"NO")<<endl;
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> v[200010];
int A[200010];
bool isOK(int index, int key) {
    int size = v[index].size();
    if (v[index][size - 1] < key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key, int size) {
    int ng = -1;
    int ok = size;

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N) cin >> A[i];
    int size = 0;
    rep(i, N) {
        int idx = binary_search(A[i], size);
        v[idx].push_back(A[i]);
        size = max(size, idx + 1);
    }
    cout << size << endl;

    return 0;
}


Measured memory_bytes: 8448
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct node{
    int y,x,t,cost;
    node(int y,int x,int t,int cost):y(y),x(x),t(t),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};

const int MAX=INT_MAX/10;
typedef vector<vvi> vvvi;
int dx[]={-1,0,1,0,0},dy[]={0,-1,0,1,0};

int main(){
    int n,m;
    while(cin>>n>>m,n){
        vvi field(n,vi(m));
		pii girl,ghost;
        REP(i,n){
			string s;
			cin>>s;
			REP(j,s.size()){
				switch(s[j]){
				case 'A':
					girl=make_pair(i,j);
					break;
				case 'B':
					ghost=make_pair(i,j);
					break;
				case '.':
					field[i][j]=0;
					break;
				case '#':
					field[i][j]=1;
					break;
				default:
					assert(0);
				}
			}
        }
		string pattern;
		cin>>pattern;
		int len=pattern.size()*50;

		vector<pii> glocs;
		REP(i,len){
			glocs.push_back(ghost);
			switch(pattern[i%pattern.size()]){
			case '2':
				if(ghost.first<n-1)ghost.first++;break;
			case '4':
				if(ghost.second>0)ghost.second--;break;
			case '8':
				if(ghost.first>0)ghost.first--;break;
			case '6':
				if(ghost.second<m-1)ghost.second++;break;
			case '5':
				break;
			default:
				assert(0);
			}
		}
        
        priority_queue<node> q;
		q.push(node(girl.first,girl.second,0,0));
        vvvi cost(n,vvi(m,vi(len,MAX)));
		cost[girl.first][girl.second][0]=0;
        while(!q.empty()){
            node cnode=q.top();q.pop();
            if(cost[cnode.y][cnode.x][cnode.t]<cnode.cost){
                continue;
            }
			REP(i,5){
				int x=cnode.x+dx[i];
				int y=cnode.y+dy[i];
				if(x>=0&&y>=0&&x<m&&y<n&&field[y][x]==0){
					int newcost=cnode.cost+1;
					int t=cnode.t+1;
					if(t<len&&cost[y][x][t]>newcost){
						cost[y][x][t]=newcost;
						q.push(node(y,x,t,newcost));
					}
				}
            }
        }
		int ans=MAX;
		pii ansloc;
		REP(i,len){
			int c=cost[glocs[i].first][glocs[i].second][i];
			if(c<ans){
				ans=c;
				ansloc=glocs[i];
			}
		}
		if(ans==MAX){
			cout<<"impossible"<<endl;
		}else{
			cout<<ans<<" "<<ansloc.first<<" "<<ansloc.second<<endl;
		}
    }
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

const int NLET = 26;

int main()
{
    int N, Q;
    cin >> N;
    string S;
    cin >> S;
    cin >> Q;
    vector<set<int>> m(NLET);
    rep(i,N) {
        m[S[i] - 'a'].insert(i);
    }
    int typ, ans;
    vector<int> ansList;
    rep(i,Q) {
        cin >> typ;
        if (typ == 1) {
            int iq; cin >> iq; iq--;
            char cq; cin >> cq;
            if (S[iq] == cq) continue;
            m[S[iq] - 'a'].erase(iq);
            m[cq - 'a'].insert(iq);
            S[iq] = cq;
        }
        else {
            int lq, rq;
            cin >> lq >> rq;
            lq--; rq--;
            ans = 0;
            rep(i, NLET) {
                auto ls = m[i].lower_bound(lq);
                auto rs = m[i].upper_bound(rq);
                if (ls != rs) ans++;
            }
            ansList.push_back(ans);
        }
    }
    for (auto ans : ansList)
        cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 26372
#include <stdio.h>

int main(){
  long int N, K;
  scanf("%ld %ld", &N, &K);
  long int count = 0;
  for(long int a = 1; a <= N; a++){
    if(2*a % K == 0){
      count += ((N-a)/K + (a-1)/K + 1)*((N-a)/K + (a-1)/K + 1);
    }
  }
  printf("%ld\n", count);
  return 0;
}

/*
a+b,b+c,c+aがKの倍数であるための必要十分う条件は，
2*a,b-a,c-aがKの倍数であること．
2*aがKの倍数となるような1以上N以下の整数aを一つ固定したとき，
1-a以上N-a以下のKの倍数の個数は
  (N-a)/K + (a-1)/K + 1
となるから，b-a, c-aがKの倍数となるような
1以上N以下の整数の組(b, c)の個数は
  ((N-a)/K + (a-1)/K + 1)*((N-a)/K + (a-1)/K + 1)
となる．
*/


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[50],b[50],c[50];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
for(int i=0;i<n-1;i++)cin>>c[i];
int s=0;
for(int i=0;i<n;i++){
if(a[i]+1==a[i+1]){s+=c[a[i]-1];}
s+=b[a[i]-1];
}
cout<<s<<'\n';
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(v: usize, n: usize, used: usize) -> usize {
    if v > n {
        return 0;
    }
    let mut ret = 0;
    if used == 7 {
        ret = 1;
    }
    for i in 0..3 {
        let nused = used | (1 << i);
        let t = [7, 5, 3][i];
        let nv = v * 10 + t;
        ret += calc(nv, n, nused);
    }
    return ret;
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut city = vec![(0, 0, 0); m];
    for i in 0..m {
        city[i].1 = read::<usize>() - 1;
        city[i].0 = read::<usize>();
        city[i].2 = i;
    }
    city.sort();
    let mut cnts = vec![0; n];
    let mut anss = vec![(0, "".to_string()); m];
    for i in 0..m {
        let c = city[i].1;
        cnts[c] += 1;
        anss[i].0 = city[i].2;
        anss[i].1 = format!("{:06}{:06}", c + 1, cnts[c]);
    }
    anss.sort();
    for i in 0..m {
        println!("{}", anss[i].1);
    }
}


Measured memory_bytes: 17916
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 5005;
const int INF = 0x3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

char s[MAXN], mn, ans[MAXN >> 1][MAXN];
int n, k, mxl, t;

void init() {
	read(n); read(k);
	scanf("%s", s + 1);
	mn = 'z';
	for (int i = 1; i <= n; ++i) {
		mn = min(mn, s[i]);
	}
	if (k >= 14) {
		for (int i = 1; i <= n; ++i) {
			putchar(mn);
		}
		exit(0);
	}
	for (int i = 1, j = 0; i <= n; ++i) {
		if (s[i] != mn) {
			j = 0;
		} else {
			mxl = max(mxl, ++j);
		}
	}
} 

inline bool check(int x, int y) {
	for (int i = 1; i <= n; ++i) {
		if (ans[x][i] < ans[y][i]) return 1;
		if (ans[x][i] > ans[y][i]) return 0;
	}
	return 0;
}

void solve() {
	for (int i = 1, j = 0; i <= n; ++i) {
		if (s[i] != mn) {
			j = 0;
		} else if ((++j) == mxl || i == n) {
			++t;
			if (i == n) {
				int tmp = min(n, j << k), x, y;
				for (x = 1; x <= tmp; ++x) {
					ans[t][x] = mn;
				}
				for (y = n - j; x <= n && y; ++x, --y) {
					ans[t][x] = s[y];
				}
			} else {
				int tmp = min(n, j << (k - 1)), x, y;
				for (x = 1; x <= tmp; ++x) {
					ans[t][x] = mn;
				}
				for (y = i + 1; x <= n && y <= n; ++x, ++y) {
					ans[t][x] = s[y];
				}
				for (y = n; x <= n && y; ++x, --y) {
					ans[t][x] = s[y];
				}
			}
		}
	}
	int p = 1;
	for (int i = 2; i <= t; ++i) {
		if (check(i, p)) p = i;
	}
	for (int i = 1; i <= n; ++i) {
		putchar(ans[p][i]);
	}
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 8448
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
		// System.err.println(System.currentTimeMillis() - t);
	}

	class E {
		int s;
		int d;
		int c;

		public E(int s_, int d_, int c_) {
			s = s_;
			d = d_;
			c = c_;
		}
	}

	@SuppressWarnings("unchecked")
	public void run() {
		Scanner sc = new Scanner(System.in);
		// int n = sc.nextInt();
		// int m = sc.nextInt();
		// int r = sc.nextInt();
		// int t = sc.nextInt();
		// ArrayList<E>[] g = new ArrayList[n];
		// for (int i = 0; i < n; ++i) {
		// g[i] = new ArrayList<>();
		// }
		// for (int i = 0; i < m; ++i) {
		// int a = sc.nextInt();
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// --a;
		// --b;
		// g[a].add(new E(a, b, c));
		// g[b].add(new E(b, a, c));
		// }
		// int[][] dist = new int[n][n];
		// for (int i = 0; i < n; ++i) {
		// for (int j = 0; j < n; ++j) {
		// if (i != j)
		// dist[i][j] = Integer.MAX_VALUE / 3;
		// }
		// }

		int n = sc.nextInt();
		ArrayList<E>[] g = new ArrayList[n];
		for (int i = 0; i < n; ++i)
			g[i] = new ArrayList<>();
		for (int i = 0; i < n; ++i) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; ++j) {
				int v = sc.nextInt();
				int c = sc.nextInt();
				g[u].add(new E(u, v, c));
			}
		}

		int[] dist = dijkstra(0, g);
		for (int i = 0; i < n; ++i) {
			System.out.println(i + " " + dist[i]);
		}
	}

	int[] dijkstra(int src, ArrayList<E>[] g) {
		class State implements Comparable<State> {
			int s;
			int d;

			public State(int s_, int d_) {
				s = s_;
				d = d_;
			}

			public int compareTo(State o) {
				return Integer.compare(d, o.d);
			};

		}

		int n = g.length;
		int[] dist = new int[n];
		Arrays.fill(dist, Integer.MAX_VALUE / 3);
		dist[src] = 0;
		PriorityQueue<State> pq = new PriorityQueue<>();
		pq.add(new State(src, 0));
		while (!pq.isEmpty()) {
			State state = pq.poll();
			if (dist[state.s] < state.d)
				continue;
			for (E e : g[state.s]) {
				if (dist[e.d] > dist[e.s] + e.c) {
					dist[e.d] = dist[e.s] + e.c;
					pq.add(new State(e.d, dist[e.d]));
				}
			}
		}
		return dist;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 40864
N, Q = [int(item) for item in input().split()]

tree_list = [input().split() for j in range(1, N)]

query_list = [input().split() for k in range(Q)]
query_list_int = [[int(k) for k in i] for i in query_list]

val_list = [0 for _ in range(N)]

linked_node_list = [[] for _ in range(N)]

for a, b in tree_list:
    a, b = int(a)-1, int(b) -1
    linked_node_list[a].append(b)
    linked_node_list[b].append(a)


for index, val in query_list_int:
    val_list[index-1] += val

stack = [0]
parent = [0] * (N+1)

while True:
    v=stack.pop()
    for child in linked_node_list[v]:
        if child != parent[v]:
            parent[child] = v
            stack.append(child)
            val_list[child] += val_list[v]
    if not stack:
        break

print(*val_list)


Measured memory_bytes: 208132
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    string s;
    cin >> s;
    ll count[2] = { 0, 0 };
    for (ll i = 0; i < ll(s.size()); i++)
    {
        count[s[i] - '0']++;
    }
    ll c = count[0] < count[1] ? count[0] : count[1];
    cout << c * 2;
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == N - 1 && S != "Y") {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int visited[200010],update,n,m;
vector<vector<int>> vt;
void dfs(int here, int depth)
{
	
	if (here == n)update = 1;
	if (depth == 3)return;
	for (int i = 0; i < vt[here].size(); i++)
	{
		int next = vt[here][i];
		if (visited[next] > depth + 1)
		{
			dfs(next, depth + 1);
		}
	}
}
int main()
{
	scanf("%d %d", &n, &m);
	vt.resize(n + 1);
	for (int i = 1; i <= n; i++)
		visited[i] = 12345;
	for (int i = 0; i < m; i++)
	{
		int q, w;
		scanf("%d %d", &q, &w);
		vt[q].push_back(w);
		vt[w].push_back(q);
	}
	dfs(1,1);
	if (update)
		puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 12784
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
 
 
public class Main{
	
	public static class Walk implements Comparable<Walk> {
		int pos;
		int money;
		int danger;
		
		public Walk(int pos, int money, int danger) {
			super();
			this.pos = pos;
			this.money = money;
			this.danger = danger;
		}

		@Override
		public int compareTo(Walk arg0) {
			return this.danger == arg0.danger ? arg0.money - this.money : this.danger - arg0.danger;
		}
		
	}
	
    public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	
    	while(true){
    		final int N = sc.nextInt();
    		final int M = sc.nextInt();
    		final int L = sc.nextInt();
    		
    		if(N == 0 && M == 0 && L == 0){
    			break;
    		}
    		
    		int[][] adj = new int[N][N];
    		int[][] warn = new int[N][N];
    		
    		for(int i = 0; i < N; i++){
    			for(int j = 0; j < N; j++){
    				adj[i][j] = -1;
    				warn[i][j] = -1;
    			}
    		}
    		
    		for(int i = 0; i < M; i++){
    			final int A = sc.nextInt() - 1;
    			final int B = sc.nextInt() - 1;
    			final int D = sc.nextInt();
    			final int E = sc.nextInt();
    			
    			adj[A][B] = adj[B][A] = D;
    			warn[A][B] = warn[B][A] = E;
    		}
    		
    		boolean[][] is_visited = new boolean[N][L + 1];
    		
    		PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
    		queue.add(new Walk(0, L, 0));
    		
    		while(!queue.isEmpty()){
    			Walk walk = queue.poll();
    			
    			if(is_visited[walk.pos][walk.money]){
    				continue;
    			}else{
    				is_visited[walk.pos][walk.money] = true;
    			}
    			
    			if(walk.pos == N - 1){
    				System.out.println(walk.danger);
    				break;
    			}
    			
    			for(int to = 0; to < N; to++){
    				if(adj[walk.pos][to] < 0){
    					continue;
    				}
    				
    				if(walk.money >= adj[walk.pos][to]){
    					final int new_money = walk.money - adj[walk.pos][to];
    					final int new_pos   = to;
    					
    					if(!is_visited[new_pos][new_money]){
    						queue.add(new Walk(new_pos, new_money, walk.danger));
    					}
    				}
    				
    				if(!is_visited[to][walk.money]){
    					queue.add(new Walk(to, walk.money, walk.danger + warn[walk.pos][to]));
    				}
    			}
    		}
    		
    	}
    	
    	
    	
    }
     
}

Measured memory_bytes: 61432
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n;
	cin>>n;
	cout<<48-n;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int l = 0;
    int r = 1e9;
    auto f = [&](int x) {
        int tmp = 0;
        rep(i,n) {
            tmp += (a[i]-1)/x;
        }
        return tmp <= k;
    };
    while (r-l>1) {
        int c = (l+r)/2;
        if (f(c)) r = c;
        else l = c;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}

void add(ll &a, ll b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

void Main()
{
	ll h,w;
	cin>>h>>w;
	VS grid(h);
	rep(i, h) cin >> grid[i];
	VVI dp(h*2,VI(w*2,0));
	dp[0][0]=1;
	rep(j,h){
		rep(i,w){
			//行き止まり
			if (j+1<h&&grid[j+1][i] == '.')	add(dp[j+1][i],dp[j][i]);
			if (i+1<w&&grid[j][i+1] == '.')	add(dp[j][i+1],dp[j][i]);
		}
	}
	ll res=dp[h-1][w-1];
	res%=MOD;
	cout << res<< "\n";
	return;
}

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


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

void make_pat(int count, char pat[])
{
	int d = 0;
	
	pat[0] = '\0';
	if (count % 3 == 0){
		d = 1;
		strcat(pat, "Fizz");
	}
	if (count % 5 == 0){
		d = 1;
		strcat(pat, "Buzz");
	}
	if (d == 0){
		sprintf(pat, "%d", count);
	}
}

int main(void)
{
	int n; // ­¾ñ
	int m; // lÌ
	int butt;
	int out[1000];
	char flag[1000];
	char in[100];
	char pat[100];
	
	while (1){
		memset(flag, 1, 1000);
		
		scanf("%d%d", &m, &n);
		if (m == 0 || n == 0){
			break;
		}
		
		butt = m;
		int check = 0;
		for (int i = 0; i < n; i++){
			scanf("%s", in);
			
			if (butt == 1){
				continue;
			}
			
			while (flag[check] == 0){
				check = (check + 1) % m;
			}
			
			make_pat(i + 1, pat);
			if (strcmp(pat, in) != 0){
				flag[check] = 0;
				butt--;
			}
			check = (check + 1) % m;
		}
		
		int count = 0;
		for (int i = 0; i < m; i++){
			if (flag[i] == 1){
				out[count++] = i + 1;
			}
		}
		
		printf("%d", out[0]);
		for (int i = 1; i < count; i++){
			printf(" %d", out[i]);
		}
		
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
using namespace std;
#define int long long
int inv(int x){
    if(x==1)
        return 2;
    else
        return 1;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<int>p(A);vector<int>q(B);vector<int>r(C);
    for(int i = 0; i < A; i++) cin >> p[i];
    for(int i = 0; i < B; i++) cin >> q[i];
    for(int i = 0; i < C; i++) cin >> r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    vector<int>l;
    for(int i = 0; i < X; i++)
        r.push_back(p[i]);
    for(int i = 0; i < Y; i++)
        r.push_back(q[i]);
    sort(r.rbegin(),r.rend());
    int ans = 0;
    for(int i = 0; i < (X+Y); ++i){
        ans += r[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6384
#include <stdio.h>

int main(){
	
	int i,j,str;
	int mt[10],high[3]={0};
	
	for(i=0;i<10;i++){
		
		scanf("%d",&mt[i]);
	}
	for(i=0;i<9;i++){
		for(j=0;j<9-i;j++){
			if(mt[j]<mt[j+1]){
				
				str = mt[j];
				mt[j] = mt[j+1];
				mt[j+1] = str;
			}
		}
	}
	for(i=0;i<3;i++)	printf("%d\n",mt[i]);
	
	return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

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

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int tot=(h2-h1)*60+(m2-m1);
    cout << tot-k;
    
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;


int main (int argc, char const *argv[])
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    
    if (abs(a-c)<=d) {
        cout<<"Yes"<<endl;
    }else 
    if (abs(a-b)<=d&&abs(b-c)<=d) {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d%d', $H, $W);
$left = $H * $W;
for($y = 0; $y < $H; $y++){
    $map[$y] = str_split(fgets(STDIN));
    for($x = 0; $x < $W; $x++){
        if($map[$y][$x] == '#'){
            $list[$y][$x] = 1;
            $left--;
        }
    }
}
$HM = $H - 1;
$WM = $W - 1;
$count = 0;
while($left){
    $count++;
    $nextList = [];
    foreach($list as $y => $xs)foreach($xs as $x => $_){
        if($x && $map[$y][$x-1] == '.'){$nextList[$y][$x-1] = $map[$y][$x-1] = 1;$left--;}
        if($y && $map[$y-1][$x] == '.'){$nextList[$y-1][$x] = $map[$y-1][$x] = 1;$left--;}
        if($x < $WM && $map[$y][$x+1] == '.'){$nextList[$y][$x+1] = $map[$y][$x+1] = 1;$left--;}
        if($y < $HM && $map[$y+1][$x] == '.'){$nextList[$y+1][$x] = $map[$y+1][$x] = 1;$left--;}
    }
    $list = $nextList;
}
echo $count;


Measured memory_bytes: 123384
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a>=1&&b>=1&&a<=100&&b<=100){
    if(a<=2*b)
        cout<<0<<endl;
    else
        cout<<(a-2*b)<<endl;
}
return 0;}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main() {
  while(true) {
    string s1;
    cin>>s1;
    if(s1==".")
      break;
    string s2;
    cin>>s2;
    bool foundDiff=false;
    bool different=false;
    auto it1=s1.begin(),it2=s2.begin();
    for(;it1!=s1.end()&&it2!=s2.end();++it1,++it2){
      if(*it1!=*it2){
        different=true;
        break;
      } else if(*it1=='"'){
        ++it1; ++it2;
        string mojiretsu1, mojiretsu2;
        while(*it1!='"')mojiretsu1+=*it1,++it1;
        while(*it2!='"')mojiretsu2+=*it2,++it2;
        if (mojiretsu1!=mojiretsu2){
          if(foundDiff) {
            different=true;
            break;
          }
          foundDiff=true;
        }
      }
    }
    if (it1!=s1.end()||it2!=s2.end()||different)
      cout<<"DIFFERENT";
    else if(foundDiff)
      cout<<"CLOSE";
    else
      cout<<"IDENTICAL";
    cout<<endl;

  }
  return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int M1,D1;
    int M2,D2;
    cin>>M1>>D1;
    cin>>M2>>D2;
    if(M1!=M2){
        cout<<1;
    }else{
        cout<<0;
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    int a,b;
    ld x=0, y=0;
    int deg=90;
    // cout << cosl(3.14) << endl;
    while(cin >> a>>c>>b, a|b){
      ld ar = deg*acosl(-1)/180;
      x+=a*cosl(ar);
      y+=a*sinl(ar);
      deg-=b;
    }
    cout << int(x) << endl;
    cout << int(y) << endl;
    return 0;
}



Measured memory_bytes: 3456
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for _ in range(N):
    A = list(map(int, input().split()))
    sum = 0
    for i in range(M):
        sum += B[i] * A[i]
    sum += C
    if sum > 0:
        ans += 1
print(ans)


Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;

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

  vector<int> x(m);
  vector<int> gap(m-1);
  int sum = 0;

  for(int i = 0; i < m; i++) cin >> x[i];

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

    for(int i = 0; i < m; i++){
      if(i != 0){
        gap[i-1] = abs(x[i]-x[i-1]);
        sum += gap[i-1];
      }
    }

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

    if(m < n) n = m;
    for(int i = 0; i < n-1; i++) sum -= gap[gap.size()-1-i];

    cout << sum << endl;


  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int N;
	scanf("%d",&N);
	
	string s,t;
	cout << 0 << endl;
	cin >> s;
	if(s[0] == 'V')return 0;
	cout << N-1 << endl;
	cin >> t;
	if(t[0] == 'V')return 0;
	
	int l = 0, r = N-1;
	while(l+2 < r){
		int m = (l+r)/2;
		if(m&1)m ++;
		string u;
		cout << m << endl;
		cin >> u;
		if(u[0] == 'V')return 0;
		if(s == u)l = m;
		else r = m;
	}
	cout << l+1 << endl;
}



Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
//komennto C+udekaijo

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int a=0,b=0;
	rep(i,int(s.length())){
		if(s[i]=='0')a++;
		if(s[i]=='1')b++;
	}
	cout<<((a>b)?b:a)*2<<endl;



	return 0;
}


Measured memory_bytes: 512
// Aizu Vol-5 0523: Card GameI
// 2017.8.30 bal4u@uu

#include <stdio.h>

#define TARO 0
#define HANA 1
#define NONE 2

char c[210];
int ba;

int main()
{
	int n, a;
	int t, i, m[2];

	while (scanf("%d", &n) && n) {
		for (i = 1; i <= n+n; i++) c[i] = HANA;
		for (i = 1; i <= n; i++) scanf("%d", &a), c[a] = TARO;
		m[0] = m[1] = n, t = TARO, ba = 0;
		while (m[0] > 0 && m[1] > 0) {
			for (i = ba + 1; i <= n+n; i++) {
				if (t == c[i]) { ba = i, c[i] = NONE, m[t]--; break; }
			}
			if (i > n+n) ba = 0;
			t = !t;
		}
		printf("%d\n%d\n", m[HANA], m[TARO]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Info{
	Info(ll arg_value){
		value = arg_value;
	}
	bool operator<(const struct Info &arg) const{

		return value < arg.value; //降順
	}

	ll value;
};
struct Data{
	Data(ll arg_value){

		value = arg_value;
	}
	bool operator<(const struct Data &arg) const{

		return value > arg.value; //昇順
	}

	ll value;
};


ll N;
ll A[3*SIZE];
ll L[3*SIZE],R[3*SIZE];



int main(){

	scanf("%lld",&N);

	for(ll i = 0; i < 3*N; i++){

		scanf("%lld",&A[i]);
	}


	priority_queue<Data> LQ; //上位N件を持つPQ

	//左の上位N件を求める
	ll sum = 0;
	for(ll i = 0; i < N; i++){

		sum += A[i];
		LQ.push(Data(A[i]));
	}
	L[N-1] = sum;
	//printf("L sum:%lld\n",sum);

	for(ll i = N; i <= 2*N-1; i++){

		if(A[i] > LQ.top().value){

			sum -= LQ.top().value;
			LQ.pop();
			LQ.push(Data(A[i]));
			sum += A[i];
		}
		L[i] = sum;
		//printf("L[%lld]:%lld\n",i,L[i]);
	}

	priority_queue<Info> RQ; //下位N件を持つPQ

	//右の下位N件を求める
	sum = 0;
	for(ll i = 3*N-1; i >= 2*N; i--){

		sum += A[i];
		RQ.push(Info(A[i]));
	}
	R[2*N] = sum;
	//printf("R sum:%lld\n",sum);

	for(ll i = 2*N-1; i >= N; i--){

		if(A[i] < RQ.top().value){
			//printf("A[%lld]:%lld top:%lld\n",i,A[i],RQ.top().value);
			sum -= RQ.top().value;
			RQ.pop();
			RQ.push(Info(Info(A[i])));
			sum += A[i];
			//printf("sum;%lld\n",sum);
		}
		R[i] = sum;
		//printf("R[%lld]:%lld\n",i,R[i]);
	}

	ll ans = -HUGE_NUM;
	for(ll i = N-1; i <= 2*N-1; i++){

		ans = max(ans,L[i]-R[i+1]);
	}

	printf("%lld\n",ans);

	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin() (x).end()

int n,m;
string s;
string IO="IO";

int main(){
	while(cin>>n && n) {
        cin >> m >> s;
        int cur = 0;
        string tg = "";
        rep(i,2*n+1) tg += IO[cur%2], cur++;
        //cout<<tg<<endl;
        int ans = 0;
        rep(i,m-n+1) {
            string t = s.substr(i,2*n+1);
            if(t == tg) ans++;
        }
        cout << ans << "\n";
    }
	
	return 0;
}

Measured memory_bytes: 2120
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 62);
ll n,k, m, t; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}bool visit[410][410],b[410][410]; vector<vector<char>> c;
ll cc[2],ans = 0;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
void dfs(int x,int y) {
    cc[b[y][x]]++;
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 0 || ny < 0 || nx >= m || ny >= n) continue;
        if (visit[ny][nx] || b[ny][nx] == b[y][x])continue;
        visit[ny][nx] = 1;
        dfs(nx, ny);
    }
}
int main() {
    cin >> n >> m; vector<vector<char>> c(n, vector<char>(m));
    Fill(visit, 0);
    rep(i, n) {
        rep(j, m) {
            cin >> c[i][j];
            b[i][j] = (c[i][j] == '#');
        }
    }
    rep(i, n) {
        rep(j, m) {
            if (visit[i][j]) continue;
            visit[i][j] = 1;
            cc[0] = 0; cc[1] = 0;
            dfs(j, i);
            ans += cc[0] * cc[1];
        }
    }cout << ans << endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	string s;
	int ans=0;
	cin >> s;
	rep(i,6){
		if(s[i]=='1') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define For(i,n) for(int i=0;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

int32_t main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	int ans= ((n/1000)+1)*1000-n;
	cout<<ans%1000<<endl;
	return 0;
}


Measured memory_bytes: 3648