akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    if "AC" in s:
        print("Yes")
    else:
        print("No")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second

constexpr int mod = 1000000007;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
int a[200020];
int ans[200020];
int divisor[200020];

void calc(int n) {
	for (int i = 1; i < int(sqrt(n)) + 1; i++) {
		if (n % i == 0) {
			divisor[i]++;
			if (i != n / i) divisor[n / i]++;
		}
	}
}

void solve() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	int cnt = 0;
	for (int i = N; i >= 1; i--){
		if (divisor[i] % 2 != a[i]) {
			ans[i] = 1;
			cnt++;
			calc(i);
		}
	}

	cout << cnt << endl;
	for (int i = 1; i <= N; i++) {
		if (ans[i] == 1) cout << i << endl;
	}

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 3200
use std::io::Read;
use std::collections::VecDeque;
fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse::<i64>().unwrap();
    let mut queue = VecDeque::<i64>::new();
    queue.push_back(3);
    queue.push_back(5);
    queue.push_back(7);
    let mut ans = 0;    
    //while queue.
    while !queue.is_empty() {
        let current = queue.pop_front().unwrap();
        if current > n { continue; }
        if ['3','5','7'].into_iter().all(|x| current.to_string().contains(*x)) { ans += 1; }
        queue.push_back(10 * current + 3);
        queue.push_back(10 * current + 5);
        queue.push_back(10 * current + 7);
    }

    println!("{}", ans);
}


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

const int NMAX = 1e5 + 5;

int n, m;
int depth[NMAX];
vector <int> G[NMAX];
int curr[NMAX];

void dfs(int nod, int parent) {
    for (auto v: G[nod]) {
        if (v == parent)
            continue;

        if (depth[v]) {
            // muchie de intoarcere
            if (depth[v] < depth[nod]) {
                curr[nod] ^= 1;
                cout << nod << " " << v << "\n";
            }
        }
        else {
            depth[v] = depth[nod] + 1;
            dfs(v, nod);
        }
    }

    if (curr[nod])
        cout << nod << " " << parent << "\n", curr[nod] ^= 1;
    else if (parent > 0) {
        cout << parent << " " << nod << "\n", curr[parent] ^= 1;
    }
}

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

    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    if (m % 2 == 1) {
        cout << -1;
        return 0;
    }


    depth[1] = 1;
    dfs(1, 0);

    return 0;
}


Measured memory_bytes: 15488
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
	int k;string s;
	cin >> k >> s;
	int len = s.size();
	if(len <= k)
	{
		cout << s;
		return 0;
	}
	for(int i = 0;i < k;++i)
		cout << s[i];
	cout << "...";
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
using namespace std;
int main(){
long a, b, x;
cin >> a;
cin >> b;
cin >> x;
long upper = b / x;
if (a == 0) upper++;
long lower = 0;
if (a-1 >= 0) lower = (a-1) / x;

cout << upper - lower;
return 0;
}


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

int decimal(const char* mcxi) {
  const char* nowp=mcxi;
  int num=1;
  int decimal=0;
  for(;*nowp;nowp++) {
    switch(*nowp) {
    case 'm':
      decimal+=1000*num;
      num=1;
      break;
    case 'c':
      decimal+=100*num;
      num=1;
      break;
    case 'x':
      decimal+=10*num;
      num=1;
      break;
    case 'i':
      decimal+=1*num;
      num=1;
      break;
    default:
      if(isdigit(*nowp))num=*nowp-'0';
    }
  }
  return decimal;
}
 
void sum(char* mcxi,int num){
  if(num>=1000){
    if(num>=2000)*(mcxi++)=(num/1000)+'0';
    *(mcxi++)='m';
    num%=1000;
  }
  if(num>=100) {
    if(num>=200)*(mcxi++)=(num/100)+'0';
    *(mcxi++)='c';
    num%=100;
  }
  if(num>=10) {
    if(num>=20)*(mcxi++)=(num/10)+'0';
    *(mcxi++)='x';
    num%=10;
  }
  if(num>=1) {
    if(num>=2)*(mcxi++)=(num/1)+'0';
    *(mcxi++)='i';
    num%=1;
  }
  *mcxi=0;
}
 
