akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll dp[55][55][55], cur[55][55][55];
ll a[55], b[55];


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



  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, 55) rep(j, 55) rep(k, 55) if (j != k) dp[i][j][k] = inf;
  FOR(i, 1, 51) {
    rep(j, 51) {
      rep(k, 51) {
        dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j%i][k] | (1LL << i));
      }
    }
  }

  rep(i,55) rep(j, 55) rep(k, 55) if (j != k) cur[i][j][k] = inf;

  RFOR(i, 1, 50) {
    tmp = 0;
    rep(idx, n) {
      ll x = min(dp[i - 1][a[idx]][b[idx]], cur[i + 1][a[idx]][b[idx]]);
      rep(j, 51) x = min(x, cur[i + 1][a[idx]][j] | dp[i - 1][j][b[idx]]);
      tmp |= x;
    }

    if (tmp >= inf) {
      rep(j, 51) rep(k, 51) cur[i][j][k] = cur[i + 1][j][k];
      rep(j, 51) {
        rep(k, 51) {
          cur[i][j][k%i] = min(cur[i][j][k%i], cur[i + 1][j][k] | (1LL << i));
        }
      }
    }
    else {
      rep(j, 55) rep(k, 55) cur[i][j][k] = cur[i + 1][j][k];
    }
  }
  
  rep(idx, n) ans |= cur[1][a[idx]][b[idx]];
  if (ans >= inf || ans < 0) ans = -1;
  cout << ans << endl;



  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n, a[101010], b[101010];
void solve(){
	cin >> n;
	i64 sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	i64 cnt = 0, ans = 0;
	for(int i = 0; i < n; i++){
		cin >> b[i];
		sum -= b[i];
		a[i] -= b[i];
		if(a[i] < 0){
			cnt += a[i];
			ans++;
		}
	}
	if(sum < 0){
		cout << -1 << endl;
		return;
	}
	sort(a,a+n, greater<i64>());
	
	for(int i = 0; i < n; i++){
		if(cnt >= 0) break;
		cnt += a[i];
		ans++;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    vector<long long> x(N), y(N), h(N);
    for (int i = 0; i < N; i++)cin >> x[i] >> y[i] >> h[i];

    for (int i = 0; i < N; i++) {
        if (h[i] == 0)continue;
        for (long long X = 0; X <= 100; X++) {
            for (long long Y = 0; Y <= 100; Y++) {
                long long H = h[i] + abs(X - x[i]) + abs(Y - y[i]);
                bool good = true;
                for (int j = 0; j < N; j++) if (max(H - abs(x[j] - X) - abs(y[j] - Y), 0LL) != h[j])good = false;
                if (good) {
                    cout << X << " " << Y << " " << H;
                    return 0;
                }
            }
        }
    }

    return 0;
}











































































Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] line = br.readLine().split(" ");
        long N = Long.parseLong(line[0]);
        long M = Long.parseLong(line[1]);
        String[] S = br.readLine().split("");
        String[] T = br.readLine().split("");

        long lcm = lcm(N, M);
        long res = lcm;
        Set<Long> setN = new HashSet<>();
        Set<Long> setM = new HashSet<>();
        long n = lcm / N;
        long m = lcm / M;

        for (long i = 0; i < N; i++) {
            setN.add(n * i + 1);
        }
        for (long i = 0; i < M; i++) {
            setM.add(m * i + 1);
        }
        for (long i: setN) {
            if (setM.contains(i)) {
                if (!S[(int)((i - 1) / n)].equals(T[(int)((i - 1) / m)])) {
                    res = - 1;
                    break;
                }
            }
        }
        out.println(res);
        out.close();
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);    
    }

    private static long gcd(long m, long n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}


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

int main() {
    int n;
  	cin >> n;
  	set<char> st;
  	char c;
  	rep(i, n) {
      	cin >> c;
    	st.insert(c);
    }
  	if(st.size() == 3){
    	cout << "Three" << endl;
    }else {
    	cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N, int M, vector<pair<int, int>> X) {
  map<int, vector<pair<int, int>>> m;
  for (int i = 0; i < M; i++) {
    m[X[i].first].push_back(make_pair(X[i].second, i));
  }
  vector<string> ans(M);
  for (auto x : m) {
    int city = x.first;
    vector<pair<int, int>> v = x.second;
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      stringstream ss;
      ss << setw(6) << setfill('0') << city;
      ss << setw(6) << setfill('0') << i + 1;
      ans[v[i].second] = ss.str();
    }
  }
  for (auto x : ans) {
    printf("%s\n", x.c_str());
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> X(M);
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    X[i] = make_pair(p, y);
  }
  solve(N, M, X);
  return 0;
}

