akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int id;
  int parent;
  int depth;
  int k;
  int *child;
} node;

node tree[100000];


int main(){

  int n,i,j,count,k,m;
  scanf("%d",&n);

 for(i=0;i<n;i++){
   tree[i].parent = -1;
   tree[i].depth = 0;
 }
 
 for(i=0;i<n;i++){
   scanf("%d",&m);
   tree[m].id = m;
   scanf("%d",&tree[m].k);
   tree[m].child = malloc(tree[m].k * sizeof(int));
   for(j=0;j<tree[m].k;j++){
     scanf("%d",&tree[m].child[j]);
     tree[tree[m].child[j]].parent = m;
   }
 }

 for(i=0;i<n;i++){
   j = i;
   while(tree[j].parent != -1){
     j = tree[j].parent;
     tree[i].depth++; 
   }
 }

 
 for(i=0;i<n;i++){
   printf("node %d: parent = %d, depth = %d, ",tree[i].id,tree[i].parent,tree[i].depth);
   if(tree[i].parent == -1) printf("root, [");
   else if(tree[i].k == 0) printf("leaf, [");
   else printf("internal node, [");
   for(k=0;k<tree[i].k;k++){
     printf("%d",tree[i].child[k]);
     if(k != tree[i].k - 1) printf(", ");
   }
   printf("]\n");
   free(tree[i].child);
 }
 
 return 0;
}
    
    

Measured memory_bytes: 6360
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=64;
const int mod=1e9+7;
bool lim[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	template <class T> inline T nxi(){
		T x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

//p: 进位　up: 上界
int dfs_dp(const int t,const bool p,const bool up){
	static int dp[N][2][2];
	if(t<0) return !p;
	if(dp[t][p][up]) return dp[t][p][up];
	int ans=0;
	bool u0=up&&(lim[t]==0);
	if(p==0){
		ans=(ans+dfs_dp(t-1,0,u0))%mod;		//0 0
		if(!up||lim[t]){
			ans=(ans+dfs_dp(t-1,1,up))%mod;	//0 0
			ans=(ans+dfs_dp(t-1,0,up))%mod;	//0 1
		}
	}
	else{
		ans=(ans+dfs_dp(t-1,1,u0))%mod;		//0 1
		ans=(ans+dfs_dp(t-1,0,u0))%mod;		//1 1
		if(!up||lim[t]){
			ans=(ans+dfs_dp(t-1,1,up))%mod;	//1 1
		}
	}
	return dp[t][p][up]=ans;
}

int solve(lint n){
	int t=0;
	for(; n; ++t,n>>=1){
		lim[t]=n&1;
	}
	return dfs_dp(t,0,1);
}

int main(){
	printf("%d\n",solve(nxi<lint>()));
	return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let a: usize = read();
    let b: usize = read();

    let ans = 6 - a - b;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    string s ; cin >> s ;
    cout << s.substr(0, 3) << endl ;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String origin = sc.next();
		char[] oArray = origin.toCharArray();
		char[] wArray = new char[oArray.length];
		char[] bArray = new char[oArray.length];
			for(int i=0;i<oArray.length;i++) {
				if(i%2==0) {
					wArray[i]='0';
				}else {
					wArray[i]='1';
				}
			}
			for(int i=0;i<oArray.length;i++) {
				if(i%2==0) {
					bArray[i]='1';
				}else {
					bArray[i]='0';
				}
			}
		int wcount=0;
		int bcount=0;
		for(int i=0;i<oArray.length;i++) {
			if(oArray[i]!=wArray[i]) wcount++;
			if(oArray[i]!=bArray[i])bcount++;
		}
		System.out.println(Math.min(wcount,bcount));
	}
}


Measured memory_bytes: 25896
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<int> a;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    a.push_back(tmp);
  }
  sort(a.begin(),a.end(),greater<int>());
  int ans = 0;
  for(int i = 0; m > i; i++){
    ans += a[i];
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int w = Integer.parseInt(scan.next());
		String str[] = s.split("");
		
		String st = "";
		
		for(int i=0;i < str.length;i =  i + w) {
			st = st + str[i];
		}
		System.out.println(st);
		scan.close();
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}
int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<pair<int, vector<int>>> v(n, pair<int, vector<int>>(0, vector<int>(m)));
    FOR(i, n)
    {
        cin >> v[i].first;
        FOR(j, m)
        {
            cin >> v[i].second[j];
        }
    }
    int best = INT_MAX;
    FOR(i, (1 << n))
    {
        VI t(m);
        int cost = 0;
        FOR(j, n)
        {
            if ((i >> j) & 1)
            {
                cost += v[j].first;
                FOR(k, m)
                {
                    t[k] += v[j].second[k];
                }
            }
        }
        bool ok = true;
        FOR(k, m)
        {
            if (t[k] < x)
            {
                ok = false;
                break;
            }
        }
        if (ok and cost < best)
            best = cost;
    }
    cout << (best == INT_MAX ? -1 : best);
}