int main(void) {
  int num,i;
  char MCXI_1[100],MCXI_2[100];

  struct{
    char sum[100];
  }SUM[9999];

  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf("%s%s",MCXI_1,MCXI_2);
    sum(SUM[i].sum,decimal(MCXI_1)+decimal(MCXI_2));
  }

  for(i=0;i<num;i++){
    printf("%s\n", SUM[i].sum);
  }

  return 0;
}

Measured memory_bytes: 784
N,X,Y = map(int,input().split())
D = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1,N):
        D[i][j] = j-i
D[X-1][Y-1] = 1
A = [0]*(N-1)
for i in range(N):
    for j in range(i+1,N):
        c,d = max(i,X-1),min(i,X-1)
        e,f = max(Y-1,j),min(j,Y-1)
        a = min(D[i][j-1]+1,D[d][c]+D[f][e]+1)
        D[i][j] = a
        if a == 0:
            continue
        A[a-1] += 1
for a in A:
    print(a)

Measured memory_bytes: 83420
def isort! a, n
  1.upto(n-1) do |i|
    puts a.map(&:to_s).join(" ")
    v = a[i]
    j = i-1
    while j >= 0 && a[j] > v
      a[j+1] = a[j]
      j -= 1
    end
    a[j+1] = v
  end
end

n = gets.chomp.to_i
a = gets.split.map(&:to_i)

isort!(a, n)
puts a.map(&:to_s).join(" ")


Measured memory_bytes: 6892
#include "bits/stdc++.h"

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================

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

	int n; cin >> n;
	vi a(n);
	REP(i, n) cin >> a[i];

	int ans = 0;
	REP(i, n - 1) {
		int minJ = i;
		REP2(j, i, n) {
			if (a[j] < a[minJ]) {
				minJ = j;
			}
		}
		if (a[i] != a[minJ]) {
			swap(a[i], a[minJ]);
			ans++;
		}
	}

	REP(i, n - 1) cout << a[i] << " ";
	cout << a[n - 1] << "\n";
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,j;
	string s;
	cin>>n>>s;
	for(i=0;i<n;i++)if(s[i]=='>')
		for(j=n-1;j>=0;j--)if(s[j]=='<')goto L;
	L:cout<<n-min(i,n-j-1)<<endl;
}

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

int main() {
ll n;
cin>>n;
ll ans=100000000000000;
for(ll i=sqrt(n)+1;i>0;i--)
{
    
    if(n%i==0)
    {
        ll temp=0;
        temp+=(i-1);
        temp+=((n/i)-1);
        if(temp<ans)
        {
            ans=temp;
        }
    }
}
cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

const ll MOD = 1'000'000'007;

int main(void) {
	std::ios_base::sync_with_stdio(false);

	string L; cin >> L;
	vector<vector<ll>> dp(L.size() + 1);
	for (int i = 0; i <= L.size(); ++i) dp[i].resize(2);
	dp[0][0] = 1;
	dp[0][1] = 2;
	for (int i = 1; i < L.size(); ++i) {
		if (L[i] == '1') {
			dp[i][0] = (dp[i - 1][0] * 3 + dp[i - 1][1]) % MOD;
			dp[i][1] = (dp[i - 1][1] * 2) % MOD;
		}
		else {
			dp[i][0] = (dp[i - 1][0] * 3) % MOD;
			dp[i][1] = dp[i - 1][1];
		}
	}

	cout << ((dp[L.size() - 1][0] + dp[L.size() - 1][1]) % MOD) << endl;

	return 0;
}



Measured memory_bytes: 5840
from collections import deque
H, W = map(int,input().split())
G = [input() for _ in range(H)]
white = 0
dist = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set()
for line in G:
  white+=line.count('.')

D = deque()
D.append((0,0,1))
rout = -1
while D:
  h, w, c = D.popleft()
  if h == H-1 and w == W-1:
    rout = c
    break
  if (h, w) in visited or G[h][w] == '#':
    continue
  else:
    visited.add((h, w))
  for dh, dw in dist:
    if (0<=h+dh<H) and (0<=w+dw<W):
      if (h+dh, w+dw) not in visited and G[h+dh][w+dw] != '#':
        D.append((h+dh, w+dw, c+1))
        
if rout == -1:
  print(rout)
else:
  print(white-rout)



Measured memory_bytes: 74152
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};


int N;
string s[102];
map<string,int> mp;

