akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int a,b,k;
  scanf("%d%d%d",&a,&b,&k);
  int i = 0;
  int turn = 0;
  for(i=0;i<k;i++){
    if(turn==0){
      b = b + a/2;
      a = a/2;
      turn = 1;
    }else{
      a = a + b/2;
      b = b/2;
      turn = 0;
    }
  }
  printf("%d %d\n",a,b);
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = []
    sm = 0
    for _ in range(n):
        x = int(input())
        if x % 10:
            a.append(x)
        sm += x
    a.sort()
    if sm % 10:
        print(sm)
    else:
        if a:
            sm -= a[0]
        else:
            sm = 0
        print(sm)
    
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""


Measured memory_bytes: 9388
import java.util.Scanner;

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

		String s = sc.next();

		while (true) {
			s = s.substring(0, s.length() - 2);
			if (s.substring(0, s.length() / 2).equals(s.substring(s.length() / 2))) {
				System.out.println(s.length());
				return;
			}

		}
	}

}


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

int main(void){
        char s[10], c;
        int l = 0, cnt = 0;
        bool ok = true;
        while((c=getchar())!='\n') s[l++] = c;
        for(int i=0; i<l; i++){
                if('a'<=s[i] && s[i]<='z') cnt++;
                else if(s[i]=='C'){
                        if(i<2 || l-2<i) ok = false;
                }
                else if(s[i]=='A'){
                        if(i!=0) ok = false;
                }
                else ok = false;
        }
        if(ok && cnt==l-2) puts("AC");
        else puts("WA");
        return 0;
}

Measured memory_bytes: 128
def print2(A,S): #print2(int or str a[:][:], str)
    for i in range(len(A)):
        b = [str(n) for n in A[i][:]]
        print(S.join(b))

h,w = map(int,input().split())
s = [0]*(h+2)
s[0] = ["."]*(w+2)
s[-1] = ["."]*(w+2)
for i in range(h):
    s[i+1] = ["."] + list(input()) + ["."]
