akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  ll n;
  cin >> n;
  ll m = (ll)sqrt((double)n);

  auto d = [](ll x) {
    ll res = 0;
    while (x) {
      x /= 10;
      res++;
    }
    return res;
  };

  rrep(i, 1, m + 1) {
    if (n % i == 0) {
      cout << max(d(i), d(n / i)) << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		String mae = s.substring(0, 2);
		String ushiro = s.substring(2, 4);
		int maeNum = Integer.parseInt(mae);
		int ushiroNum = Integer.parseInt(ushiro);

		if (!isMonth(maeNum)  && !isMonth(ushiroNum)) {
			System.out.println("NA");
		} else if (isMonth(maeNum)  && isMonth(ushiroNum)) {
			System.out.println("AMBIGUOUS");
		} else if (isMonth(maeNum)  && !isMonth(ushiroNum)) {
			System.out.println("MMYY");
		} else if (!isMonth(maeNum)  && isMonth(ushiroNum)) {
			System.out.println("YYMM");
		}

	}

	private static boolean isMonth(int num){
		return num<13 && num>0;
	}
}


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

using std::vector;
struct edge {
	int to;
	int cost;
};
int dist[100100];
vector<edge> G[100100];
bool chk[100100];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		G[l].push_back({ r,d });
		G[r].push_back({ l,-d });
	}

	std::queue<int> que;
	std::queue<int> que2;
	for (int i = 1; i <= n; i++)que2.push(i);
	while (!que2.empty()) {
		int tmp = que2.front();
		que2.pop();
		if (!chk[tmp]) {
			que.push(tmp);
			chk[tmp] = true;
		}
		while (!que.empty()) {
			int idx = que.front();
			que.pop();

			for (edge e : G[idx]) {
				if (!chk[e.to]) {
					chk[e.to] = true;
					dist[e.to] = dist[idx] + e.cost;
					que.push(e.to);
				}
				if (dist[e.to] != dist[idx] + e.cost) {
					printf("No");
					return 0;
				}
			}
		}
	}
	printf("Yes");
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int x=0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        x^=a;
    }

    cout << ( x ? "No" : "Yes" ) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;

ll n;
str s1,s2;