int main(){
      cin>>N;
      rep0(i,N) cin>>s[i];
      mp[s[0]]++;
      int f=s[0].size()-1;
      char k=s[0][f];
      bool ok=true;
      rep1(i,N-1){
            if(k!=s[i][0]) ok=false; 
            mp[s[i]]++;
            int e=s[i].size()-1;
            k=s[i][e];
      }
      rep0(i,N){
            if(mp[s[i]]>1) ok=false;
      }
      if(ok) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
#include<cstring>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; i++) {
		if ((2 * i + 4 * (x - i)) == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3632
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int x;
cin>>x;
if(x>=30)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}




/*
 * ||||


 */

Measured memory_bytes: 3592
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

K = inp()
X = [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]
print(X[K-1])

Measured memory_bytes: 4076
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> vec(n);
	for ( int i = 0 ; i < n ; i++ ) cin >> vec[i];
	
	int cnt = 1 ;
	for ( int i = 1 ; i < n ; i++ )
	{
		int j = i;
		for ( j = i ; j > 0 ; j-- )
			if ( vec[i] < vec[j] ) break; 
		if ( j == 0 && vec[i] >= vec[0] ) cnt++;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int min(int a, int b, int c){
  int m = a;
  if(b < m)
    m = b;
  if(c < m)
    m = c;
  return m;
}

int main(void){
  int P, Q, R;
  scanf("%d%d%d", &P, &Q, &R);

  int m = min(P+Q, Q+R, R+P);

  printf("%d\n", m);

  return 0;
}


Measured memory_bytes: 128
K, S = map(int, input().split())

c = 0
for x in range(K + 1):
    if x > S:
        break
    for y in range(K + 1):
        if x + y > S:
            break
        z = S - x - y
        if 0 <= z <= K:
            c += 1

print(c)

Measured memory_bytes: 40924
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define MAX 101

static int top = 0;
static int stack[MAX];

void push(int x);
int pop(void);
int isEmpty(void);
int isFull(void);


int main(void){
  char s, xs[7];
  int i, x, c = 0;

  while(c == 0){
    scanf("%c", &s);
    switch(s){
    case '+':
      push(pop()+pop());
      break;
    case '-':
      x = pop();
      push(pop()-x);
      break;
    case '*':
      push(pop()*pop());
      break;
    case '\n':
      c++;
      break;
    default:
      if(isdigit((int)s)){
	i = 0;
	xs[0] = s;
	while(isdigit((int)s)){
	  xs[i] = s;
	  i++;
	  scanf("%c", &s);
	}
	xs[i] = '\0';
	push(atoi(xs));
      }
    }
  }
  printf("%d\n", pop());
  return 0;
}


void push(int x){
  if(isFull()){
    printf("?????????????????????\n");
    exit(1);
  }
  stack[++top] = x;
}


int pop(void){
  if(isEmpty()){
    printf("??¢??????????????????\n");
    exit(1);
  }
  return stack[top--];
}


int isEmpty(void){
  return top == 0;
}


int isFull(void){
  return top >= MAX-1;
}

Measured memory_bytes: 548
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
using namespace std;

#define FOR_ALL_CIN(xs) for (auto& x : (xs)) cin >> x

int main()
{
	cout << fixed << setprecision(6);
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> paths;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			paths.push_back(make_pair(i, j));
		}
	}

	if (k > (n - 1) * (n - 2) / 2) {
		cout << -1 << endl;
		return 0;
	}

	auto it = paths.begin() + (n - 1);
	for (int i = 0; i < k; ++i) {
		it = paths.erase(it);
	}
	

	cout << paths.size() << endl;
	for (auto a : paths) {
		cout << a.first << " " << a.second << endl;
	}
	return 0;
}

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

using namespace std;

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

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

vector<int> ok[20000];

void solve(long long S) {
    ll v = sqrt(S);

    while (v * v < S) {
        v++;
    }

    ll a = v * v - S;

    cout << 0 << " " << 0 << " " << v << " " << a << " " << 1 << " " << v << endl;
}

