akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	int n,l;
	int taste[200];
	int i, min, j;
	int temp, wa1, wa2;
	int k[200];

	min = wa1 = wa2 = 0;
	scanf("%d", &n);
	scanf("%d", &l);
	for (i = 1; i <= n; i++) {
		taste[i-1] = i + l - 1;
	}
	for (i = 0; i < n; i++) {
		k[i] = taste[i];
		if (k[i] < 0) {
			k[i] *= -1;
		}
	}
	for (i = 0; i < n - 1; i++) {
		for (j = i; j < n; j++) {
			if (k[i] > k[j]) {
				temp = k[i];
				k[i] = k[j];
				k[j] = temp;
			}
		}
	}
	for (i = 0; i < n; i++) {
		wa1 += taste[i];
		wa2 += taste[i];
	}
	if (wa2 >= 0) {
		wa2 -= k[0];
	}
	else {
		wa2 += k[0];
	}
	printf("%d\n", wa2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int n,T;
  cin>>n>>T;
  int mn=inf;
  rep(i,n){
    int c,t;
    cin>>c>>t;
   if( t<=T) mn=min(mn,c);
  } 
  if(mn==inf) cout<<"TLE"<<endl;
  else cout<<mn<<endl;
}

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

#define MAX_N 20

int n;
int power[MAX_N];

int min_diff(int a, int b, int p) {
    if (p == n) return abs(a-b);
    return min(min_diff(a+power[p], b, p+1), min_diff(a, b+power[p], p+1));
}

int main() {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            cin >> power[i];
        }
        cout << min_diff(0, 0, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 864
S=str(input())
if int(S[0:2])<=12 and int(S[0:2])>=1:
  if int(S[2:4])<=12 and int(S[2:4])>=1:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if int(S[2:4])<=12 and int(S[2:4])>=1:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
def main():
    h, w = map(int, 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)]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    ret = 0
    for row in a:
        for cell in row:
            if ~cell:
                ret += c[cell][1]

    print(ret)


if __name__ == '__main__':
    main()
   

Measured memory_bytes: 3316
def multiplication():
    # 入力
    N = int(input())
    A = list(map(int, input().split()))
    # かける数に0があるか確認
    if 0 in A:
        return 0
    # 計算処理
    multi = 1
    for i in range(N):
        multi = multi * A[i]
        # 10^18比較
        if multi > 10 ** 18:
            return -1
    return multi

result = multiplication()
print(result)

Measured memory_bytes: 21548
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

nc = 0
zc = 0
pc = 0

# count negative value, zero and positive value
for i in range(n):
    if arr[i] < 0:
        nc += 1
    elif arr[i] == 0:
        zc += 1
    else:
        pc += 1

# count negative pair and so on 
ncc = nc * pc
zcc = zc * (nc + pc) + (zc * (zc - 1)) // 2
pcc = (nc * (nc - 1)) // 2 + (pc * (pc - 1)) // 2

# when k is less than ncc
if k <= ncc:
    # sort absolute value
    arr1 = [] # negative absolute
    arr2 = []
    for i in range(n):
        if arr[i] < 0:
            arr1.append(-arr[i])
        elif arr[i] > 0:
            arr2.append(arr[i])
    arr1 = arr1[::-1]
    c1 = len(arr1)
    c2 = len(arr2)
    l = 0
    r = 10 ** 18 + 1
    k = ncc - k

    # binary search
    while r - l != 1:
        mid = (l + r) // 2
        cnt = 0
        pos = c2 - 1
        # しゃくとり法
        for i in range(c1):
            while pos != -1:
                if arr2[pos] > mid // arr1[i]:
                    pos -= 1
                else:
                    break
            cnt += pos + 1
        if cnt > k:
            r = mid
        else:
            l = mid
    print(-r)
elif k <= (ncc + zcc):
    print(0)
