akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

#define ALL(v) (v).begin(), (v).end()
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl;
#define DEBUG_VEC(v) cerr<<#v<<": ";for(auto x:v)cerr<<x<<" ";cerr<<endl

#define MOD 1000000007

int n,x;
ll a[125252];

int main(){
	cin>>n>>x;
	REP(i,n)cin>>a[i];
	if(accumulate(a,a+n,0ll)==x){
		cout<<n<<endl;
	}else{
		sort(a,a+n);
		int ans = 0;
		REP(i,n){
			if(x >= a[i]){
				x -= a[i];
				ans++;
			}else{
				break;
			}
		}
		if(ans==n)ans--;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    n, m = map(int, input().strip().split())
    h = list(map(int, input().strip().split()))

    flg = [True] * n

    for i in range(m):
        a, b = map(int, input().strip().split())
        if(h[a-1]<h[b-1]):
            flg[a-1] = False
        elif(h[a-1]>h[b-1]):
            flg[b-1] = False
        else:
            flg[a-1] = False
            flg[b-1] = False

    print(flg.count(True))

main()


Measured memory_bytes: 20144
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	int x,y;
	cin >> x >> y;

	int rx=-x,ry=-y,cnt=0;
	while(true){
		if(x==y){
			cout << cnt << "\n";
			return 0;
		}
		if(x==ry){
			cout << cnt+1 << "\n";
			return 0;
		}
		if(rx==y){
			cout << cnt+1 << "\n";
			return 0;
		}
		if(rx==ry){
			cout << cnt+2 << "\n";
			return 0;
		}
		x++; rx++;
		cnt++;
	}
	return 0;
}

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

typedef long long ll;

using namespace std;

int main() {
    ll n,m;
    string s;
    
    cin >> n;
    ll cnt = 0;
    for (auto i=5; i<=n; ++(++i)){
        ll cnt2=2;
        for (auto j=3; j<i; ++(++j)){
            if (i%j==0) ++cnt2;
        }
        if (cnt2 == 8) ++cnt;
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
integer a, b, c, d, k, m, mi, ans
ans = 0

read*, a, b, c
read*, k

d = a+b+c
m = MAX(a,b,c)
mi= MIN(a,b,c)
d = d-m-mi
ans = d+mi+(m*2**k)

write(*,'(I0)') ans
end


Measured memory_bytes: 512
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    r = N % 1000
    if r == 0:
        print(0)
    else:
        print(1000 - r)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9948
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

void main() {
	auto nums = readNums();
	if(nums[1] % nums[0] == 0) {
		writefln("%s", nums[0] + nums[1]);
	} else {
		writefln("%s", nums[1] - nums[0]);
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        int x = s.nextInt();
        int k = 1;

        while ((x * k % 360) != 0) {
            k++;
        }

        System.out.println(k);

    }

}

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

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

vector<int> E[100005];
bool check[100005];

void dfs(int fro, int to) {
  if (check[to] == 1) return;
  check[to] = 1;
  for(int& e:E[to]) {
    if (e != fro) dfs(to,e);
  }
}

int main() {
  int n,m,x,y,z;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    E[x-1].push_back(y-1);
    E[y-1].push_back(x-1);
  }
  for(int i = 0; i < n; i++) check[i] = 0;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if (check[i] == 0) {
      ans++;
      dfs(-1,i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int S=0;
  for (int i=0; i<N; i++) {
    int l, r;
    cin >> l >> r;
    S=S+r-l+1;    
  }
  cout << S << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sx, sy, tx, ty = map(int, input().split())
f = []
s = []
r = 0
u = 0
for i in range(abs(tx - sx)):
  if sx < tx:
    f.append("R")
    r = 1
  else: f.append("L")
for i in range(abs(ty - sy)):
  if sy < ty:
    f.append("U")
    u = 1
  else: f.append("D")
if u:
  s.append("D")
else:
  s.append("U")
for i in range(abs(tx - sx) + 1):
  if sx < tx:
    s.append("R")
  else: s.append("L")
for i in range(abs(ty - sy) + 1):
  if sy < ty:
    s.append("U")
  else: s.append("D")
if r:
  s.append("L")
else: s.append("R")
f2 = []
s2 = []
for x in f:
  if x == "U": f2.append("D")
  elif x == "D": f2.append("U")
  elif x == "R": f2.append("L")
  else: f2.append("R")
for x in s:
  if x == "U": s2.append("D")
  elif x == "D": s2.append("U")
  elif x == "R": s2.append("L")
  else: s2.append("R")
print("".join(f + f2 + s + s2))

Measured memory_bytes: 40944
#include <stdio.h>

int	is_square(int num)
{
	int	i = 0;

	while (i < 320)
	{
		if (i * i == num)
			return (1);
		i++;
	}
	return (0);
}

int	main()
{
	int	a, b, c;
	int	digit, num;

	scanf("%d %d\n", &a, &b);
	c = b;
	digit = 10;
	while (c > 9)
	{
		c /= 10;
		digit *= 10;
	}
	num = a * digit + b;
	if (is_square(num))
		printf("Yes\n");
	else
		printf("No\n");
	return (0);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  int A[Q], B[N];
  for(int i=0; i<Q; i++) cin >> A[i];
  for(int i=0; i<N; i++) B[i] = 0;
  for(int i=0; i<Q; i++){
    B[A[i]-1]++;
  }
  for(int i=0; i<N; i++){
    if(K > Q-B[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using P = pair<ll,ll>;

ll num[10][51];
ll res[10][51];

int main(){
    int N;
    cin >> N;
    vec<ll> D(N),C(N);
    for(int i=0;i<N;i++){
        cin >> D[i] >> C[i];
    }

    auto calc = [](ll a,ll b){
        if(a+b<10) return a+b;
        else{
            ll x = a+b;
            return x/10+x%10;
        }
    };

    for(int d=0;d<10;d++){
        num[d][0] = 0;
        res[d][0] = d;
        for(int i=0;i<50;i++){
            num[d][i+1] = 2*num[d][i]+(2*res[d][i]>=10? 2:1);
            res[d][i+1] = calc(res[d][i],res[d][i]);
        }
    }
    ll ans = 0;
    vec<ll> last(N);
    
    auto doubling = [&](ll d,ll c){
        ll now = -1;
        ll r = 0;
        vec<ll> cmp;
        for(int i=50;i>=0;i--){
            if(c>=(1LL<<i)){
                c -= 1LL<<i;
                r += num[d][i];
                cmp.push_back(res[d][i]);
            }
        }
        int n = cmp.size();
        now = cmp[0];
        for(int i=1;i<n;i++){
            r += (now+cmp[i]>=10? 2:1);
            now = calc(now,cmp[i]);
        }
        return P(r,now);
    };

    vec<ll> cmp;
    for(int i=0;i<N;i++){
        P p = doubling(D[i],C[i]);
        ans += p.first;
        cmp.push_back(p.second);
    }

    ll now = cmp[0];
    int n = cmp.size();
    for(int i=1;i<n;i++){
        ans += (now+cmp[i]>=10? 2:1);
        now = calc(now,cmp[i]);
    }
    cout << ans << endl;
}

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

int main(){
    int n, ans = 1;
    string s;
    cin >> n >> s;
    
    for(int i = 1; i < n; i++){
        if(s[i] != s[i-1]) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; };
}
void solve() {
  sort(all(A));
  reverse(all(A));

  int lg = 0, sh = 0;
  int prv = -1;
  for (auto x : A) {
    if (prv == x) {
      if (!lg) {
        lg = x;
      } else if (!sh) {
        sh = x;
        break;
      }

      prv = -1;
    } else {
      prv = x;
    }
  };

  cout << lg * sh << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100005;
int a[N],b[N],c[N];
ll f[N],ans;
int n;

int main(){
	scanf("%d",&n);
	for(int i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for(int i = 0;i < n;i++)
		scanf("%d",&b[i]);
	for(int i = 0;i < n;i++)
		scanf("%d",&c[i]);
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	for(int i = 0;i < n;i++){
		if(b[i] >= c[n-1]) break;
		f[i+1] = 1ll*n-(upper_bound(c,c+n,b[i])-c);
	}
	f[0] = 0;
	for(int i = 1;i <= n;i++)
		f[i] += f[i-1];
	for(int i = 0;i < n;i++){
		if(a[i] >= b[n-1]) break;
		int s = upper_bound(b,b+n,a[i])-b;
		ans += f[n]-f[s];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
import sys

#tmp= int(input())
tmp= float(input())
#tmp = input().split()
#a,b = list(map(lambda a: int(a), tmp))


pi=3.141592653589793
print('{:.6f}'.format(tmp**2*pi),'{:.6f}'.format(tmp*2*pi))




Measured memory_bytes: 5588
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        String U = scanner.next();

        if(U.equals(S)){
            A--;
        } else if(U.equals(T)){
            B--;
        }

        System.out.println(A + " " + B);
    }
}


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

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

using namespace std;

typedef long long LL;

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

const int MOD = 1000000007;

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

    int N, K;
    cin >> N >> K;

    int b = K;
    LL ans = 1;
    while (b-1 < N) {
        ++ans;
        b *= K;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    g = {i: [] for i in range(1, n + 1)}

    for _ in range(m):
        a, b = list(map(int, readline().split()))
        g[a].append(b)
        g[b].append(a)

    from collections import deque

    que = deque()
    que.append(1)
    ans = [-1] * (n + 1)
    ans[1] = 0

    while que:
        cur = que.popleft()
        for nx in g[cur]:
            if ans[nx] == -1:
                ans[nx] = cur
                que.append(nx)

    print("Yes")
    print(*ans[2:], sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 96916
from bisect import bisect_left,bisect_right

S = input()

def b_search(Loop,key):
    #keyマス目から進んで入るループの場所とそこまでの距離
    if S[key] == "R":
        loop = Loop[bisect_left(Loop,key)]
        dist = loop - key
        return (loop,dist)
    else:
        loop = Loop[bisect_left(Loop,key)-1]
        dist = key - loop
        return (loop,dist)

Loop = []
for i in range(len(S)-1):
    if S[i] == "R" and S[i+1] == "L":
        Loop.append(i)

Ans = [0 for _ in range(len(S))]
for i in range(len(S)):
    loop,dist = b_search(Loop,i)[0],b_search(Loop,i)[1]
    if S[i] == "R":
        Ans[i+dist+(dist%2)] += 1
    else:
        Ans[i-dist+(dist%2)] += 1

ans = " ".join(map(str,Ans))
print(ans)


Measured memory_bytes: 12532
N, L = map(int, input().split())

apples = []
apples_abs = []

for i in range(1, N+1):
    apple = L+i - 1
    apples.append(apple)
    apples_abs.append(abs(apple))

min_apple_idx = apples_abs.index(min(apples_abs))
apples.pop(min_apple_idx)
print(sum(apples))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    string s,t;cin>>s>>t;
    int mka = t.length();
    if(s == t){
    	cout<<"0";
        return 0;
    }
    for(int i = 0;i<=s.length()-t.length();i++){
        int kasanari = 0;
        for(int j = 0;j<t.length();j++){
           if(s[i+j]!=t[j])kasanari += 1;
        }
        mka = min(mka,kasanari);
    }
    cout<<mka;
    return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <unordered_map>
#include <cmath>
#include <set>
#include <queue>
using namespace std;

int main(){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
    string s;
    cin >> s;
    s = '0' + s;
    int n = s.size();
    int a0, a1;
    a0 = s[n-1] - '0';
    a1 = 10 - a0;
    for(int i = n-2; i >= 0; i--){
      	int tmp = s[i] - '0', t = a0;
      	a0 = min(a0, a1 + 1) + tmp;
		a1 = min(t + 1, a1) + 9 - tmp;
    }
    cout << a0 << '\n';
}


Measured memory_bytes: 2332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


int main() {
    lli N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0; v<n; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;

  for(u=0; u<n; u++) color[u] = WHITE;
  tt = 0;

  for(u=0; u<n; u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0; u<n; u++){
    printf("%d %d %d\n", u+1, d[u], f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++) M[i][j] = 0;
  }

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int ans;
		ans = 0;
		for(;;){
			int a = scan.nextInt();
			String op = scan.next();
			int b = scan.nextInt();
			if(op.equals("?"))
				break;
			if(op.equals("+"))
				ans = a + b;
			else if(op.equals("-"))
				ans = a - b;
			else if(op.equals("*"))
				ans = a * b;
			else if(op.equals("/"))
				ans = a / b;
		System.out.println(ans);
	}
	}
	}

Measured memory_bytes: 26164
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1005],t=0;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[i]<a[j])
			{
				swap(a[i],a[j]);
			}
		}
	}
	for(int i=0;i<k;i++)
	{
		t+=a[i];
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 256
while True:
	try:
		s=input()
	except:
		exit()
	a=b=0
	for i in range(len(s)-2):
		if s[i]=="J" and s[i+1]=="O" and s[i+2]=="I":
			a+=1
		elif s[i]=="I" and s[i+1]=="O" and s[i+2]=="I":
			b+=1
	print(a)
	print(b)


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

def findLoop():
  dp = [0 for _ in range(N)]
  next = 0;
  count = 1;
  acc = []
  while dp[next]==0:
    dp[next] = count
    acc.append(next+1)
    count += 1
    next = A[next]-1
  freq = count - dp[next]
  return(acc[:dp[next]-1], acc[len(acc)-freq:])

first, loop = findLoop()

if K<max(0, len(first)-1):
  print(first[K])
else:
  print(loop[ ( K-len(first) ) % len(loop)])
  

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = 0; i <= n; ++i) {
    if (s.substr(i, n - i) == t.substr(0, n - i)) {
      cout << n + i<< endl;
      return 0;
    }
  }
}


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

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();

	int[] money = new int[3];
	money[0] = a;
	money[1] = b;
	money[2] = c;

	Arrays.sort(money);

	int sum = money[2]*10+money[1]+money[0];

	System.out.println(sum);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;


int main() {
	int n, T,c[110],t[110],ans=1000,k=0;
	cin >> n >> T;
	for (int i = 1; i <= n;i++) {
		cin >> c[i] >> t[i];
		if (t[i]<=T&&c[i]<=ans) {
			ans = c[i];
			k = 1;
		}
	}
	if (k==0) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << endl;
	}
}

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

int main(){
  int total;
  int num;
  cin >> num >> total;
  bool judge = false;
  int i = 0;
  while(2 * i <= total && i <= 100){
    if(i * 2 + (num-i) * 4 == total) {
	judge = true;
      break;
    }
    i++;
  }
  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

int mod = 1000000007;
int prev_[100009], dp[100009], dpr[100009];
int mulr[100009];

long long Q;
long long N[1 << 18], C[1 << 18], Base[1 << 18];
long long Answer[1 << 18];

void init(int pos) {
	int lims = (pos - 2) * (pos - 1) / 2;
	int lim2 = max(1, lims);
	if (pos == 1) {
		for (int i = lims; i <= 100000; i++) dp[i] = 1;
	}
	else {
		for (int i = lims; i <= 100000; i++) prev_[i] = dp[i];
		for (int i = lims; i <= 100000; i++) dp[i] = 0;
		for (int i = lims; i <= 100000 - pos; i++) dp[i + pos - 1] = prev_[i];
		for (int i = lims; i <= 100000 - pos; i++) {
			dp[i + pos] += dp[i];
			if (dp[i + pos] >= mod) dp[i + pos] -= mod;
		}
		for (int i = 0; i < lims; i++) dp[i] = 0;
	}
	for (int i = lims; i <= 100000; i++) dpr[i] = dp[i];
	for (int i = lim2; i <= 100000; i++) {
		dpr[i] += dpr[i - 1];
		if (dpr[i] >= mod) dpr[i] -= mod;
	}
	for (int i = lims; i <= 100000; i++) mulr[i] = (1LL * i * dp[i]) % mod;
	for (int i = lim2; i <= 100000; i++) {
		mulr[i] += mulr[i - 1];
		if (mulr[i] >= mod) mulr[i] -= mod;
	}
}

int main() {
	scanf("%lld", &Q);
	for (int i = 1; i <= Q; i++) scanf("%lld%lld", &N[i], &C[i]);
	for (int i = 1; i <= Q; i++) Base[i] = N[i] / C[i];
	for (int i = 1; i <= Q; i++) {
		if (Base[i] == 0) Answer[i] = N[i];
	}
	
	for (int gen = 1; gen <= 450; gen++) {
		init(gen); int lims = gen * (gen - 1) / 2;
		for (int i = 1; i <= Q; i++) {
			if (Base[i] <= lims) continue;
			int cl = Base[i] - 2 * gen + 1;
			int cr = Base[i] - gen; if (cr < 0) continue;
			
			// 1 個目の計算
			long long V1 = 0;
			if (cr >= 0) V1 = dpr[cr];
			if (cl >= 1) V1 -= dpr[cl - 1];
			if (V1 < 0) V1 += mod;
			
			long long S1 = 0;
			if (cr >= 0) S1 = mulr[cr];
			if (cl >= 1) S1 -= mulr[cl - 1];
			if (S1 < 0) S1 += mod;
			
			// 2 個目の計算
			long long V2 = 0;
			if (cl >= 1) V2 = dp[cl - 1];
			
			long long S2 = 0;
			if (cl >= 1) S2 = 1LL * (cl - 1 + gen) * dp[cl - 1] % mod;
			
			// 答えに加算
			Answer[i] += (1LL * V1 * N[i] - 1LL * S1 * C[i] + 1LL * mod * mod);
			Answer[i] += (1LL * V2 * N[i] - 1LL * S2 * C[i] + 1LL * mod * mod);
			Answer[i] %= mod; //cout << gen << ": " << V1 << " " << S1 << " " << V2 << " " << S2 << " " << Answer[i] << endl;
		}
	}
	
	for (int i = 1; i <= Q; i++) printf("%lld\n", Answer[i]);
	return 0;
}

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

z=sum(a)

sum=0
min=10**10
for i in range(n-1):
    sum+=a[i]
    x=sum
    y=z-x
    if abs(x-y)<min:
        min=abs(x-y)
print(min)

Measured memory_bytes: 24824
S = input()

ans = [S[0]]

for i in range(1,len(S)):
    candidate = []
    for j in ans:
        candidate.append(j+S[i])
        candidate.append(j+'+'+S[i])
        ans = candidate

num = 0
for a in ans:
    num += eval(a)

print(num)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}
template<typename T>
void vvdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        vdeb(da[i]);
    }
}

int main(){
	int h,w;
	int n;
	cin >> h >> w >> n;
	vector<int> da(n);
	rip(i,n,0){
		cin >> da[i];
	}
	vector<vector<int>> ans(h,vector<int>(w));
	int now=0;
	rip(i,h,0){
		rip(j,w,0){
			if(i%2){
				ans[i][j]=now+1;
			}
			else{
				ans[i][w-j-1]=now+1;
			}
			da[now]--;
			if(da[now]==0){
				now++;
			}
		}
	}
	vvdeb(ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <iterator>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  while (cin >> n, n != 0) {
    cin.get();
    string line;
    getline(cin, line);
    istringstream iss {line};
    vector<double> nums {istream_iterator<double> {iss},
      istream_iterator<double> {}};

    double sum = accumulate(nums.begin(), nums.end(), double{0});
    double average = sum / nums.size();

    double sse = 0;
    for (double s : nums)
      sse += pow(s - average, 2);

    double sd_nodiv = sqrt(sse);
    double sd = sd_nodiv / sqrt(nums.size());
    cout << fixed << sd << endl;
  }
}


Measured memory_bytes: 3264
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

        int main(){
            int n;
            cin >> n;
            int cnt=0;
            int temp=0;
            int j=0;
            for(int i=0;i<=n;i++){
                temp = i;
                j = 0;
                while(1){
                    if(temp == 0)break;
                    temp /= 10;
                    j++;
                }
                if(j %2 == 1)cnt++;
            }
            cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
#define pr(x) cout << x << endl;
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll mpow(ll a, ll b){
  ll ans=1;
  rep(i,b){
    ans*=a;
    ans%=mod;
  }
  return ans;
}

int main(){
  int s; cin >> s;
  mint ans=0;
  combination c(10000);
  int l=1;
  for(int i=s-3; i>=0; i=i-3){
    ans+=c(i+l-1,i);
    l++;
  }
  cout << ans.x << endl;

return 0;
}


Measured memory_bytes: 3788
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int x = int.Parse(Console.ReadLine());
		bool[] dp = new bool[100001];
    for(int i = 0; i <= 5; i++) dp[100+i] = true;

    for(int i = 200; i <= x; i++)
    {
      for(int j = 100; j <= 105; j++)
      {
        if(dp[i-j]) dp[i] = true;
      }
    }

		if(dp[x]) Console.WriteLine(1);
    else Console.WriteLine(0);
	}
}

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


def fib(n):
    '''f(n)=f(n-1)+f(n-2)'''
    a, b = 0, 1
    for _ in range(n-1):
        a, b = b, a+b
    return b


n, m = map(int, input().split())
mod = 10**9+7
a = [int(input()) for _ in range(m)]
if not a:
    ans = fib(n+1) % mod
else:
    ans = fib(a[0])*fib(n-a[m-1]) % mod
    for i in range(m-1):
        if a[i+1]-a[i] == 1:
            ans = 0
            break
        ans = ans * fib(a[i+1]-a[i]-1) % mod

print(ans)


Measured memory_bytes: 7080
n = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if L[i]!=L[j] and L[i]!=L[k] and L[j] != L[k] and  L[i] + L[j]> L[k]:
                cnt += 1
print(cnt)

Measured memory_bytes: 68096
n = int(input())
line = [0]
for i in range(n):
  line.append(int(input()))
check = [0 for i in range(n+1)]
count = 0
check[1] = 1
a = 1
while True:
  count += 1
  if line[a] == 2:
    break
  else:
    a = line[a]
    check[a] += 1
  
  if check[a] > 1:
    count = -1
    break
print(count)
  


Measured memory_bytes: 13720
#include<stdio.h>
 
int main(void){
    char str[5];
    scanf("%s",str);
    for(int i=0;i<4;i++){
        if(str[i]==str[i+1]){
            printf("Bad\n");
            return 0;
        }
    }
    printf("Good\n");
     return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

int main(){
	int t[5];
	for(int i=0;i<5;i++) cin >> t[i];

	int m = 0;
	for(int i=1;i<5;i++) if(t[m]%10>t[i]%10 && t[i]%10>0) m = i;

	for (int i = 0; i < 5; i++){
		if(i!=m){
			if(t[i]%10>0) t[i] += 10-(t[i]%10);
		}
	}

	int ans = 0;
	for(int i=0;i<5;i++) ans += t[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define bug cout<<"AIkahne aise"<<endl
ll A[5000001];
vector<ll>v;
vector<pair<ll,ll> >v2;
/*void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}*/
int main()
{
    ll n,k;
 string s;
 cin>>n;
 cin>>s;
 cin>>k;
 char h=s[k-1];
 for(int i=0;i<s.size();i++)
 {
     if(s[i]!=h)
        s[i]='*';
 }
 cout<<s<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

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

    if( n == 1){
        cout << 1 << endl;
    }
    else if(n % 2 == 0){
        cout << 0.5 << endl;
    }
    else {
        int gnum = n / 2;
        int knum = n - gnum;
        cout << (double)knum / n << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
increasing = []
decreasing = []
dec_special = []
for _ in range(n):
    s = input().rstrip()
    minima = 0
    fin = 0
    for ch in s:
        if ch == ")":
            fin -= 1
            if fin < minima:
                minima = fin
        else:
            fin += 1
    if fin >= 0:
        increasing.append((minima, fin))
    elif minima < fin:
        dec_special.append((minima, fin))
    else:
        decreasing.append((minima, fin))

increasing.sort(reverse=True)
decreasing.sort()
dec_special.sort()

current = 0
for minima, diff in increasing:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
for minima, diff in dec_special:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
for minima, diff in decreasing:
    if current + minima < 0:
        print("No")
        exit()
    current += diff
if current != 0:
    print("No")
else:
    print("Yes")


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

int main() {
    int k, s; cin >> k >> s;
    int ans = 0;
    for (int x = 0; x <= k; x++) for (int y = 0; y <= k; y++) {
        int z = s - x - y;
        if (0 <= z && z <= k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	double a,b,log,product;
	
	while(scanf("%lf %lf",&a,&b)!=EOF){
		product=a*b;
		
		while(a!=b){
			if(a>b){
				log=b;
				b=a-b;
				a=log;
			}
			else if(a<b){
				log=a;
				b-=a;
			}
		}
		
		product/=a;
		printf("%.0f %.0f\n",a,product);
	}
	return 0;
}

Measured memory_bytes: 644
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])
print(sum([sum(map(lambda a: 0 if a == -1 else C[a][1], row)) for row in A]))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, m;

void solve(){
    if(m <= 22){
        int a[n];
        rep(i, n){
            string s;
            cin >> s;
            a[i] = 0;
            rep(k, m) a[i] |= ((s[k] - '0') << k);
        }
        int dp[2][1 << m];
        rep(i, 2)rep(S, 1 << m) dp[i][S] = -1;
        dp[0][0] = 0;
        rep(i, n){
            rep(S, 1 << m)if(dp[0][S] >= 0){
                chmax(dp[1][S], dp[0][S]);
                chmax(dp[1][S ^ a[i]], dp[0][S] + 1);
            }
            rep(S, 1 << m){
                dp[0][S] = dp[1][S];
                dp[1][S] = -1;
            }
        }
        printf("%d\n", dp[0][0]);
    }
    else{
        int a[n][m];
        rep(i, n){
            string s;
            cin >> s;
            rep(k, m) a[i][k] = s[k] - '0';
        }
        int ans = 0;
        rep(S, 1 << n){
            int b[m];
            memset(b, 0, sizeof(b));
            rep(i, n)if(S >> i & 1){
                rep(k, m) b[k] ^= a[i][k];
            }
            if(count_if(b, b + m, [](int x){return x == 1;}) == 0){
                chmax(ans, __builtin_popcount(S));
            }
        }
        printf("%d\n", ans);
    }
}

int main(){
    while(scanf("%d%d", &n, &m) && n){
        solve();
    }
}


Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n, a[100005]; 
int dp[100005]; 
 
int func(int ind) {
	if(ind==(n-1)) return 0; 
	if(ind>=n) return INT_MAX; 
 
	if(dp[ind]!=-1) return dp[ind]; 
    
	int left = abs(a[ind]-a[ind+1]) + func(ind+1); 
	int right = INT_MAX; 
	if(ind+2<n) {
		right = abs(a[ind] - a[ind+2]) + func(ind+2); 
	}
 
	return dp[ind] = min(left, right); 
}
signed main() {
	
	cin >> n;
 
	memset(dp, -1, sizeof dp); 
	
	for(int i = 0;i<n;i++) {
		cin >> a[i]; 
	}
 
	cout << func(0); 
}

Measured memory_bytes: 4864
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, k = 0;
	cin >> n >> k;
	vector<int> p(n);
	for (auto &i : p)
	{
		cin >> i; --i;
	}
	vector<lli> c(n);
	for (auto &i : c)
		cin >> i;
	vector<pair<vector<int>, lli> > vp;
	vector<bool> vis(n, false);
	for (int i = 0; i < n; ++i)
		if (!vis[i])
		{
			vector<int> aux;
			int pos = i; lli sum = 0ll;
			while (!vis[pos])
			{
				vis[pos] = true; sum += c[pos]; aux.pb(pos); pos = p[pos];
			}
			vp.eb(aux, sum);
		}
	lli res = -LLONG_MAX;
	for (auto &i : vp)
	{
		vector<int> a = i.fi; lli s = i.se;
		int sz = a.size();
		vector<lli> v(2 * sz);
		for (int j = 0; j < sz; ++j)
		{
			v[j] = c[a[j]]; v[j + sz] = c[a[j]];
		}
		lli r = k % sz;
		vector<int> b(sz);
		if (s >= 0ll)
		{
			for (int j = 0; j < r; ++j)
				b[j] = k / sz;
			for (int j = r; j < sz; ++j)
				b[j] = k / sz - 1;
		}
		for (int j = 0; j < sz; ++j)
		{
			lli t = 0ll;
			for (int l = 0; l < min(k, sz); ++l)
			{
				t += v[j + l]; res = max(res, t + 1ll * b[l] * s);
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3848
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, l) = in.readLine.split(" ").map(_.toInt)
  val total = (1 to n).map(i => l+i-1).sum

  var res = 0
  for (i <- 1 to n) {
    var t=0
    for ( j <- 1 to n if j != i) {
      t += (l + j - 1)
    }
    if((total - res).abs > (total - t).abs) res = t
  }
  println(res)
}

Measured memory_bytes: 25640
function check(N,x:int64):Boolean;
begin
if x=1 then check:=False else begin
while N mod x=0 do N:=N div x;
check:=N mod x=1;
end;
end;
function calc(N,M:int64):Longint;
var cnt:Longint;i:int64;
begin
i:=1;
while i*i<=M do begin
if M mod i=0 then begin
if check(N,i)then inc(cnt);
if(i*i<M)and(check(N,M div i))then inc(cnt);
end;
inc(i);
end;
calc:=cnt;
end;
var N:int64;
begin
read(N);
writeln(calc(N,N)+calc(N,N-1));
end.

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

int main(void){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int train = (A<B)?A:B;
    int bus = (C<D)?C:D;
    cout<<train+bus<<endl;
    return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::BTreeMap;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
pub struct MaxFenwickTree {
    vec: Vec<i64>
}
impl MaxFenwickTree {
    fn new(size: usize) -> MaxFenwickTree {
        MaxFenwickTree{vec: vec![0; size]}
    }
    fn at(&self, mut index: usize) -> i64 {
        let mut temp_max = self.vec[index];
        while index >= !index & (index + 1) {
            index -= !index & (index + 1);
            temp_max = max(temp_max, self.vec[index]);
        }
        temp_max
    }
    fn update(&mut self, mut index: usize, value: i64) -> () {
        while index < self.vec.len() {
            self.vec[index] = max(self.vec[index], value);
            index += !index & (index + 1);
        }
    }
}

fn main() {
    let_all!(n: usize);
    let values = read_line!(' '; usize);
    let mut fenwick_tree = MaxFenwickTree::new(n + 1);
    for &i in &values {
        let current_max = fenwick_tree.at(i);
        fenwick_tree.update(i, current_max + i as i64);
    }
    println!("{}", (n as i64 * (n + 1) as i64 / 2) - fenwick_tree.at(n));
}



Measured memory_bytes: 6976
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


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


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int cnt,ans;
int n,tx[100][100],ty[100][100],vd[100][100];
void dfs(int y,int x){
  vd[y][x]=cnt;
  if(vd[ty[y][x]][tx[y][x]]==cnt)cnt++;
  else if(vd[ty[y][x]][tx[y][x]]==-1)dfs(ty[y][x],tx[y][x]);
  else ans--;
}
int main(){
  while(cin>>n&&n){
    cnt=ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>tx[i][j]>>ty[i][j];
	vd[i][j]=-1;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(vd[i][j]==-1){
	  ans++;
	  cnt++;
	  dfs(i,j);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

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

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    SANKOU((B - A) % 2 == 0,Alice,Borys);
}

Measured memory_bytes: 3588
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define memset(a,first,last,val) fs(i,first,last,1) a[i]=val
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

vl vb;
int N;

class triplet{
    public:
    ll f, s, t;};

vl in(ll n){
    vl ar;
    ll x;
    f(i,n)
    cin>>ar[i];
    return ar;
}
vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void printArray(vector<int> arr, int n) 
{ 
    ll num=0;
    for (int i = 0; i < n; i++) 
    num*=10, num+=i;

    if(n==N)
    vb.pb(num);
        
} 

int printfactorialof(int n){
    if(n<=1)
        return 1;
    
    return n*printfactorialof(n-1);
}

void solve(){
ll i,x=0,y;
cin>>i;
y=i;
while(i){
    x+=(i%10);
    i/=10;
}
if(y%x){
    cout<<"No",nl
}
else
{
    cout<<"Yes",nl
}


}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 3624
N=int(input())
T=[int(x)for x in input().split()]
M=int(input())
p=[0]*M
x=[0]*M
for i in range(M):
    p[i],x[i]=map(int,input().split())
k=0
for j in range(N):
    k+=T[j]
for i in range(M):
    ans=k+x[i]-T[p[i]-1]
    print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
void buildMaxHeap(int*);
void maxHeapify(int*,int);
int n = 0;
int main(void){
 int *array;
    int i;
    
    scanf("%d",&n);
    n+=1;
    array = (int *)malloc(n * sizeof(int));
    for(i = 1; i < n; i++){
       scanf("%d",&array[i]);  
    }
    buildMaxHeap(array);
    for(i = 1; i < n; i++){
        printf(" %d",array[i]);
    }
    printf("\n");
    return 0;
}
void maxHeapify(int* array, int i){
    int j,largest,l,r;
    l = i * 2;
    r = 2 * i + 1;
    if(l <= n && array[l] > array[i]){
    largest = l;        
    }
    else largest = i;
    if(r <= n && array[r] > array[largest]){
        largest = r;
    }
    if(largest != i){
        j = array[i];
        array[i] = array[largest];
        array[largest] = j;
        maxHeapify(array,largest);
    }
}
void buildMaxHeap(int* array){
    int i = 0;
    for(i = n/2; i > 0; i--){
        maxHeapify(array,i);
    }
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001
 
#define ad(x) int i = 100;
typedef long long ll;
// enum {
//   AST_INT,
//   AST_SYM,
//   AST_STR,
//   AST_FUNCALL,
// };
 
 
 
// double winProb(int Rp, int Rq) {
//     return 1/(1+pow(10, (Rq-Rp)/400.));
// }
 
// int R[1<<10];
// double dp[12][1<<10];
int h, w;
// int canvas[]
// int w[30010];
// int e[30010];
// int a0,a1,a2,b0,b1,b2;
int a[3];
int b[3];
int c[3][3];
int main() {
    REP(i,0,3) REP(j,0,3) cin >> c[i][j];
    
    
    a[0] = 0;
    b[0] = c[0][0] - a[0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    
    // REP(i,0,3) {
    //     cout << a[i] << " " << b[i] << endl;
    // }
    
    string ans = "Yes";
    REP(i,0,3) REP(j,0,3) {
        // cout << c[i][j] << endl;
        // if (a[i] < 0 || a[i] > 100 || b[j] < 0 || b[j] > 100) {ans = "No"; break;}
        if (c[i][j] != a[i] + b[j]) {
            ans = "No"; break;
        }
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<ll,ll> P;
#define fi first
#define se second

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
vector<ll> a(n+1),b(n);
for(ll i=0;i<n+1;i++)cin>>a.at(i);
for(ll i=0;i<n;i++)cin>>b.at(i);
ll ans=0;
for(int i=0;i<n;i++){
    ll tmp=a.at(i)+a.at(i+1);
    if(tmp-b.at(i)<0){
        ans+=tmp;
        a.at(i+1)=0;
    }
    else {
        ans+=b.at(i);
        if(a.at(i)<b.at(i))a.at(i+1)-=(b.at(i)-a.at(i));
    }
}
cout<<ans<<endl;
}


Measured memory_bytes: 1792
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n

    read*, n
    if (mod(n,10)==9 .or. mod(n/10,10)==9) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
    
end program main

Measured memory_bytes: 256