int main() {
    long long S;
    scanf("%lld", &S);
    solve(S);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin >>s;
  int p=0;
  if(n%2==0){
    for(int i=0;i<(s.size()/2);++i){
      if(s[i]==s[i+n/2]) p++;
    }
    if(p==n/2) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
  else cout <<"No"<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

#define pb push_back

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;

int main() {
    int n,y;
    cin >> n >> y;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n-i; j++) {
            int k = n-i-j;
            if(y == 10000*i + 5000*j + 1000*k) {
                cout << i << " " << j << " " << k << "\n";
                return 0;
            }
        }
    }

     cout << -1 << " " << -1 << " " << -1 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    while(1){
        ll n;cin>>n;
        if(n==0)break;
        vector<double> a(n);
        rep(i,n)cin>>a[i];
        double avg=0;
        rep(i,n)avg+=a[i]/n;
        double sum=0;
        rep(i,n)sum+=(a[i]-avg)*(a[i]-avg);
        double v=sqrt(sum/n);
        printf("%.7f\n",v);
    }
}

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



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    ll N, L; cin >> N >> L;
    vector<ll> ap(N);
    rep(i, N) ap[i] = L + i;
    ll diff = INF;
    ll ans = INF;
    ll sum = accumulate(all(ap), 0LL);
    rep(i, N) {
        ll cnt = 0;
        rep(j, N){
            if (i != j) cnt += ap[j];
        }
        if (chmin(diff, abs(sum - cnt))) ans = cnt;
    }
    pt(ans);
}

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

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
    vector<int> cal;
    cal.push_back(10*a+b+c);
    cal.push_back(10*a+c+b);
    cal.push_back(10*b+a+c);
    cal.push_back(10*b+c+a);
    cal.push_back(10*c+a+b);
    cal.push_back(10*c+b+a);
    sort(cal.begin(),cal.end());
    cout << cal[cal.size()-1] << endl;
}

Measured memory_bytes: 256
import Data.List

main = do
  n <- read <$> getLine
  x <- map (read :: String -> Int) . words <$> getLine
  let y = zipWith (-) x [1..]
      b = head . drop (div n 2) $ sort y
      ans = sum [abs (t-b) | t <- y]
  putStrLn $ show ans


Measured memory_bytes: 108924
L = input()
P = 10**9+7
N = len(L)
dp = [[0 for i in range(2)] for j in range(N)]
dp[0][0] = 1
dp[0][1] = 2
for i in range(N-1):
    if L[i+1] == "1":
        dp[i+1][0] = (dp[i][0]*3 +dp[i][1])%P
        dp[i+1][1] = (dp[i][1]*2)%P
    else:
        dp[i+1][0] = (dp[i][0]*3)%P
        dp[i+1][1] = dp[i][1]
print((dp[N-1][0]+dp[N-1][1])%P)

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

int main(){
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	
	int g=__gcd(n,m);
	long long lcm=n*1LL*m/g;
	
	int move1=lcm/m;
	int move2=lcm/n;
	
	int ptr1=0,ptr2=0,ok=1;
	while(ptr1<n){
		if(s[ptr1]!=t[ptr2]){
			ok=0;
			break;
		}
		else {
			ptr1+=move1;
			ptr2+=move2;
		}
	}
	
	if(ok){
		printf("%lld\n",lcm);
	}
	else printf("-1");
}

Measured memory_bytes: 512
#include <iostream>
#include <list>
#include <string>
using namespace std;
enum{M_P,M_A,M_B,M_C,M_D,M_E,M_F,M_S,M_M,M_END};
typedef pair<double,string> P;

double calc(int d[]){
     int earn=d[M_S]*d[M_F]*d[M_M]-d[M_P];
     int times=d[M_A]+d[M_B]+d[M_C]+(d[M_D]+d[M_E])*d[M_M];
     //cout<<times<<endl;
     return (double)earn/times;    
}
bool isgrater(const P& a,const P& b){
     if(a.first!=b.first)return a.first>b.first;
     return a.second<b.second;
}
int main(){
     int N;
     while(cin>>N,N){
	  //string namelist[N];
	  list<P> ans;

	  for(int i=0;i<N;i++){
	       string s;
	       cin>>s;
	       int d[M_END];
	       for(int i=0;i<M_END;i++){
		    cin>>d[i];
	       }
	       double p=calc(d);
	       ans.push_back(pair<double,string>(p,s));
	  }
	  ans.sort(isgrater);

	  list<P>::iterator itr=ans.begin();
	  while(itr!=ans.end()){
	       cout<<itr->second<<endl;
	       itr++;
	  }
	  cout<<"#"<<endl;
     }
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := Scanner()
	fmt.Println("ABC" + n)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define int long long
#define multi_test true and false
using namespace std;

void solve()
{
    int x;
    cin >> x;
    vector<int> factors;
    for (int i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            factors.push_back(i);
            if (i != x / i)
                factors.push_back(x / i);
        }
    }
    sort(factors.begin(), factors.end());
    for (int i : factors)
    {
        for (int a = -1000; a <= 1000; a++)
        {
            int b = a + i;
            if ((b * b * b * b * b) - (a * a * a * a * a) == x)
            {
                cout << b << ' ' << a << endl;
                return;
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int test = 1;
    if (multi_test)
        cin >> test;

    while (test--)
        solve();
    return 0;
}

Measured memory_bytes: 3592
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
for i in range(10**n):
    ans=str(i)
    if len(ans)==n and all(ans[s-1]==str(c) for s,c in sc):
        print(ans)
        exit()
print(-1)

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


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)


L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])