int main() 
{

 fast();
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  
  cin >> n;
  vec a(n+1),b(n+1),c(n+1,0);
  f(i,1,n+1)
  {
    cin >> a[i];
  }
   f(i,1,n+1)
  {
    cin >> b[i];
  }
  f(i,1,n)
  {
    cin >> c[i];
  }
  ll s=0;
  f(i,1,n)
  {
    s+=b[a[i]];
    if(a[i+1]==a[i]+1)
    {
      s+=c[a[i]];
    }
  }
  s+=b[a[n]];
  cout<<s;

 
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if (k == 0) {
        cout << 0 << "\n";
        return 0;
    }
    k--;
    vector<lint> a(n), maxi(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (i)
            maxi[i] = maxi[i - 1];
        chmax(maxi[i], a[i]);
    }
    vector<int> use;
    for (int i = 0; i < n - 1; ++i) {
        if (i < k)
            use.push_back(1);
        else
            use.push_back(0);
    }
    sort(use.begin(), use.end());
    lint ret = inf;
    do {
        lint curr = a[0];
        lint cost = 0;
        for (int i = 1; i < n; ++i) {
            if (use[i - 1] == 1) {
                chmax(curr, maxi[i - 1]);
                if (a[i] <= curr) {
                    curr++;
                    cost += curr - a[i];
                } else {
                    curr = a[i];
                }
            }
        }
        chmin(ret, cost);
    } while (next_permutation(use.begin(), use.end()));
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
// AOJ 1248: The Balance
// 2017.12.17 bal4u@uu

#include <stdio.h>
#include <math.h>

int a, b;
int ansx, ansy;

void answer(int x, int y)
{
	if (x + y < ansx + ansy) ansx = x, ansy = y;
	else if (a*x + b*y < a*ansx + b*ansy) ansx = x, ansy = y;
}

int main()
{
	int d, t, x, ax, lim;

	while(scanf("%d%d%d", &a, &b, &d) && a > 0) {
		ansx = 0x7fffff, ansy = 0x7fffff;
		lim = d << 2; if (lim > 50000) lim = 50000;
		for (ax = x = 0; x < lim; x++, ax += a) {
			t = ax + d;
			if (!(t % b)) answer(x, t/b);
			t -= d << 1;
			if (t >= 0 && !(t % b)) answer(x, t/b);
			t = -t;
			if (t >= 0 && !(t % b)) answer(x, t/b);
		}
		printf("%d %d\n", ansx, ansy);
	}
	return 0;
}

Measured memory_bytes: 1736
n,k,s=map(int,input().split())
if s<10**9:
  for _ in range(k):
    print(s),
  for _ in range(n-k):
    print(s+1),
else:
  for _ in range(k):
    print(s),
  for _ in range(n-k):
    print(s-1),

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
struct dat{
  int T,t,f,lap;
  dat(){T=t=f=lap=0;}
  vector<dat> V;
  bool operator > (const dat &a)const{return T-t>a.T-a.t;}
};

bool onFront(const dat &a,const dat &b){return a.f==b.f&&1.0*a.t/a.T<1.0*b.t/b.T;}
bool checkJam(const dat &a,const dat &b){return onFront(a,b)&&a.T-a.t<b.T-b.t;}

int merge(vector<dat>&A,int idx){
  dat &a = A[idx];
  for(int i=0;i<idx;i++){
    dat &b = A[i];
    if(!checkJam(a,b))continue;
    a.t=0, a.lap-=a.f, a.f=!a.f;
    b.V.push_back(a);
    A.erase(A.begin()+idx);
    return 1e9;
  }
  return a.T-a.t;
}

void Push(vector<dat>&A,dat &a){
  for(int i=0;i<(int)a.V.size();i++)Push(A,a.V[i]);
  a.V.clear();
  if(a.lap) A.push_back(a);
}

int sim(vector<dat> A){
  int res=0,idx=0;
  vector<dat> tmp[2]={A};
  
  while(1){
    vector<dat> &A = tmp[idx];
    if(A.empty())break;
    sort(A.begin(),A.end(),greater<dat>());
    int mn = 1e9;
    for(int i=A.size()-1;i>=0;i--)mn=min(mn,merge(A,i));

    idx=!idx;
    vector<dat>&nA=tmp[idx];tmp[idx].clear();
    for(int i=0;i<(int)A.size();i++)
      if(A[i].t+mn<A[i].T) A[i].t+=mn,nA.push_back(A[i]);
      else A[i].t=0, A[i].lap-=A[i].f, A[i].f=!A[i].f,Push(nA,A[i]);

    res+=mn;
  }
  return res;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<dat> A(n);
    for(int i=0;i<n;i++)cin>>A[i].T>>A[i].lap;
    cout<<sim(A)<<endl;
  }
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string input; cin >> input;

    map<pair<string, string>, int> funami;
    for (int i = 0; i < (1 << n); i++) {
        string a, b;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) { 
                a += input[j];
            } else {
                b += input[j];
            }
        }
        funami[{a, b}]++;
    }
    /*
    for (auto i : funami) {
        cout << i.ffir << " " << i.fsec << " " << i.sec << endl;
    }
    */
    reverse(all(input));
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        string a, b;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) { 
                a += input[j];
            } else {
                b += input[j];
            }
        }
        ans += funami[{a, b}];
    }

    cout << ans << endl;
        

    return 0;
}


Measured memory_bytes: 91904
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, N) for (int i = 0; i < N; ++i)

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    rep(i, N) cin >> W[i];

    int minT = 101;
    int s1 = 0, s2 = 0;
    for (int i = 0; i < N; i++) {
        int T = i;
        bool flag = false;
        s1 = 0, s2 = 0;
        
        rep(j, W.size()) {
            if (j > T) flag = true;
            if (flag) {
                s1 += W[j];
            } else {
                s2 += W[j];
            }
        }
        minT = min(minT, abs(s1 - s2));
    }

    cout << minT << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;
int main(void){
    long long A,B,K;
    cin>>A>>B>>K;
if(A>K){
    cout<<A-K<<" "<<B<<endl;
}
else if(A+B>K){
    cout<<"0 "<<B-K+A<<endl;
}
else{
    cout<<"0 0"<<endl;
}
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

type con struct {
	a int
	b int
}

func conunt(d int, a []int) int {
	ans := 0
	for i := 0; i < len(a); i++ {
		if a[i] == d {
			ans++
		}
	}
	return ans
}

func test(s []int) {
	s[0] = 5
}
func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	m := iScan()
	k := iScan()
	a := make([]int, n)
	b := make([]int, m)
	sa := make([]int, n+1)
	sb := make([]int, m+1)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	for i := 0; i < m; i++ {
		b[i] = iScan()
	}
	sa[0] = 0
	sb[0] = 0
	for i := 1; i <= n; i++ {
		sa[i] = a[i-1] + sa[i-1]
	}
	for i := 1; i <= m; i++ {
		sb[i] = b[i-1] + sb[i-1]
	}
	best := 0
	//i本aを読む
	for i := 0; i <= n; i++ {
		at := i
		atime := sa[i]
		if k < atime {
			break
		}
		//fmt.Println(at)
		bt := searchLow(k-atime, sb)[1]
		if at+bt > best {
			best = at + bt
		}
	}
	fmt.Println(best)
}