else:
    arr1 = []
    arr2 = []
    for i in range(n):
        if arr[i] < 0:
            arr1.append(-arr[i])
        elif arr[i] > 0:
            arr2.append(arr[i])
    arr1 = arr1[::-1]
    c1 = len(arr1)
    c2 = len(arr2)
    l = 0
    r = 10 ** 18 + 1
    k -= (ncc + zcc)
    while r - l != 1:
        mid = (l + r) // 2
        cnt1 = 0
        pos1 = c1 - 1
        for i in range(c1):
            tmp = 0
            while pos1 != -1:
                if arr1[pos1] > mid // arr1[i]:
                    pos1 -= 1
                else:
                    break
            tmp += pos1 + 1
            if arr1[i] ** 2 < mid:
                tmp -= 1
            cnt1 += tmp
        cnt1 = cnt1 // 2
        cnt2 = 0
        pos2 = c2 - 1
        for i in range(c2):
            tmp = 0
            while pos2 != -1:
                if arr2[pos2] > mid // arr2[i]:
                    pos2 -= 1
                else:
                    break
            tmp += pos2 + 1
            if arr2[i] ** 2 < mid:
                tmp -= 1
            cnt2 += tmp
        cnt2 = cnt2 // 2
        cnt = cnt1 + cnt2
        if cnt >= k:
            r = mid
        else:
            l = mid
    print(r)


        





Measured memory_bytes: 101588
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
long long gogo[200000] = {};
vector<long long> nya[200000];
int main() {
#define int long long
	int n, k;
	cin >> n >> k;
	long long ans = 0;
	long long type = 0;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		nya[a].push_back(b);
		ans += b;
	}
	vector<int> aa, bb;
	for (int i = 1; i <= n; ++i) {
		if (nya[i].size() != 0) {
			sort(nya[i].begin(), nya[i].end());
			bb.push_back(nya[i][nya[i].size() - 1]);
			REP(q, nya[i].size() - 1) {
				aa.push_back(nya[i][q]);
			}
			type++;
		}
	}
	ans += type * type;
	sort(aa.begin(), aa.end());
	sort(bb.begin(), bb.end());
	int itr[2] = {};
	bb.push_back(100000000000000LL);
	aa.push_back(100000000000000LL);
	for (int i = 0; i < n - k; ++i) {
		if (aa[itr[0]] >= bb[itr[1]]+2*type - 1) {
			ans -= bb[itr[1]] + 2*type - 1;
			type--;
			itr[1]++;
		}
		else {
			ans -= aa[itr[0]];
			itr[0]++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10616
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    ll a, b, n ;
    cin >> a >> b >> n ;
    if(n >= b){
        n = b - 1 ;
    }
    cout << a*n/b << endl; 
}  

Measured memory_bytes: 3620
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"
int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int n,k,x,y;
    cin>>n>>k;
    set<int>s;
    f(i,1,k)
    {
        cin>>x;
        f(j,1,x)
        {
            cin>>y;
            s.insert(y);
        }
    }
    cout<<n-sz(s);
}


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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int count = 0;
		int tmp = a[0];
		for (int i = 0; i < (tmp/2); i++) {
			for (int j = 0; j < n; j++) {
				if (a[j] % 2 == 0) {
					a[j] /= 2;
				} else {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
		System.out.println(count);
	}
}	

Measured memory_bytes: 23764
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

// const int mod = 1e9 + 7;
 const int mod = 998244353;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main(){
  string s,t;
  cin>>s>>t;
  int ret=mod;
  for(int i=0;i<=s.size()-t.size();i++){
    int cnt=0;
    for(int j=0;j<t.size();j++){
      if(s[i+j]!=t[j])cnt++;
    }
    ret=min(cnt,ret);
  }
  cout<<ret<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll arr[10001];
ll dp[10001][101][2];
ll m = 1e9+7;
ll f(ll idx,ll sum,ll flag,ll n,ll d){
    if(idx == n){
        if(sum==0){return 1;}
        else{return 0;}
    }
    if(dp[idx][sum][flag]!=-1){return dp[idx][sum][flag];}
    ll ans=0;
    if(flag==1){
        rep(i,0,arr[idx]){
            if(i<arr[idx]){
              ans = (ans + f(idx+1,(sum+i%d)%d,0,n,d)%m)%m;
            }else{
              ans = (ans + f(idx+1,(sum+i%d)%d,1,n,d)%m)%m;  
            }
        }
    }
    else{
        rep(i,0,9){
             ans = (ans + f(idx+1,(sum+i%d)%d,0,n,d)%m)%m;
        }
    }
    dp[idx][sum][flag] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    string k; cin>>k;
    ll d; cin>>d;
    ll n = k.length();
    rep(i,0,n-1){
     arr[i] = (ll)k[i]-48;
    }
    cout<<(f(0,0,1,n,d)-1+m)%m ;
}


Measured memory_bytes: 20240
#include<iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin>> W>> H >> x >> y >> r;
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s=="SUN"){
		cout << "7" << endl;
	}
	if (s == "MON") {
		cout << "6" << endl;
	}
	if (s == "TUE") {
		cout << "5" << endl;
	}
	if (s == "WED") {
		cout << "4" << endl;
	}
	if (s == "THU") {
		cout << "3" << endl;
	}
	if (s == "FRI") {
		cout << "2" << endl;
	}
	if (s == "SAT") {
		cout << "1" << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++) cin >> v[i];
  sort(v.begin(), v.end());
  double ans=(double)(v[0]+v[1])/2;
  for(int i=2; i<N; i++){
    ans+=v[i];
    ans/=(double)2;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from fractions import gcd
from functools import reduce
n = int(input())
num = [int(input()) for i in range(n)]
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(num))

Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll P[100005];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ll n;
	int sum = 0;
	cin >> n;
	for (ll i = 0; i < n; i++)
	{
		cin >> P[i];
	}
	sort(P, P + n);
	int R = n / 2;
	int L = (n - 1) / 2;
	sum = P[R] - P[L];
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(n) for(int &x : n) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


int n;


int main()
{   

      ios_base::sync_with_stdio(0) , cin.tie(0);cout.tie(0);

      string s;
      cin >> n >> s;
      int len = s.length();
      int cnt = 0;
      
      xloop(i, 0 , len-3)
            if(s[i]=='A' && s[i+1] == 'B' && s[i+2] == 'C') cnt++;
      

      cout << cnt << "\n";

      return 0;
}

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


class Program {

	static long mod = 998244353;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0;
		
		string res = "NO";


		//int n = int.Parse(Console.ReadLine());
		string str = Console.ReadLine();
		int win = 0;
		for ( int i = 0; i < str.Length; i++ ) {
			if ( str[i] == 'o' ) { win++; }			
		}
		win+=(15-str.Length);
		if ( win >= 8 ) {
			res = "YES";
		}

			Console.WriteLine(res);


		return;

	}

	

	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}

}

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

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

  if(s.size()>k){
    string t = "";
    rep(i,k) t+=s[i];
    t+="...";
    rep(i,t.size()) cout << t[i];
  }
  else rep(i,s.size()) cout << s[i];
  
  cout << endl;
  
  return 0;
}


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

