akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    # visited[i]:町iにvisited[i]回目の遷移で到達
    visited = [0]*(n+1)
    step = 0
    i = 1

    while k:
        i = a[i]
        step += 1
        k -= 1
        if visited[i] != 0:
            k = k % (step - visited[i])
            for _ in range(k):
                i = a[i]
            print(i)
            break
        visited[i] = step
    else:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 32272
#include<stdio.h>
int main(void)
{
	int S,s,m,h;

	scanf("%d\n",&S);

	s=S%3600%60;
	m=(S-s)%3600/60;
	h=(S-m-s)/3600;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vll;


int main() {
    int n, k;
    cin >> n >> k;
    if ((n + 1) / 2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc162/tasks/abc162_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;
    int tr = 0, tg = 0, tb = 0;
    for (auto &x : s) {
        if (x == 'R') {
            tr++;
        } else if (x == 'G') {
            tg++;
        } else {
            tb++;
        }
    }
    int ans = tr * tg * tb;
    REP(i, N - 2) {
        for (int d = 1; i + 2 * d < N; ++d) {
            // if (s[i] != s[i + d] && s[i] != s[i + 2 * d] &&
            //     s[i + d] != s[i + 2 * d]) {
            //     ans--;
            // }
            if (!(s[i] ^ s[i + d] ^ s[i + 2 * d] ^ 'R' ^ 'G' ^ 'B'))
                ans--;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
	// your code goes here
    int n; cin >> n;
    //int a[n + 1];
    int ok = 0, cnt = 0;
    vector<int> v;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        //cin >> a[i];
        if(x % 2 == 0 and x % 3 and x % 5){
            ok++;
        }
    }
    if(ok == 0)
    {
        cout << "APPROVED\n";
    }
    else
    {
        cout << "DENIED\n";
    }
	return 0;
}


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

typedef pair<int, int> point_t;

point_t operator+(const point_t &lhs, const point_t &rhs)
{
    point_t p = { lhs.first + rhs.first, lhs.second + rhs.second };
    return p;
}

bool operator==(const point_t &lhs, const point_t &rhs)
{
    return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}

bool is_in_field(int col, int row, const point_t &point)
{
    const int c = point.second;
    const int r = point.first;
    return (0 <= c && c < col) && (0 <= r && r < row); 
}

int solve(int col, int row, field_t &field, const point_t &start, const point_t &goal)
{
    // 2. 各マスの訪問履歴(memo)を作成する
    //    memoにはスタートからそのマスまでの歩数を格納する(初期値は0)
    vector<vector<int>> memo;
    for(int i = 0; i < row; ++i) {
        vector<int> v(col, 0); 
        memo.push_back(v);
    }   

    // 移動方向(上下左右)
    const point_t points[] = { 
        { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 },
    };  

    // 3. スタートのマスをキューに格納する
    queue<point_t> q;
    q.push(start);

    // 11. 4から10をキューが空になるまで繰り返す
    while( !q.empty() ) {
        // 4. キューの先頭から一マス取得する
        point_t cur = q.front(); q.pop();

        // 5. 取り出したマスがゴールなら終了
        if(cur == goal) {
            return memo[cur.first][cur.second];
        }

        for(const auto &point : points) {
            // 6. 手順4で取り出したマス(cur)から上下左右の何れかに移動する
            point_t next = cur + point;
            // 7. 移動先のマス(next)が迷路外でないことを確認する(迷路外の場合は手順6に戻る)
            if( is_in_field(col, row, next) ) {
                const char s = field[next.first][next.second];
                // 8. 移動先のマス(next)が道またはゴールであることを確認する(道でもゴールでもない場合は手順6に戻る)
                if(s == '.' || s == 'g') {
                    // 9. 移動先のマス(next)が未訪問であることを確認する(訪問済みの場合は手順6に戻る)
                    if(memo[next.first][next.second] == 0) {
                        // 10. 移動先のマス(next)をキューに格納し、訪問履歴を更新する
                        q.push(next);
                        memo[next.first][next.second] = memo[cur.first][cur.second] + 1;
                    }
                }
            }
        }
    }
    return -1;
}
int main () {
   int col, row;
    cin >> row >> col;

    point_t start, goal;
    field_t field;

    // 1. 迷路(field)を作成する
    int ans = 0;
    for(int i = 0; i < row; ++i) {
        vector<char> v;
        for(int j = 0; j < col; ++j) {
            char c;
            cin >> c;
            v.push_back(c);
            if(c == '.')ans++;
        }
        field.push_back(v);
    }
    start.first = 0;
    start.second = 0;
    field[0][0] = 's';
    goal.first = row - 1;
    goal.second = col - 1;
    field[row - 1][col - 1] = 'g';
    // 最短歩数はsolveで計算する
    cout << (solve(col, row, field, start, goal) != -1?ans - solve(col, row, field, start, goal) - 1:-1) << endl;
}

Measured memory_bytes: 256
// // -*- coding:utf-8-unix -*-

// #[macro_use]
// extern crate lazy_static;
// extern crate num_bigint; // 0.2.2
// extern crate num_traits; // 0.2.8
// use num_bigint::BigInt;
// use num_traits::Pow;
// use petgraph::algo::dijkstra;
// use petgraph::Directed;

// // use proconio::derive_readable;
// use proconio::fastout;
// use proconio::input;
// // use std::convert::TryInto;
// use ascii::{AsciiChar, AsciiString};
// use itertools::concat;
// use lazy_static::lazy_static;
// use libm::*;
// use petgraph::Graph;
// use std::cmp::*;
// use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
// use std::io::*;
// use std::ops::Range;
// use std::str::FromStr;
// use std::sync::Mutex;
// use superslice::*;

// pub 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")
// }

// // lazy_static! {
// //     static ref H: Mutex<Vec<i32>> = Mutex::default();
// //     static ref W: Mutex<Vec<i32>> = Mutex::default();
// // }

// // let mut values = VALUES.lock().unwrap();
// // values.extend_from_slice(&[1, 2, 3, 4]);
// // assert_eq!(&*values, &[1, 2, 3, 4]);

use proconio::{input, marker::Chars};
use std::collections::HashMap;

static ASCII_LOWER: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut convMap = HashMap::new();
    // for cha in ASCII_LOWER.iter() {
    //     convMap.insert(*cha, None);
    // }

    for (s, t) in s.iter().zip(t.iter()) {
        // eprintln!("{}, {}, {:?}", s, t, convMap.get(s));
        if let Some(t_decided) = convMap.get(s) {
            if t_decided != t {
                println!("No");
                return;
            }
        } else {
            convMap.insert(*s, *t);
            // convMap.insert(*t, *s);
        }
    }

    let mut convMap = HashMap::new();

    for (s, t) in s.iter().zip(t.iter()) {
        let tmp = s;
        let s = t;
        let t = tmp;
        // eprintln!("{}, {}, {:?}", s, t, convMap.get(s));
        if let Some(t_decided) = convMap.get(s) {
            if t_decided != t {
                println!("No");
                return;
            }
        } else {
            convMap.insert(*s, *t);
            // convMap.insert(*t, *s);
        }
    }

    println!("Yes");
    return;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N;
  
  if ((N % 1000) / 100 == (N % 100) / 10) {
    if (N / 1000 == (N % 1000) / 100 || (N % 100) / 10 == N % 10)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli k,n,i;
	cin>>n>>k;
	n=n%k;
	i=abs(n-k);
	n=min(n,i);
	cout<<n;
	return 0;
}

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

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

	int *h = new int[N];

	int sum = 0;
	rep(i, N) {
		cin >> h[i];
		if (K <= h[i]) sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<numeric>

#define FOR(i, a, b) for(int i=a; i<b; i++)

using namespace std;
using Int = long long;

int main(){
    Int N, x;
    cin >> N >> x;
    vector<Int> A(N);
    FOR(i, 0, N){
        cin >> A[i];
    }

    sort(begin(A), end(A));
    Int sum = 0;
    Int cnt = 0;
    for (int i=0; i<N; i++){
        sum += A[i];
        cnt ++;
        if (sum > x){
            cnt --;
            break;
        }else if (i == N-1 && x != sum){
            cnt --;
        }
    }

    cout << cnt << endl;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;


int main(){
    int n;
    cin >> n;
    int ans;
    if (n % 111 == 0){
        ans = n;
    }else{
        bool loop = true;
        ans = n + 1;
        while(loop){
            if (ans % 111 == 0){
                break;
            }
            ans++;
        }
    }
    cout << ans << "\n";
}


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

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		// long cur = System.currentTimeMillis();
		solver();
		// System.out.println(System.currentTimeMillis() - cur + "ms");
	}

	int N;

	@SuppressWarnings("rawtypes")
	void solver() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		ans = N - 1;
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}
		pow10[0] = 1;
		for (int i = 1; i <= 10; i++) {
			pow10[i] = 10L * pow10[i - 1];
		}
		factorial[0] = 1;
		for (int i = 1; i <= 10; i++) {
			factorial[i] = factorial[i - 1] *(long) i;
		}

		Arrays.fill(memo, -1);
		enumerate(A);
		Arrays.sort(A);
		second = true;
		enumerate(A).toArray(new Long[0]);
		System.out.println(ans);
	}

	int ans;
	boolean second = false;

	long[] pow10 = new long[11];
	int[] memo = new int[3628800];
	long[] factorial = new long[11];

	ArrayList<Long> enumerate(int[] A) {
		long a = to_long(A);
		ArrayDeque<Long> cur_que = new ArrayDeque<>();
		cur_que.add(a);
		ArrayDeque<Long> next_que = new ArrayDeque<>();
		ArrayList<Long> ret = new ArrayList<>();
		ret.add(a);
		int index = numbering(to_array(a));
		if (memo[index] != -1) {
			ans = Math.min(memo[index], ans);
		}

		memo[index] = 0 + (second ? 10 : 0);
		for (int i = 1; i <= N / 2 - ((N % 2 == 0) ? 1 : 0); i++) {
			while (!cur_que.isEmpty()) {
				long cur = cur_que.poll();
				for (int j = 0; j < N; j++) {
					for (int k = j + 1; k < N; k++) {
						int[] tmp = to_array(cur);
						int s = j, t = k;
						while (s < t) {
							int dummy = tmp[s];
							tmp[s] = tmp[t];
							tmp[t] = dummy;
							s++;
							t--;
						}
						long dummy = to_long(tmp);
						int idx = numbering(tmp);
						if (memo[idx] == -1) {
							next_que.add(dummy);
							memo[idx] = i + (second ? 100 : 0);
						} else if (memo[idx] < 100 && second) {
							ans = Math.min(memo[idx] + i, ans);
						}
					}
				}
			}
			ret.addAll(next_que);
			cur_que.addAll(next_que);
			next_que.clear();
		}
		return ret;
	}

	int numbering(int[] permutation) {
		int ret = 0;
		for (int i = 0; i < permutation.length; i++) {
			int count = 0;
			for (int j = i - 1; j >= 0; j--) {
				if (permutation[i] > permutation[j])
					count++;
			}
			ret += factorial[i] * count;
		}
		return ret;
	}

	long to_long(int[] array) {
		long ret = 0;
		for (int i = 0; i < array.length; i++) {
			ret += pow10[array.length - 1 - i] * array[i];
		}
		return ret;
	}

	int[] to_array(long a) {
		int[] ret = new int[N];
		int pos = N - 1;
		while (a > 0) {
			ret[pos--] = (int) (a % 10);
			a /= 10;
		}
		return ret;
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 120236
#include <iostream>

using namespace std;

int n,m,a,b,c,d,s,g,V,P;
char S;
int adm[22][22]={0}; //adjacency matrix
const int inf=1000000000;

int main()
{
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            adm[i][j]=inf;
        }
    }

    for(int i=0;i<m;i++)
    {
        cin >> a >> S >> b >> S >> c >> S >> d;
        adm[a][b]=c;
        adm[b][a]=d;
    }

    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(adm[i][j]>adm[i][k]+adm[k][j])
                {
                    adm[i][j]=adm[i][k]+adm[k][j];
                }
            }
        }
    }

    cin >> s >> S >> g >> S >> V  >> S >> P;
    cout << V-P-adm[s][g]-adm[g][s] << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm> 
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	string s;
	cin>>s;
	for (int i=0;i<n;i++)
	{
		if (i==k-1)
		{
			printf("%c",s[i]-'A'+'a');
		}
		else cout<<s[i];
	}
}

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

