akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string r,g,b;
cin >> r >> g >> b;
if(stoi(r+g+b)%4 == 0) cout << "YES" << endl;
else cout << "NO" << endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x){
    char c=getchar();
    int p=1;
    x=0;
    while(!isdigit(c)){
        if(c=='-')p=-1;
        c=getchar();
    }
    while(isdigit(c)){
        x=(x<<1)+(x<<3)+(c^'0');
        c=getchar();
    }
    x*=p;
}
char s[105];
bool use[505];
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%s",s+1);
    int n=strlen(s+1);
    if(n==26){
        for(register int i=0;i<=504;++i){
            use[i]=1;
        }
        for(register int i=n;i>=1;--i){
            use[s[i]]=0;
            while(s[i]<'z'){
                s[i]++;
                if(!use[s[i]]){
                    for(register int j=1;j<=i;++j){
                        printf("%c",s[j]);
                    }
                    return 0;
                }
            }
        }
        cout<<"-1"<<endl;
        return 0;
    }
    else{
        for(register int i=1;i<=n;++i){
            use[s[i]]=1;
        }
        for(register char c='a';c<='z';++c){
            if(!use[c]){
                printf("%s%c\n",s+1,c);
                return 0;
            }
        }
    }
    return 0;
}

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

int prime(int x)
{

int i;

if(x==2)

return 1;

else if(x%2==0)

return 0;

for(i=3;i*i<=x;i+=2){

if(x%i==0)

return 0;

}

return 1;

}

int main()
{

int n,m,i;
int a=0;

scanf("%d",&n);

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

scanf("%d",&m);

if(prime(m)==1)
{

a++;

}

}

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

return 0;

}

Measured memory_bytes: 1756
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int n;
    vector<long long> A;
    long long ans1 = 0;
    long long ans2 = 0;
    long long sum = 0;
    bool is_plus;
    
    cin >> n;
    
    
    for ( int i = 0; i < n; i++ ) {
        long long a;
        cin >> a;
        
        A.push_back(a);
    }
    
    
    is_plus = true;
    for ( int i = 0; i < n; i++ ) {
        
        if ( i ) { is_plus = sum > 0; }
        
        sum += A[i];
        
        if ( sum == 0 ) {
            ans1++;
            sum = is_plus ? -1 : 1;
        }
        else if ( is_plus == (sum > 0) ) {
            ans1 += abs(sum)+1;
            sum = is_plus ? -1 : 1;
        }
    }
    
    is_plus = false;
    sum = 0;
    for ( int i = 0; i < n; i++ ) {
        
        if ( i ) { is_plus = sum > 0; }
        
        sum += A[i];
        
        if ( sum == 0 ) {
            ans2++;
            sum = is_plus ? -1 : 1;
        }
        else if ( is_plus == (sum > 0) ) {
            ans2 += abs(sum)+1;
            sum = is_plus ? -1 : 1;
        }
    }
    
    
    
    cout << min( ans1, ans2 ) << endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

signed main() {
	fast;
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	string s;
	cin>>s;

	if(a>b){
		swap(a,b);
		swap(c,d);
	}

	if(s[a-1]=='#'||s[b-1]=='#'||s[c-1]=='#'||s[d-1]=='#') {
		cout<<"No";
		return 0;
	}

	if(a<b&&c<d){
		ll f=1;
		for(int i=b;i<d;i++){
			if(s[i]=='#'&&s[i-1]=='#') f=0;
		}
		for(int i=a;i<c;i++){
			if(s[i]=='#'&&s[i-1]=='#') f=0;
		}
		if(f) cout<<"Yes";
		else cout<<"No";
	}
	else {
		ll f=1;
		for(int i=b;i<d;i++){
			if(s[i]=='#'&&s[i-1]=='#') f=0;
		}
		for(int i=a;i<c;i++){
			if(s[i]=='#'&&s[i-1]=='#') f=0;
		}
		if(!f) {cout<<"No";return 0;}

		f=0;

		for(int i=b;i<=d;i++) {
			if(i<n&&i>1&&s[i]=='.'&&s[i-1]=='.'&&s[i-2]=='.') f=1;
			if(i<n&&s[i]=='#'&&s[i-1]=='#') break;
		}

		if(f) cout<<"Yes";
		else cout<<"No";

	}

} 

Measured memory_bytes: 592
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val ans = if (s == "ABC") {
        "ARC"
    } else {
        "ABC"
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 34352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N= sc.nextInt();
		int D = sc.nextInt();
		
			System.out.println((N + D * 2) / (D * 2 + 1));
		}

	}

