akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	int d;
	while(cin>>d){
		int n = 600/d;
		int sum=0;
		for(int i=1;i<n;i++){
			sum += d * (i*d)*(i*d);
		}
		cout<< sum<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(5);
	solve();

	return 0;
}

 

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

int main() {
  string s;
  cin >> s;
  int ans = 0, i = 0;
  while (i < s.size()) {
    int j = i + 1;
    while (true) {
      if (s[i] != s[j]) {
        ans++;
        break;
      }
      j++;
    }
    i = j;
  }
  ans = max(ans - 1, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int n,p[200001],i,j,cnt=0,c;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
		if(p[i]<=p[1]){
			cnt++;
			p[1]=p[i];
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 896
N = int(raw_input())
h = map(int, raw_input().split())

# N = 6
# h = [30, 10, 60, 10, 60, 50]

dp = [float('inf')] * N
dp[0] = 0

for i, eh in enumerate(h):
    if i + 1 < N:
        dp[i+1] = min(dp[i+1], dp[i]+abs(eh-h[i+1]))
    if i + 2 < N:
        dp[i+2] = min(dp[i+2], dp[i]+abs(eh-h[i+2]))

print dp[-1]


Measured memory_bytes: 11144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),K=sc.nextInt();
		char[] s=sc.next().toCharArray();
		for (int i=0; i<N; i++) {
			System.out.print(i==K-1?Character.toLowerCase(s[i]):s[i]);
		}
		System.out.println();
	}
}


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

int main() {
	int dp[21][2010];
	int n;
	vector<int> a(20);
	int q;
	vector<int> m(200);
	cin >> n;
	vector<int> flg(200,0);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> m[i];
	}
	for (int i = 0; i < q; i++) {
		for (int w = 0; w <= m[i]; w++) {
			dp[0][w] = 0;
		}
		for (int j = 0; j < n; j++) {
			for (int k = 0; k <= m[i]; k++) {
				if (k >= a[j]) {
					dp[j + 1][k] = max(dp[j][k - a[j]] + a[j], dp[j][k]);
					if (dp[j + 1][k] == m[i])
					{
						flg[i] = 1;
					}
				}
				else {
					dp[j + 1][k] = dp[j][k];
				}
			}
		}
	}
	
	for (int i = 0; i < q; i++)
	{
		if (flg[i] == 0)
		{
			cout << "no" << '\n';
		}
		if (flg[i] == 1)
		{
			cout << "yes" << '\n';
		}
	}
	return 0;
}


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

int a[20];

bool check(int x)
{
	int pre = 0;
	for (int i = 0; i < 10; i++) if (x & (1 << i))
	{
		if (a[i] < pre) return false;
		pre = a[i];
	}
	return true;
}