using namespace std;

int N, K;
int a[5005];
int sum[5005];
int dp[5005];

bool check(int remove);

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	sort(a, a + N + 1);
	int ans = -1;
	int r = N;
	int l = 1;
	while (l <= r) {
		int m = (l + r) / 2;
		if (!check(m)) {
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	cout << r << endl;
	return 0;
}

bool check(int remove) {
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < i; j++) {
			if (i == remove || dp[j] + a[i] >= K) {
				dp[i] = max(dp[i], dp[j]);
			} else {
				dp[i] = max(dp[i], dp[j] + a[i]);
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (dp[i] >= K - a[remove] && dp[i] < K) {
			return false;
		}
	}
	return true;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int s, s1, s2, s3, ans;
    cin >> s;
    s3 = (s%100)%10;
    s2 = (s%100)/10;
    s1 = (s - s2*1- -s3)/100;
    ans = s1 + s2 + s3;
    cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
  var input = input.split("\n");
  var string = input[0];
  var c,f,Cfound = 0;
  for(var i = 0;i < string.length;i++){
    if(string[i] == "C" && !Cfound){
      c = i;
      Cfound++;
    };
    if(Cfound && string[i] == "F"){
      f = i;
      return console.log("Yes");
    }
  };
  return console.log("No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 12664
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int n, m, i, sum, tmp, cnt;
    cin >> n >> m;
    int arr[n];
    sum=0;
    for (i=0; i<n; i++) {
        cin >> arr[i];
        sum+=arr[i];
    }
    tmp=ceil((double)sum/(double)(4*m));
    cnt=0;
    for (i=0; i<n; i++)
        if (arr[i]>=tmp) cnt++;

    if (cnt>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;
class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = stdIn.nextInt();
        }
        for(int i = 0; i < n; i++) {
            y[i] = stdIn.nextInt();
        }
        for(int p = 1; p <= 3; p++) {
            double dis = 0.0;
            for(int i = 0; i < n; i++) {
                dis += Math.pow(Math.abs(x[i] - y[i]),p);
            }
            System.out.println(Math.pow(dis, 1.0/p));
        }
        int max = 0;
        for(int i = 0; i < n; i++) {
            max = Math.max(max, Math.abs(x[i] - y[i]));
        }
        System.out.println(max);
         
    }
}


Measured memory_bytes: 26696
use proconio::input;
use proconio::marker::*;
use std::cmp;
use std::cmp::Ordering;
use std::cmp::Reverse;
use std::collections::BinaryHeap;

const MAX_V: usize = 50;
const MAX_S: i64 = MAX_V as i64 * 50 + 5;
const INF: i64 = 1e18 as i64;

#[derive(Clone, Copy)]
struct Edge {
    to: usize,
    fee: i64,
    time: i64,
}

#[derive(Eq)]
struct Data {
    v: usize,
    s: i64,
    time: i64,
}

impl Ord for Data {
    fn cmp(&self, other: &Self) -> Ordering {
        self.time.cmp(&other.time)
    }
}

impl PartialOrd for Data {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for Data {
    fn eq(&self, other: &Self) -> bool {
        self.time == other.time
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        s: i64,
        rails: [(Usize1, Usize1, i64, i64); m],
        exchanges: [(i64, i64); n],
    }

    let mut g = vec![vec![]; MAX_V];
    for (from, to, fee, time) in rails {
        g[from].push(Edge { to, fee, time });
        g[to].push(Edge {
            to: from,
            fee,
            time,
        });
    }

    let dp = vec![vec![INF; MAX_S as usize + 5]; MAX_V];

    let mut solve = Solve {
        dp,
        n,
        m,
        g,
        s,
        exchanges,
        q: BinaryHeap::new(),
    };
    solve.solve();
}

struct Solve {
    n: usize,
    m: usize,
    s: i64,
    g: Vec<Vec<Edge>>,
    dp: Vec<Vec<i64>>,
    exchanges: Vec<(i64, i64)>,
    q: BinaryHeap<Reverse<Data>>,
}

impl Solve {
    fn solve(&mut self) {
        let s = cmp::min(self.s, MAX_S);
        let g = self.g.clone();

        self.push(0, s, 0);

        while let Some(Reverse(data)) = self.q.pop() {
            let Data { v, s, time } = data;
            // if self.dp[v][s as usize] != time {
            //     continue;
            // }

            let (c, d) = self.exchanges[v];
            let ns = cmp::min(s + c, MAX_S);
            self.push(v, ns, time + d);

            for e in g[v].iter().copied() {
                self.push(e.to, s - e.fee, time + e.time);
            }
        }

        for i in 1..self.n {
            let mut ans = INF;
            for j in 0..(MAX_S + 5) {
                ans = cmp::min(ans, self.dp[i][j as usize]);
            }
            println!("{}", ans);
        }
    }

    fn push(&mut self, v: usize, s: i64, time: i64) {
        let data = Data { v, s, time };
        if s < 0 {
            return;
        }
        if self.dp[v][s as usize] <= time {
            return;
        }
        self.dp[v][s as usize] = time;
        self.q.push(Reverse(data));
    }
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007
using namespace std;

int main(){
  string dayOfWeek[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string S;
  cin >> S;
  REP(i, 7) {
    if(S == dayOfWeek[i]) {
      cout << (7 - i) << endl;
    }
  }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q; string s;
	cin >>n >>s >>q;
	vector<set<int>> wd(26);
	rep(i, n) wd[s[i]-'a'].insert(i);
	
	while(q--){
		int ck, ps, l, r; char z;
		cin >>ck;
		if(ck==1){
			cin >>ps >>z;
			if(s[ps-1]==z) continue;
			wd[s[ps-1]-'a'].erase(ps-1);
			wd[z -'a'].insert(ps-1);
			s[ps-1] = z;
		}else{
			cin >>l >>r;
			int ans = 0;
			rep(i, 26){
				auto it = wd[i].lower_bound(l-1);
				if(it != wd[i].end() && *it < r) ans++;
			}
			cout << ans <<"\n";
		}
	}
	return 0;
}


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

def main():
    N, W = map(int, input().split())
    vw = [list(map(int, input().split())) for i in range(N)]

    dp = [0] * (W+1)

    for i in range(W+1):
        for j in range(N):
            v, w = vw[j]
            if i - w >= 0:
                dp[i] = max(dp[i], dp[i-w] + v)

    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 5924
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;
#define md 1000000007
 
int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
   	// ll t;
   	// cin>>t;
   	// whln(t){
 	string a;
 	set<char>s;
 	cin>>a;
 	ll cnt =1;
 	rep(i,a.length())
 		s.insert(a[i]);

 	rep(i,a.length()-1){
 		
 		if(a[i]==a[i+1]&&a[i]=='R')
 			cnt++;
 	}
 	if(s.find('R')==s.end())
 		cnt=0;	
 	cout<<cnt<<"\n";
 
  	//}
}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool ispal(string a)
{
    long long int n=a.length();
    if(n==1)
        return true;
    else{
    int i=0,j;
    j=n-1;
    while(1)
    {
        if(a[i]!=a[j])
        {
            cout<<i<<" "<<j;
           return false;
        }
        i++,j--;
        if(i==j)
         {
        //     cout<<i<<" ";
             break;
        }
    }
    return true;
}}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  string a;
  cin>>a;
  if(n%2==1)
  {
      cout<<"No";
  }
  else{
int   i=0,j=n/2,f=0;
  while(1){
        if(j==n)
        {
            break;
        }
    if(a[i]!=a[j])
    {
        f=1;
        break;
    }
    i++,j++;
  }
  if(f==1)
  {
      cout<<"No";
  }
  else
    cout<<"Yes";
  }
  }


Measured memory_bytes: 3636
l = list(map(int,input().split()))

ans = -10000000000000000001

if l[0] * l[2] >= ans:
    ans = l[0] * l[2]
if l[0] * l[3] >= ans:
    ans = l[0] * l[3]
if l[1] * l[2] >= ans:
    ans = l[1] * l[2]
if l[1] * l[3] >= ans:
    ans = l[1] * l[3]

print(ans)


Measured memory_bytes: 9180
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        double sum=0;
        for (int i = 0; i < n; i++) {
            double x=sc.nextDouble();
            char c=sc.next().charAt(0);
            if(c=='J'){
                sum+=x;
            }else {
                sum+=(x*380000.0);
            }
        }
        out.println(sum);
    }
}