Measured memory_bytes: 23124
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		set<string>st;
		M = s.size();
		for (int j = 0; j < M - 1; j++) {
			string t;
			for (int k = 0; k <= j; k++) {
				t += s[k];
			}
			string u;
			u = t;
			reverse(u.begin(), u.end());
			string v, w;
			for (int k = j + 1; k < M; k++) {
				v += s[k];
			}
			w = v;
			reverse(w.begin(), w.end());
			st.insert(t + v);
			st.insert(t + w);
			st.insert(u + v);
			st.insert(u + w);
			st.insert(v + t);
			st.insert(w + t);
			st.insert(v + u);
			st.insert(w + u);
		}
		cout << st.size() << endl;
	}
	return 0;
}

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

  int main()
  {
    ll h, w, ans=0;
    cin >> h >> w;
    if(h == 1 || w == 1)
		cout << 1 << endl;
	else if(h * w % 2== 1)
		cout << ((h * w)/2) + 1 << endl;
    else
      cout << ((h * w)/2) << endl;
    return 0;
  }




Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
$a = array_map('intval', str_split($S));
$cnt = count($a);
$ans0 = $ans1 = 0;

for ($i = 0; $i < $cnt; $i++) {
    $ans0 += $a[$i] !== ($i % 2);
    $ans1 += $a[$i] === ($i % 2);
}

echo min($ans0, $ans1);


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

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << endl;

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//string ans="YES";


	int r,d,x;
	cin >> r >> d >> x;
	
	//vector<int> a(10);
	
	rep(i,10){
		x=r*x-d;
		cout << x << endl;
	}
	
	
	
	
	//cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 384
import sys
inp = [x.strip() for x in sys.stdin]
for s in inp:
	lens = len(s)
	for i in reversed(xrange(0, lens, 2)):
		news = s[:i]
		lennews = len(news)
		if lennews % 2 == 0 and news[:lennews/2] == news[lennews/2:]:
			print lennews
			break

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < N; i++)
  {
    int p;
    cin >> p;
    a.push_back(p);
  }
  sort(a.begin(), a.end());
  cout << a.back() - a.front() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

  int a,b,temp[7];
  
  for(int i=0 ; i < 7 ; i++){
    
    cin >>a>>b;
   
    temp[i]=a-b;
    
  }
  
  for(int i=0 ; i < 7 ; i++){
    cout <<temp[i]<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;

int main(void){
    ll n;
    cin >> n;

    vector<ll> ans;
    ll num=0;

    for(ll i=1; i<=n; i++){
        ans.push_back(i);
        num +=i;
        if(num >= n){
            num = (num-n);
            break;
        }
    }

    for(ll i=0; i<ans.size(); i++){
        if(ans[i] == num){continue;    }
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
#include <numeric>
typedef long long ll;
using namespace std;

const ll MAX = 2000;
const ll MOD = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, char *argv[]) {
  ll s, i;
  cin >> s;
  if(s<3LL){
    cout << 0 << endl;
    return 0;
  }

  COMinit();

  ll ans = 1LL;
  ll rem = s - 3LL;
  for(i=2LL;;i++){
    rem -= 3;
    if(rem<0) break;

    ans += COM(rem+i-1LL,i-1LL);
    ans %= MOD;
  }

  if(ans<0LL) ans += MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
a,b,=map(int,input().split())
if a==0 or b==0 or (a>0 and b<0) or (a<0 and b>0):
    print('Zero')
elif a<0 and b<0 and (a+b)%2==0:
    print('Negative')
else:
    print('Positive')


Measured memory_bytes: 2940
<?php
$nums = array_map('intval', explode(" ", trim(fgets(STDIN))));
$a = $nums[0];
$b = $nums[1];

$d = (int)($a / $b);
$r = $a % $b;
$f = sprintf("%.09f", ($a / $b));

echo $d." ".$r." ".$f.PHP_EOL;
?>


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

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}


int main(int argc,char* argv[]){
  int first_card,is_st;
  int i;
  int max,max2,max3,max4;
  int cards[5];
  int hands[13];
  
  while(scanf("%d,%d,%d,%d,%d",&cards[0],&cards[1],&cards[2],&cards[3],&cards[4]) != EOF){
    max = max2 = 0;is_st = 1;
    qsort(cards, 5, sizeof(int), compare_int);
    
    for(i = 0;i < 13;i++){
      hands[i] = 0;
    }
    
    for(i = 0;i < 5;i++){
      hands[cards[i] - 1]++;
    }

    for(i = 0;i < 13;i++){
      if(max <= hands[i]){
	max2 = max;
	max = hands[i];
      }else if(max2 <= hands[i]){
	max2 = hands[i];
      }
    }
    
    if(max == 4){
      printf("four card\n");
      continue;
    }

    if(max == 3 && max2 == 2){
      printf("full house\n");
      continue;
    }
    
    first_card = cards[0];
    for(i = 1;i < 5;i++){
      if(first_card + 1 != cards[i]){is_st = 0;break;}else{
	first_card++;
      }
    }

    if(is_st || (cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13)){
      printf("straight\n");
      continue;
    }
    
    if(max == 3){
      printf("three card\n");
      continue;
    }

    if(max == 2 && max2 == 2){
      printf("two pair\n");
      continue;
    }

    if(max == 2){
      printf("one pair\n");
      continue;
    }

    printf("null\n");
    
  }
  
  return 0;
  
}

Measured memory_bytes: 0
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	while(true){
	    BigInteger m = new BigInteger(in.next());
	    int n = in.nextInt();
	    if(m.equals(BigInteger.ZERO)) break;
	    BigInteger mn=BigInteger.ONE;
	    for(int i = 0; i < n; i++) mn = mn.multiply(m);      
	    BigInteger []ans = new BigInteger[18];
	    BigInteger a = BigInteger.ONE;
	    for(int i = 0; i < 4; i++) a = a.multiply(BigInteger.TEN);
	    int l = 0;
	    while(l < 18){
		BigInteger md = mn.mod(a);
		ans[l] = md;
		mn = mn.divide(a);
		l++;
	    }
	    String []anss = new String[]{"","Man","Oku","Cho","Kei", "Gai", "Jo", "Jou", "Ko",
	    	     "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"};

	    for(int i = l - 1; i >= 0; i--){
		if(ans[i].equals(BigInteger.ZERO)) continue;
		System.out.print(ans[i]+anss[i]);
	    }
	    System.out.println("");
	}
	

    }
}

