akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;

typedef pair<int,pair<int,int> > pp;
#define F first
#define S second.first
#define T second.second
#define MK make_pair


int main(){
    while(1){
    
    
    
    
    
    
    
    const int M=-1000000000;
    bool a[40][40][40][40]={};
    int w,h;
    cin>>w>>h;
        if(w==0 && h==0){break;}
    for(int i=0;i<h;i++){
        for(int t=0;t<w-1;t++){
            int c;
            cin>>c;
            if(c==0){
                a[i][t][i][t+1]=true;
                a[i][t+1][i][t]=true;
            }
        }
        if(i!=h-1){
            for(int t=0;t<w;t++){
                int c;
                cin>>c;
                if(c==0){
                    a[i][t][i+1][t]=1;
                    a[i+1][t][i][t]=1;
                }
            }
        }
    }
    
    priority_queue<pp> q;
    pp t=MK(-1,MK(0,0));
    q.push(t);
    bool done[40][40]={};
    int dis[40][40];
    fill(&dis[0][0],&dis[39][40],M);
    dis[0][0]=-1;
    while(!q.empty()){
        pp n=q.top();
        q.pop();
        if(done[n.S][n.T]){continue;}
        done[n.S][n.T]=true;
        
        if(n.S!=h-1 && a[n.S][n.T][n.S+1][n.T] && dis[n.S+1][n.T]<dis[n.S][n.T]-1){
            dis[n.S+1][n.T]=dis[n.S][n.T]-1;
            pp k=MK(dis[n.S+1][n.T],MK(n.S+1,n.T));
            q.push(k);
        }
        if(n.S!=0 && a[n.S][n.T][n.S-1][n.T] && dis[n.S-1][n.T]<dis[n.S][n.T]-1){
            dis[n.S-1][n.T]=dis[n.S][n.T]-1;
            pp k=MK(dis[n.S-1][n.T],MK(n.S-1,n.T));
            q.push(k);
        }
        if(n.T!=w-1 && a[n.S][n.T][n.S][n.T+1] && dis[n.S][n.T+1]<dis[n.S][n.T]-1){
            dis[n.S][n.T+1]=dis[n.S][n.T]-1;
            pp k=MK(dis[n.S][n.T+1],MK(n.S,n.T+1));
            q.push(k);
        }
        if(n.T!=0 && a[n.S][n.T][n.S][n.T-1] && dis[n.S][n.T-1]<dis[n.S][n.T]-1){
            dis[n.S][n.T-1]=dis[n.S][n.T]-1;
            pp k=MK(dis[n.S][n.T+1],MK(n.S,n.T-1));
            q.push(k);
        }
    }
    /*
    cout<<endl;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            cout<<-1*dis[i][t]<<" ";
        }
        cout<<endl;
    }
    */
    cout<<(dis[h-1][w-1]==M? 0:-1*dis[h-1][w-1])<<endl;
        
        
        
        
        
        
        
        
    }
    
    
    return 0;
}