Measured memory_bytes: 24528
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++) {
			double x1 = stdIn.nextDouble();
			double y1 = stdIn.nextDouble();
			double x2 = stdIn.nextDouble();
			double y2 = stdIn.nextDouble();
			double x3 = stdIn.nextDouble();
			double y3 = stdIn.nextDouble();
			
			double a = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
			double b = Math.sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
			double c = Math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
			
			double s = (a+b+c)/2;
			double r = a*b*c / (4*Math.sqrt(s*(s-a)*(s-b)*(s-c)));
			
			double A1=2*(x2-x1);
			double B1=2*(y2-y1);
			double C1=(x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
			double A2=2*(x3-x1);
			double B2=2*(y3-y1);
			double C2=(x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);
			double X=(B1*C2-B2*C1)/(A1*B2-A2*B1);
			double Y=(C1*A2-C2*A1)/(A1*B2-A2*B1);

			System.out.printf("%.3f %.3f %.3f\n",X,Y,r);
		}
	}
	public static double sr(double a) {
		a = a*10000;
		if(a%10 >=  5) {
			a += 10-a%10;
		}
		else {
			a -= a%10;
		}
		int b = (int)a;
		
		return (b/10000.0);
	}
}

Measured memory_bytes: 20812
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod1e7(ll a){
  return (a % 1000000007);
}

