akhauriyash/Code-Regression huggingface dataset:
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
    }

    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }

    void unite(ll a, ll b, ll w = 0){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }

    bool same(ll a, ll b){ return root(a) == root(b);}
    
    ll sz(ll x){ return num[root(x)];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};
ll x[100010], y[100010];
UnionFind uf(200010);
ll cnt_path[200010] = {};
set<ll> cnt_x[200010], cnt_y[200010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    rep(i,0,N){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    rep(i,0,N){
        uf.unite(x[i], y[i]+100000);
    }
    rep(i,0,N){
        ll rt = uf.root(x[i]);
        cnt_path[rt]++;
        cnt_x[rt].insert(x[i]);
        cnt_y[rt].insert(y[i]);
    }
    ll ans = 0;
    bool check[200010] = {};
    rep(i,0,N){
        ll rt = uf.root(x[i]);
        if(check[rt]) continue;
        check[rt] = true;
        ll nx = cnt_x[rt].size();
        ll ny = cnt_y[rt].size();
        ll nc = cnt_path[rt];
        ans += nx * ny - nc;
    }
    print(ans);
}

Measured memory_bytes: 32240
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    A=list(map(int, input().split()))
    yen=1000
    kabu=0
    for i in range(n-1):
        if A[i] < A[i+1]:
            kabu+=yen//A[i]
            yen=yen%A[i]
           
        elif A[i] > A[i+1]:
            yen+= kabu*A[i]
            kabu=0
    print(yen+kabu*A[n-1])


 
if __name__=='__main__':
    main()

Measured memory_bytes: 9200
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs) {
  var N = inputs[0];
  var count = 1;
  var next = 1;
  for(; count < N; count++){
    if(next == -1){
      break;
    }
    var temp  = inputs[next];
    inputs[next] = -1;
    next = temp;
    if(next == 2){
      console.log(count);
      return;
    }
  }
  console.log(-1);
}


Measured memory_bytes: 30024
while True :
	count_1 = 0
	w = raw_input()
	while True :
		t = raw_input()
		if t=='END_OF_TEXT':
			break
		else :
			a_list = t.lower().split()
	 		for i in a_list:
				if (w==i):
					count_1 += 1
	print(count_1)
	if t=='END_OF_TEXT':
		break

Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <tuple>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

struct pInfo {
    ll x;
    ll y;
    ll h;
};

ll allTrue(int n, ll x, ll y, vector<pInfo> info) {
    ll h = -1;
    REP(i, n) {
        if (info[i].h != 0) {
            ll hh = info[i].h + abs(info[i].x - x) + abs(info[i].y - y);
            if (hh > 0) {
                h = hh;
                break;
            }
        }
    }
    // cout << x << " " << y << " " << h << endl;

    REP(i, n) {
        ll hh = max(h - abs(info[i].x - x) - abs(info[i].y -y), ll(0));
        if (info[i].h != hh) {
            return -1;
        }
    }

    return h;
}

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

    int n;
    vector<pInfo> info;
    cin >> n;
    REP(i, n) {
        pInfo temp;
        cin >> temp.x >> temp.y >> temp.h;
        info.push_back(temp);
    }
    REP(x, 101) {
        REP(y, 101) {
            ll h = allTrue(n, x, y, info);
            if (h != -1) {
                cout << x << " " << y << " " << h << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    vector<tuple<string,int,int>> R(N);
    for(int i=0;i<N;i++){
        string S;
        int P;
        cin>>S>>P;
        R[i]=make_tuple(S,-P,i+1);
    }
    sort(ALL(R));
    for(int i=0;i<N;i++){
        cout<<get<2>(R[i])<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
 
int main(){
    double a,b,c,d,e,f,x,y;
 
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
        x=(c*e-b*f)/(a*e-d*b);
        y=(a*f-c*d)/(a*e-b*d);
        if(x == 0)x=0;
        if(y == 0)y=0;
        printf("%.3lf %.3lf\n",x,y);
    }
 
    return 0;
}


Measured memory_bytes: 2596
import java.util.*;


public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
for(int count=2;count<11;count++){
inner:  for(int i=2;i<=(int)Math.pow(x,0.5);i++){
        if((int)Math.pow(i,count)<=x){
        list.add((int)Math.pow(i,count));
      }else{
        break inner ;
      }
    }
}
Collections.sort(list);

        System.out.print(list.get(list.size()-1));

  }
}


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

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<int>>cake(h, vector<int>(w,0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char x;
			cin >> x;
			if (x == '#')cake.at(i).at(j) = -1;
		}
	}
	vector<int>nostr;
	vector<int>str;
	for (int i = 0; i < h; i++) {
		bool x = false;
		for (int j = 0; j < w; j++) {
			if (cake.at(i).at(j) == -1) {
				x = true;
				break;
			}
		}
		if (x)str.push_back(i);
		else nostr.push_back(i);
	}
	int ct = 1;
	for (int i = 0; i < str.size(); i++) {
		bool x = false;
		int y = str.at(i);
		for (int j = 0; j < w; j++) {
			if (cake.at(y).at(j) == 0 && x == false) cake.at(y).at(j) = ct;
			else if (cake.at(y).at(j) == -1 && x == false) {
				x = true;
				cake.at(y).at(j) = ct;
			}
			else if (x == true && cake.at(y).at(j) == 0)cake.at(y).at(j) = ct;
			else if (x == true && cake.at(y).at(j) == -1) {
				ct++;
				cake.at(y).at(j) = ct;
			}
		}
		ct++;
	}
	for (int i = 0; i < nostr.size(); i++) {
		int y = nostr.at(i);
		if (i == 0&&y!=h-1) for (int j = 0; j < w; j++) cake.at(y).at(j) = cake.at(y + 1).at(j);
		else for (int j = 0; j < w; j++)cake.at(y).at(j) = cake.at(y - 1).at(j);
	}
	for (int i = 0; i < nostr.size(); i++) {
		int y = nostr.at(nostr.size()-1-i);
		if (i == 0&&y!=0) for (int j = 0; j < w; j++) cake.at(y).at(j) = cake.at(y - 1).at(j);
		else for (int j = 0; j < w; j++)cake.at(y).at(j) = cake.at(y + 1).at(j);
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j == 0)cout << cake.at(i).at(j);
			else cout << " " << cake.at(i).at(j);
		}
		cout << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>