Measured memory_bytes: 5512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  for(int i=1;i<1000000;i++){
    ans+=n/i;
    if(n%i==0){
      ans--;
    }
    if(i>n) break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<cmath>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int C[600][600],W[600][600];

int main(){
  int N,x,y,ans=0;
  ll M,Q;
  cin>>N>>M>>Q;

  for(int i=0;i<M;i++){
    cin>>x>>y;
    C[x][y]++;
  }

  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++) W[i][j]=W[i][j-1]+C[i][j];
  }

  for(int i=0;i<Q;i++,ans=0){
    cin>>x>>y;
    for(int j=x;j<=y;j++){
      ans+=W[j][y];
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll memo[4003][2003];

ll com(ll n, ll k){
    if(k > n || k < 0 || n < 0) return 0;
    if(k == n || k == 0) return 1;
    if(memo[n][k]) return memo[n][k];
    return memo[n][k] = (com(n - 1, k) + com(n - 1, k - 1)) % MOD;
}

int main()
{
    int k, n;
    cin >> k >> n;
    ll p[2003];
    for(int i = 0; i <= k; i++){
        p[i] = com(n + k - 1 - i * 2, k - 1);
    }
    for(int i = 2; i <= k * 2; i++){
        int c = min(i / 2, (k * 2 + 2 - i) / 2);
        ll ans = 0;
        for(int j = 0; j <= c; j++){
            if(j & 1) ans = (ans + MOD - p[j] * com(c, j) % MOD) % MOD;
            else ans = (ans + p[j] * com(c, j) % MOD) % MOD;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 60800
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int m,n;
  cin>>m>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  if(m==2){
    Int ans1=0,ans2=0;
    for(Int i=0;i<n;i++){
      as[i]--;
      ans1+=(as[i]&1)==(i&1);
      ans2+=(as[i]&1)!=(i&1);
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
  }

  Int ans=0;
  Int lst=0,cnt=0;
  for(Int a:as){
    if(lst==a){
      cnt++;
      continue;
    }
    ans+=cnt/2;
    lst=a;
    cnt=1;
  }
  ans+=cnt/2;
  cout<<ans<<endl;
  return 0;
}



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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n,m;
	cin >> n >> m;
	string a[n];
	string b[n];
	int s;
	bool ans=false;
	FOR(i,n) cin >> a[i];
	FOR(i,m) cin >> b[i];
	FOR(i,n-m+1)
		FOR(j,n-m+1)
			{
				int k=0;
				while(k<m){
				if(a[j+k].substr(i,m)!=b[k]) { break;}
				k++;
				}
				if(k==m) {ans=true; break; }
			}
	if(ans)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>


int main()
{

    int n, i,m;
    for(i=1;i<10;i++){
        m=0;
        for(n=1;n<10;n++){
            printf("%dx%d=%d\n",i, n, i*n);
        }
    }

    return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int l[N];
    for (int i=0; i<N; i++){
        cin >> l[i];
    }
    sort(l, l+N, greater<int>());

    int max_length = 0;
    for (int i=0; i<K; i++){
        max_length += l[i];
    }
    cout << max_length << "\n";
    return 0;
}

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

#define INF INT_MAX
#define ll long long

using namespace std;

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

	for(int i = 0;i < s.size();i++){
		if(i == 5 || i == 13) cout << " ";
		else cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s; cin >> s;
	string t = s;
	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());
	if (t.size() == s.size()) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}


Measured memory_bytes: 3588
s=input() 
t=input() 
dp=[[0 for j in range(len(t)+1)] for i in range(len(s)+1)]
res=''  
for i in range(1,len(s)+1):
	for j in range(1,len(t)+1):
		if s[i-1]==t[j-1]: 
			dp[i][j]=1+dp[i-1][j-1] 
		else:
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]) 
length=dp[-1][-1] 
res=['']*(length+1)  
i=len(s) 
j=len(t) 
while i>0 and j>0:
	if s[i-1]==t[j-1]:
		res[length-1]=s[i-1] 
		i-=1 
		j-=1 
		length-=1 
	elif dp[i-1][j]>dp[i][j-1]:
		i-=1 
	else:
		j-=1  
print(''.join(res))

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

int main() {
 int A, B, K;
  cin >> A >> B >> K;
  
  vector<int> kouyaku(100);
  
  for(int i = 0; i < 100; i++) {
    if(A % (i + 1) == 0 && B % (i + 1) == 0) {
      kouyaku.at(i) = i + 1;
    }
    else {
      kouyaku.at(i) = 0;
    }
  }
    sort(kouyaku.begin(), kouyaku.end());
    
    cout << kouyaku.at(100 - K) <<endl;
      
 
return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
 
  ll N,A,B;
  cin >> N >> A >> B;
  
  //cout << (B - A)/2 << endl;
  
  if((B-A) % 2 == 0){
    cout << (B - A) / 2 << endl;
    //cout << "aaa" << endl;
  }else{
    if(A - 1 <= N - B){
      cout << (A + B - 1) / 2 << endl;
    }else{
      cout << N + ((1 - A - B) / 2) << endl;
      //cout << "aaa" << endl;
    }
  }

}

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

#define rep(X, Y) for( int X = 0; X < Y; ++X )
#define repi(X, Y, Z) for( int X = Y; X < Z; ++X )

int n;
long long array[5001];
long long max;

int main(){
	while( std::cin >> n, n ){
		max = std::numeric_limits<long long>::min();

		rep( i, n ) std::cin >> array[i + 1];

		rep( i, n ) array[i + 1] += array[i];

		rep( i, n + 1 ) repi( l, i + 1, n + 1 ){
			max = std::max( max, array[l] - array[i] );
		}

		std::cout << max << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1192
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (x, n) = readIs()
  if (n == 0) {
    println(x)
    return
  }
  val p = readIs().sorted()
  val q = p.binarySearch(x)
  if (q < 0) {
    println(x)
    return
  }
  var u = p.first() - 1
  run {
    (q - 1 downTo 0).forEachIndexed { i, j ->
      val a = x - i - 1
      if (a != p[j]) {
        u = a
        return@run
      }
    }
  }
  var v = p.last() + 1
  run {
    (q + 1 until n).forEachIndexed { i, j ->
      val a = x + i + 1
      if (a != p[j]) {
        v = a
        return@run
      }
    }
  }
  println(if (x - u <= v - x) u else v)
}


Measured memory_bytes: 39364
/******
	~site:    atcoder.jp
	~user:    Turkhuu
	~problem: AtCoder Beginner Contest 177 - B (abc177_b)
** **/

#include<bits/stdc++.h>

#define FFOR(i,s,e,k) for(int i=s;(k==1?i<=e:i>=e);i+=k)
#define FOR(i,n) FFOR(i,0,n-1,1)
#define FORR(i,s,e) FFOR(i,s,e,1)
#define ll long long
#define PQ priority_queue
#define pb push_back
#define ppb pop_back()
#define pp push
#define MIN(v) *min_element(v.begin(),v.end())
#define MAX(v) *max_element(v.begin(),v.end())
#define SORT(v) sort(v.begin(),v.end())
#define TROS(v) sort(v.rbegin(),v.rend())
#define CNT(v,x) count(v.begin(),v.end(),x)

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin>>s>>t;
	int ans=1001;
	FORR(i,0,s.size()-t.size()){
		string ss=s.substr(i,t.size());
		int dif=0;
		FOR(j,ss.size()) dif+=(ss[j]!=t[j]);
		ans=min(ans,dif);
	}
	cout<<ans;
}

Measured memory_bytes: 3636
s = int(input())

t = [s]
u = 0
v = 0

while u == 0:
    v += 1
    if s % 2 == 0:
        s = s//2
        t.append(s)
    else:
        s = 3*s + 1
        t.append(s)
    for i in range(0,v):
        if s == t[i]:
            u += 1

print(v+1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <fstream>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;

void solve() {
    int n, m; cin >> n >> m;
    int h[n], tmp[n];
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        tmp[i] = 1;
    }

    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b; a--; b--;
        if (h[a] == h[b]) {
            tmp[a] = 0;
            tmp[b] = 0;
        } else if (h[a] > h[b]) {
            tmp[b] = 0;
        } else if (h[a] < h[b]) {
            tmp[a] = 0;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += tmp[i];
    }

    cout << ans << endl;
}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


Measured memory_bytes: 4336
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip> 
#include <algorithm>
#include <queue>
#include <list>
#include <numeric>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>

using namespace std;

#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;

#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

const int N = int(2e5)+10;
const int K = int(1e6)+10;
// const int MOD = int(1e9)+7;
const int INF = int(1e9)+5;
const ll INF64 = 2e18;

// const ll MOD = 1e9 + 7;
// inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
// inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

int a[N],ans[N];
vi adj[N],seq;
int n;


void dfs (int s,int e) {
    if (seq.empty() || a[s] > seq.back()) {
        seq.pb(a[s]);
        ans[s] = sz(seq);
        for (auto x : adj[s]) {
            if (x == e) continue;
            dfs(x,s);
        }
        seq.pop_back();
    } else {
        int pos = lower_bound(all(seq),a[s]) - seq.begin();
        int temp = seq[pos];
        seq[pos] = a[s];
        ans[s] = sz(seq);
        for (auto x : adj[s]) {
            if (x == e) continue;
            dfs(x,s);
        }
        seq[pos] = temp;
    }
}


void solve () {
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
        ans[i] = 1;
    }
    for (int i=1;i<n;i++) {
        int u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
    for (int i=1;i<=n;i++) cout<<ans[i]<<endl;
}

int main () {
    FastIO
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t;
    // cin>>t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 27588
n = int(input())
s = input()

left = [0]*n
for i,c in enumerate(s):
    if i == n-1:
        continue
    left[i+1] = left[i] + ( 1 if c == "W" else 0 )

right = [0] * n
for i,c in reversed(list(enumerate(s))):
    if i == 0:
        continue
    right[i-1] = right[i] + ( 1 if c == "E" else 0 )

min_cost=99999999999999999999

for i in range(n):
    min_cost = min(min_cost, left[i] + right[i])

print(min_cost)

Measured memory_bytes: 58400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int syurui=(N+1)/2;
		int[] kosu=new int[syurui];
		for(int i=0; i<N; i++) {
			kosu[sc.nextInt()/2]++;
		}
		for(int i=0; i<(N+1)/2; i++) {
			if(N%2==0) {
				if(kosu[i]!=2) {
					System.out.println("0");
					System.exit(0);
				}
			}
			else {
				if(i>0) {
					if(kosu[i]!=2) {
						System.out.println("0");
						System.exit(0);
					}
				}
			}
		}
		long a=1;
		for(int i=0; i<N/2; i++) {
			a*=2;
			a%=1000000007;
		}
		System.out.println(a);

	}
	static class SC {

		private BufferedReader reader = null;

		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 31568
s = input()
a = [1 if i % 2 == 0 else 0 for i in range(len(s))]
b = [0 if i % 2 == 0 else 1 for i in range(len(s))]


da = 0
db = 0
for i in range(len(s)):
    if str(a[i]) != s[i]:
        da += 1
    if str(b[i]) != s[i]:
        db += 1

print(min(da, db))


Measured memory_bytes: 4724
# 初期入力
N_gu,M_ki = map(int, input().split())

# 最初に偶数をとると　残りはN_gu -1,M_ki
# 和が偶数とは　偶数＋偶数　OR　奇数＋奇数
from math import factorial

def kumiawase_num(n, r):
    if  n<r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))
def kumiawase_jufuku(n, r):
    if  n<r:
        return 0
    else:
        return kumiawase_num(n + r - 1, r)

gu_gu = kumiawase_num(N_gu , 2) #  
ki_ki = kumiawase_num(M_ki, 2)
print(gu_gu + ki_ki)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >> S ;
  if (S.size()<=K){
    cout << S << endl;
    return 0;
  }
  else{
      for (int  i=0 ; i<K ; i++){
          cout << S.at(i);
      }
      cout << "..." << endl;
  }
} 

