akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    int n;
    cin >> n;
    vector<pair<int, int>> a;
    vector<int> sn;
    for (int i = 0; i < n; i++) {
    	int x, l;
    	cin >> x >> l;
    	a.push_back({x - l, x + l});
    	sn.push_back(x - l);
    	sn.push_back(x + l);
    }
    sort(sn.begin(), sn.end());
    sn.resize(unique(sn.begin(), sn.end()) - sn.begin());
    for (auto &t : a) {
    	t.first = 1 + lower_bound(sn.begin(), sn.end(), t.first) - sn.begin();
    	t.second = 1 + lower_bound(sn.begin(), sn.end(), t.second) - sn.begin();
    	// cerr << t.first << ' ' << t.second << endl;
    }
    vector<int> dp(sn.size() + 1);
    dp[0] = 0;
    vector<vector<int>> bl(sn.size() + 1);
    for (int i = 0; i < n; i++) {
    	bl[a[i].second].push_back(a[i].first);
    }
    for (int i = 1; i <= (int)sn.size(); i++) {
    	for (auto l : bl[i]) {
    		dp[i] = max(dp[i], dp[l] + 1);
    	}
    	dp[i] = max(dp[i], dp[i - 1]);
    }
    cout << dp.back() << endl;
}   


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

int main()
{
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	int **s=new int*[h];
	for(int i=0;i<h;i++)
	{
		s[i]=new int[w];
	}
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
	}
	int x=0,y=0;
	int Iter=0;
	while (Iter<n)
	{
		int temp;
		if (a[Iter])
			temp = Iter + 1;
		else if (Iter == n - 1)
			break;
		else
			temp = (++Iter) + 1;

		a[Iter]--;

		s[y][x] = temp;

		if (y < ceil(h / 2.0) && x<w - y - 1 && x>y - 2)
			x++;
		else if (x > floor(w / 2.0) - 1 && y > w - x - 2 && y < h - w + x)
			y++;
		else if (y > ceil(h / 2.0) - 1 && x > h - y - 1 && x < w - h + y + 1)
			x--;
		else if (x<floor(w / 2.0) && y>x + 1 && y < h - x)
			y--;
	}
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			printf("%d ",s[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 384
n,c = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(c)]

a = [[0]*c for _ in range(3)]
b = [[[0,i] for i in range(c)] for _ in range(3)]

for i in range(n):
  l = list(map(int,input().split()))
  for j in range(n):
    a[(i+j)%3][l[j]-1] += 1
    
for i in range(3):
  for k in range(c):
    b[i][k][0] = sum([a[i][t]*d[t][k] for t in range(c)])
#print(a)
#print(b)
p = [[],[],[]]
for i in range(3):
  p[i] = sorted(b[i])[:3]
m = []
for t in p[0]:
  for s in p[1]:
    for u in p[2]:
      if (t[1] != s[1]) and (t[1] != u[1]) and (s[1] != u[1]):
        m.append(t[0]+s[0]+u[0])
print(min(m))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <deque>

using namespace std;

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	deque<int> p(a), q(b), r(c);
	for (int i = 0; i < a; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> q[i];
	}
	for (int i = 0; i < c; i++) {
		cin >> r[i];
	}

	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());

	while(p.size() > x) {
		p.pop_back();
	}
	while(q.size() > y) {
		q.pop_back();
	}

	long long ans = 0;
	for (int i = 0; i < x + y; i++) {
		int maxi = max({p[0], q[0], r[0]});
		ans += maxi;

		if (maxi == p[0]) {
			p.pop_front();
			if (p.empty()) {
				p.push_back(-1);
			}
		} else if (maxi == q[0]) {
			q.pop_front();
			if (q.empty()) {
				q.push_back(-1);
			}
		} else {
			r.pop_front();
			if (r.empty()) {
				r.push_back(-1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main()
{
        int n,a,b,enter,b_cnt;
        char s[100000];

        enter = 0;
        b_cnt = 1;

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

        for(int i = 0 ; i < n ; i++ )
                if(s[i]=='a' && a + b > enter ){
                        printf("Yes\n");
                        enter++;
                }else if(s[i]=='b'  && a + b > enter && b_cnt <= b ){
    
                        printf("Yes\n");
                        enter++;
                        b_cnt++;
    
                }else
                        printf("No\n");

}

Measured memory_bytes: 1756
#include <iostream>
#include <cstdio>
#include <cstring>

int a, v, b, w, t;

int Abs(int a) {return a > 0 ? a : -a;}

int main()
{
	scanf("%d%d%d%d%d", &a, &v, &b, &w, &t);
	if(1ll * (v - w) * t >= Abs(a - b)) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 3724
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int n,m,r;
vector <vi> dis(201,vi (201,1e9));

signed main()
{
    cin >> n >> m >> r ; 
    vi a(r);
    for (int &it: a) cin >> it ; 
    for (int i=1;i<=m;i++){
        int  x, y, c ; 
        cin >> x >> y >> c ; 
        dis[x][y] = dis[y][x] = c ; 
    }
    for (int k=1;k<=n;k++) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                dis[i][j] = min( dis[i][j], dis[i][k]+dis[k][j] ) ; 
            }
        }
    }
    int ans = 1e9 ; 
    sort(all(a));
    do {
        int sum = 0;
        for (int i=1;i<r;i++){
            sum += dis[a[i]][a[i-1]];
        }
        ans = min(ans, sum) ; 
    }
    while (next_permutation(a.begin(),a.end()));
    co ( ans ) ; 
    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    vector<int> alphabet(26, 0);
    for (auto c : s) alphabet[c - 'a']++;
    PQ_ASK pq;

    rep(i, 26) {
        if (alphabet[i] > 0) pq.push(alphabet[i]);
    }

    if (pq.size() == 1) {
        cout << s.size() << endl;
        return 0;
    }

    int ans = 0;
    while (pq.size() > 1) {
        int x = pq.top();
        pq.pop();
        int y = pq.top();
        pq.pop();
        ans += x + y;
        pq.push(x + y);
    }
    cout << ans << endl;
}


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

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

int main() {
    int N, ans = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(ans == 0) {
            ans = a;
            continue;
        }
        ans = gcd(ans, a);
    }
    cout << ans << endl;
    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 matrix[][] = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		int leftDiag = 0, rightDiag = 0;
		int row[] = new int[3], col[] = new int[3];
		for (int i = 0; i < n; i++) {
			int temp = sc.nextInt(), flag = 0;
			for (int k = 0; k < 3 && flag == 0; k++)
				for (int j = 0; j < 3; j++)
					if (matrix[k][j] == temp) {
						if (k == j) 
							leftDiag++;
						
						if (k + j == 2)
							rightDiag++;
						row[k]++;
						col[j]++;
						flag = 1;
						break;
					}
		}
		int ans = 0;
		for (int i = 0; i < col.length; i++) {
			if (col[i] == 3)
				ans = 1;
		}
		for (int i = 0; i < col.length; i++) {
			if (row[i] == 3)
				ans = 1;
		}
		if (rightDiag == 3)
			ans = 1;
		if (leftDiag == 3)
			ans = 1;
		System.out.println((ans == 1) ? "Yes" : "No");
		sc.close();
	}
}