ll mod1e9(ll a){
  return (a % 1000000009);
}

ll mod998(ll a){
  return (a % 998244353);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

vector<ll> fac(200001);
void factorial(){
  fac[0] = 1; 
  for(ll i=1; i < 200001; i++){
    fac[i] = mod998(fac[i-1]*i);
  }
}
    
ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return mod998(fac[n]/fac[r]/fac[n-r]);
}

int main(){
  ll x; cin >> x; ll ans = 0;
  
  for(ll i=1; i <= 360; i++){
    if((360-x)*i % 360 == 0){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
  
  
}

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

int main(void){

	double r,are,circ;

	scanf("%lf",&r);

	are = r * r * M_PI;
	circ = 2 * r * M_PI;

	printf("%.6lf %.6lf",are,circ);

	return 0;
}


Measured memory_bytes: 2108
import itertools
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(2*m+2)
tot=0
for l,r in zip(a,a[1:]):
	tot+=(r-l)%m
	if l>r:
		r+=m
	dif=r-l
	if dif>1:
		s[l+2]+=1
		s[r+1]-=dif
		s[r+2]+=dif-1
s=list(itertools.accumulate(list(itertools.accumulate(s))))
print(tot-max(s[i]+s[m+i] for i in a))

Measured memory_bytes: 79724
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int a,b;
  cin>>a>>b;

  cout<< ( a*b%2 ? "Odd" : "Even" )<<"\n";
}

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


Measured memory_bytes: 256
H = gets.chomp.to_i

d = (0..40).to_a.bsearch{|v| 2**v >= H}

if H == 1
  puts 1
  exit
end
ans = 3
if 2**d == H
  (d-1).times { ans = ans * 2 + 1}
else
  (d-2).times { ans = ans * 2 + 1}
end
puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,M;
  cin>>N>>M;
  vector<vector<int>>edges(N);
  REP(i,M){
    int a,b;cin>>a>>b;a--;b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  vector<int>ans(N,-1);
  ans[0]=0;
  queue<int>q;
  q.push(0);
  while(!q.empty()){
    int now=q.front();q.pop();
    for(int next:edges[now]){
      if(ans[next]!=-1)continue;

      ans[next]=now+1;
      q.push(next);
    }
  }
  cout<<"Yes"<<endl;
  FOR(i,1,N){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 10332
#include <iostream>

using namespace std;


// (n - 3) / 2
int tbl[55000];

int main() {
  int n;
  cin >> n;
  
  if (n == 2) {
    cout << "2\n";
    return 0;
  }
  
  for (int i = 0; i < 55000; ++i)
    tbl[i] = 0;
  
  for (int i = 0; i < 55000; ++i) {
    int x = i * 2 + 3;
    if (tbl[i] == 0) {
      // cout << x << endl;
      if (x >= n) {
        cout << x << endl;
        return 0;
      }
      int t = x;
      while ((t - 3) / 2 < 55000) {
        tbl[(t - 3) / 2] = 1;
        t += x * 2;
      }
    }
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());

  int B = 1;
  for(int i = 1;i<N;i++){
    if(A.at(i)>A.at(i-1)){
      B++;
      }
    else{
      continue;
    }
  }
  cout << B << endl;
      
}

Measured memory_bytes: 256
num = list(input().split())
command = list(input())

#コマンドによって位置が変わるnumのインデックス
patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

#commandの文字を読み取り、該当するpatternsのvalueを順に取り出して、numの順番を変えていく
for i in command:
    num = [num[j] for j in patterns[i]]

print(num[0])



Measured memory_bytes: 5568
n, p = map(int, input().split())
ls = list(map(int, input().split()))

odd = 0
even = 0

for i in range(n):
    if ls[i] % 2 == 0:
        even += 1
    elif ls[i] % 2 == 1:
        odd += 1

if p == 0:
    print((2 ** even) * max(2 ** (odd - 1), 1))
elif p == 1:
    if odd == 0:
        print(0)
    else:
        print((2 ** even) * max((2 ** (odd - 1), 1)))

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

signed main(void)
{
	int n, m;
	cin >> n >> m;
	long long sum, buy;
	vector<pair<long long, long long>> a(n);

	rep(i, n) cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end());
	buy = sum = 0;
	rep(i, n)
	{
		if (buy + a[i].second > m)
		{
			sum += (m - buy) * a[i].first;
			break;
		}
		else
		{
			buy += a[i].second;
			sum += a[i].first * a[i].second;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int a[n];
 map<int,vector<int> > m;
 int i;
 for(i=0;i<n;i++)
 {
	cin>>a[i];
	m[a[i]].push_back(i+1);
 }
 map<int,vector<int > > ::iterator it;
 long long int ans=0;
 map<int,long long int> m1,m2;
 for(it=m.begin();it!=m.end();it++)
 {
 	int x=it->second.size();
 	long long int p=x;
 	p*=(x-1);
 	p/=2;
 	m1[it->first]=p;
 	ans+=p;
 	p=x-1;
 	p*=(x-2);
 	p/=2;
 	m2[it->first]=p;
 }
 //cout<<ans<<endl;
 for(i=0;i<n;i++)
 {
 	cout<<ans-m1[a[i]]+m2[a[i]]<<endl;
 }
 return 0;
}


Measured memory_bytes: 34048
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
if(a>b){
	System.out.println("a > b");
}
else if(a<b){
	System.out.println("a < b");
}
if(a==b){
	System.out.println("a == b");
}

}

}

Measured memory_bytes: 26268
s = str(input())
ansor = 'Yes'

for i in range(len(s)):
    if i %2 == 0:
        if s[i] == 'R' or s[i] == 'U' or s[i] == 'D':
            continue
        else:
            ansor = 'No'
    elif i %2 == 1:
        if s[i] == 'L' or s[i] == 'U' or s[i] == 'D':
            continue
        else:
            ansor = 'No'
print(ansor)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
// #define endl "\n"


vector<vi> mat;
vector<vi> temp;
int c = 0, k, ans = 0, n, m;

void chooseCol(int rem, int p) {
    if (rem == 0) {
        int ct = 0;
        for_(i, 0, n) for_(j, 0, m) ct += temp[i][j];
        if (ct == k) ans += 1;
        return;
    }
    if (p == m) return;

    chooseCol(rem, p+1);
    vector<vi> pre = temp;
    for_(i, 0, n) temp[i][p] = 0;
    chooseCol(rem-1, p+1);
    temp = pre;
}

void chooseRow(int rem, int p) {
    if (rem == 0) {
        chooseCol(c, 0);
        return;
    }
    if (p == n) return;


    vector<vi> pre = temp;
    chooseRow(rem, p+1);
    for_(i, 0, m) temp[p][i] = 0;
    chooseRow(rem-1, p+1);
    temp = pre;
}



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

    cin >> n >> m >> k;
    mat.resize(n, vi (m));
    for_(i, 0, n) for_(j, 0, m) {
        char c; cin >> c;
        if (c == '#') mat[i][j] = 1;
    }

    for_(r, 0, n) {
        c = 0;
        while (c <= m) {
            temp = mat;
            chooseRow(r, 0);
            c++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            p1 = n * a;
            p2 = b;

            if (p1 < p2) x = p1;
            else x = p2;

            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
colors ={:black =>{:r => 0,:g =>0,:b=>0},
  :blue =>{:r => 0,:g =>0,:b=>255},
  :lime =>{:r => 0,:g =>255,:b=>0},
  :aqua =>{:r => 0,:g =>255,:b=>255},
  :red =>{:r => 255,:g =>0,:b=>0},
  :fuchsia =>{:r => 255,:g =>0,:b=>255},
  :yellow =>{:r => 255,:g =>255,:b=>0},
  :white =>{:r => 255,:g =>255,:b=>255},
}
d = lambda do |r,g,b|
  min = 444
  ans =""
  colors.each do |color,value|
    dk = Math.sqrt((r-value[:r])**2+(g-value[:g])**2+(b-value[:b])**2)
    if min > dk
      min = dk
      ans = color
    end
  end
  ans
end
loop do
  c = gets.chomp
  break if c=='0'
  r,g,b =  c.delete('#').gsub(/(.)(.)/,'\1\2 ').split.map(&:hex)
  puts d.call(r,g,b)
end

Measured memory_bytes: 2592
#090c
N,M = map(int, input().split())

if M==1:
    if N==1:
        #1回フリップ
        print(1)
    elif N==2:
        #全て2回フリップ
        print(0)
    elif N>2:
        #両端は2回フリップ、それ以外は3回フリップ
        print(M*N - 2)
elif M==2:
    if N==1:
        #全て2回フリップ
        print(0)
    elif N==2:
        #全て4回フリップ
        print(0)
    elif N>2:
        #両端4枚は4回フリップ、それ以外は6回フリップ
        print(0)
elif M>2:
    if N==1:
        #両端は2回フリップ、それ以外は3回フリップ
        print(M*N - 2)
    elif N==2:
        #両端4枚は4回フリップ、それ以外は6回フリップ
        print(0)
    elif N>2:
        #角は4回フリップ
        #角以外の周辺は6回フリップ
        #それ以外は9回フリップ
        print((M-2)*(N-2))

Measured memory_bytes: 3064
import math
n, s = [int(input()) for _ in range(2)]

def f(b,n):
    if n<b:
        return n
    elif n >= b:
        # // 少数切り捨ての割り算
        return f(b,(n//b)) + (n%b)

# nとsが同じであれば、n+1が答えであることは自明
# n==s==2の場合、bが2と仮定すると、
# 2進数で各桁の足し算を行うため、
# 2を2進数表記にすると10となる。
# 1+0 = 1となるため、偽

# n==s==2の場合、bが3と仮定すると、
# 3進数で各桁の足し算を行うため、
# 3を2進数表記にすると2となる。
# 2 = 2となるため、真
if n == s:
    print(n + 1)
    exit()
    
# 解がプラスであるときの計算
# 2～√nまでの計算
for b in range(2, int(math.sqrt(n))+1):
    if f(b,n) == s:
        print(b)
        exit()

# √n～0までの計算。-1づつする
for i in range(int(math.sqrt(n))+1,0,-1):
    b = (n-s)//i +1
    if b >1 and f(b,n) ==s:
            print(b)
            exit()

print(-1)


Measured memory_bytes: 44268
N = int(input())
S = input()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
w = ""
for x in S:
    if abc.index(x) + 1 + N > 26:
        w += abc[abc.index(x) + N - 26]
    else:
        w += abc[abc.index(x) + N]
print(w)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}
const int MAX = 3000000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  ll x,y; cin>>x>>y;
  if((2*x-y)%3 != 0 || (2*y-x)%3!=0){
    cout << 0 << endl;
  }else{
    ll a = (2*x-y)/3;
    ll b = (2*y-x)/3;
    COMinit();
    cout << COM(a+b, a) << endl;
  }
  return 0;
}


Measured memory_bytes: 70528
#include<stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);
	int check = 1;
	if(n % 2 == 1) check = 0;
	if(check) for(int i = 0, m = n/2; i < m; i++) if(s[i] != s[i + m])
	{
		check = 0;
		break;
	}
	check? puts("Yes") : puts("No");
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n,k;
    cin >> n >> k;

    int x[n];

    rep(i,n) cin >> x[i];


    ll ans = 0;

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

    cout << ans << endl;
}

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

int main(void){
    string s;
    cin >> s;
    int sum = 0;
    int mx = 0;
    rep(i,s.length()+1){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
            sum += 1;
        }
        else{
            mx = max(mx,sum);
            sum = 0;
        }
    }
    cout << mx <<endl;
    
    return 0;
}



































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    int test; cin >> test;
    rep(casenum, test){
        string a, b;
        cin >> a >> b;
        int n1 = a.size(), n2 = b.size();
        int n = max(n1, n2);
        if(n1 > 80 || n2 > 80){
            cout << "overflow" << endl;;
            continue;
        }
        if(n1 < n2){
            int sa = n2 - n1;
            string p = "";
            rep(i, sa) p += '0';
            a = p + a;
        }else if(n1 > n2){
            int sa = n1 - n2;
            string p = "";
            rep(i, sa) p += '0';
            b = p + b;
        }
        bool keta = false;
        string res = "";
        for(int i = n - 1; i >= 0; --i){
            int k = (a[i] - '0') + (b[i] - '0');
            if(keta) k++;
            if(k < 10){
                char temp = '0' + k;
                res = temp + res;
                keta = false;
            }else{
                char temp = '0' + (k - 10);
                res = temp + res;
                keta = true;
            }
        }
        if(keta) res = '1' + res;
        if(res.size() > 80){
            cout << "overflow" << endl;
            continue;
        }
        cout << res << endl;
    }
    return 0;
}

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

int main(){
    int N;
    int a[100001],b[100001],c[100001];
    long long dp[100001][3];
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];
    for(int i=2;i<=N;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    long long sum=max(dp[N][0],dp[N][1]);
    sum=max(sum,dp[N][2]);
    cout<<sum<<endl;
    return 0;
}

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

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

   int S_half_size = ceil(S.size()/2.0);
   string S_f, S_r;
   S_f = S.substr(0, S_half_size);
   S_r = S.substr(S.size()-S_half_size, S_half_size);
   reverse(S_r.begin(), S_r.end());

   int cnt=0;
   for (int i=0; i<S_half_size; i++)
      if (S_f.at(i) != S_r.at(i))
         cnt++;

   cout << cnt << endl;
}



Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