Measured memory_bytes: 19748
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    lines.shift();
    aux(lines);
});

function aux(lines)
{
    let sep="\n####################\n";
    var empty_room = [0,0,0,0,0,0,0,0,0,0];
    var residents = new Array(4);
    for (var b=0;b<4;b++) {
	residents[b] = new Array(3);
	for (var f=0;f<3;f++) {
	    residents[b][f] = Array.from(empty_room);
	}
    }
    
    let tenants = {};
    for (let notice of lines) {
	var b, f, r, v;
	[b, f, r, v] = notice.split(' ').map(Number);
	b -= 1;
	f -= 1;
	r -= 1;
	//console.log('b f r v: ', b,f,r,v);
	residents[b][f][r] += v;
    }
    //console.log('residents: ', residents);
    let buildings=[];
    for (b=0;b<4;b++){
	let building=[];
	for (f=0;f<3;f++){
	    let floor=[];
	    var fl = ' '+residents[b][f].map(String).join(' ');
	    //console.log('b,f: ', fl);
	    building.push(fl);
	}
	buildings.push(building);
    }
    var s=buildings.map(x=>x.join('\n')).join(sep);
    console.log(s);
    return;
}


Measured memory_bytes: 17024
N, X = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
ans = 0
for i in range(N-1):
    if A[i] + A[i+1] <= X:
        pass
    else:
        need = (A[i]+A[i+1]) - X
        ans += need
        A[i+1] = max(0, A[i+1]-need)

print(ans)