for i in range(N-1, -1, -1):
    R[i] = gcd(R[i+1], A[i])

ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))

print(ans)

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

const int MAX_N = 123457;

int main() {
    vector<bool> is_prime(MAX_N*2, true);
    is_prime[0] = is_prime[1] = false;

    int n;
    while(cin >> n, n) {
        int less_n = 0;
        int all_n = 0;
        for(int i=2; i<=2*n; ++i) {
            if(is_prime[i]) {
                all_n++;
                if(i <= n) {
                    less_n++;
                }
                for(int j=2*i; j<=2*n; j+=i) {
                    is_prime[j] = false;
                }
            }
        }
        cout << all_n - less_n << endl;
    }
}


Measured memory_bytes: 3100
#include<iostream>

using namespace std;

int main() {
    int x;
    cin >> x;
    int lower = x % 100;
    int upper = x / 100;
    int count = lower / 5;
    if (lower % 5 != 0)
        ++count;
    if (count <= upper) cout << "1";
    else cout << "0";
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#include<iomanip>
#include<deque>
#include<utility>
#include<functional>
#include<sstream>
#include<ctime>
#define INF 1000000000
#define fi first
#define se second
#define N 100005
#define P 1000000007
#define debug(x) cerr<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int a[N];
int main()
{
    int n, i, b[3], now = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    for(i=n;i>1&&now<2;i--)
        if (a[i] == a[i - 1])
        {
            b[now++] = a[i];
            i--;
        }
    if (now < 2)
        printf("0\n");
    else cout<<(LL)b[0] * b[1]<<endl;
}
// davidlee1999WTK 2017/
// ios::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:102400000,102400000") compiler c++,not g++
//#include<bits/stdc++.h>
/*

*/

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int n,m,k,a[2000001],b[2000001];
char s[2000001],t[2000001];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s%s",s,t);
	int lens=strlen(s),lent=strlen(t);
	for(int i=0;i<lens/2;i++) 
	{
	    char ch=s[i];s[i]=s[lens-i-1];s[lens-i-1]=ch;
	}
	for(int i=0;i<lent/2;i++)
	{
		char ch=t[i];t[i]=t[lent-i-1];t[lent-i-1]=ch;
	}
	for(int i=lens;i<=2000000;i++) s[i]='0';
	for(int i=lent;i<=2000000;i++) t[i]='0';
	for(int i=0;i<=2000000;i++) a[i]=s[i]=='1',b[i]=t[i]=='1';
	for(int i=max(n,m)-1;i>=0;i--)
		if((a[i]==1)&&(b[i]==1))
		{
			a[i]=b[i]=0;
			a[i+1]++;b[i+1]++;
			int j=i+1;int yu=k-1;
			while(yu)
			{
				if(a[j]==2) {a[j+1]++;a[j]=0;}else
				if(b[j]==2) {b[j+1]++;b[j]=0;}else
				if((a[j]==1)&&(b[j]==1))
				{
					a[j]=b[j]=0;yu--;
					a[j+1]++;b[j+1]++;
				}else break;
				j++;
			}
			if(a[j]==2) {a[j+1]++;a[j]=0;}
			if(b[j]==2) {b[j+1]++;b[j]=0;}
		}
	int j=2000000;while(a[j]==0) j--;
	for(int i=j;i>=0;i--) printf("%d",a[i]);cout<<endl;
	j=2000000;while(b[j]==0) j--;
	for(int i=j;i>=0;i--) printf("%d",b[i]);cout<<endl;
	return 0;
} 

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