Measured memory_bytes: 3624
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


class WeightedUnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
        self.par_weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            root = self.find(self.parents[x])
            self.par_weight[x] += self.par_weight[self.parents[x]]
            self.parents[x] = root
            return self.parents[x]

    def union(self, x, y, w):
        w = w + self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            self.par_weight[x] = -w
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            self.par_weight[y] = w

    def weight(self, x):
        if self.parents[x] < 0:
            return 0
        else:
            return self.par_weight[x] + self.weight(self.parents[x])

    def diff(self, x, y):
        if self.find(x) != self.find(y):
            raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
        return self.weight(y) - self.weight(x)


N, M = map(int, input().split())
uf = WeightedUnionFind(N)

ans = 'No'
for q in sys.stdin.readlines():
    L, R, D = map(int, q.split())
    L -= 1; R -= 1

    if uf.find(L) == uf.find(R):
        if uf.diff(L, R) != D:
            break
    else:
        uf.union(L, R, D)
else:
    ans = 'Yes'

print(ans)


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

int main(){
	int N;
	scanf("%d",&N);
	int d[N];
	for(int i=0; i<N; i++){
		scanf("%d",&d[i]);
	}
	int count = 0;
	for(int i=0; i<N; i++){
		for(int j=N-1; j>i; j--){
			if(d[i] == d[j]){
				d[j] = -1;
			}
		}
	}

	for(int i=0; i<N; i++){
		// printf("d[%d] = %d\n",i,d[i]);
		if(d[i] != -1){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
    int n,a,b,c,d;
    int i;
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
    int ax=0,by=0;
    i=0;
    while(n>i){
        i=i+a;
        ax+=b;
    }
    i=0;
    while(n>i){
        i=i+c;
        by+=d;
    }
    if(ax>by){
        ax=by;
    }
    printf("%d\n",ax);
    
}


Measured memory_bytes: 2112
import sys
from decimal import Decimal, ROUND_DOWN

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

a, b = map(Decimal, input().split())

ans = (a*b).quantize(Decimal('1'), rounding=ROUND_DOWN)
print(ans)


Measured memory_bytes: 9896
import math
from scipy.special import comb
n, p = map(int, input().split())
aa = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
  if aa[i] % 2 == 0:
    even.append(aa[i])
  else:
    odd.append(aa[i])
    
x = len(odd)
y = len(even)


sum1 = 0
for i in range(0, x+1, 2):
  sum1 += comb(x,i)
sum2 = 0
for i in range(1, x+1, 2):
  sum2 += comb(x,i)
  
if p == 0:
  ans = int((2 ** y) * sum1)
else:
  ans = int((2 ** y) * sum2)
print(ans)

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

using ll = long long;

int main()
{

  ll mon = 100;
  ll X;
  cin >> X;
  for(int i = 0; ; i++){
    if(mon >= X){
      cout << i << endl;
      break;
    }
    mon *= 1.01;
  }


}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

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

    int p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != i + 1) {
            count++;
        }
    }

    if (count == 0 || count == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	double r,p,a,c;
	p=3.141592653589;
	scanf("%lf",&r);
	
	
	a=r*r*p;
	c=2*r*p;
	
	printf("%f %f\n",a,c);
	
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

bool unite(string s1,string s2,int k){
	bool f = true;

	for(int i=k;i<s1.size();i++){
		int ind1 = i;
		int ind2 = i-k;
		if(ind2>=s2.size())break;
		if(s1[ind1]!=s2[ind2]){
			if(s1[ind1]!='?'&&s2[ind2]!='?'){
				f=false;
				break;
			}
		}		
	}
	return f;
}

int main(){
	
	vector<string> s(3);
	for(int i=0;i<3;i++)cin>>s[i];
	
	vector<int> a = {0,1,2};
	
	vector<vector<vector<bool>>> B(3,vector<vector<bool>>(3,vector<bool>(4005)));
	
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<4005;k++){
				if(i==j)continue;
				B[i][j][k] = unite(s[i],s[j],k);
				//if(B[i][j][k])cout<<i<<','<<j<<','<<k<<endl;
			}
		}
	}
	
	int X = s[0].size()+s[1].size()+s[2].size();
	
	int ans = 10000000;
	do{
		for(int i=0;i<2005;i++){
			if(!B[a[0]][a[1]][i])continue;
			for(int j=i;j<4005;j++){
				if(!B[a[0]][a[2]][j])continue;
				if(!B[a[1]][a[2]][j-i])continue;
				ans = min(ans,max({(int)s[a[0]].size(),i+(int)s[a[1]].size(),j+(int)s[a[2]].size()}));;
			}
		}
	}
	while(next_permutation(a.begin(),a.end()));
	
	cout<<ans<<endl;
	
	return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

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

  // string s; cin >> s;
  vector<ll> p(m), y(m) ; REP(i, m) cin >> p[i] >> y[i];
  char strbuf[100];
  vector<string> vs(m);
  REP(i, m) {
    sprintf(strbuf, "%06lld%012lld%06lld", p[i], y[i], i);
    vs[i] = strbuf;
    //    cout << vs[i] << endl;
  }
  sort(vs.begin(),vs.end());
  ll pbuf, oldp = -1, pcnt = 0;
  REP(i, m) {
    //    cout << vs[i] << endl;
    pbuf = stoll(vs[i].substr(0, 6));
    if(pbuf != oldp) {pcnt = 0; oldp = pbuf;}
    pcnt ++;
    sprintf(strbuf, "%6s%6s%06lld", vs[i].substr(18,6).c_str(), vs[i].substr(0, 6).c_str(), pcnt);
    vs[i] = strbuf;
  }
  sort(vs.begin(),vs.end());
  REP(i, m) {
    cout << vs[i].substr(6,12) << endl;
  }
  

}


Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,k,i;
  vector<int> x(200010);
  cin >> n >> k;
  for(i=1;i<=n;i++){
    x[i]=i%k;
  }
  int zero=0,same=0;
  for(i=1;i<=n;i++){
    if(x[i]==0){
      zero++;
    }
    else if(k/2==x[i]){
      same++;
    }
  }
  if(k%2==1){
    cout << (ll)pow(zero,3) << endl;
  }
  else{
    cout << (ll)pow(zero,3)+(ll)pow(same,3) << endl;
  }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> r(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        r[a-1].push_back(b-1);
    }
    set<int> ends;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (ends.count(i) > 0) {
            ans++;
            ends.clear();
        }
        for (auto e: r[i]) {
            ends.insert(e);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
int n,i;
long long a,b,c;
int main()
{
	cin>>n;
	a=2;b=1;
	if (n==0){cout<<2; return 0;}
	else if (n==1){cout<<1; return 0;}
	for(i=2;i<=n;i++)
	{
		c=a+b;
		a=b;
		b=c;
	}
	cout<<c;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int n; 
int main(){
	cin>>n;
	cout<<3*n*n<<endl;
system ("pause");
return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll n;
ll k;
vector <ll> dp;
vector <ll> h;

ll calc( ll i )
{
	if( dp[i] != -1)
	{
		return dp[i];
	}
	ll flag = i - k;
	if( flag <= 0 )
	{
		flag = i;
	}
	else
	{
		flag = k+1;
	}
	if(i <= 1)
	{
		dp[1] = 0;
		return 0;
	}
	ll temp = 1e9 + 7;
	for(int j = 1; j < flag; j++)
	{
		temp = min( temp, abs(h[i] - h[i-j]) + calc( i-j ) );
	}
	dp[i] = temp;
	return dp[i];
}

int main() 
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<=n;i++)
	{
		dp.push_back(-1);
		h.push_back(0);
	}
	for(int i=1;i<=n;i++)
	{
		ll input;
		cin>>input;
		h[i] = input;
	}
	ll ans = calc(n);
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 8300
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define ll 		int
#define int 		long long
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define vpi 		vector<pii>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    int A[n];
    map<int,int>mp,mp2;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
        mp[A[i]]++;
    }
    int s=0;
    for(auto it:mp)
    {
        int x=it.s;
        s+=(x*(x-1))/2;
    }

    for(int i=0;i<n;i++)
    {
        int x=mp[A[i]];
    
        cout<<s-x+1<<"\n";
    }

return 0;
}

