akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep2(i, x, n) for(int i = x; i < (n); ++i)

int main()
{
    string a;
    cin >> a;
    int res = 0, count = 0;
    rep(i, a.length()) {
        if (a[i] == 'S') {
            count = 0;
            continue;
        } else {
            count++;
            res = max(res, count);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////
#define N 500004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return po(mod(mod(i)*mod(i)),p/2);
    else  return mod(mod(i)*po(i,p-1));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    else if(n==0)return 1;
    else return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}


int main(){fastio
    calc();
    ll n,m,k;cin>>n>>m>>k;
    ll last=kai2[k-2];
    ll nowu=mod(n*m-2);
    rep(i,1,k-2){
        last=mod(last*nowu);
        nowu--;
        if(nowu<0)nowu=mod(nowu);
    }
    ll s[N];s[0]=0;rep(i,1,N-1)s[i]=s[i-1]+i;
    ll sum1=0,sum2=0;
    rep(i,1,m){
        sum1+=s[i-1]+s[m-i];
    }
    sum1=mod(mod(sum1*n)*n);
    rep(i,1,n){
        sum2+=s[i-1]+s[n-i];
    }
    sum2=mod(mod(sum2*m)*m);
    
    //cout<<sum1<<" "<<sum2<<endl;
    sum1=mod(sum1+sum2);
    last=mod(last*sum1);
    last=mod(last*bunbo(2));
    cout<<last<<endl;
    
    return 0;
}




Measured memory_bytes: 12032
#!/usr/bin/env python
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
Acum = list(accumulate([0] + A))

def cumsum(left, right):
    # [i, j)
    return Acum[right] - Acum[left]

def find_best_cut(left, right, prev):
    prev = max(prev, left+1)
    now = prev
    res = now
    best = abs(cumsum(left, prev) - cumsum(prev, right))
    while True:
        now += 1
        score = abs(cumsum(left, now) - cumsum(now, right))
        if score < best:
            best = score
            res = now
        else:
            return res

left = 0
right = 0
best = float('inf')
for center in range(1, N-1):
    # 左しゃくとり
    left = find_best_cut(0, center, left)
    right = find_best_cut(center, N, right)
    
    t = [cumsum(0, left), cumsum(left, center), cumsum(center, right), cumsum(right, N)]
    score = max(t) - min(t)
    if score < best:
        best = score
    
print(best)


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

int main(){

	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) cin>>arr[i];
	int l = 0,r = 0;
	long long ans = 0;
	int curr = 0;
	while(l < n){
		while(r < n && (curr^arr[r]) == curr+arr[r]){
			curr^=arr[r++];ans++;
		}
		curr^=arr[l++];
		ans+=(r-l);
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,cnt,sum1,sum2,res;
string s;
bitset<105> bt;
int f(ll res)
{
    if(res==0)
    {
        return 1;
    }
    ll ans=1;
    bt=res;
    ans+=f(res%(bt.count()));
    return ans;
}
int main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>n>>s;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='1')
            cnt++;
    }
    for(int i=0;i<=n-1;i++)
    {
        if(s[i]=='1')
        {
            if(cnt!=1)
                sum1+=qpowmod(2,n-i-1,cnt-1);
            sum2+=qpowmod(2,n-i-1,cnt+1);
        }
    }
    for(int i=0;i<=n-1;i++)
    {
        if(s[i]=='1')
        {
            if(cnt==1)
            {
                cout<<0<<endl;
                continue;
            }
            res=sum1;
            res=(((res-qpowmod(2,n-i-1,cnt-1))%(cnt-1))+(cnt-1));
            res%=(cnt-1);
        }
        else
        {
            res=sum2;
            res+=qpowmod(2,n-i-1,cnt+1);
            res%=(cnt+1);
        }
        cout<<f(res)<<endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 3752
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const LL N=1e5+5;
LL i,n,m,ans=1LL<<60,l1,l2,tmp;
LL a[N],b[N];
int main()
{
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;++i)
	{
		scanf("%lld",&tmp);
		if (tmp<0)
			a[++l1]=tmp;
		else
			b[++l2]=tmp;
	}
	for (i=1;i<=l1>>1;++i)
		swap(a[i],a[l1-i+1]);
	for (i=min(m,l1);i>=max(m-l2,0LL);--i)
		ans=min(ans,b[m-i]-a[i]+min(b[m-i],-a[i]));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896
n, m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
  p[i], s[i] = input().split()
  p[i] = int(p[i])
c = [0] * (n + 1)
w = [0] * (n + 1)
for i in range(m):
  if c[p[i]] == 0 and s[i] == 'AC':
    c[p[i]] = 1
  elif c[p[i]] == 0 and s[i] == 'WA':
    w[p[i]] = w[p[i]] + 1
    
for i in range(1, n+1):
  if c[i] == 0:
    w[i] = 0
print(sum(c), sum(w))

Measured memory_bytes: 14836
#include<stdio.h>
#include<math.h>
int main()
{
    int N, L;
    scanf("%d %d", &N, &L);

    int flav[N];

    for(int i=0; i<N; i++)
    {
        flav[i] = L+i;
    }
    long int sum2=0;
    int num=0;

    for(int i=0; i<N; i++)
        sum2+=flav[i];

    for(int i=0; i<N; i++)
    {
        if(flav[N-1]<=0)
        {
            num=flav[N-1];
            break;
        }
        else
        {
            if(flav[i]>=0)
            {
                num=flav[i];
                break;
            }
        }
    }

    sum2-=num;



    printf("%ld", sum2);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	char s[10000];
	scanf("%s",s);
	if((s[1]=='A'&&(s[0]=='B'||s[2]=='B'))||(s[1]=='B'&&(s[0]=='A'||s[2]=='A'))){
		printf("Yes");
	}else{
		printf("No");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int a[10010];
int main(){
	cin>>n;
	int count=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		while(a[i]%2==0){
			count++;
			a[i]/=2;
		}
	}
	cout<<count<<endl;
}
	

Measured memory_bytes: 256
int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d %d %d\n", a < b ? (a < c ? a : c) : (b < c ? b : c), a < b ? (a < c ? (b < c ? b : c) : a) : (b < c ? (a < c ? a : c) : b), a < b ? (b < c ? c : b) : (a < c ? c : a));
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
    int a,b,jam,zarb,kam,maxim;
    cin>>a>>b;
    jam=a+b;
    kam=a-b;
    zarb=a*b;
    maxim=max(jam,kam);
    maxim=max(maxim,zarb);
    cout<<maxim;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main(){
    int n,k;
    cin >> n >> k;

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


    for(int i=k;i<n;i++){
        if(a[i]>a[i-k]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 5152
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for j in range(h):
        for i in range(w):
            if (i + j)%2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
a=int(input())
def factorization(n):
    arr=[]
    temp=n
    for i in range(2,int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp//=i
            arr.append([i,cnt])
    if temp!=1:
        arr.append([temp,1])
    if arr==[]:
        arr.append([n,1])
    return arr
ww=factorization(a)
ans=0
if a==1:
    ans=0
else:
    for j in range(len(ww)):
        if 2>=ww[j][1]>=1:
            ans+=1
        if 5>=ww[j][1]>=3:
            ans+=2
        if 9>=ww[j][1]>=6:
            ans+=3 
        if 14>=ww[j][1]>=10:
            ans+=4
        if 20>=ww[j][1]>=15:
            ans+=5
        if 27>=ww[j][1]>=21:
            ans+=6
        if 35>=ww[j][1]>=28:
            ans+=7
        if ww[j][1]>=36:
            ans+=8
print(ans)

Measured memory_bytes: 9540
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#include<string>
#include<deque>
#include<set>
#include<vector>
#include<map>
using namespace std;
long long sum=0;
int gcd(int a,int b,int c)
{
    int x=0;
    if(a<b)
        swap(a,b);
    while(a%b!=0)
    {
        x=a%b;
        a=b;
        b=x;
    }
    if(b<c)
        swap(b,c);
    while(b%c!=0)
    {
        x=b%c;
        b=c;
        c=x;
    }
    return c;
}
int main()
{
    int k,a=1,b=1,c=1;
    scanf("%d",&k);
    for(a=1,b=1,c=1;a<=k&&b<=k&&c<=k;)
    {
        sum+=gcd(a,b,c);
        for(int i=1;a+i<=k;i++)
        {
            sum+=gcd(a+i,b,c);
        }
        for(int i=1;b+i<=k;i++)
        {
            sum+=gcd(a,b+i,c);
        }
        for(int i=1;c+i<=k;i++)
        {
            sum+=gcd(a,b,c+i);
        }
        for(int i=1;a+i<=k;i++)
        {
            for(int j=1;b+j<=k;j++)
                sum+=gcd(a+i,b+j,c);
        }
        for(int i=1;a+i<=k;i++)
        {
            for(int j=1;c+j<=k;j++)
                sum+=gcd(a+i,b,c+j);
        }
        for(int i=1;b+i<=k;i++)
        {
            for(int j=1;c+j<=k;j++)
                sum+=gcd(a,b+i,c+j);
        }
        a++;
        b++;
        c++;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
int main (){
string s1,s2,s3;
char a,b,c;
cin>>s1>>s2>>s3;
a=s1.at(0)-32;
b=s2.at(0)-32;
c=s3.at(0)-32;
cout<<a<<b<<c<<"\n";

}

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

int main() {

    int N;
    std::cin >> N;
    std::vector<int> X(N);
    for (auto& v : X)std::cin >> v;

    std::vector<int> sorted = X;
    std::sort(begin(sorted), end(sorted));
    int half = N / 2;
    for (int i = 0; i < N; ++i) {
        int n = std::distance(begin(sorted), std::lower_bound(begin(sorted), end(sorted), X[i]));
        int mid = -1;
        if (n < half)mid = sorted[half];
        else mid = sorted[half - 1];
        std::cout << mid << "\n";
    }

}


Measured memory_bytes: 3712
#include <cstdio>

int main(void){
    int n,k;
    char s[100];
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    int a = 'a' - 'A';
    s[k-1] = s[k-1]+a;
    printf("%s\n",s);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int a[200010];
int sum[200010];
map<int, int> mp;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    
    rep(i, n) cin >> a[i];
    rep(i, n) sum[i + 1] = sum[i] + a[i];
    rep(i, n + 1) {
        mp[sum[i]]++;
    }
    int ans = 0;
    rep(i, n) {
        mp[sum[i]]--;
        ans += mp[sum[i]];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19160
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def main():
    n, k = LI()
    if k > (n - 1) * (n - 2) // 2:
        print(-1)
        return
    else:
        add_v = (n - 1) * (n - 2) // 2 - k
        print(n - 1 + add_v)
        cnt = 0
        for i in range(2, n + 1):
            print(1, i)
        if cnt == add_v:
            return
        for j in range(2, n + 1):
            for l in range(j + 1, n + 1):
                print(j, l)
                cnt += 1
                if cnt >= add_v:
                    return


main()

Measured memory_bytes: 43888
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int foo(string& s, int x) {
	int l = 0, r = 2, cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		int j = (s[i] - '1') % 3;
		if (x == -1) {
			if (j <= r) {
				l = j;
				x *= -1;
			}
			else {
				r = j;
				cnt++;
			}
		}
		else {
			if (j >= l) {
				r = j;
				x *= -1;
			}
			else {
				l = j;
				cnt++;
			}
		}
	}
	return cnt;
}

int main() {
	for (;;) {
		string s; cin >> s;
		if (s == "#") break;
		cout << min(foo(s, -1), foo(s, 1)) << endl;
	}
}

Measured memory_bytes: 1320
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var g1 = "";  var g2 = "";
            for (int i = 0; i < 3; i++)
            {
                var s = Console.ReadLine().Trim();
                if (i == 0 && s == "0") goto wend;
                var a = s.Length - s.Replace("A", "").Length;
                var b = s.Length - a;
                switch (i)
                {
                    case 0:
                        a--;
                        if (a > b) { a++; g1 = "a"; }
                        else { b++; g1 = "b"; }
                        Console.WriteLine("{0} {1}", a, b);
                        break;
                    case 1:
                        if (g1 == "a") a--;
                        else b--;
                        if (a > b) { a++; g2 = "a"; }
                        else { b++; g2 = "b"; }
                        Console.WriteLine("{0} {1}", a, b);
                        break;
                    case 2:
                        if (g2 =="a") a--;
                        else b--;
                        if (a > b)  a++; 
                        else  b++;
                        Console.WriteLine("{0} {1}", a, b);
                        break;
                }
            }
        }
            wend:;
    }
}

Measured memory_bytes: 9052
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 100010
#define LLI long long

int n,
	a[MXN];
LLI ans;


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

Measured memory_bytes: 640
use std::io::*;
use std::str::*;
use std::collections::*;

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if !s.is_empty() {
        if let Ok(s) = s.parse::<T>() {
            s
        } else {
            panic!("faild to parse {}", s);
        }
    } else {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    read_from(&mut stdin)
}

pub fn chars() -> Vec<char> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let s: String = read_from(&mut stdin);
    s.chars().collect()
}

pub fn readn<T: FromStr>(n: usize) -> Vec<T> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    (0..n).map(|_| read_from(&mut stdin)).collect()
}

fn main() {
    loop {
        let n: usize = read();
        let m: usize = read();
        let q: usize = read();

        let tokens = readn(q*2+m*2);

        let mut to_l: Vec<_> = vec![BTreeSet::new(); n + 1];
        let mut to_r: Vec<_> = vec![BTreeSet::new(); n + 1];
        let mut rails: Vec<(usize, usize, usize)> = (0..m).map(|i| (tokens[i*2], tokens[i*2+1], i)).collect();
        rails.sort();
        let mut rails: VecDeque<_> = rails.iter().cloned().collect();
        for &(l, r, i) in rails.iter() {
            to_l[r].insert((l, i));
            to_r[l].insert((r, i));
        }
        let mut qs: Vec<_> = (0..q).map(|i| {
            let l: usize = tokens[m*2+i*2];
            let r: usize = tokens[m*2+i*2+1];
            (l, r, i)
        }).collect();
        qs.sort();

        let mut ans = vec![0; q];
        for &(ql, qr, i) in qs.iter() {
            while rails.len() > 0 && rails.front().unwrap().0 < ql {
                let (l, r, i) = rails.pop_front().unwrap();
                to_l[r].remove(&(l, i));
                to_r[l].remove(&(r, i));
            }
            let mut cnt = 0;
            for r in ql..qr + 1 {
                cnt += to_l[r].len();
            }
            ans[i] = cnt;
        }

        let mut buf = String::new();
        for e in ans.iter() {
            buf.push_str(&format!("{}\n", e));
        }
        print!("{}", buf);
    }
}


Measured memory_bytes: 43892
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
	int n,m,d;
	int i,j,y,x,c=0,ans=0;
	int map[105][105];
	char a;
	memset(map,0,sizeof(map));
	cin>>n>>m>>d;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>a;
			if(a=='#'){
				map[i][j]=1;
			}
		}
	}
		
	/*for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cout<<map[i][j];
		}
		cout<<endl;
	}*/
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			c=0;
			for(y=i;y<i+d;y++){
				if(y<=n){
					if(map[y][j]==0){
						c++;
					}
				}
			}
			if(c==d){
				ans++;
			}
			c=0;
			for(x=j;x<j+d;x++){
				if(x<=m){
					if(map[i][x]==0){
						c++;
					}
				}
			}
			if(c==d){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3100
k,t=map(int,input().split())
A=[int(i) for i in input().split()]
a=max(A)
if a<=(k-1)//2+1:
  print(0)
else:
  if k%2==1:
    print(2*(a-((k-1)//2+1)))
  else:
    print(2*(a-((k-1)//2+1))-1)

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

int n, m;
int field[90][90];
bool visited[90][90];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int solve(int x, int y) {
  visited[y][x] = true;
  int ret = 0;
  for (int i = 0; i < 4; i++) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (!visited[ny][nx] && 0 <= nx && nx < n && 0 <= ny && ny < m && field[ny][nx] == 1) {
      ret = max(ret, solve(nx, ny) + 1);
    }
  }
  visited[y][x] = false;
  return ret;
}

int main(void) {
  while (cin >> n >> m, n && m) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        cin >> field[i][j];
        visited[i][j] = false;
      }
    }
    int ans = -1;
    for (int x = 0; x < n; x++) {
      for (int y = 0; y < m; y++) {
        ans = max(solve(x, y), ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e3 + 3, MOD = 1e9 + 7;
ll n, q;
string S, T;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> S >> T;
    cout << T << S << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
			string s = Console.ReadLine();

			if(s.Substring(s.Length-1, 1) == "s")
            {
				Console.WriteLine(s + "es");
			}
			else
            {
				Console.WriteLine(s + "s");
			}
		}
	}
}


Measured memory_bytes: 25876
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int numberCount = sc.nextInt();
        int divisionTimes = 0;
        int minDivision = 1000000001;

        for (int i = 0; i < numberCount; i++) {
            int divisionNumber = sc.nextInt();
            while(divisionNumber % 2 == 0) {
               divisionNumber /= 2;
               divisionTimes += 1;
            }
            if(divisionTimes < minDivision) minDivision = divisionTimes;
            divisionTimes = 0;
        }
        System.out.println(minDivision);
    }
}


Measured memory_bytes: 21840
#include <stdio.h>

int main(void) {
  int n, i, j, k, a[4], b[4];
  while(scanf("%d", &a[0]) != EOF) {
    for(i = 1; i < 4; ++i) scanf("%d", &a[i]);
    for(i = 0; i < 4; ++i) scanf("%d", &b[i]);
    int h = 0, bl = 0, flag[10];
    for(i = 0; i < 10; ++i) flag[i] = 0;
    for(i = 0; i < 4; ++i) {
      if(a[i] == b[i]) h++;
      else flag[a[i]] = 1;
    }
    for(i = 0; i < 4; ++i) if(flag[b[i]]) ++bl;
    printf("%d %d\n", h, bl);
  }
  return 0;
}


Measured memory_bytes: 2676
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main 
{
	static class Grid
	{
		int x;
		int y;
		
		public Grid(int x0, int y0)
		{
			x = x0;
			y = y0;
		}
	}
	
	static int colors = 6;
	static int tar = 5;
	static int c = 0;
	static int[][] pan;
	static int w, h;	
	static int max = -1;
	static void fil(int[] ar)
	{
//		int k = 0;
		
//		int[][] m = pan.clone();
		
		ArrayList<Grid> pen = new ArrayList<Grid>();
		pen.add(new Grid(0,0));
		
		boolean[][] in = new boolean[w][h];
		in[0][0] = true;
		
		int check = 0;
		while(check < pen.size())
		{
			Grid p = pen.get(check);
//			System.out.println("Checking " + p.x + " " + p.y);
			for(int d = 0; d < 4; d++)
			{
				int xp = p.x;
				int yp = p.y;
				
				if(d==0)xp++;
				else if(d==1)xp--;
				else if(d==2)yp++;
				else if(d==3)yp--;
				
				if(xp >= 0 && xp < w && yp >= 0 && yp < h)
				{
					if(!in[xp][yp] && pan[xp][yp] == pan[0][0])
					{
//						if(true)System.out.println("COL " + pan[0][0] + ", " + xp + " " + yp);
						pen.add(new Grid(xp, yp));
						in[xp][yp] = true;
					}
				}
			}	
			check++;
		}
		

		
		boolean debug = false;
		if(ar[0] == 5 && ar[1] == 2 && ar[2] == 3 && ar[3] == 1 && ar[4] == 4)
		{
//			debug = true;
		}
		
		if(debug)System.out.println(Arrays.toString(ar));

		
		
		
		for(int i = 0; i < 5; i++)
		{
			int col = ar[i];
			int cursize = pen.size();
			
			if(debug)System.out.println("doing col " + col + " (->" + (col+1) + "), cursize " + cursize);
			if(debug)
			{
				for(Grid p : pen)
				{
					System.out.println("panel " + p.x + " " + p.y);
				}
			}
			
			for(int pi = 0; pi < pen.size(); pi++)
			{
				Grid p = pen.get(pi);
				
				
				if(pi < cursize || pan[p.x][p.y] == col)
				for(int d = 0; d < 4; d++)
				{
					int xp = p.x;
					int yp = p.y;
					
					if(d==0)xp++;
					else if(d==1)xp--;
					else if(d==2)yp++;
					else if(d==3)yp--;
					
					if(xp >= 0 && xp < w && yp >= 0 && yp < h)
					{
						if(!in[xp][yp] && pan[xp][yp] == col)
						{
							if(debug)System.out.println("COL " + col + ", " + xp + " " + yp);
							pen.add(new Grid(xp, yp));
							in[xp][yp] = true;
						}
					}
				}
			}
		}
		
		max = Math.max(max, pen.size());
		if(debug)System.out.println(pen.size());
	}
			
	static void cyc(int[] ar, int t)
	{
		if(t <= 3)
		{
			for(int i = 0; i < colors; i++)
			{
				if(t <= 0 || ar[t-1] != i)
				{
					int[] arc = ar.clone();
					arc[t] = i;
					cyc(arc, t+1);
				}
			}
		}
		else
		{
			c++;
			ar[4] = tar;
			fil(ar);
		}
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
//		System.out.println(c);
		
		while(true)
		{
			h = sc.nextInt();
			w = sc.nextInt();
			tar = sc.nextInt()-1;
			
			if(h == 0 && w == 0 && tar == -1)return;
			
			pan = new int[w][h];
			max = -1;
			
			for(int y = 0; y < h; y++)
			{
				for(int x = 0; x < w; x++)
				{
					pan[x][y] = sc.nextInt()-1;
				}
			}
			cyc(new int[]{0, -1, -1, -1 ,-1}, 0);
			System.out.println(max);
		}
	}

}


Measured memory_bytes: 68336
#include<stdio.h>

int main(){
	long long s, c;
	int sc;
	sc = scanf("%lld %lld", &s, &c);
	
	if(s * 2 < c){
		c -= 2 * s;
		s += c / 4;
	}else s = c / 2;
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

long long W, H, N, x[1 << 17], y[1 << 17];
vector<long long>X, Y;

long long solve(long long px, long long py) {
	vector<long long>I;
	for (int i = 1; i <= N; i++) {
		I.push_back(abs(px - x[i]) + abs(py - y[i]));
	}
	sort(I.begin(), I.end());
	long long rem = 0;
	for (int i = 0; i < I.size(); i++) {
		rem += I[i] * 2;
	}
	rem -= I[I.size() - 1];
	return rem;
}

int main() {
	cin >> W >> H >> N;
	for (int i = 1; i <= N; i++) {
		cin >> x[i] >> y[i];
		X.push_back(x[i]);
		Y.push_back(y[i]);
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());

	long long L = N / 2 - 5, R = N / 2 + 5; L = max(L, 0LL); R = min(R, N - 1LL);
	tuple<long long, long long, long long> ret = make_tuple((1LL << 60), 0, 0);
	for (int i = L; i <= R; i++) {
		for (int j = L; j <= R; j++) {
			long long ans = solve(X[i], Y[j]);
			ret = min(ret, make_tuple(ans, X[i], Y[j]));
		}
	}
	cout << get<0>(ret) << endl;
	cout << get<1>(ret) << " " << get<2>(ret) << endl;
	return 0;
}


Measured memory_bytes: 7864
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var a = Reads();
            a = a.OrderByDescending(x=>x).ToArray();
            long ans = 0;
            for (int i = 1; i <=2*(n-1)+1; i +=2) ans += a[i];
            Console.WriteLine(ans);

            

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 54164
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pii;


int main() {
	lld S;
	cin >> S;
    const lld LIMIT = 1e9;
	if (S <= LIMIT) {
	  cout << "0 0 " << S << " 0 0 1\n";
	} else {
	  cout << "0 0 " << LIMIT << " 1 ";
	  lld x = (S + LIMIT - 1ll) / LIMIT;
	  lld y = x * LIMIT - S;
	  cout << y << " " << x << "\n";
	}
	return 0;
}

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

int main() {
  int N,S=0;
  cin>>N;

  for(int i=1;i<N+1;i*=10){
    S+=(N/i)%10;
  }
  if(N%S==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int a[30],b[30],c[30];
int ans=0;

int main()

{
	ios::sync_with_stdio(false);
	a[0]=1e9;
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>a[i];

	for (int i=1;i<=n;i++)
		cin>>b[i];

	for (int i=1;i<n;i++)
		cin>>c[i];

	for (int i=1;i<=n;i++){
		if (a[i-1]+1==a[i]) ans+=c[a[i-1]];
		ans+=b[a[i]];
	}

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

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int A, B; cin >> A >> B;
  int ans = max(2 * A - 1, 2 * B - 1);
  ans = max(ans, A + B);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
N = int(input())
#素数リスト
primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

import math
NK=math.factorial(N)
from itertools import permutations, combinations,combinations_with_replacement,product
L = combinations(range(0,len(primes)), 3)   #nCr
L = list(L)
ans = 0
for i in L:
  x = ((primes[i[0]]**4)*(primes[i[1]]**4)*(primes[i[2]]**2))
  if NK % x ==0:
    ans +=1
  x = ((primes[i[1]]**4)*(primes[i[2]]**4)*(primes[i[0]]**2))
  if NK % x ==0:
    ans +=1
  x = ((primes[i[2]]**4)*(primes[i[0]]**4)*(primes[i[1]]**2))
  if NK % x ==0:
    ans +=1

L = combinations(range(0,len(primes)), 2)   #nCr
L = list(L)
for i in L:
  x = ((primes[i[0]]**24)*(primes[i[1]]**2))
  if NK % x ==0:
    ans +=1
  x = ((primes[i[1]]**24)*(primes[i[0]]**2))
  if NK % x ==0:
    ans +=1
  x = ((primes[i[0]]**14)*(primes[i[1]]**4))
  if NK % x ==0:
    ans +=1
  x = ((primes[i[1]]**14)*(primes[i[0]]**4))
  if NK % x ==0:
    ans +=1

L = combinations(range(0,len(primes)), 1)   #nCr
L = list(L)
for i in L:
  x = ((primes[i[0]]**74))
  if NK % x ==0:
    ans +=1

print(ans)

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

int main() {
	int h,w;
	cin >> h >> w;
	char p[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> p[i][j];
		}
	}

	for(int i=0;i<h*2;i++){
		for(int j=0;j<w;j++){
			cout << p[i/2][j];
		}
		cout << endl;
	}
	return 0;
}

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

int ans=0;
void dfs(int v, vector<vector<int>> &g, vector<bool> &visited) {
	visited[v] = true;

	bool visitedall=true;
	for (bool b : visited) {
		if (!b) {
			visitedall=false;
			break;
		}
	}
	if (visitedall) ans++;

	for (int i : g[v])
		if (!visited[i]) dfs(i,g,visited);

	visited[v] = false;
}

int main() {
	int n,m; cin>>n>>m;
	vector<vector<int>> g(n+1);
	for (int i=0; i<m; i++) {
		int a,b; cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<bool> visited(n+1);
	visited[0]=true;
	dfs(1,g,visited);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int min=1145141919;
	int E=0;
	for(int i=0;i<a;i++) {
		int b=scan.nextInt();
		int c=scan.nextInt();
		if(min>c) {
			min=c;
			E=b;
		}
	}
	System.out.println(E+min);
	}
}

Measured memory_bytes: 63684
#include<stdio.h>
int main() {
	char s[2];

	scanf("%s", s);
	if (s[0] == 'A')puts("T");
	if (s[0] == 'T')puts("A");
	if (s[0] == 'C')puts("G");
	if (s[0] == 'G')puts("C");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        int mn = INT_MAX, cnt = 0;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            mn = min(mn, q);
            if (mn >= q){
                cnt++;
            }
        }
        cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bOut(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return d
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n, m := iScan(), iScan()
	p := iSScan(n)
	ans := 0
	u := newUnionFind(n)
	for i := 0; i < m; i++ {
		u.unite(iScan()-1, iScan()-1)
	}
	for i := 0; i < n; i++ {
		if u.same(i, p[i]-1) {
			ans++
		}
	}
	fmt.Println(ans)
}

type UnionFind struct {
	par []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, ii>  iii;
typedef pair<double, double>  iidb;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 3200
#define offset 3000
#define ptr nodo*
const ll MOD=1e9+7;

using namespace std;
int n;
vector<int> g[tam];
int V[tam];
int dp2[tam][tam][3];
int dp[tam][3];
int nodo;

int solve(int pos,int cantidad,int color)
{
	if (cantidad<0)
		return INF;
	if (pos==g[nodo].size())
		return 0;
	if (dp2[pos][cantidad][color]!=-1)
		return dp2[pos][cantidad][color];
	int minn=INF,w=g[nodo][pos];
	if (dp[w][color]!=INF)
	minn=min(minn,solve(pos+1,cantidad-V[w],color)+dp[w][color]);
	if (dp[w][!color]!=INF)
	minn=min(minn,solve(pos+1,cantidad-dp[w][!color],color)+V[w]);
	dp2[pos][cantidad][color]=minn;
	return minn;
}

void dfs(int u)
{
	for(int w:g[u])
	{
		dfs(w);
	}
	if (g[u].size()==0){
		dp[u][1]=dp[u][0]=0;
		return ;
	}
	nodo=u;
	forr(cant,0,V[u]+20)
		forr(pos,0,g[u].size()+20)
			dp2[pos][cant][0]=dp2[pos][cant][1]=-1;
	dp[u][0]=solve(0,V[u],0),
	dp[u][1]=solve(0,V[u],1);

}
int main()
{	
	cin>>n;
	int valor;

	forr(i,2,n+1)
	{
		cin>>valor;
		g[valor].pb(i);
	}	
	forr(i,1,n+1)
		cin>>V[i];
	dfs(1);
	if (min(dp[1][0],dp[1][1])!=INF)
		cout<<"POSSIBLE\n";
	else
		cout<<"IMPOSSIBLE\n";
}		

Measured memory_bytes: 7848
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {

	int N;
	scanf("%d", &N);

	int temp = N;
	int f = 0;

	for (int i = 0; i < 10; i++) {
		f += temp % 10;
		temp /= 10;
	}

	if (N % f == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}


}


void  bubbleSort(char number[]) {
	for (int i = 0; i < strlen(number); i++)
		for (int j = i + 1; j < strlen(number); j++)
			if ((int)number[i] > (int)number[j]) {
				char tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
}

Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>a>>b;
if(a==0)
{cout<<0;return ;}
int count=b/2019-(a-1)/2019;
if(count)
{
    cout<<0;return ;
}
ll mi=llmax;
for(ll i=a;i<b;i++)
{
    for(ll j=i+1;j<=b;j++)
    {
      mi=min(mi,(i*j)%2019); 
    }
}
cout<<mi;

return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  int count = 0;
  int hairetu[100000];
  cin >> a >> b >>k;
  for(int i=1;i<100000;i++){
    if(a%i==0&&b%i==0){
      count++;
      hairetu[count]=i;
    }
    if(i==max(a,b)){
      break;
    }
  }
  cout << hairetu[count-k+1] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a, b, c;
  
  scanf("%d %d %d", &a, &b, &c);
  if(a == b){
    printf("%d", c);
  } else if(a == c){
    printf("%d", b);
  } else if(b == c){
    printf("%d", a);
  }
  
  return 0;
}

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

typedef pair<int, int> ii;
typedef long long ll;
const int mod = 1000000007;

int mul(int x, int y) {
  return (ll)x * y % mod;
}
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
int mpow(int x, int y) {
  if (y == 0) return 1;
  int ret = mpow(x, y / 2);
  ret = mul(ret, ret);
  if (y & 1) ret = mul(ret, x);
  return ret;
}
int inv(int x) {
  return mpow(x, mod - 2);
}
int two[200005];

struct X {
  int a, b, c;
  X() {}
  X(int x, int y, int z): a(x), b(y), c(z) {}
};

int n;
vector<int> v[200005];
int sz[200005];

deque<X> pl[200005];
deque<X> *dq[200005];

int cnt;
deque<X>* newd() {
  return &pl[cnt ++];
}

deque<X>* merge(deque<X>* d1, deque<X>* d2, int &ssz) {
  if (d1->size() < d2->size()) swap(d1, d2);
  deque<X> &p = *d1;
  deque<X> &q = *d2;

  ssz = max(ssz, (int)q.size());
  for (int i = 0; i < (int)q.size(); i ++) {
    // X tmp(add(mul(p[i].a, q[i].b), mul(p[i].b, q[i].a)), mul(p[i].b, q[i].b));
    p[i].a = add(mul(p[i].a, q[i].b), mul(p[i].b, q[i].a));
    p[i].b = mul(p[i].b, q[i].b);
    p[i].c = add(p[i].c, q[i].c);
  }
  return d1;
}

void dfs(int x) {
  if (v[x].size() == 0) {
    dq[x] = newd();
    dq[x]->push_back(X(1, 1, 1));
    return;
  }
  dq[x] = nullptr;
  int ssz = 0;

  for (int i = 0; i < (int)v[x].size(); i ++) {
    int y = v[x][i];
    dfs(y);

    if (dq[x] == nullptr) dq[x] = dq[y];
    else {
      dq[x] = merge(dq[x], dq[y], ssz);
    }
  }

  auto &d = *dq[x];
  for (int i = 0; i < ssz; i ++) {
    // d[i].a = mul(d[i].a, d[i].b);
    d[i].b = sub(two[d[i].c], d[i].a);
    // d[i].a = mul(d[i].a, inv(d[i].b));
  }
  d.push_front(X(1, 1, 1));
}

int main() {
  scanf("%d", &n);

  two[0] = 1;
  for (int i = 1; i <= n + 1; i ++) {
    two[i] = mul(two[i - 1], 2);
  }

  for (int i = 1; i <= n; i ++) {
    int pi;
    scanf("%d", &pi);
    v[pi].push_back(i);
  }

  dfs(0);

  int ans = 0;
  for (X x : *dq[0]) {
    int tmp = mul(x.a, two[n + 1 - x.c]);
    ans = add(ans, tmp);
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 164352
#include<stdio.h>
#define WHITE 0
#define INF (1<<21)
#define GRAY 1  
#define BLACK 2

int n;
int G[101][101];
int distance[101];
int color[101];

void search_distance(void);

int main(){
  int st,sum,go,w;
  int i,j;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=-1;
    }
  }
    
  for(i=0;i<n;i++){
    scanf("%d%d",&st,&sum);
    for(j=0;j<sum;j++){
      scanf("%d%d",&go,&w);
     G[st][go] = w;
    }
  }
  //printf("---unko\n");
 
  search_distance();
  
  return 0;
}

void search_distance(){
  int i,j;
  int mini,u;
  //printf("ljoj\n");
  
  for(i=0;i<n;i++){
      color[i]=WHITE;
      distance[i]=INF;
  }
  color[0]=GRAY;
  distance[0]=0;
  //printf("mMm\n");
  while(1){
    mini=INF;
    u=-1;
    
    for(i=0;i<n;i++){
      if(mini>distance[i] && color[i]!=BLACK){
        u=i;
        mini=distance[i];
      }
      }
      if(u==-1)break;
      color[u]=BLACK;

      for(i=0;i<n;i++){
	if(color[i]!= BLACK && G[u][i]!=-1){
	  if(distance[i] > distance[u]+ G[u][i]){
	    distance[i]=distance[u]+G[u][i];
	    color[i]=GRAY;
	  }
	}
      }
    }
  
    for(i=0;i<n;i++){
      printf("%d %d\n",i,distance[i]);
    }

}



Measured memory_bytes: 2004