akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>

using namespace std;

inline int read()
{
  int x=0,f=1;char ch=getchar();
  while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
  while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
  return x*f;
}

int a,b,c,d;

int main()
{
  cin>>a>>b>>c>>d;
  if (a<b) swap(a,b);
  if (a<c) swap(a,c);
  a=a*(1 << d)+b+c;
  cout<<a; 
  return 0;
}


Measured memory_bytes: 256
import math


def convert_min(h, m):
    t_min = h * 60 + m
    return t_min


def main():
    a, b, h, m = [int(v) for v in input().split(' ')]

    t_min = convert_min(h, m)

    angle_a = ((t_min * 0.5) % 360)
    angle_b = ((t_min * 6) % 360)

    diff_angle = abs(angle_a - angle_b)
    diff_angle = min(360 - diff_angle, diff_angle)
    d = diff_angle / 180 * math.pi

    l2 = (b * math.cos(math.pi / 2 - d)) ** 2 + \
        (a - b * math.sin(math.pi / 2 - d)) ** 2
    l = math.sqrt(l2)
    print(l)


if __name__ == '__main__':
    main()


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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        int W = nint();
        int maxV = 0;
        int[] ws = new int[N+1];
        int[] vs = new int[N+1];
        
        for (int i = 1; i <= N; i++) {
            ws[i] = nint();
            vs[i] = nint();
            maxV += vs[i];
        }
        
        long[][] dp = new long[N+1][maxV+1];
        for (int i = 0; i <= N; i++) {
            Arrays.fill(dp[i], INF);
        }
        for (int i = 1; i <= N; i++) {
            for (int v = 0; v <= maxV; v++) {
                if (v <= vs[i]) {
                    dp[i][v] = min(dp[i-1][v], ws[i]);
                } else {
                    dp[i][v] = min(dp[i-1][v], dp[i-1][v-vs[i]] + ws[i]);
                }
            }
        }
        for (int i = maxV; i >= 0; i--) {
            if (dp[N][i] <= W) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(0);
    }
    
    static long max(long... longs) {
        return Arrays.stream(longs).max().getAsLong();
    }
    
    static long min(long... longs) {
        return Arrays.stream(longs).min().getAsLong();
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 340140
#include<stdio.h>
#define SIZE 100000
 
int main(){
  char s[SIZE];
  int i;
 
  scanf("%s",s);
 
  for(i = 0; s[i] != '\0'; i++){
    if(i % 2 == 0){
      printf("%c",s[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b > a:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(a%b, b)


N = int(input())
A = [int(s) for s in input().split(" ")]

left = A.copy()
right = A.copy()

for i in range(1, N):
    left[i] = gcd(left[i-1], left[i])

for i in reversed(range(0, N-1)):
    right[i] = gcd(right[i+1], right[i])

ans = max(right[1], left[-2])

for i in range(1, N-1):
    ans = max(ans, gcd(left[i-1], right[i+1]))

print(ans)

Measured memory_bytes: 14428
#include<iostream>
#include<vector>
using namespace std;vector<vector<int> >a(11,vector<int>(330));void r(int n,int u,int s,int d){a[n][s]++;for(int i=10;i-->0;)if(!(u>>i&1))r(n+1,u^1<<i,s+d*i,d+1);}main(){r(0,0,0,1);for(int n,s;cin>>n>>s;)cout<<a[n][s]<<"\n";}

Measured memory_bytes: 804
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let inf = usize::max_value() as usize;
    let mut dp = vec![inf; n + 1];
    dp[0] = 0;

    use std::cmp::min;

    for i in 1..n + 1 {
        // 1
        if dp[i - 1] != inf {
            dp[i] = min(dp[i], dp[i - 1] + 1)
        }
        // 6
        let mut six = 6;
        while six <= i {
            let index = i - six;
            if dp[index] != inf {
                dp[i] = min(dp[i], dp[index] + 1)
            }
            six *= 6;
        }

        // 9
        let mut nine = 9;
        while nine <= i {
            let index = i - nine;
            if dp[index] != inf {
                dp[i] = min(dp[i], dp[index] + 1)
            }
            nine *= 9;
        }
    }

    println!("{}", dp[n])
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a[3];
  rep(i, 0, 3){
    cin >> a[i];
  }
  sort(a, a + 3);
  cout << a[0] + a[1] << "\n";
}

  

Measured memory_bytes: 3544
// Problem : D - Line++
// Contest : AtCoder - AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,x,y,cnt[2002];

int dist(int i,int j){
    return abs(i-j);
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++){
            int val = min(dist(i,j),min(dist(j,x)+dist(y,i)+1,dist(i,x)+dist(y,j)+1));
            cnt[val]++;
        }
    }
    for(int i=1;i<n;i++) cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static int mod = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(scan.next());
        }
        scan.close();

        long[] s = new long[n + 1];
        for (int i = 0; i < n; i++) {
            s[i + 1] = s[i] + a[i];
            s[i + 1] %= mod;
        }

        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            long cumsum = s[n] - s[i + 1];
            if (cumsum < 0) {
                cumsum += mod;
            }
            long add = a[i] * cumsum;
            add %= mod;
            ans += add;
            ans %= mod;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 61228
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author gainullin.ildar
 */

#include <bits/stdc++.h>

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;


typedef long long ll;
typedef unsigned long long ull;

const int M = 1e9 + 7;

inline int mul(int a, int b)
{
    return (a * (ll) b) % M;
}

inline int add(int a, int b)
{
    return (a + b) % M;
}

class Main
{
public:
    void solve(std::istream &in, std::ostream &out)
    {
        int n, m;
        in >> n >> m;
        int f_n = 1;
        int f_m = 1;
        for (int i = 1; i <= n; i++)
        {
            f_n = mul(f_n, i);
        }
        for (int i = 1; i <= m; i++)
        {
            f_m = mul(f_m, i);
        }
        int ans = 0;
        for (int st = 0; st < 2; st++)
        {
            int x = n, y = m;
            for (int cur = 0; cur < n + m; cur++)
            {
                if (cur % 2 == st)
                {
                    x--;
                }
                else
                {
                    y--;
                }
            }
            if (x >= 0 && y >= 0)
            {
                ans = add(ans, mul(f_n, f_m));
            }
        }
        out << ans << '\n';
    }
};


int main()
{
    ios::sync_with_stdio(0);
    Main solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
A = []
for i in range(3):
    A.append(list(map(int, input().split())))


n = int(input())
B = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
    num = int(input())
    for j in range(3):
        for i in range(3):
            if A[j][i] == num:
                B[j][i] = 1

ans = 0
for i in B:
    if len(set(i)) == 1 and i[0] == 1:
        ans = 1
for j in range(3):
    if B[0][j] == 1 and B[1][j] == 1 and B[2][j] == 1:
        ans = 1
if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    ans = 1
if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    ans = 1

if ans == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
n,*z=`dd`.split.map &:to_i;t=*0...n;*e=t;a=z.shift n+1;n.downto(1){|i|a[i]-=a[i-1]};k,*z=z;z.map{|x|t[x-2,2]=t[x-1],t[x-2]};60.times{|i|k[i]>0&&e.map!{|q|t[q]};t=t.map{|q|t[q]}};k,*a=a
e.map{|q|p k;k+=a[q]}
#n.times{|i|p k;k+=a[e[i]]}

Measured memory_bytes: 57444
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i = 0;i < n;i++){
            list.add(sc.nextInt());
        }
        long x = 0;
        for(int i = 0;i < n-1;i++){
            if(list.get(i) + t > list.get(i+1)){
                x += list.get(i+1) - list.get(i);
            }
            else{
                x += t;
            }
        }
        x += t;
        System.out.println(x);
    }
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> snk(n, false);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            snk.at(a) = true;
        }
    }
    int ans = 0;
    rep(i, n) {
        if(!snk.at(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long

main()
{
  int n;
  int a;
  deque < int > deq;

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    if((n + i) % 2 == 1) {
      deq.push_front(a);
    } else {
      deq.push_back(a);
    }
  }

  while(!deq.empty()) {
    cout << deq.front();
    deq.pop_front();
    if(!deq.empty()) cout << " ";
  }
  cout << endl;
  return (0);
}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int n, m, a[50 * 2];

int main(void) {
	int ans[50] = {};
	cin >> n >> m;
	for (int i = 0; i < m * 2; i++) {
		cin >> a[i];
		ans[a[i]-1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

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

const int N = 500;

using namespace std;

int main() {
	int n, x, l, r = 1;
	
	cin >> n >> x;
	
	vector<int> v(n + 1, 0);
	
	rep(i, 1, n + 1) {
		cin >> l;
		v[i] = l + v[i - 1];
		r += (v[i] <= x);
	}
	
	cout << r << endl;
	
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    bool flag = false;
    ll tmp_R = 0;
    ll tmp_L = 0;
    vector<ll>ans(s.size(),0);
    rep(i,s.size())
    {
        if(s[i] == 'L')
        {
            flag = true;
            tmp_L++;
        }
        else if(flag)
        {
            if( (tmp_R+tmp_L+2)%2 == 0 )
            {
                ans[i-tmp_L] = (tmp_R+tmp_L)/2;
                ans[i-tmp_L-1] = (tmp_R+tmp_L)/2;
            }
            else
            {
                if( (tmp_R+2)%2==0 )
                {
                    ans[i-tmp_L-1] = (tmp_R+tmp_L)/2;
                    ans[i-tmp_L] = tmp_R+tmp_L - ans[i-tmp_L-1];
                }
                else
                {
                    ans[i-tmp_L] = (tmp_R+tmp_L)/2;
                    ans[i-tmp_L-1] = tmp_R+tmp_L-ans[i-tmp_L];
                }
            }
            flag = false;
            tmp_L = 0;
            tmp_R = 1;
        }
        else tmp_R++;
    }

    if( (tmp_R+tmp_L+2)%2 == 0 )
    {
        ans[ans.size()-tmp_L] = (tmp_R+tmp_L)/2;
        ans[ans.size()-tmp_L-1] = (tmp_R+tmp_L)/2;
    }
    else
    {
        if( (tmp_R+2)%2==0 )
        {
            ans[ans.size()-tmp_L-1] = (tmp_R+tmp_L)/2;
            ans[ans.size()-tmp_L] = tmp_R+tmp_L - ans[ans.size()-tmp_L-1];
        }
        else
        {
            ans[ans.size()-tmp_L] = (tmp_R+tmp_L)/2;
            ans[ans.size()-tmp_L-1] = tmp_R+tmp_L-ans[ans.size()-tmp_L];
        }
    }


    rep(i,ans.size())
    {
        cout << ans[i];
        if(i+1 != ans.size()) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s,t; cin>>s>>t;
    t.pop_back();
    if(s == t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3596
import sys
import math

def main():
    n_d_a = sys.stdin.readline().strip().split(' ')
    n, d, a = [int(s) for s in n_d_a]
    xh = [[]] * n

    for i in range(n):
        x, h = [int(s) for s in sys.stdin.readline().strip().split(' ')]
        xh[i] = [x, h]
    # n = 3
    # d = 1
    # a = 1
    # xh = [[1, 4], [2, 1], [3, 100]]
    xh.sort()

    cur = 0
    right_indices = [0] * n
    for i in range(n):
        cur = max(cur, i)
        x, h = xh[i]
        right_val = x + d * 2
        while cur < n-1 and xh[cur+1][0] <= right_val:
            cur += 1
        right_indices[i] = cur

    imos = [0] * (n+1)
    ans = 0
    for i in range(n):
        if imos[i] < xh[i][1]:
            need = math.ceil((xh[i][1] - imos[i]) / a)
            ans += need
            imos[i] += need * a
            right_idx = right_indices[i]
            imos[right_idx+1] -= need * a
        imos[i+1] += imos[i]
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 79836
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using sll = signed long long;
using ui = unsigned int;
using ull = unsigned long long;


auto power(ui base, ui exponent) {
	return
		static_cast<sll>
			(std::powl(base, exponent) );
}

int main() {
//	std::cout << -10 % 3 << "\n";


	sll n;
	std::cin >> n;


	std::string ans;
	ui i{};
	while (n != 0) {
		
		const auto rem = n % power(2, i + 1);

		ans += rem != 0 ? '1' : '0';
		n += rem * (i % 2 == 0 ? -1 : 1)*(n<0?-1:1);

//		std::cout << i << " " << rem << " " << n << "\n";
		++i;
	}

	if (ans.empty()) {
		std::cout << 0 << "\n";
	}
	else {
		for (ui i{}; i < ans.size(); ++i)
			std::cout << ans[ans.size() - i - 1];
		std::cout << "\n";
	}
}




Measured memory_bytes: 256
//Forever... Check size - Reading order - Use scanf - Clear structures
#pragma GCC optimize ("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
#define REP(i,a,b) for(int i = int(a); i < int(b); ++ i)
typedef long long ll;
typedef pair<int, int> ii;

const int N = 2e5 + 2;
const int Mod = 1e9 + 7;
 
int f[N], inv[N], ans[N];

bool below(ii from, ii to){
	if(from.ff > to.ff) return false;
	return from.ss <= to.ss;
}

int ways(ii pos){
	int n = pos.ff, m = pos.ss;
	// comb(n+m, m)
	int res = (1LL * f[n+m] * inv[n]) % Mod;
	return (1LL * res * inv[m]) % Mod;
}

int bp(int base, int expo){
	if(expo == 0) return 1;
	if(expo % 2) return (1LL * base * bp(base, expo - 1)) % Mod;
	int val = bp(base, expo / 2);
	return (1LL * val * val) % Mod;
}

int main(){
	fastio;
	f[0] = inv[0] = 1;
	REP(i,1,N) {
		f[i] = (1LL * f[i - 1] * i) % Mod;
		inv[i] = bp(f[i], Mod - 2);
	}
	int h, w, n; cin >> h >> w >> n;
	vector<ii> vec;
	vec.pb(ii(h-1, w-1));
	REP(i,0,n) {
		int a, b; cin >> a >> b;
		vec.pb(ii(a - 1, b - 1));
	}
	sort(vec.begin(), vec.end());
	REP(i,0,sz(vec)){
		int ret = ways(vec[i]);
		REP(j,0,i){
			if(!below(vec[j], vec[i])) continue;
			int x = ways(ii(vec[i].ff - vec[j].ff, vec[i].ss - vec[j].ss));
			ret -= (1LL * x * ans[j]) % Mod;
			if(ret < 0) ret += Mod;
		}
		ans[i] = ret;
		if(i == sz(vec)-1) cout << ret << endl;
	}
	return 0;
}



Measured memory_bytes: 5232
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int H,W;
    cin >> H >> W;
    char C[100][100];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> C[i][j];
        }
    }
    for(int i=0; i<H*2; i++){
        for(int j=0; j<W; j++){
            cout << C[i/2][j];
        }
        cout << endl;
    }
    
    return 0;
}

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

#define M 1000333/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}


int h1(long long key){ return key%M;/* your task */; }
int h2(long long key){ return 1+key%(M-1)/* your task */; }


int find(char str[]){

    /* your task */
    long long key = getKey(str);
	long long h;
	for(int i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
    	if(strcmp(H[h],str)==0) return 1;
		else if(strlen(H[h])==0) return 0;
	}
    return 0;

}

int insert(char str[]){

    /* your task */
    long long key = getKey(str);
	long long h;
	for(int i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
    	if(strcmp(H[h],str)==0) return 1;
		else if(strlen(H[h])==0) {
			strcpy(H[h],str);
			return 0;
		}
	}
    return 0;

}

int main(){
    int i, n;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)==1){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15420
from math import factorial
X,Y = map(int,input().split())
if (X + Y) % 3 != 0:
  print(0)
  exit()
MOD = 10**9 + 7
i2 = (2 * X - Y) // 3
i1 = X - 2 * i2
if i1 < 0 or i2 < 0:
  print(0)
  exit()
  
def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

factorials, invs = prepare(i1+i2,MOD)
print(factorials[i1+i2] * invs[i1] % MOD * invs[i2] % MOD)

Measured memory_bytes: 55852
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[][] rev = new int[2][N+1];
		for(int i=0; i<N; i++)
			rev[0][i+1] = rev[0][i] + (s[i]=='#' ? 1 : 0);
		for(int i=N-1; i>=0; i--)
			rev[1][i] = rev[1][i+1] + (s[i]=='.' ? 1 : 0);
		int ans = N;
		for(int i=0; i<=N; i++)
			ans = Math.min(ans, rev[0][i] + rev[1][i]);
		
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 30672
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
  int f[N2];
  int space;
  string path;

  bool operator < ( const Puzzle &p ) const {
    for ( int i = 0; i < N2; i++ ) {
      if ( f[i] == p.f[i] ) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p) {
  for ( int i = 0; i < N2; i++ )
    if ( p.f[i] != (i + 1) ) return false;
  return true;
}

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while ( !Q.empty() ) {
    u = Q.front(); Q.pop();
    if ( isTarget(u) ) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for ( int r = 0; r < 4; r++ ) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ) {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main() {
  Puzzle in;

  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;  // set space
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 30580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,W;
    cin>>n>>W;
    long long int w[n],v[n],dp[W+2];
    for(int i=0;i<=W;i++)dp[i]=0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=W;j>=w[i];j--)
        {
            dp[j]=max(dp[j],v[i]+dp[j-w[i]]);
           // cout<<i<<" "<<j<<" "<<dp[j]<<" "<<v[i]+dp[j-w[i]]<<"\n";
        }
    }
cout<<dp[W];
    
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int maxn=2e5+6;
const int mod=1e9+7;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
char a[101][101];
int b[101];
int c[101];

int main() {
 int k;
 cin >> k;
 cout << (k/2) *((k/2)+(k%2)) << endl;
}


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

using namespace std;

int main() {
  int N, s{}, m{100};
  cin >> N;
  while(cin >> N) {
    s += N;
    if (N % 10) m = min(m,N);
  }
  if (m==100) s = 0;
  else if (s % 10 == 0) s -= m;
  cout << s << endl;
}


Measured memory_bytes: 3620
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, C, D = lr()
time1 = (A+D-1) // D
time2 = (C+B-1) // B
bl = time1 >= time2
print('Yes' if bl else 'No')


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, weight;
    cin >> n >> weight;
    long long w[n], v[n];
    for (long long i = 0; i < n; i++) cin >> w[i] >> v[i];
    long long b[n + 1][weight + 1];
    for (long long i = 0; i <= n; i++)
    {
        for (long long j = 0; j <= weight; j++)
        {
            if (i == 0 || j == 0) b[i][j] = 0;
            else if (j < w[i - 1]) b[i][j] = b[i - 1][j];
            else b[i][j] = max(b[i - 1][j], b[i - 1][j - w[i - 1]] + v[i - 1]);
        }
    }
    cout << b[n][weight];
}

Measured memory_bytes: 82364
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
int a,b,c; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}


int main()
{
	a = read();
	b = read();
	c = read();
	if(a == b && b != c)
	{
		printf("Yes\n");
		return 0;
	}
	if(b == c && a != c)
	{
		printf("Yes\n");
		return 0;
	}
	if(a == c && a != b)
	{
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)  //a~(b - 1)まで

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
/*-------------------------------*/

int num(int a)
{
  if (a == 1){
    return 1;
  }
  return a + num(a - 1);
}

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

  cout << num(n) << endl;

  return 0;
}


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


using namespace std;

int main()
{long long int N;
cin>>N;
long long int M = 1000000000000;
for(int x = 1;x<N;x++){
    long long int L = x,R = N-x;
    long long int S=0,s=0;
    while(L!=0){
        S+=L%10;
        L/=10;
    }while(R!=0){
        s+=R%10;
        R/=10;
    }
    if(S+s<M){
        M = S+s;
    }
}
cout<<M<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
bool prime[1000];
int main(){
    fill(prime+2,prime+1000,true);
    for(int i = 2; i < 1000; ++i)
        if(prime[i])
            for(int j = 2*i; j < 1000; j+=i)
                prime[j] = false;
    int n;
    cin >> n;
    ll ans = 1;
    for(int p = 1; p < 1000; ++p){
        if(!prime[p]) continue;
        int times = 0;
        int cur = p;
        while(n/cur > 0){
            times += n/cur;
            cur *= p;
        }
        ans = (ans*(times+1))%MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#input 整数N
#output N以下の桁数が奇数である正の整数

# 1~9 : 9               #10~99 : 90
# 100~999 : 900         #1000~9999 : 9000
# 10000~99999 : 90000
# :
# :

N = int(input())
o = len(str(N))
i = 1
sum = 0

if o % 2 == 0:
    while 2*i-1 <= o:
        sum += 9 * 100 ** (i-1)
        i += 1
else:
    sum += N
    while 2*i <= o:
        sum -= 90 * 100 ** (i-1)
        i += 1 

print(sum)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s, t,u;
	int n, m, c,i,j;
	getline(cin, s);
	getline(cin, t);
	u = s + s;
	n = s.length();
	m = t.length();
	c = 0;
	for (i = 0; i < n; i++) {
		if (u[i] == t[0]) {
			for (j = 0; j < m; j++) {
				if (u[i + j] != t[j])break;
				else if (j == m-1) {
					c = 1;
				}
			}
		}
	}
	if (c == 1) {
		cout << "Yes" << endl;
	}
	else if(c==0){
		cout << "No" << endl;
	}
	return 0;
}



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

using namespace std;

const int MAXN = 1e2;
const int MAXK = 1e5 + 5;
const int MOD = 1e9 + 7;
const int TSIZE = (1 << 20);

int n, k;
int a[MAXN];
int T[MAXN][MAXK];
int tree[TSIZE][2];

int add(int f, int s)
{
    f += s;
    return f % MOD;
}

int get_index(int index)
{
    return (TSIZE >> 1) + index;
}

void update(int index, int value, int s)
{
    index = get_index(index);

    tree[index][s] = value;

    for(int i = index >> 1; i > 0; i >>= 1)
    {
        tree[i][s] = add(tree[i * 2][s], tree[i * 2 + 1][s]);
    }
}

int query(int l, int r, int s)
{
    l = get_index(l); r = get_index(r);

    if(l == r)
    {
        return tree[l][s] % MOD;
    }

    int ans = add(tree[l][s], tree[r][s]);

    while(l + 1 != r)
    {
        if((l & 1) == 0) ans = add(ans, tree[l + 1][s]);
        if((r & 1) == 1) ans = add(ans, tree[r - 1][s]);
        l >>= 1; r >>= 1;
    }
    return ans;
}


void read_input()
{
    scanf("%d %d", &n, &k);

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

void solve()
{
    for(int i = 0; i <= a[0]; i++)
    {
        update(k - i, 1, 0);
        //T[0][k - i] = 1;
    }

    //printf("%d\n", query(0, 1, 0));

    int t = 1;

    int ans = 0;

    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j <= k; j++)
        {
            int right = min(k, j + a[i]);
            int temp = query(j, right, t ^ 1);
            update(j, temp, t);
            if(j == 0) ans = temp;
            /*for(int z = 0; z <= a[i]; z++)
            {
                if(j + z > k) break;
                T[i][j] = add(T[i][j], T[i - 1][j + z]);
            }*/
        }
        t ^= 1;
        for(int j = 0; j <= TSIZE; j++)
        {
            tree[j][t] = 0;
        }
    }
    printf("%d\n", query(0, 0, t ^ 1));
}

int main()
{
    read_input();
    solve();

    return 0;
}


Measured memory_bytes: 10368
import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res


hash_l = []
for i in range(N-1):
    if l[i] == l[i+1]:
        if i == 0:
            hash_l.append(0)
        if l[i-1] == l[i]:
            hash_l[-1] += 1
        else:
            hash_l.append(1)

cnt = 0
for x in hash_l:
    cnt += fac(x)
print(cnt)

Measured memory_bytes: 55004
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int N, K, A[100001], ans = 0;
vi G[100001];
int height[100001];

void dfs(int u, int parent) {
    if(!sz(G[u]))return;
    each(v, G[u]) {
        dfs(v, u);
    }
    if(parent != -1) {
        int h = 0;
        each(v, G[u]) {
            smax(h, height[v] + 1);
        }
        if((parent == 0 && h == K) || (parent != 0 && h == K - 1)) {
            h = -1;
            ans++;
        }
        height[u] = h;
    }
}

int main(){
    cin >> N >> K;
    rep(i, N)scanf("%d", &A[i]), --A[i];
    if(A[0] != 0)ans++;
    if(K == 1) {
        for(int i = 1; i < N; ++i)if(A[i] != 0) {
            ans++;
        }
    } else {
        for(int i = 1; i < N; ++i) {
            G[A[i]].push_back(i);
        }
        dfs(0, -1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int n;

int main(void)
{
	cin >> n;
	vector<LL>L;
	L.push_back(2);
	L.push_back(1);
	for (int i = 0; i < 100; ++i) {
		L.push_back(L[L.size() - 1] + L[L.size() - 2]);
	}
	cout << L[n] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    int count=0;
    for(int i=0;i<s1.length();i++)
    {
    	if(s1[i]!=s2[i]) count++;
	}
    cout<<count<<"\n";
}


Measured memory_bytes: 3812
def gcd(x,y):
    if y == 0:
        return x
    else: return gcd(y, x % y)

n,X = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
list = []
for i in x:
    list.append(abs(i-X))
if n == 1:
    print(abs(x[0]-X))
else:
    mn = 10000000000
    for i in range(1,len(list)):
        mn = min(mn, gcd(list[i-1],list[i]))
    print(mn)



Measured memory_bytes: 14252
N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
 
A_sum = [0]
sum_count = {}
sum_count[0] = 1

for i in range(N):
    r = (A_sum[i] + A[i]) % M
    A_sum.append(r)
    if r in sum_count:
        sum_count[r] += 1
    else:
        sum_count[r] = 1
        
result = 0
for key in sum_count:
    cnt = sum_count[key]
    result += cnt * (cnt - 1) / 2
    
print(int(result))

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

using namespace std;

const int MAXN = 1e5 + 10;

int n;

int a[MAXN];

const int MOD = 1e9 + 7;

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

    int ans = (x / 500) * 1000;
    x = x % 500;
    ans += (x / 5) * 5;

    cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

#define H 50
#define W 50

int main() {
	static char cc[H][W + 1];
	int h, w, i, j;

	scanf("%d%d", &h, &w);
	for (i = 0; i < h; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			if (cc[i][j] == '#') {
				int bad1, bad2, bad3, bad4;

				bad1 = bad2 = bad3 = bad4 = 0;
				if (i + 1 < h && cc[i + 1][j] != '#')
					bad1 = 1;
				if (j + 1 < w && cc[i][j + 1] != '#')
					bad2 = 1;
				if (i - 1 >= 0 && cc[i - 1][j] != '#')
					bad3 = 1;
				if (j - 1 >= 0 && cc[i][j - 1] != '#')
					bad4 = 1;
				if (bad1 && bad2 && bad3 && bad4) {
					printf("No\n");
					return 0;
				}
			}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 128
//# define FLAG
///delet....................................
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <cstdio>
# include <string>
# include <cmath>
# include <ctime>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <bitset>
# include <vector>
# include <fstream>
# include <algorithm>
using namespace std;
# define eps 1e-8
# define pb push_back
# define mp make_pair
# define pi acos(-1.0)
# define bug puts("H");
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false);
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define MAX 0x7fffffffffffff
# define INF 0x3f3f3f3f
# define MOD 1000000007
///          1234567890
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;
inline int Scan(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
///coding...................................

char a[60],b[60];

int main()
{
    IOS
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif /// FLAG
//    printf("%lld\n",((LL)1<<19)*3*3*3*3*3*3*3*3*3*3);
//    printf("%lld\n",(LL)3*2*1*3*1*2*2*2*1*3*1*2*1*3*3*3*3*3*1*2*1*1*2*2*2*2*2*1*1*2*2*2*2*2*2*2*1*3*1*2*1*3*1%MOD);
    int n,flag=0;
    LL ans=1;
    cin>>n>>a+1>>b+1;
    FOR(i,1,n) {
        if(a[i]==b[i]) {
            if(flag==0)ans*=3;
            else if(flag==1)ans*=2;
            flag=1;
        }
        else {
            if(flag==0)ans*=6;
            else if(flag==1)ans*=2;
            else if(flag==2)ans*=3;
            flag=2,++i;
        }
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
///delete FLAG..............................



















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

using namespace std;

double dp[606][605];
int cnt[606];
bool life[606][606];

int main()
{
    int n,m,x,y,now=1;
    double maxx,minn;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        cnt[x]++;
        life[x][y]=1;
    }
    for(int i=n-1;i>=1;i--)
    {
        maxx=-1;
        minn=1;
        for(int j=i+1;j<=n;j++)
            if(life[i][j])
            {
                dp[i][0]+=dp[j][0];
                maxx=max(maxx,dp[j][0]);
                for(int k=i+1;k<=n;k++)
                    dp[i][k]+=dp[j][k];
            }
        for(int j=1;j<=i;j++)
            dp[i][j]=dp[i][0]/cnt[i]+1;
        for(int j=i+1;j<=n;j++)
            dp[i][j]=dp[i][j]/cnt[i]+1;
        if(cnt[i]!=1)
            dp[i][i]=(dp[i][0]-maxx)/(cnt[i]-1)+1;

        dp[i][0]=dp[i][0]/cnt[i]+1;
        //cout<<i<<":"<<dp[i][0]<<" "<<dp[i][1]<<endl;
    }
    for(int i=1;i<=n;i++)
        dp[1][0]=min(dp[1][0],dp[1][i]);
    printf("%.8f\n",dp[1][0]);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 998244353LL
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,x,m;cin>>n>>x>>m;
  if(x==0){cout<<0<<endl; return 0;}

  vector<ll>l;
  ll c = x;
  l.push_back(c);
  map<int, int>mm;
  mm[c]++;

  rep(i, 100000*4){
    c = c*c%m;
    l.push_back(c);
    mm[c]++;
  }

  if(n<400000){
    ll result = 0;
    rep(i, n)result += l[i];
    cout<<result<<endl;

    return 0;
  }


  ll loop_len = 0;
  ll loop_sum=0;
  for(auto p:mm)if(p.second>1){
    loop_len++;
    loop_sum += p.first;
  }

  ll first_len=0;
  ll first_sum=0;
  for(auto p:mm)if(p.second==1){
    first_len++;
    first_sum += p.first;
  }

  vector<ll>loop;
  rep(i, m*4){
    if(mm[l[i]]>1)loop.push_back(l[i]);
    if(loop.size()>1 && loop[0]==l[i])break;
  }

  ll result = first_sum;
  n -= first_len;;
  result += n/loop_len*loop_sum;

  n = n%loop_len;
  ll last_sum=0;
  rep(i, n)last_sum += loop[i];

  cout<<result+last_sum<<endl;
  return 0;

  cout<<first_len<<' '<<first_sum<<endl;
  cout<<last_sum<<endl;
  cout<<loop_sum<<' '<<loop_len<<endl;

//cout<<loop.size()<<endl;

  return 0;
}

Measured memory_bytes: 9596
while 1:
    x = input().split()
    a = int(x[0])
    b = int(x[2])
    op = x[1]
    if op == "+":
        c = a+b
        print(c)
    elif op == "-":
        d = a-b
        print(d)
    elif op == "*":
        e = a*b
        print(e)
    elif op == "/":
        f = a//b
        print(f)
    elif op == "?":
        break



Measured memory_bytes: 5596
#include<stdio.h>

int main(){
  int i,n,t[3];
  int data,kari,hakari;

  while(1){
    scanf("%d%d%d",&t[0],&t[1],&t[2]);
    if(t[0] == 0 || t[1] == 0 || t[2] == 0)
      break;
    scanf("%d",&n);
    if(t[0] >= t[2]){
      t[0] = t[2];
       t[2] = -1;
      }
    if(t[1] >= t[2]&&t[2] != -1)
      t[1] = t[2];
    hakari = t[0] * t[0] + t[1] *t[1];
    for(i = 0; i < n; i++){
      scanf("%d",&data);
      data = data * 2;
      data = data * data;
      if(hakari < data)
	printf("OK\n");
      else 
	printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long n, sum, a, i, b;
    cin >> n;
    sum = 1;
    b = 1;
    a = 1;
 
    for (i = 0; i < n; i++)
    {
        sum = (10 * sum) % 1000000007;
        b = (9 * b) % 1000000007;
        a = (8 * a) % 1000000007;
    }
    while (sum - 2 * b + a < 0)
    {
        sum += 1000000007;
    }
    if (n == 1)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << sum - 2 * b + a << endl;
    }
    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	char *p;
	char str[1000];
	scanf("%d\n",&n);
	while(n--){
	gets(str);
	for(p;p=strstr(str,"Hoshino");)p[6]='a';
	puts(str);
	}
	return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> bnum(n+1), wnum(n+1);
  rep(i, n) {
    bnum[i+1] += bnum[i];
    wnum[i+1] += wnum[i];
    if (s[i] == '#')
      bnum[i+1]++;
    else
      wnum[i+1]++;
  }
  int ans = 1e9;
  rep(i, n+1)
    chmin(ans , bnum[i]+wnum[n]-wnum[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2180
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    n = readline().strip()
    print(n.translate(n.maketrans('19', '91')))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8860
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x) make_pair(x)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
 
int main() {

    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n)    cin>>s.at(i);

    ll m=0,a=0,r=0,c=0,h=0;
    rep(i,n) {
        if(s[i][0]=='M')    m++;
        if(s[i][0]=='A')    a++;
        if(s[i][0]=='R')    r++;
        if(s[i][0]=='C')    c++;
        if(s[i][0]=='H')    h++;
    }
    ll ans=m*a*(r+c+h)+m*r*(c+h)+(m+a+r)*c*h+a*r*(c+h);
    
    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e9)

int main(){
	int n, m;
	cin >> n >> m;
	ll x[m], d[m-1];
	for(int i=0; i<m; i++){
		cin >> x[i];
	}
	if(m==1 || n>=m){
		cout << 0 << endl;
		return 0;
	}

	sort(x, x+m);
	for(int i=0; i<m-1; i++){
		d[i]=x[i+1]-x[i];
	}
	sort(d, d+m-1, greater<int>());
	ll ans=x[m-1]-x[0];
	for(int i=0; i<n-1; i++){
		ans-=d[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a;
    cin >> a;
    if(a%10==9 || a/10%10==9){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256