akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    map<string,int> M;
    
    int n;
    cin>>n;
    
    int maxx=0;
    
    for(int i=0; i<n; i++)
    {
        string s;
        cin>>s;
        
        M[s]++;
        maxx=max(maxx,M[s]);
    }
    
    vector<string> ans;
    
    for(auto m:M) if(m.second==maxx) ans.push_back(m.first);
    
    sort(ans.begin(),ans.end());
    for(auto a:ans) cout << a << endl;
}

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

bool ch(int two, vector<int> v){
    if(v[two] < 2)  return false;
    v[two] -= 2;
    for(int i = 0; i < 9; i++){
        if(v[i] >= 3)   v[i] -= 3;
        while(i <= 6 && v[i] && v[i+1] && v[i+2]) v[i]--, v[i+1]--, v[i+2]--;
        if(v[i])    return false;
    }
    return true;
}

bool check(vector<int> v){
    for(int i = 0; i < 9; i++){
        if(ch(i, v))    return true;
    }
    return false;
}

int main(){
    string s;
    while(cin >> s){
        vector<int> v(9, 0);
        for(char x : s) v[x-'1']++;
        
        vector<int> res;
        for(int i = 0; i < 9; i++){
            if(v[i] >= 4)   continue;
            v[i]++;
            if(check(v))    res.push_back(i+1);
            v[i]--;
        }
        if(res.size() == 0) res.push_back(0);
        
        for(int i = 0; i < res.size(); i++) cout << res[i] << " \n"[i == res.size()-1];
    }

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;cin>>n;
  bool f=true,ff=false;
  vector<int> x(n+1);
  for(int i=1;i<=n;++i)cin>>x[i];

  while(f){
    f=false;
    for(int i=n;i>0;--i){
      if(x[i]!=0&&x[i-1]==0)c++;
      x[i]=max(0,x[i]-1);
    }
    for(int i=1;i<=n;++i){
      if(x[i]!=0)f=true;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int now = 0, ov = 0;
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    rep(i, 0, s.size()){
        if(s[i] == 'a'){
            now++;
            cout << (now <= (a + b) ? "Yes" : "No") << endl;
        }
        if(s[i] == 'b'){
            ov++;
            if(ov <= b){
                now++;
            }
            cout << ((now <= (a + b) && ov <= b) ? "Yes" : "No") << endl;
        }
        if(s[i] == 'c'){
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 848
class UnionFind: # simple
    def __init__(self, n):
        self.prsz = [-1] * n # parent ' size
    def find(self, v): # root
        if self.prsz[v] < 0: return v
        else:
            self.prsz[v] = self.find(self.prsz[v])
            return self.prsz[v]
    def union(self, v, u): # unite
        v = self.find(v); u = self.find(u)
        if v == u: return False
        if self.g_size(v) < self.g_size(u): v, u = u, v
        self.prsz[v] += self.prsz[u]
        self.prsz[u] = v
        return True
    def g_size(self, v): return -self.prsz[self.find(v)]

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m): uf.union(*map(lambda x: int(x)-1, input().split())) # unite
ans = 0
for i in range(n): ans = max(ans, uf.g_size(i))
print(ans)


Measured memory_bytes: 14696
package main

import (
  "fmt"
)

func main() {
  var x, a, b int
  
  fmt.Scanf("%d %d %d", &x, &a, &b)
  
  if a >= b{
    fmt.Printf("delicious")
  }else if a + x >= b{
    fmt.Printf("safe")
  }else{
    fmt.Printf("dangerous")
  }
}

Measured memory_bytes: 1832
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
lld gcd(lld a, lld b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lld a,b;
	cin >> a >> b;
	lld gc = gcd(a,b);
	lld lc = (a*b)/gc;
	cout << lc;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1){cout<<1;return 0;}
    cout<<(h*w+1)/2;
    return 0;
}

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

int main() {
  ll n,ans=0;
  cin >> n;
  for(ll i = 1; i < (n+1); i++) {
    if (i % 15) {
      if (i % 3) {
        if (i % 5) {
          ans += i;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int n, m;

int main() {
	while(scanf("%d %d", &n, &m) != EOF) {
		int ans = 0;
		if(m % n == 0) ans = m / n;
		else {
			int t = m / n;
			for(int i = 1; i <= t; i++) {
				if(m % i == 0 && m / i >= n) ans = max(ans, i);
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans=0,a=0,b=0,c=0;
  string s;
  for(int i=0;i<n;i++){
    cin >> s;
    int l=s.size();
    for(int j=0;j<l;j++){
      if(s[j]=='A'&&s[j+1]=='B'){
        ans++;
        j++;
      }
    }
    if(s[0]=='B'&&s[l-1]=='A')a++;
    else if(s[0]=='B')b++;
    else if(s[l-1]=='A')c++;
  }
  ans+=(a?(b+c)?(a+min(b,c)):(a-1):min(b,c));
  cout << ans << endl;
  return 0;
}

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

    int n, x;
    cin >> n >> x;
    vector<int> y(n+1);
    rep(i, n) cin >> y[i];

    y[n] = x;
    sort(y.begin(), y.end());

    vector<int> v(n);
    rep(i, n){
        v[i] = y[i+1] - y[i];
    }

    int ans = v[0];
    rep(i, n){
        ans = min(ans, v[i]);
    }

    bool check = true;
    for(int i=ans; i>=1; i--){
        check = true;
        rep(j, n){
            if(v[j] % i != 0){
                check = false;
            }
        }
        if(check){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ld a,b; cin >>a >>b;
	cout <<(ll)(a*b);
	return 0;
}
/******************************************************************************
******************************************************************************/


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

int main(){
    int n,a;
    cin >> n >> a;
    if(n%500 <= a) cout << "Yes ";
    else cout << "No ";
    
    return 0;
}


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

using namespace std;
int a[1080], b[1080];
int n, m;
int main(){
	while(cin >> n >> m, n | m){
		int asum = 0, bsum = 0;
		for(int i = 0;i < n;i++)cin >> a[i], asum += a[i];
		for(int i = 0;i < m;i++)cin >> b[i], bsum += b[i];
		int aans = -1, bans;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(asum - bsum == 2 * (a[i] - b[j])){
					if(aans == -1 || aans + bans > a[i] + b[j]){
						aans = a[i];
						bans = b[j];
					}
				}
			}
		}
		if(aans == -1)
			cout << -1 << endl;
		else
			cout << aans << " "<< bans << endl;	
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[(int)((s).size())-1]
#define prelast(s) (s)[(int)((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza
//#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
//#define time chas
#define y0 lolik
#define x1 ashkjl
#define y1 fakakaka
#define y2 ololol
#define x2 jejejejej
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("robot.in", "r", stdin);freopen("robot.out", "w", stdout);
#define ref svyazi
// #define int long long
#define lint __int128
#define ii pair<int, int>
#define llong long long
#define ld long double
#define list spisok
#define tm kozerog
    
    
const ld eps = 1e-9;
const ld Pi = acos(-1);
const int md = (1e9+7);
// const int fakmd = 998244353;
// const int mod = (1 << 30) + 1;

using namespace std;
//using namespace __gnu_cxx;

/*

*/
int32_t main() {
    kchay;
    // files;
    int n, k;
    cin >> n >> k;
    
    n = (n + 1) / 2;
    
    if(n >= k)cout << "YES"; else cout << "NO";
    return 0;
}

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

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> score(N);
  int t;
  for (int i = 0; i < Q; i++){
    cin >> t;
    score.at(t-1) += 1;
  }
  for (int i = 0; i < N; i++){
    if (score.at(i) - Q + K >= 1){
      cout << "Yes\n";
    }
    else{
      cout << "No\n";
    }
  }
}

Measured memory_bytes: 1024
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
for i in range(1, N-1):
    diff = max(A[i] + A[i-1] - x, 0)
    ans += diff
    if diff > 0:
        if diff > A[i]:
            A[i-1] -= diff - A[i]
            A[i] = 0
        else:
            A[i] -= diff

ans += max(0, A[-1] + A[-2] - x)

print(ans)


Measured memory_bytes: 63856
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<int>());
    bool can = true;
    if (s.size() < t.size()) {
        REP(i, s.size()) {
            if (s.at(i) < t.at(i)) {
                break;
            }
            if (s.at(i) == t.at(i)) {
                continue;
            }
            if (s.at(i) > t.at(i)) {
                can = false;
                break;
            }
        }
    } else {
        REP(i, t.size()) {
            if (s.at(i) < t.at(i)) {
                break;
            }
            if (s.at(i) == t.at(i)) {
                if (i == t.size() - 1) {
                    can = false;
                }
                continue;
            }
            if (s.at(i) > t.at(i)) {
                can = false;
                break;
            }
        }
    }
    if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a= sc.nextInt(),   b= sc.nextInt();

		String s = a<b? "<":
				   a>b? ">": "==";

		System.out.println("a " + s + " b");
	}
}

Measured memory_bytes: 26356
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  string s;
  cin>>n>>s>>k;
  for(int i=0;i<n;i++){
    if(s[k-1]==s[i]){
      cout<<s[i];
    }else{
      cout<<"*";
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
def binary_search(cond, left_initial, right_initial):

    left = left_initial
    right = right_initial

    while left + 1 < right:
        mid = (left + right) // 2

        if cond(mid):
            right = mid
        else:
            left = mid

    return left


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def solve_e(n, p_list):
    ind_list = [0] * (n + 1)
    for i in range(n):
        ind_list[p_list[i]] = i + 1

    bit = Bit(n + 1)

    res = 0

    for i in range(n, 0, -1):
        ind = ind_list[i]
        bit.add(ind, 1)
        # right
        r1 = n + 1
        r2 = n + 1
        if bit.sum(n + 1) - bit.sum(ind) > 0:
            r1 = binary_search(lambda k: bit.sum(k) - bit.sum(ind) >= 1, ind, n + 1) + 1
        if bit.sum(n + 1) - bit.sum(ind) > 1:
            r2 = binary_search(lambda k: bit.sum(k) - bit.sum(ind) >= 2, ind, n + 1) + 1

        # left
        l1 = 0
        l2 = 0
        if bit.sum(ind) >= 2:
            l1 = binary_search(lambda k: bit.sum(ind) - bit.sum(k) <= 1, 0, ind) + 1
        if bit.sum(ind) >= 3:
            l2 = binary_search(lambda k: bit.sum(ind) - bit.sum(k) <= 2, 0, ind) + 1
        # print(l1, l2, r1, r2, ind, i)
        cnt = (ind - l1) * (r2 - r1) + (l1 - l2) * (r1 - ind)
        res += cnt * i

    return res


def main():
    n = int(input())
    p_list = list(map(int, input().split()))
    print(solve_e(n, p_list))


if __name__ == "__main__":
    main()


Measured memory_bytes: 63008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const ld Pi=acos(-1);
int nature(ll a){
  if(a>=0){return a;}
  else{return 0;}
}
vector<long long> fact, fact_inv, inv;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(ll SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
ll nCk(ll n,ll k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}
int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  vector<ll> vec(N);
    for(ll i=0;i<N;i++){
      cin>>vec.at(i);  
    }
  sort(vec.begin(),vec.end());
  if(K==1){cout<<0<<endl;}
  else{
    init_nCk(1000000);
  //for(ll i=0;i<N;i++){
    //vec.at(i)
    //if(i>=K-1){
    for(ll i=K-1;i<N;i++){
      ans+=vec.at(i)*nCk(i,K-1)%MOD;
      ans=(ans+MOD)%MOD;
      //cout<<ans<<endl;
    }
    //}
    //if(i<=N-K){
    for(ll i=N-K;i>=0;i--){
      ans-=vec.at(i)*nCk(N-i-1,K-1)%MOD;
      ans=(ans+MOD)%MOD;
    }
    //}
    cout<<ans<<endl;
    //cout<<nCk(10,2);
  }
}

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

int main(){
    int n;
    long int tmp,memo,rec;
    vector <long int> leaf;
    vector <long int>::iterator itr;
    while(cin >> n,n){
        for(int i=0;i<n+1;i++){
            cin >> tmp;
            leaf.push_back(tmp);
        }
        for(itr=leaf.begin();itr!=leaf.end();itr++){
            bool ju = true;
            memo = (*itr);
            itr = leaf.erase(itr);
            rec = leaf[1] - leaf[0];
            for(int i=2;i<n;i++){
                if(rec == leaf[i] - leaf[i-1]) ju = true;
                else{
                    ju = false;
                    break;
                }
            }
            if(ju){
                cout << memo << endl;
                leaf.clear();
                break;
            }
            leaf.insert(itr,memo);
        }
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll N;
  cin >> N;
  ll ans = 1e13, tmp = 0;
  ll j;
  for (ll i = 1; i <= sqrt(N); i++)
  {
    if (N % i == 0)
    {
      j = N / i;
      tmp = i + j - 2;
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n, greater<int>());

    int alice = 0, bob = 0;

    rep(i, n) {
        if (i % 2 == 0)
            alice += a[i];
        else
            bob += a[i];
    }

    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import permutations
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

def d(p1,p2):
    return sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)
    

res = 0.0
cnt = 0
for p in permutations(range(n), n):
    cnt += 1
    for i in range(n-1):
        res += d(xy[p[i]],xy[p[i+1]])

print(res/cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;
int k;
int n,m,x,ans=INF;
int a[211111];
int f[211111];
vector<int> v,v2;
signed main(){
	cin>>n>>k;
	rep(i,n){
		cin>>a[i];
		a[i]--;
	}
	int now=0;f[0]=1;int fini;
	v.push_back(0);
	while(true){
		now=a[now];
		if(f[now]){
			fini=now;
			break;
		}
		f[now]=1;
		v.push_back(now);
	}
	int finif=0;
	rep(i,v.size()){
		if(v[i]==fini)finif=1;
		if(finif)v2.push_back(v[i]);
	}
	int fcnt=0,scnt=0,mode=0;
	rep(i,v.size()){
		if(mode==0){
			fcnt++;
			if(i==v.size()-1)continue;
			if(v[i+1]==fini){
				mode=1;
			}
		}
		else{
			scnt++;
		}
	}//cout<<fcnt<<" "<<scnt<<endl;
	//cout<<v.size()<<endl;
	
	//rep(i,v.size())cout<<v[i]+1<<" ";cout<<endl;
	
	if(fcnt>k){
		cout<<v[k]+1<<endl;
		return 0;
	}
	
	k-=fcnt;
	k++;
	if(scnt==0){
		k%=fcnt;
		if(k==0)cout<<v2[fcnt-1]+1<<endl;
		else cout<<v2[k-1]+1<<endl;
		return 0;
	}
	k%=scnt;
	
	
	//cout<<endl;
	//cout<<k<<endl;
	if(k==0)cout<<v2[scnt-1]+1<<endl;
	else cout<<v2[k-1]+1<<endl;
	
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 200
#define INF 1125899906842624
i64 d[MAX_N][MAX_N];

int main() {
    i64 N, M, R; cin >> N >> M >> R;
    vector<i64> seq(R);
    REP(i, R) {
        cin >> seq[i];
        seq[i]--;
    }
    sort(seq.begin(), seq.end());

    REP(i, N) REP(j, N) {
        if (i == j) d[i][j] = 0;
        else {
            d[i][j] = INF;
            d[j][i] = INF;
        }
    }
    REP(i, M) {
        i64 u, v, c; cin >> u >> v >> c;
        u--, v--;
        d[u][v] = c;
        d[v][u] = c;
    }

    REP(k, N) {
        REP(i, N) {
            REP(j, N) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    i64 minc = numeric_limits<i64>::max();
    do {
        i64 sc = 0;
        for (i64 i = 1; i < R; i++) {
            sc += d[seq[i - 1]][seq[i]];
        }
        chmin(minc, sc);
    } while (next_permutation(seq.begin(), seq.end()));

    cout << minc << endl;

    return 0;
}

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

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

    int x, min = 1000;
    for(int i=0;i<s.length()-2;i++) {
        x = (s[i]-'0')*100 + (s[i+1]-'0')*10 + s[i+2]-'0';
        if(753-x>=0 && min>753-x) {
            min = 753 - x;
        }
        if(x-753>=0 && min>x-753) {
            min = x - 753;
        }
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
def f_a():
    s, k = input(), int(input())
    l, c = [], 1
    for i in range(1, len(s)):
        if s[i-1]==s[i]:
            c += 1
        else:
            l.append(c)
            c = 1
    if len(l)==0 or c>1:
        l.append(c)
    if len(l)>1:
        o = sum(map(lambda x: x//2*k, l[1:-1]))
        fe = l[0]//2+l[-1]//2
        if s[0]==s[-1]:
            o += fe+(l[0]+l[-1])//2*(k-1)
        else:
            o += fe*k
    else:
        o = l[0]*k//2
    print(o)

if __name__ == "__main__":
    f_a()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;

    return 0;
}


Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC088BCardGameForTwo solver = new ABC088BCardGameForTwo();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC088BCardGameForTwo {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] a = IntStream.range(0, in.nextInt()).map(x -> in.nextInt()).sorted().toArray();
            int ans = 0;
            for (int i = 0; i < a.length; i++) {
                if (i % 2 == 0) {
                    ans += a[a.length - i - 1];
                } else {
                    ans -= a[a.length - i - 1];
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 26964
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, q;
ll a[500009], b[500009];

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

    cin >> n >> a[0];
    FOR(i, 1, n + 1) cin >> a[i];

    b[n] = 1;
    for(int i = n - 1; i; i--) {
        b[i] = b[i + 1];
        if(abs(b[i] - a[i + 1]) < b[i]) b[i] += a[i + 1];
    }
    FOR(i, 1, n + 1) a[i] = min(a[i - 1], abs(a[i - 1] - a[i]));

    cin >> q;
    while(q--) {
        int x;
        cin >> x;
        cout << (a[x - 1] >= b[x] ? "YES" : "NO") << "\n";
    }

    return 0;
}

Measured memory_bytes: 9728
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAXN (100001)

ll n;
vector<vector<ll>> g(MAXN, vector<ll>(0));
vector<ll> taka(MAXN, INF);
vector<ll> ao(MAXN, INF);

void deftaka(ll u,ll v, ll k) {
	taka[v] = k;
	k++;
	for (auto a : g[v]) {
		if (a == u) continue;
		deftaka(v, a, k);
	}
}

void defao(ll u, ll v, ll k) {
	ao[v] = k;
	k++;
	for (auto a : g[v]) {
		if (a == u) continue;
		defao(v, a, k);
	}
}

ll dfs(ll u, ll v) {
	if (taka[v] >= ao[v]) return -1;
	ll res = ao[v]-1;
	for (auto a : g[v]) {
		if (a == u) continue;
		res = max(res, dfs(v, a));
	}
	return res;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	ll  staka, sao; cin >> staka >> sao;
	rep(i, n-1) {
		ll a, b; cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	deftaka(-1,staka, 0);
	defao(-1,sao, 0);

	ll ans = dfs(-1, staka);
	cout << ans << endl;
}

Measured memory_bytes: 11264
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
using namespace std;
template <typename T> inline T __lcm(T a,T b)
{
    return (a*b)/__gcd(a,b);
}

ll n;
ll a[1000000][4];
ll dp[1000000][4];

ll fun(ll i,ll pos)
{
    if(i==n)
    {
        return 0;
    }
    if(dp[i][pos]!=-1)
    {
        return dp[i][pos];
    }
    ll profit1;
    ll profit2;
    if(pos==0)
    {
        profit1=a[i][pos]+fun(i+1,1);
        profit2=a[i][pos]+fun(i+1,2);
    }
    else if(pos==1)
    {
        profit1=a[i][pos]+fun(i+1,0);
        profit2=a[i][pos]+fun(i+1,2);
    }
    else
    {
        profit1=a[i][pos]+fun(i+1,0);
        profit2=a[i][pos]+fun(i+1,1);
    }
    return dp[i][pos]=max(profit1,profit2);

}

int main()
{
    memset(dp,-1,sizeof(dp[0][0])*1000000*4);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll ans=max(fun(0,2),max(fun(0,0),fun(0,1)));
    printf("%lld\n",ans);
}


Measured memory_bytes: 39808
def dfs(cnt=0, y=0, x=0):
    if y == H-1 and x == W-1:
        if S == cnt+1:
            global naraba
            naraba = True
        return
    for dy, dx in [(1, 0), (0, 1)]:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and A[ny][nx] == "#" and not V[ny][nx]:
            V[ny][nx] = True
            dfs(cnt+1, ny, nx)
            V[ny][nx] = False


if __name__ == "__main__":
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    V = [[False]*W for _ in range(H)]
    S = 0
    for a in A:
        S += a.count("#")
    V[0][0] = True
    naraba = False
    dfs()
    if naraba:
        print("Possible")
    else:
        print("Impossible")


Measured memory_bytes: 9208
#include <stdio.h>

void swap(int &a,int &b){
	int tmp=a ; a=b ; b = tmp; 
}
int main(){
	int array[3];
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
    for(int i=0; i<3; i++) scanf("%d",&array[i]);
    for(int i=0; i<3; i++) for(int j=0; j<2; j++) if(array[j]>array[j+1]) {
        swap(array[j],array[j+1]); 
        
    }
	if(array[0]*array[0]+array[1]*array[1]==array[2]*array[2]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	}
    return 0;
}

Measured memory_bytes: 1008
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100000];
int ind[100000];
int main(){
  int i;
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    ind[i] = i+1;
  }
  sortA_L(N, A, ind);
  {
    int KL2GvlyY;
    if(N==0){
      putchar_unlocked('\n');
    }
    else{
      for(KL2GvlyY=(0);KL2GvlyY<(N-1);KL2GvlyY++){
        wt_L(ind[KL2GvlyY]);
        wt_L(' ');
      }
      wt_L(ind[KL2GvlyY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190928-1

// --- original code ---
// int N, A[1d5], ind[1d5];
// {
//   rd(N,A(N));
//   rep(i,N) ind[i] = i+1;
//   sortA(N, A, ind);
//   wt(ind(N));
// }


Measured memory_bytes: 2432
// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
void solve(){
    int n, m, k, r=0, t;
    cin>>n>>m>>k;
    vector<ll>a(n+1), b(m+1);
    for(int i=1;i<=n;++i) {
      cin>>t;
      a[i]=a[i-1]+t;
    }
    for(int j=1;j<=m;++j) {
      cin>>t;
      b[j]=b[j-1]+t;
    }
    for(int i=0, j=m;i<=n && j>=0 && a[i]<=k;++i){
      while(a[i]+b[j]>k) j--;
      r=max(r, i+j);
    }
    cout << r << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
} 

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

int main(){
    while(1){
        int n,m,p,luck; cin>>n>>m>>p;

        if(n==0 && m== 0 && p==0 ) break;

        long long sum=0;

        vector<int> x(n);

        for(int i=0; i<n; i++){
            cin>>x[i];
            sum += x[i];
        }

        sum *= (100-p);
        luck = x[--m];
        int  ans=0;

        if(luck != 0) ans =  sum/luck;

        cout<<floor(ans)<<endl;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <iostream>

using namespace std;

const long long Q = 998244353;

int fact[202020];
int revf[202020];

int exp(int n, int m)
{
    int ret = 1;
    while(m)
    {
        if(m & 1) ret = (long long)ret * n % Q;
        n = (long long)n * n % Q;
        m >>= 1;
    }
    return ret;
}

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

    int n; cin >> n;
    int arr[n]; for(auto &i : arr) cin >> i;
    if(arr[0] != 0) {cout << 0; return 0;}
    int cnt[n + 1]{}; for(auto &i : arr) ++cnt[i];
    if(cnt[0] != 1) {cout << 0; return 0;}

    int nm = 0;
    int ans = 1;
    while(cnt[++nm])
    {
        ans = (long long)ans * exp(cnt[nm - 1], cnt[nm]) % Q;
    }
    for(int i = nm; i <= n; ++i)
    if(cnt[i]) {cout << 0; return 0;}

    cout << ans;
    return 0;
}


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


void solve(long long a){
    printf("%lld\n", (long long)(a*a*a + a*a + a));
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    solve(a);
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

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

    int N;
    pair<int, int> red[100], blue[100];
    bool used[100] = {false};
    cin >> N;

    rep(i, N) {
        int a, b;
        cin >> a >> b;
        red[i] = make_pair(a, b);
    }
    rep(i, N) {
        int c, d;
        cin >> c >> d;
        blue[i] = make_pair(c, d);
    }

    sort(red, red+N);
    sort(blue, blue+N);

    int ans = 0;

    rep(j, N) {
        int maxY = -1;
        int argMaxY = -1;
        for(int i = N-1; i>-1; i--) {
            if(red[i].first < blue[j].first
            && !used[i]) {
                if(maxY < red[i].second
                && red[i].second < blue[j].second) {
                    maxY = red[i].second;
                    argMaxY = i;
                }
            }
        }
        if(maxY > -1) {
            // match
            used[argMaxY] = true;
            ans++;
        }

    }

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


Measured memory_bytes: 256
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)

#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M             32000

int main()
{

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;





return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 998244353
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 100002
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO
    ll n,l,d1,d2;
    cin>>n;
    l=sqrt(n)+1;
    for(int i=l;i>0;i--){
        if(n%i==0){
           d1=log10(i)+1;
           d2=log10(n/i)+1;
           cout<<max(d1,d2)<<endl;
           return 0;
        }
    }
    return 0;
}


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

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

    sort(S.begin(), S.end());
    for(int i=0; i+1<S.size(); i++){
        char a = S[i];
        char b = S[i+1];
        if(a==b){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]

p1 = 0
p2 = 0
P1 = [0]
P2 = [0]
for a in A:
    if a == 0:
        p1 -= 2
        p2 += 1
    elif a % 2 == 0:
        p2 -= 1
    elif a % 2 == 1:
        p1 -= 1
        p2 += 1
    p1 += a
    P1.append(p1)
    P2.append(p2)

S = sum(A)
dp = [[0, 0, 0, 0] for _ in range(N+1)]

dp[N] = [P1[N], P1[N]+P2[N], -P1[N], 0]

for i in reversed(range(N)):
    dp[i][0] = max(dp[i+1][0], P1[i])
    dp[i][1] = max(dp[i+1][1], P2[i]+dp[i][0])
    dp[i][2] = min(dp[i+1][2], P2[i]-dp[i][1])
    dp[i][3] = min(dp[i+1][3], P1[i]+dp[i][2])

print(dp[0][3]+S)   


Measured memory_bytes: 64636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int N, cnt = 1;
	while (cin >> N && N) {
		putsp(cnt++);
		double ans = 0;
		vector <int> xs(N), ys(N);
		rep(N, i) {
			cin >> xs[i] >> ys[i];
		}
		int ox = xs[0], oy = ys[0];
		rep(N-2, i) {
			int dx1 = xs[i+1] - ox, dx2 = xs[i+2] - ox;
			int dy1 = ys[i+1] - oy, dy2 = ys[i+2] - oy;
			ans += (dx2*dy1 - dx1*dy2) / 2.;
		}
		printf("%.1lf\n", ans);
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> vp;
	rep(i, m){
		int s, c;
		cin >> s >> c;
		s--;
		vp.push_back(make_pair(s, c));
	}
	rep(i,pow(10, n)){
		string s = to_string(i);
		if(s.size() != n) continue;
		bool flag = true;
		for(auto p : vp){
			if(s[p.first] != p.second + '0'){
				flag = false;
				break;
			}
		}
		if(flag == true){
			cout << s << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

n = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i != 0:
                n[i-1][j] += 1
                if j != 0:
                    n[i-1][j-1] += 1
                if j != w-1:
                    n[i-1][j+1] += 1
            if i != h-1:
                n[i+1][j] += 1
                if j != 0:
                    n[i+1][j-1] += 1
                if j != w-1:
                    n[i+1][j+1] += 1
            if j != 0:
                n[i][j-1] += 1
            if j != w-1:
                n[i][j+1] += 1


for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            n[i][j] = "#"
    print(''.join(map(str, n[i])))

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

#define lson rt << 1
#define rson rt << 1 | 1
#define mid ((l + r) >> 1)
#define Lson l, mid, lson
#define Rson mid + 1, r, rson
const int MAXN = 2e5 + 100;
using pa = pair<int, int>;
using ll = long long;
const int MOD = 1e9 + 7;
ll p[MAXN][2];
ll cal(int n) {
    ll ans = 0;
    for (int s = 0; s < (1 << 2); ++s) {
        ll mx = -1e18, mn = 1e18;
        for (int i = 0; i < n; ++i) {
            ll tmp = 0;
            for (int j = 0; j < 2; ++j)
                tmp += (s & (1 << j)) ? p[i][j] : -p[i][j];
            mx = max(mx, tmp), mn = min(mn, tmp);
        }
        ans = max(ans, mx - mn);
    }
    return ans;
}

int main() {
    int n;
    cin >> n; 
    for (int i = 0; i < n; i++) cin >> p[i][0] >> p[i][1];
    cout << cal(n) << endl;
}


Measured memory_bytes: 6756
import kotlin.random.Random

//

fun main() {
    intro_heuristicsa()
}

fun intro_heuristicsa() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val s = MutableList(d) { listOf<Int>() }
    repeat(d) {
        s[it] = readLine()!!.split(" ").map { it.toInt() }
    }
    val nextContest = (1..26).toMutableList()
    nextContest.shuffle()
    val last = IntArray(26) { 0 }
    repeat(d) {
        val scores = s[it].mapIndexed { index, i -> index to i }
        val day = it + 1
        val disapoint = last.mapIndexed { index, i -> (it - i + 1) * c[index] }.sum()
        val max_score = scores.maxBy { (index, value) -> value + (c[index] * (day - last[index])) - disapoint }!!
        println(max_score.first + 1)
        last[max_score.first] = day
    }
}


Measured memory_bytes: 40576
using System;

namespace ABC068C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int N = int.Parse(bufs[0]);
            int M = int.Parse(bufs[1]);

            int[] path = new int[N];

            for (int i = 0; i < M; i++)
            {
                bufs = Console.ReadLine().Split(' ');
                int a = int.Parse(bufs[0]);
                int b = int.Parse(bufs[1]);

                if (a == 1)
                {
                    path[b] |= 2;
                }
                else if (b == N)
                {
                    path[a] |= 1;
                }
            }

            for (int i = 0; i < N; i++)
            {
                if ((path[i] & 3) == 3)
                {
                    Console.WriteLine("POSSIBLE");
                    return;
                }
            }

            Console.WriteLine("IMPOSSIBLE");

        }
    }
}


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

int main() {
    int N;
    cin >> N;
    
    if(N == 1)
    cout << 1 << endl;
    else if( N <= 3)
    cout << 2 << endl;
    else if( N <= 7)
    cout << 4 << endl;
    else if( N <= 15)
    cout << 8 << endl;
    else if( N <= 31)
    cout << 16 << endl;
    else if( N <= 63)
    cout << 32 << endl;
    else if( N < 101)
    cout << 64 << endl;



    
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
int dp[101010][2];

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	vector<int>X(M); rep(i, 0, M) { cin >> X[i]; }
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	sort(all(X));
	dump(X);
	vector<int>y;
	rep(i, 0, M - 1) {
		y.eb(X[i + 1] - X[i]);
	}
	dump(y);
	sort(all(y));
	dump(y);
	int ans = accumulate(y.begin(), y.begin() + (M - N), 0ll);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2168