akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	ll N,M;
  	cin>>N>>M;
  	ll mod=1;
  
  	rep(i,N) mod=mod*(i+1)%MOD;
  	rep(j,M) mod=mod*(j+1)%MOD;
  	if(M==N) mod=mod*2%MOD;
  	if(abs(M-N)>=2) mod=0;
  	cout<<mod<<endl;
}


Measured memory_bytes: 3640
#入力をN Mで受ける
N,M = map(int,input().split())

#A1...ANを大きい順に並べ替えてAlistとして受ける
Alist = sorted(list(map(int,input().split())),reverse=True)

#M番目の商品の得票率(A[M番目]/sum(A1...AN))が1/4M以上はYes、未満はNo
if Alist[M-1] / sum(Alist) >= 1 / 4 / M:
    print('Yes')
else:
    print('No')

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

using namespace std;

const int maxN = 1e5 + 10;
int n, k;
string str;
int sum[maxN], ans, l, r;

bool check(int x) {
    for (int i = 0; i < n; ++i) {
        if (n - i < x) return 0;
        if (i > 0 && str[i] == '0' && str[i - 1] == '0') continue;
        if (sum[i + x - 1] - (i == 0 ? 0 : sum[i - 1]) <= k){
           // cout << i << " !!! " << i + x - 1 << endl;
            return 1;
        }
    }
    return 0;
}


int main() {

  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cin >> n >> k;
  cin >> str;
  int tmp = 0;
  ans = 0;
  if (k == -1) {
      for (int i = 0; i <= n; ++i) {
          if (i < n && str[i] == '1') tmp += 1;
          else {
              ans = max(ans, tmp);
              tmp = 0;
          }
      }
      cout << ans;
      return 0;
  }


  sum[0] = str[0] == '0' ? 1 : 0;
  for (int i = 1; i < n; ++i) {
      if (str[i] == '0' && str[i - 1] == '1') sum[i] = sum[i - 1] + 1;
      else sum[i] = sum[i - 1];
  }
  l = 0, r = n;
  while (l <= r) {
      int mid = (l + r) / 2;
      if (check(mid)) {
          ans = mid;
          l = mid + 1;
      } else r = mid - 1;
  }
  cout << ans;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}

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 pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int p[2000];
int main(){
	int n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&p[i]);
	sort(p,p+n);
	int ans=0;
	rep(i,K)ans+=p[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n{0};
	cin>>n;

	ll arr[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}

	ll start=arr[0];
	ll sum{0};
	for(ll i=1;i<n;i++){
		if(arr[i]>start){
			start=arr[i];
		}
		else{
			sum=sum+(start-arr[i]);
		}
	}

	cout<<sum<<endl;


	return 0;
}



Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  string S;
  cin >>  N >> S;
  int r = 0;
  int b = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      r++;
    } else {
      b++;
    }
  }
  if (r > b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3548
N = int(input())
A = list(map(int, input().split()))

A_sum = sum(A)
A_sum_hulf = A_sum / 2

A_sum_rui = 0

for i in range(N):
    A_sum_rui += A[i]
    if A_sum_rui > A_sum / 2:
        if A_sum_rui - (A_sum / 2) < (A_sum / 2) -(A_sum_rui - A[i]):
            print(A_sum_rui - (sum(A) - A_sum_rui))
        else:
            print(sum(A) - 2 * (A_sum_rui - A[i]))
        break




Measured memory_bytes: 26764
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
#include <complex>

using namespace std;

// deq notes ツ閉スツ姪環甘エツ可スツづ可つィツつッツづゥツベツクツトツδ仰可可算 http://www.deqnotes.net/acmicpc/2d_geometry/

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)


double helon (double a, double b, double c )
{
//	cout << "a: " << a << " b: " << b << " c: " << c << endl;

	double z = (a + b + c)/2.;

//	cout << "z: " << z << endl;

	double S = sqrt( z*(z - a)*(z - b)*(z - c) );

//	cout << "S: " << S << endl;

	return S;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.aop", "r", stdin);
	string str = "";
	vector <double> px, py;

	while (getline (cin, str ) ){
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		double x, y;
		stringstream ss(str);
		ss >> x >> y;
		px.push_back(x); py.push_back(y);
	} // end loop
	int size = px.size();
	P v[size];	
	int i;

	for (i = 0; i < size; ++i){
		v[i].real() = px[(i+1) % size] - px[0];
		v[i].imag() = py[(i+1) % size] - py[0];
//		cout << '(' << v[i].real() << ',' << v[i].imag() << ')' << endl;
	} // end for

	double res = 0.;
	for (i = 0; i < size - 2; ++i){
		res += helon (abs(v[i]), abs(v[i+1]), abs (v[i+1] - v[i]) );
	} // end for
	cout << res << endl;	
		
	return 0;
}

