akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>

using pii = std::pair<int, int>;
const int MAXN = (int)1e5;

std::vector<pii> edges[MAXN];
int edge_color[MAXN];

void dfs(int u, int par, int par_edge_color) {
  int cur_color = 1;
  for (const auto &cur : edges[u]) {
    int v = cur.first;
    int edge_index = cur.second;
    if (v == par) continue;
    if (cur_color == par_edge_color) ++cur_color;
    edge_color[edge_index] = cur_color++;
    dfs(v, u, edge_color[edge_index]);
  }
}

void solve(int n) {
  int color_num = 0;
  int root = 0;
  for (int i = 0; i < n; ++i) {
    if (edges[i].size() > color_num) {
      color_num = edges[i].size();
      root = i;
    }
  }
  dfs(root, -1, 0);

  std::cout << color_num << std::endl;
  for (int i = 0; i < n - 1; ++i) {
    std::cout << edge_color[i] << std::endl;
  }
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 0, u, v; i < n - 1; ++i) {
    std::cin >> u >> v;
    --u;
    --v;
    edges[u].emplace_back(v, i);
    edges[v].emplace_back(u, i);
  }
  solve(n);
  return 0;
}


Measured memory_bytes: 9344
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define in cin >>
#define out cout <<
#define sort1(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
    int n,k;
       cin >> n >> k;
    vector<int> a(n+3);
    vector<int> d(k+3);  
    int b;

   for(int j=0;j<k;j++){
       cin >> d[j];
   for(int i=0;i<d[j];i++){
       cin >> b;
       int b1=b-1;
       a[b1]=1;
   }
   }
   
   int ans=0;
   for(int i=0;i<n;i++){
           ans=a[i]+ans;
   }

   ans=n-ans;
    cout << ans;

}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int res=0;
	res+=(n*(n-1))/2;
	if(m==1);
	else{
		res+=(m*(m-1))/2;
	}
	cout<<res;
	return 0;
}

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

int main(){
  char ch,a;
  scanf("%c",&ch);
  a='\n';
  while(!(a==ch)){
    if(islower(ch)){
      printf("%c",toupper(ch));}
    else if(isupper(ch)){
      printf("%c",tolower(ch));}
    else printf("%c",ch);
    scanf("%c",&ch);
    }
  printf("%c",a);
  return 0;}

Measured memory_bytes: 524
let str = require('fs').readFileSync('/dev/stdin', 'UTF-8');
let array = str.split('\n');
for ( let i = 0; i < array.length; i++) {
  let ab = array[i].split(' ').map(Number);
  if (ab[0] === 0 && ab[1] === 0) break;
  ab.sort((a, b) => { return a-b; });
  console.log(ab[0] + ' ' + ab[1]);
}


Measured memory_bytes: 20296
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.close();
		char[] c1 = s.toCharArray();
		char[] c2 = t.toCharArray();
		int ans = 0;
		for (int i = 0; i < s.length(); i++)
			if (c1[i] == c2[i])
				ans++;

		System.out.println(ans);

	}
}

Measured memory_bytes: 23892
#include <vector>
#include <iostream>
              
void solve() {
  std::string X, Y;
  std::cin >> X >> Y;
  const int LX = X.size();
  const int LY = Y.size();
  std::vector<int> dp0(LY+1, 0), dp1(LY+1, 0);
  std::vector<int> *dp = &dp0;
  std::vector<int> *dp_ = &dp1;
  for (int i = 1; i < LX+1; i++) {
    std::swap(dp, dp_);
    for (int j = 1; j < LY+1; j++) {
      (*dp)[j] = std::max((*dp)[j-1], (*dp_)[j]);
      if (X[i-1] == Y[j-1]) {
        (*dp)[j] = std::max((*dp)[j], (*dp_)[j-1] + 1);
      }       
    }         
  }           
  std::cout << dp->back() << std::endl;
}             
              
