akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll n;cin>>n;
    vector<ll>v(n+1);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            v[j]+=1;
    }

    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans+=i*v[i];
    cout<<ans<<endl;

}


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

using namespace std;
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    
    string s; cin>>s;
    int sum =0;
    for(int i=0;i<s.size();i++){
        sum += (s[i] - '0');
    }
    if(sum % 9 ==0){
        cout <<"Yes" <<'\n';
    }else cout <<"No"<<'\n';



}



Measured memory_bytes: 3724
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Dec 28 16:01:15 2018
//
package main

import (
	"fmt"
	"math"
)

func main() {
	var Q int
	fmt.Scan(&Q)

	for i := 0; i < Q; i++ {
		var A, B int
		fmt.Scan(&A, &B)
		if B < A {
			A, B = B, A
		}

		if A == B {
			fmt.Println(2*A - 2)
		} else if A+1 == B {
			fmt.Println(2*A - 2)
		} else {
			c := int(math.Sqrt(float64(A * B)))
			if A*B == c*c {
				c--
			}
			if c*(c+1) >= A*B {
				fmt.Println(2*c - 2)
			} else {
				fmt.Println(2*c - 1)
			}
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    int A,B; cin>>A>>B;
    vector<int> a(3,1);
    a[A-1]--;
    a[B-1]--;
    rep(i,3){
        if(a[i]==1) cout<<i+1<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 250

int main(){
    int size,i,key[N];
    //for(i=0 ; i<N ; i++){
    key[1] = NULL;
    //}
    scanf("%d",&size);
    for(i=1 ; i<size+1 ; i++){
        scanf("%d",&key[i]);
    }
    for(i=1 ; i<size+1 ; i++)
    {
        printf("node %d: ",i);
        printf("key = %d, ",key[i]);
        if(i/2>0)printf("parent key = %d, ",key[i/2]);
        if(2*i <= size) printf("left key = %d, ",key[2*i]);
        if(2*i+1 <= size) printf("right key = %d, ",key[2*i+1]);
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
	int n;
	double sum=0.0;
	cin >>n;
	vector<int> x(n);
	vector<int> y(n);
	for(int i=0; i<n; i++){
		cin >>x[i];
	}
	for(int i=0; i<n; i++){
		cin >>y[i];
	}
	for(int i=0; i<3; i++){
		sum=0.0;
		for(int j=0; j<n; j++){
			sum+=pow(abs(x[j]-y[j]), (i+1.0));
		}
		sum=pow(sum, 1.0/(i+1.0));
		cout <<fixed <<setprecision(10) <<sum <<endl;
	}
	sum=0.0;
	for(int i=0; i<n; i++){
		sum =max((int)sum, abs(x[i]-y[i]));
	}
	cout <<fixed <<setprecision(10) <<sum <<endl;
    return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
int sum(int n){
    int res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}
signed main() {
    int X;cin>>X;
    X%=7;
    vector<string>Ans(7);
    Ans={"thu","fri","sat","sun","mon","tue","wed"};
    cout<<Ans[X]<<endl;
}



Measured memory_bytes: 3196
n, k = map(int, input().split())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
a.sort()
for i in range(n):
    if k - a[i][1] <= 0:
        print(a[i][0])
        break
    k -= a[i][1]


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

#define wait() system("pause")

int main () {
	int n; cin>>n;
	int ret = 0;
	for(int i=1; i<=n; i++) {
		int x, y; cin>>x>>y;
		ret += (y-x+1);
	} cout<<ret<<endl;
	//wait();
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int s, w;
    cin >> s >> w;
    if(s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};



int main(){
    LL a;string s;cin >> a >> s;
    LL b = 0;
    LL p = 1;
    for (int i = s.length()-1; i >= 0; i--) {
        if(s[i] == '.') continue;
        b += (s[i] - '0') * p;
        p *= 10;
    }
    cout << a * b / 100 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ad(x,y) (x=((x)+(y))%1000000007)
#define N 21
#define M 1050005
using namespace std;

int n,m,cnt,p0[N],p1[N],f[M][N],dp[M];
int main(){
	scanf("%d%d%d",&n,&m,&cnt); n--;
	int i,j,k,x,y,z;
	for (i=1; i<=cnt; i++){
		scanf("%d%d%d",&x,&y,&z);
		y=n-y;
		if (z) p1[x]|=1<<y; else p0[x]|=1<<y;
	}
	int tot=1<<n;
	for (i=0; i<tot; i++) if ((i&p1[1])==p1[1] && (i&p0[1])==0) dp[i]=1;
	for (i=0; i<tot; i++)
		for (j=0; j<n; j++){
			for (k=j-1; k>=0; k--) if (!(i>>k&1)) break;
			f[i][j]=(k<0)?i:(i|1<<k);
		}
	for (i=2; i<=m; i++){
		for (j=0; j<n; j++)
			for (k=0; k<tot; k++) if (k>>j&1) ad(dp[k],dp[f[k^(1<<j)][j]]);
		for (j=0; j<tot; j++) if ((j&p1[i])!=p1[i] || (j&p0[i])!=0) dp[j]=0;
	}
	for (j=1; j<tot; j++) ad(dp[0],dp[j]);
	printf("%d\n",dp[0]);
	return 0;
}


Measured memory_bytes: 49536
#include <cstdio>
int main(){
  char YM[5];
  int flag=0;
  scanf("%s",YM);
  if((YM[0]=='0' && YM[1]>='1')||(YM[0]=='1' && YM[1]<='2'))flag+=1;
  if((YM[2]=='0' && YM[3]>='1')||(YM[2]=='1' && YM[3]<='2'))flag+=2;
  switch(flag){
    case 0:printf("NA\n");break;
    case 1:printf("MMYY\n");break;
    case 2:printf("YYMM\n");break;
    case 3:printf("AMBIGUOUS\n");break;
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];

int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i, 0, a.size()) {
        cin >> a[i];
    }
    ll money = 1000;
    rep(i, 0, a.size()-1) {
        if(a[i] < a[i+1]) {
            ll cnt = money/a[i];
            money = money%a[i];
            money += a[i+1] * cnt;
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 5980
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int M = 1e3 + 10;
const int N = 1e6 + 10;

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " ";
    cout << max(0, a + b - n);
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("a.in", "r", stdin);
    solve();
}


Measured memory_bytes: 256
N=int(input())
S=input()

ans=''
b=0
for c in reversed(S):
    if c==')':
        b+=1
        ans=c+ans
    else:
        if b==0:
            ans=c+ans
            ans+=')'
        else:
            b-=1
            ans=c+ans
for _ in range(b):
    ans='('+ans
print(ans)

Measured memory_bytes: 3060
n,m = map(int, raw_input().split())
adj = [[] for i in range(n)]

for i in range(m):
    a,b = map(int, raw_input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


q = [(0,0)]
all_visited = (1 << n) - 1
ans = 0

while len(q) > 0:
    u,visited = q.pop(0)
    visited = visited ^ (1 << u)
    
    if visited == all_visited:
       ans += 1 
    
    for v in adj[u]:
        if visited & (1 << v):
            continue
        q.append((v,visited))

print ans        

Measured memory_bytes: 2948
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int m;
    cin>>m>>m;
    int x;
    cin>>x;
    int a[m];
    rep(i,m){
        cin>>a[i];
    }
    x=lower_bound(a,a+m,x)-a;
    cout<<min(x,m-x)<<endl;
    return 0;
}

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

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

int main(void)
{
    string S;

    cin >> S;
  
    if ((S[2] == S[3]) && (S[4] == S[5]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

   

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,i;
	i = 0;
	scanf("%d %d %d",&a,&b,&c); //a=3 b=2 c=1 i=0
	if(a > b){
		i = a; //a=3 b=2 c=1 i=3
		a = b; //a=2 b=2 c=1 i=3
		b = i; //a=2 b=3 c=1 i=3
	}if(a > c){
		i = a; //a=2 b=3 c=1 i=2
		a = c; //a=1 b=3 c=1 i=2
		c = i; //a=1 b=3 c=2 i=2
	}if(b > c){
		i = b;
		b = c;
		c = i;
	}
	printf("%d %d %d\n",a,b,c);

return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
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 print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    if(A <= 5){
        print(0);
    }else if(A <= 12){
        print(B/2);
    }else{
        print(B);
    }
    
}

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

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

  if (N == 1) {
    cout << "Hello World" << endl;
  } else  if(N == 2) {
    int A,B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}


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

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = new bool[n + 1];
        var b = new int[m];
        for (int i = 0; i < m; i++)
        {
            var w = int.Parse(Console.ReadLine().Trim());
            a[w] = true;
            b[i] = w;
        }
        Array.Reverse(b);
        var hs = new HashSet<int>();
        foreach (var x in b)
            if (!hs.Contains(x)) { Console.WriteLine(x); hs.Add(x); }
        for (int i = 1; i < n + 1; i++)
            if (!a[i]) Console.WriteLine(i);
    }
}


Measured memory_bytes: 16760
N = int(input())
A = int(input())
B = int(input())
C  = int(input())
D = int(input())
E = int(input())

if(N%min(A,B,C,D,E)!=0):
    ans = N//min(A,B,C,D,E) + 5
else:
    ans = N//min(A,B,C,D,E) + 5 - 1


print(ans)

Measured memory_bytes: 3064
import sys,math
input = sys.stdin.readline

N,M = list(map(int,input().split()))
S = input().rstrip()
T = input().rstrip()

L = N*M//math.gcd(N,M)

sn = L//M
tm = L//N

for i in range(N//sn):
    if S[i*sn] == T[i*tm]:
        continue
    else:
        print(-1)
        exit()
print(L)
    


Measured memory_bytes: 9144
#include<stdio.h>

int main()
{
  int res,N,A,B,p1,p2;
  scanf("%d %d %d",&N,&A,&B);
  p1 = A * N;
  p2 = B;
  res = p1 > p2 ? p2 : p1;
  printf("%d\n",res);
  return 0;
}



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

int main(void){
    int n,k,x,y,ans = 0;
    cin >> n >> k >> x >> y;
    if(n >= k){
        ans += k * x;
        ans += (n - k) * y;
    } else {
        ans += n * x;
    }
    cout << ans << endl;
}

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

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<int> b;

  if (n % 2 == 0) {
    for (int i = n-1; i > 0; i-=2) {
      printf("%d ", a[i]);
    }

    for (int i = 0; i < n; i+=2) {
      printf("%d ", a[i]);
    }
  } else {
    for (int i = n-1; i >= 0; i-=2) {
      printf("%d ", a[i]);
    }

    for (int i = 1; i < n; i+=2) {
      printf("%d ", a[i]);
    }
  }
}

Measured memory_bytes: 2944
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
use std::cmp::*;
fn main() {
    input! {
        n:usize,
        m:i32,
        q:i32,
        abcd:[(Usize1,Usize1,i32,i32);q]
    }
    let mut ans = 0;
    let mut A: Vec<i32> = vec![1; n];
    A[n - 1] = 0;

    let mut ans = 0;
    while next(&mut A, n, m) {
        let mut tmp = 0;
        for &(a, b, c, d) in abcd.iter() {
            if A[b] - A[a] == c {
                tmp += d;
            }
        }
        //println!("a={:?}, tmp={}", A, tmp);
        ans = max(ans, tmp);
    }
    println!("{}", ans);
}

fn next(a: &mut Vec<i32>, n: usize, m: i32) -> bool {
    let mut i = n - 1;
    while a[i] == m {
        if i == 0 {
            return false;
        } else {
            i -= 1;
        }
    }
    a[i] += 1;
    for j in i + 1..n {
        a[j] = a[i];
    }
    true
}


Measured memory_bytes: 2188
def min2(x,y):
    return x if x < y else y

from math import ceil
D, G = map(int, input().split())
P = []
C = []
for _ in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)
res = float("inf")
for bit in range(1<<D):
    temp = 0
    cnt = 0
    for i in range(D):
        if (bit>>i)&1:
            temp += 100*(i+1)*P[i]+C[i]
            cnt += P[i]
    if temp >= G:
        res = min2(res, cnt)
        continue
    for i in reversed(range(D)):
        if not (bit>>i)&1:
            k = ceil((G-temp)/(100*(i+1)))
            if k >= P[i]:
                temp += 100*(i+1)*(P[i]-1)
                cnt += P[i]-1
            else:
                cnt += k
                res = min2(res, cnt)
                break
print(res)


Measured memory_bytes: 67896
import java.util.Scanner;

/**
 *
 * @author HP
 */
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n  = s.nextInt();
        int m  = s.nextInt();
        int limit = s.nextInt();

        int a[] = new int[n];
        long sumA[] = new long[n+1];
        int b[] = new int[m];
        long sumB[] = new long[m+1];

        for(int i = 1; i <= n; ++i) {
            a[i-1] =  s.nextInt();
            sumA[i] = sumA[i-1] + a[i-1];
//            System.out.println(sumA[i]);
        }

        for(int i = 1; i <= m; ++i) {
            b[i-1] =  s.nextInt();
            sumB[i] = sumB[i-1] + b[i-1];
//            System.out.println(sumB[i]);
        }

        int j = m;
        int ans = 0;
        for(int i = 0; i <= n; i++) {
            if(sumA[i] > limit) {
                break;
            }
            while(limit - sumA[i] < sumB[j]) {
                j--;
            }
            ans = Math.max(ans,i+j);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 65024
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int d[300001]={};

const ll INF=100000000001;
int main() {
	int k,n;

	cin>>k>>n;
	if(k%2==0){
		cout<<k/2;
		for(int i=1;i<n;i++)cout<<" "<<k;
		cout<<endl;
//	}else if(k==1){
//		cout<<"1";
//		for(int i=2;i<n/2+n%2+1;i++)cout<<" 1";
//		cout<<endl;
//
	}else{
		int s=n/2;
		int kk=1;
		for(int i=1;i<n+1;i++)d[i]=(k/2+1);
		int h=1;
		while(s>0){
			if(s>=kk*(d[h]-1)){
				s-=kk*(d[h]-1);
				d[h]=1;
				if(s>0){
					d[h]=0;
					s--;
				}
				h++;
				kk*=k;
				kk++;
			}else{
				d[h]-=s/kk;
				s%=kk;
				if(s>0){
					d[h]--;
					s--;
					for(int i=1;i<h;++i)d[i]=k;
					h=1;
					kk=1;
				}
			}
		}
		cout<<d[n];
		for(int i=n-1;i>0&&d[i]>0;i--)cout<<" "<<d[i];
		cout<<endl;

	}
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
int main() {
	int N;
	int one[200], two[200], three[200];
	scanf("%d", &N);
	rep(i, N) scanf("%d %d %d", &one[i], &two[i], &three[i]);
	int point[200] = {0};
	rep(i, N) {
		bool flag = true;
		rep(j, N) {
			if(i == j) continue;
			if(one[i] == one[j]) {
				flag = false;
				break;
			}
		}
		if(flag) point[i] += one[i];
	}
	rep(i, N) {
		bool flag = true;
		rep(j, N) {
			if(i == j) continue;
			if(two[i] == two[j]) {
				flag = false;
				break;
			}
		}
		if(flag) point[i] += two[i];
	}
	rep(i, N) {
		bool flag = true;
		rep(j, N) {
			if(i == j) continue;
			if(three[i] == three[j]) {
				flag = false;
				break;
			}
		}
		if(flag) point[i] += three[i];
	}
	rep(i, N) printf("%d\n", point[i]);
	return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define INF 100000
#define MAX 100005

using namespace std;
#define For(i, a, b) for ( int i = (a); i < (b); i++ )
#define Fors(i, sz) for ( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset (a, s, sizeof (a))
 #define EXPLORED 2
#define VISITED 1
#define UNVISITED 0
typedef long long int ll;
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <int > vi;
 vector<vii> adj(MAX);
 vi dfs_num,dfs_parent,dfs_low;
 vi d(100005,INF),p;
 queue <int> q;
int dfsNumberCounter=0,dfsRoot,rootChildren=0;
int vis[100005];
int s=5;
void bfs(int a)
 {
  q.push(a);
  d[a]=0;
  while(!q.empty())
{
 
  int u=q.front();
  q.pop();
  cout<<u<<" ";
  for(int i=0;i<adj[u].size();i++)
  {
    
    ii v=adj[u][i];
    if(d[v.first]==INF)
    {
      // cout<<"count= "<<cnt++<<endl;
      d[v.first]=d[u]+1;
      if(vis[i]==0)
      q.push(v.first);
      p[v.first]=u;
    }
  }
}
}
int main()
{
  //int ans[10000][100000];
 //  freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 ll n,a,b,c,ans=0,w;
cin>>w>>a>>b;
if(b<a)
{
  if(b+w>=a)
    ans=0;
  else
    ans=a-(b+w);
}
else if(b>=a && b<=a+w)
ans=0;
else
  ans=b-(a+w);
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 2944
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using usize = std::size_t;
using isize = std::ptrdiff_t;
using u64 = std::uint64_t;

static constexpr u64 mod = 1000000007;

template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  usize n, cc;
  std::cin >> n >> cc;
  static constexpr usize C = 100;
  static constexpr usize A = 10000;

  std::array<std::array<isize, A + 1>, C + 1> dp;
  for (auto &v : dp) {
    std::fill(v.begin(), v.end(), std::numeric_limits<isize>::min());
  }
  dp[0][0] = 0;
  for (usize nn = 0; nn != n; ++nn) {
    usize a, b, c;
    std::cin >> a >> b >> c;
    for (usize i = C + 1; i-- != 0;) {
      for (usize j = 0; j <= A; ++j) {
        if (i >= c && j >= a) {
          chmax<isize>(dp[i][j], dp[i - c][j - a] + b);
        }
        if (i >= c && j >= b) {
          chmax<isize>(dp[i][j], dp[i - c][j - b] + a);
        }
      }
    }
  }

  usize ans = 0;
  for (usize i = 0; i <= C; ++i) {
    for (usize j = 0; j <= A; ++j) {
      if (i <= cc && dp[i][j] >= 0) {
        chmax(ans, std::min<usize>(j, dp[i][j]));
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 10992
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<cmath>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n;
string s, t;
signed main(){
	cin >> n >> s >> t;
	rep(i, n) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,c,sat;

	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		sat=b;
		b=a;
		a=sat;
	}
	if(b>c){
		sat=c;
		c=b;
		b=sat;
	}
	if(a>b){
		sat=b;
		b=a;
		a=sat;
	}
	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 596
s = list(input())
#print(s)

len_s = len(s)
start = -1
end = -1
for i in range(len_s):
    i_1 = i + 1
    i_2 = i + 2
    if i_1 < len_s:
        if s[i] == s[i_1]:
            start = i + 1
            end = i_1 + 1
            break
    if i_2 < len_s:
        if s[i] == s[i_2]:
            start = i + 1
            end = i_2 + 1
            break

print(start, end)

Measured memory_bytes: 3956
n = int(input())
d = {}
ans = 0
for _ in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in d:
        d[s] += 1
        ans += d[s]
    else:
        d.update({s : 0})
print(ans)

Measured memory_bytes: 17808
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[100009],dp[100009][4],k,z[4],zx,i,j,xc,pas;
long long g[100009];
vector <long long> v[100009];
map <char, long long> m;
string s;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>k;
    //cin>>r>>s>>p;
    cin>>z[1]>>z[2]>>z[3];
    m['r']=1;m['s']=2;m['p']=3;
    cin>>s;
    for(b=0; b<a; b++){
        if(s[b]=='r'){
            g[b+1]=m['p'];
        }
        if(s[b]=='s'){
            g[b+1]=m['r'];
        }
        if(s[b]=='p') g[b+1]=m['s'];
    }
    for(b=1; b<=a; b++){
        v[b%k].push_back(b);
    }
    for(b=0; b<k; b++){
        if(v[b].size()==0) continue;
        zx=v[b][0];
        for(d=1; d<=3; d++){
            if(d==g[zx]){
                dp[zx][d]=z[d];
            }else{
                dp[zx][d]=0;
            }
        }
        for(c=1; c<v[b].size(); c++){
            zx=v[b][c];
            xc=v[b][c-1];
            for(d=1; d<=3; d++){
                if(d==g[zx]) i=z[d]; else i=0;
                for(e=1; e<=3; e++){
                    if(d==e) continue;
                    if(dp[zx][d]<dp[xc][e]+i) dp[zx][d]=dp[xc][e]+i;
                }
            }
        }
        i=0;
        for(d=1; d<=3; d++){
            if(i<dp[v[b][v[b].size()-1]][d]) i=dp[v[b][v[b].size()-1]][d];
        }
//        cout<<i<<endl;
        pas+=i;
    }
    cout<<pas;
    return 0;
}


Measured memory_bytes: 9424
from itertools import permutations
import copy
n,m = map(int,input().split())
g = [[0]*n for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    g[a-1][b-1] = 1
    g[b-1][a-1] = 1
stock = list(permutations([i for i in range(1,n)]))
#print(stock)
ans = 0
for i in stock:
    h = copy.deepcopy(g)
    cnt = 1
    p = 0
    for k in i:
        if h[p][k] == 0:
            break
        else:
            cnt += 1
            p = k
    if cnt == n:
        ans += 1
    #print(i,cnt,h,g)
print(ans)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a, b, c;
    cin >> a >> b >> c;
    a -= b;
    a -= c;
    if(a <= 0) cout << abs(a) << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

A = []
B = []
for i in range(m):
    a, b= map(int, input().split())
    A.append(a)
    B.append(b)
t = 0
ans = 0
for i in range(10000):
    t = 0
    if len(str(i)) == n:
        for j in range(m):
            if int(str(i)[A[j] - 1]) == B[j]:
                t += 1
        if t == m:
            print(i)
            ans = 1
            break
if ans == 0:
    print(-1)

Measured memory_bytes: 40560
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

int main(){
  int a[1000],b[1000],c[1000],i,j,cnt=0,cnt2=0;

  j=0;
  while(scanf("%d,%d,%d",&a[j],&b[j],&c[j])!=EOF){
    if(a[j] == b[j])cnt2++;
    else if(pow(a[j],2)+pow(b[j],2) == pow(c[j],2))cnt++;

    j++;
  }  

  cout << cnt << endl;
  cout << cnt2 << endl;


}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cstring>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

void solve() {
    int n,m;
    cin >> n >> m;
    int k[n];
    int map[m+1];
    memset(map,0,sizeof(map));
    for(int i = 0;i < n;i++){
        cin >> k[i];
        
        for(int j = 1; j < k[i]+1;j++){
            int a;
            cin >> a;
            map[a]++;
        }
         
    }
    int ans = 0;
    for(int i = 1; i < m+1;i++){
        if(map[i] == n) ans++;
    }
    cout << ans << endl;

}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    char[] S = new char[N];
    int[] count = new int[5];
    int check =0;
    for (int i =0; i<N; i++) {
      S[i] = sc.next().charAt(0);
      if (S[i] == 'M') count[0]++;
      if (S[i] == 'A') count[1]++;
      if (S[i] == 'R') count[2]++;
      if (S[i] == 'C') count[3]++;
      if (S[i] == 'H') count[4]++;
    }
    for (int i =0; i<5; i++) {
      if (count[i] == 0) check++;
    }
    if (check >= 3) {
        System.out.println(0);
    } else {
      long ans =0;
      for (int i =0; i<=2; i++) {
        for (int j =i+1; j<=3; j++) {
          for (int k =j+1; k<=4; k++) {
            ans += (long)count[i] * count[j] * count[k];
          }
        }
      }
      System.out.println(ans);
    }
  }
}   

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

using namespace std;

using ll = long long;
#define REP(i, n) for(int (i) = 0;(i) < (n);(i)++)
#define all(x) (x).begin(),(x).end()
struct Trie{
  struct Node{
      int c;
      bool accept;
      vector<int> nextid;
      Node(int c):c(c),accept(false){
        nextid.assign(26,-1);
      }
  };
  vector<Node> g;
  Trie(){
    g.emplace_back(0);
  }
  bool match(int tmp,int c){
//    assert(tmp < g.size());
    return (g[tmp].nextid[c] != -1) && g[g[tmp].nextid[c]].accept;
  }
  void insert(string& s){
    int tmp = 0;
    for(int i = 0;i < s.size();i++){
      int& nid = g[tmp].nextid[s[i] - 'a'];
      if(nid == -1){
        nid = g.size();
        g.emplace_back(s[i] - 'a');
      }
      tmp = nid;
    }
    g[tmp].accept = true;
  }
};

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

  int n;
  cin >> n;
  vector<string> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    reverse(all(a[i]));
  }
  sort(a.begin(),a.end(),[](string& s,string& t){
    return s.size() < t.size();
  });

  Trie trie;
  ll ans = 0;
  for(int i = 0;i < n;i++){
    string s = a[i];
    int sz = s.size();
    vector<int> last(26,-1);
    for(int j = sz - 1;j >= 0;j--) {
      if(last[s[j] - 'a'] == -1){
        last[s[j] - 'a'] = j;
      }
    }
    int tmp = 0;
    for(int j = 0;j < sz;j++){
      for(int c = 0;c < 26;c++){
        if(j <= last[c] && trie.match(tmp,c)){
          ans++;
        }
      }
      int nid = trie.g[tmp].nextid[s[j] - 'a'];
      if(nid == -1) break;
      else tmp = nid;
    }
    trie.insert(s);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 144584
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

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

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll h1,m1,h2,m2,k;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>h1>>m1>>h2>>m2>>k;
		ll l1 =h1*60+m1;
		ll l2 = h2*60+m2;
		ll l3 = l2-l1;
		cout<<l3-k<<endl;
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 5988
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>

using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}

ll extgcd(ll a, ll b, ll& x, ll& y, ll k){
	ll d=a;
	if(b!=0){
		d=extgcd(b, a%b, y, x, k);
		y-=(a/b)*x;
	}else{
		x=k/a, y=0;
	}
	return d;
}

long long int powmod(long long int a, long long int k, long long int m){ //0<=a<=1e9, 0<k<=1e18, 0<m<=1e9
	if(a==0){
		return 0;
	}
	long long int apow[60], c[60];
	for(int i=0; i<60; i++){
		if(i==0){
			apow[i]=a;
			c[i]=1;
		}else{
			apow[i]=apow[i-1]*apow[i-1]%m;
			c[i]=c[i-1]*2;
		}
	}
	long long int ans=1;
	for(int i=59; i>=0; i--){
		if(k>=c[i]){
			ans=ans*apow[i]%m;
		}
		k=k%c[i];
	}
	return ans;
}

long long int eulerphi(long long int n){
	if(n==1) return 1;
	long long int res=n;
	for(long long int i=2; i*i<=n; i++){
		if(n%i==0){
			res=res/i*(i-1);
			while(n%i==0) n/=i;
		}
	}
	if(n!=1) res=res/n*(n-1);
	return res;
}

ll ans(ll a, ll m){  // ans>=30
	if(a==0) return m;
	if(m==1) return 30;

	ll m1=m, m2=1;
	ll d;
	while((d=gcd(a, m1))>1){
		m1/=d;
		m2*=d;
	}
	ll phi1=eulerphi(m1);
	ll s=ans(a, phi1);
	ll k1=powmod(a, s, m), k2=powmod(a, s, phi1), k;
	ll x, y;
	extgcd(m, phi1, x, y, k2-k1);
	k=m*(x%phi1)+k1;
	while(k<30) k+=(m*phi1);
	return k;
}

int main()
{
	int q;
	scanf("%d", &q);
	for(int i=0; i<q; i++){
		ll a, m, k;
		scanf("%lld %lld", &a, &m);
      k=ans(a, m);
		printf("%lld\n", k);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int r,D,x;
  int ANS;
  int i;
  scanf("%d%d%d",&r,&D,&x);
  for(i=1;i<=10;i++){
    x=r*x-D;
    printf("%d\n",x);
  }
return 0;
}


Measured memory_bytes: 128
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}
int a;
main(){
	cin>>a;
	dump(1110-a);
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, P> PP;

P toll(string s){
    ll h = 0, l = 0;
    int n = s.size();
    ll k = 1;
    for(int i = 0; i < n; i++){
        if(i < 9) l += ((ll)(s[i] - 'a' + 1)) * k;
        else h += ((ll)(s[i] - 'a' + 1)) * k;
        k *= 100;
        if(i == 8) k = 1;
    }
    return P(h, l);
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<PP, int> mp;
    for(int i = 0; i < (1 << n); i++){
        string r = "";
        string b = "";
        for(int j = 0; j < n; j++){
            if(i & (1 << j)) r += s[n * 2 - 1 - j];
            else b += s[n * 2 - 1 - j];
        }
        mp[PP(toll(r), toll(b))]++;
    }
    ll ans = 0;
    for(int i = 0; i < (1 << n); i++){
        string r = "";
        string b = "";
        for(int j = 0; j < n; j++){
            if(i & (1 << j)) r += s[j];
            else b += s[j];
        }
        ans += mp[PP(toll(r), toll(b))];
    }
    cout << ans << endl;
}

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

int main(){
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fast_io();
    
    int n, k;
    cin>>n>>k;

    ll a[n];

    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    ll b[n];
    b[0] = 0;  

    for(int i=1; i<n; i++){
        ll mindist = INT_MAX;
        for(int j=i-1; j>=0 && j >= i-k; j--){
            mindist = min(mindist, abs(a[i]-a[j])+b[j]);    
        }
        b[i] = mindist;        
    }

    cout<<b[n-1]<<"\n";

    return 0;

}
  

Measured memory_bytes: 5200
#include<bits/stdc++.h>
    using namespace std ;
    #define endl '\n'
    #define lld long long int 
    #define ull unsigned long long int 
    ull power(ull x, ull y){ull temp;if( y == 0)return 1;temp = power(x, y/2); if (y%2 == 0) return temp*temp;else return x*temp*temp; } 
    ull gcdFactor(ull n){ ull tmp=n,res=0;for(ull i=1 ; i*i <=tmp ; i++){if(tmp%i==0){res++;if(tmp/i!=i)res++;}}return res;}
    #define ullmax ULLONG_MAX
    void solution(void);
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        solution();
        return 0;
    }
    
    
    // The difference between the novice and the master is that the master has failed more than the novice has tried  
    // It is not over when you lose it is over when you quit
    // If you have time to think for a beautiful end, then live beautifully until the end
    
    
    void solution(){
        int n;
        cin>>n;
        double arr[n];
        double sm = 0;
        for(int i=0 ; i<n ; i++){
            cin>>arr[i];
            sm += (double)((double)1/arr[i]);
        }
        cout<<setprecision(10)<<1/sm;
    }

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()+" "
A=[0]*(n+1)
cnt=0
for i in range(1,n):
    if s[i-1]+s[i]=="AC":
        cnt +=1
    A[i+1]=cnt

for i in range(q):
    l,r=map(int,input().split())
    print(A[r]-A[l])

Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int a[200001];
int main()
{
	int n,m,s=0;
	cin>>n;
	for(int i=0;i<n;i++)
	  cin>>a[i],v.push_back(a[i]);
	sort(v.rbegin(),v.rend());
	m=v[0],s=v[1];
	for(int i=0;i<n;i++)
	  if(a[i]==m)
	    cout<<s<<endl;
	  else
	    cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3316
#include<stdio.h>
#define gc() getchar()
int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}
int a[200000];
int main()
{
	int d, i,k,n,max;
	k = in(), n = in();
	a[0] = in(),a[1]=in();
	max = a[1] - a[0];
	for (i = 2; i < n; i++)
	{
		a[i] = in(); d = a[i] - a[i - 1];
		if (d > max) max = d;
	}
	if (k - a[n - 1] + a[0] > max) max = k - a[n - 1] + a[0];
	printf("%d", k - max);
}

Measured memory_bytes: 896
nums = [int(x) for x in input().split()]
N,K = nums[0],nums[1]
D = set([int(x) for x in input().split()])

ans = N

def solve(M):
    M = [int(x) for x in str(M)]
    for m in M:
        if m in D: return False
    return True


while(1):
    if solve(ans):
        print(ans)
        break
    else:
        ans +=1

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, Ma, Mb, a[41], b[41], c[41], memo[41][412][412];

int dp(int n, int aa, int bb)
{
	if (aa > 0 && bb > 0 && aa*Mb / Ma == bb && bb*Ma / Mb == aa) return 0;
	if (n == N) return 114514;
	if (memo[n][aa][bb] != -1) return memo[n][aa][bb];
	int res1 = dp(n + 1, aa + a[n], bb + b[n]) + c[n];
	int res2 = dp(n + 1, aa, bb);
	return memo[n][aa][bb] = std::min(res1, res2);
}

int main()
{
	in >> N >> Ma >> Mb;
	rep(i, N) in >> a[i] >> b[i] >> c[i];
	memset(memo, -1, sizeof(memo));
	out << (dp(0, 0, 0) >= 114514 ? -1 : dp(0, 0, 0)) << std::endl;
	return 0;
}


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

int n;
int a[100001],b[100000];
long long int ans;

int main(){
    cin>>n;
    for (int i=0; i<n+1; i++){
        cin>>a[i];
    }
    int temp=0;
    ans=0;
    for (int i=0; i<n; i++){
        cin>>b[i];
        ans+=min(temp,a[i]);
        a[i]-=temp;
        a[i]=max(a[i],0);
        ans+=min(a[i],b[i]);
        temp=max(0, b[i]-a[i]);
        //cout<<i<<" : "<<temp<<" : "<<ans<<endl;
    }
    ans+=min(temp,a[n]);
    //cout<<min(temp,a[n]);
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int N, max=0;
	cin>>N;
	map<string, int> m;
	
	for(int i=0; i<N; i++)
	{
		string temp;
		cin>>temp;
		m[temp]++;
		
		if(m[temp]>max)
			max=m[temp];
	}
	
	map<string, int>::iterator itr;
	for(itr=m.begin(); itr!=m.end(); itr++)
	{
		if(itr->second==max)
			cout<<itr->first<<endl;
	}
	
	return 0;
}


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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    std::cout << std::fixed;
    std::cout << std::setprecision(6);
    double d;
    cin>>d;
    cout<<2.0*d*M_PI<<endl;
    
    return 0;
}

Measured memory_bytes: 3788
package main

import (
	"fmt"
)

func main() {
	var m, f, r int
	for {
		fmt.Scan(&m)
		fmt.Scan(&f)
		fmt.Scan(&r)
		if m == -1 && f == -1 && r == -1 {
			break
		}
		judge(m, f, r)
	}
}

func judge(m, f, r int) {
	if m == -1 || f == -1 {
		fmt.Println("F")
		return
	}
	total := fix(m) + fix(f)
	if total >= 80 {
		fmt.Println("A")
	} else if total >= 65 && total < 80 {
		fmt.Println("B")
	} else if total >= 50 && total < 65 {
		fmt.Println("C")
	} else if total >= 30 && total < 50 {
		if r >= 50 {
			fmt.Println("C")
		} else {
			fmt.Println("D")
		}
	} else if total < 30 {
		fmt.Println("F")
	}
}

func fix(n int) int {
	if n == -1 {
		return 0
	}
	return n
}



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

using namespace std;
#define NIL -1

struct node{int p,r,l;};

node tree[30];
int n;

void preorder(int u){
  if(u==NIL) return;
  cout<<" "<<u;
  preorder(tree[u].r);
  preorder(tree[u].l);
}

void inorder(int u){
  if(u==NIL) return;
  inorder(tree[u].r);
  cout<<" "<<u;
  inorder(tree[u].l);
}

void postorder(int u){
  if(u==NIL) return; 
  postorder(tree[u].r);
  postorder(tree[u].l);
  cout<<" "<<u;
}

int main(){
  int n;
  int num,r,l,A,root;
  cin>>n;
  for(int i=0;i<n;i++){
    tree[i].p=NIL;
  }
  for(int i=0;i<n;i++){
    cin>>num>>r>>l;
    if(l!=NIL) tree[l].p=num;
    if(r!=NIL) tree[r].p=num;
    tree[num].l=l;
    tree[num].r=r;
  }
  for(int i=0;i<n;i++) if(tree[i].p==NIL) root=i;
  cout<<"Preorder"<<endl;
  preorder(root);
  cout<<endl<<"Inorder"<<endl;
  inorder(root);
  cout<<endl<<"Postorder"<<endl;
  postorder(root);
  cout<<endl;
  return 0;
}
  




Measured memory_bytes: 3080
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> ans(n);
    ans[0] = 0;
    rep(i, n) if ((i & 1) == 0) ans[0] += a[i]; else ans[0] -= a[i];
    rep(i, n - 1) {
        ans[i + 1] = 2 * a[i] - ans[i];
    }

    rep(i, n - 1) cout << ans[i] << ' ';
    cout << ans[n-1] << '\n';

    return 0;
}



Measured memory_bytes: 2176