Measured memory_bytes: 11136
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void File()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	/*freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);*/
#endif
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
	//File();
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e5 + 15;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

int main()
{
	fast();
	double b;
	cin >> b;
	cout << fx(20) << 2 * pi*b << endl;
	return 0;
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	priority_queue<ll> Q;
	int n, k;
	cin >> n >> k;
	rep(i, n){
		ll x;
		cin >> x;
		Q.push(x);
	}
	ll co = 0;
	int v =Q.size();
	rep(i, v){
		if(k > 0){
			k--;
			Q.pop();
			continue;
		}
		ll h = Q.top();
		co += h;
		Q.pop();
	}
	cout << co << endl;
}


Measured memory_bytes: 5372
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
const int MOD=1000000007;
int add(int a,int b){ 
	int val=a+b;
	if(val>=MOD){
		val-=MOD;
	} 
	return val;
}
int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	int H,W;
	cin>>H>>W;
	vector<vector<bool>> graph(H,vector<bool>(W,false));
	char c;
	for(int i=0;i<H;i++){ 
		for(int j=0;j<W;j++){ 
			cin>>c;
			if(c=='#'){ 
				graph[i][j]=true;
			} 
		} 
	} 
	vector<vector<int>> dp(H,vector<int>(W,0)); 
	dp[0][0]=1;
	for(int i=1;i<W;i++){ 
		if(!graph[0][i]){
			dp[0][i]=dp[0][i-1];
		}
	}
	for(int i=1;i<H;i++){ 
		if(!graph[i][0]){ 
			dp[i][0]=dp[i-1][0];
		}
		for(int j=0;j<W;j++){ 
			if(!graph[i][j]){
			       dp[i][j]=add(dp[i-1][j],dp[i][j-1]);
			}	       
		} 
	}
	cout<<dp[H-1][W-1]; 

			

	
	return 0;
} 



Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