Measured memory_bytes: 35816
import java.util.*;
 
public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int tmp = 0;
            int tmp1 = i;
            while (tmp1 > 0) {
                tmp += tmp1%10;
                tmp1 /= 10;
            }
            if (a <= tmp && tmp <= b) sum+=i;
        }
 
        System.out.println(sum);
    }
}

Measured memory_bytes: 35644
#include <stdio.h>

void insertionSort(int A[], int N) {
  int i, j;
  for (i = 1; i < N; i++) {
    j = i;
    while(j > 0 && A[j-1] > A[j]) {
      swap(&A[j-1], &A[j]);
      j--;
    }
    trace(A, N);
  }
} 

void swap(int *num_large, int *num_small) {
  int tmp;
  tmp = *num_large;
  *num_large = *num_small;
  *num_small = tmp;
}

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

int main() {
  int A[100], N, i;
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &A[i]);

  trace(A, N);
  insertionSort(A, N);

  return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc() {
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x=0; int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f;
}
const int maxN=1000+5;
int N;
char an[maxN][maxN];
string s[8][8];
void init() {
	s[4][0]="aabc";
	s[4][1]="ddbc";
	s[4][2]="bcaa";
	s[4][3]="bcdd";
	s[5][0]="aabba"; 
	s[5][1]="bcc.a"; 
	s[5][2]="b..cb"; 
	s[5][3]="a..cb"; 
	s[5][4]="abbaa";
	s[6][0]="aabc..";
	s[6][1]="ddbc..";
	s[6][2]="..aabc";
	s[6][3]="..ddbc";
	s[6][4]="bc..aa";
	s[6][5]="bc..dd";
	s[7][0]="aabbcc.";
	s[7][1]="dd.dd.a";
	s[7][2]="..d..da";
	s[7][3]="..d..db";
	s[7][4]="dd.dd.b";
	s[7][5]="..d..dc";
	s[7][6]="..d..dc";
}
void work(int x,int y,int n) {
	for(int i=0;i<n;++i) for(int j=0;j<n;++j) an[x+i][x+j]=s[n][i][j];
}
int main() {
	init();
	read(N);
	if(N==2) puts("-1");
	else if(N==3) {
		puts("aa.");
		puts("..a");
		puts("..a");
	}
	else {
		int n=N;
		for(int i=0;i<n;++i) for(int j=0;j<n;++j) an[i][j]='.';
		while(n>7) work(n-4,n-4,4),n-=4;
		work(0,0,n);
		for(int i=0;i<N;++i) {
			for(int j=0;j<N;++j) printf("%c",an[i][j]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 4584
S = input()
if len(S) % 2 == 1:
  print("No")
else:
  while (len(S) != 0):
    if S[0] == 'h' and S[1] == 'i':
      S = S[2:]
    else:
      break
  if len(S) != 0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 3060
def main():
    N, M = map(int, input().split())
    b_cnt = 2 ** N #箱の数は最大12個
    INF = 10 ** 9
    dp = [INF] * b_cnt
    dp[0] = 0

    for i in range(M):
        a, b = map(int, input().split())
        c = sum([2 ** (int(x)-1) for x in list(input().split())])
        for j in range(b_cnt):
            if dp[j|c] > dp[j] + a:
                dp[j|c] = dp[j] + a

    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, _): (usize, usize) = read();
    let d: Vec<usize> = readnc();

    let mut m: Vec<bool> = vec![true; 10];
    for di in d {
        m[di] = false;
    }

    for i in n..(n+1000000) {
        if ok(i, &m) {
            println!("{}", i);
            break;
        }
    }
}

fn ok(num: usize, m: &Vec<bool>) -> bool {
    let mut num = num;
    while num >= 1 {
        if !m[num%10] {
            return false;
        }
        num /= 10;
    }
    true
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
using namespace std;
long long cur = 100;
long long n;
int main() {
	cin >> n;
	for (int i = 1; i <= 10000; i++) {
		cur = cur + cur * 0.01;
		if (cur >= n) {
			cout << i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int h[999];
  h[0]=1;
  for(int i=1;i<999;i++) h[i]=h[i-1]+i+1;
  int ans;
  for(int i=0;i<999;i++){
    int j=i+1;
    if(h[i]-a == h[j]-b){
      ans=h[i]-a;
    }
  }
  cout << ans << endl;
  return 0;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MD = 1e9 + 7;
map<pair<ll, ll>, int> ma;
int quick_pow(int x, int y) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = 1LL * ans * x % MD;
        y >>= 1;
        x = 1LL * x * x % MD;
    }
    return ans;
}
int main() {
    int n, s = 0, s1 = 0, s2 = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        ll d = __gcd(a, b);
        if(d == 0) {
            s++;
            continue;
        }
        if(a == 0) {
            s1++;
            continue;
        }else if(b == 0) {
            s2++;
            continue;
        }
        a /= d, b /= d;
        if(a < 0) a = -a, b = -b;
        ma[{a, b}]++;
    }
    ll ans = (1LL * quick_pow(2, s1) + quick_pow(2, s2) - 1 + MD) % MD;
    for(auto it : ma) {
        if(it.second == 0) continue;
        ll a = it.first.first, b = it.first.second;
        ll d = quick_pow(2, ma[{a, b}]);
        b = -b;
        if(b < 0) a = -a, b = -b;
        if(ma.count({b, a})) {
            d = (d + quick_pow(2, ma[{b, a}]) - 1) % MD;
            ma[{b, a}] = 0;
        }
        ans = ans * d % MD;
    }
    ans = (ans - 1 + s + MD) % MD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 16200
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int r, g, b, n, i, j, ans;

    scanf("%d%d%d%d", &r, &g, &b, &n);

    ans = 0;
    i = 0;
    while (r * i <= n)
    {
        j = 0;
        while (r * i + g * j <= n)
        {
            if ((n - r * i - g * j) % b == 0)
                ans++;
            j++;
        }
        i++;
    }

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

    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	int t=1;
	//cin>>t;
	
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		
		int *arr=new int[n];
		for(int i=0;i<n;i++)
		{
			cin>>arr[i];
		}
		
		int* dp=new int[n];
		dp[0]=0;
		dp[1]=abs(arr[1]-arr[0]);
		
		for(int i=2;i<n;i++)
		{
			dp[i]=INT_MAX;
			for(int j=i-1;j>=0&&j>=i-k;j--)
			{
				dp[i]=min(dp[i],abs(arr[i]-arr[j])+dp[j]);
			}
			
		}
		
		
		cout<<dp[n-1]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 4336
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#define LL long long
#define num 50
using namespace std;

int main()
{
 LL N,i,p[num],swap_cnt,cpy[num];
 
  scanf("%lld",&N);
  
  for(i=0;i<N;i++){
  	
    scanf("%lld",&p[i]);
   
  }
  
  
  for(i=0;i<N;i++){
  	
    cpy[i]=p[i];
    
  }
  
  sort(p,p+N);
  
  for(i=0;i<N;i++){

    if(cpy[i]!=p[i]){
    	swap_cnt++;
    }
    
  }
  
  if(swap_cnt==2||swap_cnt==0){
    puts("YES");
  }else{
  	puts("NO"); 
  }
   
     return 0;
}

Measured memory_bytes: 128
// inputに入力データ全体が入る
    function Main(input) {
    	// 1行目がinput[0], 2行目がinput[1], …に入る
    	input = input.split("\n");
      tmp = input[0].split(" ");
      
    	//文字列から10進数に変換するときはparseIntを使います
    	var N = parseInt(tmp[0], 10);
    	var A = parseInt(tmp[1], 10);
    	var B = parseInt(tmp[2], 10);

      var CalcA = A * N;

      if( CalcA <= B){
      	console.log('%d',CalcA);
      }else{
        console.log('%d',B);
      }

    	//出力
    	//console.log('%d %s',a+b+c,s);
    }

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



Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
using namespace std;
void dice(){
  int d1,d2,d3,d4,d5,d6;
  cin>>d1>>d2>>d3>>d4>>d5>>d6;

  char dir;
  int tmp;
  while(true){
      cin>>dir;
      if(cin.eof()) break;
      if(dir=='E'){
          tmp=d1;d1=d4;d4=d6;d6=d3;d3=tmp;
      }else if(dir=='N'){
          tmp=d1;d1=d2;d2=d6;d6=d5;d5=tmp;
      }else if(dir=='S'){
          tmp=d1;d1=d5;d5=d6;d6=d2;d2=tmp;
      }else if(dir=='W'){
          tmp=d1;d1=d3;d3=d6;d6=d4;d4=tmp;
      }
  }
  cout<<d1<<endl;
}
int main(){
  dice();
  return 0;
}


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

const int mod=1000000007;
int f[61][61][61],n,c[61][61];

int main()
{
	for (int i=0; i<=60; i++)
	{
		c[i][0]=1;
		for (int j=1; j<=i; j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	scanf("%d",&n);
	for (int i=1; i<=n; i++) f[1][i/2][(i-1)/2]=n;
	for (int i=1; i<=n; i++)
		for (int j=0; j<=n; j++)
			for (int k=(j==0); k<=n; k++)
				if (f[i][j][k])
					for (int l=0; i+j+k+l<=n; l++)
						for (int m=0; i+j+k+l+m<=n; m++)
							if (max(0,l-m)<=min(k,l-m+j))
								f[i+j+k][l][m]=(f[i+j+k][l][m]+1ll*f[i][j][k]*c[j+k][m-l+k]%mod*c[n-i][j+k])%mod;
	printf("%d\n",f[n][0][0]);
	return 0;
}

Measured memory_bytes: 640
n, x = map(int, input().split())
l = list(map(int, input().split()))
t = 0
c = 0

for i in range(len(l)):
    t += l[i]
    if x < t:
        print(i + 1)
        c += 1
        break

if c == 0:
    print(n + 1)


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

int main() {
    ll N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> F[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    sort(F.begin(), F.end());
    ll cost = 0;
    ll ans = F[0] * A[0];
    ll l = -1;
    ll r = 100000000000000000ll;
    ll m;
    // for (int i = 0; i < N; i++) {
    //     cout<< F[i] << " " << A[i] << "\n";
    // }
    while (r - l > 1) {
        m = l + (r - l) / 2;
        cost = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] * F[i] > m) {
                cost += (A[i] * F[i] - m + F[i] - 1) / F[i];
            }
        }
       
        if (cost <= K) {
            ans = m;
            r = m;
        } else {
            l = m;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    double ans = 0;
    repl(i, 1, n + 1) {
        double p = 1;
        int x = i;
        while(x < k) {
            p *= 0.5;
            x *= 2;
        }
        ans += p / n;
    }
    cout << setprecision(15) << ans << endl;
    return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
	return 0;
}

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

int main(void){
	int A;
	int B;
	scanf("%d %d", &A, &B);
	
	if(1<=A<=100 && 1<=B<=100){
		if(A%3 == 0||B%3 == 0||(A+B)%3 == 0){
			printf("Possible");
		} else {
			printf("Impossible");
			}
	} else {
		exit(1);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

const int Maxn = 110;

int ans[Maxn][Maxn];
vector<int> v;

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    REP(i,1,n + 1){
        int a;
        cin >> a;
        REP(j,0,a){
            v.push_back(i);
        }
    }

    int p = 0;
    REP(i,0,h){
        REP(j,0,w){
            if (i % 2 == 0) ans[i][j] = v[p];
            else ans[i][w - 1 - j] = v[p];
            p++;
        }
    }

    REP(i,0,h){
        REP(j,0,w){
            if (j != 0) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }

        Arrays.sort(H);
        long sum = 0;

        for (int i = 0; i < N - K; i++) {
            sum += H[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 64956
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;

int a[N], n, x;

int main(){
	scanf("%d%d", &n, &x);
	for (int i = 0; i < n; ++ i)
		scanf("%d", &a[i]);
	ll ans = 0;
	if (a[0] > x){
		ans = a[0] - x;
		a[0] = x;
	}
	for (int i = 1; i < n; ++ i){
		if (a[i - 1] + a[i] > x){
			ans += a[i - 1] + a[i] - x;
			a[i] = x - a[i - 1];
		}
	}
	printf("%lld", ans);
	return 0;
}

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

#define int long long
#define max(a,b) max((signed)a,(signed)b)
#define mn(a,b) min((signed)a,(signed)b)

using namespace std;

signed main(){
	string n;
	cin>>n;
	if(islower(n[0])){
		cout<<"a";
	}
	else{
		cout<<"A";
	}
}

Measured memory_bytes: 3624
import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] count = new int[1001];

        for (int i = 2; i <= n; i++) {
            int x = i;
            for (int j = 2; j <= i; j++) {
                while (x % j == 0) {
                    x /= j;
                    count[j]++;
                }
            }
        }
        
        long ans = 1;
        for (int i=2; i<=n; i++){
            ans = ans*(count[i]+1) % 1000000007;
                                       
        }
        System.out.println(ans);
        
    }
    
}


Measured memory_bytes: 21716
n, k = map(int, input().split())
MOD = 10**9 + 7

fact = [0] * (n+1)
inv_fact = [0] * (n+1)

fact[0] = 1
for i in range(1, n+1):
    fact[i] = fact[i-1] * i % MOD

inv_fact[n] = pow(fact[n], MOD-2, MOD)
for i in range(n, 0, -1):
    inv_fact[i-1] = inv_fact[i] * i % MOD


def nCk(n, k):
    return fact[n] * inv_fact[k] * inv_fact[n-k] % MOD
  
ans = 1
for i in range(1, n):
    if i > k:
      break
    ans += nCk(n, i) * nCk(n-1, n-i-1) % MOD
print(ans % MOD)

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

const int times = 3;

int main() {
	string s, t;
	int k, sz;
	cin >> t >> k;
	
	vector<long long> change(times, 0);
	
	for (int len = 0; len < times; ++len) {
		s += t;
		sz = s.size();
		for (int i = 1; i < sz; ++i) {
			if (s[i] == s[i - 1]) {
				++change[len];
				s[i] = '0';
			}
		}
		// printf("change[%d]: %lld\n", len, change[len]);
	}
	
	if (k & 1) {
		cout << change[0] + (change[1] + change[2]) * (k >> 1) << "\n";
	}
	else {
		cout << change[0] + (change[1] + change[2]) * (k >> 1) - change[2] << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string t;
    cin >> t;
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        s += s;
        for (int j = 0; j <= s.length() - t.length(); j++) {
            if (s.substr(j, t.length()) == t) {
                ans++;
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int r,d,x;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> r >> d >> x;
	rep(10){
		x=x*r-d;
		print1(x);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

struct node{
	string key;
	string value;
	int depth;
	vector<int> child;
};

signed main(){
	vector<string> str;
	string q;
	{
		getline(cin, q);
		string s;
		while(getline(cin, s)){
			str.emplace_back(s);
		}
	}

	vector<node> t;
	t.emplace_back(node{"root", "", -1, vector<int>()});

	vector<int> parent;
	parent.emplace_back(0);
	for(auto& s : str){
		int depth = 0;
		for(auto c : s){
			if(c != ' ') break;
			depth++;
		}
		s = s.substr(depth);

		while(depth <= t[parent.back()].depth){
			parent.pop_back();
		}

		int c;
		rep(i,s.size()){
			if(s[i] == ':'){
				c = i;
			}
		}
		string key = s.substr(0, c);
		string value = c + 1 == s.size() ? "" : s.substr(c + 2);

		t[parent.back()].child.emplace_back(t.size());
		t.emplace_back(node{key, value, depth, vector<int>()});
		if(c + 1 == s.size()){
			parent.emplace_back(t.size() - 1);
		}
	}

	//for(auto i:t){ cout << i.key << ' ' << i.value << endl; cout << i.child << endl; }

	auto search = [&](int cur, string& word){
		for(auto to : t[cur].child){
			if(t[to].key == word){
				return to;
			}
		}
		return -1LL;
	};

	string word;
	int idx = 0;
	q += '.';
	range(i,1,q.size()){
		if(q[i] == '.'){
			idx = search(idx, word);
			if(idx == -1){
				cout << "no such property" << endl;
				return 0;
			}
			word = "";
		}else{
			word += q[i];
		}
	}

	if(t[idx].value.empty()){
		cout << "object" << endl;
	}else{
		cout << "string \"" << t[idx].value << "\"" << endl;
	}
}



Measured memory_bytes: 3384
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

int main() {
	
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (a + b > c + d) { cout << "Left" << endl; };

	if (a + b == c + d) { cout << "Balanced" << endl; };

	if (a + b < c + d) { cout << "Right" << endl; };
}

Measured memory_bytes: 256
import sys
import heapq


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    a = [-v for v in list(map(int, input().rstrip('\n').split()))]
    heapq.heapify(a)
    for i in range(m):
        t = -heapq.heappop(a)
        heapq.heappush(a, -(t // 2))
    print(-sum(a))


if __name__ == '__main__':
    solve()


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

int main()
{
    long N, A, B, count, c;
    cin >> N >> A >> B;
    c = N / (A + B);
    count = c * A;
    if (N - c * (A + B) >= A)
    {
        count += A;
    }
    else
    {
        count += N - c * (A + B);
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 ,-1};
signed main(){
    int H,W;
    cin >> H >> W;
    vector<string>S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<vector<int>>cnt(H,vector<int>(W));
    for(int i = 0; i < H; i++) {
        int sum = 0;
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '.')sum++;
            else sum = 0;
            cnt[i][j] += sum;
        }
    }
    for(int i = 0; i < H; i++) {
        int sum = 0;
        for(int j = W-1; j >= 0; j--) {
            if(S[i][j] == '.')sum++;
            else sum = 0;
            cnt[i][j] += sum;
        }
    }
    for(int i = 0; i < W; i++) {
        int sum = 0;
        for(int j = 0; j < H; j++) {
            if(S[j][i] == '.')sum++;
            else sum = 0;
            cnt[j][i] += sum;
        }
    }
    for(int i = 0; i < W; i++) {
        int sum = 0;
        for(int j = H-1; j >= 0; j--) {
            if(S[j][i] == '.')sum++;
            else sum = 0;
            cnt[j][i] += sum;
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            ans = max(ans,cnt[i][j]);
        }
    }
    cout << ans-3 << endl;
}


Measured memory_bytes: 42284
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back
#define mp make_pair

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

ll a[3010];

ll memo[3010][3010];
int cached[3010][3010];
ll dp(int l, int r) {
  if (l > r) return 0;
  if (cached[l][r]) return memo[l][r];
  cached[l][r] = true;
  ll bst = max(-dp(l, r - 1) + a[r], -dp(l + 1, r) + a[l]);
  return memo[l][r] = bst;
}

int main() {
  // code
  memset(cached, 0, sizeof(cached));

  int n;
  cin >> n;

  rep(i, 0, n) cin >> a[i];

  cout << dp(0, n - 1) << endl;

  // codend
}


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

const int MAXH = 30;
const int MAXW = 30;
int W, H;
char G[MAXH][MAXW];

int dfs(int x, int y) {
  const static int dx[] = {1,0,-1,0};
  const static int dy[] = {0,1,0,-1};
  G[y][x] = '#';
  int res = 1;
  for(int k = 0; k < 4; ++k) {
    int nx = x + dx[k];
    int ny = y + dy[k];
    if(nx < 0 || nx >= W) continue;
    if(ny < 0 || ny >= H) continue;
    if(G[ny][nx] == '#') continue;
    res += dfs(nx, ny);
  }
  return res;
}

int main() {
  for(; cin >> W >> H && (W|H);) {
    int sx, sy;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] == '@') {
          sx = j;
          sy = i;
        }
      }
    }
    cout << dfs(sx, sy) << endl;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
typedef int64_t int64;
using namespace std;

void fastscan(int &number) {
    bool negative = false;
    int c;
    number = 0;
    c = getchar();
    if (c == '-') {
        negative = true;
        c = getchar();
    }
    for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
    if (negative) number *= -1;
}
     
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
        
    int N; fastscan(N);
    int A[N];
    for (int i = 0; i < N; ++i) fastscan(A[i]);
     
    int64 s[N] = {};
    s[0] = A[0];
    for (int i = 1; i < N; ++i) {
        s[i] = A[i] + s[i - 1];
    }
     
    sort(s, s + N);
     
    int64 answer = 0;
    int begin = 0;
     
    for (int i = 0; i < N; ++i) {
        if (s[i] == 0) ++answer;
    }
     
    while (begin < N){
        int end = begin;
        while (end + 1 < N && s[end + 1] == s[begin]) ++end;
        int64 len = end - begin + 1;
        answer += len * (len - 1) / 2;
        begin = end + 1;
    }
    cout << answer << '\n';          
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int n,preA,preB,preC;
bool ans = true;

int main(){
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		int dis = abs(b-preB) + abs(c-preC);
		int time = a - preA - dis;
		if(time < 0 || time%2)
			ans = false;
		
		preA = a;
		preB = b;
		preC = c;
	}
	
	printf(ans ? "Yes" : "No"); 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MN = 5e3+5;

int A[MN], B[MN][202], cost[202];

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

	int N, M; cin >> N >> M;
	for (int i = 0; i < N-1; ++i) cin >> A[i];
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < M; ++j) cin >> B[i][j];
	
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ll sum = 0;
		for (int j = 0; j < M; ++j) sum += (cost[j] = B[i][j]);
		ans = max(sum, ans);
		for (int j = i+1; j < N; ++j) {
			sum -= A[j-1];
			for (int k = 0; k < M; ++k) {
				if (cost[k] < B[j][k]) sum += (B[j][k]-cost[k]), cost[k] = B[j][k];
			}
			ans = max(sum, ans);
		}
	}
	cout << ans;
}


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

int main() {
    int a, b;
    cin >> a>> b;
    cout << (a + b + 1) / 2 << endl;
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  bool flag=true;
  for (int i=1; i<s.size(); i++) 
    if (s[i-1]==s[i]) flag=false;
  if (flag)
    cout<<"Good"<<endl;
  else
    cout<<"Bad"<<endl;
  return 0;
}



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

typedef long long ll;

ll N;
vector<vector<ll>> Kids;
vector<ll> X;
const ll MAX_X = 5000;

pair<ll, ll> dfs(ll v) {
  ll sum_total = 0;
  bitset<MAX_X + 1> sums;
  sums[0] = 1;
  for (ll w : Kids[v]) {
    ll sum0, sum1;
    tie(sum0, sum1) = dfs(w);
    if (sum0 < 0) return make_pair(-1, -1);
    sums = (sums << sum0) | (sums << sum1);
    sum_total += sum0 + sum1;
  }
  for (ll sum = X[v]; sum >= 0; --sum) {
    if (sums[sum]) return make_pair(X[v], sum_total - sum);
  }
  return make_pair(-1, -1);
}
int main() {
  cin >> N;
  Kids.resize(N);
  for (ll v = 1; v < N; ++v) {
    ll p;
    cin >> p;
    --p;
    Kids[p].push_back(v);
  }
  X.resize(N);
  for (ll v = 0; v < N; ++v) cin >> X[v];
  cout << (dfs(0).first >= 0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <set>

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

    int ans = 1;
    for (int n = 2; n <= X; n++) {
        int cur = n * n;
        while (cur <= X) {
            ans = std::max(ans, cur);
            cur *= n;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
vector<vll> S;
vector<bool> vis;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli n;
	cin>>n;
	vll S(n);
	loop(i, 0, n)	cin>>S[i];
	vll sf(n, 0);
	vll pf(n, 0);
	pf[0] = S[0];
	loop(i, 1, n)	pf[i] = pf[i-1] + S[i];
	sf[n-1] = S[n-1];
	loopb(i, n-2, 0)	sf[i] = sf[i+1] + S[i];
	lli ans = 1e18;
	loop(i, 0, n-1){
		ans = min(ans, abs(pf[i] - sf[i+1]));
	}
	cout<<ans<<"\n";
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 5504
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;

    while (cin >> n && n) {
        int m = sqrt(n);
        int ans = 0;
        REP(i,m+1) FOR(j,i,m) FOR(k,j,m) FOR(l,k,m){
            if (i*i + j*j + k*k + l*l == n){
                ans++;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}







int main(){
 ll n;
 cin >> n;
 ll a[n+1];
 rep (i,n){
   cin >> a[i];
 }
 ll ans=a[0];
 rep (i,n-1){
   ans = gcd(ans,a[i+1]);
 }
 cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double Heron(double a, double b, double c){
  double s = (a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
  double a, l, x;
  while(cin >> a >> l >> x){
    double ABC = Heron(a, l, l);
    double ADC = Heron(l, (l+x)/2, (l+x)/2);
    cout << fixed << setprecision(10) << ABC+ADC*2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    sort(all(a)); sort(all(b)); sort(all(c));
    ll ans = 0;
    rep(i, 0, n) {
        ll upper = lower_bound(all(a), b[i]) - a.begin();
        ll lower = upper_bound(all(c), b[i]) - c.begin();
        ans += (n - lower) * upper;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int k, n;
    cin >> k >> n;
    for (int j = n - k + 1; j <= n - 1; j++)
        cout << j << " ";
    cout << n;
    for (int j = n + 1; j < n + k; j++)
        cout << " " << j;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<stdlib.h>
using namespace std;
int top=0,S[1000];

void p(int x)
{
    S[++top]=x;
}

int pop()
{
    top--;
    return S[top+1];
}
int main()
{
    int a,b;
    top=0;
    char s[100];

    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            a=pop();
            b=pop();
            p(a+b);
        }
        else if(s[0]=='-')
        {
            b=pop();
            a=pop();
            p(a-b);
        }else if(s[0]=='*')
        {
            a=pop();
            b=pop();
            p(a*b);
        }else p(atoi(s));
    }
    cout<<pop()<<endl;
    return 0;
}

Measured memory_bytes: 3212
import os, sys, re, math

def oneidx(S):
    idx = -1
    for s in S:
        if s == '1':
            idx += 1
        else:
            break
    return idx

S = input()
N = int(input()) - 1
idx = oneidx(S)

if idx >= N:
    print('1')
else:
    print(S[idx+1])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int h,w;
    cin >> h >> w;
    string s[h];
    rep(i,h)cin >> s[i];

    int ans = 0;

    rep(i,w-1){
        int c[h+1][h+1];
        int dp[h+1][h+1];
        /*
        rep(j,h+1){
            rep(k,h+1){
                c[j][k] = 0;
                dp[j][k] = 0;
            }
        }
        */

        rep(j,h+1){
            c[0][j] = 0;
            int k = 1;
            while(j+k<=h){
                c[k][j+k] = c[k-1][j+k-1];
                if(s[k-1][i] == s[j+k-1][i+1])c[k][j+k]++;
                k++;
            }
        } 
        rep(j,h+1){
            c[j][0] = 0;
            int k = 1;
            while(j+k<=h){
                c[j+k][k] = c[j+k-1][k-1];
                if(s[j+k-1][i] == s[k-1][i+1])c[j+k][k]++;
                k++;
            }
        }
        drep(l,h*2+1){
            rep(j,l+1){
                int k = l - j;
                if(j > h)break;
                if(k < 0)break;
                if(k > h)continue;
                if(j == h && k == h){
                    dp[j][k] = 0;
                    continue;
                }
                dp[j][k] = 1001001001;
                if(j < h){
                    dp[j][k] = min(dp[j][k], dp[j+1][k] + c[j+1][k]);
                }
                if(k < h){
                    dp[j][k] = min(dp[j][k], dp[j][k+1] + c[j][k+1]);
                }
            }
        }
        ans += dp[0][0];
        /*
        drep(j,h+1){
            rep(k,h+1){
                cout << c[j][k] << ' ';
            }
            cout << endl;
        }
        cout << dp[0][0] << endl;
        */

    }

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


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];
    int d=a[0];
    int s=0;
    for(int i=0;i<n;++i)
    {
        if(a[i]<=d)
            ++s;
        d=min(d,a[i]);
        if(a[i]==1)
            break;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 4412