akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main()
{
  int S;
  int h, m, s;

  std::cin >> S;

  s = S % 60;
  S = (S - s) / 60;
  m = S % 60;
  h = (S - m) / 60 ;

  std::cout << h << ":" << m << ":" << s << '\n';
}


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

using namespace std;

int main()
{  
    int n;
    bool flag = false;
    int count = 0;
    int a, b;

    cin >> n;


    for( int i = 0; i < n; i++ )
    {
        cin >> a >> b;

        if( flag )
            continue;
        
        if( a == b )
            count++;
        else
            count = 0;
        
        if( count > 2 )
            flag = true;
    }
    
    if( flag )
        cout << "Yes\n";
    else   
        cout << "No\n";

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<long,long>
using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");
int i,m,ans,R,C;
double n;
vector<pair<double,double > >v;
int perm[15],viz[15];
double sum;
double calculate_dist(pair<double,double> a,pair<double,double> b)
{
    return (sqrt((b.first-a.first)*(b.first-a.first)+(b.second-a.second)*(b.second-a.second)));
}
double prelucrare(int n)
{
    double ans=0;
    int i,ok=0;
    for(i=1;i<=n-1;i++)
    {
        //cout<<perm[i]<<" ";
        ans+=calculate_dist(v[perm[i]],v[perm[i+1]]);
    }
    //cout<<perm[n]<<"\n";
    //ans+=calculate_dist(v[perm[n]],v[perm[1]]);
   // cout<<ans<<" ";
    return ans;
}
void bkt(int k,int n)
{
    if(k==n+1)
    {
        sum+=prelucrare(n);
        return;
    }
    else
    {
        int i;
        for(i=1;i<=n;i++)
        {
            if(viz[i]==0)
            {
                viz[i]=1;
                perm[k]=i;
                bkt(k+1,n);
                viz[i]=0;
            }
        }
    }
}
int main()
{
    cin>>n;
    v=vector<pair<double,double> >(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>v[i].first>>v[i].second;
    }

    bkt(1,n);
    double i,fact=1;
    for(i=1;i<=n;i++)
    {
        fact=fact*i;
    }
   // cout<<fact<<" ";
   // cout<<sum/9<<" ";

      cout << fixed << setprecision(6) << sum/fact << "\n";
    fin.close();
    fout.close();
    return 0;
}


Measured memory_bytes: 256
require 'prime'

n = gets.to_i
ans = (n-1).prime_division.inject(1){|r, (_, v)| r * (v + 1)} - 1

n.prime_division.map do |k, v| 
    Array.new(v+1) {|i| k ** i}
end.inject([1], :product).map{|e| e.flatten.inject(:*)}.drop(1).each do |x|
    y = n
    y /= x while y % x == 0
    ans += 1 if y % x == 1
end

puts ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){int n,m,i,a,b,ans=0;
cin>>n>>m;
int h[n+1];
int mx[n+1]={0};
for(i=1;i<=n;i++){cin>>h[i];}
for(i=0;i<m;i++){cin>>a>>b;
    mx[a]=max(mx[a],h[b]);
    mx[b]=max(mx[b],h[a]);
}
for(i=1;i<=n;i++){if(mx[i]<h[i]){ans++;}}
cout<<ans;
    return 0;}

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

string S;

