akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	map<string, int> cnt;
	rep(i, 0, N) {
		string s; cin >> s;
		cnt[s]++;
	}

	int ma = -1;
	fore(p, cnt) chmax(ma, p.second);
	fore(p, cnt) if (p.second == ma) printf("%s\n", p.first.c_str());
}







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

using namespace std;

# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

using lint = long long;
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; }


#define M_DEBUG if (1)

/******************************************************************************
	Main
******************************************************************************/
int main()
{
	double n = 0.0;
	cin >> n;
	assert(n >= 1 && n <= 100);


	cout << int(ceil(n / 2)) << endl;

	return 0;
}


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

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s){
		int n=s.length();
		bool flag=0;
		for(int i=0;i<n;i++){
			if(s[i]=='9') flag=1;
		}
		if(flag) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,q,r[510][510];
    cin>>n>>m>>q;
    rep(i,m){
        int R,L;
        cin>>R>>L;
        r[R][L]++;
    }
    rep2(i,1,n+1){
        rep2(j,1,n+1){
            r[i][j] +=r[i][j-1];
        }
    }
    rep2(i,1,n+1){
        rep2(j,1,n+1){
            r[i][j] +=r[i-1][j];
        }
    }
    rep(i,q){
        int R,L;
        cin>>R>>L;
        cout<<r[L][L]+r[R-1][R-1]-r[R-1][L]-r[L][R-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin>>N;
    string str,cstr;
    cin >> str;
    cstr=str;
    for(int i=0;str.length()!=0;){
        if(str[i]=='('&&str[i+1]==')'){
            str.erase(str.begin()+i,str.begin()+i+2);
            i=0;
            
        }else if(str[i]==')'){
            str="("+str;
            cstr="("+cstr;
            
        }else if(str[i]=='('&&i==str.length()-1){
            str=str+")";
            cstr=cstr+")";

            
        }else{i++;}
        
        
    }
    
    cout << cstr <<"\n";
    
    return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
using namespace std;
int main(void){
    int a,b,c,x,y,z,ans=0;
    cin>>a>>b>>c;
    x=fabs(a-b);
    y=fabs(b-c);
    z=fabs(c-a);
    if(a%2==1){
        cout<<0<<endl;
        goto end;
    }
    if(x==y&&y==z){
        cout<<-1<<endl;
        goto end;
    }
    
    while(x%2==0&&y%2==0&&z%2==0){
        x/=2;
        y/=2;
        z/=2;
        ans++;
    }
    cout<<ans<<endl;
    
    end:
    x=0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    vl w(4);
    in(4,w);
    ll N;cin >> N;
    
    ll one = min({w[0]*4,w[1]*2,w[2]});
    ll twe = min({w[0]*8,w[1]*4,w[2]*2,w[3]});
    
    cout << N/2*twe + N%2 * one  << endl;
    
    

    return 0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    S = list(input())

    R = []
    G = []
    B = []
    for i, s in enumerate(S):
        if s == 'R':
            R.append(i)
        elif s == 'G':
            G.append(i)
        else:
            B.append(i)

    cnt = 0
    for i in range(0, n):
        for j in range(i+1, n):
            k = 2 * j - i
            if k >= n:
                continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                # print(i, j, k)
                cnt = cnt + 1

    print(len(R) * len(G) * len(B) - cnt)

if __name__ == '__main__':
    solve()


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

main()
{
    char a,b;
    cin>>a>>b;
    if(a=='H' && b=='H')
        cout<<"H"<<endl;
    else if(a=='H' && b=='D')
        cout<<"D"<<endl;
    else if(a=='D' && b=='H')
        cout<<"D"<<endl;
    else if(a=='D' && b=='D')
        cout<<"H"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    string s; cin >> s;
    int g = 0, p = 0;
    for (char c : s) (c == 'g' ? g : p) += 1;
    cout << (s.size() / 2) - p << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	
	// ll t;
	// cin>>t;
	// while(t--)
	{
	  char c;
	  cin>>c;
	  if(c>='A' && c<='Z')
	  cout<<"A";
	  else
	  cout<<"a";
	
	
	}
	
	
	return 0;
}

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

using namespace std;

#define foorp(i , a , n) for (int (i) = (a); (i) < (n); (i)++)
#define foorm(i , a , n) for (int (i) = (a); (i) > (n); (i)--)
#define ll long long int

ll a[3];

int main()
{
    cin >> a[0] >> a[1] >> a[2];
    sort(a , a + 3);
    if ((a[0] * a[1] * a[2]) % 2 == 0)
        cout << 0;
    else
        cout << a[0] * a[1];

    return 0;
}



Measured memory_bytes: 256
import math
X = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while 1:
    r = is_prime(X)
    if r:
        break
    X += 1
print(X)

Measured memory_bytes: 9028
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using ul = unsigned long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

void out_string(string s, bool d) {
    if (d) {
        rep(i, s.size()) { cout << s[i]; }
    } else {
        rep(i, s.size()) {
            ll index = s.size() - i - 1;
            cout << s[index];
        }
    }
}

int main() {
source:
    string s;
    cin >> s;
    ll q;
    cin >> q;
    bool direction = true;
    string front = "", back = "";
    rep(i, q) {
        ll t;
        cin >> t;
        if (t == 1) {
            direction = !direction;
        } else if (t == 2) {
            ll f;
            cin >> f;
            char c;
            cin >> c;
            if (f == 1) {
                if (direction) {
                    front += c;
                } else {
                    back += c;
                }
            } else if (f == 2) {
                if (direction) {
                    back += c;
                } else {
                    front += c;
                }
            }
        }
    }
    if (direction) {
        out_string(front, false);
        out_string(s, true);
        out_string(back, true);
        cout << endl;
    } else {
        out_string(back, false);
        out_string(s, false);
        out_string(front, true);
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=5){
		printf("0\n");
	} 
	else if(a<=12){
		printf("%d\n",b/2);
	}
	else{
		printf("%d\n",b);
	}
	return 0;
}


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

int main()
{
	int x,y;
	cin >> x >> y;
	 if ((x == 4 ||x == 6||x == 9 || x == 11) 
		&& (y ==4 || y == 6 || y == 9 || y == 11) ){
		cout <<"Yes" << endl;
	}else if ((x == 1 || x == 3 || x== 5
				|| x== 7 || x == 8 ||x == 10 ||x == 12)
				&&(y == 1 || y == 3 || y == 5 
				|| y == 7 || y == 8 ||y == 10 ||y == 12)){
		cout << "Yes" << endl;
	}else if (x == 2 && y == 2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_4_B&lang=jp
# Rotate

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n1 = int(input())
    l1 = list(map(int,input().split()))
    l2 = []
    for i in range(int(input())):
        (b,m,e) = map(int,input().split())   
        for k in range(b):
            l2.append(l1[k])
        for k in range(m,e):
            l2.append (l1[k]) 
        for k in range(b,m):
            l2.append(l1[k])
        for k in range(e,len(l1)):
            l2.append(l1[k])
        l1 = l2
        l2 = []
    print (" ".join(map(str,l1)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6076
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
diffa = [a[i+1] - a[i] for i in range(n+1)]
cost = sum([abs(diffa[i]) for i in range(len(diffa))])
for i in range(n):
    res = cost - abs(diffa[i]) - abs(diffa[i+1])
    res += abs(diffa[i] + diffa[i+1])
    print(res)


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);
ll fre[mx] = {0};

int main() {
    ll n, a, b;
    cin >> n;
    ll s = 0;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        fre[x]++;
        s += x;
    }
    ll q;
    cin >> q;
    while(q--) {
        cin >> a >> b;
        s -=  ((a - b)*fre[a]);
        fre[b] += fre[a];
        fre[a] = 0;
        cout << s << endl;
    }
    return 0;

}




Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    string s;
    cin >> s;
    int p = 0;
    for (i = 0; i < s.size(); i++) {
        if (s[i] == 'p') p++;
    }
    cout << s.size() / 2 - p << endl;
}

Measured memory_bytes: 3728
#include <iostream>

using namespace std;

char sir[105];

int main()
{
    int n;
    cin>>n;
    int a=0;
    int b=0;
    for (int i=1; i<=n; i++){
        cin>>sir[i];
        if (sir[i] == '('){
            a++;
        }
        if (sir[i] == ')' && a>0){
            a--;
            continue;
        }
        if (sir[i] == ')' && a==0){
            b++;
        }
    }
    for (int i=n; i>=1; i--){
        sir[i+b]=sir[i];
    }
    for (int i=1; i<=b; i++){
        sir[i]='(';
    }
    a=0;
    for (int i=1; i<=n+b; i++){
        if (sir[i] == '('){
            a++;
        }
        if (sir[i] == ')'){
            a--;
        }
    }
    for (int i=1; i<=n+b; i++){
        cout<<sir[i];
    }
    for (int i=1; i<=a; i++){
        cout<<')';
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(K: int, X: int):
    if 500*K>=X:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(K, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13268
unittest
{
	assert( [ "3 1", "ABC" ].parse.expand.solve == "aBC" );
	assert( [ "4 3", "CABA" ].parse.expand.solve == "CAbA" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto s = input.front.to!( dchar[] );
	return tuple( nk[ 1 ], s );
}

auto solve( long k, dchar[] s )
{
	s[ k - 1 ] = s[ k - 1 ] - ( 'A' - 'a' );
	return s;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (int b = k + 1; b <= n; b++) {
    ans += n / b * (b - k) + max(0LL, n % b - k + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

#define MAX 200010
long long mod = 1000000007;
long long inv[MAX],fact[MAX],fi[MAX];

void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
}

void factinv(){
	int i;
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

long long comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

long long pow(long long a,long long b){
	if(b==0){
		return 1;
	}else{
		if(b%2==0){
			return pow(a,b/2)*pow(a,b/2)%mod;
		}else{
			return pow(a,b/2)*pow(a,b/2)%mod*a%mod;
		}
	}
}
long long i,j,k,n,a,b,c,d,dp[1010][1010];
int main(){
	cin >> n >> a >> b >> c >> d ;
	for(i=1;i<=n;i++){
		dp[a-1][i] = 0;
	}
	dp[a-1][0] = 1;
	inverse(); factinv();
	for(i=a;i<=b;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = dp[i-1][j];
			for(k=c;k*i<=j && k<=d ;k++){
				dp[i][j] += fact[n+k*i-j]*fi[n-j]%mod*pow(fi[i],k)%mod*fi[k]%mod*dp[i-1][j-k*i]%mod;
				dp[i][j] = dp[i][j]%mod;
			}
		}
	}
	cout << dp[b][n] << endl;
}

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

int main()
{
  int N, M;
  cin >> N;
  vector<int > T(N);
  int sum = 0;
  for(int i = 0;i < N; i++){
    cin >> T.at(i);
    sum += T.at(i);
  }
  
  cin >> M;
  vector<int > P(M), X(M);
  for(int i = 0;i < M; i++){
    cin >> P.at(i) >> X.at(i);
  }
  for(int i = 0; i < M;i ++){
    cout << sum - T.at(P.at(i) - 1) + X.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n, m, c,t,ans=0;
	cin >> n >> m >> c;
	vector<int>vec(m);
	vector<vector<int>>vec1(n, vector<int>(m));
	vecin(vec);
	rep(i, n) {
		rep(j, m) {
			cin >> vec1[i][j];
		}
	}
	rep(i, n) {
		t = 0;
		rep(j, m) {
			t += vec1[i][j] * vec[j];
		}
		t += c;
		if (t > 0) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1200000000

using namespace std;

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

int main() {
    LL n, z, w;
    cin >> n >> z >> w;

    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());

    LL ans = 0;
    if (n == 1) {
        ans = abs(a[0] - w);
    } else {
        ans = max(abs(a[1] - a[0]), abs(w - a[0]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

if abs(A-B) % 2 == 0:
    print(abs(A-B)//2)

else:
    ans1 = min(A, B) + (max(A, B)-min(A, B)-1)//2
    ans2 = N-max(A, B)+1 + (N-min(A, B) - (N-max(A, B)) -1)//2
    print(min(ans1, ans2))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstdio>
#include <numeric>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)

#define ii(n) int n; cin>>n;
#define vi(v,n) vector<int> v(n); REP(i,n) cin>>v[i];
#define ss(x) string x; cin>>x;
#define sl(x) char x[]; string y; cin>>y; x=c_str(y);

#define iout(n) cout<<n<<endl;
#define sout(s) cout<<s<<endl;
#define vmin(v) *std::min_element(v.begin(), v.end())
#define vmax(v) *std::max_element(v.begin(), v.end())
#define vave(v) 1.*accumulate(v.begin(), v.end(), 0) / v.size()

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


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

	ss(x)
	int cur=0;
	bool flag=false;
	while (cur<=x.size()-1 && x.size()!=0){
	    if(flag){
	        if (x[cur]=='T'){
	            flag=false;
	            x.erase(x.begin()+cur-1);
	            x.erase(x.begin()+cur-1);
	            cur-=2;
	            if (cur<0){
	                cur=0;
	            }
	        }else{
	            cur+=1;
	        }
	    }else{
	        if (x[cur]=='S'){
	            flag=true;
	            cur+=1;
	        }else{
	            cur+=1;
	        }
	    }
	}
	iout(x.size())








	return 0;
}


Measured memory_bytes: 1336
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	string s; cin >> s;
	int K; cin >> K;
	int N = s.size();
	rep(i,N){
		int d = 'z'-s[i]+1;
		if(s[i] != 'a' && d <= K){
			s[i] = 'a';
			K -= d;
		}
	}
	K %= 26;
	s[N-1] = s[N-1]+K;
	cout << s << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
#include<type_traits>
using namespace std;

int main() {
	long long int N,a,b,c;
	a = 100000000000;
	b = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> c;
		a = min(a, c);
		b = max(b, c);
	}
	cout << b - a << endl;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, l;
    cin >> n >> l;
    vector<i64> a(n);
    for (auto& e : a) cin >> e;

    i64 idx = adjacent_find(all(a), [&](i64 x, i64 y) { return x + y >= l; }) - begin(a);
    if (idx == n) {
        cout << "Impossible" << endl;
        return;
    }

    cout << "Possible" << endl;
    for (i64 i = 0; i < idx; i++) cout << i + 1 << endl;
    for (i64 i = n - 2; i > idx; i--) cout << i + 1 << endl;
    cout << idx + 1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

int main(){
	int n;
	while(cin >> n, n){
		vector<vector<int> > vvi;
		vector<int> vi;
		for(int i = 0; i < n; i++){
			int k;
			cin >> k;
			vi.push_back(k);
		}
		vvi.push_back(vi);
		int cnt = 0;
		do{
			vi.clear();
			for(int i = 0; i < vvi[cnt].size(); i++){
				vi.push_back(count(vvi[cnt].begin(), vvi[cnt].end(), vvi[cnt][i]));
			}
			vvi.push_back(vi);
			cnt++;
		}while(vvi[cnt] != vvi[cnt-1]);

		cout << cnt-1 << endl;
		for(int i = 0; i < vvi[cnt].size(); i++){
			if(i){
				cout << ' ';
			}
			cout << vvi[cnt][i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 1000;

struct Edge {
  int f, t;
  ll c;

  Edge(int f, int t, ll c): f(f), t(t), c(c) {}

  bool operator < (const Edge& e) const {
    return (f != e.f ? f < e.f : t < e.t);
  }
};

int n, m;

vector<Edge> e;
vector<ll> d(MAX, INF);

void Bellmanford() {
  d[0] = 0;
  bool negative = false;
  rep(i, 2 * n) {
    rep(j, m) {
      if (d[e[j].f] == INF) continue;
      if (d[e[j].f] + e[j].c < d[e[j].t]) {
        if (e[j].t == n - 1 && i == 2 * n - 1) negative = true;
        d[e[j].t] = d[e[j].f] + e[j].c;
      }
    }
  }
  if (negative) cout << "inf" << endl;
  else cout << -d[n - 1] << endl;
}

int main() {
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    e.push_back(Edge(a - 1, b - 1, -c));
  }

  sort(e.begin(), e.end());

  Bellmanford();



  
  return 0;
}


Measured memory_bytes: 256
// abc161_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;

    ll x = N % K;
    ll ans = min(x, K - x);

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;
int main() {
	int f = 0, n = 0, N,a;
	bool t = false;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		if (a % 4 == 0)f++;
		else if (a % 2 == 0)t = true;
		else n++;
	}
	if (t)n++;
	cout << (((f + 1) >= n )? "Yes" : "No");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

typedef double re;
const int MN = 3005;
const re PI = acos(-1);

int N, l, t[MN];
re Ansx, Ansy;

int main() {
	scanf("%d%d", &N, &l);
	for (int i = 1; i <= N; ++i) scanf("%d", &t[i]);
	for (int i = 1; i < N; ++i) {
		for (int j = i + 1; j <= N; ++j) {
			re Ax = cos(PI * (t[i] + t[j]) / l);
			re Ay = sin(PI * (t[i] + t[j]) / l);
			Ansx += Ax * (N - 2 * (j - i));
			Ansy += Ay * (N - 2 * (j - i));
		}
	}
	re iCN3 = 6. / N / (N - 1) / (N - 2);
	printf("%.15lf %.15lf\n", Ansx * iCN3, Ansy * iCN3);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

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

void solve(std::string S){
    set<char> a;
    rep(i,3){
        a.insert(S[i]);
    }
    if(a.count('a')&&a.count('b')&&a.count('c'))
        cout << YES << endl;
    else 
        cout << NO << endl;

}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return x;}

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

UnionFind uf;

int main() {
	int n,I;
	cin >> n >> I;
	cout << n - I + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n , k;
    cin>>n>>k ;
    int arr[n] , dp[n];
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i];
    for(int i = 0 ; i < n ; ++i)
        dp[i] = 1e9+5 ;
    dp[n-1] = 0 ;
    for(int j = n-2 ; j >= 0 ; --j)
    {
        for(int i = 1 ; i <= k ; ++i)
        {
            if(j+i >= n)
                break;
            dp[j] = min(dp[j] , dp[j+i] + abs(arr[j] - arr[j+i]));
        }
    }
    return cout<<dp[0]<<"\n" , 0 ;
}


Measured memory_bytes: 1024
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]

cnt = 0

for i in range(n):
    nai = 0
    for j in range(m):
        nai += a[i][j]*b[j]
    if nai+c>0:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <stdint.h>

using namespace std;

#define MAX 100000
static uint64_t counts[MAX];

int32_t main()
{
  int64_t N, K;
  cin >> N >> K;

  for (int32_t i = 0; i < N; i++) {
    uint32_t a, b;
    cin >> a >> b;
    counts[a - 1] += b;
  }

  for (int32_t i = 0; i < MAX; i++) {
    K -= counts[i];
    if (K <= 0) {
      cout << i + 1 << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace	std;
typedef	long long ll;
int main() {
  ll X;	cin>>X;
  ll v = 100;
  for(int i = 1; ; i++) {
    v += (v / 100LL);
    if(v >= X) {
      cout << i	<< endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <list>

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

    int Q;
    std::cin >> Q;
    std::list<int> v;
    auto itr = v.end();
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int x;
            std::cin >> x;
            itr = v.insert(itr, x);
        } else if (t == 1) {
            int d;
            std::cin >> d;
            while (d > 0) {
                ++itr;
                --d;
            }
            while (d < 0) {
                --itr;
                ++d;
            }
        } else {
            itr = v.erase(itr);
        }
    }

    for (int e : v) std::cout << e << "\n";
    return 0;
}



Measured memory_bytes: 18552
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;


template <typename T> class LazySegmentTree {

private:

    int n;
    vector < bool > flag;
    vector < T > node, lazy;
    const T INF = numeric_limits<T>::max() / 2;
    
    void  lazy_eval (int l, int r, int k) {
        if (flag[k]) {
            node[k] = lazy[k];
            flag[k] = false;
            if (r - l > 1) {
                lazy[2 * k + 1] = lazy[k];
                lazy[2 * k + 2] = lazy[k];
                flag[2 * k + 1] = true;
                flag[2 * k + 2] = true;
            }
        }
    }
    
    void _update (int a, int b, T val, int k, int l, int r) {
        lazy_eval(l, r, k);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = val;
            flag[k] = true;
            lazy_eval(l, r, k);
        } else {
            _update (a, b, val, 2 * k + 1, l, (l + r) / 2);
            _update (a, b, val, 2 * k + 2, (l + r) / 2, r);
            node[k] = min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    T _get_min (int a, int b, int k, int l, int r) {
        lazy_eval (l, r, k);
        if (b <= l || r <= a) return INF;
        if (a <= l && r <= b) return node[k];
        T vl = _get_min (a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _get_min (a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
    
public:
    
    LazySegmentTree (int _n) : n(1) {
        while (n < _n) n <<= 1;
        node.resize (2 * n, INF);
        lazy.resize (2 * n, INF);
        flag.resize (2 * n, false);
    }
    
    void update (int l, int r, T val) {
        _update (l, r, val, 0, 0, n);
    }
    
    T get_min (int l, int r) {
        return _get_min (l, r, 0, 0, n);
    }
    
};

int main() {
    
    int n,q; cin >> n >> q;
    
    LazySegmentTree < ll > inst(100010);
    
    const ll INF = numeric_limits<ll>::max() / 2;
    
    REP(i,q) {
        int a,l,r;
        cin >> a;
        if (a == 0) {
            int l,r;
            cin >> l >> r;
            ll x; cin >> x;
            inst.update(l, r + 1, x);
        } else {
            int i; cin >> i;
            ll ans = inst.get_min(i, i + 1);
            if (ans == INF) {
                cout << ((1LL << 31LL) - 1LL) << endl;
            } else {
                cout << ans << endl;
            }
        }
    }

    return 0;
}





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

int main(void) {
    int A, B, T;
    cin >> A >> B >> T;

    int ans=0;
    for(int i=A;i<=T;i+=A){
        ans+=B;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int read()
{
	char c=getchar();int x=0,f=1;
	while(c>'9'||c<'0'){if(c='-'){f=-1;}c=getchar();}
	
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
int main()
{cin>>a>>b;
	cout<<(a+b)%24<<endl;
	return 0;
	
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<long long>> v(n, vector<long long>(3));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> v[i][j];
        }
    }
    long long ans = -1e16;
    for (int i = -1; i < 2; i += 2) {
        for (int j = -1; j < 2; j += 2) {
            for (int k = -1; k < 2; k += 2) {
                vector<long long> vv(n);
                for (int l = 0; l < n; ++l) {
                    vv[l] = v[l][0] * i + v[l][1] * j + v[l][2] * k;
                }
                sort(vv.begin(), vv.end());
                reverse(vv.begin(), vv.end());
                long long sum = 0;
                for (int l = 0; l < m; ++l) {
                    sum += vv[l];
                }
                ans = max(ans, sum);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,a,b,c;cin>>N;
  vector<int> A(N),B(N),C(N);
  REP(i,0,N){
    cin>>a;
    a--;
    A[i]=a;
  }
  REP(i,0,N){
    cin>>b;
    B[i]=b;
  }
  REP(i,0,N-1){
    cin>>c;
    C[i]=c;
  }
  int pre=-10,ans=0;
  REP(i,0,N){
    ans+=B[A[i]];
    if((pre+1)==A[i])ans+=C[pre];
    pre=A[i];
  }
  print(ans)
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N,A,B; cin >> N >> A >> B;
    if(N==1){
        if(A == B) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else cout << max((ll)0, (N-1)*B+A - (N-1)*A-B + 1) << endl;
    return 0;
}

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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < (int)s.size(); ++i)
        if (s[i] != t[i])
            ++count;

    cout << count << endl;
}

Measured memory_bytes: 3916
c = 0
while True:
    c += 1
    n = raw_input()
    if n == "0":
        break
    l = []
    for i in xrange(int(n)):
        l.append(map(float, raw_input().split()))
    raw_input()
    a = 0
    tmp = l[-1]
    for i in l:
        a += (i[1]+tmp[1])*(i[0]-tmp[0])/2.0
        tmp = i
    print "{0} {1}".format(c, a)

Measured memory_bytes: 4260
import sys
import copy
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


H, W, K = LI()
c = []
for i in range(H):
    tmp_l = S()
    c.append([1 if c == "#" else 0 for c in tmp_l])


num_pattern = 0
for h in range(2 ** H):
    format_str = "{:0" + str(H) + "b}"
    h_update = [c == "1" for c in reversed(format_str.format(h))]

    for w in range(2 ** W):
        format_str = "{:0" + str(W) + "b}"
        w_update = [c == "1" for c in reversed(format_str.format(w))]
        # print(h_update, w_update)

        cc = copy.deepcopy(c)
        for i, flag in enumerate(h_update):
            if flag:
                cc[i] = [0 for _ in range(W)]
        for i, flag in enumerate(w_update):
            if flag:
                for j in range(H):
                    cc[j][i] = 0

        total = sum([sum(cc[i]) for i in range(H)])
        if total == K:
            num_pattern += 1

print(num_pattern)

Measured memory_bytes: 9132
#include <iostream>

using namespace std;

int main(void) {
  int R;
  cin >> R;

  if(R < 1200){
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll h,w;
    while(true){
        cin>>h>>w;
        if(h==0&&w==0)return 0;
        REP(i,h){
            REP(j,w)cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3092
object Main extends App {
  val Seq(n,q): Seq[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
  val ds = new DisjointSets(n)
  (0 until q) foreach {_ =>
    io.StdIn.readLine().split(" ").map(_.toInt) match {
      case Array(0, x, y) => ds.union(x, y)
      case Array(1, x, y) => println(if (ds.same(x,y)) 1 else 0)
    }
  }
}
class DisjointSets(size: Int) {
  val parent: Array[Int] = Array.tabulate(size)(i => i)
  val rank: Array[Int] = Array.fill(size)(0)
  def union(x: Int, y: Int): Unit = {
    val i = find(x)
    val j = find(y)
    if (rank(i) > rank(j)) parent(j) = i
    else {
      parent(i) = j
      rank(i) += (if (rank(i) == rank(j)) 1 else 0)
    }
  }
  def find(x: Int): Int = parent(x) match {
    case p if x == p => x
    case p =>
      val i = find(p)
      parent(x) = i
      rank(x) = 0
      i
  }
  def same(x: Int, y: Int):Boolean = find(x) == find(y)
}

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

typedef long long ll;
#pragma GCC optimize ("Ofast")
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 1000000007
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    ll n, d;
    cin >> n >> d;
    if(n <= 1+2*d) {cout << 1 << endl;return 0;}
    int cnt = 0;
    int last = 0;
    for(int i = d+1; i+d <= n; i+=2*d+1){
        cnt++;
        last = i+d;
    }
    if(last < n) cnt++;
    cout << cnt << endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int a = A+B , b = C+D;
  
if ( a > b ) {
  cout << " Left " << endl;
}
else if (a < b) {
  cout << " Right " << endl;
}
else {
  cout << " Balanced " << endl;
}
}

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

using namespace std;

int main()
{
    vector<int> a(3);
    for(int i=0;i<3;i++) cin >> a[i];

    int ans=0;
    sort(a.begin(),a.end());
    for(int i=1;i<3;i++){
        ans+=abs(a[i]-a[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, h;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> h;
  priority_queue<P> que;

  REP(i, n) {
    int a, b;
    cin >> a >> b;

    que.push(P(a, 0));
    que.push(P(b, 1));
  }

  int sum = 0, ans = 0;
  while(!que.empty() && sum < h) {
    P p = que.top(); que.pop();
    if(p.second == 1) {
      sum += p.first;
      ans++;
    } else {
      while(sum < h) {
        sum += p.first;
        ans++;
      }
    }
  }

  cout << ans << endl;
}


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

//vector<vector<pair<int, int>>> g(1e5);

//void dfs ( int now, int prev, vector<int>& color, int col ) {
void dfs (vector<vector<pair<int, int>>>& g, int now, int prev, vector<int>& color, int col ) {
    color[now] = col;
    for ( auto tmp_num : g[now] ) {
        if ( tmp_num.first != prev ) {
//            dfs(tmp_num.first, now, color, col ^ ( tmp_num.second&1) );
            dfs(g, tmp_num.first, now, color, col ^ ( tmp_num.second&1) );
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> g(n);
    rep(i, n-1) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        --u, --v;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    vector<int> color(n, 1e8);
//    dfs(0, -1, color, 0);
    dfs(g, 0, -1, color, 0);
    rep(i, color.size()) {
        cout << color[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9728
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x in (1,n-1):continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:d,s = d>>1,s+1
        return maybe_prime(d,s,n)

cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Measured memory_bytes: 7772
n,x=map(int,input().split())

bp=[]
h=[]
for i in range(n+1):
    bp.append([2**(i+1)-2,2**(i+1)-1])
    h.append(2**(i+2)-3)


p=0
while x!=0:
    if n==0:
        p+=1
        x=0
    elif x<=h[n-1]+1:
        x=x-1
    elif x==h[n-1]+2:
        p+=1
        x=x-2
    elif x<=2*h[n-1]+2:
        p+=bp[n-1][1]+1
        x=x-h[n-1]-2
    else:
        p+=2*bp[n-1][1]+1
        x=0
    n=n-1

print(p)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
typedef long long int ll;

int main(void){
	ll N, K, cnt = 0, loop = 0, current = 1, kaho = 1;
	std::cin >> N >> K;
	std::vector<int> A(N+1, 0), cnt_a(N+1, 0);
	for(ll i = 1; i <= N; i++) std::cin >> A[i];

	if(K <= N){
		for(ll i = 0; i < K; i++){
			current = A[current];
		}
		std::cout << current << std::endl;
	} else {
		for(ll i = 1; i <= N; i++){
			cnt_a[current]++;
			if(cnt_a[current] == 2){
				kaho = current;
				break;
			}
			current = A[current];
			cnt++;
		}
		// std::cout << cnt << " " << kaho << std::endl;
		
		current = kaho;
		for(ll i = 1; i <= N; i++){
			cnt_a[current]++;
			if(cnt_a[kaho] == 4) break;
			loop++;
			current = A[current];
		}

		// std::cout << loop << " " << (K-cnt)%loop << std::endl;
		current = 1;
		for(ll i = 1; i <= cnt + (K-cnt) % loop; i++) current = A[current];
		std::cout << current << std::endl;
	}
}


Measured memory_bytes: 4820