Measured memory_bytes: 3640
package main

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

func main() {
	A, B, S := ReadInt(), ReadInt(), ReadString()
	ok := true
	for i := 0; i < A; i++ {
		if !('0' <= S[i] && S[i] <= '9') {
			ok = false
			break
		}
	}
	if S[A] != '-' {
		ok = false
	}
	for i := A + 1; i < A+B+1; i++ {
		if !('0' <= S[i] && S[i] <= '9') {
			ok = false
			break
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int N,D,X;
int ans;

int main()
{
    scanf("%d%d%d",&N,&D,&X);

    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        for(int j = 1; j <= D; j += a)ans++;
    }

    printf("%d\n",ans + X);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
#define ma 100001
#define mod 1000000007
#define ll long long int
using namespace std;
int main(){
	int n=0,k=0;
	cin >> n >> k;
	vector <int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	vector<bool> dp(k+1);
	for(int x=0;x<k+1;x++){
		for(int s=0;s<n;s++){
			if(x>=v[s] && !dp[x-v[s]]){
				dp[x]=true;	
			}
		}
	}
	if(dp[k]==true){
		cout << "First";
	}
	else{
		cout << "Second";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
const int MOD = 998244353;
 
inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }
 
inline int power(int x, int k) {
  int tmp = 1;
  while(k) {
    if(k & 1) tmp = mul(tmp,x);
    x = mul(x,x);
    k >>= 1;
  }
  return tmp;
}

int n, cnt[4], a[4], b[4];
char s[maxn];

inline int get(char c) {
	if(c == 'R') return 0;
	if(c == 'G') return 1;
	if(c == 'B') return 2;
}

int main() {
//	freopen("data.in","r",stdin);
  scanf("%d%s", &n, s + 1);
	int Ans = 1;
	for(int i = 1;i <= n;i ++) Ans = mul(Ans,i);
	for(int i = 1;i <= 3 * n;i ++) {
		for(int j = 0;j < 3;j ++) a[j] = cnt[j];
		cnt[get(s[i])] ++;
		for(int j = 0;j < 3;j ++) b[j] = cnt[j];
		sort(a,a + 3); sort(b,b + 3);
		if(a[0] != b[0]) Ans = mul(Ans,a[1] - a[0]);
		if(a[1] != b[1]) Ans = mul(Ans,a[2] - a[1]);
	}
	printf("%d\n", Ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi l(N);
    cin >> l;
    sort(ALL(l));
    REP(i, N) {
        FOR(j, i + 1, N) {
            FOR(k, j + 1, N) {
                if (l[i] == l[j] || l[j] == l[k] || l[i] == l[k])
                    continue;
                if (l[i] + l[j] > l[k]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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

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

    REP(i, 0, S.size()) {
        char tmp = S[i] + N;
        if (tmp > 'Z') {
            tmp = (tmp % 'Z') + '@';
        }
        cout << tmp;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
use strict;
use warnings;

chomp(my $n = <>);
chomp(my $input = <>);
my @a = split(/ /, $input);

for (my $i = 0; $i < $n; $i++){
  if ($a[$i] % 2 == 0 && $a[$i] % 3 != 0 && $a[$i] % 5 != 0) {
    print "DENIED\n";
    exit;
  }
}

print "APPROVED\n";


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define MAX_N 100
#define INF 100000
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, s, t) for(int i=s; i<=s; ++i)

using namespace std;

int field[2001][2001];

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    const int dx=tx-sx, dy=ty-sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy+1, 'U') << string(dx+1, 'R') << 'D';
    cout << 'R' << string(dy+1, 'D') << string(dx+1, 'L') << 'U' << endl;

    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    int n, d;
    map<int, bool> m;
  
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d;
 
        auto p = m.find(d);

        if (p == end(m)) {
            m[d] = true;
        } else {
            m.erase(p);
        }
    }

    cout << m.size() << endl;

    return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            long N = long.Parse(Console.ReadLine());

            int k = 0;
            int keta = 0;

            if (N > 0) {
                k = (int)Math.Ceiling(Math.Log10(3 * N + 1) / Math.Log10(4)) - 1;
                keta = 2 * k + 1;
            } else if (N < 0) {
                k = (int)Math.Ceiling(Math.Log10(1 - 1.5f * N) / Math.Log10(4));
                keta = 2 * k;
            } else {
                Console.WriteLine(0);
                return;
            }

            string ans = "";

            for (int i = 0; i < keta; i++) {
                if (N % 2 == 0) {
                    ans = "0" + ans;
                } else {
                    ans = "1" + ans;
                    N -= 1;
                }
                N /= -2;
            }

            Console.WriteLine(ans);
        }

    }
}

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

using namespace std;

int a, b, c;
int ans;

int main(){
	ans = 100000000;
	
	cin >> a >> b >> c;
	int x = max(a, max(b, c));
	if(3*x % 2 == (a+b+c) % 2) ans = (3*x-(a+b+c))/2;
	else ans = (3*(x+1)-(a+b+c))/2;
	cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);
    REP(i, N - 1) {
        if (A[i] == A[i + 1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    char a;
    while(scanf("%c",&a)==1)
    {
        if(a=='C')
            printf("G\n");
        if(a=='G')
            printf("C\n");
        if(a=='A')
        printf("T\n");
        if(a=='T')
            printf("A\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define foR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define fors(i, n, s) for (int i = 0; i < (int)(n); i += s)
#define foRs(i, a, b, s) for (int i = (int)(a); i < (int)(b); i += s)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define foRr(i, a, b) for (int i = (int)(a) - 1; i >= (int)(b); --i)

#define prnt(a) cout << (a)
#define prntl(a) cout << (a) << endl
#define in insert
#define rem remove
#define er erase

#define linf ((ll) 1e9)
#define inf ((int) 1e5)
#define otherinf 555555

#define mod 1000000007

int main()
{
	ll a, b;
	cin >> a >> b;
	if(a== 1)
		a= 15;
	if(b== 1)
		b= 15;

	if(a>b)
		cout << "Alice";
	else if (b> a)
		cout << "Bob";
	else cout << "Draw";

	return 0;
}

Measured memory_bytes: 256
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
d=set()
for i in range(1,int(sum(a)**0.5)+5):
    if s%i==0: d.add(i);d.add(s//i)
d=sorted(list(d),reverse=True)
for x in d:
    b=sorted([a[i]%x for i in range(n)],reverse=True)
    s=sum(b)
    p=s//x
    if s-sum(b[:p])<=k: break
print(x)

Measured memory_bytes: 42204
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
bool cmp(int val1,int val2){
	return val1>val2;
}
int main(){
	int A,B;
	cin>>A>>B;
	string s,r;
	int cnt =0;
	for(int n=A;n<=B; n++){
		s = to_string(n);
		r = s;
		reverse(all(r));
		if(s.compare(r)==0) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

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

using namespace std;

int main() 
{
	int n;
	cin >> n;
	vector <int> l, m;
	l.resize(n);m.resize(n);
	for (int i = 0;i < n;i++) cin >> l[i] >> m[i];

	int count = 0;
	for (int i = 0;i < n;i++)
	{
		count += m[i] - l[i] + 1;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional>
// using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
int main()
{
//   ios_base::sync_with_stdio(false);
//   cin.tie(NULL);
//   cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
  // tes(t)
  // {
  // }
  ll x;
  ll a[105]={0};
  ll n;
  cin>>x>>n;
  rep(i,0,n-1)
  {
    ll b;
    cin>>b;
    a[b]++;

  }
  ll ans,ans1;
  rep(i,x,101)
  {
    if(a[i]==0)
    {ans=i;
     break;
    }
  }
  // cout<<ans;
  repd(i,x,0)
  {
    if(a[i]==0)
    {
      ans1=i;
      break;
    }
  }
  if(x-ans1<=ans-x)
  cout<<ans1;
  else cout<<ans;

}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int V[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	int ret=0;
	int L=-1,R=-1;
	FOR(i,N) {
		cin>>x;
		if(L==-1) {
			L=R=x;
			ret++;
		}
		else if(L==R || R==x) {
			R=x;
		}
		else {
			if(L<R) {
				if(x<R) {
					L=R=x;
					ret++;
				}
				else {
					R=x;
				}
			}
			else {
				if(x<R) {
					R=x;
				}
				else {
					L=R=x;
					ret++;
				}
			}
		}
	}
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,m,x[100000],sa[100000],ans=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d",&x[i]);
    }
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        sa[i]=x[i+1]-x[i];
    }
    if(m-1>0){
        sort(sa,sa+m-1);
        for(int i=0;i<m-n;i++){
            ans+=sa[i];
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int l, r;
    cin >> l >> r;

    if (r - l >= 2019)
        cout << "0\n";
    else
    {
        l %= 2019, r %= 2019;

        int ans = 2147483647;
        if (l > r)
        {
            vector<int> v;
            for (int i = l; i < 2019; i++)
                v.push_back(i);
            for (int i = 0; i <= r; i++)
                v.push_back(i);

            for (int i = 0; i < v.size(); i++)
                for (int j = i + 1; j < v.size(); j++)
                    ans = min(ans, i * j % 2019);
        }
        else
        {
            for (int i = l; i <= r; i++)
                for (int j = i + 1; j <= r; j++)
                    ans = min(ans, i * j % 2019);
        }
        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int m = Integer.parseInt(str2[1]);
    int l = Integer.parseInt(str2[2]);

    long[][] matrixA = new long[n][m];
    long[][] matrixB = new long[m][l];
    long[][] matrixC = new long[n][l];

    for (int i = 0; i < n; i++){
      String[] str3 = br.readLine().split(" ");
      for(int j = 0; j < m; j++){
        matrixA[i][j] = Integer.parseInt(str3[j]);
      }
    }
    for (int i = 0; i < m; i++){
      String[] str4 = br.readLine().split(" ");
      for(int j = 0; j < l; j++){
        matrixB[i][j] = Integer.parseInt(str4[j]);
      }
    }
    for (int i = 0; i < n; i++){
      for (int j = 0; j < l; j++){
        for(int k = 0; k < m; k++){
          matrixC[i][j] += (matrixA[i][k] * matrixB[k][j]);
        }
      }
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n; i++){
      for (int j = 0; j < l; j++){
        sb.append(matrixC[i][j]);
        if(j < l - 1)
          sb.append(" ");
      }
        sb.append("\n");
    }
    System.out.print(sb);
  }
}

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

using namespace std;

int N, W, weight, value;
long long dp[100001];

int main() {
    cin >> N >> W;
    while (N--) {
        cin >> weight >> value;

        for (int j = W - weight; j >= 0; --j)
            dp[j + weight] = max(dp[j] + value, dp[j + weight]);
    }

    cout << dp[W];
    return 0;
}

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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code
	ll n;
	cin >> n;
	bool ans=false;
	forn(i,101){
		int rem=n-i*4;
		if(rem<0) continue;
		forn(j,101){
			int final=rem-j*7;
			if(final==0) ans=true;
		}
	}	
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i < (int)(n); i++)

const int mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  int keta;
  int top = k;
  int max = top - 1;
  rep (i, 100) {
    if (max >= n) {
      keta = i;
      break;
    }
    top *= k;
    max = top - 1;
  }
  // cout << max << " / " << k << endl;
  cout << keta << endl;
  return 0;

}



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

typedef long long ll;
typedef pair<int,int> P;

#define pb push_back
#define fr first
#define sc second

int main(){
	static int H,W;
	static string S[2002];
	scanf("%d%d",&H,&W);
	for(int i = 1 ; i <= H ; i ++){
		cin >> S[i];
	}
	
	static int a[2002][2002] = {};
	for(int i = 1 ; i <= H-1 ; i ++){
		for(int j = 1 ; j <= W-1 ; j ++){
			int cnt = 0;
			if(S[i][j-1] == '#')cnt ++;
			if(S[i+1][j-1] == '#')cnt ++;
			if(S[i][j] == '#')cnt ++;
			if(S[i+1][j] == '#')cnt ++;
			if(cnt%2 == 0)a[i][j] = 1;
		}
	}
	
	static int b[2002][2002] = {};
	for(int i = 1 ; i <= H-1 ; i ++){
		for(int j = W-1 ; j >= 1 ; j --){
			if(a[i][j] == 0){
				b[i][j] = 0;
			}
			else {
				b[i][j] = b[i][j+1]+1;
			}
		}
	}
	
	static int ret = max( H , W );
	for(int j = 1 ; j <= W-1 ; j ++){
		vector<P> vec;
		for(int i = 1 ; i <= H-1 ; i ++){
			vec.pb(P(b[i][j],i));
		}
		sort(vec.begin(),vec.end());
		set<int> s;
		s.insert(0);
		s.insert(H);
		for(int i = 0 ; i < vec.size() ; i ++){
			set<int>::iterator itr = s.lower_bound(vec[i].sc);
			int h = *itr;
			itr--;
			h -= *itr;
			ret = max( ret , (vec[i].fr+1)*h );
			s.insert(vec[i].sc);
		}
	}
	cout << ret << endl;
}
		



Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

bool comp1(const pii &a, const pii &b) {
	if (a.fi != b.fi)
		return a.fi > b.fi;
	else
		return a.se > b.se;
}

bool comp2(const pii &a, const pii &b) {
	if (a.fi != b.fi)
		return a.fi < b.fi;
	else
		return a.se < b.se;
}

int main() {
	fast_io;
	int n;
	cin >> n;
	string s[n];
	for (int i = 0;i < n;i++)
		cin >> s[i];
	vii po, ne;
	for (int i = 0;i < n;i++) {
		int del = 0, low = 0;
		for (auto c : s[i]) {
			if (c == '(')
				del++;
			else
				del--;
			low = min(low, del);
		}
		if (del >= 0)
			po.pb({low, del});
		else
			ne.pb({low - del, del});
	}
	sort(all(po), comp1);
	sort(all(ne), comp2);
	int cur = 0;
	bool ans = 1;
	for (auto x : po) {
		if (x.fi + cur < 0)
			ans = 0;
		cur += x.se;
	}
	for (auto x : ne) {
		if (x.se + x.fi + cur < 0)
			ans = 0;
		cur += x.se;
	}
	if (cur != 0)
		ans = 0;
	(ans && cout << "Yes\n") || cout << "No\n";
}


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

int A[MAX],n;

int  partition(int p,int r)
{
  int x,i,t,j;//t=change
  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[i]=A[j];
	  A[j]=t;
	}
    }
  t=A[i+1];// A[i+1] と A[r] を交換
  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: 2108
#include <iostream>
using namespace std;

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

    int a_count = 0;
    int b_count = 0;
    int c_count = 0;

    for(int i = 0; i < 3; i++) {
        if(S[i] == 'a') a_count++;
        if(S[i] == 'b') b_count++;
        if(S[i] == 'c') c_count++;
    }

    if(a_count == 1 && b_count == 1 && c_count == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e7
int dp[1<<20];
int t[20][20];
int n;


int main(){
  while(cin>>n && n){
    for(int i=0;i<n;i++)
      for(int j=0;j<=n;j++)
        cin>>t[i][j];
    for(int i=0;i<(1<<n);i++)
      dp[i]=INF;

    dp[0]=0; 
    for(int s=0;s<(1<<n);s++){
      for(int v=0;v<n;v++){
        if((s>>v)&1) continue;
        int co=t[v][0];
        for(int k=0;k<n;k++)
          if((s>>k)&1) co = min(co,t[v][k+1]);
        dp[(s|(1<<v))] = min(dp[(s|(1<<v))],dp[s]+co);
      }
    }
    cout<<dp[(1<<n)-1]<<endl;
  }
  return 0;
}

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

int main() {
	multiset<int, greater<int>> ms; int temp;
	for (int i = 0; i < 10; i++) {
		cin >> temp; ms.insert(temp);
	}
	multiset<int, greater<int>>::iterator itr = ms.begin();
	for (int i = 0; i < 3; i++, ++itr) {
		cout << *itr << endl;
	}
	return 0;
}


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

typedef long long ll;

int main() {

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

    ll a = 0, b = 0, c = 0, d = 0;
    cin >> a >> b >> c >> d;


    while(true) {

        c = c - b;
        if(c <= 0) {
            cout << "Yes\n";
            break;
        }
        a = a - d;
        if(a <= 0) {
            cout << "No\n";
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();		
		String s = r.str();
		Set<Character> set = new HashSet<>();
		for(char c : s.toCharArray()) {
			if(set.contains(c)) {
				print("no");
				return;
			}
			set.add(c);
		}
		print("yes");
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int l[222];
int main() {
	int n; scanf("%d", &n);
	n *= 2;
	rep(i, n) scanf("%d", &l[i]);
	sort(l, l + n);
	int ans = 0;
	rep(i, n) {
		if (i % 2 == 0) ans += l[i];
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 200
#define INF 922337203685477580

//問題文のとおり
LL Q,H,S,D,N;
LL ans=INF;
LL ansTemp;
LL NTemp;
int main() {
	cin>>Q>>H>>S>>D>>N;
	//1
	NTemp=N;
	ansTemp=NTemp*4*Q;
	ans=min(N*4*Q,ans);
	//2
	ans=min(N*2*H,ans);
	//3
	ans=min(N*S,ans);
	//4
	ans=min((N/2)*D+S*(N%2),ans);
	//5
	ans = min((N / 2)*D + H*(N % 2) * 2, ans);
	//6
	ans = min((N / 2)*D + Q*(N % 2) * 4, ans);

	cout<<ans<<endl;
	//cin>>N;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = (int)1e9 + 7;
int main() {
    int N, D; cin >> N >> D;
    vector<vector<int>> p(N, vector<int>(D));
    for (auto &pi: p) for (auto &pij: pi) cin >> pij;
    vector<int> v(D, INF);
    for (int j = 0; j < D; j++) {
        for (int i = 0; i < N; i++) chmin(v[j], p[i][j]);
    }
    vector<vector<int>> dp(D, vector<int>(N, INF));
    vector<vector<int>> rev(D, vector<int>(N));
    for (int hotel = 0; hotel < N; hotel++) if (v[D - 1] == p[hotel][D - 1]) {
        dp[D - 1][hotel] = 0, rev[D - 1][hotel] = -1;
    }
    for (int day = D - 2; day >= 0; day--) {
        for (int cur = 0; cur < N; cur++) for (int nxt = 0; nxt < N; nxt++) {
            if (v[day] != p[cur][day]) continue;
            if (chmin(dp[day][cur], dp[day + 1][nxt] + (cur != nxt))) {
                rev[day][cur] = nxt;
            }
        }
    }
    int it = min_element(dp[0].begin(), dp[0].end()) - dp[0].begin();
    cout << accumulate(v.begin(), v.end(), 0) << " " << dp[0][it] << endl;
    for (int d = 0; d < D; d++) cout << (it + 1) << endl, it = rev[d][it];
    return 0;
}


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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,a,b,ans;

main() {
    cin >> n >> a >> b;
    rep1(i,n) {
        int cnt=0,hoge=i;
        while(hoge) {
            cnt += hoge%10;
            hoge/=10;
        }
        if (cnt >= a && cnt <= b) ans += i;
    }
    ct(ans)
}

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

using namespace std;

const static inline void rec(int data) {
  if(data == 0) return;
  int next = abs(data) % 2;
  if(data < 0) next = (2 - next) % 2;
  rec((data - next) / -2);
  cout << next;
}

int main() {
  int N;
  cin >> N;
  if(N == 0) {
    cout << 0 << endl;
    return 0;
  }
  rec(N);
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 2000000 + 5, mod = 1e9 + 7;
int fpow(int base, int v) {
	int tot = 1;
	for(; v; v >>= 1, base = 1LL * base * base % mod) if (v & 1) tot = 1LL * tot * base % mod;
	return tot;
}
int fac[N], invfac[N], x[7], y[7], ans;
int F(int x1, int y1, int x2, int y2) { return 1LL * fac[x2 - x1 + y2 - y1] * invfac[x2 - x1] % mod * invfac[y2 - y1] % mod; }
int main() {
	fac[0] = 1; for(int i = 1; i <= 2000000; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
	invfac[2000000] = fpow(fac[2000000], mod - 2);
	for(int i = 1999999; i >= 0; --i) invfac[i] = 1LL * invfac[i + 1] * (i + 1) % mod;
	for(int i = 1; i <= 6; ++i) scanf("%d", &x[i]);
	for(int i = 1; i <= 6; ++i) scanf("%d", &y[i]);
	for(int i = x[3]; i <= x[4]; ++i)
		ans = (ans - 
			  1LL * (1LL * F(i, y[3], x[5], y[5]) + F(i, y[3], x[6] + 1, y[6] + 1) - F(i, y[3], x[5], y[6] + 1) - F(i, y[3], x[6] + 1, y[5]) + 2 * mod) % mod *
					(1LL * F(x[1] - 1, y[1] - 1, i, y[3] - 1) + F(x[2], y[2], i, y[3] - 1) - F(x[1] - 1, y[2], i, y[3] - 1) - F(x[2], y[1] - 1, i, y[3] - 1) + 2 * mod) % mod *
					(i + y[3] - 1) % mod
			   + mod) % mod;
	for(int i = y[3]; i <= y[4]; ++i)
		ans = (ans - 
			  1LL * (1LL * F(x[3], i, x[5], y[5]) + F(x[3], i, x[6] + 1, y[6] + 1) - F(x[3], i, x[5], y[6] + 1) - F(x[3], i, x[6] + 1, y[5]) + 2 * mod) % mod *
			  	    (1LL * F(x[1] - 1, y[1] - 1, x[3] - 1, i) + F(x[2], y[2], x[3] - 1, i) - F(x[1] - 1, y[2], x[3] - 1, i) - F(x[2], y[1] - 1, x[3] - 1, i) + 2 * mod) % mod *
					(i + x[3] - 1) % mod
			   + mod) % mod;
	for(int i = x[3]; i <= x[4]; ++i)
		ans = (ans +
			  1LL * (1LL * F(i, y[4] + 1, x[5], y[5]) + F(i, y[4] + 1, x[6] + 1, y[6] + 1) - F(i, y[4] + 1, x[5], y[6] + 1) - F(i, y[4] + 1, x[6] + 1, y[5]) + 2 * mod) % mod *
					(1LL * F(x[1] - 1, y[1] - 1, i, y[4]) + F(x[2], y[2], i, y[4]) - F(x[1] - 1, y[2], i, y[4]) - F(x[2], y[1] - 1, i, y[4]) + 2 * mod) % mod *
					(i + y[4]) % mod
			  ) % mod;
	for(int i = y[3]; i <= y[4]; ++i)
		ans = (ans + 
			  1LL * (1LL * F(x[4] + 1, i, x[5], y[5]) + F(x[4] + 1, i, x[6] + 1, y[6] + 1) - F(x[4] + 1, i, x[5], y[6] + 1) - F(x[4] + 1, i, x[6] + 1, y[5]) + 2 * mod) % mod *
			  	    (1LL * F(x[1] - 1, y[1] - 1, x[4], i) + F(x[2], y[2], x[4], i) - F(x[1] - 1, y[2], x[4], i) - F(x[2], y[1] - 1, x[4], i) + 2 * mod) % mod *
					(i + x[4]) % mod
			  ) % mod;
	printf("%d\n", ans);
	return 0;
}






















Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
long long f[maxn], s[maxn];
long long ans;

int main(){
    int n, x; cin >> n;
    for(int i = 1; i <= n; i++){
        scanf("%d", &x);
        f[i] = f[i-1] + x;
        s[i] = s[i-1] ^ x;
    }
    int l = 1;
    for(int r = 1; r <= n; r++){
        for(; f[r] - f[l-1] != (s[r] ^ s[l-1]); l++);
        ans += r - l + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <vector>
#include <cstdlib>

struct Node {
	bool visited = false;
	bool flag = false;
	int depth = 0;
	std::vector<Node*> next;
};

bool dfs(Node* node) {
	bool any_found = false;
	if (node->flag) {
		return true;
	} else if (!node->visited) {
		node->flag = true;
		for (auto it = node->next.begin(); it != node->next.end(); ++it) {
			any_found |= dfs(*it);
		}
		node->flag = false;
		node->visited = true;
	}
	return any_found;
}

int longestPath(Node* node) {
	if (node->visited) {
		return node->depth;
	}
	node->visited = true;
	if (node->next.empty()) {
		node->depth = 1;
		return 1;
	} else {
		int max_depth = 0;
		for (auto it = node->next.begin(); it != node->next.end(); ++it) {
			max_depth = std::max(longestPath(*it), max_depth);
		}
		node->depth = max_depth + 1;
		return max_depth + 1;
	}
}

int index(int N, int i, int j) {
	int temp;
	if (i > j) {
		temp = i;
		i = j;
		j = temp;
	}
	return i * N + j;
}

int main() {
	int N, A[1000][1000 - 1];
	std::scanf("%d", &N);
	std::vector<Node*> v(N * N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			std::scanf("%d", &A[i][j]);
			--A[i][j];
			if (v[index(N, i, A[i][j])] == nullptr) {
				v[index(N, i, A[i][j])] = new Node;
			}
			if (j > 0) {
				v[index(N, i, A[i][j - 1])]->next.push_back(v[index(N, i, A[i][j])]);
			}
		}
	}
	bool any = false;
	for (int i = 0; i < N * N; ++i) {
		if (v[i] != nullptr && !v[i]->visited && !v[i]->flag) {
			any |= dfs(v[i]);
		}
	}
	if (any) {
		std::printf("%d", -1);
	} else {
		std::for_each(v.begin(), v.end(), [](Node* n){
			if (n != nullptr) {
				n->visited = false;
			}
		});
		int max_depth = 0;
		for (int i = 0; i < N * N; ++i) {
			if (v[i] != nullptr && !v[i]->visited) {
				max_depth = std::max(max_depth, longestPath(v[i]));
			}
		}
		std::printf("%d", max_depth);
	}
	std::for_each(v.begin(), v.end(), [](Node* n){ delete n; });
}

Measured memory_bytes: 51072
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

ll ans;
ll gr[10][10];
ll n;

void searchPath(ll curNode, vector<bool> visitedStatus, ll pathSize){
    rp(i,n){
        if(gr[curNode][i] == 1 && !visitedStatus[i]){
            if(pathSize == n-1) {ans++;continue;}
            std::vector<bool> temp = visitedStatus;
            temp[i] = true;
            searchPath(i,temp,pathSize+1);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::fixed;
    cout << std::setprecision(9);

    ll m;
    cin >> n  >> m;
    rp(i,m){
        ll x,y;
        cin >> x >> y;
        gr[--x][--y] = 1;
        gr[y][x] = 1;
    }
    std::vector<bool> v(n,false);
    v[0] = true;

    searchPath(0,v,1);
    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
def main():
    """
    1 <=  D <= 100
    1 <= pi <= 100
    1 <=  i <= D
    100 <= G
    100 <= ci <= 10^6

    all: sum(p)
        max: 100 * 10 = 1000
    """
    D, G = map(int, input().split())
    P, C = zip(*(
        map(int, input().split())
        for _ in range(D)
    ))

    # ans = f(D, G, P, C)
    ans = editorial(D, G, P, C)
    print(ans)


def editorial(D, G, P, C):
    ans = float("inf")
    for i in range(2 ** D):
        c = 0
        score = 0
        clear = [False] * D
        for j in range(D):
            if i & (1 << j):
                c += P[j]
                score += 100 * (j + 1) * P[j] + C[j]
                clear[j] = True

        # print(i, clear, c, score)
        for j in range(D)[::-1]:
            if score >= G:
                break
            if clear[j]:
                continue

            rest = G - score
            base_score = 100 * (j + 1)
            add_c = (rest + base_score - 1) // base_score
            add_c = min(add_c, P[j] - 1)
            c += add_c
            score += base_score * add_c

            # print("\t", base_score, c, score)

        if score >= G:
            ans = min(ans, c)

    return ans


def f(D, G, P, C):
    """
    i, P から問題をすべて分割
    すべての解き方を列挙する
    sum_p ! = 1000 ! => TLE

    点数の高いものから解けばいいとは限らない

    dpっぽく前の解き方を利用してみる
    ans[0] = 0
    ans[1] = max_i * 100 or ボーナスあり
        ボーナスがあるので、前の答え＋点の良い問題とは限らない
        前の解き方のうち、１つ変えるとどうなるか？
            ボーナスがなくなってしまうかもしれない
            代わりにボーナスになる可能性もある
            前の解き方からｘ問変えるとどうなるか？
                同様
    ボーナスもらえるテーブルを作る？
        それとボーナス加味しないDPテーブルとの比較
        b_dp[5] = p1 全完了
        dp[2] = p2
            fix[]
    """
    from itertools import permutations
    from collections import defaultdict

    sum_p = sum(P)
    dp = [float("inf") for _ in range(sum_p + 1)]
    dp[0] = 0
    max_state = {}

    # 総スコアと効率、
    total = [(i + 1) * 100 * P[i] + C[i] for i in range(D)]
    ratio = [total[i] / P[i] for i in range(D)]
    bonus = [False for _ in range(D)]
    for i in range(1, sum_p + 1):
        score = 0
        rest = i
        for j in range(D):
            if bonus[j]:
                rest -= P[j]
                score += total[j]
            elif P[j] <= rest:
                bonus[j] = True
                rest -= P[j]
                score += total[j]

        if dp[i] >= G:
            return i


if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
#include <cstdio>
#include <algorithm>

#define maxn 100005

using namespace std ;
int n;
int d[maxn] ;

int main(void) {
	scanf("%d",&n) ;
	for(int i=1; i<=n; i++) scanf("%d",&d[i]) ;

	long long ans1 = 0 , sum = 0 ;
	for(int i=1;i<=n; i++) {
		if(i%2==0) {
			int a =0 ;
			if(sum+d[i]>=0) {
				a = abs(sum+d[i])+1 ;
				ans1 += a ;
				sum = -1 ;
			} else sum+=d[i] ;
		} else {
			int a = 0 ;
			if(sum+d[i]<=0) {
				a = abs(sum+d[i])+1;
				ans1 += a ;
				sum = 1 ;
			}else sum+=d[i] ;
		}
	}
	long long ans2 = 0 ; sum = 0 ;
	for(int i=1;i<=n; i++) {
		if(i%2==0) {
			int a =0 ;
			if(sum+d[i]<=0) {
				a = abs(sum+d[i])+1;
				ans2 += a ;
				sum = 1 ;
			}else sum+=d[i] ;
		} else {
			int a = 0 ;
			if(sum+d[i]>=0) {
				a = abs(sum+d[i])+1;
				ans2 += a ;
				sum = -1 ;
			}else sum+=d[i] ;
		}
	}
	printf("%lld\n",min(ans1,ans2)) ;
	
}

Measured memory_bytes: 512