namespace myapp
{
    class AtCoder_abc085_c
    {
        private const int M10000 = 10000;
        private const int M5000 = 5000;
        private const int M1000 = 1000;

        public static void Main()
        {
            IReadOnlyList<int> lineString = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList();
            int totalCount = lineString[0];
            int totalAmount = lineString[1];

            for (int count10000 = 0; count10000 <= totalCount; count10000++)
            {
                for (int count5000 = totalCount - count10000; count5000 >= 0; count5000--)
                {
                    if ((M10000 * count10000) + (M5000 * count5000) + (M1000 * (totalCount - count10000 - count5000)) == totalAmount)
                    {
                        Console.WriteLine($"{count10000} {count5000} {totalCount - count10000 - count5000}");
                        return;
                    }
                }
            }

            Console.WriteLine("-1 -1 -1");
            return;
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int x, d;
    x = s.length();
    bool a, b, c;
    a = (s[0] == 'A');
    for(int i = 2; i < x - 1 ; i++){
        if(s[i] == 'C') d++;
    }
    b = (d == 1);
    for(int i = 1; i < x; i++){
        if(s[i] >= 97 && s[i] <= 122) d++;
    }
    c = (x - 1 == d);
    if(a && b && c){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);

    REP(i,1,50001) {
        if (lli(i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;


}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        var A = int.Parse(input[1]);
        var B = int.Parse(input[2]);

        Console.WriteLine(Math.Min(N * A, B));
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
using namespace std;
int main(){

	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k<<'\n';
	}
	else if(a+b>=k){
		cout<<a<<'\n';
	}else{

		cout<<a-(k-a-b)<<'\n';
	}

	return 0;
}

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


int main() {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	rep(i,n) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	ll now_b, num_a, num_c, ans = 0;
	ll idx_a, idx_c;
	rep(i,n) {
		now_b = b[i];
		num_a = 0;
		num_c = 0;

		auto iter_a = lower_bound(a.begin(), a.end(), now_b);
		idx_a = distance(a.begin(), iter_a);
		if (iter_a == a.end()) num_a = n;
		else num_a = idx_a;

		auto iter_c = upper_bound(c.begin(), c.end(), now_b);
		idx_c = distance(c.begin(), iter_c);
		if (iter_c == c.end()) num_c = 0;
		else num_c = n - idx_c;

		ans += num_a * num_c;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int x = N % 1000;
  int y = 1000 - x;
  if(x == 0){
    cout << x << endl;
  }
  else{
    cout << y << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
    {
        int k,s=0,y;
        cin>>k;

        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                    y= __gcd(i,j);
                for(int l=1;l<=k;l++){
                    s+= __gcd(y,l);
                }
            }
        }
        cout<<s;


    }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;
  return 0;
}

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

using namespace std;

int main() {
  int a, l;
  while (cin >> a >> l) {
    if (a == 0 && l == 0) { break; }

    map<int, int> mp;
    int i = 0;

    while (true) {
      if ( mp.find(a) != mp.end() ) {
        cout << mp[a] << " " << a << " " << i-mp[a] << endl;
        break;
      }
      mp[a] = i++;
      // int -> string 変換 (C++11以降から使用可)
      string s = to_string(a);
      int len = s.length();
      // 0埋め
      for (int i = 0; i < l-len; i++) {
        s = "0" + s;
      }
      int big, little;
      sort( s.begin(), s.end(), greater<char>() );
      big = stoi(s);
      sort( s.begin(), s.end() );
      little = stoi(s);
      // aの値を更新
      a = big-little;
    }
  }

  return 0;
}


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

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else s[k-1]='c';

    cout << s << endl;
}

Measured memory_bytes: 3564
C1=list(map(int,input().split()))
C2=list(map(int,input().split()))
C3=list(map(int,input().split()))
k2=C2[0]-C1[0]
k3=C3[0]-C1[0]
C2=[i-k2 for i in C2]
C3=[i-k3 for i in C3]
print(['No','Yes'][C1==C2==C3])

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String [] commandLineArgument){

        Scanner input = new Scanner(System.in);
        int [][] matrix = new int[3][3];
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 3; ++j){
                matrix[i][j] = input.nextInt();
            }
        }
        int [][] quadSum = new int[3][3];
        for(int i = 0; i < 3; ++i){
            Arrays.fill(quadSum[i] , 0);
        }
        int n = input.nextInt();
        int [] b = new int[n];
        for(int k = 0; k < n; ++k){
            b[k] = input.nextInt();
            for(int i = 0; i < 3; ++i){
                for(int j = 0; j < 3; ++j){
                    if(matrix[i][j] == b[k]){
                        ++quadSum[i][j];
                    }
                }
            }
        }
        