typedef long long ll;


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

#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;





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

    ll ans = 0;


    for (ll i = 2; i * i <= n; i++) {

        ll count = 0;
        ll z = 0;

        while (n % i == 0) {
            count++;
            n /= i;
            if (count > z) {
                count = 0;
                z++;
            }
        }
        ans += z;
    }

    if (n != 1)
        ans++;

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n, t;
    cin >> n >> t;
    int c = 10000;
    vector<vector<int>> data(n,vector<int>(2));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            cin >> data.at(i).at(j);
        }
    }

    for(int i = 0; i < n; i++){
        if(t >= data.at(i).at(1) && data.at(i).at(0) < c) c = data.at(i).at(0);
    }

    if(c == 10000) cout << "TLE" << endl;
    else cout << c << endl;
}



Measured memory_bytes: 256
from fractions import gcd
a,b,c,d = map(int,input().split())
cab = (b//c)-((a-1)//c)
dab = (b//d)-((a-1)//d)
lcm = int(c*d/gcd(c,d))
cdab = (b//lcm)-((a-1)//lcm)
print((b-a+1)-cab-dab+cdab)

Measured memory_bytes: 5048
#include<stdio.h>
#include<math.h>
/*
long long check(long long x)
{
	if(x%4==0)return x;
	if(x%4==1)return 1;
	if(x%4==2)return x+1;
	if(x%4==3)return 0;
}
*/
int main()
{
	int m,k;
    scanf("%d%d",&m,&k);
    if(k>=pow(2,m)||(m==1&&k!=0)||(m==0&&k!=0))
	{
		printf("-1\n");
		return 0;
	}
	if(m==0&&k==0)
    {
    	printf("0 0\n");
    	return 0;
	}
    if(m==1&&k==0)
	{
		printf("0 0 1 1\n");
		return 0;
	}
	if(k!=0)
	{
		printf("0 %d ",k);
		for(int i=1;i<pow(2,m);i++)if(i!=k)printf("%d ",i);
		printf("%d 0 ",k);
		for(int i=pow(2,m)-1;i>0;i--)
		{
			if(i!=k)printf("%d ",i);
		}
		printf("\n");
	}
	else
	{
		for(int i=0;i<pow(2,m);i++)printf("%d ",i);
		for(int i=pow(2,m)-1;i>=0;i--)printf("%d ",i);
		printf("\n");
	}
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
     
int read(){
   	int x=0,f=1;
   	char c=getchar();
   	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
   	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
   	return x*f;
}
     
int k,m,n;
int gcd(int x,int y){
   	if(!y)return x;
   	return gcd(y,x%y);
}
int ans=0,a[100010];
signed main(){
 	n=read();k=read();
   	for(register int i=1;i<=n;i++){
   		a[i]=read();
   	}
	m=1;
   	while(1){
   		int flag=0;
   		for(register int i=1;i<=n;i++)if(a[i]&1)flag=1;
   		if(flag)break;
   		for(register int i=1;i<=n;i++){
   			a[i]>>=1;
   		}
   		m<<=1;
  	}
   	for(register int i=1;i<=n;i++){
   		if(!(a[i]&1)){puts("0");return 0;}
   	}
	m*=a[1];
   	for(register int i=2;i<=n;i++){
   		m*=a[i]/gcd(m,a[i]);
   		if(m>k*2){puts("0");return 0;}
   	}
   	printf("%lld\n",((k*2/m)+1)/2);
   	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];

    int ans=0;
    rep(i,n){
        int flag=0;
        for(int j=0;j<i;j++){
            if(a[i]<a[j])flag=1;
        }
        if(flag==0)ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
	int a[100] = { 0 };
	int N, K,d,e,l = 0;

	cin>> N>> K;

	for (int i = 0; i < K; i++) {
		cin >> d;
		for (int j = 0; j < d; j++) {

		cin >> e;
		a[e - 1]++;
		}
		
	}

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

		if (a[i] == 0) {
			l++;
		}
	}

	cout << l;
}

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

const int MAX_N = 1299709;

int main() {
    vector<char> prime(MAX_N + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i * i <= MAX_N; i++)
        if(prime[i])
            for(int j = 2 * i; j <= MAX_N; j += i)
                prime[j] = false;
    vector<int> A;
    for(int i = 2; i <= MAX_N; i++) if(prime[i]) A.push_back(i);
    for(int N; cin >> N, N; ) {
        if(binary_search(A.begin(), A.end(), N)) {
            cout << 0 << endl;
        }
        else {
            vector<int>::iterator lb = lower_bound(A.begin(), A.end(), N);
            vector<int>::iterator ub = upper_bound(A.begin(), A.end(), N);
            cout << *ub - *(lb - 1) << endl;
        }
    }
}

Measured memory_bytes: 2996
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を2と3以上の奇数で順次割っていくする（下から計算したら、素数判定は不要）
# 3. 2.の結果に含まれる数の種類の数＋１が答え

def main():
  a, b = map(int, input().split())
  while b != 0: a, b = b, a % b #最大公約数を求める
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  
  if n == 1: return ans
  
  cursor = 2
  if n % cursor == 0: ans += 1
  while n % cursor == 0: n = n // cursor
  
  cursor = 3
  # リストを作成して探索範囲を先に作ってforで回す処理だと、リスト生成時の計算量やメモリ消費が多いからwhileで都度計算
  while cursor ** 2 <= n: 
    if n == 1: break
    if n % cursor == 0: ans += 1
    while n % cursor == 0: n = n // cursor
    cursor += 2
  
  if n != 1: ans += 1
    
  return ans

if __name__ == "__main__":
  main()


Measured memory_bytes: 38512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()
B = LIST()

CA = Counter(A)
CB = Counter(B)

for k in CB.keys():
	if CB[k] > N-CA[k]:
		print("No")
		exit()
else:
	print("Yes")

B = B[::-1]

j = 0
jdx = 1

for i in range(N):
	if A[i] == B[i]:
		if B[i] == B[j] or B[i] == A[j]:
			j = -1
			jdx = -1
		B[i], B[j] = B[j], B[i]
		j += jdx

print(*B)




Measured memory_bytes: 57284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

string s, t;
ll n, m, memo[500008], hs[500008], ht;
ll base = 10007;
ll bf = 1;
ll mod = 1000000009;

ll get_memo(ll st, ll cnt){
	if(hs[st] != ht){
		return 0;
	}
	if(cnt == n){
		return n;
	}
	if(memo[st] == 0){
		return memo[st] = get_memo((st+m)%n, cnt+1)+1;
	}
	return memo[st];
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> s >> t;
	n = s.size();
	m = t.size();
	bool tmp = true;
	zep(i, 0, n){if(s[i] != s[0]){tmp = false;}}
	zep(i, 0, m){if(t[i] != s[0]){tmp = false;}}
	if(tmp){print(-1) return 0;}
	
	rep(i, 1, m){
		bf *= base;
		bf %= mod;
	}
	
	vector<ll> sv, tv;
	zep(i, 0, n){sv.push_back(s[i]-'a'+1);}
	zep(i, 0, m){tv.push_back(t[i]-'a'+1);}
	
	hs[0] = 0;
	zep(i, 0, m){
		hs[0] *= base;
		hs[0] %= mod;
		hs[0] += sv[i%n];
		hs[0] %= mod;
	}
	
	zep(i, 1, n){
		hs[i] = hs[i-1]*base;
		hs[i] %= mod;
		hs[i] += mod-(bf*sv[(i-1)%n])%mod;
		hs[i] %= mod;
		hs[i] += sv[(i+m-1)%n];
		hs[i] %= mod;
	}
	
	ht = 0;
	zep(i, 0, m){
		ht *= base;
		ht %= mod;
		ht += tv[i];
		ht %= mod;
	}
	
	ll ans = 0;
	memset(memo, 0, sizeof(memo));
	zep(i, 0, n){
		ans = max(get_memo(i, 0), ans);
	}
	
	if(ans >= n){
		ans = -1;
	}
	print(ans)
	
	return 0;
}

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

int main(){
	string S;
  	cin>>S;
  	int N = S.size();
  	for (int i=0;i<N-1;++i){
    	if (S[i] == S[i+1]){
        	cout<<i+1<<' '<<i+2;
	        return 0;
        }
    }
  	for (int i=0;i<N-2;++i){
    	if (S[i] == S[i+2]){
        	cout<<i+1<<' '<<i+3;
	        return 0;
        }
    }
  cout<<"-1 -1";
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2+2],R[MAX/2+2];
llong merge(int A[] , int n , int left , int mid , int right)
{
	int i , j , k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for( i = 0; i < n1;i++) L[i] = A[left+i];
	for( i = 0; i < n2;i++) R[i] = A[mid+i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for( k = left; k < right; k++)
	{
		if(L[i] <= R[j])
		{
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
			cnt += n1 -i;
		}
	}
	return cnt;
}

llong mergeSort(int A[] , int n , int left , int right)
{
	int mid;
	llong v1, v2, v3, a;
	if(left + 1 < right){
		mid =( left + right)/2;
		v1 = mergeSort(A,n,left,mid);
		v2 = mergeSort(A,n,mid,right);
		v3 = merge(A,n,left,mid,right);
		a = v1+v2+v3;
		return a;
	}
	else return 0;
}

int main(void)
{
    int A[MAX],n,i;
    cin >> n;
    for( i = 0; i < n;i++)
    {
        cin >> A[i];
    }
    llong ans = mergeSort(A,n,0,n);
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	string s;
	cin >> s;
	VVLL dp(2020, VLL(2, 0));
	dp[s[0] - '0'][0] = 1;
	//dp[s[0] - '0'][1] = 1;
	ll ans = 0;
	FOR(i, 1, s.size()) {
		ll k = s[i] - '0';
		REP(j, 2020) {
			dp[(j * 10 + k) % 2019][1] += dp[j][0];
		}
		dp[k][1]++;
		REP(j, 2020) {
			dp[j][0] = dp[j][1];
			dp[j][1] = 0;
		}
		ans += dp[0][0];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		
		int cnt = 0;
		for (int x = 0; x <= k && x <= s; x++) {
			for (int y = 0; y <= k && x + y <= s; y++) {
				if (s - x - y <= k) cnt++;
			}
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
	
}




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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin>>n;
  string s;
  cin>>s;

  vector<int> as;
  for(char c:s) as.emplace_back(c-'1');

  auto comb=[&](int n,int k){return (n|k)==n;};

  {
    int parity=0;
    for(int i=0;i<n;i++)
      parity+=comb(n-1,i)*(as[i]==1);
    parity%=2;
    if(parity) drop(1);
  }

  if(count(as.begin(),as.end(),1)) drop(0);

  {
    int parity=0;
    for(int i=0;i<n;i++)
      parity+=comb(n-1,i)*(as[i]==2);
    parity%=2;
    drop(parity*2);
  }
  return 0;
}


Measured memory_bytes: 9024
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main(){
	daman;
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
		
	sort(arr,arr+n);
	
	lli sum = 0;
	for(int i=0;i<k;i++)
		sum += arr[i];
		
	cout<<sum<<"\n";
	
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, h;
    cin >> n >> h;
    vector<P> attack;
    rep(i, n){ 
        int a, b;
        cin >> a >> b;
        attack.emplace_back(a, 1);
        attack.emplace_back(b, 0);
    }
    sort(attack.begin(), attack.end(), greater<P>());

    int ans = 0;
    int sum = 0;
    for(auto at: attack){
        if (at.second == 0){
            sum += at.first; 
            ans++;
        } else {
            //この攻撃を繰り返す
            int num = ((h-sum)+at.first-1)/at.first;
            ans+=num;
            break;
        }
        if (sum >= h){
            break;
        }
    }
    
    cout << ans << endl;

}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const ll INF = 1e18;
const int MX = 100001;

int stir[3001][3001];

int N,MOD;

template<int SZ> struct Combo {
    ll fac[SZ+1], ifac[SZ+1];
    
    void init () {
        fac[0] = ifac[0] = 1;
    	FOR(i,1,SZ+1) {
    	    fac[i] = i*fac[i-1] % MOD;
    	    ifac[i] = inv(fac[i]);
    	}
    }
    
    ll po (ll b, ll p) { return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD; }
    ll inv (ll b) { return po(b,MOD-2); }
    
    ll comb(ll a, ll b) {
        if (a < b || b < 0 || a < 0) return 0;
        ll tmp = fac[a]*ifac[b] % MOD;
        tmp = tmp*ifac[a-b] % MOD;
        return tmp;
    }
};

Combo<3001> C;


ll po (ll b, ll p, ll m) { return !p?1:po(b*b%m,p/2,m)*(p&1?b:1)%m; }

ll ad(ll a, ll b) { return (a+b)%MOD; }
ll sub(ll a, ll b) { return (a-b+MOD)%MOD; }
ll mul(ll a, ll b) { return a*b%MOD; }


int solve(int bad) {
    int rem = N-bad;
    ll po2[bad+1]; 
    po2[0] = 1;
    po2[1] = po(2,rem,MOD);
    FOR(i,2,bad+1) po2[i] = mul(po2[i-1],po2[1]);
    ll t = 0;
    F0R(i,bad+1) {
        t = ad(t,mul(stir[bad][i],po2[i]));
        if (i) t = ad(t,mul(i,mul(stir[bad][i],po2[i-1])));
    }
    t = mul(t,po(2,po(2,rem,MOD-1),MOD));
    t = mul(t,C.fac[N]);
    t = mul(t,C.ifac[N-bad]);
    t = mul(t,C.ifac[bad]);
    return t;
} 

void genStir() {
    stir[0][0] = 1;
    FOR(i,1,3001) FOR(j,1,3001) stir[i][j] = ad(mul(j,stir[i-1][j]),stir[i-1][j-1]);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> MOD;
    genStir();
    C.init();
    ll ans = 0;
    F0R(i,N+1) {
        if (i&1) ans = sub(ans,solve(i));
        else ans = ad(ans,solve(i));
    }
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 35456
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define N 101000
#define ll long long
using namespace std;
int n,ans=0;
ll a[N],b[N];
map<ll,int> s;
map<ll,bool> bz;
int main()
{
	scanf("%d",&n);
	fo(i,1,n)
	{
		ll x;scanf("%lld",&x);
		a[i]=b[i]=1;
		fo(j,2,2155)
		if(x%j==0)
		{
			ll t=j*j*j;
			while(x%t==0) x/=t;
			t=j*j;
			if(x%t==0) a[i]*=t,b[i]*=j;
			else if(x%j==0) a[i]*=j,b[i]*=t;
			while(x%j==0) x/=j;
		}
		if(x)
		{
			ll t=sqrt(x);
			if(t*t==x) a[i]*=x,b[i]*=t;
			else a[i]*=x,b[i]*=x*x;
		}
	}
	fo(i,1,n) s[a[i]]++;
	fo(i,1,n)
	if(!bz[a[i]])
	{
		bz[a[i]]=1;
		if(a[i]==b[i]) ans++;
		else ans+=max(s[a[i]],s[b[i]]),bz[b[i]]=1;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 26752
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    int a, b, c; cin >> a >> b >> c;
    cout << min({a, b, c}) << " " << max({a, b, c}) << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

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

#define DEBUG
#undef DEBUG

using ll = long long;

ll N;

int F(ll a, ll b)
{
    return static_cast<int>(log10(max(a,b))) + 1;
}

int main()
{
    cin >> N;

    int f_min = 99999;
    ll isqrt = static_cast<ll>(sqrt(N));
    FOR(i, 1, isqrt+1) {
        if(N % i == 0) {
            int f = F(i, N/i);
            if(f < f_min) {
                f_min = f;
            }
        }
    }

    cout << f_min << "\n";

    return 0;
}


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

#define INF 1000000000000


int main(){

  string n;cin>>n;
  if(n[0]=='7' || n[1]=='7' || n[2]=='7'){cout<<"Yes";}
  else cout<<"No";

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = 0x3f3f3f3f;

int dp[(1<<21)+5];
bool g[22][22];
int n;

void add(int &a, int b)
{
    a += b;
    if(a>=mod)
        a-=mod;
}

bool check(int i, int mask)
{
    int a=0;
    while(mask)
    {
        a += (mask&1);
        mask>>=1;
    }
    return (a==i-1);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            cin >> g[i][j];
    dp[0]=1;
    for(int i=1; i<=n; i++)
    {
        for(int mask=0; mask<(1<<n); mask++)
        {
            if(!check(i, mask)) continue;
            for(int j=1; j<=n; j++)
            {
                if(!g[i][j]||(mask&(1<<(j-1)))) continue;
                add(dp[(mask|(1<<(j-1)))], dp[mask]);
            }
        }
    }
    cout << dp[(1<<n)-1];
}


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

int main() {
    int N,K;
    cin>>N>>K;
    bitset<100> b;
    for (int i = 0; i < K; i++){
        int d;
        cin>>d;
        for (int j = 0; j < d; j++){
            int a;
            cin>>a;
            b.set(a-1);
        }
    }
    cout<<N-b.count()<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> edges(n);
    vector<pair<int, int>> v;
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
        v.emplace_back(a, b);
    }
    int ans = INF<int>;
    for (int i = 0; i < n-k%2; ++i) {
        stack<pair<int, int>> S;
        vector<int> dist(n, INF<int>);
        if(k % 2 == 0) S.emplace(i, 0);
        else {
            S.emplace(v[i].first, 0);
            S.emplace(v[i].second, 0);
        }
        int p = 0;
        while(!S.empty()){
            int x, c;
            tie(x, c) = S.top(); S.pop();
            for (auto &&j : edges[x]) {
                if(c+1 < dist[j]) S.emplace(j, c+1);
            }
            dist[x] = min(dist[x], c);
        }
        for (int j = 0; j < n; ++j) {
            if(dist[j] > k/2) p++;
        }
        ans = min(ans, p);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
N, M = map(int,input().split())
X = list(map(int,input().split()))

X =sorted(X)

y = []
for i in range(M-1):
    m = X[i+1] - X[i]
    y.append(m)
y = sorted(y)

z = 0
for i in range(len(y)-N+1):
    z += y[i]
print(z)

Measured memory_bytes: 13968
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long prev[3]={0};

    long i, j;
    for(i=0; i<n; i++) {
        long a[3];
        scanf("%ld %ld %ld", &(a[0]), &(a[1]), &(a[2]));
        long curr[3] = {MAX(prev[1],prev[2])+a[0], MAX(prev[2],prev[0])+a[1], MAX(prev[0],prev[1])+a[2]};

        prev[0]=curr[0];
        prev[1]=curr[1];
        prev[2]=curr[2];
    }
    printf("%d\n", MAX(MAX(prev[0],prev[1]),prev[2]));

    return 0;
}


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

char a[1001][1001];
int mod = 1e9+7;

int dp[10001][10001];
ll solve(int i, int j, int n, int m){
	
	if(i==(n-1) && j==(m-1))
		return 1;
	
	if(i>=n || j>=m)
		return 0;
		
	if(a[i][j] == '#')
		return 0;
	
	if(dp[i][j] != -1)
		return dp[i][j];
	
	ll ans=0;
	
	ans = (solve(i+1, j, n, m) % mod) + (solve(i, j+1, n, m) % mod);
	
	return dp[i][j] = ans%mod;
}

void solve(){
	int n, m;
	cin >> n >> m;
	
	memset(dp, -1, sizeof dp);
	
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			cin >> a[i][j];
			
	cout << solve(0, 0, n, m);
}

int main(){
	solve();
}


Measured memory_bytes: 395412
#include <stdio.h>

void judgeOddEven(){
  int a, b;
  scanf("%d %d", &a, &b);
  if((a*b)%2 == 0){
    printf("Even");
  }else{
    printf("Odd");
  }
}

int main(){
  judgeOddEven();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < b; i++) {
    if (a * i % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

int main() {
    int N, W; cin >> N >> W;
    vector<vector<ll>> dp(N+1, vector<ll> (W+1));
    for (int i = 0; i <= W; i++) {
        dp[0][i] = 0;
    }
    ll w, v;
    for (int i = 1; i <= N; i++) {
        cin >> w >> v;
        for (int j = 0; j <= W; j++) {
            if (j >= w)
                dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j]);
            else
                dp[i][j] =  dp[i-1][j];
        }
    }
    cout << *max_element( dp[N].begin(), dp[N].end() ) << endl;;
}


Measured memory_bytes: 80256
use proconio::input;

fn main() {
    input! {
        x: i32,
    }
    let num = match x {
        400..=599 => 8,
        600..=799 => 7,
        800..=999 => 6,
        1000..=1199 => 5,
        1200..=1399 => 4,
        1400..=1599 => 3,
        1600..=1799 => 2,
        1800..=1999 => 1,
        _ => unreachable!(),
    };
    println!("{}", num);
}

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t h,n;
  cin >> h >> n;
  int64_t s[n];
  int64_t i,sum=0;
  for(i=0;i<n;i++){
    cin >> s[i];
    sum+=s[i];
  }
  if(sum>=h){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>

int main(){
    int v,n;
    //int a = 0;
    long int min = 1000000;
    long int max = -1000000;
    long int total = 0;
    std::cin >> n;
    for(int a=0; a<n; a++){
        std::cin >> v;
        if(v <= min)min = v;
        if(v >= max)max = v;
        total = total + v;
    }
    std::cout << min <<" "<< max <<" "<< total<<std::endl;
    return 0;

}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

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

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

template<class T>
bool chmax(T &a, initializer_list<T> l)
{
	return chmax(a, *max_element(l.begin(), l.end()));
}

template<class T>
bool chmin(T &a, initializer_list<T> l)
{
	return chmin(a, *min_element(l.begin(), l.end));
}

ll N;
vector<vector<ll>> G;

const ll MAX = 1000*1000+10;
ll seen[MAX];
ll d[MAX];

ll dfs(ll n)
{
	if (seen[n] == 2) return d[n];
	seen[n] = 1;
	for (auto &nv : G[n])
	{
		if (seen[nv] == 1)
		{
			std::cout << -1 << std::endl;
			exit(0);
		}
		chmax(d[n], dfs(nv) + 1);
	}
	seen[n] = 2;
	return d[n];
}

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N;
	G.resize(N*(N-1) / 2 + 1);

	auto f = [](ll i, ll j) -> ll
			 {
				 if (i < j) swap(i, j);
				 return i * (i - 1) / 2 + j + 1;
			 };

	REP(i, N)
	{
		ll pre = 0;
		REP(j, N-1)
		{
			ll a; cin >> a;
			--a;
			ll now = f(i, a);
			G[pre].push_back(now);
			pre = now;
		}
	}
	std::cout << dfs(0) << std::endl;
	return 0;
}


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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int h, w;
	while (cin >> h >> w){
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << ((i + 1 + j + 1) % 2 == 0 ? "#" : ".");
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
	cin >> n;
	vi v(n);
	REP(i,n) {
		cin >> v[i];
	}
	vi va;
	va.push_back(abs(v[0] - 0));
	REP(i,n-1) {
		va.push_back(abs(v[i + 1] - v[i]));
	}
	va.push_back(abs(v[n - 1] - 0));
	sum = accumulate(ALL(va), 0LL);
	REP(i,n) {
		if(i==0){
			cout << sum - va[i] - va[i + 1] + abs(v[i + 1]) << endl;
		}else if(i==n-1){
			cout << sum - va[i] - va[i + 1] + abs(v[i - 1] - 0) << endl;
		}else{
			cout << sum - va[i] - va[i + 1] + abs(v[i + 1] - v[i - 1]) << endl;
		}
	}
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
    
  ll N, ans = 0;
  cin >> N;
  for(ll i = 1; i < N; i++){
    ans += (N-1)/i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,k;
    cin>>n>>k;
    n=n%k;
    n=min(n,abs(n-k));
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
from collections import deque
k=int(input())
ans=[]
d=deque([1,2,3,4,5,6,7,8,9])
c=0
while c<11:
    q=d.popleft()
    ans.append(q)
    c=len(str(q))
    b=q%10
    if b!=0:
        d.append(q*10+b-1)
    d.append(q*10+b)
    if b!=9:
        d.append(q*10+b+1)
    
print(ans[k-1])

Measured memory_bytes: 29176
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s;
	cin >> s;
	int cnt[26];
	fill(cnt, cnt+26, 0);

	for(int i=0; i<s.length(); i++){
		cnt[s.at(i)-'a']++;
	}

	for(int i=0; i<26; i++){
		if(cnt[i]%2 == 1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];
  Int ans=0,lst=1e9+1;
  for(Int i=0;i<n;i++){
    if(as[i]<=lst) ans++;
    lst=as[i];
  }
  cout<<ans<<endl<<n<<endl;
  return 0;
}



Measured memory_bytes: 3560
using System;
class Program
{
    static void Main(String[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int K = int.Parse(Console.ReadLine());
        int X = int.Parse(Console.ReadLine());
        int Y = int.Parse(Console.ReadLine());

        if (N > K) Console.WriteLine(X * K + Y * (N - K));
        else Console.WriteLine(X * N);

    }
}


Measured memory_bytes: 2648
#include<iostream>

using namespace std;

int calc_abso(int a,int b){
    int abso;
    if(a>=b){
        abso=a-b;
    }else if(a<b){
        abso=b-a;
    }
    return abso;
}

struct WEAR{
    int min;        //適す最高気温(下限)
    int max;        //適す最高気温(上限)
    int looks;      //派手さ
};

int dp[256][256]={{0}};    //[日数][服の種]    //値は派手さの絶対値の合計（一番大きいものを最終的に取るように）


int main (void){
    int D,N;
    WEAR status[256];
    int tempe[256];

    cin >> D >> N;

    for(int i=0;i<D;i++){
        cin >> tempe[i];
    }
    for(int i=0;i<N;i++){
        cin >> status[i].min >> status[i].max >> status[i].looks;
        //cout << status[i].min << status[i].max << status[i].looks << endl;
    }
    for(int j=0;j<N;j++){
        if((status[j].min<=tempe[0])&&(status[j].max>=tempe[0])){       //この服が初日適しているか？

        }else{
            dp[0][j]=-1;
        }
    }

    for(int i=1;i<D;i++){
        //cout << "###DBG" << i;
        for(int j=0;j<N;j++){
            //cout << "\tbef:" << dp[i][j];
            if((status[j].min<=tempe[i])&&(status[j].max>=tempe[i])){      //この服が今日適しているか？
                int MAX_tortal=-1;    //(前日の服との差+それまで)の最大値
                for(int k=0;k<N;k++){   //前日の服
                    if(dp[i-1][k]!=-1){
                        int THIS_tortal=calc_abso(status[j].looks , status[k].looks)+dp[i-1][k];
                        //cout<< "\tadd" << THIS_tortal;
                        //cout << "###DBG" << endl;
                        if(THIS_tortal>MAX_tortal){
                            MAX_tortal=THIS_tortal;
                        }
                    }
                }
                dp[i][j]+=MAX_tortal;
            }else{
                dp[i][j]=-1;
            }
            //cout << "\taft:" << dp[i][j] << "/";
        }
        //cout << endl;
    }

    int LAST_MAX_tortal=-1;
    for(int i=0;i<N;i++){
        if(dp[D-1][i]>LAST_MAX_tortal){
            LAST_MAX_tortal=dp[D-1][i];
        }
    }

    cout << LAST_MAX_tortal << endl;


    return 0;
}

Measured memory_bytes: 1364
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
l_d = [0]*(n-1)
r_d = [0]*(n-1)
for i in range(n-1):
    l_d[i] = gcd(l_d[i-1], a[i])
    r_d[i] = gcd(r_d[i-1], a[n-i-1])
ans = max(l_d[-1], r_d[-1])
for i in range(n-2):
    ans = max(ans, gcd(l_d[i], r_d[n-i-3]))
print(ans)

Measured memory_bytes: 89580
main = do
  n <- readLn :: IO Int
  bs <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ let k = breakBricks bs in if k == length bs then -1 else k

foldlState :: (c -> a -> b -> (c, a)) -> c -> a -> [b] -> a
foldlState f s a l = snd $ foldl (\(s,a) -> f s a) (s, a) l

breakBricks bs = foldlState step 1 0 bs
    where step k n b = if k == b then (k+1, n) else (k, n+1)


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int k,n;
	cin>>k>>n;
	vector<int> h(n);
	for (auto &i : h){
		cin>>i;
	}
	sort(h.begin(),h.end());
	int ma = 0;
	for (int i = 1; i < n; ++i){
		ma = max(ma, h[i] - h[i-1]);
	}
	ma = max(ma, k-h[n-1]+h[0]);
	cout<<k - ma<<endl;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = k;
    
    rep(i, (n - 1)) {
        ans *= (k - 1);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256