int main() {  
  int N;      
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    solve();  
  }           
}             
     


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,l,r,mid,num[55],ans,now[55];
bool check(long long x)
{
	if (x<0) return 0;
	long long i,s=0;
	for (i=1;i<=n;i++) now[i]=num[i]+x;
	for (i=1;i<=n;i++)
	{
		if (now[i]>=n)
		{
			s+=(now[i]-(n-1)+n)/(n+1);
		}
	}
	return s<=x;
}
int main()
{
	cin>>n;
	for (i=1;i<=n;i++) cin>>num[i];
	/*sort(num+1,num+n+1);
	reverse(num+1,num+n+1);*/
	l=0;r=6e18;
	while (l<r)
	{
		mid=(l+r+1)/2;
		if (check(mid))
		{
			r=mid-1;
			ans=mid; 
		}
		else l=mid;
	}
	for (i=ans-5000;i<=ans+5000;i++)
	{
		if (i<0) continue;
		if (i>1e18) continue;
		if (check(i))
		{
			cout<<i;
			return 0;
		}
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;

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

    ll x;
    cin >> x;
    double rate = 1.01;
    ll money = 100;
    for(int i=1;i<=4000;i++){
        money *= rate;
        if(money>=x){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	A := nextInt()
	B := nextInt()
	C := nextInt()

	if A == B && A != C {
		fmt.Println("Yes")
	} else if A == C && A != B {
		fmt.Println("Yes")
	} else if B == C && B != A {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


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

    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ans=a[0]-1;
    ll num=2;
    for(int i=1;i<n;i++){
        if(a[i]==num){
            num++;
        }
        else if(a[i]<num){
            continue;
        }
        else{
            ans+=a[i]/num;
            if(a[i]%num==0) ans--;
        }
    }  
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		List<TreeSet<Integer>> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(new TreeSet<>());
		}
		UnionFind uf = new UnionFind(n);
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
			uf.union(a, b);
		}
		List<TreeSet<Integer>> list2 = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list2.add(new TreeSet<>());
		}
		for (int i = 0; i < k; i++) {
			sa = br.readLine().split(" ");
			int c = Integer.parseInt(sa[0]) - 1;
			int d = Integer.parseInt(sa[1]) - 1;
			list2.get(c).add(d);
			list2.get(d).add(c);
		}
		br.close();

		int[] ans = new int[n];
		for (int i = 0; i < n; i++) {
			int size = uf.size(i);
			size -= list.get(i).size();
			Set<Integer> set2 = list2.get(i);
			for (Integer o : set2) {
				if (uf.same(i, o)) {
					size--;
				}
			}
			ans[i] = size - 1;
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ans.length; i++) {
			sb.append(ans[i]).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}

	static class UnionFind {
		int[] parent, size;
		int num = 0; // 連結成分の数。頂点初登場時に+1

		UnionFind(int n) {
			parent = new int[n];
			size = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
				size[i] = 1;
			}
		}

		void union(int x, int y) {
			int px = find(x);
			int py = find(y);
			if (px != py) {
				parent[px] = py;
				size[py] += size[px];
				num--;
			}
		}

		int find(int x) {
			if (parent[x] == x) {
				return x;
			}
			parent[x] = find(parent[x]);
			return parent[x];
		}

		/**
		 * xとyが同一連結成分か
		 */
		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		/**
		 * xを含む連結成分のサイズ
		 */
		int size(int x) {
			return size[find(x)];
		}
	}
}


Measured memory_bytes: 105980
#include <iostream>
#include<cstring>
#include<math.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    char s[1001];
    char t[1001];
    cin >> s >> t ;
    n=strlen(s) ;
    m=strlen(t);
    int ans=1000000;
    for (int i=0 ; i<= n-m ; i++){
        int count =0 ;
        for (int j=0 ; j<m ;j++){
            if (s[i+j]!=t[j]){
                count++ ;
            }
        }
        ans=min(ans,count);
    }

    cout << ans ;
}

Measured memory_bytes: 3640
using System;
using System.Linq;
 