namespace abc167b
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            List<decimal> input = Console.ReadLine().Split(' ').Select(decimal.Parse).ToList();
            decimal a = input[0];//1
            decimal b = input[1];//0
            decimal c = input[2];//-1
            decimal k = input[3];

            decimal output = 0;


            if (k <= a)
            {
                output = k;
            }
            else if (k <= a + b)
            {
                output = a;
            }
            else
            {
                output = a + (k - (a + b)) * (-1);

            }
            //==========================================================================================================================
            //2) output

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 28332
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    long long a[100000], n, sum=0, b[100000];
    scanf("%lld",&n);
    for(long long i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        sum=sum+a[i];
    }
    for(int i=n-2;i>0;i=i-2)
    {
        sum=sum-a[i]*2;
    }
    b[0]=sum;
    for(long long i=1;i<n;i++)
    {
        b[i]=a[i-1]*2-b[i-1];
    }
    for(long long i=0;i<n;i++)
    {
        printf("%lld ",b[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define lli long long
int dp[100005][4];
int a[100005][4];

int main() 
{
    int n;
    cin >> n;
    
    for(int i=1;i<=n;i++) for(int j=1;j<=3;j++) cin >> a[i][j];
    
    dp[1][1] = a[1][1], dp[1][2] = a[1][2], dp[1][3] = a[1][3];
    
    for(int i=2;i<=n;i++){
        for(int j=1;j<=3;j++){
            if(j==1){
                dp[i][j] = max(dp[i-1][2],dp[i-1][3]) + a[i][j];
            }
            if(j==2){
                dp[i][j] = max(dp[i-1][1],dp[i-1][3]) + a[i][j];
            }
            if(j==3){
                dp[i][j] = max(dp[i-1][2],dp[i-1][1]) + a[i][j];
            }
        }
    }
    
    int ans = max(dp[n][1],max(dp[n][2],dp[n][3]));
    
    cout << ans << endl;
    
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#define N 500000

typedef struct{
  int key, left, right;
}Node;

Node tree[N+1];
int size;

void insert(int x){
  int a = 0;
  while(1){
    if(x < tree[a].key){
      if(tree[a].left == -1){
        tree[a].left = size;
        tree[size++].key = x;
        break;
      }else a = tree[a].left;
    }else{
      if(tree[a].right == -1){
        tree[a].right = size;
        tree[size++].key = x;
        break;
      }else a = tree[a].right;
    }
  }
}

void inorder(int a){
  if(tree[a].left != -1) inorder(tree[a].left);
  printf(" %d", tree[a].key);
  if(tree[a].right != -1) inorder(tree[a].right);
}

void preorder(int a){
  printf(" %d", tree[a].key);
  if(tree[a].left != -1) preorder(tree[a].left);
  if(tree[a].right != -1) preorder(tree[a].right);
}

int find(int a, int x){
  if(tree[a].key == x) return 1;
  if(x < tree[a].key && tree[a].left != -1) if(find(tree[a].left, x)) return 1;
  if(tree[a].key < x && tree[a].right != -1) if(find(tree[a].right, x)) return 1;
  return 0;
}

main(){
  int n, i, f;
  f = 1;
  scanf("%d", &n);
  if(n > N)exit(1);

  for(i = 0 ; i <= n ; i++) tree[i].key = tree[i].left = tree[i].right = -1;
  size = 0;
  while(n--){
    char str[100];
    scanf("%s", str);
    if(!strcmp(str, "insert")){
      int in;
      scanf("%d", &in);
      if(f){
        tree[size++].key = in;
        f = 0;
      }
      else insert(in);
    }else if(!strcmp(str, "find")){
      int in;
      scanf("%d", &in);
      printf("%s\n", (find(0, in) ? "yes" : "no"));
    }else{
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 7600
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>
 
using namespace std;

int main(){
	long long int A,B;	
  cin >> A >> B;
  if((A+B)%2==0){
    cout << (A+B)/2 << endl;
  }else{
  	cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[300001];
ll sum[300001];

int main(void){
	scanf("%d",&n);
	bool flag=false;
	for(ll i=1;i<=n;i++){
		sum[i]=i+sum[i-1];
	}
	
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i==0 && a[i]!=0LL)flag=true;
		if(i>0 && a[i]>a[i-1]+1LL)flag=true;
	}
	if(flag){
		printf("-1\n");
		return 0;
	}
	ll ans=0;
	ll su=0;
	ll no=0;
	for(int i=0;i<n;i++){
		if(i>0 && a[i]<a[i-1]){
			ans+=su;
			if(no>0)ans-=sum[no-1];
			su=a[i];
			if(a[i]>1LL){
				su+=sum[a[i]-1];
			}
			no=a[i];
		}else{
			su+=a[i];
			no=max(a[i],no);
		}
	}
	ans+=su;
	if(no>0)ans-=sum[no-1];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n, m;
int a[2][50];
bool used[51][51][101][2][3];
int ans[51][51][101][2][3];
//自分がi枚目、相手がj枚目、stackはk枚、自分はid、何回passされたか
int dfs(int i, int j, int k,int id,int pas) {
	if (used[i][j][k][id][pas])return ans[i][j][k][id][pas];
	used[i][j][k][id][pas] = true;
	vector<int> v;
	int nij[2] = { i - 1,j - 1 };
	rep(b, k) {
		int nid = (b % 2) ^ id^1;
		v.push_back(a[nid][nij[nid]]);
		nij[nid]--;
	}
	bool val[2] = { true,true };
	int sum = 0;
	rep(b, k) {
		if (b % 2) {
			if (v[b] < 0) {
				val[1] = false;
			}
			else {
				if (!val[0])continue;
				sum += v[b];
			}
		}
		else {
			if (v[b] < 0) {
				val[0] = false;
			}
			else {
				if (!val[1])continue;
				sum -= v[b];
			}
		}
	}
	//if (i == n && j == m)return ans[i][j][k][id][pas] = sum;
	int ma = -mod;
		//pass
		if (pas<=1) {
			ma = max(ma, -dfs(i, j, 0, id ^ 1,pas+1) + sum);
		}
		else {
			ma = max(ma, sum);
		}
	//not pass
	if (id == 0&&i<n) {
			ma = max(ma, -dfs(i + 1, j, k + 1, 1,0));
	}
	if (id == 1 && j < m) {
		ma = max(ma, -dfs(i, j + 1, k + 1, 0,0));
	}
	//cout << i << " " << j << " " << k << " " << id << " " << ma << endl;
	return ans[i][j][k][id][pas]= ma;
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[0][i];
	}
	rep(i, m) {
		cin >> a[1][i];
	}
	cout << dfs(0, 0, 0, 0,1) << endl;
	return 0;
}


Measured memory_bytes: 10932
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,k,i,j,d[1010][1010],has;
char a[1010][1010];
queue<pair<ll,ll> > q;
ll dx[4]={0,0,-1,1};
ll dy[4]={-1,1,0,0};
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='S')
			{
				q.push(mp(i,j));
			}
			else
				d[i][j]=1e18;
		}
	has=1e18;
	while(!q.empty())
	{
		ll x=q.front().fi;
		ll y=q.front().se;
		if(d[x][y]<=k)
		{
		//	cout<<x<<" "<<y<<"_\n";
			has=min(has,min(min(x-1,y-1),min(n-x,m-y)));
		}
		q.pop();
		for(i=0;i<4;i++)
		{
			ll nx=x+dx[i];
			ll ny=y+dy[i];
			if(a[nx][ny]=='.'&&d[nx][ny]==1e18)
			{
		//		cout<<nx<<" "<<ny<<"\n";
				d[nx][ny]=d[x][y]+1;
				q.push(mp(nx,ny));
			}
		}
	}
	//cout<<has<<"\n";
	ll tam=0;
	if((has%k)!=0)
		tam=1;
	has=(has/k)+tam;
	has++;
	cout<<has<<"\n";
}

Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int prime[10000000];
bool isprime[10000001];

int sieve(int n){
	int p=0;
	for(int i=0;i<=n;i++)isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=0;i<=n;i++){
		if(isprime[i]){
			prime[p++]=i;
			for(int j=i*2;j<=n;j+=i)isprime[j]=false;
		}
	}
	return p;
}

int main(){
	sieve(1e+4);
	int n;
	while(cin>>n){
		if(!n)return 0;
		do{
			if(isprime[n]&&isprime[n-2]){
				cout<<n-2<<" "<<n<<endl;
				break;
			}
		}while(n--);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
    int a;
    cin >> a;
    if(a==1){
      cout << 0 << endl;
    }else{
      cout << 1 << endl;
    }
}


Measured memory_bytes: 3632
/*
   Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;

#define pii pair < int, int >
#define vi vector < int >
#define vb vector < bool >
#define vvi vector < vector < int > >
#define vvb vector < vector < bool > >
#define vpii vector < pair < int, int > >
#define vvpii vector < vector < pair < int, int > > >
#define pb push_back
#define f first
#define s second
#define mp make_pair

vvi adj;
vi vec;

void add_edge(int u, int v){
    adj[u].pb(v);
    adj[v].pb(u);
}

void bfs(int u){
    queue < int > q;
    vi distance(adj.size(), 0);
    vb visited(adj.size(), false);
    visited[u] = true, q.push(u);

    while(!q.empty()){
        int v = q.front();
        q.pop();
        
        for(int to : adj[v]){
            if(!visited[to])
                visited[to] = true, distance[to] = distance[v] + 1, q.push(to);
        }
    }

    for(int i=0; i<(int)adj.size(); i++)
        vec[distance[i]]++;
}

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    adj.resize(n), vec.resize(n, 0);
    for(int i=0; i<n-1; i++)
        add_edge(i, i+1);
    add_edge(x, y);
    for(int i=0; i<n; i++)
        bfs(i);

    for(int i=1; i<n; i++)
        cout << vec[i]/2 << endl;
    return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int cont(string s, char c) {
    int b = 0, mb = 0;
    for (char cc: s) {
        if (cc == c) ++b, uax(mb, b);
        else b = 0;
    }
    return mb;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    --a; --b; --c; --d;
    bool ok = cont(string(s.begin() + a, s.begin() + c + 1), '#') < 2 && cont(string(s.begin() + b, s.begin() + d + 1), '#') < 2;
    if (c > d) ok &= cont(string(s.begin() + b - 1, s.begin() + d + 2), '.') >= 3;
    cout << (ok ? "Yes" : "No") << '\n';


#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};




int n,a[100010];
 
signed main(){
	cin>>n;
	int sum=0;
	rep(i,0,n){
	    cin>>a[i];
	    sum+=a[i];
	}
	int x=((1+n)*n)/2;
	int cnt=sum/x;
	if(sum%x){
	    cout<<"NO"<<endl;
	    return 0;
	}
	int cnt1=0;
	rep(i,0,n-1){
	    int b=a[i+1]-a[i];
	       while(b<cnt){
	           b+=n;
	           cnt1++;
	       }
	}
	int b=a[0]-a[n-1];
	while(b<cnt){
	    b+=n;
	    cnt1++;
	}
	//cout<<cnt1<<endl;
	if(cnt1==cnt)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S[2] == S[3] && S[4] == S[5])
        cout << YES << endl;
    else
        cout << NO << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    //          int[] split = Console.ReadLine().Split().Select(int.Parse).ToArray();

    public static void Main()
    {
        int[] split = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int X = split[0];
        int A = split[1];
        int output = 0;
        if (X < A)
        {
        }
        else
        {
            output = 10;

        }

        Console.WriteLine(output);

    }



}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <complex>
#include <iomanip>
using namespace std;
typedef complex<double> P;
const double EPS = 1e-10;
//二つのスカラーが等しいか
#define EQ(a, b) (abs((a) - (b)) < EPS)

//二つのベクトルが等しいか
#define EQV(a, b) (EQ((a), real(), (b).real()) && EQ((a), imag(), (b).imag()))

namespace std
{
bool operator<(P &a, P &b)
{
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

double dot(P a, P b)
{
    return real(a) * real(b) + imag(a) * imag(b);
}

double cross(P a, P b)
{
    return real(a) * imag(b) - imag(a) * real(b);
}

int is_orthogonal(P a1, P a2, P b1, P b2)
{
    return EQ(dot(a1 - a2, b1 - b2), 0.0);
}
int is_parallel(P a1, P a2, P b1, P b2)
{
    return EQ(cross(a1 - a2, b1 - b2), 0.0);
}
int ccw(P a, P b, P c)
{
    b -= a;
    c -= a;
    if (cross(b, c) > 0)
        return 1;
    if (cross(b, c) < 0)
        return -1;
    if (dot(b, c) < 0)
        return 2;
    if (norm(b) < norm(c))
        return -2;
    return 0;
}
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        double a, b, c, d, e, f, g, h;
        cin >> a >> b >> c >> d >> e >> f >> g >> h;

        P p0(a, b);
        P p1(c, d);
        P p2(e, f);
        P p3(g, h);

        if (EQ(cross(p1 - p0, p3 - p2), 0.0))
            cout << "2" << endl;
        else if (EQ(dot(p1 - p0, p3 - p2), 0.0))
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
}


Measured memory_bytes: 3232
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
s = inputS()

alpha = "abcdefghijklmnopqrstuvwxyz"

for l in alpha:
  if l not in s:
    print(l)
    exit()
print("None")


Measured memory_bytes: 39152
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,t,e;
  cin >> n >> t >> e;
  int ans=-1;
  rep(i,n) {
    int x;
    cin >> x;
    int k=x;
    bool ck=false;
    while(k<=t+e) {
      if(k>=t-e && k<=t+e) {
	ck=true;
	break;
      }
      k+=x;
    }
    if(ck) ans=i+1;
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 1164
//int64_t a;
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int64_t a,b,c;
  cin >>a>>b>>c;
  int num=c;
  rep(i,10){
    num = a* num-b;
    cout<<num<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string s;
int main(){
    cin>>s;
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
    {
        cout<<"Yes"<<endl;
    }
    else
cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N>>K;
	vector<int> l(N);
	int i;
	for (i=0;i<N;i++){
		cin>>l[i];
	}
	sort(l.begin(),l.end());
	int aw=0;
	for (i=0;i<N;i++){
		if (i<N-K){
			continue;
		}
		aw+=l[i];
	}
	cout<<aw<<endl;
	return 0;
}

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

int main()
{
    long long a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;

    if(a>=k){
        sum+=k;
        k=0;
    }
    else{
        sum+=a;
        k-=a;
    }
    if(b>=k)k=0;
    else k-=b;

    if(c>=k)sum+=(-k);
    else sum+=(-c);

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


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

#define ll long long

int main(){
    
    int i,j;
    int N,K;

    cin >> N >> K;
    
    int ans=1;

    for(i=0;i<N;i++){
        if(ans*2 < ans+K){
            ans *= 2;
        }
        else{
            ans += K;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    N--;
    cout << ( 1 + N ) * N / 2 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct node
{
  int pos;
  string name;
  int score;
  node (int pos,string name,int score):pos(pos),name(name),score(score){}
  friend bool operator < (const node a, const node b)
  {
    if(a.name == b.name) return a.score > b.score;
    else return a.name < b.name;
  }
};
int main()
{
  int n;
  scanf("%d",&n);
  vector<node>V;
  pair<string,int>P[n+1];
  string str;
  int score;
  for(int i = 1 ; i <= n ; i++)
  {
    cin>>str>>score;
    V.push_back(node(i,str,score));
  }
  sort(V.begin(),V.end());
  for(int i = 0 ; i < V.size() ; i++) cout<<V[i].pos<<endl;

}

Measured memory_bytes: 256
s = input()
K = int(input())
n =len(s)

dp = [[[0] * 2 for _ in range(4)] for _ in range(101)]

dp[0][0][0]=1
for i in range(n):
    for j in range(4):
        for k in range(2):
            nd = int(s[i])

            for d in range(10):
                ni = i+1; nj = j; nk = k

                if d != 0 :nj+=1
                if nj > K:continue
                if k==0:
                    if d > nd:continue
                    if d < nd:nk =1
                dp[ni][nj][nk] += dp[i][j][k]
                # print(d,k)
                # print(i,j,k,dp[i][j][k])
                # print(ni,nj,nk,dp[ni][nj][nk])
                # [print(i) for i in dp]

ans=dp[n][K][0] + dp[n][K][1]
print(ans)
# [print(i) for i in dp]

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

int n,m;
int x[100000];
int d[100000];

signed main() {
  cin >> n >> m;
  for(int i=0; i<m; i++) cin >> x[i];

  if( n>=m ) {puts("0"); return 0;}

  sort(x, x+m);

  priority_queue<pair<int, int>> pq;
  int sum = 0;
  for(int i=0; i<m-1; i++) {
    d[i] = x[i+1] - x[i];
    sum += d[i];
    pq.emplace(d[i], i);
  }

  cerr << sum << endl;

  while(n>1) {
    auto p = pq.top(); pq.pop();
    sum -= p.first;
    n -= 1;
  }

  cout << sum << endl;
}


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int A,B,C;
  cin>>A>>B>>C;
  int ANS = 0;
  int DAY = 0;
  while(true)
  {
    DAY++;
    ANS += A;
    if(DAY%7 == 0)
    {
      ANS += B;
    }
    if(ANS >= C)
    {
      break;
    }
    
  }
  cout<<DAY<<endl;
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p, int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#a以上b以下の整数のうちcでもdでも割り切れないものの個数を求めてください
#1以上b以下の整数の条件を満たすものから1以上a-1以下のもので条件を満たすものを取り除くようにすればいい
import fractions

a,b,c,d=map(int,input().split())
x=c*d//fractions.gcd(c,d)
n=b-((b//c)+(b//d)-b//(x))
m=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(x))
print(n-m)

Measured memory_bytes: 5048
n = int(input())
b = list(map(int, input().split()))
a = [0 for _ in range(n)]

a[0] = b[0]
for i in range(1, n-1):
    a[i] = min(b[i-1],b[i])
a[n-1] = b[n-2]
print(sum(a))


Measured memory_bytes: 3060
def linp():return list(map(int,input().split()))
n=int(input())
p=linp()
s=0
for i in range(n):
    if i==p[i]-1:continue
    else:
        p[p[i]-1]=p[i]
        s+=1
if s<=1:print("YES")
else:print("NO")


Measured memory_bytes: 3060