Measured memory_bytes: 16384
a,b = list(map(int, input().strip().split()))
c=0
for i in range(1,10):
    for j in range(10):
        for w in range(10):
            # TODO: write code... in range(10):
            if a<=i*10001+j*1010+w*100 and i*10001+j*1010+w*100<=b:
                c=c+1
print(c)
            

Measured memory_bytes: 8768
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x) cout << "Yes";
	else cout << "No";
	cout << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        cout << lower_bound(all(a), k) - a.begin() << endl;
    }
}



Measured memory_bytes: 3364
#include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <cstdio>
    #include <functional>
    #include <numeric>
    #include <stack>
    #include <queue>
    #include <map>
    #include <set>
    #include <utility>
    #include <sstream>
    #include <complex>
    #include <fstream>
    #include <bitset>
    #include <time.h>
    #include <tuple>
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<ll, ll> P;
    typedef vector<ll> V;
    typedef complex<double> Point;
     
    #define PI acos(-1.0)
    #define EPS 1e-10
    const ll INF = 1e12;
    const ll MOD = 1e9 + 7;
     
    #define FOR(i,a,b) for(int i=(a);i<(b);i++)
    #define rep(i,N) for(int i=0;i<(N);i++)
    #define ALL(s) (s).begin(),(s).end()
    #define EQ(a,b) (abs((a)-(b))<EPS)
    #define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
    #define fi first
    #define se second
    #define N_SIZE (1LL << 20)
    #define NIL -1
    #define MAX_N 100100 * 3
     
    int n;
    ll a, b;
    ll h[100100];
    ll sum = 0;
     
    bool C(double mid) {
    	//cout << "!" << mid << endl;
    	ll nm = (ll)(mid + 0.5);
    	ll cnt = nm;
    	rep(i, n) {
    		ll kk = h[i] - nm*b;
    		//cout << kk << " ";
    		if (kk <= 0)continue;
    		cnt -= (kk / (a - b) + (kk % (a - b) != 0));
    		if (cnt < 0)return false;
    	}
    	return true;
    }
     
    int main() {
    	cin >> n >> a >> b;
    	rep(i, n) {
    		cin >> h[i];
    		sum += h[i];
    	}
    	double lb = 0, ub = sum / b + (sum%b != 0);
    	rep(i, 100) {
    		//cout << endl;
    		//cout << lb << " " << ub << endl;
    		double mid = (ub + lb) / 2;
    		if (C(mid))ub = mid;
    		else lb = mid;
    	}
    	//cout << ub << lb << endl;
    	cout << (ll)(ub + 0.5) << endl;
    }

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

int main(){
  int n;
  cin >> n;
  cout << (n*(n-1)/2) - (n/2)<< endl;
  for(int x = 1; x <= n; x++){
    for(int y = x+1; y<= n; y++){
      if(x != n - y + ((n+1)%2)){
        cout << x << " " << y << endl;
      }
    }
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static boolean isConcat(String s){
		if((s.length()%2)!=0){
			return false;
			}
		int a = 0,b = s.length()/2;
		
		for(int i = 0;i<s.length()/2;i++){
			if(s.charAt(a+i)!=s.charAt(b+i)){
				return false;
				}
			}
		return true;
		}
	
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		if(isConcat(s)){
			System.out.println("Yes");
			}

		else{
			System.out.println("No");
			}

	}
}

Measured memory_bytes: 22996
using System;
using System.Collections;
using System.Linq;