int main(){
    
    int N,K;
    cin >> N >> K;
    int arr[N];
    
    for(int i=0;i<N;i++){
        cin >> arr[i];
    }
    
    vector<bool>dp(K+1, false);
    
    for(int i=0;i<=K;i++){
        for(int j=0;j<N;j++){
            if(i-arr[j] >=0 and dp[i-arr[j]] == false)
                dp[i] = true;
        }
    }

    if(dp[K]){
        cout <<"First";
    }
    else 
        cout << "Second";
	return 0;
}


Measured memory_bytes: 256
// 及时当勉励，岁月不待人！
//当前状态 : attempted
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
inline int read() { int ret = 0, sgn = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-')sgn = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); }return ret * sgn; }


//结构体
struct node {
    int mv;
    bool operator<(const node& b)const
    {
        return this->mv < b.mv;
    }
};
//全局变量
priority_queue<node> q;
const int maxn = 2e5+3;
int input[maxn];
//函数
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll sum = 0;
    for(int i=1;i<=n;++i){
        cin>>input[i];
    }
    sort(input+1,input+n+1,cmp);
    sum+=input[1];
    for (int i = 1; i <= 2; ++i) { q.push(node{input[2]}); }
    
    for (int i = 3; i <= n; ++i) {
        node t = q.top(); q.pop();
        sum += t.mv;
        for (int j = 1; j <= 2; ++j) { q.push(node{input[i]}); }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5108
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::u128;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<f64>();
    let a1 = line[0] as u128 /100*100;
    let a2 = line[0] as u128%100;
    let b = line[1];
    let b1 = (line[1] as f64).floor() as u128;
    let b2 = (line[1] *100.0).round() as u128%100;

    // dbg!(a1);
    // dbg!(a2);
    // dbg!(b);
    // dbg!(b1);
    // dbg!(b2);
    //println!("{}", ans_int + ans_f);
    println!("{}",
             a1*b1+b1*a2+(a1/100*b2) + (b2*a2/100)
    );
}


Measured memory_bytes: 2684
import java.util.Scanner;

public class Main{

   static void trace(int A[],int N){
        for (int i = 0; i<N;i++){
            if (i>0) System.out.print(" ");
            System.out.print(A[i]);
        }
        System.out.println();
    }
   static void insertionsort(int A[],int N){
        for (int i = 1; i<N;i++){
            int v =  A[i];
            int j = i-1;
            while (j>=0&&A[j]>v){
                A[j+1] = A[j];
                j--;
            }
            A[j+1] = v;
            trace(A,N);
        }
    }

    public static void main(String[]args){
        int A[] = new int[100];
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for (int i = 0; i<N; i++){
            A[i] = scanner.nextInt();
        }

        trace(A,N);
        insertionsort(A,N);
    }
}



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

#define INF INT32_MAX
#define MAX 100000

int main() {
	int H, W, h, w;

	cin >> H >> W >> h >> w;

	int ans = (H -h) * (W -w);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define PI 3.14159265359
#define eps (1e-8)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

string k;
int D;
int dp[10001][100][2];

int f(int indx,int sum,int nine){
    if(indx==k.size())return sum==0;
    if(dp[indx][sum][nine]!=-1)return dp[indx][sum][nine];
    int ans=0;
    int e = nine?9:(k[indx]-'0');
    for(int i=0;i<=e;i++){
        ans=(ans+f(indx+1,(sum+i)%D,nine||(i<e)))%MOD;
    }
    return dp[indx][sum][nine]=ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>k>>D;
    cout<<(f(0,0,0)-1+MOD)%MOD;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n-1){
    if(s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  rep(i,n-2){
    if(s[i] == s[i+2]){
      cout << i+1 << " "<< i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " "<< -1 << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

#define MAX_N 200000

class UnionFind {
private:
  // ?????¨??¨?????±???
  int par[MAX_N];
  int rank[MAX_N];
  int s[MAX_N];
public:
  void init(int n);
  int find(int x);
  void unite(int x, int y);
  bool same(int x, int y);
};

// ????´???°n??§?????????
void UnionFind::init (int n) {
  for(int i=0; i<n; i++) {
    par[i] = i;
    rank[i] = 0;
    s[i] = 1;
  }
}

// ????´?x??????????±???????
int UnionFind::find(int x) {
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// x??¨y????±??????????????????????
void UnionFind::unite(int x, int y) {
  // x??¨y??????
  x = find(x);
  y = find(y);
  if(x == y) return;

  // y??????????????±????????±??????x?????????y??????
  if(rank[x] < rank[y]) {
    par[x] = y;
    s[y] = s[x] + s[y];
  }
  else {
    par[y] = x;
    s[x] = s[x] + s[y];
    if( rank[x] == rank[y] ) rank[x]++;
  }
}

// x??¨y???????????????????±??????????
bool UnionFind::same(int x, int y) { return find(x) == find(y);}

struct edge{
  int u, v, cost;
};

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

edge es[10000];
int v, e;
UnionFind uf;

int kruskal() {
  sort(es, es+e, comp);
  uf.init(v);
  int res = 0;
  REP(i, e) {
    edge e = es[i];
    if(!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

signed main(void)
{
  while(true) {
    cin >> v;
    if(!v) break;
    cin >> e;
    REP(i, e) {
      int a, b, c;
      scanf("%d,%d,%d", &a, &b, &c);
      es[i] = {a, b, c/100-1};
    }
    cout << kruskal() << endl;
  }

  return 0;
}

Measured memory_bytes: 3208
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a,b,c >=-100 && a,b,c<=100)
	{
		if(c>=a && c<=b)
		{
			printf("Yes\n");
		}
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include<string>
#include<vector>

using namespace std;

int main() {
	int n, num = 0, re = 0;
	cin >> n;
	for (int i = 0; i < 100/4; i++)
	{
		for (int j = 0; j < 100/7; j++)
		{
			if(4*i+7*j==n)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


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

int main() {
    int n;
    cin >> n;
    map<string, int> s;
    for (int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        s[tmp]++;
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19204
# 入力
N, A, B, C, D = map(int, input().split())

# 左から右を引いた値が非負であるものの個数がm とすると負であるものの個数を N - 1 - m である。
# 各 m について一番右にBをかけるか判定する
ans = (
    'YES' if any(
        A + C * m - D * (N - 1 - m) <= B <= A + D * m - C * (N - 1 - m)
        for m in range(N)
    ) else
    'NO'
)

# 出力
print(ans)


Measured memory_bytes: 2940
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
string s ;
int k ; 
int n ; 
int dp[101][4][2] ;
int dfs(int x, int cur, int flag){
    if ( x == n ){
        if ( cur == k ) return 1 ;
        return 0 ; 
    }
    if ( dp[x][cur][flag] != -1 ) return dp[x][cur][flag] ;
    int ans = 0 ; 
    int digit = s[x] - '0' ;
    if ( not flag ) {
        for(int i = 0; i < digit; i++){
            if ( i > 0 && cur < k ) ans += dfs(x + 1, cur + 1, 1) ;
            else if ( i == 0 ) ans += dfs(x + 1, cur, 1) ;
        }
        if ( digit != 0 && cur < k ) {
            ans += dfs(x + 1, cur + 1, 0) ;
        }
        else if ( digit == 0 ) ans += dfs(x + 1, cur, 0) ;
    }
    else{
        ans += dfs(x + 1, cur, 1) ;
        for(int i = 1; i < 10; i++){
            if ( cur < k ) ans += dfs(x + 1, cur + 1, 1) ;
        }
    }
    return dp[x][cur][flag] = ans ;
}
signed main(){
    fastio
    memset(dp, -1 , sizeof dp) ;
    cin >> s >> k ; 
    n = (int) s.size() ;
    int ans = dfs(0, 0, 0) ;
    cout << ans << endl ;
    return 0; 
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define print(n) cout << n << endl;


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

    if(N%1000!=0){
    cout << 1000-N%1000 << endl;
    }else{
        cout << 0 << endl;
    }




    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define ull unsigned long long int
#define T int test; scanf("%d",&test); while(test--)
#define pb push_back
#define in insert
#define PI acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define lsc(n) scanf("%lld",&n)
#define lsc2(a,b) scanf("%lld%lld",&a,&b)
#define rep(i,n) for(i=0;i<n;i++)
#define fr(i,a,b) for(i=a;i<b;i++)
#define gcd(a,b) __gcd(a,b)
#define gcd3(a,b,c) __gcd(__gcd(a,b),c)
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;



int main()
{
	ll n,k;
	lsc2(n,k);
	ll a[n],i,s=0;
	rep(i,n)
	{
		lsc(a[i]);
	}
	sort(a,a+n);
	rep(i,n-k)
	{
		s+=a[i];
	}
	cout << s << endl;
    return 0;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc139/submissions/7298310

#include <iostream>
#include <vector>

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

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[1010][1010] = {};
    int head[1010] = {};
    rep(i,n){
        rep(j,n-1){
            int x;
            cin >> x;
            x--;
            a[i][j] = x;
        }
    }
    int turn = 0;
    int used[1010] = {};
    for (int i = 0; i < 1010; i++) used[i] = -1;
    while(true){
        bool ng = true;
        int empty_cnt = 0;
        rep(i,n){
            if (head[i] == n-1) {
                empty_cnt++;
                continue;
            }
            int j = a[i][head[i]];
            if (used[i] == turn || used[j] == turn) continue;
            if (a[j][head[j]] == i) {
                head[i]++;
                head[j]++;
                used[i] = used[j] = turn;
                ng = false;
            }
        }
        if (empty_cnt == n) break;
        if (ng) {
            cout << -1 << endl;
            return 0;
        }
        turn++;
    }
    cout << turn << endl;

    return 0;
}


Measured memory_bytes: 4352
w, h, n = map(int, input().split())
l = [[0]*w for _ in range(h)]
count = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 2:
        for i in range(h):
            for j in range(x,w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 3:
        for i in range(y):
            for j in range(w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1
    if a == 4:
        for i in range(y,h):
            for j in range(w):
                if l[i][j] == 0:
                    l[i][j] = 1
                    count += 1

print(w*h - count)           

Measured memory_bytes: 9156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

long long par[2001000];
long long ranks[2001000];
//rootからどれだけ右にあるか
long long diff_weight[2001000]={};

void init(long long n){
  for(long long i=0;i<n;i++){
    par[i]=i;
    ranks[i]=0;
  }
}

long long find(long long x){
  if(par[x]==x){
    return x;
  }else{
    int r=find(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
  }
}

long long weight(long long x){
  find(x);
  return diff_weight[x];
}

void unite(long long x,long long y,long long dist){
  dist-=weight(y);
  dist+=weight(x);
  x=find(x);
  y=find(y);
  if(x==y){
    return ;
  }
  if(ranks[x]<ranks[y]){
    par[x]=y;
    diff_weight[x]=(-dist);
  }
  else{
    par[y]=x;
    diff_weight[y]=dist;
  }
  if(ranks[x]==ranks[y]){
    ranks[x]++;
  }
}

bool same(long long x,long long y){
  return find(x)==find(y);
}


int main(){
  long long N,M;
  cin>>N>>M;
  bool judge=true;
  long long L,R,D;
  init(200020);
  for(long long i=0;i<M;++i){
    cin>>L>>R>>D;
    if(same(L,R)){
      if(weight(R)-weight(L)!=D){
        judge=false;
        break;
      }
    }
    else{
      unite(L,R,D);
    }
  }
  if(judge){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
return 0;
}


Measured memory_bytes: 9344
import java.io.*
import java.util.*

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val inp = Main.InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = Main.TaskC()
    solver.solve(inp, out)
    out.close()
}

class Main {
    internal class TaskC {
        fun solve(inp: InputReader, out: PrintWriter) {
            var n = inp.nextLong()
            var ans = Long.MAX_VALUE
            var d = 2L
            var isSimple = true
            while (d * d <= n) {
                if (n % d == 0L) {
                    isSimple = false
                    val curDist = (d - 1) + (n / d - 1)
                    ans = Math.min(ans, curDist)
                }
                d++
            }
            if (isSimple)
                ans = n - 1
            out.println(ans)
        }
    }

    internal class InputReader(stream: InputStream) {
        private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)
        private var tokenizer: StringTokenizer? = null

        init {
            tokenizer = null
        }

        operator fun next(): String {
            while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
                try {
                    tokenizer = StringTokenizer(reader.readLine())
                } catch (e: IOException) {
                    throw RuntimeException(e)
                }
            }
            return tokenizer!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return next().toLong()
        }
    }
}


Measured memory_bytes: 31516
using System;

class Abc
{
    static void Main()
    {
        int[] AB = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int A = AB[0];
        int B = AB[1];
        if (A == B) Console.WriteLine("Draw");
        else if (A == 1) Console.WriteLine("Alice");
        else if (B == 1) Console.WriteLine("Bob");
        else if (A > B) Console.WriteLine("Alice");
        else if (A < B) Console.WriteLine("Bob");
    }
}

Measured memory_bytes: 11092