func searchLow(d int, s []int) []int {
	ans := 0
	left := -1
	right := len(s)
	now := 0
	for {
		if right-left <= 1 {
			break
		}
		now = left + (right-left)/2
		if s[now] <= d {
			left = now
		} else {
			right = now
		}
	}
	//fmt.Println(ans, left)
	return []int{ans, left}
}

Measured memory_bytes: 13504
n = int(input())
for i in range(n):
    
    Tr = list(input())
    cou = 0
    ans = [Tr[cou]]
    while len(Tr) -1 > cou:
        
        if Tr[cou + 1] == "-":
            if Tr[cou + 3] in ans:
                cou += 3
                continue
            else:
                ans = ans + [Tr[cou + 3]]
          
        else:
            if Tr[cou + 3] in ans:
                cou += 3
                continue
            else:
                ans = [Tr[cou + 3]] + ans
        cou += 3
    a_s = ""
    for i in range(len(ans)):
        a_s = a_s + ans[i]
    print(a_s)

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL x,k,d; cin>>x>>k>>d;

    x = abs(x);

    //dump(x/d)

    if(x/d <= k){
        k -= x/d;
        x -= d*(x/d);
        //dump("hoge")
    }
    else{
        x -= d*k;
        k = 0;
    }

    //dump(x)
    //dump(k)

    LL result = 0;
    if(k%2 == 0){
        result = x;
    }
    else{
        result = abs(x-d);
    }
    cout<<result<<endl;
    
	return;
}

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

Measured memory_bytes: 3648
S = input()


#偶数を0,奇数を1にする場合
count01 = 0
for i in range(len(S)):
  if i%2 == 0:#偶数番目のとき
    if S[i] != "0":
      count01 += 1
  else:
    if S[i] != "1":
      count01 += 1
#偶数を1,奇数を0にする場合
count10 = 0
for i in range(len(S)):
  if i%2 == 0:#偶数番目のとき
    if S[i] != "1":
      count10 += 1
  else:
    if S[i] != "0":
      count10 += 1
      
print(min(count01,count10))

Measured memory_bytes: 3188
import sys
from collections import defaultdict, deque


def main():
    n, m = map(int, sys.stdin.readline().split())

    out_list = defaultdict(list)
    in_cnt = defaultdict(int)
    for _ in range(n - 1 + m):
        a, b = map(int, sys.stdin.readline().split())
        out_list[a].append(b)
        in_cnt[b] = in_cnt[b] + 1
    ans = [0] * (n + 1)
    que = deque([i for i in range(n) if in_cnt[i] == 0])

    while que:
        p = que.popleft()
        for i in out_list[p]:
            in_cnt[i] = in_cnt[i] - 1
            if in_cnt[i] == 0:
                que.append(i)
                ans[i] = p

    for i in ans[1:]:
        print(i)


if __name__ == "__main__":
    main()

Measured memory_bytes: 35440
#include <iostream>
#include <string>

using namespace std;

int main(){
        string a,b,c;
        cin >> a >> b >> c;
        if(a.back() == b.front() && b.back() == c.front()){
                cout << "YES" << endl;
        }else{
                cout << "NO" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int a[3][3];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> a[i][j];
		}
	}
	bool f = true;
	for(int i = 0; i < 2; i++){
		int x, y, z;
		x = a[i][0] - a[i + 1][0];
		y = a[i][1] - a[i + 1][1];
		z = a[i][2] - a[i + 1][2];
		if(x != y || y != z){
			f = false;
			break;
		}
	}
	if(f){
		for(int i = 0; i < 2; i++){
			int x, y, z;
			x = a[0][i] - a[0][i + 1];
			y = a[1][i] - a[1][i + 1];
			z = a[2][i] - a[2][i + 1];
			if(x != y || y != z){
				f = false;
				break;
			}
		}
	}
	cout << (f? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    int n,a[4][200];

    scanf("%d",&n);
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }

    int i,j;
    i=j=0;

    int sum[200]={},tmp=0;
    int max=-1;
    for(int i=0;i<n;i++){
        sum[i]=a[0][i]+tmp;
        tmp=sum[i];
        for(int j=i;j<n;j++){
            sum[i]+=a[1][j];
        }
        if(max<sum[i])max=sum[i];
        //printf("sum[%d]=%d\n",i,sum[i]);
    }
    printf("%d\n",max);

    return 0;
}

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

int min(int a, int b){
    return (a<=b) ? a : b ;
}


int main() {

    string s ;
    cin >> s ;

    int cntZ = 0;
    int cntO = 0;

    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='0') cntZ++ ;
        if(s[i]=='1') cntO++ ;
    }

    cout << min(cntO,cntZ)*2 << endl ;    

	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};