class ABC121B{
    public static void Main(){
        var NMC = Console.ReadLine().Split().Select(int.Parse).ToList();
        var B = Console.ReadLine().Split().Select(int.Parse).ToList();
        var count = 0;
        foreach(var N in Enumerable.Range(0,NMC[0])){
            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            var sum = NMC[2];
            foreach(var n in Enumerable.Range(0,NMC[1])){
                sum += B[n]*a[n];
            }
            if(sum>0)count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13268
a, b, c  = gets.split.map(&:to_i)

case a <=> b
when -1
  x1 = a
  x2 = b
when 0, 1
  x1 = b
  x2 = a
end

case x1 <=> c
when -1
  ans1 = x1
  y2 = c
when 0, 1
  ans1 = c
  y2 = x1
end

case x2 <=> y2
when -1
  ans2 = x2
  ans3 = y2
when 0, 1
  ans2 = y2
  ans3 = x2
end

puts "#{ans1} #{ans2} #{ans3}"

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

#define l long

int main() {
    l n;
    cin>>n;
    l a[n+1],b[n];
    for(int i = 0; i <= n; i++) cin>>a[i];
    for(int i = 0; i < n; i++) cin>>b[i];
    l count = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i; j < i + 2; j++) {
         if(b[i] > a[j]) {
             b[i] -= a[j];
             count += a[j];
             a[j] = 0;
         }   
         else {
             a[j] -= b[i];
             count += b[i];
             b[i] = 0;
         }
       }
    }
    cout<<count<<"\n";
    return 0;
}


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

A = [[0 for i in range(n)] for j in range(m)]

for i in range(m):
  data = input().split()
  for j in range(n):
    A[i][j] = int(data[j])

B = [0 for i in range(n)]

for j in range(n):
  data = input()
  B[j] = int(data)

total = [0 for i in range(m)]

for i in range(m):
  for j in range(n):
    total[i] += A[i][j] * B[j]

for i in range(m):
  print(total[i])




Measured memory_bytes: 5960
n = int(input())
num_list = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,15,21,24,27,20,28,32,36,25,30,35,40,45,36,42,48,54,49,56,63,64,72,81]
if n in num_list:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    set< string > st;
    cin >> n;
    string s;
    cin >> s;
    bool flg = true;
    char f = s[s.size() - 1];
    st.insert( s );
    for( int i = 1; i < n; ++i ) {
        cin >> s;
        if( s[0] != f ) {
            flg = false;

        }
        f = s[s.size() - 1];
        st.insert( s );

    }

    if( !flg || st.size() != n ) cout << "No";
    else cout << "Yes";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
int a[15];
int solve(int n){
	int b, c = 1;
	while(n){
		b = n % 10;
		if(a[b]){
			c = 0;
			break;
		}
		n /= 10;
	}
	if(c == 1)
		return 1;
	else
		return 0;
}