Measured memory_bytes: 0
'use strict';

const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const foo = (str) => str.split(' ').map(v => parseInt(v, 10));

const numbers1 = foo(inputs[0]);

if (numbers1[1] === 0) {
  console.log(numbers1[0]);
  return;
}

const target = numbers1[0];

const numbers2 = foo(inputs[1]);

if (!numbers2.includes(target)) {
  console.log(target);
  return;
}

let count1 = target;
let count2 = target;

while(true) {
  --count1;

  if (!numbers2.includes(count1)) {
    console.log(count1);
    return;
  }

  ++count2;

  if (!numbers2.includes(count2)) {
    console.log(count2);
    return;
  }
}

Measured memory_bytes: 29644
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    cout<< (N+1)/2<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

int main(){
	int h, w; cin >> h >> w;
	string s[100];
	for(int i = 0; i < h; i++) cin >> s[i];
	for(int i = 0; i < h + 2; i++){
		if(i == 0 || i == h + 1) cout << string(w + 2, '#') << endl;
		else cout << "#" + s[i - 1] + "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
W,H,N=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]

minx=W
maxx=0
miny=H
maxy=0

for x,y,a in List:
  if a==1:
    if x > maxx:
      maxx=x
  elif a==2:
    if x < minx:
      minx=x  
  elif a==3:
    if y > maxy:
      maxy=y    
  elif a==4:
    if y < miny:
      miny=y

lenx=(minx-maxx)
leny=(miny-maxy)
if lenx >0 and leny >0:
  print(lenx*leny)
else:
  print(0)
    

Measured memory_bytes: 3064
ans = []
while True:
    m,f,r = [int(i) for i in input().split()]
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        ans.append("F")
    elif m + f >= 80:
        ans.append("A")
    elif m + f >= 65:
        ans.append("B")
    elif m + f >= 50:
        ans.append("C")
    elif m + f >= 30:
        if r >= 50:
            ans.append("C")
        else:
            ans.append("D")
    else:
        ans.append("F")

for i in range(len(ans)):
    print(ans[i])



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

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

  const int size = ('z' - 'a' + 1);
  vector<int> arr(size, 0);

  for(int i = 0;i < w.length();i++){
    unsigned int idx = w[i] - 'a';
    arr[idx] = ~arr[idx];
  }

  bool res = true;
  for(int i = 0;i < size;i++){
    if(arr[i] != 0) {res = false; break;};
  }

  std::cout << (res ? "Yes" : "No") << std::endl;

}


Measured memory_bytes: 256
n, k = map(int, input().split())
v = list(map(int, input().split()))  # 筒

c = min(n, k)
ans = 0
for a in range(c + 1):
    for b in range(c + 1 - a):
        w = v[:a] + v[n-b:]  # 手持ち
        w.sort()
        for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
        ans = max(ans, sum(w))
print(ans)

Measured memory_bytes: 41196
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    dp = [float('inf')] * N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])

    for i in range(2,N):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

    print(dp[-1])
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18092
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int ex(int n) {
  if (n <= 0)
    return 1;
  int ret = 1;
  FOR(i, 1, n + 1) { ret *= i; }
  return ret;
}

int main() {
  int n;
  cin >> n;
  double x[8] = {}, y[8] = {};
  REP(i, n) { cin >> x[i] >> y[i]; }

  double ans = 0;
  REP(i, n) {
    REP(j, n) {
      if (i == j)
        continue;
      double d =
          sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
      ans += d * ex(n - 1);
    }
  }
  cout << fixed << setprecision(10) << ans / ex(n) << endl;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    printf("%d %d %f\n", d, r, f);
    
    return 0;
}


