akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int Q;
long long A, B;
long long ans;





void solve2() {
	long long AB = A * B;
	long long AB_sqr = sqrt(AB);
	if ((A * B) == AB_sqr*AB_sqr) AB_sqr--;
	long long tmp;

	if (A == B) tmp = 0;
	else if (AB_sqr * (AB_sqr + 1) >= AB) tmp = 2;
	else tmp = 1;

	ans = AB_sqr * 2 - tmp;
}

void solve() {
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A >> B;
		solve2();
		cout << ans << endl;
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
pos = list(map(int, input().split()))
max_distance = 0
for i in range(n-1):
    max_distance = max(max_distance, pos[i+1]-pos[i])
max_distance = max(max_distance, k-pos[-1]+pos[0])
print(k-max_distance)

Measured memory_bytes: 26436
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

ll a[51], p[51];

ll dfs(ll n, ll x){
    if(n==0) return 1LL;
    if(x==1) return 0LL;

    if(x>=2 && x<=a[n-1]+1)return dfs(n-1, x-1);
    else if(x==a[n-1]+2)return p[n-1]+1;
    else if(x>=a[n-1]+3 && x<=2*a[n-1]+2)return dfs(n-1, x-a[n-1]-2)+p[n-1]+1;
    else if(x==2*a[n-1]+3)return p[n];
}

int main() {
    ll N, X; cin>>N>>X;
    
    a[0]=1, p[0]=1;
    for (int i = 0; i < 50; i++) {
        a[i+1]=2*a[i]+3;
        p[i+1]=2*p[i]+1;
    }

    cout<<dfs(N, X)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
long long p[1001][1001],h[1001],w[1001];
int main(){
long long i,j,n,m;
cin>>n>>m;
for(i=0;i<n;i++)cin>>h[i];
for(i=0;i<m;i++)cin>>w[i];
memset(p,0x7f,sizeof(p));
p[0][0]=0;
for(i=0;i<=n;i++){
for(j=0;j<m;j++){
p[i+1][j+1]=min(p[i+1][j+1],p[i][j]+(h[i]*w[j]));
p[i][j+1]=min(p[i][j+1],p[i][j]);
}
}
cout<<p[n][m]<<endl;
return 0;
}

Measured memory_bytes: 10924
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int memo[555][555],d[555][555];
bool done[555][555];

int dp(int l, int r){
	if(done[l][r]){
		return memo[l][r];
	}
	done[l][r] = true;
	if(l && r){
		memo[l][r] = d[l][r]+dp(l-1,r)+dp(l,r-1)-dp(l-1,r-1);
	}else if(l){
		memo[l][r] = d[l][r]+dp(l-1,r);
	}else if(r){
		memo[l][r] = d[l][r]+dp(l,r-1);
	}else{
		memo[l][r] = d[l][r];
	}
	return memo[l][r];
}

int main(void){
	int n,m,q,i,l,r;
	fill(d[0],d[555],0);
	fill(done[0],done[555],false);
	cin >> n >> m >> q;
	for(i=0; i<m; ++i){
		cin >> l >> r;
		++d[n-l][r-1];
	}
	for(i=0; i<q; ++i){
		cin >> l >> r;
		cout << (dp(n-l,r-1)) << endl;
	}
	return 0;
}


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

using namespace std;

// 答え, 頂点数, 辺の本数, 始点の配列, 終点の配列, 訪れた頂点数
int ans, N, M, a[28], b[28], num_visted;
// 隣接リスト
vector< vector<int> > G;
// 訪問済み頂点
vector<bool> visted;

// 深さ優先探索
void dfs(int now){
	visted[now] = true;
	num_visted++;
	if(num_visted == N) ans++;
	for(int i = 0; i < G[now].size(); ++i){
		if(!visted[G[now][i]]) dfs(G[now][i]);
	}
	visted[now] = false;
	num_visted--;
}

int main(){
	// 入力
	cin >> N >> M;
	for(int i = 0; i < M; ++i) cin >> a[i] >> b[i];
	// 訪問済み頂点の初期化
	visted = vector<bool>(N, false);
	// 入力から隣接リストに変換
	G = vector< vector<int> >(N);
	for(int i = 0; i < M; ++i){
		G[a[i]-1].push_back(b[i]-1);
		G[b[i]-1].push_back(a[i]-1);
	}
	// 再帰
	dfs(0);
	// 答えを出力
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main(){

 ll a,b,sum1=0  ,sum2=0  ;
 cin >> a ;
 for(int i=0 ;i<a;i++)
 {
     cin >> b ;
     if(b%2==0)
    {sum1++ ;
       if(b%3==0||b%5==0){sum2++ ;} }

 }
 if(sum1==sum2) {cout<< "APPROVED" <<endl;}
 else {cout << "DENIED" <<endl ;}
    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int h1, m1, h2, m2, k;
	int h=0;

	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

	m1 = (60 - m1) % 60;
	h = m1+m2;

	if (m1 > 0)
		h1++;

	h += (h2 - h1) * 60;

	h -= k;

	printf("%d\n", h);

	return 0;
}

Measured memory_bytes: 1736
def x(a):
	m=-10**9
	for c in N:
		p=[0]*n 
		for e in range(c,n):
			for r in N:
				p[r]+=a[r][e]
			m=max(P(p),m)
	return m

def P(a):
	m,c=-100000,0
	for i in N:
		c+=a[i]
		m=max(c,m)
		if c<0:c=0
	return m

n = input()
N = range(n)
print x([map(int, raw_input().split()) for i in N])

Measured memory_bytes: 4560
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	string s,t;
	cin>>s>>t;
	if(s.size() != t.size()-1)
	{
		cout<<"No"<<endl;return 0;
	}
	for(int i = 0;i<s.size();i++)
	{
		if(s[i] != t[i])
		{
			cout<<"No"<<endl;return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(void){
char str1[4001],str2[4001];
 int i,j,count,len1,len2;
static short dp[4002][4002];

  while(~scanf("%[^\n]%*c",str1)){
    scanf("%[^\n]%*c",str2);

    memset(dp,0,sizeof(dp));

    count=0;
    len1=strlen(str1);
    len2=strlen(str2);
    for(i=0;i<len1;i++){
      for(j=0;j<len2;j++){
	if(str1[i]==str2[j]){
	  dp[i+1][j+1]=dp[i][j]+1;
	  count=count>dp[i+1][j+1]?count:dp[i+1][j+1];
	}
	else dp[i+1][j+1]=0;
	
      }
    }
    printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 0
A = int(input()) #500円玉
B = int(input()) #100円玉
C = int(input()) #50円玉
X = int(input()) #この値にする合計を求める

count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            total = 500 * a + 100 * b + 50 * c
            if total == X:
                count += 1
print(count)


Measured memory_bytes: 9160
/*
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque

#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GL_ getline
#define NL_   "\n"
#define SP_ " "

#define fr(i, n) for(i = 0; i < n; i++)
#define fe(x, n) for(i = x; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000
vi v;


ll N, T, tc = 0, i, j, k;
ul step(ul n)
{
    if(n< 6)
        return n;
    ul cnt= 6;
    while(cnt <= n)
        cnt*=6;
    cnt /= 6;
    ul st1 = 1+step(n - cnt);
    ul st2;
    if(n < 9)
        st2 = n;
    else
    {
        cnt= 9;
        while(cnt <= n)
            cnt*=9;
        cnt /= 9;
        st2 = 1+step(n - cnt);
    }
    return min(st1, st2);
}

int main()
{
  ul n;
  cin >> n;
  cout << step(n);
  return 0;

}


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

using namespace std;

vector<vector<int> > graph(20);
int bridges[20][20];
bool used[20][20];

int calc_sum(int from)
{
	int sum = 0;

	for (int i = 0; i < graph[from].size(); ++i) {
		int to = graph[from][i];
		if (graph[to].size() == 1) continue;
		if (used[from][to]) continue;
		used[to][from] = true;
		sum += bridges[from][to] * 2 + calc_sum(to);
	}

	return sum;
}

int calc_max(int from)
{
	int ma = 0;

	for (int i = 0; i < graph[from].size(); ++i) {
		int to = graph[from][i];
		if (graph[to].size() == 1) continue;
		if (used[from][to]) continue;
		used[to][from] = true;
		ma = max(ma, bridges[from][to] + calc_max(to));
	}

	return ma;
}

int main()
{
	int n;
	while (cin >> n, n) {
		memset(bridges, 0, sizeof(bridges));
		for (int i = 0; i < 20; ++i) graph[i].clear();
		for (int i = 0; i < n - 1; ++i) {
			int a, b, t; cin >> a >> b >> t;
			a--; b--;
			bridges[a][b] = bridges[b][a] = t;
			graph[a].push_back(b); graph[b].push_back(a);
		}

		memset(used, 0, sizeof(used));
		int sum = calc_sum(0);
		memset(used, 0, sizeof(used));
		int ma = calc_max(0);

		cout << sum - ma << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

string s;
int n;
signed main() {

    cin >> n >> s;
    vector<int> a(s.size()+5), b(s.size()+5);

    for(int i = 1; i <= n; i++) {
        a[i] = a[i-1];
        if(s[i-1]=='(')
            a[i]++;
        else
            a[i] = max(0, a[i-1]-1);
        
    }

    for(int i = n; i > 0; i--) {
        b[i] = b[i+1];
        if(s[i-1] == ')')
            b[i]++;
        else
            b[i] = max(0, b[i]-1);
    }

    for(int i = 0; i < b[1]; i++) cout << '(';
    cout << s ;
    for(int i = 0; i < a[n]; i++) cout << ')';
    cout << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        ArrayList<Character> w = new ArrayList<Character>();
        for(int i = 0; i < line.length(); i++) {
            w.add(line.charAt(i));
        }
        char c = '0';
        boolean b = true;
        for(int i = 1; i < line.length(); i++) {
            c = w.get(0);
            w.remove(0);
            if(w.indexOf(c) != -1){
                b = false;
            }
        }
        if(b) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }
}

Measured memory_bytes: 21844
fn main() {
    let (a, b, c) = read_tuple::<i32>();
    if (a == b && b != c) || (b == c && c != a) || (c == a && a != b) {
        println!("Yes");
    } else {
        println!("No");
    }
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T, T) {
    let temp = read_vec();
    (temp[0], temp[1], temp[2])
}



Measured memory_bytes: 4352
n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B = []
    for i in range(n):
        if ANS[i] != 0:
            B.append(str (i+1))
        else:
            pass
    B =" ".join(B)
    print(B)


Measured memory_bytes: 16184
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
import bisect
import sys
import logging
import heapq

#logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()[:-1]
	t = input()[:-1]
	for i in reversed(range(len(s) - len(t) + 1)):
		flag = True
		for j in range(len(t)):
			if(s[i+j]  != '?' and s[i+j] != t[j]):
				flag = False
				break
		if flag:
			ans = []
			for j in s:
				ans.append(j)
			for j in range(i, i+len(t)):
				ans[j] = t[j-i]
			a = ''
			for i in ans:
				a += i
			print(a.replace('?','a'))
			return
	print('UNRESTORABLE')


def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()


Measured memory_bytes: 67820
a,b,c,d=input()

pm=['-','+']

def calc():
    for i in pm :
        for j in pm:
            for k in pm:
                s=a+i+b+j+c+k+d
                total=eval(s)
                if total==7:
                    return s+'='+str(total)

print(calc())


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

int fact(int n) {
    if (n == 0) return 1;
    return n * fact(n - 1);
}

int main() {
    int N;  cin >> N;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];

    vector<vector<double>> d(N, vector<double>(N));
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            d[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }

    vector<int> perm;
    for (int i = 0; i < N; ++i) perm.push_back(i);
    double ans = 0;
    do {
        for (int i = 0; i < N - 1; ++i) {
            int p1 = min(perm[i], perm[i + 1]);
            int p2 = max(perm[i], perm[i + 1]);
            ans += d[p1][p2];
        }
    } while (next_permutation(perm.begin(), perm.end()));

    cout << fixed << setprecision(6) << ans / fact(N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int a , b , c;
  	cin >> a >> b >> c;
  	cout << min( b / a, c);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
n = input()
maxVal = 1
current = 1
for i in range(3):
    if n[i] == n[i+1]:
        current = current + 1
        maxVal = max(maxVal, current)
    else:
        current = 1
if maxVal >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char ch[1000];
int main( ) {
	scanf( "%s", ch );
	int len = strlen(ch);
	for( register int i = 0; i < len - 8; i++ ) printf( "%c", ch[i] );
	return 0;
}

Measured memory_bytes: 256
// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

// END tpl.

inline char *read_str(char *s)
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	for(; isgraph(ch); ch = getc()) *s++ = ch;
	*s = '\0';
	return s;
}

const int MOD = 998244353;

const int MAXN = 100;

string s;

inline void input()
{
	static char S[MAXN + 5];
	read_str(S), s = string(S);
}

unordered_map<string, int> f, g;

inline int F(string S);
inline int G(string S);

inline int G(string S)
{
	int N = SZ(S);
	if(N == 1) return S[0] == '1' ? 2 : 1;
	if(g.count(S)) return g[S];

	int res = 0;
	for(int k = 1; k < N; ++k) if(N % k == 0)
	{
		string T = S.substr(0, k);
		for(int i = k; i < N; i += k)
			for(int j = 0; j < k; ++j) T[j] = ((T[j] - '0') & (S[i + j] - '0'))+ '0';
		(res += F(T)) %= MOD;
	}
	return g[S] = res;
}

inline int F(string S)
{
	int N = SZ(S);
	if(N == 1) return S[0] == '1' ? 2 : 1;
	if(f.count(S)) return f[S];

	int res = 0;
	for(int i = 0; i < N; ++i) (res += (LL) F(S.substr(0, i)) * G(S.substr(i)) % MOD) %= MOD;
	for(int k = 1; k < N; ++k) if(N % k == 0)
	{
		string T = S.substr(0, k);
		for(int i = k; i < N; i += k)
			for(int j = 0; j < k; ++j) T[j] = ((T[j] - '0') & (S[i + j] - '0'))+ '0';
		(res += F(T)) %= MOD;
	}
	return f[S] = res;
}

inline void solve()
{
	printf("%d\n", (F(s) + MOD) % MOD);
}

int main()
{
#ifdef K_ON
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 12184
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

ll exp(ll);

int main() {

	ll x; cin >> x;

	rep(i, -118, 120) {
		rep(j, -118, 120) {
			if (i*i*i*i*i - j*j*j*j*j == x) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3640
# http://logfiles.hatenablog.com/entry/2018/06/30/215140

def main():
    n = int(input())
    *a, = map(int, input().split())
    *b, = map(int, input().split())

    cnt = sum(b) - sum(a)

    if cnt < 0:
        print('No')
        return

    elif cnt == 0:
        print('Yes' if a == b else 'No')
        return

    na = 0
    for i in range(n):
        if a[i] < b[i]:
            t = (b[i] - a[i] + 1) // 2
            a[i] += t * 2
            na += t

    nb = 0
    for i in range(n):
        if a[i] > b[i]:
            t = a[i] - b[i]
            b[i] += t
            nb += t

    print('Yes' if na >= nb else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
def solve(n):

  if n <= 6:
    print(1)
    return

  if n <= 11:
    print(2)
    return

  d = n//11
  if n % 11 == 0:
    print(d*2)
    return

  roku = n - (d*11)
  add = 2 if roku - 6 > 0 else 1
  print((d * 2)+add)

   
n = int(input())
solve(n)


Measured memory_bytes: 38448
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b;
	cin>>a>>b;
	int t=0;
	if(a<=3)t+=4-a;
	if(b<=3)t+=4-b;
	if(a==1&&b==1)t+=4;
	cout<<t*100000<<endl;
}












Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int A, B, C; scanf("%d%d%d", &A, &B, &C);
	printf("%d", max(0,C - (A-B)));

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	cin >> s;
	Yes(s[0]=='7' || s[1]=='7' || s[2]=='7');
	return 0;
}


Measured memory_bytes: 3596
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [-1 for _ in range(S+1)]
visited = [0]
dp[0] = 1
dp = tuple(dp)
for k in range(N):
  a = A[k]
  nextdp = list(dp)
  nextvisit = []
  for item in visited:
    #process1 追加する
    if item + a <= S:
      if nextdp[item+a] == -1:
        nextvisit.append(item+a)
        nextdp[item+a] = 0
      nextdp[item+a] += dp[item]
      nextdp[item+a] %= mod
    #process2 追加しない
    nextdp[item] += dp[item]
    nextdp[item] %= mod
  dp = tuple(nextdp)
  visited.extend(nextvisit)

print(max(dp[-1], 0))


Measured memory_bytes: 103360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
const int mod = 1e9 + 7;
// const int mod=998244353;
//const int mod=1e9+9;
//const int INF=4e18+10;
const int INF = 4e18 + 10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) \
int n;      \
cin >> n;
#define readv(x, n)   \
vector<int> x(n); \
for (auto &i : x) \
    cin >> i;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template <typename T1, typename T2>
void set_min(T1 &a, T2 b)
{
    a = min(a, (T1)b);
}

int multiply(int a, int b, int in_mod) { return (a * b) % in_mod; }
int mult_identity(int a) { return 1; }


auto power(auto a, int b, int in_mod)
{
    auto prod = mult_identity(a);
    auto mult = a % in_mod;
    while (b != 0)
    {
        if (b % 2)
        {
            prod = multiply(prod, mult, in_mod);
        }
        mult = multiply(mult, mult, in_mod);
        b /= 2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod - 2, in_mod);
}

void  solve()
{

    int x, k, d;
    cin>>x>>k>>d;

    x = abs(x);
    if(k>=(x+d-1)/d)
    {
        int moves = (x+d-1)/d;
        int left = k - moves;
        if(left%2)
        {
            cout<<x-(moves-1)*d<<endl;;
        }
        else
            cout<<abs(x-(moves)*d)<<endl;
    }
    else
    {
        cout<<min(x-k*d, x+k*d)<<endl;
    }
}



signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cerr.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin >> t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<":\n";
        //cout<<"Trip #"<<test<<": ";
        // cout<<endl;
        solve();
        // solveB();

        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
const double PI=3.14159265358979323846;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  double R;
  cin >> R;
  double res = 2 * R * PI;
  cout << res << endl;
  


  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int sum = H * W;
    sum -= H * w;
    sum -= W * h;
    sum += w * h;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fast();
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    unordered_map<int,int> mp;
    r(i,0,n)
    {
        cin>>a[i];
        b[i]=a[i];
        mp[a[i]]++;
    }
    sort(all(a));
    int y=a[n-1];
    int z=a[n-2];
    if(mp[a[n-1]]>1)
    {
        r(i,0,n)
        cout<<a[n-1]<<endl;
    }
    else
    {
        r(i,0,n)
        if(b[i]==a[n-1])
            cout<<z<<endl;
        else
            cout<<y<<endl;

    }

	return 0;
}


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

int main() {
 int N;
 /*  2+1
  3+1
  4+3
  7+4*/
cin >> N;
int64_t LL=2,LR=1,LRold;
for (size_t i = 0; i < N-1; i++)
{
  LRold=LR;
 LR=LL+LR;
 LL=LRold;
 
}


 cout << LR << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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 dp[3010][3010];
int main(){
  string s,t;
  cin >> s >> t;
  for(int i=0; i<3010; i++){
    for(int j=0; j<3010; j++){
      dp[i][j] = 0;
    }
  }
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<t.size(); j++){
      if(s[i] == t[j]){
        chmax(dp[i+1][j+1], dp[i][j]+1);
      }
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  string ans = "";
  int i=(int)s.size();
  int j=(int)t.size();
  while(i>0 && j>0){
    if(dp[i][j] == dp[i-1][j]){
      --i;
    }else if(dp[i][j] == dp[i][j-1]){
      --j;
    }else{
      ans += s[i-1];
      --i;
      --j;
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35712
#include<iostream>

using namespace std;

int main() {
	int n, a;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 == 0 || a % 5 == 0) {

			}
			else {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}

	cout << "APPROVED" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

table = [0] * 26
letters = "abcdefghijklmnopqrstuvwxyz"

text = sys.stdin.read().lower()

for a in range(0, len(text)):
    for b in range(0, 26):
        if letters[b] == text[a] or letters[b].upper() == text[a]:
            table[b] += 1

for i in range(0, len(letters)):
    print(str(letters[i]) + " : " + str(table[i]))


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

int main(void) {
    int h, w;
    cin >> h >> w;
    cout << string(w + 2, '#') << endl;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        cout << "#" + s + "#" << endl;
    }
    cout << string(w + 2, '#') << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <iostream>
using namespace std;
int main(void){
    
   int a, b, c;
   cin >> a >> b >> c;
   if(a>=c){
       cout << "0" << endl;
   }
    else if((a+b)>=c){
        cout<<(c-a)<<endl;
   }
    else{
        cout <<"NA" << endl;
    }
}



Measured memory_bytes: 3096
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll K, A, B, C;
  while (cin >> A >> B >> C >> K) {
    ll res = K % 2 == 0 ? A - B : B - A;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var count = 0
    for (i in 0 until n-2) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') count++
    }
    println(count)
}

Measured memory_bytes: 33652
#include<cstdio>
#include<string>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<math.h>
using namespace std;
#define ll long long
int n,t;
int a[105],w[105];
int p(int T)
{
    int sum1=0,sum2=0;
    for(int i=0; i<=T; i++)
    {
        sum1+=w[i];
    }
    for(int i=T+1; i<n; i++)
    {
        sum2+=w[i];
    }
    a[t++]=abs(sum1-sum2);
    if(T==n-1) return 0;
    return p(T+1);
}
int main()
{
    while(~scanf("%d",&n))
    {
        t=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&w[i]);
        }
        p(1);
        sort(a,a+t);
        printf("%d\n",a[0]);
    }
    return 0;
}


Measured memory_bytes: 256
a[2][101],n,m,i,j,c,p;main(s){for(;scanf(m="%d",&n),n;printf(m>210?"NA\n":"%d\n",m)){for(i=2;i--;)for(j=0;j-n;scanf(m,a[i]+j++));for(;++i-2;m>c?m=c:0)for(j=i,c=p=0;s=a[j][p],c<220&&s==2|n+~p;)p<n&s<2?s-1|a[j][p+1]-1?p+=2,j=1&~j,++c:++p:--p;}}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<char> prime (55556, true);
    prime[0] = prime[1] = false;
    for (long long i=2; i<= 55555; ++i)
        if (prime[i])
            if (i * i <= 55555)
                for (int j=i*i; j<=55555; j+=i)
                    prime[j] = false;
    
    int cnt = 0;
    for(int i = 2; i <= 55555; ++i){
        if(prime[i] && i % 5 == 1){
            cout << i << " ";
            cnt++;
        }
        if(cnt == n) return 0;
    }
}

Measured memory_bytes: 256
function main(arg) {
	arg = arg.split("\n")[0]

	var src = arg.split("")
	var count = 0
	for (var i  = 0; i < src.length; i++) {
		if (src[i] == "2") {
			count++
		}
	}
	console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

//=====================modint=====================
// + - * / += -= *= /= ++ -- pow <<,>>,での出力

template <int mod>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator+() const { return *this; }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt operator++() { return ModInt(*this) += 1; }
  ModInt operator--() { return ModInt(*this) -= 1; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt<1000000007>;

// ====================================================================

mint dp[100010][2];  // 頂点を白(0)/黒(1) で塗る組み合わせ
vector<int> g[100010];

void dfs(int now, int p) {  // 部分木の頂点数
  dp[now][0] = dp[now][1] = 1;
  for (auto x : g[now]) {
    if (x == p) continue;  // 親には戻らない
    dfs(x, now);
    dp[now][0] *= dp[x][0] + dp[x][1];
    dp[now][1] *= dp[x][0];
  }
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(0, -1);
  cout << dp[0][0] + dp[0][1] << endl;
}


Measured memory_bytes: 13440
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair

using namespace std;
int const N = 200001;
ll const MOD = 1000000007;

int main()
{
    ll n, k;
    cin >> n >> k;
    cout << min(abs((n % k) - k), n%k);
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


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

    ll ans = 0, b = 0;
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == 'B') b++;
        else{
            ans += b;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3688
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Main {
    public static void main(String[] args) {
        try {
			final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			final String word = input.readLine();
			int count = 0;
			boolean flag = true;
			while(flag){
			    for(final String str : input.readLine().split(" ")){
			    	if (str.equals("END_OF_TEXT")) {
			    		flag = false;
			    	} else if(str.equalsIgnoreCase(word)){
			            count++;
			        }
			    }
			}
			System.out.println(count);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}

Measured memory_bytes: 17040
import sys
A,B = map(int,input().split())
def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        # nがi（の累乗）で割り切れるかを調べる
        while n % i == 0:
            # nがiで割り切れる場合、iを素因数としてリストに追加する
            prime_factors.append(i)
            # nをiで割った商で更新しておく
            n //= i
    # nの平方根より大きい素因数が存在する場合
    if n > 1:
        prime_factors.append(n)

    return prime_factors

A = set(trial_division(A))
B = set(trial_division(B))
print(len(A & B)+1)


Measured memory_bytes: 38512
def input_data_sets
  data_sets = []
  
  while data_count = gets.strip.to_i
    return data_sets if data_count.nil? || data_count.to_i == 0
    data_sets << input_data_set(data_count)
  end
  
  data_sets
end

def input_data_set(data_count)
  data_count.times.map{ gets.strip.split.map(&:to_i) }
end

data_sets = input_data_sets
=begin
data_sets = [
  #4
  [
    [52, 96, 15, 20],
    [86, 22, 35, 45],
    [45, 78, 54, 36],
    [16, 86, 74, 55],
  ],
  #4
  [
    [52, 96, 15, 20],
    [86, 22, 35, 45],
    [45, 78, 54, 36],
    [16, 86, 74, 55],
  ],
  #0
]
=end

sum_proc = ->(data) { data <<= data.inject(&:+) }
data_sets.each do |data_set|
  puts data_set.transpose.map(&sum_proc).transpose.map(&sum_proc).map{ |data| data.map{ |d| d.to_s.rjust(5) }.join }.join("\n")
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
// other libs
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) {
  return a * b / gcd(a, b);
}

class dijkstra {
private:
  int V;
  int d[100002];
  priority_queue<P, vector<P>, greater<>> que;

public:
  dijkstra(int v, int s, vector<edge> G[]) {
    V = v;
    update(s, G);
  }

  void update(int s, vector<edge> G[]) {
    fill(d, d + V + 1, 100000000000ll);
    d[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (d[v] < p.first)
        continue;
      rep(i, G[v].size()) {
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(make_pair(d[e.to], e.to));
        }
      }
    }
  }

  int find(int e) {
    return d[e];
  }
};
template<typename T>
class Union_Find {
private:
  vector<T> t, s;

public:
  Union_Find(T max_length) {
    rep(i, max_length + 1) {
      t.push_back(i);
      s.push_back(1);
    }
  }

  void Union(T x, T y) {
    if (same(x, y))
      return;
    T tx = Find(x), ty = Find(y);
    if (s[tx] < s[ty]) {
      s[ty] += s[tx];
      t[tx] = ty;
    }
    else if (s[tx] > s[ty]) {
      s[tx] += s[ty];
      t[ty] = tx;
    }
    else if (tx > ty) {
      t[tx] = ty;
      s[ty] += s[tx];
    }
    else {
      t[ty] = tx;
      s[tx] += s[ty];
    }
  }
  T Find(T n) {
    if (t[n] == n)
      return n;
    else
      return t[n] = Find(t[n]);
  }

  bool same(T x, T y) {
    return Find(x) == Find(y);
  }

  T get_Size(size_t a) {
    return s[a];
  }
};
bool ifPrime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

set<int> prime_num_factor(int n){
  if(n<2)return set<int>();
  set<int> prime;
  prime.insert(2);
  for(int i=3;i<=n;i++){
    for(int it:prime){
      if(it*it>i){
        prime.insert(i);
        break;
      }
      if(i%it==0)break;
    }
  }
  return prime;
}
vector<int> makeDivisors(int n){
  vector<int> re;
  REP(i,1,sqrt(n)+1){
    if(n%i==0){
      re.push_back(i);
      if(i!=n/i)re.push_back(n/i);
    }
  }
  return re;
}
int modPow(int a,int n,int mod){
  int ret=1;
  while(n){
    if(n&1)ret=ret*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ret;
}
signed main(signed argc, char* argv[]) {
  int a,b;
  cin>>a>>b;
  cout<<max(a-b*2,0ll)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll mypow(ll b, ll e, ll mod) {
    if( e == 0 ) return 1;
    if( e%2 == 0 )
	return mypow(b*b%mod, e/2,mod) % mod;
    else
	return b* mypow(b*b%mod, e/2,mod) % mod;
}
 
 
int main () {
 
    ll m,n;
    cin >> m >> n;
    ll mod = 1000000007;
    ll ans = mypow(m,n,mod);
    cout << ans % mod<< endl;
    return 0;
}

Measured memory_bytes: 3084