akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	
	int N;
	cin >> N;
	vint A(N);
	vvint X(N), Y(N);

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

		for (int j = 0; j < A[i]; j++) {
			int t, s;
			cin >> t >> s;
			X[i].emplace_back(t - 1);
			Y[i].emplace_back(s);
		}
	}
	
	int ans = 0;

	 //　二進数 正直者のリスト
	for (int bits = 0; bits < (2 << N); bits++) {

		vint list(N);
		for (int i = 0; i < N; i++) {
			list[i] = (bits >> i) & 1;
		}


		//　矛盾がないかチェック
		bool end = false;

		for (int i = 0; i < N; i++) {
			
			
			if (list[i] == 1) {

				// この人の言うことは真実なはず
				for (int j = 0; j < A[i]; j++) {
					if (Y[i][j] != list[X[i][j]]) {
						end = true;
						break;
					}

					
					
				}

				if (end) {
					break;
				}


			}

			if (end) {
				break;
			}
			else if (i == N - 1) {
				int sum = 0;
				for (int i = 0; i < N; i++) {
					sum += list[i];
				}
				ans = max(ans, sum);

			}

		}


	}


	cout << ans;




}




Measured memory_bytes: 256
n = int(input())
s = list(map(int,input().split()))
t = 0
for i in range(n):
  s.append(i)

for i in range(n):
  if(s[i] == i + 1):
    t += 0
  else:
    t += 1
if(t == 0 or t == 2):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <queue>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;
#define int long long

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

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

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

const int INF = 1LL << 60;

bool f(const string& s, const string& t, int len) {
    bool ok = true;
    for (int i = 0; i < len; i++) {
        if ((s[i] == '?') || (s[i] == t[i])) {

        }
        else {
            ok = false;
        }
    }
    return ok;
}

signed main() {
    int a, b; cin >> a >> b;
    if (abs(a - b) > 1) {
        puts("0");
        return 0;
    }

    int A = 1;
    for (int i = 1; i <= a; i++) {
        A = A * i % MOD;
    }
    int B = 1;
    for (int i = 1; i <= b; i++) {
        B = B*i%MOD;
    }
    int ans;
    if (a == b) {
        // 犬から並べるか猿からならべるかで*2通り
        ans = A * B * 2 % MOD;
    }
    else {
        // 端っこは数の多い方と決まるので*1通り
        ans = A * B % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int r, g;
		r = sc.nextInt();
		g = sc.nextInt();
		sc.close();
		int ans;
		
		ans = 2 * g - r;
		System.out.println(ans);
	}

}