ans = [[0 for j in range(w)] for i in range(h)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            ans[i-1][j-1] = "#"
        else:
            for y in range(-1,2):
                for x in range(-1,2):
                    if s[i+y][j+x] == "#":
                        ans[i-1][j-1] += 1
print2(ans,"")

Measured memory_bytes: 3064
input_int_list = list(map(int, input().split()))


N = input_int_list[0]
M = input_int_list[1]

Q_ans_list = [0] * (N+1)

ans_correct = 0
ans_penalty = 0

for i in range(M):
	input_list_i = list( input().split())
	Q_num = int(input_list_i[0])
	if input_list_i[1] == "WA":
		if Q_ans_list[Q_num] != -1:
			Q_ans_list[Q_num] = Q_ans_list[Q_num] + 1
	elif input_list_i[1] == "AC":
		if Q_ans_list[Q_num] != -1:
			ans_correct = ans_correct + 1
			ans_penalty = ans_penalty + Q_ans_list[Q_num]
			Q_ans_list[Q_num] = -1





print(ans_correct,ans_penalty)


Measured memory_bytes: 3828
import java.util.Scanner;
public class Main {
	static int N;
	static String ans="NO";
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		if(N==7||N==5||N==3)ans="YES";
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_MESSAGE_LEN 25
#define MAX_MESSENGERS_NUM 6

int n;
char message[MAX_MESSAGE_LEN + 1];

/* rotate message left by one */
void J()
{
    int i;
    char t = message[0];

    for(i = 0; i < n - 1; i++)
        message[i] = message[i + 1];
    message[i] = t;
}

/* rotate message right by one */
void C()
{
    int i;
    char t = message[n - 1];

    for(i = n - 1; i >= 0; i--)
        message[i] = message[i - 1];
    message[0] = t;
}

/* swap left and right halves of message */
void E()
{
    int half = n / 2;
    char buf[MAX_MESSAGE_LEN / 2];

    memcpy(buf, message, half);
    memcpy(message, message + half + (n % 2), half);
    memcpy(message + half + (n % 2), buf, half);
}

/* reverse message */
void A()
{
    int i, half = n / 2;
    char t;

    for(i = 0; i < half; i++)
    {
        t = message[i];
        message[i] = message[n - i - 1];
        message[n - i - 1] = t;
    }
}

/* increment digits in message */
void P()
{
    int i;

    for(i = 0; i < n; i++)
        if(isdigit((int)message[i]))
            message[i] = ((message[i] - '0') + 1) % 10 + '0';
}

/* decrement digits in message */
void M()
{
    int i;

    for(i = 0; i < n; i++)
        if(isdigit((int)message[i]))
            message[i] = ((message[i] - '0') + 9) % 10 + '0';
}

int main(void)
{
    int i;
    char messengers[MAX_MESSENGERS_NUM + 1];

    scanf("%*d%*c");

    while(~scanf("%s%*c", messengers))
    {
        scanf("%s%*c", message);
        n = strlen(message);

        for(i = strlen(messengers) - 1; i >= 0; i--)
            switch(messengers[i])
            {
              case 'J': C(); break;
              case 'C': J(); break;
              case 'E': E(); break;
              case 'A': A(); break;
              case 'P': M(); break;
              case 'M': P(); break;
            }

        puts(message);
    }

    return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

    string s, t;
    int cnt = 0;
    REP(i, 0, S.size()){
        s = S[i];
        t = T[i];
        if (s!=t){
            ++cnt;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

ll dfs(ll N, ll X) {
    ll ret = 0;
    if (N == 0 || X == 0) {
        ret = X;
    } else {
        ll len = (1LL << (N + 2)) - 3;
        ll len2 = (1LL << (N + 1)) - 3;
        ll p_num = (1LL << (N + 1)) - 1;
        ll p_num2 = (1LL << N) - 1;
        if (X >= len - 1) {
            ret = p_num;
        } else if (X > len2 + 2) {
            ret = p_num2 + 1 + dfs(N - 1, X - (len2 + 2));
        } else if (X == len2 + 2) {
            ret = p_num2 + 1;
        } else {
            ret = dfs(N - 1, X - 1);
        }
    }
    /*
    debug(N);
    debug(X);
    debug(ret);
    */
    return ret;
}

int main() {
    ll N, X;
    cin >> N >> X;
    cout << dfs(N, X) << endl;
}


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

int N, M;
vector<int> p, r;

void init(int n) {
  rep(i, n) {
    p[i] = i;
    r[i] = 0;
  }
}
int parent(int x) {
  if(p[x] == x) return x;
  else return p[x] = parent(p[x]);
}
void unite(int x, int y) {
  x = parent(x), y = parent(y);
  if(x == y) return;
  if(r[x] < r[y]) p[x] = y;
  else p[y] = x;
  if(r[x] == r[y]) r[x]++;
}

int main() {
  int a, b, ans = 0;
  map<int, int> m;
  cin >> N >> M;
  p.resize(N);
  r.resize(N);
  init(N);
  rep(i, M) {
    cin >> a >> b;
    a--;
    b--;
    unite(a, b);
  }
  for(auto x : p) m[parent(x)]++;
  for(auto c : m) ans = max(ans, c.second);
  cout << ans << endl;
}

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

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

    string s;
    cin >> s;

    int ans = 0;
    rep(i, n - 2) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::collections::*;
use std::cmp::{min, max};

////////// missing functions in 1.15.1 //////////
macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
/////////////////////////////////////////////////
pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

fn run() {
	let (N, M) = read!(usize, usize);
	let mut g = vec![vec![]; N];
	let mut deg = vec![0; N];
	for _ in 0..N+M-1 {
		let (a, b) = read!(usize, usize);
		g[a - 1].push(b - 1);
		deg[b - 1] += 1;
	}
	let mut parent = vec![!0; N];
	let mut stack = vec![];
	for i in 0..N {
		if deg[i] == 0 {
			stack.push(i);
			parent[i] = 0;
		}
	}
	while let Some(u) = stack.pop() {
		for &v in &g[u] {
			deg[v] -= 1;
			if deg[v] == 0 {
				parent[v] = u + 1;
				stack.push(v);
			}
		}
	}
	for i in 0..N {
		println!("{}", parent[i]);
	}
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    string s;
    cin >> k >> s;
    cout << s.substr(0,k);
    if((int)s.size()>k) cout << "...";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
long long n, x, y;
long long a[200000];
long long b[200000];
long long  c[400000];
int main() {
	scanf("%lld", &n);
	for (long long i = 0; i < n; i++) {
		scanf("%lld", a + i);
		b[i] = a[i] - i;
		if (b[i] < 200000)c[b[i] + 200000]++;
	}
	for (long long i = 0; i < n; i++) {
		y = -b[i] - 2 * i;
		if (-200000 < y && y < 200000) {
			x += c[y + 200000];
		}
		if (b[i] < 200000)c[b[i] + 200000]--;
	}
	printf("%lld\n", x);
}

Measured memory_bytes: 7924
#include <stdio.h>
#include <cmath>

inline double volume(int a, int b, double theta) {
  if (a * std::tan(theta) >= b) {
    return a*b*b / 2.0 / std::tan(theta);
  } else {
    return a*a*b - a*a*a*std::tan(theta)/2.0;
  }
}

int main(void) {
  int a, b, x;
  scanf("%d %d %d", &a, &b, &x);
  double ng = M_PI / 2.0, ok = 0, mid = 0, midold;
  do {
    midold = mid;
    mid = (ng+ok)/2.0;
    if (volume(a, b, mid) >= x) {
      ok = mid;
    } else {
      ng = mid;
    }
  } while (mid != midold);

  printf("%.10f\n", mid * 180.0 / M_PI);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main()
{
	unsigned a, b;
	char op;
	
	while(1){
		
	scanf("%u %c %u",&a ,&op ,&b);
		if      (op == '+') printf("%d\n",a+b);
		else if (op == '-') printf("%d\n",a-b);
		else if (op == '*') printf("%d\n",a*b);
		else if (op == '/') printf("%d\n",a/b);
		else break;
	}
	return 0;
}

Measured memory_bytes: 604
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool sortbysecdesc(const pair<string,ll> &a,const pair<string,ll> &b)
{
       return a.second>b.second;
}
int main() {
	int n;cin>>n;
	vector<string>v(n);
	loop(n,i,0){
		string s;cin>>s;
		sort(allv(s));
		v[i]=s;
	}
	sort(allv(v));
	ll res=0,cnt=1;
	loop(n,i,1){
		if(v[i]==v[i-1])cnt++;
		else res+=cnt*(cnt-1)/2,cnt=1;
	}
	res+=cnt*(cnt-1)/2;
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s, t;
	cin >> s >> t;

	if (s == t) {
		cout << "Yes" << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); i++) {
		string str = s;
		char temp = s[s.size() - 1];
		for (int j = 0; j < s.size() - 1; j++) {
			str[j + 1] = s[j];
		}
		str[0] = temp;

		s = str;

		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
using namespace std;
int main(){ 
  string S;
  cin >>S;
  int N=S.size();
  int key=0;
  for(int i=0;i<(N-1)/4;i++){
    if (S[i]!=S[(N-1)/2-1-i]){
      key=1;
    }
        }
        for(int i=0;i<(N-1)/2;i++){
          if(S[i]!=S[N-1-i]){
            key=1;
          }
        }
  if(key==0){
    cout <<"Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
R = [int(input()) for _ in range(N)]

p_buy = R[0]
p_sale = R[1]
buy = R[1]
sale = None
for i in range(2, N):
    if p_sale < R[i]:
        p_sale = R[i]
    if buy > R[i]:
        if sale is None:
            sale = R[i]
        if p_sale - p_buy < sale - buy:
            p_sale, p_buy = sale, buy 
        sale, buy = None, R[i]
    else:
        if sale is None or sale < R[i]:
            sale = R[i]

p_gain = p_sale - p_buy
print(p_gain if sale is None else max(p_gain, sale - buy))

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

int main() {
	int n;
    cin >> n;
    switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    default:
        break;
    }
}

Measured memory_bytes: 3600
S = input()
Q = int(input())
bs = ''
fs = ''
hanten = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        hanten += 1
    else:
        if query[1] == '1':
            if hanten % 2 == 0:
                fs += query[2]
            else:
                bs += query[2]
        else:
            if hanten % 2 == 0:
                bs += query[2]
            else:
                fs += query[2]
if hanten % 2 == 0:
    print(fs[::-1]+S+bs)
else:
    print(bs[::-1]+S[::-1]+fs)

Measured memory_bytes: 178412
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int n,x,ans=1e9;
int main(){
cin>>n>>x;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]=abs(a[i]-x);
ans=min(a[i],ans);//D 最大只能是起点到城市的最近距离
}
for(int i=1;i<=n;i++)
ans=__gcd(ans,a[i]);//__gcd() 前面是两条短横线
cout<<ans;
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

template<class V> class segtree {
private:
    int n;
    vector<V> node, lazy;
    vector<bool> lazyFlag;

public:
    segtree(vector<V> v) {
        int sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1,false);
        rep(i,sz){
            node[i+n-1] = v[i];
        }
    }
    void eval(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }
    void range(int a, int b, V x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            eval(k, l, r);
        }
        else {
            range(a, b, x, 2*k+1, l, (l+r)/2);
            range(a, b, x, 2*k+2, (l+r)/2, r);
        }
    }
    V find(int a, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(r - l == 1){
            return node[k];
        }
        if(a < (l+r)/2){
            return find(a, 2*k+1, l, (l+r)/2);
        }else{
            return find(a, 2*k+2, (l+r)/2, r);
        }
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    segtree<int> sg(vector<int>(n,INT_MAX));
    rep(i,q){
        int k;
        cin >> k;
        if(k){
            int x;
            cin >> x;
            cout << sg.find(x) << "\n";
        }else{
            int x,y,z;
            cin >> x >> y >> z;
            sg.range(x,y+1,z);
        }
    }
}

Measured memory_bytes: 5164
#include <iostream>
using namespace std;
#define MAX 1000000

int main()
{
	int n;
	int a[MAX];
	int counter;
	
	a[0] = 0;
	a[1] = 0;
	for (int i = 2; i < MAX; i++) {
		a[i] = 1;
	}
	
	int j = 2;
	while (j < MAX) {
		if (a[j] == 0) {
			j++;
		} else {
			for (int k = j *2; k < MAX; k += j)
				a[k] = 0;
			j++;
		}
	}
	
	while (cin >> n) {
		counter = 0;
		for (int i = 2; i <= n; i++)
			if (a[i])
				counter++;
		cout << counter << "\n";
	}
		
	return 0;
}

Measured memory_bytes: 5064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }

int main() {
	while (true) {
		int n;
		long long dp[31] = { 0 };
		cin >> n;
		if (n == 0) return 0;
		dp[0] = 1;
		for (int i = 1; i <= n; i++) {
			dp[i] += dp[i - 1];
			if (i - 2>=0) dp[i] += dp[i - 2];
			if (i - 3>=0) dp[i] += dp[i - 3];
		}
		cout << (dp[n] / 3650) + 1 << endl;
	}
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    map<ll, int> list;
    rep(i, 18){
        int dig = i + 1;
        rep(j, 1 << dig){
            string s = "";
            for (int k = dig - 1; k >= 0; k--) {
                if (1 & j >> k) {
                    s += "8";
                }
                else s += "2";
            }
            list[stoll(s)] = 1;
        }
    }
    
    ll N;
    cin >> N;
    map<ll, int> nums; // num, times
    nums[N] = 0;
    for (pair<ll, int> good : list) {
        ll god = good.first;
        if (god * god > N) {
            break;
        }
        for (pair<ll, int> num : nums) {
            ll now = god;
            for (int time = 1; num.first % now == 0; now *= god, time++) {
                nums[num.first / now] = max(nums[num.first / now], nums[num.first] + time);
            }
        }
        
    }
    
    for(pair<ll, int> num : nums){
        if (list[num.first] == 1 && num.first != 1) {
            nums[1] = max(nums[1], num.second + 1);
        }
    }
    
    
    output((nums[1] == 0) ? -1 : nums[1], 0);
    
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	ll n;

	cin >> n;

	ll now = 111;

	while (true) {
		if (n <= now) {
			cout << now << endl;
			break;
		}

		now += 111;
	}
}

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

int main() {
  string A,B;
  cin >> A >> B;
  if (A.at(0) == B.at(2) &&
      A.at(1) == B.at(1) &&
      A.at(2) == B.at(0) )
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}


Measured memory_bytes: 3632
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();
        PriorityQueue<Integer> q = new PriorityQueue<Integer>( );
        
        q.add(P);
        q.add(Q);
        q.add(R);
        System.out.println(q.poll()+q.poll());
        
    }
}


Measured memory_bytes: 21972
#include <iostream>
using namespace std;
int main() {
int N,D,X,P[110],sum;
sum=0;
cin>>N>>D>>X;
for(int i=1;i<=N;i++){
cin>>P[i];
for(int a=1;a<=D;a+=P[i]){sum++;}
}
cout<<X+sum<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=305,MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}

int n,m,P;
char s[MAXN];
int a[MAXN],f[MAXN][MAXN][MAXN],p[MAXN][MAXN][MAXN],q[MAXN][MAXN][MAXN];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	scanf("%s",s+1);readint(P);
	n=strlen(s+1);
	m=1;
	for(int i=1;i<=n;++i)
		if(s[i]=='0')++m;
		else ++a[m];
	f[0][0][0]=1;
	for(int j=0;j<=n;++j)p[0][j][0]=q[0][j][j]=1;
	for(int i=1;i<=m;++i)
		for(int j=0;j<=n;++j)
			for(int k=0;k<=n;++k)
			{
				f[i][j][k]=dmy(dmy(p[i-1][min(n,j+a[i])][k]-p[i-1][j][k]+MOD)+q[i-1][j][k]);
				if(j)p[i][j][k]=dmy(p[i][j-1][k]+f[i][j][k]);
				else p[i][j][k]=f[i][j][k];
				if(j && k)q[i][j][k]=dmy(q[i][j-1][k-1]+f[i][j][k]);
				else q[i][j][k]=f[i][j][k];
			}
	int ans=0;
	for(int k=0;k<=n && k<=P;++k)
		ans=dmy(ans+f[m][0][k]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 329700
#include <stdio.h>
#include <stdlib.h>

int main() {
	int h, w;
	scanf("%d %d", &h, &w);
	while (1) {
		if (h == 0 && w == 0) break;
		for (int j = 0; j < h; j++) {
			for (int i = 0; i < w; i++) {
				if (j % 2 == 0) {
					if (i % 2 == 0) {
						printf("#");
					}
					else {
						printf(".");
					}
				}
				else {
					if (i % 2 == 0) {
						printf(".");
					}
					else {
						printf("#");
					}
				}
				
				
				if (i == w - 1) printf("\n");
			}
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}


	return 0;

}


Measured memory_bytes: 2064
N,A,B = map(int,input().split())
#N,A,B = 20,2,5

def sum_digit(n):
	sum = 0
	while n > 0:
		sum += n % 10
		n = n // 10
	return sum

if __name__ == '__main__':
	ans = 0
	for n in range(1,N+1):
		sum = sum_digit(n)
		if sum >= A and sum <= B:
			ans = ans + n

	print(ans)

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


int mem[100005][4];

struct activity{
	int swim;
	int bugs;
	int homework;
};

vector<activity> v;

int dp(int i,int a)
{
	if(i == 0)
	{
		if(a==1)
		return v[i].swim;
		else if(a==2)
		return v[i].bugs;
		else if(a==3)
		return v[i].homework; 
	}
	if(mem[i][a]!=-1)
	return mem[i][a];
	int ans=0;
	if(a==1)
	{
		ans= max(v[i].swim+dp(i-1,3),v[i].swim+dp(i-1,2));
	}
	else if(a==2)
	{
		ans= max(v[i].bugs+dp(i-1,1),v[i].bugs+dp(i-1,3));
	}
	else if(a==3)
	{
		ans= max(v[i].homework+dp(i-1,1),v[i].homework+dp(i-1,2));
	}
	mem[i][a]=ans;
	return ans;
}

int main()
{
	int n;
	cin>>n;
	memset(mem,-1,sizeof(mem));
	for(int i=0;i<n;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		activity a;
		a.swim = x;
		a.bugs = y;
		a.homework = z;
		v.push_back(a);
	}
	cout<<max(dp(n-1,1),max(dp(n-1,2),dp(n-1,3)));
	return 0;
}

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

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

const int INF = 1001001001;

vector<int> to[2505];
vector<int> rto[2505];
int reachableFrom1[2505];
int reachableFromN[2505];
int ok[2505];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int u: to[v]) {
        dfs(u);
    }
}

void r_dfs(int v) {
    if (reachableFromN[v]) return;
    reachableFromN[v] = true;
    for (int u: rto[v]) {
        r_dfs(u);
    }
}

int main(void) {
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        c -= p;
        c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    r_dfs(n - 1);
    rep(i, n) ok[i] = reachableFrom1[i] & reachableFromN[i];
    { // bellman-ford
        vector<int> d(n, INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            rep(i, m) {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;
                int newD = d[a] + c;
                if (newD < d[b]) {
                    upd = true;
                    d[b] = newD;
                }
            }
            step++;
            if (step > n) {
                puts("-1");
                return 0;
            }
        }

        int ans = -d[n - 1];
        ans = max(ans, 0);
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
int a,b,c,k;
  cin>>a>>b>>c>>k;

  int n=max((a, b), c);
  int m=max((a, b), c);
  
  for(int i=1; i<=k; i++){
   m*=2;}
  
  cout<<m+a+b+c-n<<endl;
}

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


static const int MAX = 1405;
int G[MAX][MAX], T[MAX][MAX];

struct Rectangle
{
	int height, pos;
};

int getLargestRectangle(int W, int buffer[]) {
 	stack<Rectangle> s;
 	int maxRect = 0;
 	buffer[W] = 0;

 	for( int i = 0; i <= W; i++) {
        Rectangle rect;
        rect.height = buffer[i];
        rect.pos = i;

        if( s.empty() || s.top().height < rect.height ) {
        	s.push( rect );
        } else  if ( s.top().height > rect.height) {
        		int target = i;
        		while( !s.empty() && s.top().height > rect.height ) {
        		Rectangle pre = s.top(); s.pop();
        		int area = pre.height * ( i - pre.pos );
        		maxRect = max(maxRect, area);
        		target = pre.pos;
        	   }
        	   rect.pos = target;
        	   s.push(rect);
        	}
 
 	}

 	return maxRect;
}
int getLargestRectangle( int H, int W ) {
	for( int i = 0; i < H; i++) {
		for( int j = 0; j < W; j++ ) {
			if ( G[i][j] ) T[i][j] = 0;
			else {
				T[i][j] = ( i > 0 ) ? T[i - 1][j] + 1 : 1;
			}
		}
	}

    int maxRect = 0;
    for ( int i = 0; i < H; i++) {
    	maxRect = max( maxRect, getLargestRectangle(W, T[i]));
    }

    return maxRect;
}
int main() {
	int H, W;

	cin >> H >> W;
	for( int i = 0; i < H; i++ )
		for( int j =0; j < W; j++ ) cin >> G[i][j];

	cout << getLargestRectangle( H, W ) << endl;

}



Measured memory_bytes: 18428
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a[3];
	for (int i = 0; i < 3; i++) cin >> a[i];
	sort(a, a + 3);
	cout << a[2] * 10 + a[1] + a[0] << endl;
}

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

using namespace std;

const int N = 207;
const int oo = 1e9 + 7;

int n, m, c[N][N], f[N][N], t;
int S, T, res, d[N], vis[N];
char ch;
vector <int> adj[N];

inline void AddEdge(int u, int v, int cap){
    adj[u].push_back(v);
    adj[v].push_back(u);
    c[u][v] = c[v][u] = cap;
}

bool bfs(){
    queue <int> q;
    memset(d, 0, sizeof(d));
    d[S] = 1;
    q.push(S);
    while (q.size()){
        int u = q.front();
        q.pop();
        if (u == T) return true;
        for (auto v: adj[u]){
            if (!d[v] && f[u][v] < c[u][v]){
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
    return false;
}

int dfs(int u, int mn){
    if (u == T) return mn;
    if (vis[u] != t) vis[u] = t;
    else
        return 0;
    for (auto v: adj[u]){
        if (f[u][v] < c[u][v])
            if (vis[v] != t && d[v] == d[u] + 1)
            if (int x = dfs(v, min(mn, c[u][v] - f[u][v]))){
                f[u][v] += x;
                f[v][u] -= x;
                return x;
            }
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    cin >> n >> m;
    S = 0; T = m + n + 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            cin >> ch;
            if (ch == 'S'){
                AddEdge(S, i, oo);
                AddEdge(S, j + n, oo);
            }
            if (ch == 'T'){
                AddEdge(T, i, oo);
                AddEdge(T, j + n, oo);
            }
            if (ch == 'o'){
                AddEdge(i, j + n, 1);
            }
        }
    while (bfs()){
        if (int x = (t++, dfs(S, oo)))
            res += x;
    }
    if (res >= oo){
        cout << -1;
        return 0;
    }
    cout << res;
}


Measured memory_bytes: 768
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int h,w;
   cin >> h >> w;
   string c;

   rep(i,h){
   cin >> c;
   cout << c << endl;
   cout << c << endl;
   }





   return 0;
}

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

int main(void){
  int a[10]={0};
  int ans;
  
  for (int i=0; i<3; i++){
    int t; cin >> t;
    a[t]++;
  }
  ans = 0;
  for (int i=1; i<=9; i++){
    if (a[i]==2) ans = 1;
  }
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define number 4
int main(){
	char s[number];
	int flag = 0,i;

	scanf("%s",s);

	for(i=0;i<number-1;i++){
		if(s[i] == s[i+1]){
			flag = 1;
			break;
		}
	}

	if(flag == 0)
		cout << "Good" << endl;
	else
		cout << "Bad" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

        // input
        int height = scan.nextInt();
        int width = scan.nextInt();
        int y = scan.nextInt();
        int x = scan.nextInt();

        // answer
        System.out.println((height - y) * (width - x));

    }
}

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

	public static void main(String[] args) {
		//スキャナ変数の初期化
		Scanner sc = new Scanner(System.in);
		//支払金額を入力から受け取る
		int N = sc.nextInt();
		//1円硬貨の枚数を入力から受け取る
		int A = sc.nextInt();

		//支払金額を500で割った余りを表示
		int C = (N % 500);
		
		//余りがA以下Yes,それ以外はNoを表示する
		if (C <= A ) {
			System.out.print("Yes") ;
		} else  {
			System.out.println("No");
		}

		//scanner閉じ
		 sc.close();
	}

}


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

int main() {
  vector<int> num(3);
  rep(i,3) {
    cin >> num.at(i);
  }
  sort(num.begin(), num.end());
  int A = num.at(0);
  int B = num.at(1);
  int C = num.at(2);
  int AB = B - A;
  int BC = C - B;
  int answer = 0;
  if ( AB % 2 == 0 ) {
    answer = AB / 2 + BC;
  }
  else {
    answer = (AB+1)/2 + BC + 1;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << Yes[s[0] == '9' || s[1] == '9'];
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()

# 最初のN以外は、平行四辺形を小さくしていくと考える
def rec(a, b):
    a, b = min(a, b), max(a, b)
    if a == 0:
        # 最後に割り切れた時は半分でいいので減らす
        return -b
    # 同じだけ小さくする所はまとめてやる
    return a*2*(b//a) + rec(a, b%a)

print(N+rec(X, N-X))


Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int sum = 0;
    for(int i = 0; i < str.length(); i++){
      //System.out.println(str.charAt(i));
      sum += Character.getNumericValue(str.charAt(i));
      //System.out.println(sum);
    }
      //System.out.println(sum);
    
    if (sum==0 || sum%9==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 40328
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int K = 60;
int low[K], high[K];
int dp[K][2][2][2][2];
int highest;

void add(int& x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}

int solve(int pos, bool one, bool tight, bool tight_low, bool tight_high) {
  if (pos < 0) {
    return 1;
  }
  // trace(pos, low[pos], high[pos], tight_low, tight_high);
  int& ret = dp[pos][one][tight][tight_low][tight_high];
  if (ret >= 0) return ret;
  ret = 0;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      if (tight_high && i > high[pos]) continue;
      if (tight_low && j < low[pos]) continue;
      if (!one && i != j) continue;
      if (i < j) continue;
      bool nxt_tight_low = tight_low && j == low[pos];
      bool nxt_tight_high = tight_high && i == high[pos];
      bool nxt_tight = tight && i == j;
      bool nxt_one = one || (i == 1 && j == 1);
      add(ret, solve(pos - 1, nxt_one, nxt_tight, nxt_tight_low,
                     nxt_tight_high));
    }
  }
  return ret;
}

int main() {
  int64 L, R;
  cin >> L >> R;
  highest = -1;
  for (int k = 0; k < K; ++k) {
    low[k] = L % 2;
    high[k] = R % 2;
    L >>= 1;
    R >>= 1;
    if (high[k]) highest = k;
  }
  // for (int k = 0; k <= highest; ++k) {
  //   trace(k, low[k], high[k]);
  // }

  memset(dp, 255, sizeof(dp));
  int ret = solve(highest, 0, 1, 1, 1);
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [k, t] <- getIntList
  as <- do ts <- getIntList
           V.thaw $ V.fromList ts

  let lookupCands i c1 m1 c2 m2 | i == t = return (c1, c2)
                                | otherwise = do
                                    n <- VM.read as i
                                    if n > m1
                                      then lookupCands (i+1) i n c1 m1
                                      else if n > m2
                                           then lookupCands (i+1) c1 m1 i n
                                           else lookupCands (i+1) c1 m1 c2 m2

  v <- VM.new (k+1)
  VM.write v 0 t
  forM_ [1..k] $ \i -> do
    t0 <- VM.read v 0
    (c1, c2) <- lookupCands 0 (-1) 0 (-1) 0
    if c1 /= t0 || c2 < 0
      then do n <- VM.read as c1
              VM.write as c1 (n-1)
              VM.write v i c1
              VM.write v 0 c1
      else do n <- VM.read as c2
              VM.write as c2 (n-1)
              VM.write v i c2
              VM.write v 0 c2

  v' <- V.freeze v

  let countAns (x:y:zs) res = countAns (y:zs) (res + (if x==y then 1 else 0))
      countAns _        res = res

  print $ countAns (tail $ V.toList v') 0

Measured memory_bytes: 1148
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            double min = 100000000000;
            double power = 0;
            for (var i = 1; i <= 100; i++)
            {
                power = 0;
                var p = i;
                for (var j = 0; j < n; j++)
                {
                    power += Math.Pow((inputLongArray[j] - p), 2);
                }
                if (min > power) min = power;
            }
            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 28340
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


vector<vector<int>> enuCmb(int n, int k) {
    vector<vector<int>> res;
    if (n==0 || k==0 || n<k) {
      	return res;
    } else { 
		res=enuCmb(n-1,k);
		vector<vector<int>> res1=enuCmb(n-1,k-1);
		rep(i,res1.size()) {
			res1[i].push_back(n-1);
			res.push_back(res1[i]);
		}
		if (k==1) {
			vector<int> ins={n-1};
			res.push_back(ins);
		}
		return res;
    }
}

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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    string t="MARCH";
    vector<ll> a(5);
    rep(i,n) {
        rep(j,5) {
            if (s[i][0]==t[j]) ++a[j];
        }
    } 
    ll ans=0;
    vector<vector<int>> enu=enuCmb(5,3);
	rep(i,enu.size()) {
        ll tans=1;
		rep(j,3) tans*=a[enu[i][j]];
        ans+=tans;
	}
    cout << ans << endl;
    
    return 0;   
}

Measured memory_bytes: 6336