Measured memory_bytes: 2756
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a;
  cin>>a;
  int e=0;
  int b[a];
  rep(i,a)cin>>b[i];
  rep(i,a-2){
    int c,d;
    c=min(b[i],min(b[i+1],b[i+2]));
    d=max(b[i],max(b[i+1],b[i+2]));
    if(b[i+1]!=c&&b[i+1]!=d)e++;
  }
  cout<<e;
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 11:54:41 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b = na()
print(a * (a - 1) // 2 + b * (b - 1) // 2)

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

#define SEP " "

struct card {
    int n;
    int c;
    struct card *next;
};

unsigned long int remain(unsigned long int n, struct card *first) {
    struct card *f = first;
    while (f != NULL) {
        if(f->c > 2 && f->c % 2 == 0) {
            f->c = 2;
        } else if(f->c > 2 && f->c % 2 == 1) {
            f->c = 1;
        }
        f = f->next;
    }
    
    f = first;
    while (f != NULL) {
        if(f->c > 1) {
            //find next
            struct card *t = NULL;
            struct card *next = f->next;
            while(next != NULL) {
                if(next->c > 1) {
                    t = next;
                    break;
                }
                next = next->next;
            }
            if(t == NULL) {
                next = first;
                while (next != NULL) {
                    if(next->c > 0 && next != f) {
                        t = next;
                        break;
                    }
                    next = next->next;
                }
            }
            if(t != NULL) {
                f->c -= 1;
                t->c -= 1;
            }
        }
        f = f->next;
    }
    
    unsigned long int r = 0;
    struct card *last = first;
    while(last != NULL) {
        if(last->c > 0) {
            r++;
        }
        last = last->next;
    }
    
    last = first;
    while(last != NULL) {
        free(last);
        last = last->next;
    }

    return r;
}

int main(int argc, const char * argv[]) {
    unsigned long int n;
    scanf("%lu\n", &n);

    struct card *first = NULL;
    
    struct card *cards[100001];
    memset(cards, 0, sizeof(cards));
    int c;
    for(unsigned long int i = 0; i < n; i++) {
        scanf("%d", &c);
        struct card *last = cards[c];
        if(last == NULL) {
            last = malloc(sizeof(struct card));
            memset(last, 0, sizeof(struct card));
            last->n = c;
            last->next = NULL;
            cards[c] = last;
        }
        last->c += 1;
    }
    
    struct card *prev = NULL;
    for(unsigned long int i = 0; i < 100001; i++) {
        struct card *last = cards[i];
        if(last == NULL) {
            continue;
        }
        if(first == NULL) {
            first = last;
            prev = first;
        }
        else{
            prev->next = last;
            prev = last;
        }
    }
    
    printf("%lu\n", remain(n, first));
    return 0;
}


Measured memory_bytes: 4096
N = gets.to_i
c = gets.chomp.chars

# 全部どちらか or R..RW..Wb でOK

zenbu = [c.count(?R), c.count(?W)].min

rw = 0
left = 0
right = N-1
while true
    # pp c
    while c[left] == ?R
        left += 1
    end
    while c[right] == ?W
        right -= 1
    end
    break if left >= right

    c[left] = ?R
    c[right] = ?W
    rw += 1
end

p [zenbu, rw].min

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

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	ll N, A, B;
	
	cin >> N >> A >> B;

	ll x[N];

	ll sum = 0;

	rep(i, N)
	{
		cin >> x[i];
		if ( i > 0)
		{
			ll cost = (x[i] - x[i - 1]) * A;
			if ( cost > B)
			{
				sum += B;
			}
			else
			{
				sum += cost;
			}
		}
	} 
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x == 500 * i + 100 * j + 50 * k:
                ans += 1
print(ans)

Measured memory_bytes: 3444
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] a = new String[]{sc.next(), sc.next()};
        int res = a[0].compareTo(a[1]);
        if (res > 0) {
            System.out.println(">");
        } else if (res < 0) {
            System.out.println("<");
        } else {
            System.out.println("=");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  int a[m];
  rep(i,m)cin >> a[i];
  int sum = 0;
  rep(i,m)sum+=a[i];
  int ans = n - sum;
  if(ans>=0)cout << ans << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 3624
import sys

input = sys.stdin.readline


def main():
    k, x = [int(i) for i in input().split()]
    num = k - 1
    min_ = max(x - num, - 1000000)
    max_ = min(x + num + 1, 1000001)
    print(" ".join([str(i) for i in range(min_, max_)]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
   int a, b, c;
   cin >> a >> b >> c;
   if(c >= a && b >= c) cout << "Yes" << endl;
   else if(c >= b && a >= c) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,b,ans;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(b=k+1;b<=n;b++)
	{
		ans+=(b-k)*(n/b);
		if(n-n/b*b>=k) ans+=n-n/b*b-k+1;
	}
	if(!k) ans-=n;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define pii pair<ll,ll>
#define mod 1000000007
int main()
{
    string s;
    cin>>s;
    ll i,j;
    i=0;
    j=s.length()-1;
    while(s[i]!='A')
        i++;
    while(s[j]!='Z')
        j--;
    cout<<j-i+1<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    cout << (*max_element(all(a)) - *min_element(all(a))) << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
for _ in range(int(input())):
    code=input().split()
    if code[0]=='print'  :
        print(s[int(code[1]):int(code[2])+1])
    elif code[0]=='reverse':
        s = s[:int(code[1])] + s[int(code[1]):int(code[2])+1][::-1] + s[int(code[2])+1:]
    elif code[0]=='replace':
        s = s[:int(code[1])] + code[3] + s[int(code[2])+1:]

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    string s;
    int k;
    cin >> s >> k;
    int len = int(s.size());
    set<string> ans;
    for(int i=1; i<=k; i++){
        for(int j=0; j<len-i+1; j++){
            string now = s.substr(j,i);
            ans.insert(now);
        }
    }
    auto itr = ans.begin();
    rep(i,k-1) ++itr;
    cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 4732
#include <iostream>
#include <string>
int digitSum(int x) {
    int s = 0;
    while (x > 0) {
        s += x % 10;
        x /= 10;
    }
    return s;
}
int main() {
    int n;
    std::cin >> n;
    int ans = 1001001001;
    for (int a = 1; a < n; ++a)
        ans = std::min(ans, digitSum(a) + digitSum(n - a));
    std::cout << ans << '\n';
}

Measured memory_bytes: 256
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f
using namespace std;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	for(char e:s){
		if(e=='1'){
			cout<<9;
		}
		else if(e=='9'){
			cout<<1;
		}
		else{
			cout<<e;
		}
	}	
	return 0;
}



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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void wr(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    ll k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto& it:a) cin>>it,it--;
    vector<bool> vis(n);
    vector<int> go(n+1,-1);
    int cnt=0,pos=0;
    int last;
    go[0]=0;
    while(1){
        if(vis[pos]){
            last=pos;
            break;
        }
        vis[pos]=1;
        pos=a[pos];
        cnt++;
        go[cnt]=pos;
    }
    //for(auto it:go) cout<<it<<' ';cout<<endl;
    //cout<<cnt<<' '<<last<<endl;
    if(k<=cnt) cout<<go[k]+1;
    else{
        for(int i=0;i<=n;i++){
            if(go[i]==last){
                //cout<<i<<endl;
                int cycle=cnt-i;
                cout<<go[i+(k-i)%cycle]+1;
                return 0;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 4820
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int A, B;
	cin >> A >> B;
	vector<vector<char>> c(100, vector<char>(100));
	for (int i = 0; i < 50; i++){
		for (int j = 0; j < 100; j++){
			c[i][j] = '#';
		}
	}
	for (int i = 50; i < 100; i++){
		for (int j = 0; j < 100; j++){
			c[i][j] = '.';
		}
	}
	for (int i = 0; i < A - 1; i++){
		c[i / 50 * 2][i % 50 * 2] = '.';
	}
	for (int i = 0; i < B - 1; i++){
		c[99 - i / 50 * 2][i % 50 * 2] = '#';
	}
	cout << "100 100" << endl;
	for (int i = 0; i < 100; i++){
		for (int j = 0; j < 100; j++){
			cout << c[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3624
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000000000000;
//#define PI 3.14159265358979323846
//
//int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
//int findSumDigits(int s) {
//    int num = 0;
//    int temp = 0;
//    while (s) {
//        temp = s % 10;
//        num += temp;
//        s = s / 10;
//    }
//    return num;
//}
//
//int countDivisorNum(int n) {
//    int count = 0;
//    for (int i = 1; i <= n; i++) {
//        if (n % i == 0) {
//            count++;
//        }
//    }
//    return count;
//}

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

    ll count = 0;
    ll temp = 0;

    rep(i, n, 0) {
        if (s[i] == 'R') {
            count++;
        }
    }

    temp = min(count, n - count);
    char scomp = 'W';
    if (temp < count) {
        reverse(s.begin(), s.end());
        scomp = 'R';
    }

    ll ans = 0;
    rep(i, temp, 0) {
        if (s[i] == scomp) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3660
n = int(input())

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)


Measured memory_bytes: 73892
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    ll  ans=INF;
    for(int i=-100;i<=100;i++){
    ll tmp=0;
    rep(j,n){
        tmp+=llpow((ll)(a[j]-i),2LL);
    }
    chmin(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()

if a[0]==0:
    a.remove(0)
    sta=0
else:
    sta=1
for i in range(1,len(a),2):
    if a[i]!=a[i-1] or a[i]%2!=sta or a[i]!=i+1-sta:
        print(0)
        exit()
ans=2**(len(a)//2)
print(ans%(10**9+7))

Measured memory_bytes: 14008
n=int(input())
c=input()

r=c.count('R')
w=c.count('W')

from_l=0
from_r=len(c)
rp=0
while 1:
    from_l=c.find('W',from_l)
    if from_l==-1:
        from_l=len(c)
    from_r=c.rfind('R',0,from_r)

    if from_l>=from_r:
        break
    rp+=1
    from_l+=1
    if from_l==len(c):
        break
    
print(min(r,w,rp))


Measured memory_bytes: 9472
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a,b,c ;
      a = sc.nextInt();
      b = sc.nextInt();
      c = sc.nextInt();
      
      if(a==5 && b ==5 && c==7){
      	System.out.println("YES");
      }else if(a==5 && b ==7 && c==5){
        System.out.println("YES");
      }else if(a==7 && b ==5 && c==5){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

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

    if (S.at(len(S) - 1) != 's') {
        cout << S + "s" << endl;
    } else {
        cout << S + "es" << endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <utility>

void print_array(int N, std::pair<char, int> *array)
{
    for (int i = 0; i < N - 1; i++)
        std::cout << array[i].first << array[i].second << " ";
    std::cout << array[N - 1].first << array[N - 1].second << std::endl;
}

void copy(int N, std::pair<char, int> *source, std::pair<char, int> *destination)
{
    for (int i = 0; i < N; i++)
        destination[i] = source[i];
}

void bubble_sort(int N, std::pair<char, int> *array)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = N - 1; j > i; j--)
        {
            if (array[j].second < array[j - 1].second)
            {
                std::swap(array[j], array[j - 1]);
            }
        }
    }
}

int selection_sort(int N, std::pair<char, int> *array)
{
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if (array[j].second < array[minj].second)
                minj = j;
        }
        if (i != minj)
        {
            std::swap(array[i], array[minj]);
        }
    }
}

bool isStable(int N, std::pair<char, int> *stable, std::pair<char, int> *unknown)
{
    bool flag = true;
    for (int i = 0; i < N; i++)
    {
        if (stable[i].first != unknown[i].first)
        {
            flag = false;
            break;
        }
    }
    return flag;
}

int main()
{
    /* input process */
    int N;
    scanf("%d", &N);
    std::pair<char, int> *bubble = new std::pair<char, int>[N];
    std::pair<char, int> *selection = new std::pair<char, int>[N];
    for (int i = 0; i < N; i++)
        std::cin >> bubble[i].first >> bubble[i].second;

    copy(N, bubble, selection);

    /* sort */
    bubble_sort(N, bubble);
    selection_sort(N, selection);

    /* print */
    print_array(N, bubble);
    std::cout << "Stable" << std::endl;
    print_array(N, selection);
    if(isStable(N, bubble, selection))
        std::cout << "Stable" << std::endl;
    else
        std::cout << "Not stable" << std::endl;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
	int n = 0;
	cin >> n;
	int ans = 0;
	for (int i = 0;; i++)
	{
		if ((i * i) > n)
		{
			ans = (i - 1) * (i -1);
			COUT(ans);
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 384
// from https://atcoder.jp/contests/dp/submissions/3937222
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll dp[3001][3001];

int main(){
  string s,t;cin>>s>>t;
  rep(i, s.size())rep(j, t.size()){
    if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1;
    else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
  }

//  cout<<dp[s.size()][t.size()]<<endl;

//  rep(i, s.size()+1){
//    rep(j, t.size()+1) cout<<dp[i][j]<<' '; cout<<endl;
//  }

  vector<char> result;
  int i=s.size();
  int j=t.size();
  while(i+j){
    ll c = dp[i][j];
    if( i && dp[i-1][j]==c) i--;
    else if( j && dp[i][j-1]==c) j--;
    else {
      result.push_back(s[i-1]);
      i--;j--;
    }
  }

//cout<<i<<j<<endl;

  rrep(i,result.size())cout<<result[i];
  cout<<endl;

  return 0;
}

Measured memory_bytes: 70656
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ks = scanner.nextLine().split(" ", 2);
        int k = Integer.parseInt(ks[0]);
        int s = Integer.parseInt(ks[1]);

        int count = 0;
        for (int x = 0; x <= Math.min(k, s); x++) {
            for (int y = 0; y <= Math.min(k, s - x); y++) {
                int z = s - x - y;
                if (0 <= z && z <= k) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


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

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        int c = n / i;
        if (n % i == 0 && c >= 1 && c <= 9) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
code={}
[*97..122].each {|c| code[c.chr]=0}
m=code.dup
m.each{|k,v|m[k]=100}
N = gets.to_i
N.times do |i|
    s = gets.chomp.split('')
    l=code.dup
    s.each{|t| l[t]+=1}
    l.each{|k,v|m[k]=[m[k],v].min}
end
ans=''
m.each do |k,v|
    next if v==0
    ans += k*v
end
puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fs first
#define se second
 
struct trap{
	ll l=-1,r=-1,d=-1;
};
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	ll n=s.size();
	ll c=0;
	for(ll i=0;i<n/2;i++)
		if(s[i]!=s[n-1-i])
			c++;
	cout<<c<<endl;

}

Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let n: u64 = read_line().trim().parse().unwrap();
    let mut speed = n;
    for _ in 0..5 {
        let a: u64 = read_line().trim().parse().unwrap();
        speed = cmp::min(speed, a);
    }

    println!("{}", (n + speed -1)/speed + 4);
}


Measured memory_bytes: 4352
n=int(input())
w = list(map(int, input().split()))

ans=999999999
s1=0
s2=sum(w)
for i in range(n):
  s1+=w[i]
  s2-=w[i]
  if ans>abs(s1-s2):
    ans=abs(s1-s2)
    
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>

typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

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

	int n;
	cin >> n;
	int* b;
	b = new int[n - 1];
	for (int i = 0; i < n - 1; ++i) {
		cin >> b[i];
	}

	int ans = 0;
	ans += b[0];
	for (int i = 1; i < n - 1; ++i) {
		ans += min(b[i - 1], b[i]);
	}
	ans += b[n - 2];

	cout << ans << "\n";
 }


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  constexpr ll SIZE=1ll<<7;
  constexpr ll MAXN=1ll<<18;
  constexpr ll MAXW=100010;

  std::vector<ll> v(MAXN-1,0),w(MAXN-1,0);
  rep(i,0,n)std::cin>>v[i]>>w[i];

  std::vector<std::vector<ll>> dp(SIZE-1,std::vector<ll>(MAXW,0));

  rep(i,w[0],MAXW)dp[0][i]=v[0];

  rep(i,1,SIZE-1){
    rep(j,0,w[i])dp[i][j]=dp[(i-1)/2][j];
    rep(j,w[i],MAXW)dp[i][j]=std::max(dp[(i-1)/2][j],dp[(i-1)/2][j-w[i]]+v[i]);
  }

  ll q;
  std::cin>>q;

  using P=std::pair<ll,ll>;

  while(q--){
    ll a,l;
    std::cin>>a>>l;
    a--;

    if(a<SIZE-1){
      std::cout<<dp[a][l]<<"\n";
      continue;
    }

    std::vector<P> tmp(1,{0,0});
    while(a>=SIZE-1){
      ll m=tmp.size();
      rep(i,0,m){
        if(tmp[i].first+w[a]<=l)tmp.emplace_back(tmp[i].first+w[a],tmp[i].second+v[a]);
      }
      a=(a-1)/2;
    }

    ll ans=0;
    for(const auto& e:tmp){
      chmax(ans,e.second+dp[a][l-e.first]);
    }
    std::cout<<ans<<"\n";
  }

  return 0;
}


Measured memory_bytes: 107752
#include <stdio.h>
#include <math.h>

int main() {
    long long int n, i, j;

    scanf("%lld", &n);

    i = sqrt(n);

    while (1) {
        if (n % i == 0) {
            j = n / i;
            printf("%lld\n", (i - 1) + (j - 1));
            break;
        }

        i--;
    }

    return 0;
}


Measured memory_bytes: 128
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Text.Printf

main :: IO ()
main = do
  n <- inp toInt
  xs <- inpn n $ splt toDbl
  mapM_ (\[x,y,z] -> printf "%.3f %.3f %.3f\n" (round3 x) (round3 y) (round3 z)) $ solve xs

solve :: [[Double]] -> [[Double]]
solve = map ccircle

ccircle :: [Double] -> [Double]
ccircle (x0:y0:x1:y1:x2:y2:_) = (fromPoint . head $ intersect pla plb) ++ [r]
  where
    p0 = toPoint x0 y0
    p1 = toPoint x1 y1
    p2 = toPoint x2 y2
    va = toVector p1 p0
    vb = toVector p2 p0
    vc = toVector p2 p1
    st = abs $ crossVector va vb / (lenVector va * lenVector vb)
    r = lenVector vc / (2.0 * st)
    la = sqrt $ r ^ 2 - (lenVector va / 2.0) ^ 2
    lb = sqrt $ r ^ 2 - (lenVector vb / 2.0) ^ 2
    pca = cntPoint p0 p1
    pcb = cntPoint p0 p2
    vua = toUVector $ toNVector va
    vub = toUVector $ toNVector vb
    pla = [mvPoint pca (mulSVector la vua), mvPoint pca (mulSVector (negate la) vua)]
    plb = [mvPoint pcb (mulSVector lb vub), mvPoint pcb (mulSVector (negate lb) vub)]
    
toInt :: String -> Int
toInt s = read s

toDbl :: String -> Double
toDbl s = read s

splt :: (String -> a) -> String -> [a]
splt f = map f . words

inp :: (String -> a) -> IO a
inp f = f <$> getLine

inpn :: Int -> (String -> a) -> IO [a]
inpn n f = map f <$> replicateM n getLine

round3 :: Double -> Double
round3 = (/ 1000) . fromIntegral . round . (* 1000)

data Point = Point Double Double deriving Show
data Vector = Vector Double Double deriving Show

toPoint :: Double -> Double -> Point
toPoint x y = Point x y

fromPoint :: Point -> [Double]
fromPoint (Point x y) = [x, y]

cntPoint :: Point -> Point -> Point
cntPoint (Point x0 y0) (Point x1 y1) = toPoint ((x0 + x1) / 2.0) ((y0 + y1) / 2.0)

toVector :: Point -> Point -> Vector
toVector (Point x0 y0) (Point x1 y1) = Vector (x1 - x0) (y1 - y0)

toNVector :: Vector -> Vector
toNVector (Vector x y) = Vector (negate y) x

toUVector :: Vector -> Vector
toUVector (Vector x y) = Vector (x / l) (y / l)
  where l = sqrt $ x ^ 2 + y ^ 2

mulSVector :: Double -> Vector -> Vector
mulSVector s (Vector x y) = Vector (s * x) (s * y)

lenVector :: Vector -> Double
lenVector (Vector x y) = sqrt $ x ^ 2 + y ^ 2

crossVector :: Vector -> Vector -> Double
crossVector (Vector x0 y0) (Vector x1 y1) = x0 * y1 - x1 * y0

mvPoint :: Point -> Vector -> Point
mvPoint (Point px py) (Vector vx vy) = toPoint (px + vx) (py + vy)

instance Eq Point where
  (Point x0 y0) == (Point x1 y1) = (abs (x0 - x1) < 0.000000001) && (abs (y0 - y1) < 0.000000001)

Measured memory_bytes: 4532
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n=5;
    vector<int> abc(n);
    vector<int> abc10(n);
    for(int i=0;i<n;i++){
        cin>>abc[i];
    }
    for(int i=0;i<n;i++){
        if(0==abc[i]%10){
            abc10[i]=abc[i];
        }else{
            abc10[i]=(abc[i]/10+1)*10;
        }
    }
    vector<pair<int,int>> abclist(n);
    for(int i=0;i<n;i++){
        abclist[i]=make_pair(abc[i]%10,i);
    }
    sort(abclist.begin(),abclist.end());
    int index=0;
    for(int i=0;i<n;i++){
        if(0!=abclist[i].first){
            index=i;
            break;
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(i==abclist[index].second){
            sum+=abc[i];
        }else{
            sum+=abc10[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int t,k;
  cin>>k>>t;
  vin a(t);
  rep(i,0,k) cin>>a[i];
  //////////
  if(k>1){
  rep(i,0,k){
          sort(all(a));
    //cout<<a[0]<<a[1]<<a[2]<<endl;
    reverse(all(a));
		  if(a[0]==0) break;
          if(a[1]==0) break;
          a[0]--;a[1]--;
  }
  }
  if(a[0]==0) a[0]++;
  cout<<a[0]-1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1];
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef unsigned long long ull;
const int Hash_CNT=10;
const ull seedpool[]={146527,19260817,16777291,65557,257,65539,16777259,65479,239,229};
const ull modpool[]={1000000009,998244353,10000000033,16777259,99999941,4294967029,4294967311,16777291,999999893,4294967371};
char str[maxn];
struct Hash{
    ull seed,mod;
    vector<ull>p,h;
    Hash(){}
    Hash(const char *s,const int & seed_index,const int & mod_index){
        seed=seedpool[seed_index];
        mod=modpool[mod_index];
        int n=strlen(str);
        p.resize(n+1),h.resize(n+1);
        p[0]=1;
        for(int i=1;i<=n;i++) p[i]=p[i-1]*seed%mod;
        for(int i=1;i<=n;i++) h[i]=(h[i-1]*seed%mod+s[i-1])%mod;
    }
    ull get(int l,int r) {
        return (h[r]-h[l]*p[r-l]%mod+mod)%mod;
    }
    ull substr(int l,int m){
        return get(l,l+m);
    }
}hasher[2];
int n;
typedef pair<int,int>pll;
map<pll,int>mp;
bool check(int x){
    mp.clear();
    for(int i=0;i+x<=n;i++){
        pll p;
        p.first=hasher[0].substr(i,x);
        p.second=hasher[1].substr(i,x);
        //if(x==5) printf("%d %d %d\n",p.first,p.second,i);
        if(!mp[p]) mp[p]=i+1;
        else{
            if(mp[p]+x-1<=i) return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",str);
    for(int j=0;j<2;j++) hasher[j]=Hash(str,j,j);
    int l=0,r=strlen(str)/2;
    int res=0;
    while(l<=r){
        int mid=(l+r)>>1;
        //cout<<check(mid)<<" "<<mid<<endl;
        if(check(mid)) res=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",res);
    return 0;
}

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

ll n;

void f(ll cur,int use,ll &cal){
  if(cur>n) return;
  if(use==0b111) ++cal;

  f(cur*10+7,use | 0b001,cal);
  f(cur*10+5,use | 0b010,cal);
  f(cur*10+3,use | 0b100,cal);
}

int main(){
  ll ans=0;
  cin >> n;
  f(0,0,ans);
  cout << ans << endl;
  return 0;
}


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

int main() {
    std::size_t n{};
    std::cin >> n;
    std::vector<int> w(n, 0);
    for (std::size_t i = 0; i < n; ++i)
        std::cin >> w[i];
    int d = std::numeric_limits<int>::max();
    for (std::size_t i = 0; i < n; ++i) {
        int s1 = 0;
        int s2 = 0;
        for (std::size_t j = 0; j < n; ++j) {
            if (j <= i)
                s1 += w[j];
            else
                s2 += w[j];
        }
        d = std::min(d, std::abs(s1 - s2));
    }
    std::cout << d << std::endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m; cin >> n >> m;
  vector<bool> sel(n+1, false);
  vi a;
  REP(i, m) {
    int tmp; cin>> tmp;
    a.pb(tmp);
  }
  reverse(ALL(a));
  REP(i, m) {
    if(!sel[a[i]]) cout << a[i] << endl;
    sel[a[i]] = true;
  }
  FOR(i, 1, n+1) {
    if(!sel[i]) cout << i << endl;
  }
}



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

using ll = int64_t;
#define int ll

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

const int _MA = 100000 + 10;
const int MA = 100000 + 5;
int dp[_MA];

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

  int n, w;
  std::cin >> n >> w;
  rrep(i, MA) dp[i] = inf;
  dp[0] = 0;
  rep(i, n) {
    int wi, vi;
    std::cin >> wi >> vi;
    drep(j, MA - vi + 1) { dp[vi + j] = min(dp[vi + j], dp[j] + wi); }
  }
  int ans = 0;
  rep(i, MA) if (dp[i] <= w) ans = i;
  print(ans);
}


Measured memory_bytes: 1024