using Graph=vector<vector<edge>>;
using pint=pair<int,int>;
const int INF=1e9;

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

    int N; cin>>N;
    Graph G(N);
    for(int i=0;i<N;i++){
        int u,k; cin>>u>>k;
        while(k--){
            int v,c; cin>>v>>c;
            G[u].push_back({v,c});
        }
    }

    vector<int> dist(N,INF),finished(N,false);
    priority_queue<pint,vector<pint>,greater<pint>> Q;
    dist[0]=0;
    Q.push({0,0});
    while(!Q.empty()){
        int v=Q.top().second; Q.pop();
        if(finished[v]) continue;
        finished[v]=true;
        for(edge e:G[v]) if(chmin(dist[e.to],dist[v]+e.cost)){
            Q.push({dist[e.to],e.to});
        }
    }
    for(int i=0;i<N;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 7872
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_i = 0
min_temp = 100000000000000

for i, h in enumerate(H):

    temp = T - h * 0.006

    if abs(A - temp) < min_temp:
        min_i = i
        min_temp = abs(A - temp)

print(min_i + 1)


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


int main() {

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

  // C は大きい順に並び替えておく
  sort(C.begin(), C.end(), std::greater<long long>());

  // A + B を全部作る
  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]);
    }
  }

  // A + B を大きい順に並び替える
  sort(AB.begin(), AB.end(), std::greater<long long>());

  // (A + B) + C を作る
  // (A + B) は、大きい方から K 個と(A + B)の個数との小さい方を使う
  vector<long long> ABC;
  for (int i = 0; i < min(K, (int) AB.size()); i++) {
    for (int j = 0; j < Z; j++) {
      ABC.push_back(AB[i] + C[j]);
    }
  }

  // (A + B) + C を大きい順に並び替える
  sort(ABC.begin(), ABC.end(), std::greater<long long>());

  // 出力する
  for (int i = 0; i < K; i++) {
    cout << ABC[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 43368
import java.util.Scanner;
 class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        if(n==0) {
            System.out.println("0");
            return;
        }
        int[][] arr = new int[n][3];
        int[][]dp = new int[n][3];

        for(int i=0;i<n;++i){
            for(int j=0;j<=2;++j){
                arr[i][j]=input.nextInt();
            }
        }

        //base cases
        dp[0][0]=arr[0][0];
        dp[0][1]=arr[0][1];
        dp[0][2]=arr[0][2];

        for(int i=1;i<n;++i){

            //pick max points from previous day
            dp[i][0]=arr[i][0]+Math.max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=arr[i][1]+Math.max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=arr[i][2]+Math.max(dp[i-1][0],dp[i-1][1]);
        }
        System.out.println(Math.max(dp[n-1][0],Math.max(dp[n-1][1],dp[n-1][2])));
    }
}