Measured memory_bytes: 20820
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        char[] data = S.toCharArray();
        int answer = 0;
        int x = 0;
        for (int i = 0; i < N; i++) {
            if (data[i] == 'I') {
                x += 1;
            } else {
                x -= 1;
            }
            answer = Math.max(answer, x);
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21716
N = int(input())
A = [int(input()) for _ in range(N)]
dic = {}
for x in A:
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
ans = 0
for x in dic.values():
    if x%2 == 1:
        ans += 1
print(ans)

Measured memory_bytes: 16268
n,a=map(int,input().split())
lists=list(map(int,input().split()))

for i in range(n):
    lists[i]-=a
answer=0
dp=[[0 for i in range(5001)] for _ in range(51)]
#dp[i][j]で0からi枚目まで好きなように選択してそのそうわがｊ-2500となるような撮り方の総数
#最終的に求めるのはdp[i][0]である

for i in range(n+1):
    for j in range(4951):
        if i>=1 and j>=lists[i-1]:
            dp[i][j]=dp[i-1][j-lists[i-1]]+dp[i-1][j]
        if i>=1 and j<lists[i-1]:
            dp[i][j]=dp[i-1][j]
        else:
            if j==2500 and i==0:
                dp[i][j]=1
            elif j!=2500 and i==0:
                dp[i][j]=0
print(dp[n][2500]-1)  
        

Measured memory_bytes: 5748
#include<iostream>
using namespace std;
long long n,k;
int a[200005],end[200005];
bool visited[200005];
int main(){
cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int tmp = min(k, 200000LL);
    k -= tmp;
    int curr = 1;
    while(tmp > 0)
    {
        curr = a[curr];
        tmp--;
    }
    if(k == 0)
    {
        cout << curr;
        return 0;
    }
    int tn = 0;
    while(!visited[curr])
    {
        visited[curr] = 1;
        tn++;
        curr = a[curr];
    }
    k %= tn;
    while(k > 0)
    {
        curr = a[curr];
        k--;
    }
    cout << curr;
        return 0;
}


Measured memory_bytes: 4572
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n * (n - 2) / 2 << endl;
        REP1(i, n) {
            FOR(j, i + 1, n + 1) {
                if (i + j == n + 1) continue;
                cout << i << " " << j << endl;
            }
        }
    } else {
        cout << n * (n - 1) / 2 - (n - 1) / 2 << endl;
        REP1(i, n - 1) {
            FOR(j, i + 1, n + 1) {
                if (i == j or i + j == n) continue;
                cout << i << " " << j << endl;
            }
        }
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int n, i,nmin = 1000001,nmax = -1000001,temp;
	long long int sum = 0;
	cin >> n;
	for (i=0;i<n;i++)
	{
		cin >> temp;
		sum += temp;
		nmax = max(nmax, temp);
		nmin = min(nmin, temp);
	}
	printf("%d %d %lld\n",nmin, nmax, sum);
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
    
using namespace std;
vector<string >num;
vector<vector<long long> >dp;
vector<pair<int,int> >be;
int row,col;

int main(){
cin>>row>>col;

for(int i=0;i<row;i++){
	string s;
	cin>>s;
	num.push_back(s);
}
for(int i=0;i<row;i++){
	dp.push_back(vector<long long>());
	for(int j=0;j<col;j++){
		if(i==0&&j==0){
		dp[i].push_back(1);
		}
		else{
			dp[i].push_back(0);
			if(num[i][j]=='#'){
				continue;
			}
			if(i>0&&num[i-1][j]!='#'){
			dp[i][j]+=dp[i-1][j];
			}
		    if(j>0&&num[i][j-1]!='#'){
				dp[i][j]+=dp[i][j-1];
			}
			dp[i][j]%=1000000007;
		}
	}
}
cout<<dp[row-1][col-1];
return 0;
}

Measured memory_bytes: 9344
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main(void) {
	int a, b;
	cin >> a >> b;
	if (a >= b) {
		swap(a, b);
	}
	for (int i = 0; i < b; i++) {
		cout << a;
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

ans = 0
tmp = A[0]

for a in A[1:]:
	ans += max(0, tmp-a)
	tmp = max(tmp, a)

print(ans)

Measured memory_bytes: 35024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,n,w;
  cin>>n>>w;
  vector<vector<unsigned long int>> arr(n , vector<unsigned long int>(2,0));
  for(i=0;i<n;i++)
  for(j=0;j<2;j++)
  cin>>arr[i][j]; //Weight, Value

  vector<vector<unsigned long int>> dp(n+1, vector<unsigned long int>(w+1,0));
  for(i=1;i<=n;i++)
  for(j=0;j<=w;j++)
  if(arr[i-1][0]<=j)
    dp[i][j]=max(dp[i-1][j], arr[i-1][1]+dp[i-1][j-arr[i-1][0]]);
  else
    dp[i][j]=dp[i-1][j];

  cout<<dp[n][w]<<endl;
  return 0;
}


Measured memory_bytes: 80256
H,W=map(int, input().split())
a= ["#"*(W+1)] + ["#" + input() for _ in range(H)]
dp=[[0]*(W+1) for _ in range(H+1)]
MOD=10**9+7
dp[1][1] = 1
for i in range(1, H+1):
    for j in range(1, W+1):
        if i == 1 and j == 1:
            continue
        if a[i][j] == ".":
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD
print(dp[H][W]%MOD)

Measured memory_bytes: 74588
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b = input_int_list()
    if b < a or (n == 1 and a != b):
        print(0)
        sys.exit()
    n -= 2
    if n == 0:
        print(1)
    else:
        ans = (b * n) - (a * n) + 1
        print(ans)

    return


if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

long double l;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
   
  cin >> l;
  
 cout << setprecision(12) << (l/3)*(l/3)*(l/3) << endl;
  
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>
#include <atcoder/fenwicktree>

using namespace std;
using namespace atcoder;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

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

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

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

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

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, q; cin >> n >> q;
	fenwick_tree<ll> fw(n);
	rep(i, n)
	{
		int a; cin >> a;
		fw.add(i, a);
	}
	while (q--)
	{
		int query; cin >> query;
		if (query == 0)
		{
			int p, x; cin >> p >> x;
			fw.add(p, x);
		}
		else
		{
			int l, r; cin >> l >> r;
			cout << fw.sum(l, r) << endl;
		}
	}
}

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

int	main()
{
  int cnt = 0;
  int rate = 0;
  
  cin >> cnt >> rate;
  if (cnt < 10)
  {
    cout << rate + 100 * (10 - cnt) << endl;
  }else
  {
    cout << rate << endl;
  }
}

Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())
print("D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"+"U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+'R'*(tx-sx+1)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy))



Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;


void solve(){
  string s,t;
  int a,b;
  string u;
  cin>>s>>t>>a>>b>>u;
  if(u==s)a--;
  else b--;
  cout<<a<<" "<<b;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w;
  cin >> h >> w;
  vector<vector<ll>> v(h,vector<ll>(w));
  auto v2 = v;
  rep(j,h){
    rep(i,w){
      cin >> v[j][i];
      v[j][i] = !v[j][i];
    }
  }
  ll ans = 0;
  {
    stack<pll> st;
    rep(i,w){
      v2[0][i] = v[0][i];
      if(st.empty()){
        st.push(mp(v2[0][i],i));
      }
      else if(st.top().fi < v2[0][i]){
        st.push(mp(v2[0][i],i));
      }
      else if(st.top().fi > v2[0][i]){
        ll pos = i;
        while(!st.empty()){
          if(st.top().fi >= v2[0][i]){
            auto t = st.top();st.pop();
            ans = max(ans,t.fi * (i - t.se));
            pos = t.se;
          }
          else break;
        }
        st.push(mp(v2[0][i],pos));
      }
    }
    ans = max(ans,st.top().fi * (w - st.top().se));
  }
  REP(j,1,h){
    stack<pll> st;
    rep(i,w){
      if(v[j][i]){
        v2[j][i] += v2[j-1][i] + 1;
      }
      if(st.empty()){
        st.push(mp(v2[j][i],i));
      }
      else if(st.top().fi < v2[j][i]){
        st.push(mp(v2[j][i],i));
      }
      else if(st.top().fi > v2[j][i]){
        ll pos = i;
        while(!st.empty()){
          if(st.top().fi >= v2[j][i]){
            auto t = st.top();st.pop();
            ans = max(ans,t.fi * (i - t.se));
            pos = t.se;
          }
          else break;
        }
        st.push(mp(v2[j][i],pos));
      }
    }
    while(!st.empty()){
      auto t = st.top();st.pop();
      ans = max(ans,t.fi * (w - t.se));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 33388
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon" << endl;
    } else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout << "pon" << endl;
    } else{
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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(){
  cout << fixed << setprecision(15);
  int ans = 0;
  //string ans = "No";

  int balls, robot; cin >> balls >> robot;
  vector<int> ballplace(balls);
  rep(i, balls) cin >> ballplace[i];

  rep(i, balls){
    ans += min(abs(ballplace[i] - robot), ballplace[i]);
  }
  ans *= 2;

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

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=25,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int vis[maxn][maxn],dis[maxn][maxn],h,w,mp[maxn][maxn],ans;
struct node
{
	int x,y;
};	
queue<node>q;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
void gkd(int x,int y)
{
	memset(dis,0,sizeof(dis));
	memset(vis,0,sizeof(vis));
	node s;
	s.x=x,s.y=y;
	vis[x][y]=1;
	q.push(s);
	while(!q.empty())
	{
		node now=q.front();
		q.pop();
		int xx=now.x,yy=now.y;
		for(int i=0;i<4;++i)
		{
			int tx=xx+dx[i],ty=yy+dy[i];
			if(!mp[tx][ty]||vis[tx][ty]||tx<1||tx>h||ty<1||ty>w)
				continue;
			dis[tx][ty]=dis[xx][yy]+1;
			ans=max(ans,dis[tx][ty]);
			vis[tx][ty]=1;
			node nxt;
			nxt.x=tx,nxt.y=ty;
			q.push(nxt);
		}
	}
}
int main()
{
    h=read(),w=read();
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
		{
			char ch;
			cin>>ch;
			if(ch=='.')
				mp[i][j]=1;
			else
				mp[i][j]=0;
		}
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			if(mp[i][j])
				gkd(i,j);
	write(ans);
    return 0;
}


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

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


int main()
{
    long long H;
    cin >> H;

    long long ans = 0, n = 1;
    while(H > 0){
        H /= 2;
        ans += n;
        n *= 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
int main(){
    bool finish = true;
    while(finish){
        int H,W;
        cin >> H >> W;
        if(H*W == 0){
            finish = false;
        }
        else{
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    cout << '#';
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) (n); i++)
#define ll long long
#define scout cout << fixed << setprecision(20)
ll INF = 9e17;
ll mod = 1e9 + 7;

int main() {
	int n,a; cin >> n >> a;
	cout << n*n-a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    long long int a,b,x,aans,bans,ans;
    cin >> a >> b >> x;
    bans=b/x+1;
    aans=(a-1)/x+1;
    if(a==0)aans=0;
    ans=bans-aans;
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 20

int main(void) {
	char c;
	char str[N];
	int i = 0;

	while(scanf("%1c", &c) != EOF) {
		str[i++] = c;
	}

	for(i -= 2; i >= 0; i--) {	// «µ·¬½ÌÆüsR[hÆNULL¶Ìª¾¯}CiX
		printf("%c", str[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int n, m;
  cin >> n >> m;
  vector<int> box(n, 1);
  vector<bool> red(n, false);
  red[0] = true;

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    box[a]--; box[b]++;
    if (red[a]) red[b] = true;
    if (box[a] == 0) red[a] = false;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (red[i]) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int flag=1;
    string s;
    cin >> s;
    map<int,int> mp;
    for(char i='a';i<='z';i++){
        mp[i]=0;
    }
    rep(i,s.length()){
        mp[s[i]]++;
    }
    for(char i='a';i<='z';i++){
        if(mp[i]%2){
            flag=0;
            break;
        }
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    t,a=map(int, input().split())
    h=list(map(int,input().split()))
    tempabs=[abs(a-(t-i*0.006)) for i in h]
    minabs=min(tempabs)
    print(tempabs.index(minabs)+1)
resolve()

Measured memory_bytes: 3060
K=int(input())
S=set()
ans=0

x=7%K
i=1
while True:
    if x==0:
        ans=1
        break
    if x in S:
        break
    else:
        S.add(x)
    x=(x*10+7)%K
    i+=1

print(i if ans else -1)

Measured memory_bytes: 77928
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

int gcd(int a, int b){return b? gcd(b, a%b): a;}

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i,N){
		cin>>A[i];
	}

	int g = gcd(A[0],A[1]);
	for(int i=2; i<N; ++i){
		g = gcd(g, A[i]);
	}
	ote(g);
}


Measured memory_bytes: 640
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
d = defaultdict(int)
for i in readChars():
	d[i]+=1
m =readInt()
t = defaultdict(int)
for i in readChars():
	t[i]+=1

for key in t:
	if d[key]-t[key]<0:
		print("NO")
		exit()
print("YES")

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

int a[110000];
int m[110000];
int n;

int dp(){
	m[0] = 0;
	m[1] = abs(a[0] - a[1]);
	for(int i = 2;i<n;i++){
		m[i] = min(
			(m[i-1] + abs(a[i] - a[i-1])),
			(m[i-2] + abs(a[i] - a[i-2]))
		);	
	}
	return m[n-1];
}

int main(){
	cin>>n;
	for(int i = 0;i<n;i++){
		cin>>a[i];
	}
	cout<<dp()<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**8)

def dfs(h,w,visited,S):
    #print(h,w)
    for i in range(8):
        h0 = h+dh[i]
        w0 = w+dw[i]
        if visited[h0][w0]==False and S[h0][w0]=='1':
            visited[h0][w0]=True
            dfs(h0,w0,visited,S)

ans = []
while True:
    W,H = map(int, input().split())
    if (W,H) == (0,0):
        break
    S = [0]*(H+2)
    S[0] = ['*']*(W+2)
    S[H+1] = ['*']*(W+2)
    for h in range(1,H+1):
        S[h] = ['*'] + input().split() + ['*']

    visited = [[False]*(W+2) for _ in range(H+2)]
    dh = [0,1,1,1,0,-1,-1,-1]
    dw = [1,1,0,-1,-1,-1,0,1]

    cnt = 0
    for h in range(1,H+2):
        for w in range(1,W+2):
            if visited[h][w]==False and S[h][w]=='1':
                visited[h][w]=True
                dfs(h,w,visited,S)
                cnt += 1
    ans.append(cnt)
print(*ans, sep='\n')


Measured memory_bytes: 8048
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut v:Vec<usize> = Vec::new();
    for _i in 0..3 {
        let a:usize = read!();
        v.push(a);
    }
    v.sort();
    println!("{}",v[0]+v[1]+v[2]*10);
}

Measured memory_bytes: 2188
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 5

int N,M;
ll DIST,ans;
ll start_time[NUM];
ll unit_time[NUM],loc[NUM];

ll goal_time(int car_id){

	return start_time[car_id]+unit_time[car_id]*DIST;
}

void recursive(int car_id){

	for(int i = 0; i < N; i++){
		if(start_time[i] == -1)continue;

		if(goal_time(i) >= ans){
			return;
		}
	}

	ll pre = 0;

	for(int i = 1; i < N; i++){
		if(start_time[i] == -1)continue;

		if(start_time[i] <= pre){
			return;
		}

		pre = start_time[i];
	}

	if(car_id == N){

		for(int i = 0; i < N; i++){
			if(start_time[i] == -1)return;
		}

		bool FLG;

		vector<ll> V[NUM];

		for(int i = 0; i < N-1; i++){
			for(int k = i+1; k < N; k++){
				if(goal_time(i) <= goal_time(k))continue;

				FLG = false;

				for(int a = 0; a < M; a++){
					if(start_time[i]+unit_time[i]*loc[a] == start_time[k]+unit_time[k]*loc[a]){
						V[a].push_back(start_time[i]+unit_time[i]*loc[a]);
						FLG = true;
						break;
					}
				}

				if(!FLG)return;
			}
		}

		for(int i = 0; i < M; i++){
			if(V[i].size() <= 1)continue;

			for(int a = 0; a < V[i].size()-1; a++){
				for(int b = a+1; b < V[i].size(); b++){
					if(V[i][a] == V[i][b]){
						return;
					}
				}
			}
		}

		ll tmp_ans = -1;
		for(int i = 0; i < N; i++){
			tmp_ans = max(tmp_ans,goal_time(i));
		}

		ans = min(ans,tmp_ans);

		return;
	}

	for(int i = 0; i < N-1; i++){

		if(start_time[i] != -1 && start_time[i+1] == -1){

			start_time[i+1] = start_time[i]+1;
			recursive(car_id+1);
			start_time[i+1] = -1;
		}

		if(start_time[i] == -1 && start_time[i+1] != -1){

			start_time[i] = start_time[i+1]-1;
			recursive(car_id+1);
			start_time[i] = -1;
		}
	}

	for(int i = 1; i < N; i++){
		if(start_time[i] != -1)continue;

		for(int k = 0; k < N; k++){
			if(k == i || start_time[k] == -1 || (k < i && unit_time[k] <= unit_time[i]) || (i < k && unit_time[i] <= unit_time[k]))continue;

			for(int a = 0; a < M; a++){

				start_time[i] = start_time[k]+(unit_time[k]-unit_time[i])*loc[a];
				recursive(car_id+1);
				start_time[i] = -1;
			}
			start_time[i] = start_time[k]+(unit_time[k]-unit_time[i])*DIST;
			recursive(car_id+1);
			start_time[i] = -1;
		}
	}
}

int main(){

	scanf("%lld",&DIST);
	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		scanf("%lld",&unit_time[i]);
	}

	scanf("%d",&M);

	for(int i = 0; i < M; i++){
		scanf("%lld",&loc[i]);
	}

	if(N == 1){

		printf("%lld\n",unit_time[0]*DIST);
		return 0;
	}

	start_time[0] = 0;

	for(int i = 1; i < N; i++){
		start_time[i] = -1;
	}

	ans = HUGE_NUM;

	recursive(1);

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3284
a, b, m = map(int, input().split())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))

ans = min(l_a) + min(l_b)
for i in range(m):
    x, y, c = map(int, input().split())
    o_sum = l_a[x-1] + l_b[y-1] - c
    ans = min(o_sum, ans)

print(ans)

Measured memory_bytes: 18648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
    int n; cin >> n;
    vector<int>a(n+2);
    for(int i=0;i<n+2;i++){
        a[i] = 0;
    }

    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    int sum = 0;
    for(int i=1;i<=n+1;i++){
        sum += abs(a[i-1]-a[i]);
    }
    // cout << sum << endl;
    for(int i=1;i<=n;i++){
        int r = max(a[i+1],a[i-1]),l = min(a[i+1],a[i-1]);
        if(l <= a[i] && a[i] <= r) cout << sum << endl;
        else cout << sum - 2*min(abs(a[i]-a[i+1]),abs(a[i]-a[i-1])) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#define NIL -1
struct Node {
    int parent, left, right;
};
int getParent(Node* nodeArray, int index)
{
    return nodeArray[index].parent;
}
int getSibling(Node* nodeArray, int index)
{
    if (nodeArray[index].parent == NIL) {
	return NIL;
    }
    int parent = nodeArray[index].parent;
    if (nodeArray[parent].left == index) {
	return nodeArray[parent].right;
    } else {
	return nodeArray[parent].left;
    }
}
//????????°
int getDegree(Node* nodeArray, int index)
{
    int count = 0;
    if (nodeArray[index].left != NIL) {
	count++;
    }
    if (nodeArray[index].right != NIL) {
	count++;
    }
    return count;
}
int getDepth(Node* nodeArray, int index)
{
    int parent = nodeArray[index].parent;
    int depth = 0;
    while (parent != NIL) {
	depth++;
	parent = nodeArray[parent].parent;
    }
    return depth;
}
int getHeight(Node* nodeArray, int index)
{
    int h1 = 0;
    int h2 = 0;
    if (nodeArray[index].left != NIL) {
	h1 += getHeight(nodeArray, nodeArray[index].left) + 1;
    }
    if (nodeArray[index].right != NIL) {
	h2 += getHeight(nodeArray, nodeArray[index].right) + 1;
    }
    return std::max(h1, h2);
}
std::string getType(Node* nodeArray, int index)
{
    if (nodeArray[index].parent == NIL) {
	return "root";
    }
    if (nodeArray[index].left == NIL && nodeArray[index].right == NIL) {
	return "leaf";
    }
    return "internal node";
}
void printNode(Node* nodeArray, int n)
{
    for (int i = 0; i < n; i++) {
	std::cout << "node " << i << ": ";
	std::cout << "parent = " << getParent(nodeArray, i) << ", ";
	std::cout << "sibling = " << getSibling(nodeArray, i) << ", ";
	std::cout << "degree = " << getDegree(nodeArray, i) << ", ";
	std::cout << "depth = " << getDepth(nodeArray, i) << ", ";
	std::cout << "height = " << getHeight(nodeArray, i) << ", ";
	std::cout << getType(nodeArray, i);
	std::cout << std::endl;
    }
}
int main()
{
    int n = 0;
    std::cin >> n;
    Node* nodeArray = (Node*)malloc(n * sizeof(Node));
    for (int i = 0; i < n; i++) {
	nodeArray[i].parent = NIL;
	nodeArray[i].left = NIL;
	nodeArray[i].right = NIL;
    }
    for (int i = 0; i < n; i++) {
	int index, left, right;
	std::cin >> index;
	std::cin >> left;
	std::cin >> right;
	nodeArray[left].parent = index;
	nodeArray[right].parent = index;
	nodeArray[index].left = left;
	nodeArray[index].right = right;
    }
    printNode(nodeArray, n);
}

Measured memory_bytes: 3168
#include <stdio.h>

int have_data(long data, long* p, long len);

int main(void){

    long a[4][4];
    for(long i=0;i<3;i++){
        for(long j=0;j<3;j++){
            scanf("%ld", &a[i][j]);
        }
    }
    for(long i=0;i<3;i++){
        a[i][3] = 1;
        a[3][i] = 1;
    }

    long n;
    scanf("%ld", &n);

    long b[n];
    for(long i=0;i<n;i++){
        scanf("%ld", &b[i]);
    }

    long d1 = 1, d2 = 1;
    for(long i=0;i<3;i++){
        for(long j=0;j<3;j++){
            a[i][3] &= have_data(a[i][j], b, n);
            a[3][j] &= have_data(a[i][j], b, n);
        }
        d1 &= have_data(a[i][i], b, n);
        d2 &= have_data(a[i][3-1-i], b, n);
    }

    long res = 0;
    for(long i=0;i<3;i++){
        res |= a[i][3] | a[3][i] | d1 | d2;
    }

    printf("%s\n", res ? "Yes" : "No");

    return 0;
}

int have_data(long data, long* p, long len){
    for(long i=0;i<len;i++){
        if(p[i] == data) return 1;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int oo = 1e9;
ll a[N],b[N],c[N],s[N],lr[N];
int main() {
	int n;
	cin>>n;
	for(int x=0;x<n;x++){
		cin>>a[x];
	}
	for(int x=0;x<n;x++){
		cin>>b[x];
	}
	for(int x=0;x<n;x++){
		cin>>c[x];
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	ll sum=0;
	int id=0;
	for(int x=0;x<n;x++){
		while(a[x]>=b[id]&&id<n){
			id++;
			s[id]=s[id-1]+x;
		}
		s[id]= s[id-1]+x+1;
	}
	if(s[id]==0){
		if(id==0){
			s[id]= lr[id];
		}else{
			s[id]= lr[id]+s[id-1];
		}
	}
	for(int x=id+1;x<n;x++){
		s[x]=s[x-1]+n;
	}
	for(int x=0;x<n;x++){
		ll s1,s2;
		int mid,lo=0,hi=n-1,best=-1;
		while(lo<=hi){
			mid = (lo+hi)/2;
			if(b[mid]>=c[x]){
				hi = mid-1;
			}else{
				lo = mid+1;
				best = lo;
			}
		}
		s1=best;
		if(s1<0){
			continue;
		}
		sum+= s[s1-1];
	}
	cout << sum << endl;
}

Measured memory_bytes: 3328
import numpy as np

N = int(input())
A = [int(input()) for i in range(N)]
A = np.array(A)

A_max = np.max(A)
A_argmax = np.argmax(A)

for i in range(N):
  if i == A_argmax:
    print(A[A.argsort()[::-1][1]])
  else:
    print(A_max)


Measured memory_bytes: 21832
#include <stdio.h>
 
int main(void)
{
    int n, m;
    int i, j;
    int a[100][100]={};
    int b[100]={};
    int c[100]={};
     
    scanf("%d%d", &n, &m);
     
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++)
            scanf("%d", &a[i][j]);
    }
    for(j=0; j<m; j++)
        scanf("%d", &b[j]);
     
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++)
            c[i]+=a[i][j]*b[j];
        printf("%d\n", c[i]);
    }
     
    return 0;
}


Measured memory_bytes: 2072
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	fmt.Println((N-1) * (1+N-1) / 2)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
    int N, K;
    scanf("%d%d", &N, &K);
    int a[N];
    int i;
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < N-1; i++)
    {
        for (int j = 0; j < N-1; j++)
        {
            if(a[j] > a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }  
    }
    int sum = 0;
    i = 0;
    while(K--){
        sum += a[i++];
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1732
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(1,N):
        A[i]+=A[i-1]
    A = Counter(A)
    ret = 0
    for x in A.values():
        ret += x*(x-1)//2
    ret += A.get(0,0)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39812
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 1e5;
vector<int> conns[N];
ll dp[N][2];

void solve(int i, int p) {
	dp[i][0] = 1; // Ways to have be black
	dp[i][1] = 1; // Ways to have be white
	for (auto t : conns[i]) {
		if (t == p) continue;
		solve(t, i);
		dp[i][0] = (dp[i][0] * dp[t][1]) % MOD;
		dp[i][1] = (dp[i][1] * (dp[t][0] + dp[t][1])) % MOD;
	}
}

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

	int n;
	cin >> n;
	for (int i = 0; i < n-1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		conns[a].push_back(b);
		conns[b].push_back(a);
	}
	solve(0, 0);
	cout << (dp[0][0] + dp[0][1]) % MOD << '\n';
}


Measured memory_bytes: 14208
import java.util.Scanner;


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

		String input = sc.nextLine();
		for (int i = 0; i < input.length(); i++)
		{
			if (Character.isLowerCase(input.charAt(i)))
			{
				System.out.print(Character.toUpperCase(input.charAt(i)));

			}
			else if (Character.isUpperCase(input.charAt(i)))
			{
				System.out.print(Character.toLowerCase(input.charAt(i)));

			}
			else
			{
				System.out.print(input.charAt(i));
			}
		}

		System.out.println();
	}
}



Measured memory_bytes: 26568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll tmp0 = 0;
  ll tmp1 = 0;
  ll sum0 = 0;
  ll sum1 = 0;
  // + - + -...
  for (int i = 0; i < n; i++) {
    sum0 += a[i];
    sum1 += a[i];

    if(i % 2 == 0) {
      if(sum0 <= 0) {
        ll adj = 1 - sum0;
        tmp0 += abs(adj);
        sum0 = 1;
      }
    } else {
      if(sum0 >= 0) {
        ll adj = -1 - sum0;
        tmp0 += abs(adj);
        sum0 = -1;
      }
    }

    if(i % 2 == 1) {
      if(sum1 <= 0) {
        ll adj = 1 - sum1;
        tmp1 += abs(adj);
        sum1 = 1;
      }
    } else {
      if(sum1 >= 0) {
        ll adj = -1 - sum1;
        tmp1 += abs(adj);
        sum1 = -1;
      }
    }
  }
  cout << min(tmp0, tmp1) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

int main()
{
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }

  bool f = true;

  ll c = 0;
  ll d = a[0];
  while(d%2==0){
    d /= 2;
    c++;
  }
  rep1(i,n-1){
    ll cnt = 0;
    ll b = a[i];
    while(b%2==0){
      b /= 2;
      cnt++;
    }
    if(c!=cnt){
      f = false;
      break;
    }
  }
  
  ll g = 1;
  rep(i,n){
    g = lcm(g,a[i]/2);
    
  }

  if(!f){
    cout << 0 << "\n";
  }
  else{
    ll res = m/g;
    res  = (res+1)/2;
    cout << res << "\n";
  }

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val arr = IntArray(n){scn.nextInt()}
	val sum = arr.sum()
	var ans = 0
	arr.forEach { ans += it*(sum-it) }
	println(ans/2)
}

Measured memory_bytes: 35916
#include <stdio.h>

int main() {

    int i;
    char s[11]={0}, t[11]={0}, u[11]={0};
    int a, b, sa=0, sb=0;

    scanf("%s%s%d%d%s", s, t, &a, &b, u);

    for(i = 0; i < 10; i++) {
        if(s[i] == u[i]) {
            sa++;
        }
        if(t[i] == u[i]) {
            sb++;
        }
    }
    if(sa == 10) {
        a--;
    }
    if(sb == 10) {
        b--;
    }

    printf("%d %d\n", a, b);
    
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int day = sc.nextInt();
		int work_count = sc.nextInt();

		int homework [] = new int[work_count];

		for (int i = 0; i < work_count; i++) {
			homework[i] = sc.nextInt();
		}

		int sum = 0;

		for (int i = 0; i < work_count; i++) {
			sum += homework[i];
		}

		if (day >= sum) {
			System.out.print(day - sum);
		} else {
			System.out.print(-1);
		}

	return;

	}
}


Measured memory_bytes: 39596
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,n,x,ans=0;
    string s;
    cin>>n;
    if(n%4==0||n%7==0)
        return cout <<"Yes"<<endl,0;
    for(i=0; i<=n/4; i++)
    {
        for(j=0; j<=n/7; j++)
        {
            if(i*4+j*7==n)
                return cout <<"Yes"<<endl,0;
        }
    }
    return cout <<"No"<<endl,0;
    return 0;
}





Measured memory_bytes: 3596
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, d = rli()
    ans = n // (2*d+1)
    if n % (2*d+1) > 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940