int main() {
    cin >> S;

    int p1 = 0, p2 = 0;

    // 0始まり
    rep(i, S.size()) {
        if (i % 2 == 0 && S[i] != '0') p1++;
        if (i % 2 == 1 && S[i] != '1') p1++; 
    }

    // 1始まり
    rep(i, S.size()) {
        if (i % 2 == 0 && S[i] != '1') p2++;
        if (i % 2 == 1 && S[i] != '0') p2++; 
    }

    printf("%d\n", min(p1, p2));
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main(void){
    using namespace  std;
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    sort(all(H));
    long total = 0;
    rep(i, N - K) total += H[i];

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 1024
#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>;

int main() {
    string s;
    cin >> s;
    if(s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll A, B, C;
int main(){
	cin >> A>> B >>C;
	if(A+B+C >= 22){
		p("bust");
	}else{
		p("win");
	}

	return 0;
}

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

using namespace std;

int main() {
    int N,i,j;
    cin>>N;
    vector<int> primes;
    primes.push_back(2);
    primes.push_back(3);
    primes.push_back(5);
    primes.push_back(7);
    int divisors[101]={0,};
    for(i=9;i<=N;i+=2){
        bool isOkay=true;
        for(int j=2;j*j<9;j++){
            if(i%j==0){
                isOkay=false;
                break;
            }
        }
        if(isOkay)primes.push_back(i);
    }
    for(i=2;i<=N;i++){
        int num=i;
        for(auto prime:primes){
            while(num%prime==0){
                num/=prime;
                divisors[prime]++;
            }
            if(num==1)break;
        }
        if(num!=1)divisors[num]++;
    }
    int ans=0;
    for(i=2;i<=N;i++){
        if(divisors[i]==0)continue;
        if(divisors[i]>73)ans++;
        // cout<<i<<" = " << divisors[i]<<endl;
        for(j=i+1;j<=N;j++){
            if(divisors[j]==0)continue;
            if(divisors[j]>73)ans++;

            if(divisors[i]>23&&divisors[j]>1)ans++;
            if(divisors[j]>23&&divisors[i]>1)ans++;
            if(divisors[i]>13&&divisors[j]>3)ans++;
            if(divisors[j]>13&&divisors[i]>3)ans++;
            for(int k=j+1;k<=N;k++){
                if(divisors[k]==0)continue;
                if(divisors[k]>73)ans++;

                // if(divisors[i]>23&&divisors[k]>1)ans++;
                // if(divisors[j]>23&&divisors[k]>1)ans++;
                // if(divisors[k]>23&&divisors[i]>1)ans++;
                // if(divisors[k]>23&&divisors[j]>1)ans++;
                // if(divisors[i]>13&&divisors[k]>3)ans++;
                // if(divisors[j]>13&&divisors[k]>3)ans++;
                // if(divisors[k]>13&&divisors[i]>3)ans++;
                // if(divisors[k]>13&&divisors[j]>3)ans++;

                if(divisors[i]>3&&divisors[j]>3&&divisors[k]>1){
                    ans+=1;
                }
                if(divisors[i]>1&&divisors[j]>3&&divisors[k]>3){
                    ans+=1;
                }
                if(divisors[i]>3&&divisors[j]>1&&divisors[k]>3){
                    ans+=1;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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(b<a){a=b;return true;}return false;}

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

    string s;cin>>s;
    if(s.size()%2!=0){
        cout<<"No"<<endl;
        return 0;
    }

    rep(i,s.size()){
        if(i%2==0 and s[i]!='h'){
            cout<<"No"<<endl;
            return 0;
        }
        if(i%2==1 and s[i]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl

int main(){
	cin.tie(0);	ios::sync_with_stdio(false);
	vector<pair<int, char>> asset;
	int m, n; cin>>n>>m;
	while(m--){
		int s; char c; cin>>s>>c;
		asset.push_back(make_pair(s - 1, c));
	}
	for(int mask = 0; mask < pow(10, n); mask++){
		string s = to_string(mask);
		if(int(s.size()) != n) continue;
		bool ok = true;
		for(auto tmp: asset){
			int id = tmp.first;
			char ch = tmp.second;
			if(s[id] != ch){
				ok = false;
				break;
			}
		}
		if(ok){
			cout<<s<<endl;
			return 0;
		}
	}
	cout<<"-1\n";
}


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

using namespace std;

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;
    int sum = 0;
    if(P >= Q && P>=R)
        cout << Q+R;
    else if(Q >= P && Q>=R)
        cout << P+R;
    else if(R >= Q && R>=P)
        cout << P+Q;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

class Point{
public:
	double x, y;
	Point(double x=0, double y=0):x(x), y(y){}

	Point operator + (Point p){ return Point(x + p.x, y + p.y); }
	Point operator - (Point p){ return Point(x - p.x, y - p.y); }
	Point operator * (double a){ return Point(a * x, a * y); }
	Point operator / (double a){ return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y;}
	bool operator < (const Point &p) const {
		// first x, second y
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.y - a.y * b.x;
}

// Orthogonal
bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1- b2);
}

// Orthogonal
bool isParallel(Vector a, Vector b){
	return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2){
	return isParallel(a1 - a2, b1- b2);
}
int Q;
int main() {
	cin >> Q;
	rep(i, Q){
		Point p0, p1, p2, p3;
		cin >> p0.x >> p0.y;
		cin >> p1.x >> p1.y;
		cin >> p2.x >> p2.y;
		cin >> p3.x >> p3.y;
		int r;
		if(isOrthogonal(p0,p1,p2,p3)) {
			r = 1;
		}
		else if(isParallel(p0,p1,p2,p3)){
			r = 2;
		}
		else{
			r = 0;
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

vector<ll> divisor(ll sum){
    vector<ll> div;
    for(int i=1; i*i<=sum; ++i){
        if(sum%i == 0 && i*i != sum) { div.push_back(i); div.push_back(sum/i); }
        else if(sum%i == 0) div.push_back(i);
    }

    return div;
}

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

    ll n , k; cin >> n >> k;
    ll sum = 0;
    vector<int> a(n);
    for(int i=0; i<n; ++i) { cin >> a[i]; sum += a[i]; }

    vector<ll> div = divisor(sum);
    sort(div.rbegin(), div.rend());
    

    vector<ll> r(n), remC(n, 0), lackC(n, 0);
    for(auto d:div){
        for(int i=0; i<n; ++i) r[i] = a[i]%d;
        sort(r.begin(), r.end());
        for(int i=0; i<n; ++i) remC[i] = r[i] + (i == 0? 0:remC[i-1]);
        for(int i=n-1; i>=0; --i) lackC[i] = (d - r[i]) + (i == n-1? 0:lackC[i+1]);

        // if(d == 10){
        //     for(int i=0; i<n; ++i) cout << remC[i] << ' ';
        //     cout << endl;
        //     for(auto e:lackC) cout << e << ' ';
        //     cout << endl;
        // }


        ll cnt = 1e15;
        for(int i=0; i<=n-2; ++i){
            chmin(cnt, max(remC[i], lackC[i+1]));
        }
        if(cnt <= k){
            cout << d << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = input()
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
if int(n[-1]) in hon:
    print("hon")
elif int(n[-1]) in pon:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9172
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
typedef long long ll;
typedef pair<int,int> P;


int main(){
   int N,K,a,count=0;
   cin>>N>>K;
   for(int i=0;i<N;i++){
       cin>>a;
       if(a>=K) count++;
   }
   cout<<count<<endl;
}


Measured memory_bytes: 256
#coding: utf-8
import numpy as np

array = list(map(int,input().strip().split(" ")))
res = 0
array.sort()
if (array[1]-array[0])%2 == 0:
    res_max = array[2]
else:
    res_max = array[2]+1

for ele in array:
    res += res_max - ele

print(int(res/2))

Measured memory_bytes: 19832
#include<iostream>
#include<string>
using namespace std;
char s[20][20];
void bon(int x,int y){
    s[x][y]='0';
    for(int i=1;i<4;i++){
        if((x+i)<=8&&s[x+i][y]=='1')bon(x+i,y);
        if((x-i)>0&&s[x-i][y]=='1')bon(x-i,y);
        if((y+i)<=8&&s[x][y+i]=='1')bon(x,y+i);
        if((y-i)>0&&s[x][y-i]=='1')bon(x,y-i);
    }
    }
int main(){
    int n;
    cin >> n;
    for(int o=1;o<=n;o++){
    for(int k=1;k<=8;k++){
        for(int j=1;j<=8;j++){
            cin >> s[j][k];
        }
    }
    int X,Y;
    cin >> X >> Y;
    bon(X,Y);
    cout << "Data " << o << ':' << endl;
    for(int k=1;k<9;k++){
        for(int j=1;j<9;j++){
            cout << s[j][k];
        }
        cout << endl;
    }
    }
return 0;
}

Measured memory_bytes: 1160
# A - ABC Swap
x, y, z = map((int),(input().split()))

tmp = 0

# 箱Aと箱Bの中身を入れ替える
tmp = x
x = y
y = tmp

# 箱Aと箱Cの中身を入れ替える
tmp = x
x = z
z = tmp

print(str(x) + " " + str(y) + " " + str(z))

Measured memory_bytes: 3060
from itertools import accumulate
from collections import Counter

S = list(input())
S = list(map(int, S))
s = [0] * len(S)
mod = 2019
s[-1] = S[-1]
d = 1
for i in range(len(s) - 2, -1, -1):
    d = (d * 10) % mod
    s[i] = (S[i] * d) % mod

acc = list(accumulate(s[::-1]))[::-1] + [0]
acc = [i % mod for i in acc]
answer = sum(i * (i - 1) // 2 for i in Counter(acc).values())
print(answer)


Measured memory_bytes: 35020
#include <stdio.h>
#include<math.h>
#include <iostream>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
#define mod 1000000007
int main()
{
    int n,k,d[105],a[105][105];
    scanf("%d%d",&n,&k);
    map<int,int>mp;
    for(int i=0; i<k; i++)
    {
        scanf("%d",&d[i]);
        for(int j=0; j<d[i]; j++)
        {
            scanf("%d",&a[i][j]);
            mp[a[i][j]]++;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(mp[i]==0)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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

using s32 = int;
using u32 = unsigned int;
using s64 = long long int;
using u64 = unsigned long long int;

u64 n;
u32 A[200000];
u32 B[200000];
u32 C[200000];
u32 D[200000];

int main(){
  scanf("%lld", &n);
  for(int i = 0; i < n; ++i) scanf("%d%d", A+i, B+i), C[i] = A[i], D[i] = B[i];

  std::sort(C, C+n);
  std::sort(D, D+n);

  if(n & 1){
    u32 l = C[n/2];
    u32 r = D[n/2];
    printf("%d\n", r - l + 1);
  }
  else {
    u32 l0 = C[n/2-1];
    u32 r0 = D[n/2-1];
    u32 l1 = C[n/2];
    u32 r1 = D[n/2];
    printf("%d\n", r0 + r1 - (l0 + l1) + 1);
  }

  return 0;
}


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

Alice=0
Bob=0
n=1

while n<=N:
  if n%2==1:
    Alice=Alice+max(A)
    A.remove(max(A))
    n=n+1
  else:
    Bob=Bob+max(A)
    A.remove(max(A))
    n=n+1
print(Alice-Bob)

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

using namespace std;

int main(){
	string S,T;
	cin>>S>>T;
	if(S.length()>T.length()){
		swap(S,T);
	}
	vector<vector<int>>memo(S.length() + 1, vector<int>(26));
	for(int i = 0; i < S.length(); i++){
		memo[i+1]=memo[i];
		memo[i+1][S[i]-'a']++;
	}
	vector<vector<int>>memo2(T.length() + 1, vector<int>(26));
	for(int i = 0; i < T.length(); i++){
		memo2[i+1]=memo2[i];
		memo2[i+1][T[i]-'a']++;
	}
	{
		bool f=false;
		for(int i = 0; i< 26; i++){
			if(memo[S.length()][i]&&memo2[T.length()][i]){
				f=true;
				break;
			}
		}
		if(!f){
			cout<<0<<endl;
			return 0;
		}
	}

	vector<int>now(26);
	int ans=0;
	for(int len = S.length(); len >= 1; len--){
		set<vector<int>>SVI;
		for(int i = 0; i + len < memo.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo[i+len][k] - memo[i][k];
			}
			SVI.insert(now);
		}
		for(int i = 0; i + len < memo2.size(); i++){
			for(int k = 0; k < 26; k++){
				now[k] = memo2[i+len][k] - memo2[i][k];
			}
			if(SVI.count(now)){
				cout<<len<<endl;
				return 0;
			}
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll lucas(int N)
{
  ll first = 1LL;
  ll second = 2LL;
  ll ans = 3LL;
  for (int i = 0; i < N - 2; i++)
  {
    second = first;
    first = ans;
    ans = first + second;
  }
  return ans;
}

int main()
{
  int n;
  cin >> n;
  if (n < 2)
  {
    cout << 2 - n;
  }
  else
  {
  cout << lucas(n) << endl;
  }
}



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

 int main(){
 int N, X, m[101];
 cin >> N >> X;
 int S = 0, M = 1001001001;
 for(int i = 0; i < N; ++i){
cin >> m[i];
 S += m[i];
 if(m[i] < M){
 M = m[i];
 }
 }
 int ans = N + (X - S) / M;
 cout << ans << endl;
 }


Measured memory_bytes: 256
#include<iostream>
        #include<cstdio>
        #include<math.h>
        #include<string>
        #include<algorithm>
        #include<functional>
        #include<vector>
        #include<set>
        #include<map>
        #define INF 999999
        #define EPS 1.0e-6
         
        using namespace std;
         
        typedef long long ll;
        typedef pair<int, int> P;
        typedef pair<int, P> PP;
         
        string s;
        string t;
         
        int main()
        {
        	cin >> s;
        	cin >> t;
        	int slen = s.length();
        	int tlen = t.length();
        	vector<string>v;
         
        	for (int i = slen - 1; i >= tlen - 1; i--) {
        		int ope = 0;
        		string ans = s;
        		for (int j = i; j >= i - tlen + 1; j--) {
        			if (s[j] != t[tlen - 1 - (i - j)] && s[j] != '?') {
        				ope++; break;
        			}
        		}
        		if (ope == 0) {
        			for (int j = i; j >= i - tlen + 1; j--) {
        				ans[j] = t[tlen - 1 - (i - j)];
        			}
        			for (int i = 0; i < slen; i++) {
        				if (ans[i] == '?')ans[i] = 'a';
        			}
        			v.push_back(ans);
        		}
        	}
        	/*
        	for (int i = 0; i < v.size(); i++) {
        		cout << v[i] << endl;
        	}
        	*/
        	if (v.empty()) {
        		cout << "UNRESTORABLE" << endl;
        		return 0;
        	}
        	sort(v.begin(), v.end());
         
        	cout << v[0] << endl;
         
        	return 0;
        }

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
#[macro_use] extern crate text_io;
use proconio::marker::*;
use std::mem::*;
use std::collections::*;
use std::cmp::*;

struct UF{
    par:Vec<usize>,
    rank:Vec<usize>,
}
impl UF{
    fn new(n:usize)->UF{
        let mut v=vec![0;n];
        for i in 0..n{
            v[i]=i;
        }
        UF{
            par:v,
            rank:vec![1;n],
        }
    }
    fn root(&mut self,x:usize)->usize{
        if x==self.par[x]{
            x
        }else{
            let par=self.par[x];
            let res=self.root(par);
            self.par[x]=res;
            res
        }
    }
    fn same(&mut self,a:usize,b:usize)->bool{
        self.root(a)==self.root(b)
    }
    fn unite(&mut self,a:usize,b:usize)->bool{
        let ap=self.root(a);
        let bp=self.root(b);
        if ap==bp{
            return false;
        }
        if self.rank[ap]<self.rank[bp]{
            self.par[bp]=ap;
            self.rank[ap]+=self.rank[bp];
        }else{
            self.par[ap]=bp;
            self.rank[bp]+=self.rank[ap];
        }
        return true;
    }
    fn size(&mut self,a:usize)->usize{
        let ap=self.root(a);
        self.rank[ap]
    }
}
#[fastout]
fn main() {
    input!{
        n:usize,
        m:usize,
        mut v:[[usize;2];m],
    }
    let mut uf:UF=UF::new(n);
    for e in v{
        uf.unite(e[0]-1,e[1]-1);
    }
    let mut ans:usize=0;
    for i in 0..n{
        if ans<uf.size(i){
            ans=uf.size(i);
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 20020
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	// この問題の解説はPDFだとよく分からないのでYouTubeを見たほうが良い。

	LL X, Y;
	cin >> X >> Y;
	O(X + Y / 2);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	ll n,W;
	cin>>n>>W;
	ll wt[n],val[n];
	FOR0(i,n) cin>>wt[i]>>val[i];
	ll i, w; 

   	ll K[n+1][W+1]; 
  
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
   cout<<K[n][W];
}




Measured memory_bytes: 79104
import sys
from fractions import gcd
from functools import reduce

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def lcm(x, y):
    return x * y // gcd(x, y)


def main():
    N, M, *A = map(int, read().split())
    A = [a // 2 for a in A]

    semi_lcm = reduce(lcm, A)
    for a in A[1:]:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M or semi_lcm // a % 2 == 0:
            print(0)
            return

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 96824
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200005
#define INF 1000000005
#define INFLL (long long)1e18
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    int sum=0;
    REP(i,n)sum=sum^a[i];
    REP(i,n)OUT(sum^a[i]);
    return 0;
}


Measured memory_bytes: 4004
#include<bits/stdc++.h>
#define int long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define MOD 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define pp pop_back
#define pi 3.141592653589793238
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}
int lcm(int a, int b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  
bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
void solve()
{
	int a,b,k;
	cin>>k;
	cin>>a>>b;
	rep(i,a,b+1)
	{
		if(i%k==0)
		{
			cout<<"OK";
			return;
		}
	}cout<<"NG";
}    
signed main()
{
                     
  int t=1;
 //cin>>t;
  while(t--){
  solve();
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  

Measured memory_bytes: 3776
///----> bismillahir rahmanir rahim <---- -- { ^ _ ^ }
///     { ^_^ }   { ^ _ ^ }



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi; ///VECTOR<VECTOR<INT>NAME>NAME 2
typedef vector<vl> vvl;///LONG LONG
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;///VECTOR WITH PAIR
typedef vector<pll> vll;
typedef double dl;

#define endl "\n"
#define PB push_back
#define F first
#define S second
#define as(a) (a).begin(),(a).end()
#define ras(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define over return 0;

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


///--------> YOUR JOURNEY STARTS HERE <-------



int main(){
multiset<ll>sett;
set<ll>s;

int n;
cin>>n;
while(n--){
    int t;
    cin>>t;
    sett.insert(t);
    s.insert(t);
}
ll sum=0;
for(auto e: s){int z=sett.count(e);
    if(z>e){
        sum+=(z-e);
    }
    else if(z<e){
        sum+=z;
    }
}
cout<<sum<<endl;

over
}

Measured memory_bytes: 12600
import std.stdio;
import std.string;
import std.array;
import std.range;
import std.algorithm;
import std.conv;
import std.typecons;

long byTwoCount(long a){
    long result = 0;
    while(a % 2 == 0){
        result++;
        a /= 2;
    }
    return result;
}

long solve(long[] as){
    return as.map!(byTwoCount).sum();
}

void main(){
    readln();
    auto as = readln().chomp().split().map!(to!long).array();
    solve(as).writeln();
}

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

int main()
{
    long long k,a,b;
    cin >> k >> a >> b;
    // a->b;
    if ( (a-1)+1+1>k||b<=a+2 ) {
        cout << k+1 << '\n';
    } else {
        long long x=a;
        long long kk=k;
        kk-=(a-1); // get b biscuit
        x+=(long long)(b-a)*(kk/2);
        if ( kk%2 ) {
            x++;
        }
        cout << max(k+1,x) << '\n';
    }

    return 0;
}


Measured memory_bytes: 3568
#!/usr/bin/env python3

from math import gcd

def lcm(x,y):
  return x*y//gcd(x,y)

def solve(a,b,c,d):
  def countNonDivisor(n,c,d):
    return n - n//c - n//d + n//lcm(c,d)
  return countNonDivisor(b,c,d) - countNonDivisor(a-1,c,d)



def main():
  a,b,c,d = map(int,input().split())
  print(solve(a,b,c,d))

  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
#define MAXE 100000
#define MAXN 100000
typedef long long ll;
struct EDGES{
    ll u,v,cap,flow,nextedge;
};
class MAXIMUM_FLOW{
    public :
    EDGES edge[MAXE];
    ll n , m , level[MAXN],Prev[MAXN],last[MAXN];
    queue<ll>Q;
    void init(ll N){
        n = N;
        m = -1;
        for(ll j=0;j<=n;j++) last[j] = -1;
    }
    void addedge(ll a,ll b,ll c){
        edge[++m].u=a , edge[m].v=b , edge[m].cap=c , edge[m].flow=0 , edge[m].nextedge=last[a] , last[a]=m;
        edge[++m].u=b , edge[m].v=a , edge[m].cap=0 , edge[m].flow=0 , edge[m].nextedge=last[b] , last[b]=m;
    }
    bool level_graph(ll src,ll snk){
        for(ll j=0;j<=n;j++) level[j]=-1;
        ll node,nxt;
        level[src]=1;
        Q.push(src);
        while(!Q.empty()){
            node=Q.front(); Q.pop();
            for(ll j=last[node];j!=-1;j=edge[j].nextedge){
                nxt=edge[j].v;
                if(level[nxt]==-1 && edge[j].flow<edge[j].cap){
                    level[nxt]=level[node]+1;
                    Q.push(nxt);
                }
            }
        }
        return (level[snk]!=-1);
    }
    ll dfs(ll node,ll snk,ll flow){
        ll nxt,curflow;
        if(node==snk) return flow;
        for(ll &j=Prev[node];j!=-1;j=edge[j].nextedge){
            nxt=edge[j].v;
            if(level[nxt]==level[node]+1 && edge[j].flow<edge[j].cap){
                curflow=dfs(nxt,snk,min(flow,edge[j].cap-edge[j].flow));
                if(curflow==0) continue;
                edge[j].flow+=curflow;
                edge[j^1].flow-=curflow;
                return curflow;
            }
        }
        return 0;
    }
    ll MAX_FLOW(ll src,ll snk){
        ll flow,ans=0;
        while(level_graph(src,snk)){
            for(ll j=0;j<=n;j++)
                Prev[j]=last[j];
            while(flow=dfs(src,snk,(1<<31)-1)) ans+=flow;
        }
        return ans;
    }
}G;
ll a[101];
int main(){
  ll n;
  ll sm=0;
  cin>>n;
  G.init(n+n);
  for(ll i=1; i<=n; ++i){
    cin>>a[i];
    if(a[i]>0){
      G.addedge(i, n+1, a[i]);
      sm+=a[i];
    }
    else{
      G.addedge(0, i, -a[i]);
    }
  }
  for(ll i=1; i<=n; ++i){
    for(ll j=1; j*i<=n; ++j){
      G.addedge(i, i*j, (1e9)+10);
    }
  }
  ll ans=sm-G.MAX_FLOW(0, n+1);
  cout<<ans<<endl;
  return 0;
}


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

int height[100010],dp[100010];

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


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

int main()
{
  int a, b, ave;
  cin >> a >> b;
  ave = (a + b) / 2 + 1;
  if((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0)){
    ave --;
  }
  cout << ave << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

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

  auto dfs = [&](auto& f, int now, ll k)->ll{
    if (!now) return 1;
    ll len = (1LL << (now + 1)) - 3;
    ll num = (1LL << now) - 1;
    if (k == 1) return 0;
    else if (k <= len + 1) return f(f, now - 1, k - 1);
    else if (k == len + 2) return num + 1;
    else if (k <= (len + 1) * 2) return num + 1 + f(f, now-1, k - len - 2);
    return num * 2 + 1;
  };

  cout << dfs(dfs, n, x) << endl;
  return 0;  
} 

Measured memory_bytes: 256
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    if n < 1000:
        print('ABC')
    else:
        print('ABD')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int s[105];
int main()
{
	int n,m;
	int a,b;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		sum+=s[i];
	}
	cin>>m;
	while(m--)
	{
		scanf("%d %d",&a,&b);
		printf("%d\n",sum-s[a]+b);
	}
	return 0;
}

Measured memory_bytes: 256
#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


#最小公倍数
def lcm(a,b):
    return a * b // gcd(a, b)


n = int(input())
T = list(int(input()) for _ in range(n))

res = T[0]
for i in range(1, n):
    res = lcm(res, T[i])
print(res)

Measured memory_bytes: 3064
import numpy as np

def python_list_add(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()

n, m, x = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
 #価格の合計
ans = []

for i in range(2 ** n):
    bag = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(j)  # フラグが立っていたら bag に果物を詰める
    
    p = 0
    org = [0]*m
    for k in bag:
        p += li[k][0]
        pos = li[k][1:]
        org = python_list_add(org, pos)
    if all(l >= x for l in org): #条件を満たしていたら
        ans.append(p)


if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 27392
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int res = 0;
      for (int k = 0; k < d; ++k) {
        res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      bool ok = false;
      for (int i = 1; i <= 10000; ++i) {
        if (i * i == res) ok = true;
      }
      if (ok) ans++;
    }
  }
  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++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int n,l;
    cin>>n>>l;
    int s=300;
    REP(i,n){
        if(abs(s)>abs(l+i)){
            s=l+i;
        }
    }
    int ans=(l*n-n+n*(n+1)/2)-s;
    OUT(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

const long long mod = 1e9 + 7;

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

	long long n_all = 1;
	long long not_have_0 = 1;
	long long not_have_9 = 1;
	long long not_have_09 = 1;


	for (int i = 0; i < n; i++) {
		n_all *= 10;
		n_all %= mod;
	}

	for (int i = 0; i < n; i++) {
		not_have_0 *= 9;
		not_have_0 %= mod;
	}
	not_have_9 = not_have_0;

	for (int i = 0; i < n; i++) {
		not_have_09 *= 8;
		not_have_09 %= mod;
	}

	cerr << n_all << endl;
	cerr << not_have_0 << endl;;
	cerr << not_have_09 << endl;

	long long ans = n_all - not_have_0 - not_have_9 + not_have_09 + mod * 2;
	ans %= mod;

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


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    // コンストラクタ　親は-頂点数を保管
    UnionFind(int N) : d(N, -1) {}

    int find(int x) {
        if (d[x] < 0) {
            return x;
        }
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        if (d[x] > d[y]) {
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<ll> ans(m + 1, 0);
    vector<int> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    ans[m] = n * (n - 1) / 2;
    for(int i = m - 1; i >= 0; i--){
        if(!uf.same(a[i], b[i])){
            ans[i] = ans[i + 1] - (ll)uf.size(a[i]) * uf.size(b[i]);
        }else ans[i] = ans[i + 1];
        uf.unite(a[i], b[i]);
        
    }
    rep(i, m)cout << ans[i + 1] << endl;
}

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


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll INF = 1e18;
int n, m;

int main() {
    while(1) {
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        ll Landdp[n][n];
        ll Seadp[n][n];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(i == j) Landdp[i][j] = 0;
                else Landdp[i][j] = INF;
            }
        }
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(i == j) Seadp[i][j] = 0;
                else Seadp[i][j] = INF;
            }
        }
        for(int i = 0; i < m; ++i) {
            int x, y, t; char sl;
            cin >> x >> y >> t >> sl;
            x--; y--;
            if(sl == 'L') {
                Landdp[x][y] = t;
                Landdp[y][x] = t;
            }else {
                Seadp[x][y] = t;
                Seadp[y][x] = t;
            }
        }
        for(int k = 0; k < n; ++k) {
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < n; ++j) {
                    chmin(Landdp[i][j], Landdp[i][k]+Landdp[k][j]);
                }
            }
        }
        for(int k = 0; k < n; ++k) {
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < n; ++j) {
                    chmin(Seadp[i][j], Seadp[i][k]+Seadp[k][j]);
                }
            }
        }

        int R; cin >> R;
        vector<int> zyun(R, 0);
        for(int i = 0; i < R; ++i) {
            cin >> zyun.at(i); zyun.at(i)--;
        }

        ll dp[R+1][n+1];
        for(int i = 0; i <= R; ++i) {
            for(int j = 0; j <= n; ++j) {
                dp[i][j] = INF;
            }
        }
        dp[0][zyun.at(0)] = 0;

        // 陸路のみか、陸路→海路→陸路
        // dp[i][j] : 頂点jに舟がある状態でi番目の配達先に訪れる
        // 舟の場所が異なる : i番目の配達先→k(舟があるところ)→j(目的地)→i+1番目の配達先
        // 舟の場所が一緒 : i番目の配達先→i+1番目の配達先
        for(int i = 0; i < R-1; ++i) {
            for(int j = 0; j < n; ++j) {
                for(int k = 0; k < n; ++k) {
                    if(j != k) {
                        chmin(dp[i+1][j], dp[i][k] + Landdp[zyun.at(i)][k] + Seadp[k][j] + Landdp[j][zyun.at(i+1)]);
                    }else {
                        chmin(dp[i+1][j], dp[i][j] + Landdp[zyun.at(i)][zyun.at(i+1)]);
                    }
                }
            }
        }

        ll ans = INF;
        for(int j = 0; j < n; ++j) {
            chmin(ans, dp[R-1][j]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 5204
N = int(input())

A = list(map(int, input().split()))

cnt = 1
flag = 0

for i in range(1,N):
    if flag == 0:
        if A[i-1] < A[i]:
            flag = 1
        elif A[i-1] > A[i]:
            flag = -1
    if flag == 1:
        if A[i-1] > A[i]:
            flag = 0
            cnt += 1
    if flag == -1:
        if A[i-1] < A[i]:
            flag = 0
            cnt +=1

print(cnt)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin>>p[i];
    int tmp=0,sum=0,pos=k-1;//posは右端
    for(int i=0;i<k;i++) sum+=p[i];
    tmp=sum;
    for(int i=k;i<n;i++){
        tmp-=p[i-k];
        tmp+=p[i];
        if(tmp>sum){
            sum=tmp;
            pos=i;
        }
    }
    double ans=0.0;
    for(int i=pos-k+1;i<=pos;i++){
        ans+=double(p[i]*(p[i]+1)/2.0)/double(p[i]);
    }
    printf("%.12lf\n",ans);
    return 0;
    return 0;
}


Measured memory_bytes: 1024
from collections import Counter
from string import ascii_lowercase


n = int(input())
INF = 1 << 31
dic = {c: INF for c in ascii_lowercase}
for _ in range(n):
    tmp = Counter(input())
    for c in ascii_lowercase:
        dic[c] = min(dic[c], tmp.get(c, 0))

ans = ''
print(''.join(c * dic[c] for c in ascii_lowercase))

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
string greedy(string s, int k){
	if (k == 0) return s;
	int n = s.size();
	while (k > 1){
		int take = 1;
		while (take < n && s[n-take-1] == s[n-1]) take++;
		string t = "";
		for (int i=0; i < n-take;i++) t += s[take+i];
		for (int i=0; i < take; i++) t += s[n-i-1];
		s = t;
		k--;
	}
	int take = 1;
	while (take < n && s[n-take-1] == s[n-1]) take++;
	string t = "";
	for (int i=0; i < take;i++) t += s[n-take+i];
	for (int i=0; i < n-take; i++) t += s[n-i-1];
	return t;
}
signed main() {
	#ifdef LOCAL
		freopen("H_input.txt", "r", stdin);
		//freopen("C_output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    k = min(k, 15);
    string res = "";
    for (int i=0; i < n; i++) res += 'z';
    string t = s;
	reverse(t.begin(), t.end());
	s += t;
	for (int i=0; i <= n; i++){
		string var = "";
		for (int j=0; j < n; j++) var += s[i+j];
		res = min(res, greedy(var, k-1));
	}
	cout << res;
}

Measured memory_bytes: 384
long M=1e9+7,m[1<<18],h,w,a,s;p(a,b)long a;{return b?p(a*a%M,b/2)*(b%2?a:1)%M:1;}main(i){for(*m=1;i<1<<18;)m[i]=m[i-1]*i++%M;for(scanf("%d%d%d%d",&h,&w,&a,&i);i<w;)s=(s+m[h-a-1+i]*m[a+w-i-2]%M*p(m[h-a-1]*m[i]%M*m[a-1]%M*m[w-1-i++]%M,M-2)%M)%M;printf("%d",s);}

Measured memory_bytes: 2176