namespace abc064_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((x[1] * 10 + x[2]) % 4 == 0 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

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

        int initRem = a % b;
        if (initRem == c) {
            System.out.println("YES");
            return;
        }
        int n = a + a;
        while (true) {
            if (n % b == c) {
                System.out.println("YES");
                return;
            }
            if (n % b == initRem) {
                System.out.println("NO");
                return;
            }
            n = n + a;
        }
    }
}


Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  long long n; cin >> n;
  int ans = INF;
  for (long long a = 1; a * a <= n; ++a) {
    if (n % a == 0) ans = min(ans, (int)max(to_string(a).size(), (to_string(n / a)).size()));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import collections
s = list(input())
sset = set(s)
if len(sset) != 26:
    for i in range(97,123):
        if chr(i) in sset:
            continue
        else:
            tmp = chr(i)
            s.append(tmp)
            break

    print(''.join(s))
    exit()
else:
    tmp = []
    flg = False
    # 昇順のインデックス見つける
    for i in range(1,26):
        if s[i-1] < s[i]:
            tmp.append(i-1)
            continue
    # ０なら-1
    if len(tmp) == 0:
        print(-1)
        exit()
    # 末尾の昇順のとこかえる
    change_i = max(tmp)
    ans = s[:change_i]
    for i in range(97,123):
        if chr(i) in ans:
            continue
        else:
            if ord(s[change_i]) < i:
                ans.append(chr(i))
                break
    print(''.join(ans))


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

int n,m;
vector<int>to[10010],ans;
bool ok[10010];

void dfs(int v){
    ok[v]=true;
    for(int u:to[v]){
        if(ok[u])continue;
        dfs(u);
    }
    ans.push_back(v);
    return;
}

void Tsort(){
    rep(i,n){
        if(!ok[i])dfs(i);
    }
    return;
}

int main(){
    cin>>n>>m;
    rep(i,m){
        int s,t; cin>>s>>t;
        to[s].push_back(t);
    }
    Tsort();
    reverse(ans.begin(),ans.end());
    for(auto& x:ans){
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	
	int n,m,x;
	cin>>m>>n;
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		sum=sum+x;
	}
	if(sum>m)cout<<-1;
	else cout<<m-sum;
	
	
}

Measured memory_bytes: 3632
n = gets.to_i
dp = Array.new(n) { Array.new n }
ss = n.times.map { s, d, v = gets.split.map(&:to_i); [s, d, 20 * v] }
if n == 1
  p ss[0][0]
  exit
end
encode = lambda do |xs|
  xs.reduce 0 do |r, x|
    r | (1 << x)
  end
end
dist = lambda {|a, b, w| (a[1] - b[1]).abs * (70 + w) / 2000.0 }
puts n.times.map {
  cs = Array.new(2**(n-1)) { Array.new n-1, Float::INFINITY }
  ws = Array.new(2**(n-1)) { Array.new n-1 }
  ps = Array.new(2**(n-1)) { Array.new n-1 }
  s0, *ss = ss
  ss.each_with_index do |s, i|
    e = encode[[i]]
    ws[e] = s0[2] + s[2]
    cs[e][i] = dist[s0, s, s0[2]]
  end
  for i in 2..n-1
    [*0...n-1].combination(i) do |ks|
      #e = encode[ks]
      e = ks.reduce(0) {|r, x| r | (1 << x) }
      ws[e] = ws[e - (1 << ks[0])] + ss[ks[0]][2]
      ks.each do |k|
        f = e - (1 << k)
        ks.each do |i|
          next if i == k
          #c = cs[f][i] + dist[ss[i], ss[k], ws[f]]
          c = cs[f][i] + (ss[i][1] - ss[k][1]).abs * (70 + ws[f]) / 2000.0
          if c < cs[e][k]
            cs[e][k] = c
            ps[e][k] = i
          end
        end
      end
    end
  end
  e = encode[(n-1).times.to_a]
  k = (n-1).times.min_by {|i| cs[e][i] }
  c = cs[e][k]
  rs = []
  loop do
    rs << ss[k][0]
    break unless ps[e][k]
    e, k = e - (1 << k), ps[e][k]
  end
  ss << s0
  rs << s0[0]
  [c, rs.reverse!]
}.min_by(&:first)[1].join ' '

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define inf 1e18
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;



int main() {
	ll n,a,b, c;
	cin >> n >> a >> b >> c;
	vector<int> f(n);
	rep(i, n) {
		cin >> f[i];
	}
	ll ans = inf;
	rep(i, pow(4, n)){
		ll sub = 0;
		ll aa=0, bb=0, cc=0;
		ll cnta = 0 , cntb = 0, cntc = 0;
		rep(j, n) {
			int s = i / pow(4, j);
			if (s%4 == 1) {
				aa += f[j];
				cnta++;
			}
			if (s % 4 == 2) {
				bb += f[j];
				cntb++;
			}
			if (s % 4 == 3) {
				cc += f[j];
				cntc++;
			}
		}
		if (min(aa, min(bb, cc))> 0) {
			sub = abs(aa - a) + abs(bb - b) + abs(cc - c);
		}
		else {
			sub = inf;
		}
		if (cnta != 0)	sub += (cnta - 1) * 10;
		if (cntb != 0)	sub += (cntb - 1) * 10;
		if (cntc != 0)	sub += (cntc - 1) * 10;
		ans = min(ans, sub);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int h,w,n,i;
  scanf("%d %d %d",&h,&w,&n);
  for(i=1;i<=n;i++){
    if(h*i>=n){
      printf("%d\n",i);
	break;
	}
    if(w*i>=n){
      printf("%d\n",i);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 128
import numpy

n,m = map(int,input().split(" "))
h = [int(e) for e in input().split(" ")]
ab = []
tenbou = {}
best = 0

for i in range(1,n+1):
    tenbou[i] = []
for i in range(m):
    ab.append([int(e) for e in input().split(" ")])

for road in ab:
    tenbou[road[0]].append(road[1])
    tenbou[road[1]].append(road[0])

for i in tenbou:
    tmp = 0
    for j in tenbou[i]:
        if (h[i-1] <= h[j-1]):
            tmp += 1
    if tmp == 0:
        best += 1
print(best)

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

using namespace std;

int main(){

	//入力
	long long x, y ,z, k;cin >> x >> y >> z >> k;
	vector<long long> a(x);
	for(int i = 0;i < x;i++)cin >> a[i];
	vector<long long> b(y);
	for(int i = 0;i < y;i++)cin >> b[i];
	vector<long long> c(z);
	for(int i = 0;i < z;i++)cin >> c[i];
	
	// 1のケーキと2のケーキの組み合わせを計算する
	vector<long long> AB;
	for(int i = 0;i < x;i++){
		for(int j = 0;j < y;j++){
			AB.push_back(a[i] + b[j]);
		}
	}
	
	sort(AB.begin(), AB.end(), greater<long long>());
	
	vector<long long> ans;
	
	for(int i = 0;i < z;i++){
		for(int j = 0;j < min((int)AB.size(), 3000);j++){
			ans.push_back(c[i] + AB[j]);
		}
	}
	
	sort(ans.begin(), ans.end(), greater<long long>());
	
	for(int i = 0;i < k;i++){
		cout << ans[i] << endl;
	}
	
	

	return 0;
}


Measured memory_bytes: 43240
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************

vector<ll> calc(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++){
        if (N % i == 0){
            ret.push_back(i); 
            ll j = N / i;
            if (i != j) ret.push_back(j);
        }
    }
    sort(ALL(ret));

    return ret;

}


int main(){

    ll N;
    cin >> N;

    const vector<ll> &vec1 = calc(N);
    const vector<ll> &vec2 = calc(N-1);

    ll ans = vec2.size() - 1;

    for(auto& v: vec1) {
        if (v == 1) continue;

        ll NN = N;
        while(NN % v == 0) NN /= v;
        if ((NN - 1) % v == 0) ans++;
    }


    cout << ans << endl;

    return 0;
}


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

int up[2000][2000];
int dn[2000][2000];
int ri[2000][2000];
int le[2000][2000];
string s[2000];
int h,w;


int main(){
    cin>>h>>w;
    for (int i = 0; i < h; i++)
    {
        cin>>s[i];
    }

    //////////////up
    for(int j = 0; j < w; j++){
        if(s[0][j]=='.'){
            up[0][j]=1;
        }else{
            up[0][j]=0;
        }
    }
    for (int i = 1; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(s[i][j]=='.'){
                up[i][j]=up[i-1][j]+1;
            }else{
                up[i][j]=0;
            }
        }
    }
    ////////////le
    for(int j = 0; j < h; j++){
        if(s[j][0]=='.'){
            le[j][0]=1;
        }else{
            le[j][0]=0;
        }
    }
    for (int i = 1; i < w; i++)
    {
        for (int j = 0; j < h; j++)
        {
            if(s[j][i]=='.'){
                le[j][i]=le[j][i-1]+1;
            }else{
                le[j][i]=0;
            }
        }
    }
    ////////////dn
    for(int j = w-1; j>=0; j--){
        if(s[h-1][j]=='.'){
            dn[h-1][j]=1;
        }else{
            dn[h-1][j]=0;
        }
    }
    for (int i = h-2; i>=0; i--)
    {
        for (int j = 0; j < w; j++)
        {
            if(s[i][j]=='.'){
                dn[i][j]=dn[i+1][j]+1;
            }else{
                dn[i][j]=0;
            }
        }
    }
    ////////////ri
    for(int j = h-1; j >=0 ; j--){
        if(s[j][w-1]=='.'){
            ri[j][w-1]=1;
        }else{
            ri[j][w-1]=0;
        }
    }
    for (int i = w-2; i >= 0; i--)
    {
        for (int j = 0; j <h ; j++)
        {
            if(s[j][i]=='.'){
                ri[j][i]=ri[j][i+1]+1;
            }else{
                ri[j][i]=0;
            }
        }
    }
    
    int ans = 0;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(ans<up[i][j]+dn[i][j]+ri[i][j]+le[i][j]-3){
                ans = up[i][j]+dn[i][j]+ri[i][j]+le[i][j]-3;
            }
        }
    }
    
    
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 66816
#include <iostream>

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

int main() {
  int K;
  std::cin >> K;

  long long res = 0;
  for (int a = 1; a <= K; ++a) {
    for (int b = 1; b <= K; ++b) {
      for (int c = 1; c <= K; ++c) {
        res += gcd(gcd(a, b), c);
      }
    }
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

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

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

int main(){
    int n; cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - (n % 1000) << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nk[0];
            int k = nk[1];
            long[] vs = new long[n];
            for (int i = 0; i < n; i++)
            {
                vs[i] = long.Parse(ReadLine());
            }
            Array.Sort(vs);
            long ans = long.MaxValue;
            for (int i = 0; i < n-(k-1); i++)
            {
                ans = Min(ans, Abs(vs[i] - vs[i + (k-1)]));
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18268
while True:
    L=input().split( )
    n=int(L[0])
    x=int(L[1])
    if n==0 and x==0:
        break
    i=0
    for c in range(n+1):
        for b in range(c):
            if x-c-b<b and x-c-b>0:
                i+=1
    print(i)



Measured memory_bytes: 5596
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >> S;
	bool flag_input = false;

	REP(i, 3) {
		if (S[i] == S[i + 1]){
			flag_input = true;
		}
	}	

	if (flag_input) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
// D - AtCoder Express 2
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N,M,Q; cin>>N>>M>>Q;
	vi L(M),R(M);
	rep(i, M) cin>>L[i]>>R[i];
	vvi X(N+1, vi(N+1, 0));
	rep(i, M) X[L[i]][R[i]]++;
	rep(l, N) rep(r, N) X[l+1][r+1] += X[l+1][r];
	rep(r, N) rep(l, N) X[l+1][r+1] += X[l][r+1];
	while(Q--){
		int p,q; cin>>p>>q;
		cout<< X[N][q] - X[p-1][q] <<endl;
	}
}

Measured memory_bytes: 3456
N, M, X = [int(n) for n in input().split()]

C = []
A = []

for i in range(N):
    c, *a = [int(n) for n in input().split()]
    C.append(c)
    A.append(a)

# C[N-1],A[N-1][M-1]

mc = -1
for k in range(2**N):
    kk = k
    rikai = [0] * M
    cost = 0
    for i in range(N):
        if kk & 1:
            cost += C[i]
            rikai = [r + a for (r, a) in zip(rikai, A[i])]
            if all([r >= X for r in rikai]):
                if mc == -1 or mc > cost:
                    mc = cost
        kk >>= 1

print(mc)


Measured memory_bytes: 9224
#include <stdio.h>

int n;
int a[100000];
int b[100000];
int c[100000];
int dp[100000][3];
int before = 4;
int next;

int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0;i < n; i++)
		scanf("%d %d %d", &a[i], &b[i], &c[i]);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if(j == 0)
				dp[i+1][j] = max(a[i] + dp[i][j+1], a[i] + dp[i][j+2]);
			if (j == 1)
				dp[i+1][j] = max(b[i] + dp[i][j-1], b[i] + dp[i][j+1]);
			if (j == 2)
				dp[i+1][j] = max(c[i] + dp[i][j-2], c[i] + dp[i][j-1]);
		}
	}
	int ans = dp[n][0];
	if (ans < dp[n][1])
		ans = dp[n][1];
	if (ans < dp[n][2])
		ans = dp[n][2];
	
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    B = inputList()
    
    ans = 0
    for i,val in enumerate(B):
        if i == len(B)-1:
            ans += val
        else:
            if val <= B[i+1]:
                ans += val
            else:
                ans += B[i+1]
            
    print(ans+B[0])
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 40048
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll x[200010], y[200010];
    rep(i,0,N) cin >> x[i] >> y[i];
    ll xd[200010], yd[200010];
    rep(i,0,N){
        xd[i] = x[i] + y[i];
        yd[i] = x[i] - y[i];
    }
    sort(xd, xd+N);
    sort(yd, yd+N);
    ll ans = max(xd[N-1] - xd[0], yd[N-1] - yd[0]);
    print(ans);

    

}

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

Measured memory_bytes: 9904
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int big = max(a, c);
    int small = min( a, c);
    
    int abbig = max( a, b );
    int abmin = min( a, b );
    
    int cbbig = max( c, b );
    int cbmin = min ( c, b );
    
    if ( big - small <= d ){
        cout << "Yes" << endl;
    } else if ( abbig - abmin <= d && cbbig - cbmin <= d ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
bool check(string a,string b)
{
	int a_len=a.length();
	int b_len=b.length();
	for(int i=0;i+b_len<=a_len;i++)
	{
		bool flag=true;
		for(int j=0;j<b_len;j++)
		{
		if(a[i+j]=='?'||a[i+j]==b[j]);
		else flag=false;
		}
		if(flag)
			return true;
	}
	return false;
}
int main() {
	string s,t;
	cin>>s>>t;
	if(!check(s,t))
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	int s_len=s.length();
	for(int i=0;i<s_len;i++)
	{
		if(s[i]=='?')
		for(char c='a';;c++)
		{
			s[i]=c;
			if(check(s,t))
				break;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
typedef long long LL;
int n, m, u[N], v[N], du[N], a[N];
set<int> G[N];
set<pair<int, int>> s;
pair<int, int> ans[N];
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &n);
	int fst = 1;
	while (fst < n) fst <<= 1;
	if (fst == n) {
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	printf("1 2\n2 3\n3 %d\n", n + 1);
	printf("%d 1\n%d %d\n", n + 3, n + 3, n + 2);
	if (n & 1) {
		for (int i = 4; i <= n; i += 2) {
			printf("%d %d\n", n + i, n + i + 1);
			printf("%d %d\n", n + i + 1, 3);
			printf("%d %d\n", i, 2);
			printf("%d %d\n", i + 1, i);
		}
	} else {
		int t = n;
		fst = fst >> 1;
		vector<int> q;
		while (t) {
			if (t >= fst) {
				q.push_back(fst);
				t -= fst;
			}
			fst >>= 1;
		}
		reverse(q.begin(), q.end());
		int head = q[0] == 2;
		for (int i = 4; i < n; i += 2) {
			if (head < q.size() && q[head] == i) {
				int pre = head == 0 ? 2 : q[head - 1];
				printf("%d %d\n", pre, i);
				printf("%d %d\n", i, i + 1);
				printf("%d %d\n", pre + 1, n + i + 1);
				printf("%d %d\n", n + i + 1, n + i);
				head++;
			} else {
				printf("%d %d\n", n + i, n + i + 1);
				printf("%d %d\n", n + i + 1, 3);
				printf("%d %d\n", i, 2);
				printf("%d %d\n", i + 1, i);
			}
		}
		printf("%d %d\n", q[0], n);
		printf("%d %d\n", q[head - 1], n + n);
	}
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
//manhhungking
long long n,x,dem,dem2;
int main()
{
    cin>>n;
    for(long long i=1;i<=n;++i){cin>>x;if(x%4==0)dem++; else if(x%2==0)dem2++;}
    if(dem2<2){
        if(dem*2>=n-1)cout<<"Yes";
        else cout<<"No";
    }
    else {
    if(dem*2+dem2>=n)cout<<"Yes";
    else cout<<"No";
    }
    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

template<class T>
struct ModInt {
    T x;
    ModInt(T x = 0) :x((x + mod) % mod) {}
    ModInt& operator+=(const ModInt a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(const ModInt a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator*=(const ModInt a) {
        (x *= a.x) %= mod;
        return *this;
    }
    ModInt operator+(const ModInt a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator-(const ModInt a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator*(const ModInt a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(T t) const {
        if (!t) return 1;
        ModInt a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(mod - 2);
    }
    ModInt& operator/=(const ModInt a) {
        return (*this) *= a.inv();
    }
    ModInt operator/(const ModInt a) const {
        ModInt res(*this);
        return res /= a;
    }
};
using mint = ModInt<long long>;


int n;
ll x[100005];
void solve() {
    cin >> n;
    rep(i, n) cin >> x[i];
    stack<ll> s;
    mint ans = 1;
    rep(i, n) {
        s.push(x[i]);
        if (x[i] < 2 * s.size() - 1) {
            ans *= s.size();
            s.pop();
        }
    }

    reps(i, s.size()) ans *= i;

    cout << ans.x << endn;
}

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


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double k,space,minn=9999999,now;
	cin>>n>>k;
	int f[n];
	for(int i=0;i<n;i++) 
	{cin>>f[i];if(f[i]==1) space=i;}
	if(n==k) cout<<1;
	else{
		for(int i=1;i<k-1;i++)
		{
			now=1+ceil((space-i)/(k-1))+ceil((n-1-space-(k-i-1))/(k-1));
			if(now<minn) minn=now;
		}
		cout<<min(minn,ceil(space/(k-1))+ceil((n-1-space)/(k-1)));
	}
}

Measured memory_bytes: 640
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
        	
            var s = cin.Read;
            //Console.WriteLine(s.Count(x => x == '1'));
            
            int counter = 0;

            if (s[0] == '1') { counter++; }
            if (s[1] == '1') { counter++; }
            if (s[2] == '1') { counter++; }

            Console.WriteLine(counter);
  
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}




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

int main(){
int a,b,x,y,z;

cin >> a >> b;

x=a+b;
y=a-b;
z=a*b;

if(x>=y && x>=z){
cout << x;
}else if(y>=x && y>=z){
cout << y;
}else{
cout << z;
}
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MX = 1e5 + 5;
const int MS = 1e5 + 5;
const int INF = 0x3f3f3f3f;


int n, A[MX], B[MX];

int main() {
    // FIN;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &A[i], &B[i]);
    }
    LL ans = 0;
    for(int i = n; i >= 1; i--) {
        int tmp = (A[i] + ans) % B[i];
        if(tmp) ans += B[i] - tmp;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
if n % digitSum(n) == 0:
    print("Yes")
else:
    print("No")

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

bool isKaibun(string str){
   for(int i = 0; i < str.length() / 2; i++){
      if(str[i] != str[str.length() - i - 1]){
        return false;
      }
    }
    return true;
}

signed main() {
  string str;
  cin >> str;
  bool isAllKaibun = isKaibun(str);
  bool isFrontKaibun = isKaibun(str.substr(0, (str.length() - 1) / 2));
  bool isBackKaibun = false;
  if((str.length() + 3) / 2 - 1 < str.length()){
    isBackKaibun = isKaibun(str.substr((str.length() + 3) / 2 - 1, str.length()));
  }

  if(isAllKaibun && isFrontKaibun && isBackKaibun){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static int MOD = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var ap = new List<int>();
        var am = new List<int>();
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(line[i]);
            if (w >= 0) ap.Add(w);
            else am.Add(-w);
        }
        var apc = ap.Count();
        var amc = am.Count();
        var c = checkPlus(n, k, apc, amc);
        if (c) calcPlus(k, ap, am);
        else calcMinus(k, ap, am);
    }
    static void calcPlus(int k, List<int> ap, List<int> am)
    {
        ap.Sort(); am.Sort();
        ap.Reverse(); am.Reverse();
        if (k == 1) { Console.WriteLine(ap[0]); return; }
        var pair = new List<long>();
        var p = k % 2 == 1 ? 1 : 0;
        while (p + 1 < ap.Count())
        {
            pair.Add((long)ap[p] * ap[p + 1]);
            p += 2;
        }
        p = 0;
        while (p + 1 < am.Count())
        {
            pair.Add((long)am[p] * am[p + 1]);
            p += 2;
        }
        pair.Sort(); pair.Reverse();
        long ans = k % 2 == 1 ? ap[0] : 1L;
        for (int i = 0; i < k / 2; i++)
        {
            var pp = pair[i] % MOD;
            ans *= pp;
            ans %= MOD;
        }
        if (ans < 0) ans += MOD;
        Console.WriteLine(ans);
    }
    static void calcMinus(int k, List<int> ap, List<int> am)
    {
        if (ap.Count() == 0)
        {
            am.Sort();
            var ans = 1L;
            for (int i = 0; i < k; i++)
            {
                ans *= -am[i];
                ans %= MOD;
            }
            if (ans < 0) ans += MOD;
            Console.WriteLine(ans);
            return;
        }
        else
        {
            var ans = 1L;
            for (int i = 0; i < am.Count(); i++)
            {
                ans *= -am[i];
                ans %= MOD;
            }
            for (int i = 0; i < ap.Count(); i++)
            {
                ans *= ap[i];
                ans %= MOD;
            }
            if (ans < 0) ans += MOD;
            Console.WriteLine(ans);
        }
    }
    static bool checkPlus(int n, int k, int apc, int amc)
    {
        if (apc > 0)
        {
            if (n == k) return amc % 2 == 0;
            else return true;
        }
        else return k % 2 == 0;
    }
}


Measured memory_bytes: 50052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  string s;
  cin >> s;
  if(s.at(s.size()-1)=='s'){
    s+="es";
  }else{
    s+='s';
  }
  cout << s;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a;
  set<int> bon{3},pon{0,1,6,8};
  cin >>a;
  a%=10;
  string ans="hon";
  if(bon.count(a)==1) ans="bon";
  if(pon.count(a)==1) ans="pon";
  cout <<ans;
}

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

int main(){

    ll int n,k;
    cin>>n>>k;
    ll int arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    ll int dp[n];
    memset(dp,0,sizeof(dp));
    dp[0] = 0;
    for(int i = 1;i<n;i++){
        dp[i] = INT_MAX;
        for(ll int j = i-1;j>=0 && j>=i-k;j--){
            dp[i] = min(dp[i],abs(arr[j]-arr[i])+dp[j]);
        }
    }

    cout<<dp[n-1]<<endl;

}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  cout << (a *3 + b) /2 << endl;
 return 0;
}

Measured memory_bytes: 256
arg = [" "]
while (get = gets)
  arg[-1,1] = *(get.downcase.chomp.split(" "))
end
arg.shift
max = 0
suspection = []
temp = 0
count = 0
arg.sort.each{|i|
  if temp == i
    count += 1
    if max < count
      suspection = [i]
      max = count
    elsif max == count
      suspection << i
    end
  else
    temp = i
    count = 1
  end}
puts [suspection, arg.sort_by{|a|a.length}[-1]].join(" ")

Measured memory_bytes: 6100
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
const int INF = 1<<30;

int dp[100010] = {0};

int main(){
	int n;
	cin >> n;
	int turn = 2;
	for (int j = 0; int(pow(6,j)) < 100010; j++) dp[int(pow(6,j))] = 1;
	for (int j = 0; int(pow(9,j)) < 100010; j++) dp[int(pow(9,j))] = 1;
	while(!dp[n]){
		for (int i = 100000; i > 0; i--){
			if(dp[i] == turn-1){
				for (int j = 0; i+int(pow(6,j)) < 100010; j++) dp[i + int(pow(6,j))] = turn;
				for (int j = 0; i+int(pow(9,j)) < 100010; j++) dp[i + int(pow(9,j))] = turn;
			}
		}
		turn++;
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 896
a, b, c = gets.chomp.split.map(&:to_i)
k = gets.to_i
while k >= 0
  if a < b && b < c
    break
  elsif a >= b
    b *= 2
  else
    c *= 2
  end
  k -= 1
end

puts (k >= 0)? "Yes" : "No"

Measured memory_bytes: 14292
#include <stdio.h>
 
int main() {
int x,y;
int i;

for(i = 0; i < 3000 ; i++){
scanf("%d%d",&x,&y);
if(x==0 && y ==0)
	break;
if (x>y){
printf("%d %d\n",y,x);
 }else {
	printf ("%d %d\n",x,y);
	}
}
return 0;
}

Measured memory_bytes: 600
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)


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


N = int(input())
l = deque()
if N == 0:
    print(0)
else:
    while N != 0:
        x = (-2) ** len(l)
        y = (-2) * x
        if abs(N) % abs(y) != 0:
            N -= x
            l.appendleft('1')
        else:
            l.appendleft('0')
    print(''.join(l))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  cout << (n-1) * (m-1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

int main(){
	
	int n;
	cin>>n;
	
	vector<int> cnt(26,Inf);
	
	for(int i=0;i<n;i++){
		string S;
		cin>>S;
		vector<int> S_cnt(26,0);
		
		for(int j=0;j<S.size();j++){
			S_cnt[S[j]-'a']++;
		}
		
		for(int j=0;j<26;j++){
			cnt[j] = min(cnt[j],S_cnt[j]);
		}
	}
	
	string ans = "";
	for(int i=0;i<26;i++){
		for(int j=0;j<cnt[i];j++){
			ans += (char)('a'+i);
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}



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

int main(){
    int N;
    int F[100][11];
    int P[100][11];
    int ans = -1100000000;
    cin >> N;
    rep(i,N) rep(j,10) cin >> F[i][j];
    rep(i,N) rep(j,11) cin >> P[i][j];

    for(int b=1; b<(1<<10); b++){
        int sum=0;
        for(int i=0; i<N; i++){
            int k=0;
            for(int j=0; j<10; j++){
                if((b>>j&1)&&F[i][j]){
                    k++;
                }
            }
            sum+=P[i][k];
        }
        if(ans<sum){
            ans=sum;
        }
    }

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

Measured memory_bytes: 256