map<long long, int> factorize(long long n){
    map<long long, int> res;
    
    if(n%2 == 0){
        int a = 0;
        while(n%2 == 0){
            n /= 2;
            a++;
        }
        res[2] = a;
    }
    
    for(long long i=3; i*i<=n; i+=2){
        if(n%i) continue;
        int a = 0;
        while(n%i == 0){
            n /= i;
            a++;
        }
        res[i] = a;
    }
    if(n != 1) res[n] = 1;
    return res;
}

long long powint(long long a, long long n){
    long long res = 1;
    while(n){
        res *= a;
        n--;
    }
    return res;
}

long long lcm(long long A, long long B){
    auto factA = factorize(A), factB = factorize(B);
    map<long long, int> fact;

    for(auto f : factA){
        fact[f.first] = f.second;
    }
    for(auto f : factB){
        if(fact.find(f.first) == fact.end()) fact[f.first] = f.second;
        else{
            if(fact[f.first] < f.second) fact[f.first] = f.second;
        }
    }

    long long res = 1;
    for(auto f: fact){
        res *= powint(f.first, f.second);
    }

    return res;
}

int main(void){
    int A,B; cin >> A >> B;
    cout << lcm((ll)A, (ll)B) << endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	double sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	double mean = sum / N;
	double MIN = 9999;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (MIN > abs(mean - A[i])) {
			ans = i;
			MIN = abs(mean - A[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if(n%2==0){
            System.out.println(n/2);
        }else{
            System.out.println((n/2) +1 );
        }

    }
}

Measured memory_bytes: 23124