Measured memory_bytes: 14252
import java.util.*;
import java.lang.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc  = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
		int[] a = new int[n];
 
		for(int i=0; i<n; i++){
		
			a[i] = Integer.parseInt(sc.next());
		}
		int sum = t;
		for(int i=0; i<n-1; i++){
			if(a[i]+t<a[i+1]){
				sum = sum + t;
			}else{
				sum = sum + a[i+1] - a[i];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 60820
#include<stdio.h>

int main(){
	int n,i,j;
	int ar[12];
	int old_ar[12];
	int t;
	while(1){
	scanf("%d",&n);
		if(n==0)return 0;
	for(i=0;i<n;i++){
		scanf("%d",&ar[i]);
		old_ar[i]=ar[i];
	}
	t=0;
	int c;
	while(1){
		t++;
		for(i=0;i<n;i++){
			c=0;
			for(j=0;j<n;j++)if(old_ar[i]==old_ar[j])c++;
			ar[i]=c;
		}
		for(i=0;i<n;i++)if(ar[i]!=old_ar[i])break;
		if(i==n)break;
		for(i=0;i<n;i++)old_ar[i]=ar[i];
	}
	printf("%d\n",t-1);
	for(i=0;i<n;i++)printf("%d%c",ar[i],i==n-1?'\n':' ');
	}
}
	

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

bool isPrime(int x){
    if(x < 2) return false;
    for(int i=2; i*i<x; i++){
        if(x % i == 0) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    while(!isPrime(n)){
        n++;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list([x - 500 for x in range(1, 1000)])
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])


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

string a[101];
int counta[27];
int h, w;
bool judge(int xx, int yy);

int main()
{
  cin >> h >> w;
  for(int i=0;i<h;i++){
    cin >> a[i];
  }
  for(int i=0;i<27;i++){
    counta[i] = 0;
  }
  for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	counta[a[i][j] - 'a' + 1]++;
      }
    }
  bool flag;
  
  if(h%2 == 0 && w%2 == 0){
    flag = judge(h/2 * w/2, 0);
  }else if(h%2 == 0 && w%2 != 0){
    flag = judge(h/2 * (w-1)/2, h/2);
  }else if(h%2 != 0 && w%2 == 0){
    flag = judge((h-1)/2 * w/2, w/2);
  }else{
    flag = judge((h-1)/2 * (w-1)/2, (h-1)/2 + (w-1)/2);
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

// x -> 4, y -> 2
bool judge(int xx, int yy){
  int x = xx;
  int y = yy;
  
  for(int i=0;i<27;i++){
    while(true){
      if(x == 0){
	break;
      }
      if(counta[i] < 4){
	break;
      }
      x--;
      counta[i] -= 4;
    }
  }
  if(x != 0){
    return false;
  }
  for(int i=0;i<27;i++){
    while(true){
      if(y == 0){
	return true;
      }
      if(counta[i] < 2){
	break;
      }
      y--;
      counta[i] -= 2;
    }
  }
  if(y != 0){
    return false;
  }
  return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
 	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
const int V = 2000005;
int X[7],Y[7],ans,fac[V + 5],invfac[V + 5];

int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int W(int x,int y) {
    return C(x + y,x);
}
int way1(int x,int y) {
    int s1 = x - X[2],s2 = x - X[1];
    int t1 = y - Y[2],t2 = y - Y[1];
    return inc(inc(W(s2 + 1,t2 + 1),W(s1,t1)),MOD - inc(W(s2 + 1,t1),W(s1,t2 + 1)));
}
int way2(int x,int y) {
    int s1 = X[5] - x,s2 = X[6] - x;
    int t1 = Y[5] - y,t2 = Y[6] - y;
    return inc(inc(W(s2 + 1,t2 + 1),W(s1,t1)),MOD - inc(W(s2 + 1,t1),W(s1,t2 + 1)));
}
void Solve() {
    fac[0] = 1;
    for(int i = 1 ; i <= V ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[V] = fpow(fac[V],MOD - 2);
    for(int i = V - 1 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    for(int i = 1 ; i <= 6 ; ++i) read(X[i]);
    for(int i = 1 ; i <= 6 ; ++i) read(Y[i]);
    for(int i = X[3] ; i <= X[4] ; ++i) {
	update(ans,mul(MOD - (i + Y[3] - 1),mul(way1(i,Y[3] - 1),way2(i,Y[3]))));
	update(ans,mul(i + Y[4],mul(way1(i,Y[4]),way2(i,Y[4] + 1))));
    }
    for(int j = Y[3] ; j <= Y[4] ; ++j) {
	update(ans,mul(MOD - (X[3] - 1 + j),mul(way1(X[3] - 1,j),way2(X[3],j))));
	update(ans,mul(j + X[4],mul(way1(X[4],j),way2(X[4] + 1,j))));
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
using namespace std;
int main(){
	int retsu,gyou,count,count2,masu[101][101]={0};
	cin>>retsu>>gyou;
	for(count=0;count<retsu;count++){
		for(count2=0;count2<gyou;count2++){
			cin>>masu[count][count2];
			masu[retsu][count2]+=masu[count][count2];
			masu[count][gyou]+=masu[count][count2];
		}
	}
	for(count=0;count<retsu;count++){
		masu[retsu][gyou]+=masu[count][gyou];
	}
	for(count=0;count<=retsu;count++){
		for(count2=0;count2<=gyou;count2++){
			if(count2!=gyou){cout<<masu[count][count2]<<' ';}
			else{cout<<masu[count][count2];}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    double A;
    cin >> A;
    double B;
    cin >> B;
    double H;
    cin >> H;
    double M;
    cin >> M;
    long double pai=3.1415926535897932384626;
    double pai2=2*pai;
    double t=H/12.0-11.0*M/720;
    double D=abs(t*pai2);
    double S=A*A+B*B-2.0*A*B*cos(D);
    cout << fixed << setprecision(20);
    double ans=sqrt(S);
    cout<<ans<<endl;

    return 0;
}

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


int main() {
	ll n,y;
	cin>>n>>y;
	for(int i=n;i>=0;i--){
		for(int j=n-i;j>=0;j--){
			ll remain=y-i*10000-j*5000;
			remain=remain/1000;//ｓ札枚数
			if(remain>=0&& remain+i+j==n){
				cout << i << " "<< j<< " " <<remain;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,X; cin >> K >> X;
  int N = X+K-1;
  int M = X-K+1;
  for(int i=M; i<=N; i++) {
    cout << i << " ";
  }
  return 0;
}

Measured memory_bytes: 3556
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().decode('utf8')
ans = 753
for i in range(len(S) - 2):
    ans = min(abs(753 - int(S[i:i + 3])), ans)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    
    vector<int> f(N), b(N);
    vector<bool> exist(N);
    for (int i = 0; i < N; ++i) {
        f[i] = (i + 1) % N;
        b[i] = (i - 1 + N) % N;
        exist[i] = 1;
    }
    
    int baton = 0;
    for (int i = 0; i < M; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j < a; ++j) {
            baton = (a & 1 ? b[baton] : f[baton]);
        }
        exist[baton] = 0;
        b[f[baton]] = b[baton];
        f[b[baton]] = f[baton];        
        baton = f[baton];
    }    
    for (int i = 0; i < Q; ++i) {
        int q;
        cin >> q;
        cout << exist[q] << endl;
    }
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    string s;
    cin >> n;
    getline(cin, s);
    rep(i, n)
    {
        getline(cin, s);
        while (s.find("Hoshino") != string::npos)
        {
            int a = s.find("Hoshino");
            s.replace(a, 7, "Hoshina");
        }
        OP(s);
    }
    return 0;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    int len=s.size();
    if(len<a+b+1||len>a+b+1){
    	cout<<"No\n";
    	return 0;
	}for(int i=0;i<a;i++){
		if(s[i]<'0'||s[i]>'9'){
			cout<<"No\n";
    		return 0;
		}
	}if(s[a]!='-'){
		cout<<"No\n";
    	return 0;
	}for(int i=a+1;i<a+b+1;i++){
		if(s[i]<'0'||s[i]>'9'){
			cout<<"No\n";
    		return 0;
		}
	}
	cout<<"Yes\n";
    return 0;
}

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

namespace AtTest.Tenka1_2019
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s = Read();
            int[] blackCnt = new int[n];
            blackCnt[n - 1] = s[n - 1] == '#' ? 1 : 0;

            for (int i = n-2; i>=0; i--)
            {
                blackCnt[i] = blackCnt[i + 1];
                if (s[i] == '#') blackCnt[i]++;
            }
            int res = int.MaxValue;
            for(int i = n - 1; i >= 0; i--)
            {
                int tmp = blackCnt[0] - blackCnt[i];
                tmp += n - i - blackCnt[i];
                res = Min(res, tmp);
            }
            res = Min(res, blackCnt[0]);
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13216
W, H, N = map(int, input().split())
a1, a2, a3, a4 = [], [], [], []
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)

max_x = max(a1) if a1 else 0
min_x = min(a2) if a2 else W
max_y = max(a3) if a3 else 0
min_y = min(a4) if a4 else H
ans = max(0, min_x - max_x) * max(0, min_y - max_y)
print(ans)

Measured memory_bytes: 62688
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#define LL long long
#define pii pair<int,int>
#define mp make_pair
 
using namespace std;
 
inline char nc(){
	/*
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
  	*/return getchar();
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline int read(char *s)
{
    char c=nc();int len=0;
    for(;!(c>='0' && c<='9');c=nc()) if (c==EOF) return 0;
    for(;(c>='0' && c<='9');s[len++]=c,c=nc());
    s[len++]='\0';
    return len;
}
 
inline void read(char &x){
  for (x=nc();!(x>='A' || x<='B');x=nc());
}
 
int wt,ss[19];
inline void print(int x){
    if (x<0) x=-x,putchar('-'); 
    if (!x) putchar(48); else {
    for (wt=0;x;ss[++wt]=x%10,x/=10);
    for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
    if (x<0) x=-x,putchar('-');
    if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

LL x,y;

int main()
{
	read(x);read(y);
	if (x<y) swap(x,y);
	if (x-y<=1) puts("Brown");
	else puts("Alice");
	return 0;
}

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

int A[101];

int main() {
  int N;
  cin>>N;
  int ans=10000000;
  for (int i=0;i<N;++i){
    cin>>A[i];
  }
 
  for (int p=1;p<101;++p){
    int sum=0;
    for (int i=0;i<N;++i){
      sum+=(A[i]-p)*(A[i]-p);
    }
    if (sum<=ans){
        ans=sum;
    }
    
  }
  
  cout <<ans<<endl;
      
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc162/tasks/abc162_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 main() {
  ll N;cin>>N;
  ll ans=0;
  FOR(i,1,N+1){
    if(i%3==0||i%5==0){

    }else{
      ans += i;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
C=0;
p=input().rstrip().split(' ')
x=input().rstrip().split(' ')
for i in range(0,len(x)-1):
    t=int(x[i]) + int(x[i+1])
    if t>int(p[1]):
        g=t-int(p[1])
        C+=g;
        if g>int(x[i+1]):
            g=g-int(x[i+1])
            x[i+1]=0;
            x[i]=int(x[i])-g;
        else:
            x[i+1]=int(x[i+1])-g;
            
print(C)

Measured memory_bytes: 13744
#include <cstdio>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

map<string,int> data;

string rev(string s){
	reverse(s.begin(),s.end());
	return s;
}

void solve(){
	string s;
	cin >> s;
	int n = s.length();
	for(int i=1;i<n;++i){
		string a = s.substr(0,i);
		string b = s.substr(i,n-i);
		string a1 = rev(a);
		string b1 = rev(b);
		data[a+b]++;
		data[a1+b]++;
		data[a+b1]++;
		data[a1+b1]++;
		data[b+a]++;
		data[b1+a]++;
		data[b+a1]++;
		data[b1+a1]++;
	}
	cout<<data.size()<<endl;
}
int main(){
	int n;
	for(cin>>n;n;n--){
		data.clear();
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1300
from collections import deque
N=int(input())
ten=[0]*N
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w])
    G[v-1].append([u-1,w])
#print(G)
que=deque()
que.append(0)
visited=[[0] for i in range(N)]
visited[0]=1
while que:
    v=que.pop()
    for u in G[v]:
        #print(u)
        if visited[u[0]]==1:
            continue
        if u[1]%2==0:
            ten[u[0]]=ten[v]
        else:
            ten[u[0]]=1-ten[v]
        #print(ten)
        visited[u[0]]=1
        que.appendleft(u[0])
for i in range(N):
    print(ten[i])


Measured memory_bytes: 91680
#include <cstdio>
#include <cstring>
int n, nxt[26][200005], pre[26][200005], now, cnt[26], l[200005], r[200005], idx;
char buf[200005];
int main() {
	std::scanf("%s", buf + 1);
	n = std::strlen(buf + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 26; j++) pre[j][i] = pre[j][i - 1];
		++pre[buf[i] - 97][i];
	}
	r[idx = 1] = n;
	for (int i = n; i; i--) {
		for (int j = 0; j < 26; j++) nxt[j][i] = nxt[j][i + 1];
		nxt[buf[i] - 97][i] = i;
		now += cnt[buf[i] - 97]++ == 0;
		if (now == 26) {
			now = 0;
			for (int j = 0; j < 26; j++) cnt[j] = 0;
			l[idx] = i;
			r[++idx] = i - 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < 26; i++) if (!pre[i][r[idx]]) {
		std::putchar((ans = i) + 97); 
		break; 
	}
	for (int i = idx - 1; i; i--) {
		int x = nxt[ans][l[i]];
		for (int j = 0; j < 26; j++) if (!(pre[j][r[i]] - pre[j][x])) {
			std::putchar((ans = j) + 97); break; 
		}
	}
	return 0;
}

Measured memory_bytes: 41088
#include<iostream>
using namespace std;
int main() {
    int n, b, f, r, v;
    cin >> n;
    int a[4][3][10] = {};
    for (int i=0; i < n; i++) {
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }
    for (int j=0; j < 4; j++){
        for (int k=0; k < 3; k++) {
            for (int l=0; l < 10; l++) {
                cout << " " << a[j][k][l]; 
            }
            cout << endl;
        }
        if (j<=2) {
            for (int c=0; c<20; c++){
                cout << "#"; 
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long				ll;
typedef pair <int, int> ii;
 
/*
struct point{
	ll x;
	ll y;
	point(){x = 0;y = 0;}
	point(ll x, ll y):x(x), y(y){}
};
*/

int main() {
	
	int a, l;
	while(cin >> a >> l, a, l){
		vector<int> as;
		
		rep(loop, 50){
			bool endflag = false;
			rep(i, as.size()){
				if(as[i] == a){
					cout << i << " " << a << " " << loop - i << endl;
					endflag = true;
					break;
				}
			}
			if(endflag) break;
			as.push_back(a);
			vector<int> tmp(l);
			int i = 0;
			while(a != 0){
				tmp[i] = a % 10;
				a /= 10;
				i++;
			}
			
			SORT(tmp);
			
			//rep(i, tmp.size()) cout << tmp[i] << "\t";
			//cout << endl;
			int maxi = 0, mini = 0;
			int dex = 1;
			rep(i, l){
				mini += (dex * tmp[l-1-i]);
				maxi += (dex * tmp[i]);
				dex *= 10;
			}
			//cout << maxi << endl << mini << endl;
			a = maxi - mini;
		}
	}
	
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		long sum1 = 0;
		long[] b = new long[n];

		for ( int i = 0 ; i < n ; i++ ) {
			b[i] = sc1.nextLong() - ( i + 1 );
		}

		Arrays.sort(b);

		long b1 = b[n/2];

		for ( int i = 0 ; i < n ; i++ ) {
			sum1 += Math.abs(b[i] - b1);
		}

		System.out.println(sum1);

		sc1.close();

	}

}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int n,k,sum=0;
    cin>>n>>k;
    vi p(n);
    rep(i,n)cin>>p[i];
    sort(ALL(p));
    rep(i,k)sum+=p[i];
    cout<<sum<<endl;
    return 0;
}

//a=97,z=122

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

namespace
{
	ll RecL(int s, int e, vvl& dp, const vl& a)
	{
		static const ll MAX = 10000000000000000;
		if (dp[s][e] != MAX)
			return dp[s][e];
		if (s == e)
			return dp[s][e] = a[s];
		ll k = a[s] - RecL(s + 1, e, dp, a);
		ll m = a[e] - RecL(s, e - 1, dp, a);
		return dp[s][e] = max(k, m);
	}
}

void EducationalDP_L()
{
	static const ll MAX = 10000000000000000;
	int N;
	cin >> N;
	vl a(N);
	for(auto& x : a)
		cin >> x;
	vvl dp(N, vl(N, MAX));
	ll ret = RecL(0, N - 1, dp, a);
	cout << ret << endl;
}
int main()
{
	EducationalDP_L();
	return 0;
}

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

using namespace std;

typedef pair<int, int> ii;

int A[100005];

int B[100005];
int C[100005];

ii CB[100005];

int D[100005];

int E[100005];

int main(){
	int N, M;
	scanf("%d%d", &N, &M);
	
	for(int i = 0; i < N; i ++){
		scanf("%d", &A[i]);
	}
	
	sort(A, A+N);
	
	for(int i = 0; i < M; i ++){
		scanf("%d%d", &B[i], &C[i]);
		CB[i] = ii(C[i], B[i]);
	}
	
	sort(CB, CB+M);
	reverse(CB, CB+M);
	
	int j = 0;
	for(int i = 0; i < M; i ++){
		int b = CB[i].second;
		int c = CB[i].first;
		//printf(" %d %d\n", c, b);
		for(int k = 0; k < b; k ++){
			E[j++] = c;
			//printf(" %d\n", j);
			if(j >= N+2){break;}
		}
		if(j >= N+2){break;}
	}
	
	long long ans = 0;
	for(int i = 0; i < N; i ++){
		ans += max(E[i], A[i]);
	}
	
	printf("%lld", ans);
	
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
#define pi 3.14159265358979
//ll string_inp() {cin.get(); for(int i =0;i<n;i++){ getline(cin,s[i]);}}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll power(ll x, ll y, ll mod = 2e18)
{
    ll ans = 1;
    x %= mod;
    while(y)
    {
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m,a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if(x < 0)
        x += m0;
    return x;
}
int takemod(int a, int mod = MOD)
{
    a%=mod;
    if(a<0)
        a+=mod;
    return a;
}
ll binsearch(std::vector<ll>& nums, ll target)
{
    ll n = nums.size();
    ll l = 0;
    ll r = n-1;
    while(l<=r)
    {
        ll mid = l+ (r-l)/2;
        if(nums[mid]==target)
            return mid;
        else if(nums[mid]>target)
            r = mid-1;
        else
            l = mid+1;
    }
    return -1;
}
bool isPowerOfTwo (int x)
{
    return x && (!(x&(x-1)));
}

using namespace std;

int main()
{
    fastio
    ll t,x;
    cin>>t;
    __int128 ans=1,comp =1000000000000000000;
    ll flag =0;
    ll finalans;
    while(t--)
    {


        cin>>x;
        ans*=x;
        if(x==0)
        {
            flag=2;
            break;
        }
        if(ans>comp)
            flag=1;
    }

    if(flag==1)
        finalans=-1;

    else if(flag==2)
        finalans=0;

    else
        finalans=ans;


    cout<<finalans;
}




Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i=1,ans = 0;
    while(i<n){
        ans++;
        while(i<n && s[i]==s[i-1]){
            i++;
        }
        i++;
    }
    if(n==1){
        cout<<1;
        return 0;
    }
    if(n>=2 && s[n-1]==s[n-2]){
        cout<<ans;
    }
    else{
        cout<<ans+1;
    }
    //ans==1?cout<<ans:cout<<ans+1;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MaxN = 1e5;

int n;
int a[MaxN + 5], b[MaxN + 5], c[MaxN + 5];

bool cmp(int x, int y){ return x > y; } 

int main(){
	while(~scanf("%d", &n)){
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
		for(int i = 1; i <= n; i++) scanf("%d", &c[i]);
		sort(a + 1, a + 1 + n);
		sort(b + 1, b + 1 + n);
		sort(c + 1, c + 1 + n, cmp);
		ULL ans = 0;
		for(int i = 1; i <= n; i++){
			int l = 1, r = n, posl = 0, posr = 0;
			while(l <= r){
				int mid = (l + r) >> 1;
				if(a[mid] < b[i]){
					posl = mid;
					l = mid + 1;
				}
				else r = mid - 1;
			}
			l = 1, r = n;
			while(l <= r){
				int mid = (l + r) >> 1;
				if(c[mid] > b[i]){
					posr = mid;
					l = mid + 1;
				}
				else r = mid - 1;
			}
			//printf("%d %d %d\n", posl, i, posr);
			ans = ans + (ULL)posl * (ULL)posr;
		}
		printf("%llu\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100000;
int R, C, n;
vector<pair<pair<int, int>, pair<int, int> > > pts;
vector<pair<int,int> > ed;
int id(int r, int c) {
	if (r == 0)
		return c;
	if (c == C)
		return r + C;
	if (r == R)
		return C - c + C + R;
	return R - r + C + C + R;
}
vector<pair<int,int> > v;
bool comp(const pair<int,int> &a, const pair<int,int> &b) {
	return abs(a.first) < abs(b.first);
}
bool check() {
	v.clear();
	for (int i = 0; i < ed.size(); ++i) {
		v.push_back(make_pair(ed[i].first + 1, i));
		v.push_back(make_pair(-(ed[i].second + 1), i));
	}
	sort(v.begin(), v.end(), comp);
	stack<int> s;
	for (int i = 0; i < v.size(); ++i) {
		if (s.empty() || v[i].first> 0)
			s.push(v[i].second);
		else {
			if (s.top() != v[i].second)
				return false;
			s.pop();
		}
	}
	return s.empty();
}
int main() {
	scanf("%d%d%d", &R, &C, &n);
	for (int i = 0; i < n; ++i) {
		int r1, c1, r2, c2;
		scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
		int on = 0;
		if (r1 == 0 || r1 == R || c1 == 0 || c1 == C)
			++on;
		if (r2 == 0 || r2 == R || c2 == 0 || c2 == C)
			++on;
		if (on == 2)
			pts.push_back(make_pair(make_pair(r1, c1), make_pair(r2, c2)));
	}
	for (int it = 0; it < 4; ++it) {
		ed.clear();
		for (int i = 0; i < pts.size(); ++i) {
			int r1 = pts[i].first.first;
			int c1 = pts[i].first.second;
			int r2 = pts[i].second.first;
			int c2 = pts[i].second.second;
			int A = id(r1, c1);
			int B = id(r2, c2);
			if (A > B)
				swap(A, B);
			ed.push_back(make_pair(A, B));
			swap(r1, c1);
			swap(r2, c2);
			c1 = R - c1;
			c2 = R - c2;
			pts[i] = make_pair(make_pair(r1, c1), make_pair(r2, c2));
		}
		if (!check()) {
			puts("NO");
			return 0;
		}
		swap(R, C);
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 7152
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

template <class my>
inline my aabs (const my &a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b, int m=mod) { return a + b >= m ? a + b - m : a + b; }
inline int sub(const int &a, const int &b, int m=mod) { return a - b < 0 ? a - b + m : a - b; }
inline int mul(const int &a, const int &b, int m=mod) { return int(a * 1ll * b % m); }
inline int pow(int a, int b, int m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
        b >>= 1;
    }
    return ans;
}

void solve()
{
    lli n, m, t, k=0, q, temp=0, u=0, v=0, ans1=0, ans2=0, val=0, sum=0;
    cin>>n>>m;
    vector<int> vect[n+5];
    fol(i,0,n)
    {
        fol(j,0,m)
        {
            cin>>temp;
            vect[i].pb(temp);
        }
    }
    fol(i,0,n)
    {
        fol(j,i+1,n)
        {
            double sum=0;
            fol(k,0,m)
            {
                temp=vect[i][k]-vect[j][k];
                temp*=temp;
                sum+=temp;
            }
            double val=sqrt(sum);
            if(val==ceil(val)) ans1++;
        }
    }
    cout<<ans1<<endl;
}

int main()
{
    fastio cout<<endl;
    cout << fixed << setprecision(7);
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

ll a[100100];
P p[100100];

int main(void){
    ll n,m,b,c;
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++){
        cin>>b>>c;
        p[i]=P(c,b);
    }
    sort(a,a+n);
    sort(p,p+m);
    reverse(p,p+m);
    ll k=0;
    for(int i=0;i<n;i++){
        if(a[i]>=p[k].first) break;
        a[i]=p[k].first;
        p[k].second--;
        if(p[k].second==0) k++;
        if(k==m) break;
    }
    ll ans=0;
    for(int i=0;i<n;i++) ans+=a[i];
    cout<<ans<<endl;
}

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

using namespace std;

int n=0;
int t=0;
int a[3000];
int b[3000];
pair<int, int> p[3001];
int dp[3002][3002];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	cin >> t;
	for (int i=0; i<n; i++)	
	{
		cin >> a[i] >> b[i];
		p[i].first = a[i];
		p[i].second = b[i];
	}	
	sort(p, p+n);
	for (int i=0; i<n; i++)
	{
		a[i] = p[i].first;
		b[i] = p[i].second;
	}
	for (int i=0; i<n; i++)	
	{
		for (int j=0; j<t; j++)
		{
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			dp[i+1][min(t, j+a[i])] = max(dp[i+1][min(t, j+a[i])], dp[i][j]+b[i]);
		}	
	}	
	int Max = 0;
	for (int i=0; i<n; i++)
		Max = max(Max, b[i]);
	for (int i=0; i<=n; i++)
	{
		for (int j=0; j<=t; j++)
		{
			Max = max(Max, dp[i][j]);
		}
	}
	cout << Max;
	return 0;
}


Measured memory_bytes: 35456
#include<stdio.h>
int main(){
	char su[1001];
	int i,sum=0;
	while(1){
		scanf("%s",&su);
		if(su[0]=='0'){
			break;
		}
		for(i=0;i<1001;i++){
			if(su[i]=='\0') break;
			sum+=su[i]-'0';
		}
		printf("%d\n",sum);
		sum=0;
	}
}


Measured memory_bytes: 2044