        boolean status = true;
        for(int i = 0; i < 3; ++i){
            status = true;
            for(int j = 0; j < 3; ++j){
                if(quadSum[i][j] == 0){
                    status = false;
                    break;
                }
            }
            if(status){
                break;
            }
        }
        if(status){
            System.out.println("Yes");
            return;
        }
        for(int j = 0; j < 3; ++j){
            status = true;
            for(int i = 0; i < 3; ++i){
                if(quadSum[i][j] == 0){
                    status = false;
                    break;
                }
            }
            if(status){
                break;
            }
        }
        
        if(quadSum[0][0] != 0 && quadSum[1][1] != 0 && quadSum[2][2] != 0){
            status = true;
        }
        if(quadSum[0][2] != 0 && quadSum[1][1] != 0 && quadSum[2][0] != 0){
            status = true;
        }
        String answer = (status) ? "Yes" : "No";
        System.out.println(answer);

    }
}


Measured memory_bytes: 23252
import sys
input = sys.stdin.readline

N = int(input())
A = [[] for _ in range(N)] 
for i in range(N-1):
    u,v,w = map(int,input().split())
    A[u-1].append((v-1,w))
    A[v-1].append((u-1,w))

color = [-1]*N
color[0] = 0
stack = [0]

while stack:
    u = stack.pop()
    for v,w in A[u]:
        if color[v] != -1:
            continue
        color[v] = color[u]^(w&1)
        stack.append(v)