int main(){
	int n, k;
	while(~scanf("%d %d", &n, &k)){
		memset(a, 0, sizeof(a));
		for(int i = 0; i < k; i++){
			int t;
			cin >> t;
			a[t] = 1;
		}
		for(int i = n; ; i++){
		/*	int b, c = 1;
			while(i){
				b = n % 10;
				if(a[b]){
					c = 0;
					break;
				}
				n /= 10;
			}*/
			if(solve(i)){
				printf("%d\n", i);
				break;
			}
		}
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

a,b,c,d = l_in()

while True:
    c -= b
    if c <= 0:
        print("Yes")
        break

    a -= d
    if a <= 0:
        print("No")
        break
    


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

int main(void){
    ll N,x;
    double ans=0;
    cin >> N;
    if(N%2==1) x= (N/2)+1;
    else x = N/2;
    ans = 1.0*x/N;
    std::cout << std::fixed;
    std::cout << std::setprecision(8); // "3.14"
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        String s = sc.next();
		sc.close();
		if((s.contains("N") && !s.contains("S")) || (!s.contains("N") && s.contains("S")) || (s.contains("E") && !s.contains("W")) || (!s.contains("E") && s.contains("W"))){
            System.out.println("No");
        }else{
        	System.out.println("Yes");
        }
        
	}
}


Measured memory_bytes: 21844
n,k=gets.split.map(&:to_i)
num=gets.split.map(&:to_i)
num=num.tally
num=num.to_a
if num.length<=k
    p 0
else
num=num.sort{|a,b|a[1]<=>b[1]}
count=num.length-k
result=0
while count>0
    v=num.shift
    result+=v[1]
    count-=1
end
p result
end

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

using namespace std;

const int MAX_N = 150 ;
int A[5][MAX_N] = {0} ;

int N ;

int dfs(int x, int y, int sc){
  if(x==2 && y==N) return sc;
  if(x>2 ||y>N ) return 0 ;
  else return max(dfs(x+1,y,sc+A[x+1][y]),dfs(x,y+1,sc+A[x][y+1]));
}


int main(void){
  cin >> N ;
  for(int i = 1; i <=2; i++){
    for(int j = 1; j <= N ; j++){
      cin >> A[i][j];
    }
  }

  cout << dfs(1,1,A[1][1]) << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef pair<int, int> ii;
typedef long long int lli;

#define int long long int

signed main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> roots;
    for (int i = 0; i < R; i++) {
        int r;
        cin >> r;
        roots.push_back(r-1);
    }

    const int infinity = 20000 * 100000 + 1;
    int dist[200][200];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            dist[i][j] = i == j ? 0 : infinity;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a-1][b-1] = c;
        dist[b-1][a-1] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    sort(roots.begin(), roots.end());

    int ans = infinity;
    do {
        int tmp_ans = 0;
        auto it = roots.begin();
        int u = *it;
        ++it;
        for (; it != roots.end(); ++it) {
            tmp_ans += dist[u][*it];
            u = *it;
        }
        ans = min(ans, tmp_ans);
    }while (next_permutation(roots.begin(), roots.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL X, K, D, ans;
    cin >> X >> K >> D;
    if (D < abs(X)) {
        LL preMove = min(K, abs(X) / D);
        if (0 < X) {
            X -= D*preMove;
        } else {
            X += D*preMove;
        }
        K -= preMove;
    }

    if (K == 0) {
        ans = abs(X);
    } else {
        if (K % 2 == 0) {
            ans = abs(X);
        } else {
            ans = D-abs(X);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define int long long
#define double long double
int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    int ans=1e9;
    for(int i=a[0];i<=a[n-1];i++){
        int ans1=0;
        rep(j,n){
            ans1+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,ans1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };

int main() {

	int n, r;
	cin >> n >> r;

	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + 100 * (10 - n) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  s.at(5)=' ';
  s.at(13)=' ';
  cout << s << endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    cout << (A-1)*(B-1) << endl;


    return 0;
    

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define PI (acos(-1))
#define _GLIBCXX_DEBUG

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

  int ans;
  if (s =="SUN") ans = 7;
  else if (s =="MON") ans = 6;
  else if (s =="TUE") ans = 5;
  else if (s =="WED") ans = 4;
  else if (s =="THU") ans = 3;
  else if (s =="FRI") ans = 2;
  else ans = 1;

  cout << ans << endl;

}

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

const int N = 2010;

char s[N];

int n, m, Q, a[N][N], A[N][N], B[N][N], C[N][N];

int cal(int arr[N][N], int x1, int y1, int x2, int y2){
	if(x1 > x2 || y1 > y2)	return 0;
	return arr[x2][y2] + arr[x1-1][y1-1] - arr[x1-1][y2] - arr[x2][y1-1];
}

int main(){
	while(~scanf("%d %d %d", &n, &m, &Q)){
		for(int i=1; i<=n; i++){
			scanf("%s", s);
			for(int j=1; j<=m; j++){
				a[i][j] = s[j-1] - '0';
			}
		}
		memset(A, 0, sizeof(A));
		memset(B, 0, sizeof(B));
		memset(C, 0, sizeof(C));
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				A[i][j] = A[i-1][j] + A[i][j-1] - A[i-1][j-1] + a[i][j];
				B[i][j] = B[i-1][j] + B[i][j-1] - B[i-1][j-1];
				C[i][j] = C[i-1][j] + C[i][j-1] - C[i-1][j-1];
                if(i < n && a[i][j] && a[i+1][j]){
					B[i][j]++;
                }
                if(j < m && a[i][j] && a[i][j+1]){
					C[i][j]++;
                }
			}
		}
        int x1, x2, y1, y2;
        while(Q--){
			scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
			printf("%d\n", cal(A, x1, y1, x2, y2) - cal(B, x1, y1, x2-1, y2) - cal(C, x1, y1, x2, y2-1));
        }
	}
	return 0;
}


Measured memory_bytes: 64896
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;

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

int d[301][301];

int main() {
    rep(i,301) rep(j,301) {
        d[i][j] = (i==j) ? 0 : INF;
    }

    int n, m, l;
    cin >> n >> m >> l;

    rep(i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k,n) rep(i,n) rep(j,n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    rep(i,n) rep(j,n) {
        d[i][j] = d[i][j] <= l ? 1 : INF;
    }

    rep(k,n) rep(i,n) rep(j,n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int q,s,t;
    cin >> q;
    rep(i,q) {
        cin >> s >> t;
        s--;
        t--;
        int ans = d[s][t] == INF ? -1 : d[s][t] -1;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 896
ls=list(input())
ls1=['0','1']
ls2=['1','0']
a=int(len(ls)/2)
ls1=ls1*a
ls2=ls2*a
#print(ls1)
b=0
c=0
if len(ls)%2 == 1:
    ls1.append('0')
    ls2.append('1')
#print(ls1)
#print(type(ls1))
for i in range(len(ls)):
    if ls[i]==ls1[i]:
        b=b+1
    if ls[i] == ls2[i]:
        c=c+1
ans=min([b,c])
print(ans)

Measured memory_bytes: 5544
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int A[] = new int[N];
        for(int i = 0; i < N; i++){
        	A[i] = sc.nextInt()-1;
        }
        int count = 0;
        for(int i = 0; i < N; i++){
        	if(i == A[A[i]]){
            	count += 1;
            }
        }
        System.out.println(count / 2);
     }
}

Measured memory_bytes: 59904
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use rand::{thread_rng, Rng};

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - y);
        }
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut plan = vec![0; d];
    let mut v = vec![];
    for p in 0..d {
        input! {
            buf:[isize;26]
        }
        let mut max = 0;
        let mut max_idx = 0;
        for i in 0..buf.len() {
            if max < buf[i] {
                max = buf[i];
                max_idx = i;
            }
        }
        plan[p] = max_idx;
        v.push(buf);
    }
    let mut rng = rand::thread_rng();
    let mut prev_score = calc(&v, &plan, &c);

    let mut k = d;

    for q in 0..300_000 {
        let idx = vec![rng.gen_range(0, d); k];
        let to = vec![rng.gen_range(0, 26); k];
        let mut from = vec![];
        for &i in &idx {
            from.push(plan[i]);
        }
        for i in 0..idx.len() {
            plan[idx[i]] = to[i];
        }
        let next_score = calc(&v, &plan, &c);
        if next_score > prev_score {
            prev_score = next_score;
        } else {
            for i in 0..idx.len() {
                plan[idx[i]] = from[i];
            }
        }
        if k > 1 && q % 500 == 0 {
            k -= 1;
        }
    }
    for i in plan {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 2980
X, N = map(int, input().split())
if N != 0:
    p = list(map(int, input().split()))
else:
    print(X)
    exit()

N_set = set(p)
flag = True
i = 1

if X not in N_set:
    print(X)
    flag = False
while flag:
    if X-i not in N_set:
        print(X-i)
        break
    if X+i not in N_set:
        print(X+i)
        break
    i += 1


Measured memory_bytes: 9196
# ref: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=924554#1
from itertools import product
while(True):
    H,W = map(int,input().split())
    if not H: break
    ma = [list(map(int,input().replace(".","1").replace("*","0")))+[0] for _ in range(H)]
    for i,j in product(range(1,H),range(W)):
        if ma[i][j]: ma[i][j] += ma[i-1][j]
    ans = 0
    for i in range(H):
        stk = []
        for j in range(W+1):
            cur = ma[i][j]
            if (not stk) or stk[-1][1] < cur:
                stk.append([j,cur])
            elif stk[-1][1] > cur:
                idx = j
                while stk and stk[-1][1] >= cur:
                    idx = stk[-1][0]
                    ans = max(ans,stk[-1][1]*(j-stk[-1][0]))
                    stk.pop()
                stk.append([idx,cur])
    print(ans)


Measured memory_bytes: 9692
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    int x, y, A, B, C, tmp;
    cin >> x >> y >> A >> B >> C;

    vector<int> red(A), green(B), ambiguous(C);
    
    for (int i = 0; i < A; ++i) {
        cin >> tmp;
        red[i] = tmp;
    }

    for (int i = 0; i < B; ++i) {
        cin >> tmp;
        green[i] = tmp;
    }

    for (int i = 0; i < C; ++i) {
        cin >> tmp;
        ambiguous[i] = tmp;
    }

    sort(red.rbegin(), red.rend());
    sort(green.rbegin(), green.rend());
    sort(ambiguous.rbegin(), ambiguous.rend());

    priority_queue<int, vector<int>, greater<int> > pq;

    long long ans = 0;
    for (int i = 0; i < x; ++i) {
        pq.push(red[i]);
        ans += red[i];
    }
    for (int i = 0; i < y; ++i) {
        pq.push(green[i]);
        ans += green[i];
    }

    for (int i = 0; i < C && !pq.empty() && pq.top() < ambiguous[i]; ++i) {
        ans = ans - pq.top() + ambiguous[i];
        pq.pop();
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define pii pair<int, int>
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, x, n) for(int i = x; i <= n; ++i)
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238462643383279502884L
#define lld long double
#define r0 return 0

const int inf = 1e9 + 1;
const ll modw = 1e9 + 7;
  
using namespace std;
using namespace __gnu_pbds;

int last[N];
vector<int> g[N];

void bfs(int x)
{
	last[x] = 1;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		for(auto u:g[v])
		{
			if(!last[u])
			{
				last[u] = v;
				q.push(u);
			}
		}
	}
}

int main()
{
	vector<int> ans;
	int n, m;
	cin >> n >> m;
	forn(i, m)
	{
		int t1, t2;
		cin >> t1 >> t2;
		g[t1].pb(t2);
		g[t2].pb(t1);
	}
	bfs(1);
	for(int i = 2; i <= n; i++)
	{
		if(!last[i])
		{
			cout << "NO";
			r0;
		}
		ans.pb(last[i]);
	}
	cout << "Yes\n";
	for(auto i:ans)	cout << i << endl;
}









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

int main() {
  int N, K, i = 0;
  double curr, prev;
  cin >> N >> K;

  curr = pow(2, N);
  prev = curr;

  while (curr >= pow(2, N - i) + K * i) {
    prev = curr;
    curr = pow(2, N - i) + K * i;
    i++;
  }

  cout << curr << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <cctype>
#include <climits> // INT_MAX ...
#include <cstring> //

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
def f(y, m, d)
	x = 0
	x += (y / 3) * 590
	y %= 3
	if y < 2
		x += y * 195
		x += g(m, d)
	else
		x += 390
		x += h(m, d)
	end
	x
end

def g(m, d)
	x = 0
	x += (m / 2) * 39
	m %= 2
	if m == 0
		x += d
	else
		x += 20 + d
	end
	x
end

def h(m, d)
	20 * m + d
end

n = gets.to_i
millenium = f(999, 0, 0)
n.times {
	y, m, d = gets.split.map &:to_i
	p millenium - f(y-1, m-1, d-1)
}

Measured memory_bytes: 8708
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)

int main(void)
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a+b+c >= 22) puts("bust");
	else puts("win");
	return 0;
}

Measured memory_bytes: 128
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
map<char,map<int,int> >ma;
map<char,int>name;
bool h=true;
int f(string s){
	if(isdigit(s[0]))return stoi(s);
	int itr=f(s.substr(2,s.size()-3));
	if(name[s[0]]<=itr){
		h=false;
		return 0;
	}
	if(ma[s[0]].count(itr)==0){
		h=false;
		return 0;
	}
	return ma[s[0]][itr];
}
signed main(){
	while(1){
		ma.clear();
		vs in;
		string s;
		while(cin>>s,s!=".")in.pb(s);
		if(!in.size())break;
		rep(i,in.size()){
			int it=-1;
			rep(j,in[i].size())if(in[i][j]=='=')it=j;
			if(it+1){
				if(name.count(in[i][0])==0){
					cout<<i+1<<endl;
					goto end;
				}
				int itr=f(in[i].substr(2,it-3));
				if(!h||name[in[i][0]]<=itr){
					h=true;
					cout<<i+1<<endl;
					goto end;
				}
				int num=f(in[i].substr(it+1,in[i].size()-it-1));
				if(!h){
					h=true;
					cout<<i+1<<endl;
					goto end;
				}
				ma[in[i][0]][itr]=num;
			}else name[in[i][0]]=stoi(in[i].substr(2,in[i].size()-3));
		}
		cout<<0<<endl;
		end:;
	}
}









Measured memory_bytes: 3344
using System;
public class Pg
{
    static int[,] _correct = new int[,] { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 }, { 0, 3, 6 }, { 1, 4, 7 }, { 2, 5, 8 }, { 0, 4, 8 }, { 2, 4, 6 } };
    static void Main()
    {
        for (string line; (line = Console.ReadLine()) != null; Console.WriteLine(GetWinner(line.Trim())));
    }
    internal static string GetWinner(string line)
    {
        for (int i = 0; i < 8; ++i)
        {
            var str = "";
            for (int j = 0; j < 3; j++)
            {
                str += line[_correct[i, j]].ToString();
            }
            if (str == "ooo")
                return "o";
            else if (str == "xxx")
                return "x";
        }
        return "d";
    }
}


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

int main(){
	
	int n ;
	while( cin >> n , n ){
		
		int m[11][11] = {} ;
		
		for( int i=0; i<n ; i++ ){
			for( int j=0 ; j<n ; j++ ){
				cin >> m[i][j] ;
				m[i][n] += m[i][j] ;
			}
		}
		
		for( int j=0 ; j<=n ; j++ ){
			for( int i=0 ; i<n ; i++ ){
				m[n][j] += m[i][j] ;
			}
		}
		
		for( int i=0 ; i<=n ; i++ ){
			for( int j=0 ; j<=n ; j++ ){
				if( m[i][j] < 10 ) cout << ' ' ;
				if( m[i][j] < 100 ) cout << ' ' ;
				if( m[i][j] < 1000 ) cout << ' ' ;
				if( m[i][j] < 10000 ) cout << ' ' ;
				cout << m[i][j] ;
			}
			cout << endl ;
		}
	}
	
return 0 ;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<long long,long long>

const double eps = (double)1e-6;
const int maxn = 2e5+5;
const ll mod = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

pll arr[maxn];
ll need[maxn], diff[maxn];

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

    ll n,d,a; cin >> n >> d >> a;
    for (int i = 1; i <= n; i++) {
        ll x,h; cin >> x >> h;
        arr[i] = {x,h};
    }
    sort(arr+1,arr+1+n);
    for (int i = 1; i <= n; i++) need[i] = (arr[i].second+a-1)/a;
    ll ans = 0;

    for (int i = 1; i <= n; i++) diff[i] = need[i] - need[i-1];

    for (int i = 1, j = 1; i <= n; i++) {
        need[i] = need[i-1]+diff[i];
        if (need[i] <= 0) {
            continue;
        }
        while (j <= n && arr[i].first + 2*d >= arr[j].first) j++;
        ans += need[i];
        diff[i] -= need[i];
        diff[j] += need[i];
        need[i] = need[i-1]+diff[i];
        // need[i+1] = need[i] + diff[i+1];
    }

    cout << ans << endl;


}



Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#include <cmath>
int main() {
    int n;
    cin >> n;
    string ans = "";
    for(int i = 0; i < 3; i++) {
        int m = n % 10;
        if (m == 9) {
            ans += '1';
        } else {
            ans += '9';
        }
        n = n / 10;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


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

main(){
  char S[10];
  scanf("%s",S);
  
  sort(S,S+4);
  printf((S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]) ? "Yes\n" : "No\n");
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n, a, b, c, d;
string str;

int main() {
    cin >> n >> a >> b >> c >> d;
    cin >> str;
    a--; b--; c--; d--;
    {
        bool con = false;
        for (int i = b+1; i < d; i++) {
            if (str[i] == '#') {
                if (con) {
                    cout << "No" << endl;
                    return 0;
                }
                con = true;
            } else {
                con = false;
            }
        }
    }
    {
        bool con = false;
        for (int i = a+1; i < c; i++) {
            if (str[i] == '#') {
                if (con) {
                    cout << "No" << endl;
                    return 0;
                }
                con = true;
            } else {
                con = false;
            }
        }
    }
    if (a < b && d < c) {
        bool ok = false;
        for (int i = b; i <= d; i++) {
            if (str[i-1] != '#' && str[i] != '#' && str[i+1] != '#') {
                ok = true;
            } 
        }
        if (!ok) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[100006];
signed main() {
	int m, n; cin >> m >> n;
	rep(i, n)cin >> a[i];
	if (m == 2) {
		vector<int>V;
		rep(i, n)V.push_back(i % 2 + 1);
		int dif = 0;
		rep(i, n)if (V[i] != a[i])dif++;
		int dif2 = 0;
		rep(i, n){if (V[i] == 1)V[i] = 2; else V[i] = 1;
	}
		rep(i, n)if (V[i] != a[i])dif2++;
		cout << min(dif, dif2) << endl;
	}
	else {
		int cnt = 0;
		int now = a[0];
		int ans = 0;
		rep(i, n) {
			if (now == a[i])cnt++;
			else {
				ans += cnt / 2;
				cnt = 1;
				now = a[i];
			}
		}
		ans += cnt / 2;
		cout << ans << endl;
	}
}


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

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

// ABC132-B

int main() {

    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }

    int ans = 0;
    for(int i=0; i<n-2; i++){
        if((p[i] > p[i+1] && p[i+1] > p[i+2]) || (p[i] < p[i+1] && p[i+1] < p[i+2])){
            ans++;
        }
    }

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


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

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll c_b = (A-1)/C+1;
  ll c_e = B/C;
  ll d_b = (A-1)/D+1;
  ll d_e = B/D;
  ll lcm = C*D/__gcd(C, D);
  ll com_b = (A-1)/lcm+1;
  ll com_e = B/lcm;
  ll ans = (B-A+1) - (c_e-c_b+1) - (d_e-d_b+1) + (com_e-com_b+1);
  cout << ans << endl;
}

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

using namespace std;
int N[4];

int main() {
   cin >> N[0] >> N[1] >> N[2] >> N[3];
   sort(N, N + 4);
   if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) cout << "YES" << endl;
   else cout << "NO" << endl;
   return 0;
}


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

#define pb push_back
#define pob pop_back
#define st first
#define nd second
#define test cout<<"test"<<endl;
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

ll INF = 1e9;
ll mod = 1e9+7;

ll n,m,k,l,r,ans;

ll min(ll a, ll b) {
	return (a<b)? a:b;
}
ll max(ll a, ll b) {
	return a+b-min(a,b);
}

int main() {
	cin>>n;
	vector<ll> nums;
	nums.resize(n+1);
	vector<ll> places;
	places.resize(n+1);
	for(int i=1; i<=n; i++) {
		cin>>nums[i];
		places[nums[i]] = i;
	}
	ll cur = n;
	vector<ll> anss;
	anss.resize(n+1);
	anss[cur--] = 1;
	ans = 1;
	while(cur != 0) {
		if(places[cur+1] > places[cur]) anss[cur] = anss[cur+1]+1;
		else anss[cur] = 1;
		if(anss[cur] > ans) ans = anss[cur];
		cur--;
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    char a,b,c;
    while(~scanf("%c%c%c",&a,&b,&c))
    {
        getchar();
        if(a+b+c==294)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
using namespace std;

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	int four=0, two=0, one = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i * 2 == h-1&&j * 2 == w-1)one += 1;
			if ((i * 2 == h-1&&j * 2 != w-1) || (i * 2 != h-1&&j * 2 == w-1))two += 1;
			if (i * 2 != h-1&&j * 2 != w-1)four += 1;
		}
	}
	four /= 4;
	two /= 2;
	int a[10000] = { 0 };
	string s;
	for (int i = 0; i < h; i++) {
		cin >> s;
		for (int j = 0; j < w; j++) {
			a[s[j]] += 1;
		}
	}
	for (int i = 0; i < 10000; i++) {
		if (a[i] >= 4) {
			int m = min(a[i] / 4, four);
			four -= m;
			a[i] -= m*4;
		}
	}
	for (int i = 0; i < 10000; i++) {
		if (a[i] >= 2) {
			int m = min(a[i] / 2, two);
			two -= m;
			a[i] -= m * 2;
		}
	}
	if (four == 0 && two == 0)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{ int n,i,s1=0,s2=0,s3=0,s4=0;
cin>>n;
 string s[n];
 for(i=0;i<n;i++)
 {cin>>s[i];}
for(i=0;i<n;i++)
{if(s[i]=="AC")
   s1++;
    if(s[i]=="WA")
       s2++;
       if(s[i]=="TLE")
          s3++;
          if(s[i]=="RE")
             s4++;}
  cout<<"AC x "<<s1<<endl; 
cout<<"WA x "<<s2<<endl;         
cout<<"TLE x "<<s3<<endl;         
cout<<"RE x "<<s4; 
 return 0;}

Measured memory_bytes: 6740