Measured memory_bytes: 101704
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    //int end = (int)Math.sqrt(n) + 1;
    int end = n / 2;
    int[] cntOfDivisors = new int[n + 1];
    Arrays.fill(cntOfDivisors, 2);
    cntOfDivisors[0] = 0;
    cntOfDivisors[1] = 1;
    for(int i = 2; i <= end; i++){
      int t = 2;
      while(i * t <= n){
        cntOfDivisors[i * t]++;
        t++;
      }
    }
    long answer = 0;
    for(int i = 1; i <= n; i++){
      answer += cntOfDivisors[i] * (long)i;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 75480
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct E { lli i, j, c; };

lli n;
vector<lli> x, y;
vector<E> e;
vector<lli> uf;

lli root(lli i) {
  if (uf[i] < 0) return i;
  return uf[i] = root(uf[i]);
}

bool same(lli i, lli j) {
  return root(i) == root(j);
}

void unite(lli i, lli j) {
  if (!same(i, j)) uf[root(i)] = root(j);
}

int main() {
  cin >> n;
  init_n(x, n); init_n(y, n);
  for (lli i=0; i<n; ++i) cin >> x[i] >> y[i];

  vector<lli> ix(n); iota(begin(ix), end(ix), 0);
  sort(begin(ix), end(ix), [&](lli i, lli j) { return x[i] < x[j]; });
  for (lli i=0; i<n-1; ++i) 
    e.push_back({ix[i], ix[i+1], abs(x[ix[i+1]] - x[ix[i]])});
  vector<lli> iy(n); iota(begin(iy), end(iy), 0);
  sort(begin(iy), end(iy), [&](lli i, lli j) { return y[i] < y[j]; });
  for (lli i=0; i<n-1; ++i) 
    e.push_back({iy[i], iy[i+1], abs(y[iy[i+1]] - y[iy[i]])});

  sort(begin(e), end(e), [](E& e, E& f) { return e.c < f.c; });

  init_n(uf, n, -1);
  lli ans = 0;
  for (E& f : e) {
    // cout << f.i << ',' << f.j << ' ' << f.c << endl;
    if (!same(f.i, f.j)) {
      unite(f.i, f.j);
      ans += f.c;
    }
  }

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



Measured memory_bytes: 11504
#include<iostream>
using namespace std;
int main() {
	int a, b;
	while (cin >> a >> b) {
		if (a + b < 10){
			cout << 1 << endl;
		}
		else if (a + b < 100){
			cout << 2 << endl;
		}
		else if (a + b < 1000) {
			cout << 3 << endl;
		}
		else if (a + b < 10000) {
			cout << 4 << endl;
		}
		else if (a + b < 100000) {
			cout << 5 << endl;
		}
		else if (a + b < 1000000) {
			cout << 6 << endl;
		}
		else if (a + b < 10000000) {
			cout << 7 << endl;
		}
	}
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	for (int i=0;i<=s.length()-1-8;i++)
	cout<<s[i];
	return 0;
}
/* 
神犇保佑
STO 神犇 orz 
%%%ZXD
%%%JHJ 
*/

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

using namespace std;

int main(){
    int l,n,a[100],tong=0,apple,min=1309;
    cin >> n >> l;
    for(int i=0;i<n;i++){
        a[i]=l+i;
        tong+=a[i];
        //cout <<tong << " ";
        if(abs(a[i])<min){
            min=abs(a[i]);
            apple=i;
        }
    }
    cout << tong-a[apple];
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;

int main(){
  string str;
  cin >> str;
  int lres = str[0] - '0';
  for(int i=1; i<str.size(); i+=2){
    char ope = str[i];
    int tmp = str[i+1] - '0';
    if(ope == '+') lres += tmp;
    if(ope == '*') lres *= tmp;
  }
  vector<int> digits;
  int tmp = 1;
  for(int i=0; i<str.size()-1; i+=2){
    int digit = str[i] - '0';
    tmp *= digit;
    char ope = str[i+1];
    if(ope == '+') { digits.push_back(tmp); tmp = 1; }
  }
  digits.push_back(tmp * (str[str.size()-1] - '0'));
  int mres = 0;
  REP(i, digits.size()) mres += digits[i];
  int ans; cin >> ans;
  if(mres == ans and lres == ans) cout << "U" << endl;
  else if (mres == ans) cout << "M" << endl;
  else if (lres == ans) cout << "L" << endl;
  else cout << "I" << endl;
  return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#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 vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<pii> G[MAX];
int d[MAX];

int main() {
	long long k;cin>>k;
	rep(i,k) {
		G[i].push_back(pii(1,(i+1)%k));
		G[i].push_back(pii(0,i*10%k));
		d[i]=INF;
	}
	priority_queue<pii, vector<pii>, greater<pii>> Q;
	Q.push(pii(0,1));
	d[1]=0;
	while(!Q.empty()){
		pii p=Q.top();Q.pop();
		for(auto i:G[p.second]) {
			if(d[i.second]>d[p.second]+i.first) {
				d[i.second]=d[p.second]+i.first;
				Q.push(i);
			}
		}
	}
	cout<<d[0]+1<<endl;
}


Measured memory_bytes: 7288
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
   int n,T;
   cin>>n>>T;
   int cost=1001;
   int t,c;
   for(int i=0;i<n;i++){
      cin>>c>>t;
      if(t<=T)cost=min(c,cost);
    }
    if(cost==1001)cout<<"TLE"<<endl;
    else cout<<cost<<endl;
}

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

#define N 100000

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int aa[N];
	int n, i, j, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	qsort(aa, n, sizeof *aa, compare);
	ans = 0;
	for (i = 0; i < n; ) {
		j = i;
		while (j < n && aa[j] == aa[i])
			j++;
		ans += (j - i >= aa[i] ? (j - i) - aa[i] : j - i);
		i = j;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 892
//e-knapsack
#include<bits/stdc++.h>
#define ll long long
#define inf 1e9+1
using namespace std;
ll go(int n,int w,vector<int>wt,vector<int>prices){
	ll maxval=n*1000;
	int dp[n+1][maxval+1]={};
	for(int i=0;i<=maxval;i++){
		dp[1][i]=inf;
	}
	dp[1][0]=0;
	dp[1][prices[0]]=wt[0];
	for(int i=2;i<=n;i++){
		for(int j=0;j<=maxval;j++){
			dp[i][j]=dp[i-1][j];
			if(prices[i-1]>j)
			continue;
			dp[i][j]=min(dp[i-1][j-prices[i-1]]+wt[i-1],dp[i-1][j]);
		}
	}
	int ans=0;
	for(int i=0;i<=maxval;i++){
		if(dp[n][i]<=w){
			ans=max(ans,i);
		}
	}
	return ans;
}
int main(){
	int n,w;
	cin>>n>>w;
	vector<int>wt(n+1);
	vector<int>prices(n+1);
	for(int i=0;i<n;i++){
		cin>>wt[i]>>prices[i];
	}
	cout<<go(n,w,wt,prices);
}

Measured memory_bytes: 43024
#include <iostream>
#include <algorithm>

using namespace std;
  
int main()
{
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  double ret1;
  int ret2;

  ret1 = w * h / 2;
  if(w/2 == x && h/2 == y) ret2 = 1; else ret2 = 0;

  cout << ret1 << " " << ret2;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    for (int i = 0; i < n; i++) {
        cin >> m[i];
    }
    int sum = accumulate(m.begin(), m.end(), 0);
    int min = *min_element(m.begin(), m.end());
    x -= sum;
    n += x / min;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k,*data = list(map(int,read().split()))
mod = 998244353

dp = [0] * n
dp[0] = 1
route = 0
for j in range(1,n):
    for i in range(k):
        l,r = data[i*2:i*2+2]
        if(j >= l):
            route += dp[j-l]
        if(j > r):
            route -= dp[j-r-1]
        route %= mod
    dp[j] += route


print(dp[-1])

Measured memory_bytes: 69908
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
typedef long long ll;
const ll ccc=10000000;
bool prime[ccc+1];
vector<ll> pr;
void makeprime(){
	ll iii,jjj;
	for(iii=0;iii<=ccc;iii++){
		prime[iii]=true;
	}
	prime[0]=false;
	prime[1]=false;
	for(iii=2;iii*iii<=ccc;iii++){
		if(prime[iii]){
			for(jjj=2*iii;jjj<=ccc;jjj+=iii){
				prime[jjj]=false;
			}
		}
	}
	for(iii=2;iii<=ccc;iii++) if(prime[iii]) pr.push_back(iii);
}
ll gcd(ll x,ll y){
	if(x<y) swap(x,y);
	ll r=1;
	while(r!=0){
		r=x%y;
		if(r==0) return y;
		x=y;
		y=r;
	}
}
int main(){
	makeprime();
	ll n,m,x,y;
	cin >> n >> m;
	cin >> x;
	rep(i,n-1){
		ll a;
		cin >> a;
		x=gcd(x,a);
	}
	cin >> y;
	rep(j,m-1){
		ll b,c;
		cin >> b;
		c=gcd(y,b);
		if((double)b/c>(double)((ll)1e+14)/y+1e-9){
			cout << 0 << endl;
			return 0;
		}
		y*=(b/c);
	}
	if(x%y!=0){
		cout << 0 << endl;
		return 0;
	}
	ll p=x/y,ans=1;
	rep(i,pr.size()){
		int cnt=1;
		while(p%pr[i]==0){
			cnt++;
			p/=pr[i];
		}
		ans*=cnt;
		if(p==1) break;
	}
	if(p>1) ans*=2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21196
#include <bits/stdc++.h>
#define RI register int

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc();
  while (ch < '0' || ch > '9') ch = gc();
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
}

int const MAXN = 1 << 20, mod = 1e9 + 7;
int dp[2][MAXN], Limit[25][25];

inline int lowbit(int x) { return x & (-x); }
inline int Mo(int x) { return x >= mod ? x - mod : (x < 0 ? x + mod : x); }

int main() {
 // freopen("a.in", "r", stdin);
 // freopen("a.out", "w", stdout);
  int n, m, k;
  read(n), read(m), read(k); --n;
  for (RI i = 1, a, b, c; i <= k; ++i)
    read(a), read(b), read(c), Limit[a][b] = c + 1;
  int nxt = 0, cur = 1;
  int Max = (1 << n);
  dp[0][0] = 1;
  for (RI i = 1; i <= m; ++i) {
    for (RI j = 0; j < n; ++j) {
      swap(nxt, cur);
      memset(dp[nxt], 0, sizeof(dp[nxt]));
      int bit = 1 << j, lower = (Max - 1) ^ ((bit << 1) - 1);
      for (RI s = 0; s < Max; ++s) {
        if (Limit[i][j + 1] != 2)
          if (!(s & bit))
            dp[nxt][s] = Mo(dp[nxt][s] + dp[cur][s]);
        if (Limit[i][j + 1] != 1) {
          int nxts;
          if (s & bit) nxts = s;
          else if (!(s & lower)) nxts = s | bit;
          else nxts = (s | bit) ^ lowbit(s & lower);
          dp[nxt][nxts] = Mo(dp[nxt][nxts] + dp[cur][s]);
        }
      }
    }
  }
  int ans = 0;
  for (RI s = 0; s < Max; ++s) ans = Mo(ans + dp[nxt][s]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int n,ans;
  int p[20];

  cin>>n;
  ans=n-2;
  rep(i,n) cin>>p[i];

  rep(i,n-2){
    if((p[i+1]>p[i] && p[i+1]>p[i+2]) || (p[i+1]<p[i] && p[i+1]<p[i+2])) ans--;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];} 
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";} cout<<endl;
#define S second
#define F first
#define SZ(x) (int)x.size()
typedef long long ll;
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;

int main(){
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i = 0 ; i < n ; i++){
        cin>>v[i];
    }
    int c = 0;
    int mn = INT_MAX;
    for(int i = 0; i < n ; i++){
        if(v[i] <= mn) c++;
        mn = min(mn , v[i]);
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	for i := 0; i < max(a, b); i++ {
		if (a-i)*(a-i) == (b-i)*(b-i) {
			fmt.Println(i)
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;

ll n, ans;
ll fac[1000005];
ll fiv[1000005];
ll s[1000005];
ll a[1000005];

ll C(ll p, ll q)
{
    if(p < 0 || q < 0 || p < q) return 0;
    return fac[p] * fiv[q] % M * fiv[p - q] % M;
}

int main()
{
    cin>>n;
    fac[0] = 1;
    for(ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % M;
    fiv[n] = 1;
    ll t = fac[n];
    for(ll i = 0; (1 << i) <= M - 2; i++)
    {
        if((1 << i) & (M - 2)) fiv[n] *= t, fiv[n] %= M;
        t *= t;
        t %= M;
    }
    for(ll i = n - 1; i >= 0; i--)
    {
        fiv[i] = fiv[i + 1] * (i + 1) % M;
    }
    for(ll i = 1; i < n; i++)
    {
        s[i] = C(i - 1, n - i - 1) * fac[i] % M * fac[n - i - 1] % M;
        a[i] = s[i] - s[i - 1] + M;
        a[i] %= M;
        ans += a[i] * i % M;
        ans %= M;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 31488
n=int(input())
a=[[0,0,0]for i in range(n+1)]
for i in range(n):
    s,t,u=map(int,input().split())
    a[i+1][0]=max(a[i][1]+s,a[i][2]+s)
    a[i+1][1]=max(a[i][0]+t,a[i][2]+t)
    a[i+1][2]=max(a[i][1]+u,a[i][0]+u)
print(max(a[n]))

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

int main()
{
	int N, A, T;
	cin >> N;
	ll ans[2] = { 1,1 };
	for (int i = 0; i < N; i++) {
		cin >> T >> A;
		ll p = max((ans[0] % T == 0 ? ans[0] / T : ans[0] / T + 1), (ans[1] % A == 0 ? ans[1] / A : ans[1] / A + 1));
		ans[0] = T * p;
		ans[1] = A * p;
	}
	cout << ans[0] + ans[1] << endl;
}


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

int main(void) {
	char c;
	int cnt, len, ans;

	cnt = len = 0;
	while (true) {
		scanf("%c", &c);
		if (c == '\n')
			break;
		if (c == 'p')
			++cnt;
		++len;
	}
 
	ans = len / 2 - cnt;
	cout << ans << '\n';
	return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, K;
int a[1111];
vec<int> cand;

int func(int mask) {
   int cnt = 0;
   for (int i = 0; i < cand.size(); i++) {
      if ((cand[i] & mask) == mask) {
         cnt++;
      }
   }
   return cnt;
}


signed main() {
   cin >> N >> K;
   for (int i = 0; i < N; i++) {
      cin >> a[i];
   }

   for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
         sum += a[j];
         cand.push_back(sum);
      }
   }

   int mask = 0;
   for (int i = 40; i >= 0; i--) {
      if (func(mask | (1LL << i)) >= K) {
         mask |= (1LL << i);
      }
   }
   cout << mask << endl;

   return 0;
}

Measured memory_bytes: 5744
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int X;
	cin >> X;
	int ans = 1;
	for (int i = 2; i <= X; i++) {
		for (int j = i*i; j <= X; j*=i) {
			chmax(ans,j);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;

  if (N % 2 != 0) {
    // 奇数の場合
    std::cout << "No";
  } else {
    // 偶数の場合
    const int m = N / 2;
    for (int i = 0; i < m; ++i) {
      if (S[i] != S[m + i]) {
        std::cout << "No";
        return 0;
      }
    }
    std::cout << "Yes";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  char c; cin >> c;
  char res;
  if (c == 'A') res = 'T';
  if (c == 'T') res = 'A';
  if (c == 'C') res = 'G';
  if (c == 'G') res = 'C';
  cout << res << '\n';
}

Measured memory_bytes: 256
"use strict"

const main = (input) => {
    const _input = input.split(' ');
    const A = parseInt(_input[0], 10);
    const B = parseInt(_input[1], 10);
    const C = parseInt(_input[2], 10);

    const sum = B + C;
    if(sum > A){
        const remaining = sum - A;
        console.log(remaining);
    } else {
        console.log(0);
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense

H, W = [int(x) for x in input().split()]
C = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]


G = csgraph_from_dense(C, null_value=0)

d = floyd_warshall(G)

ans = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == 1 or A[i][j] == -1:
            continue
        ans += d[A[i][j]][1]


print(int(ans))




Measured memory_bytes: 37808
n = int(input())
A = list(map(int, input().split()))

a = sorted(A)
ave = sum(a)/n

ans = 0
ans2 = 0
flag = 0
for i in range(n):
    if a[i] == ave:
        ans = a[i]
        break
    elif a[i] > ave:
        if i == 0:
            ans = a[0]
        elif a[i] - ave < ave - a[i-1]:
            ans = a[i]
        elif a[i] - ave == ave - a[i-1]:
            flag = 1
            ans = a[i]
            ans2 = a[i-1]
        else:
            ans = a[i-1]
        break
    else:
        ans = a[i]

if flag == 0:
    print(A.index(ans))
else:
    print(min(A.index(ans), A.index(ans2)))

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

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

    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == '1')
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

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

//最大公約数?
void solve() {
    ll n, x; cin >> n >> x;
    Vl v(n+1);
    rep(i, 0, n) cin >> v[i];
    v[n] = x;
    sort(ALL(v));
    Vl a(n);
    rep(i, 0, n){
        a[i] = v[i+1] - v[i];
    }
    // rep(i, 0, n) cout << a[i] << " ";
    // cout << endl;
    ll ans = a[0];
    rep(i, 1, n){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

struct Edge {
    int to;
    int id;
};
using Graph = vector<vector<Edge>>;

Graph G;
int max_color = 0;
vector<int> parent, color, ans;
vector<vector<int>> child;

void dfs(int v) {
    int cnt = 0;
    for (auto e : G[v]) {
        if (e.to != parent[v]) {
            ++cnt;
            if (cnt == color[v]) ++cnt;
            parent[e.to] = v;
            child[v].push_back(e.to);
            ans[e.id] = cnt;
            color[e.to] = cnt;
            max_color = max(max_color, cnt);
            dfs(e.to);
        }
    }
}

int main() {
    int N;
    cin >> N;
    G = Graph(N);
    parent = vector<int>(N, -1);
    color = vector<int>(N, 0);
    ans = vector<int>(N - 1, 0);
    child = vector<vector<int>>(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back({b, i});
        G[b].push_back({a, i});
    }
    dfs(0);
    cout << max_color << endl;
    rep(i, N - 1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 12032
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

int n;
vector<int> l;

int main() {
	cin >> n;
	l.resize(2 * n);
	for (int i = 0; i < 2*n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());

	int ans = 0;
	for (int i = 0; i < 2 * n; i = i + 2) {
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
from collections import defaultdict

N = int(input())
MOD = 10**9+7

nglist = [
    "?AGC", "AGC?",
    "A?GC", "AG?C",
    "GAC?", "?GAC",
    "ACG?", "?ACG"
]
ng = {}
for t in "AGCT":
    for n in nglist:
        ng[n.replace('?', t)] = 1

dp = {"TTT": 1}

for i in range(N):
    ans = 0
    _dp = defaultdict(int)
    for k, v in dp.items():
        for t in "AGCT":
            s = k+t
            if s not in ng:
                _dp[s[1:]] += v
                ans = (ans+v) % MOD
    dp = _dp
    if i == (N-1):
        print(ans)


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    if (P == 2 || P == 5) {
        ll ans = 0;
        for (int i = N - 1; i >= 0; --i) {
            if ((S[i] - '0') % P == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    map<ll, ll> mp;
    ++mp[0];
    ll cur = 0;
    ll fac = 1;
    for (int i = N - 1; i >= 0; --i) {
        cur = (cur + (S[i] - '0') * fac) % P;
        fac *= 10;
        fac %= P;
        ++mp[cur];
    }

    ll ans = 0;
    for (auto e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4084
N = int(raw_input())
P = map(int, raw_input().split(' '))

count = 0

for i in range(N):
    if P[i] != i+1:
        count += 1
        
    if count > 2:
        print("NO")
        break
if count == 2 or count ==0:
    print("YES")


Measured memory_bytes: 2568