for c in color:
    print(c)

Measured memory_bytes: 38828
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define M 1000000007
ll n,ans;
int main(void){
    cin>>n;
    n++;
    while(n>9){
        ans+=9;
        n/=10;
    }
    ans+=n-1;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
X = [float(x) for x in input().split()]
Y = [float(y) for y in input().split()]

for p in range(1, 4):
    print(sum(map(lambda x, y: abs(x - y) ** p, X, Y)) ** (1 / p))
print(max(map(lambda x, y: abs(x - y), X, Y)))


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
#define int long long

signed main(){
    int n; cin >> n;
    vector<vector<int>> field(2, vector<int>(n+1));
    field[0][0] = field[1][0] = 0;
    
    rep(c,2)rep(i,n){
        cin >> field[c][i+1];
        field[c][i+1] += field[c][i];
    }
    
    int ans = 0;
    reps(i,1,n){
        ans = max(ans, field[0][i] + field[1][n] - field[1][i-1]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);


  ll N,K;
  cin >>N>>K;
  // deque<ll> V(N);
  vint V(N);
  rep(i,N)cin>>V[i];

  ll ans = 0;


  rep(i,K+1){
    // cout <<"hoge"<<endl;

    rep(j,K+1){
      // cout <<"hoge"<<endl;

      if(i+j>K || i+j>N) continue;

      ll temp = 0;
      vint waste;
      // cout <<"hoge"<<endl;

      rep(ii,i){
        temp += V[ii];
        if(V[ii]<0) waste.pb(V[ii]);
      }
      // cout <<"hoge"<<endl;

      rep(jj,j){
        temp += V[N-1-jj];
        if(V[N-1-jj]<0) waste.pb(V[N-1-jj]);
      }
      // cout <<waste.size()<<endl;

      vsort(waste);

      rep(k,min(K-i-j, (ll)waste.size())){
        temp -= waste[k];
      }
      ans = max(ans,temp);
      // cout <<"hoge"<<endl;



    }
  }




  cout << ans << endl;

}

















//


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(input())


from collections import deque
todo = deque()
seen = [[False] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        if A[y][x] == '#':
            todo.append((x, y))
            seen[y][x] = True

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
cnt = -1
while todo:
    cnt += 1
    for _ in range(len(todo)):
        x, y = todo.popleft()
        for i in range(4):
            if 0 <= x + dx[i] < W and 0 <= y + dy[i] < H:
                if seen[y + dy[i]][x + dx[i]] == False:
                    seen[y + dy[i]][x + dx[i]] = True
                    todo.append((x + dx[i], y + dy[i]))

print(cnt)

Measured memory_bytes: 87004