bool dfs(int i, int x, int pre)
{
	if (i == 10)
	{
		return check(x);
	}
	bool temp = false;
	if (a[i] > pre) temp = dfs(i + 1, x, a[i]);
	return temp || dfs(i + 1, x | (1 << i), pre);
}

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for (int i = 0; i < 10; i++) scanf("%d", &a[i]);
		printf("%s\n", dfs(1, 0, a[0]) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 3116
#include <algorithm>
#include <string.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
ll x[N], p[64], sum1[N], sum0[N];
int main()
{
    p[0] = 1;
    for (int i = 1; i <63; i++)
        p[i] = (p[i - 1] * 2ll)%mod;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    ll ans = 0;
    for (int i = 0; i <63; i++)
    {
        memset(sum1, 0, sizeof(sum1));
        memset(sum0, 0, sizeof(sum0));
        for (int j = n; j >= 1; j--)
        {
            sum1[j] = sum1[j + 1];
            sum0[j] = sum0[j + 1];
            if ((x[j] >> i) & 1)
                sum1[j]++;
            else
                sum0[j]++;
            if ((x[j] >> i) & 1)
            {
                ll temp = (sum0[j + 1] % mod * p[i] % mod);
                ans = (ans % mod + temp % mod) % mod;
            }
            else
            {
                ll temp = (sum1[j + 1] % mod * p[i] % mod);
                ans = (ans % mod + temp % mod) % mod;
            }
        }
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>
int main(void){
  int a,b,c,i,sum=0;
  scanf("%d %d",&a,&b);
  c = b-a;
  for(i=c-1;i>0;i--){
    sum+=i;
  }
  printf("%d",sum-a);
  return 0;
}


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

int main(void){
  int n, t, x, y, tn=0, xn=0, yn=0, d, i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&t,&x,&y);
    d = t-tn-abs(x-xn)-abs(y-yn);
    if(d<0 || d%2!=0) break;
    xn=x;  yn=y; tn=t;
  }
  if(i==n) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#define mp make_pair
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int main(){
	int n;
	vector<PP> vec;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a[3];
		cin >> a[0] >> a[1] >> a[2];
		sort(a,a + 3);
		vec.push_back(mp(a[0],mp(a[1],a[2])));
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	cout << n - vec.size() << endl;
	return 0;
}

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

int main() {

  long long int r, g, b, n;
  cin >> r >> g >> b >> n;

  long long int ans = 0;
  for ( long long int rr = 0; rr * r <= n; rr++ ) {
    long long int cnt = n - rr * r;
    for ( long long int gg = 0; cnt - gg * g >= 0; gg++ ) {
      if ( ( ( cnt - gg * g ) % b ) != 0 ) continue;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
    int n;
    cin >> n;

    int ans = 0;
    while(n > 0){
        int t = n % 10;
        if(t == 2){
            ans++;
        }
        n /= 10;
    }
    cout << ans << endl;
    

    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a=0,b=0;
    for(int i=0;i<n;i++){
        string taro,hanako;
        cin>>taro>>hanako;
        if(taro>hanako)a+=3;
        else if(taro<hanako)b+=3;
        else{a+=1;b+=1;}
    }
    cout<<a<<' '<<b<<endl;
    return 0;
}


Measured memory_bytes: 3164
import java.util.Scanner;

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

		char three = s.charAt(2);
		char four = s.charAt(3);
		char five = s.charAt(4);
		char six = s.charAt(5);

		boolean answer = false;
		if (three == four && five == six) {
			answer = true;
		}

		printBool(answer);
	}

    private static void printBool(boolean answer) {
        System.out.println(answer ?  "Yes" : "No");
    }
}

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

int main() {
  int N; cin >> N;
  int cnt = 1;
  int H1; cin >> H1;
  
  int t = H1;
  rep(i,N-1) {
    int H; cin >> H;
    if(H>=t) cnt++;
    t = max(H,t);
  }
  
  cout << cnt << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  cout << max(a + a - 1, max(b + b - 1, a + b)) << endl;
}


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

int main()
{
	bool hash[] = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, now;
	char alpha[33];
	int ans;
	while (scanf("%s", alpha) && alpha[0] != '#') {
		ans = 0;
		for (char *ptr = alpha, now = hash[alpha[0] - 'a']; *ptr != '\0'; ptr++) {
			if (hash[*ptr - 'a'] != now) {
				ans += 1;
				now = hash[*ptr - 'a'];
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

using namespace std;

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  if (A[A.size() -1] == B[0] && B[B.size() -1] == C[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
    using namespace std;
    long A,B,C,D;
    long a,b,c,d,e;
    cin>>A;
    cin>>B;
    cin>>C;
    cin>>D;
    a=A*C;
    b=A*D;
    c=B*C;
    d=B*D;
    if(a>b)
    {
        if(a>c)
        {
            if(a>d)
                e=a;
            else
                e=d;
        }
        else
        {
            if(c>d)
                e=c;
            else
                e=d;

        }
    }
    else
    {
        if(b>c)
        {
            if(b>d)
                e=b;
            else
                e=d;
        }
        else
        {
            if(c>d)
                e=c;
            else
                e=d;
        }
    }
    cout<<e<<endl;
    return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

ll nc2(ll n) {
    if (n<2) return 0;
    ll res = n*(n-1)%mod;
    res *= pw(2, mod-2);
    res %= mod;
    return res;
}

int n, k;
int a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
    cin>>n>>k;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    ll inv0=0;
    for (int i=0; i<n; i++) {
	for (int j=i+1; j<n; j++) {
	    if (a[i]>a[j]) {
		inv0++;
	    }
	}
    }


    ll inv1=0;
    for (int i=0; i<n; i++) {
	for (int j=0; j<n; j++) {
	    if (a[i]>a[j]) {
		inv1++;
	    }
	}
    }

    ll res = 1ll*k*inv0%mod;
    ll res2 = nc2(k)*inv1%mod;
    res += res2;
    res %= mod;
    cout<<res<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String s = scan.next();
	StringBuilder str = new StringBuilder();
	for (int i = 0; i < s.length(); i++) {
	    switch(s.charAt(i)) {
		case '0':
		    str.append('0');
		    break;
		case '1':
		    str.append('1');
		    break;
		case 'B':
		    if(str.length() > 0) {
			str.deleteCharAt(str.length() - 1);
		    }
		    break;
	    }
	}

	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

template <typename T>
T gcd(T a, T b) {
    while (a) {
        b %= a;
        swap(a, b);
    }
    return b;
}

ll solve(int n, std::vector<ll> a) {
    ll b = a[0];
    for (ll a_i : a) {
        b = gcd(b, a_i);
    }
    return b;
}

int main() {
    int N;
    scanf("%d", &N);
    std::vector<ll> A(N);
    for (int i = 0 ; i < N ; ++ i){
        scanf("%lld", &A[i]);
    }
    ll answer = solve(N, std::move(A));
    std::cout << answer << std::endl;
    return 0;
}


Measured memory_bytes: 1024
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




def main():
    # r = int(input())
    # print(r*r)
    # n = int(input())
    # s = input()
    # if n % 2 == 1:
    #     print("No")
    #     exit()
    # for i in range(n//2):
    #     if s[i] != s[i + n//2]:
    #         print("No")
    #         exit()
    # print("Yes")
    n = int(input())
    xy = [list(map(int, input().split())) for i in range(n)]
    
    L = []
    for l in itertools.permutations(xy):
        t = 0
        for i in range(n - 1):
            t += ((l[i][0] - l[i + 1][0])** 2 + (l[i][1] - l[i + 1][1])** 2)**(1 / 2)
        L.append(t)
    
    k = 1
    for i in range(1,n+1):
        k*=i

    print(sum(L)/k)
    


        




            
            
            
            
            
        


if __name__ == '__main__':
    main()


Measured memory_bytes: 77676
import java.util.*;

public class Main {

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

		final long MOD = 998244353;

		long[][] dp = new long[2][sum+1];
		dp[0][0] = 1;
		int flg=0;
		for(int i=0; i<N; i++) {
			Arrays.fill(dp[flg^1], 0);
			for(int j=0; j<=sum; j++) {
				dp[flg^1][j] = (dp[flg^1][j] + dp[flg][j]*2) %MOD;
				if(j+a[i]<=sum)
					dp[flg^1][j+a[i]] = (dp[flg^1][j+a[i]] + dp[flg][j]) %MOD;
			}
			flg ^= 1;
		}
		long over = 0;
		for(int i=(sum+1)/2; i<=sum; i++)
			over = (over + dp[flg][i])%MOD;
		
		long ans = 1;
		for(int i=0; i<N; i++)
			ans = (ans * 3) % MOD;
		
		ans = (ans - over*3 + MOD*3) % MOD;
		if(sum%2==0) {
			long[][] dp2 = new long[2][sum/2+1];
			dp2[0][0] = 1;
			flg=0;
			for(int i=0; i<N; i++) {
				Arrays.fill(dp2[flg^1], 0);
				for(int j=0; j<=sum/2; j++) {
					dp2[flg^1][j] = (dp2[flg^1][j] + dp2[flg][j]) %MOD;
					if(j+a[i]<=sum/2)
						dp2[flg^1][j+a[i]] = (dp2[flg^1][j+a[i]] + dp2[flg][j]) %MOD;
				}
				flg ^= 1;
			}
			ans = (ans + dp2[flg][sum/2]*3 + MOD*3) % MOD;

		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 25640
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    {
      let mut v = Vec::new();
      for _ in 0..$i {
        v.push($e.get::<$t>());
      }
      v
    }
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn recursion(vec: &Vec<i32>, idx: usize, m: i32) -> bool {
  if m == 0 {
    return true;
  }
  if idx >= vec.len() {
    return false;
  }
  let next = m - vec[idx];
  recursion(vec, idx + 1, m) || recursion(vec, idx + 1, next)
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; i32);
  let a = scan!(sc => n; i32);
  let q = scan!(sc; i32);
  let m = scan!(sc => q; i32);
  for &m in m.iter() {
    println!("{}", if recursion(&a, 0, m) { "yes" } else { "no" });
  }
}



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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

ll h,w;
/*
片方奇数偶数

両方偶数

両方奇数
*/
int main(){
  scanf("%d %d",&h,&w);
  if(h%3==0||w%3==0){
    printf("0\n");
    return 0;
  }
  ll mi = min(h,w);
  FOR(i,1,h){
    ll x = w/2;
    ll sa = i*w;
    ll sb = (h-i)*x;
    ll sc = (h-i)*(w-x);
    ll t_mi = min(min(sa,sb),sc);
    ll t_ma = max(max(sa,sb),sc);
    mi = min(mi,t_ma-t_mi);
  }
  FOR(i,1,w){
    ll x = h/2;
    ll sa = i*h;
    ll sb = (w-i)*x;
    ll sc = (w-i)*(h-x);
    ll t_mi = min(min(sa,sb),sc);
    ll t_ma = max(max(sa,sb),sc);
    mi = min(mi,t_ma-t_mi);
  }
  printf("%lld\n",mi);
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    cout << ((n + 1) / 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
string s; cin>>s;
 bool flag=0;

if(s[2]==s[3]&&s[4]==s[5])flag=1;

 if(flag)
  cout << "Yes" << endl;
  else
    cout << "No" << endl;

}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;
  bool in = false;
  rep(i,s.size())
    if(s[i]=='9')
      in = true;

  if(in) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
  set<int>se;
	int a,b,c;
  cin>>a>>b>>c;
  se.insert(a);
  se.insert(b);
  se.insert(c);
  if(se.size()==2)
  {
	cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256
function main(input) {
    var a = input[0]-0;
    var b = input[1]-0;
    var c = input[2]-0;
    var x = input[3]-0;
    var ans = 0;
    for(var i=0;i<=a;i++)for(var j=0;j<=b;j++)for(var k=0;k<=c;k++){
        if(500*i+100*j+50*k == x) ans++;
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))



Measured memory_bytes: 7500
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

for i, j, k in zip(range(N), range(1, N), range(2, N)):
    if D[i][0] == D[i][1] and D[j][0] == D[j][1] and D[k][0] == D[k][1]:
        print('Yes')
        exit()
print('No')


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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    ll m; cin >> m;
    ll d[m],c[m];
    ll dig = 0;
    ll sum = 0;
    rep(i,m){
        cin >> d[i] >> c[i];
        sum += d[i] * c[i];
        dig += c[i];
    }
    cout << dig - 1 + (sum-1)/9 << endl;
}

Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc136/tasks/abc136_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        h: [i32; n]
    };

    let mut h = h;
    let mut ok = true;
    h[0] -= 1;
    for i in 1..n {
        if h[i-1] > h[i] {
            ok = false;
        } else if h[i-1] < h[i] {
            h[i] -= 1;
        }
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <complex>

#define all(n) n.begin(), n.end()
#define INF (1<<10)

using namespace std;

struct P : public complex<int> {
    P(){}
    P(int x, int y) : complex<int>(x, y) {}
    static bool comp_x(const P&a, const P& b){
        if(a.real() != b.real())
            return a.real() < b.real();
        else return a.imag() < b.imag();
    }
    static bool comp_y(const P&a, const P& b){
        if(a.imag() != b.imag())
            return a.imag() < b.imag();
        else return a.real() < b.real();
    }
};

struct L : public pair<P, P> {
    L(P a, P b) : pair<P, P>(a, b){}
};
inline int norm(const L& l){
    return norm(l.first - l.second);
}

int n;

L closest_pair(vector<P>::iterator begin, vector<P>::iterator end, bool init = true){
    int len = end - begin;
    if(len <= 1) return L(P(), P(INF, INF));
    if(init) sort(begin, end, P::comp_x);
    auto mid = begin + len / 2;
    int x = mid->real();
    auto pL = closest_pair(begin, mid, false), pR = closest_pair(mid, end, false);
    int dL = norm(pL), dR = norm(pR);

    auto res = dL < dR ? pL : pR;
    int range = norm(res);

    inplace_merge(begin, mid, end, P::comp_y);
    vector<P> b;
    for(int i = 0; i < len; i++){
        if(abs(begin[i].real() - x) >= range) continue;
        for(int j = b.size() - 1; j >= 0; j--) {
            int dx = begin[i].real() - b[j].real();
            int dy = begin[i].imag() - b[j].imag();
            if(dy >= range)
                break;
            if(dx*dx + dy*dy < range){
                range = dx*dx + dy*dy;
                res = L(begin[i], b[j]);
            }
            range = min(range, dx*dx + dy*dy);
        }
        b.push_back(begin[i]);
    }
    return res;
}

int main(){
    cin >> n;
    vector<P> a(n);
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        a[i] = P(x, y);
    }
    auto ans = closest_pair(all(a));
    cout << norm(ans) << endl;
}

Measured memory_bytes: 10704
class Array
	def accum
		ac = Array.new(size + 1)
		ac[0] = 0
		(1..size).each do |i|
			ac[i] = ac[i-1] + self[i-1]
		end
		ac
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end
end		

def encode(i1, i2, j1, j2)
    (i1 << 18) + (i2 << 12) + (j1 << 6) + j2
end

def f(i1, i2, j1, j2)
    key = encode(i1, i2, j1, j2)
    cache = $memo[key]
    return cache if cache

    x = $a[i2][j2] - $a[i2][j1-1] - $a[i1-1][j2] + $a[i1-1][j1-1]
    return nil if x < $target

    if i1 == i2 && j1 == j2
        return $memo[key] = [1, x - $target]
    end

    best_num = 1
    best_afford = x - $target

    if i1 < i2
        (i1+1..i2).each do |i|
            n1, a1 = f(i1, i-1, j1, j2)
            next unless n1
            n2, a2 = f(i, i2, j1, j2)
            next unless n2
            if n1 + n2 > (best_num || 0)
                best_num = n1 + n2
                best_afford = [a1, a2].min
            elsif n1 + n2 == best_num
                m = [a1, a2].min
                best_afford = m if m > best_afford
            end
        end
    end

    if j1 < j2
        (j1+1..j2).each do |j|
            n1, a1 = f(i1, i2, j1, j-1)
            next unless n1
            n2, a2 = f(i1, i2, j, j2)
            next unless n2
            if n1 + n2 > (best_num || 0)
                best_num = n1 + n2
                best_afford = [a1, a2].min
            elsif n1 + n2 == best_num
                m = [a1, a2].min
                best_afford = m if m > best_afford
            end
        end
    end

    $memo[key] = [best_num, best_afford]
end

loop do
    h, w, s = gets.split.map(&:to_i)
    break if h == 0
    $a = (1..h).map {gets.split.map(&:to_i)}.accum_2d
    $target = $a[-1][-1] - s
    $memo = {}

    puts f(1, h, 1, w) * ' '
end

Measured memory_bytes: 53152
import java.util.Scanner;

public class Main {

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

	    int a=gi();
	    int b=gi();
	    int c=gi();

        //System.out.println(a);
        if (a+b>=c) {
        	System.out.print("Yes");
        }else {
        	System.out.print("No");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35196
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int a, b, q;
	cin >> a >> b >> q;
	set<long long int> sa, sb;
	unordered_map<long long int, int> uma, umb;
	for (int i = 0; i < a; i++) {
		long long int aa;
		cin >> aa;
		sa.insert(aa);
		uma[aa] = i;
	}	
	for (int i = 0; i < b; i++) {
		long long int bb;
		cin >> bb;
		sb.insert(bb);
		umb[bb] = i;
	}
	vector<long long int> va(a, -1), vb(b, -1);
	for (auto p : uma) {
		long long int d = p.first;
		int index = p.second;

		auto it = sb.lower_bound(d);
		if (it != sb.end()) {
			long long int diff = *it - d;
			if (va[index] == -1 || va[index] > diff) va[index] = diff;
		}
		if (it != sb.begin()) {
			it--;
			long long int diff = d - *it;
			if (va[index] == -1 || va[index] > diff) va[index] = diff;
		}
	}

	for (auto p : umb) {
		long long int d = p.first;
		int index = p.second;

		auto it = sa.lower_bound(d);
		if (it != sa.end()) {
			long long int diff = *it - d;
			if (vb[index] == -1 || vb[index] > diff) vb[index] = diff;
		}
		if (it != sa.begin()) {
			it--;
			long long int diff = d - *it;
			if (vb[index] == -1 || vb[index] > diff) vb[index] = diff;
		}
	}

	for (int i = 0; i < q; i++) {
		long long int x;
		cin >> x;
		long long int res = -1;
		auto it = sa.lower_bound(x);
		long long int temp = 0;
		if (it != sa.end()) {
			temp = abs(x - *it) + va[uma[*it]];
			if (res == -1 || temp < res) res = temp;
		}
		if (it != sa.begin()) {
			it--;
			temp = abs(x - *it) + va[uma[*it]];
			if (res == -1 || temp < res) res = temp;
		}

		it = sb.lower_bound(x);
		if (it != sb.end()) {
			temp = abs(x - *it) + vb[umb[*it]];
			if (res == -1 || temp < res) res = temp;
		}
		if (it != sb.begin()) {
			it--;
			temp = abs(x - *it) + vb[umb[*it]];
			if (res == -1 || temp < res) res = temp;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 22392
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn=1, Kr=1, Knr=1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N;
	long int A[100005];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	sort(A, A + N);

	pair<long int, long int> ans[100005];
	int c = 0;

	for (int i = N - 2; i >= 0; i--)
	{
		if (i == 0 || A[i] < 0) break;

		ans[c].first = A[0];
		ans[c].second = A[i];
		c++;

		A[0] -= A[i];
	}

	int k = c;

	for (int i = 0; i < N-k-1; i++)
	{
		ans[c].first = A[N - 1];
		ans[c].second = A[i];
		c++;

		A[N - 1] -= A[i];
	}

	cout << A[N - 1] << endl;
	for (int i = 0; i < N-1; i++)
	{
		cout << ans[i].first << " " << ans[i].second << endl;
	}


	return 0;
}

Measured memory_bytes: 4224
N = int(input())
l = len(str(N))
if N < 2:
    print(0)
elif N % 2 == 1:
    print(0)
else:
    ans = 0
 
    for i in range(1, 2*l):
        tmp = 0
        ans += (N // 10**i)
        tmp += (N // (10 * (5**i)))
        tmp -= N // (10 * (10**i))
        ans += max(tmp, 0)
 
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    rep(i, s.size() - 1)
    {
        if (s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
inputs = STDIN.readlines.map{|line|line.strip.split()}
line = inputs.shift

n = line[0].to_i
m = line[1].to_i

root_size = []
(n + 1).times do |i|
    root_size.push([i, 1])
end
usage_list = [n * (n - 1) / 2]
inputs.reverse.each do |input|
    a = input[0].to_i
    b = input[1].to_i

    ret_size = 0
    temp = a
    stack_a = [a]
    while root_size[temp][0] != temp
        temp = root_size[temp][0]
        stack_a.push(temp)
    end
    ra = temp

    temp = b
    stack_b = [b]
    while root_size[temp][0] != temp
        temp = root_size[temp][0]
        stack_b.push(temp)
    end
    rb = temp

    if root_size[ra][0] != root_size[rb][0] then
        ret_size = root_size[ra][1] * root_size[rb][1]
        root_size[ra][1] += root_size[rb][1]
        while stack_b.size > 0
            s = stack_b.pop
            root_size[s][0] = ra
            root_size[s][1] = 0
        end
    end

    usage_list.unshift(usage_list[0] - ret_size)
end
usage_list.shift
usage_list.each do |usage|
    puts(usage)
end


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

using namespace std;
const long long INF = 1LL << 60;

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

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> weight(N);
  vector<long long> value(N);

  for (int i = 0; i < N; i++) {
    cin >> weight[i] >> value[i];
  }

  vector<vector<long long> > dp(N + 1, vector<long long>(W + 1, 0));

  // DPループ
  for (int i = 0; i < N; ++i) {
    for (int sum_w = 0; sum_w <= W; ++sum_w) { //sum_wを超えてはいけない
      // i 番目の品物を選ぶ場合
      if (sum_w - weight[i] >= 0) { 
        chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]); //価値を加算
      }

      // i 番目の品物を選ばない場合
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

  // 最適値の出力
  cout << dp[N][W] << endl;
}

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

int main(){
    int a,b;
    int i,j,k;
    
    while(1){
        cin >> a >> b;

        if(a == 0 && b == 0) break;
        
        int n = 0;
        for(i = 1; i <= a; i++){
            for(j = i + 1; j <= a; j++){
                for(k = j + 1; k <= a; k++){
                    if (i + j + k == b) n ++;
                }
            }
        }
        cout << n << endl;
    }
    return 0;
}


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

from collections import deque

q = deque([])

for i in range(N):
  if i % 2:
    q.appendleft(A[i])
  else:
    q.append(A[i])
    
if N % 2:
  q = list(q)[::-1]
  
print(*q)

Measured memory_bytes: 30888
n = int(input())
a = list(map(int, input().split()))
hoge = [0] * n
cnt = 0
for i in range(n):
    #hoge[i + 1] = hoge[i] + a[i]
    cnt += a[i]
    hoge[i] = cnt
hoge_ = [0] * n
cnt = 0
for i in range(n - 1, -1, -1):
    cnt += a[i]
    hoge_[i] = cnt
ans = float('Inf')
for i in range(n - 1):
    ans = min(ans, abs(hoge[i] - hoge_[i + 1]))
print(ans)

Measured memory_bytes: 30828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;
 
 
int main(){
    int n,m; cin >> n >> m;
    ll ans=0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    vector<P> ko;
    rep(i,m){
        int b,c; cin >> b >> c;
        ko.emplace_back(c,b);
    }
    sort(all(ko));
    int now=0;
    rep(i,n){
        if(ko.empty() || a[i]>=ko.back().first){
            ans+=a[i];
            continue;
        }
        ans+=ko.back().first;
        ko.back().second--;
        if(ko.back().second==0) ko.pop_back();
    }
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 2804
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
 
using namespace std;
typedef long long LL;
const int N=200005,mod=924844033;
int n,h[N],cnt,f[N],siz[N],len,bin[N<<2];
LL flv[N],inv[N],ans[N],c[N<<2],F[N<<2],G[N<<2],w[N<<2];
struct edge{int v,n;} e[N<<1];
 
int getint()
{
    char ch;
    while(!isdigit(ch=getchar()));
    int x=ch-48;
    while(isdigit(ch=getchar())) x=x*10+ch-48;
    return x;
}
 
LL getmi(LL a,int x)
{
    LL rt=1;
    while(x)
    {
        if(x&1) rt=rt*a%mod;
        a=a*a%mod,x>>=1;
    }
    return rt;
}
 
LL C(int n,int m)
{
    return flv[n]*inv[m]%mod*inv[n-m]%mod;
}
 
void addedge(int u,int v)
{
    e[cnt]=(edge){v,h[u]},h[u]=cnt++;
    e[cnt]=(edge){u,h[v]},h[v]=cnt++;
}
 
void dfs(int x,int fa)
{
    f[x]=fa,siz[x]=1;
    for(int i=h[x]; i!=-1; i=e[i].n)
        if(e[i].v!=fa)
            dfs(e[i].v,x),siz[x]+=siz[e[i].v];
}
 
void FFT(LL a[],int tp)
{
    rep(i,0,len-1) if(i<bin[i]) swap(a[i],a[bin[i]]);
    for(int i=1; i<len; i<<=1)
    {
        LL wn=getmi(5,(mod-1)/(i<<1));
        if(tp==-1) wn=getmi(wn,mod-2);
        w[0]=1;
        rep(j,1,i-1) w[j]=w[j-1]*wn%mod;
        for(int j=0; j<len; j+=(i<<1))
            rep(k,0,i-1)
            {
                LL x=a[j+k],y=w[k]*a[i+j+k]%mod;
                a[j+k]=(x+y)%mod;
                a[j+k+i]=(x-y+mod)%mod;
            }
    }
    if(tp==-1)
    {
        LL x=getmi(len,mod-2);
        rep(i,0,len-1) a[i]=a[i]*x%mod;
    }
}
 
int main()
{
    n=getint(),memset(h,-1,sizeof(h));
    rep(i,1,n-1) addedge(getint(),getint());
    dfs(1,0);
    flv[0]=1;
    rep(i,1,n) flv[i]=flv[i-1]*i%mod;
    inv[n]=getmi(flv[n],mod-2);
    repd(i,n,1) inv[i-1]=inv[i]*i%mod;
    rep(i,1,n)
    {
        for(int sz=0,j=h[i]; j!=-1; j=e[j].n)
        {
            if(e[j].v==f[i]) sz=n-siz[i];
            else sz=siz[e[j].v];
            ++c[sz];
        }
    }
    rep(i,1,n) c[i]=c[i]*flv[i]%mod;
    rep(i,0,n) F[i]=getmi(flv[n-i],mod-2);
    for(len=1; len<n+n; len<<=1);
    rep(i,1,len) bin[i]=(bin[i>>1]>>1)|((i&1)*(len>>1));
    FFT(c,1),FFT(F,1);
    rep(i,0,len) G[i]=c[i]*F[i]%mod;
    FFT(G,-1);
    rep(i,1,n)
    {
        ans[i]=(n*C(n,i)%mod-G[i+n]*getmi(flv[i],mod-2)%mod)%mod;
        printf("%lld\n",(ans[i]+mod)%mod);
    }
    return 0;
}

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

int main(){
  int N; cin >>N;
  double ans = 0;
  for(int i=0;i<N;i++){
    double x; cin >> x;
    x = 1/x;
    ans += x;
  }

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


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

const int MOD = 998244353;
const int MAX = 300001;

long long fc[MAX];
long long fci[MAX];

long long modpow(long long a, long long b) {
    long long bp[31];
    bp[0] = a;
    for (int i=1; i<31; ++i) {
        bp[i] = bp[i-1] * bp[i-1] % MOD;
    }
    long long ret = 1;
    for (int i=0; i<31; ++i) {
        if (b & (1LL << i)) {
            ret *= bp[i];
            ret %= MOD;
        }
    }
    return ret;
}

void init() {
    fc[0] = fc[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fc[i] = (fc[i-1] * i) % MOD;
    }

    fci[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fci[i] = (fci[i-1] * modpow(i, MOD-2)) % MOD;
    }
}

long long C(long long n, long long k) {
    if (k == 0 || n == k) return 1;
    return (fc[n] * fci[k] % MOD) * fci[n-k] % MOD;
}

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

    init();

    int N;
    long long A, B, K;
    cin >> N >> A >> B >> K;

    long long ans = 0;
    for (long long a=0; a*A<=K; ++a) {
        if ( (K-a*A) % B != 0 ) continue;
        long long b = (K-a*A) / B;
        if (N < a || N < b) continue;
        ans += C(N, a) * C(N, b);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
const int m=1000005;
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  vector<int>cnt(m);
  for(int x:a){
    if(cnt[x]!=0){
      cnt[x]=2;
      continue;
    }
    for(int i=x;i<m;i+=x){
      cnt[i]++;
    }
  }
  int ans=0;
  for(int x:a){
    if(cnt[x]==1){
      ans++;
    }
  }
  cout << ans << endl;
}
    


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

int main() {
    int n, x;
    while (cin >> n >> x) {
        int ans = 0;
        if (n == 0 && x == 0) return 0;
        
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    if ((i == j) || (j == k) || (k == i)) continue; 
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans/(3 * 2 * 1) << endl;
    } 
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int a;
	
	scanf("%d", &n);
	
	a = 0;
	for (i = 1; i <= n; i++){
		a += i;
	}
	
	printf("%d\n", a);
	
	return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  cout << std::min(N*A, B) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int cnt = 0;
	for (int i = 0; i <= 3000; i++) {
		int R = r*i;
		if (R > n) break;
		for (int j = 0; j <= 3000; j++) {
			int G = g*j;
			int RG = R + G;
			if (RG > n) break;
			int rest = (n - RG);
			if(rest%b==0) cnt++;

		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a,b,c,d[1000],e[1000],ans;
cin>>a>>b>>c;
for(int i=0;i<a;i++){
d[i]=0;
e[i]=0;
}
for(int i=0;i<a;i++){
cin>>d[i];
cin>>e[i];
}
for(int i=0;i<a;i++){
if(d[i]>=b&&e[i]>=c)
ans++;
}
cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+100;
int a[N],b[N];
vector<int>ve;
int main()
{
     ios::sync_with_stdio(0);cin.tie(0);
     int n;cin>>n;
     for(int i=1;i<=n;i++) cin>>a[i];
     for(int i=n;i>=1;i--)
     {
         if((b[i]&1)^a[i]){
              ve.push_back(i);
        for(int j=1;j*j<=i;j++){
            if(i%j==0){
                if(j*j==i) b[j]++;
                else  b[j]++,b[i/j]++;
            }
        }
        }
     }
     cout<<ve.size()<<endl;
     for(auto v:ve){
        cout<<v<<" ";
     }
    return 0;
}


Measured memory_bytes: 5316
import itertools

N = int(input())
P = map(int, input().split())
Q = map(int, input().split())
P = tuple(P)
Q = tuple(Q)

dlist = range(1, N+1)
permlist = list(itertools.permutations(dlist))

a = 0
b = 0
for i, p in enumerate(permlist):
	if P == p:
		a = i
	if Q == p:
		b = i

print(abs(a-b))

Measured memory_bytes: 8052
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    int ans = inf;
    vector<int> alp(26, 0);
    for(auto c: s){
        alp[c - 'a']++;
    }
    rep(i, 26){
        if(alp[i] == 0) continue;
        char a = 'a' + i;
        int ma = 0;
        int cur = 0;
        for(auto c: s){
            if(a == c){
                ma = max(ma, cur);
                cur = 0;
            }
            else{
                cur++;
            }
        }
        ma = max(ma, cur);
//        output(ma);
        ans = min(ans, ma);
    }
    output(ans);
    
    return 0;
}

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

using namespace std;


int main(){
	int n,k,m,i;
	vector<int> vec;
	while(1){
		cin >> n >> k >> m;
		vec.clear();
		if(n == 0)break;
		for(i = 0;i < n;i++){
			vec.push_back(i+1);
		}
		i = m - 1;
		while(1){
			if(vec.size() == 1){
				break;
			}
			vec.erase(vec.begin() + i);
			i--;
			i += k;
			i %= vec.size();
		}
		cout << vec[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 3260
N = int(input())
B = 4
F = 3
R = 10
dp = [0] * B * F * R

for i in range(N):
    b, f, r, v = [int(n) for n in input().split()]
    dp[(b-1)*F*R+(f-1)*R+(r-1)] += v
for i in range(B):
    for j in range(F):
        print(' ', end='')
        print(*dp[i*F*R+j*R:i*F*R+j*R+R])
    if i<B-1: print('#'*20)



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

int main(){
    int R,G,B,k;
    cin >> R >> G >> B >> k;
    if (R >= G){
        while (R >= G){
            G *= 2;
            k--;
        }
    }

    if (G >= B){
        while (G >= B){
            B *= 2;
            k--;
        }
    }

    if (k >= 0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


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

int main(){
  string S;
  cin >> S;
  
  int f = ((int)S[0] - (int)'0') * 10 + ((int)S[1] - (int)'0');
  int l = ((int)S[2] - (int)'0') * 10 + ((int)S[3] - (int)'0');
  
  bool Mf, Ml;
  if (f == 0 || f >= 13) Mf = false; else Mf = true;
  if (l == 0 || l >= 13) Ml = false; else Ml = true;
  
  if (Mf == true && Ml == true) cout << "AMBIGUOUS";
  else if (Mf == true && Ml == false) cout << "MMYY";
  else if (Mf == false && Ml == true) cout << "YYMM";
  else if (Mf == false && Ml == false) cout << "NA";
}

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

int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	rep(i,s.length()){
		int p=(int)s[i];
		p=(p-65+n)%26+65;
		s[i]=(char)p;
	}
	
	cout<<s<<endl;
}


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

using namespace std;

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

double dp[800];

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n);
  REP(i, m){
    int p, q;
    cin >> p >> q;
    --p, --q;
    a[p].push_back(q);
  }
  double mini = 1e40;
  REP(v, n) if(v == n - 1 || a[v].size() > 1){
    for(int i = n - 2; i >= 0; --i){
      double x = a[i].size();
      double m = 0.;
      double s = 0.;
      REP(j, a[i].size()){
        int d = a[i][j];
        s += dp[d];
        if(m < dp[d]){
          m = dp[d];
        }
      }
      if(i == v){
        s -= m;
        x -= 1.;
      }
      dp[i] = s / x + 1.;
    }
    mini = min(mini, dp[0]);
  }
  printf("%.10f\n", mini);
  return 0;
}


Measured memory_bytes: 1408
from bisect import bisect_left
n = int(input())
L = sorted(list(map(int, input().split())))
#print(L)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
        #print(i,j,bisect_left(L,L[i]+L[j]),(j+1))
print(ans)




Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(a+n);i++)
#define var auto
using namespace std;
using ll = long long;

int main() {
  int a[3][3];
  cin >> a[0][0] >> a[0][1] >> a[0][2];
  cin >> a[1][0] >> a[1][1] >> a[1][2];
  cin >> a[2][0] >> a[2][1] >> a[2][2];
  int n;
  cin >> n;
  vector<int> b;
  rep(i,0,n) {
    int bb; cin >> bb;
    b.push_back(bb);
  }

  bool ans = false;
  // 縦のビンゴ
  rep(i,0,3) {
    if (find(b.begin(), b.end(), a[0][i]) != b.end() 
      && find(b.begin(), b.end(), a[1][i]) != b.end() 
      && find(b.begin(), b.end(), a[2][i]) != b.end()) {
        ans = true;
        break;
    }
  }

  // 横のビンゴ
  rep(i,0,3) {
    if (find(b.begin(), b.end(), a[i][0]) != b.end() 
      && find(b.begin(), b.end(), a[i][1]) != b.end() 
      && find(b.begin(), b.end(), a[i][2]) != b.end()) {
        ans = true;
        break;
    }
  }

  // 斜めのビンゴ
  
  if (find(b.begin(), b.end(), a[0][0]) != b.end() 
    && find(b.begin(), b.end(), a[1][1]) != b.end() 
    && find(b.begin(), b.end(), a[2][2]) != b.end()) {
      ans = true;
  }
  if (find(b.begin(), b.end(), a[0][2]) != b.end() 
    && find(b.begin(), b.end(), a[1][1]) != b.end() 
    && find(b.begin(), b.end(), a[2][0]) != b.end()) {
      ans = true;
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256