akhauriyash/Code-Regression huggingface dataset:
import sys
from heapq import heappush, heappop

# わからん
pq = []
lines = sys.stdin.readlines()
for line in lines:
    op = line.strip().split(' ')
    if op[0] == 'insert':
        heappush(pq, -int(op[1]))
    elif op[0] == 'extract':
        print(-heappop(pq))
    else:
        break

# import sys, time
#
# class PriorityQueue:
#     __slots__ = ['nodes', 'num']
#
#     def __init__(self):
#         self.nodes = []
#         self.num = 0
#
#     def max_heapify(self, i):
#         if i >= self.num: return
#         left, right = (i+1)*2-1, (i+1)*2
#
#         largest = i
#         if left < self.num and self.nodes[i] < self.nodes[left]: largest = left
#         if right < self.num and self.nodes[largest] < self.nodes[right]: largest = right
#
#         if largest != i:
#             self.nodes[i], self.nodes[largest] = self.nodes[largest], self.nodes[i]
#             self.max_heapify(largest)
#
#     def extract_max(self):
#         if self.num < 1: return
#         max = self.nodes[0]
#         self.nodes[0] = self.nodes[-1]
#         self.nodes.pop()
#         self.num -= 1
#         self.max_heapify(0)
#         return max
#
#     def insert(self, key):
#         self.nodes.append(key)
#         self.num += 1
#         i = self.num-1
#         par = lambda i: (i-1)//2
#         while i > 0 and self.nodes[par(i)] < self.nodes[i]:
#             self.nodes[i], self.nodes[par(i)] = self.nodes[par(i)], self.nodes[i]
#             i = par(i)
#
#     def print_element(self):
#         for node in self.nodes:
#             print('', node, end='')
#         print('')
#
# pq = PriorityQueue()
#
# start = time.time()
# lines = sys.stdin.readlines()
# for line in lines:
#     op = line.strip().split(' ')
#     if op[0] == 'insert':
#         pq.insert(int(op[1]))
#     elif op[0] == 'extract':
#         # print(pq.extract_max())
#         pq.extract_max()
#     else:
#         break
# print('elapsed:', time.time()-start)



Measured memory_bytes: 188224
def main():
    n = int(input())
    a = 'abcdefghijklmnopqrstuvwxyz'
    ans = []
    while n:
        ans.append(a[(n-1) % 26])
        if (n-1) % 26 == 25:
            n -= 1
        n //= 26
    print("".join(reversed(ans)))


main()


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

long long X, Y;
long long M = 1000000007;

int main() {
    cin >> X >> Y;

    long long x = X;
    long long y = Y;
    
    long long A = 0;
    long long B = 0;

    while (x > 0 && y > 0) {
        bool xy = x <= y;
        ++A;
        B += xy ? 1 : 0;
        x -= xy ? 1 : 2;
        y -= xy ? 2 : 1;
    }

    if (x != 0 || y != 0) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1;

    for (long long i = A - B + 1; i <= A; ++i) {
        ans = ans * i % M;
    }

    long long b = 1;

    for (long long i = 2; i <= B; ++i) {
        b = b * i % M;
    }

    long long b5 = 1;

    for (int i = 0; i < 5; ++i) {
        b5 = b5 * b % M;
    }

    long long b10_9;
    long long bb = b;

    for (int i = 0; i < 9; ++i) {
        b10_9 = 1;
        for (int j = 0; j < 10; ++j) {
            b10_9 = b10_9 * bb % M;
        }
        bb = b10_9;
    }

    long long b10_9_5 = b10_9 * b5 % M;

    ans = ans * b10_9_5 % M;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  }
}
    

Measured memory_bytes: 19820
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
	return 0;
}

Measured memory_bytes: 384
# ABC066C - pushpush (ARC077)
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B, x = deque(), N & 1
    for i, a in enumerate(A, start=x):
        if i & 1:
            B.appendleft(a)
        else:
            B.append(a)
    print(*B)


if __name__ == "__main__":
    main()

Measured memory_bytes: 25948
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

string s, t;
int dp[3100][3100];

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

  rep(i,s.size()) {
    rep(j,t.size()) {
      if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }

  // 復元
  string ans;
  int i = sz(s), j = sz(t);
  while (i>0 && j>0) {
    if (dp[i][j] == dp[i-1][j]) --i;
    else if (dp[i][j] == dp[i][j-1]) --j;
    else {
      ans = s[i-1] + ans;
      --i, --j;
    }
  }

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

Measured memory_bytes: 37120
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a_index = 0;
    REP(i, s.size()){
        if(s[i] == 'A') {
            a_index = i;
            break;
        }
    }
    FORR(i, s.size() - 1, a_index + 1){
        if(s[i] == 'Z'){
            cout << i - a_index + 1 << "\n";
            return 0;
        }
    }
    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);
    vi a(N);

    Rep(i,N){
        Scd(a[i]);
    }

    int l = 0, r = 1e9;
    int c;
    ll sum;

    while( r-l > 1 ){
        c = (r+l)/2;
        sum = 0;
        Rep(i,N) sum += (a[i]-1)/c;
        if( sum > K ) l = c;
        else r = c;
    }

    printf ("%d\n", r );

    return 0;
}




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

const int MAX = 200001;

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

  int pop_count_origin = count(x.begin(), x.end(), '1');
  int pop_count_m = pop_count_origin - 1;
  int pop_count_p = pop_count_origin + 1;

  int x_m_origin = 0;
  int x_p_origin = 0;
  rep(i, n) {
    if (pop_count_m != 0)
      x_m_origin = (x_m_origin * 2 + int(x[i] - '0')) % pop_count_m;
    x_p_origin = (x_p_origin * 2 + int(x[i] - '0')) % pop_count_p;
  }

  vector<int> pow_m(MAX, 1);
  vector<int> pow_p(MAX, 1);
  for (int i = 1; i < MAX; i++) {
    if (pop_count_m != 0) pow_m[i] = (pow_m[i - 1] * 2) % pop_count_m;
    pow_p[i] = (pow_p[i - 1] * 2) % pop_count_p;
  }

  vector<int> f(MAX);
  vector<int> pop_count(MAX);
  for (int i = 1; i < MAX; i++) {
    pop_count[i] = pop_count[i / 2] + i % 2;
    f[i] = f[i % pop_count[i]] + 1;
  }

  rep(i, n) {
    if (x[i] == '1') {
      if (pop_count_m != 0) {
        int next = (x_m_origin - pow_m[n - 1 - i]) % pop_count_m;
        if (next < 0) next += pop_count_m;
        cout << f[next] + 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      int next = (x_p_origin + pow_p[n - 1 - i]) % pop_count_p;
      if (next < 0) next += pop_count_p;
      cout << f[next] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6740
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a-c<0)cout<<"0"<<endl;
	else cout<<(a-c)/(b+c)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int E=0, F=0;
  if(A%D != 0) E++;
  if(C%B != 0) F++;
  if(A/D + E >= C/B +F){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3620
#include<stdio.h> 
#include<string.h> 
int main(){ 
  int n; 
  char s[10010]; 
  scanf("%d%s",&n,&s); 
  int len=strlen(s); 
  for(int i=0;i<len;i++){ 
    int x=s[i]-'A'; 
    x=(x+n)%26; 
    putchar('A'+x); 
  } 
  putchar('\n'); 
}


Measured memory_bytes: 128
# get n
loop do
  n = gets.to_i

  if n == 0
    break
  end

  # initialize scores
  score_a = 0
  score_b = 0

  # compare cards and add score
  n.times do
    card_a, card_b = gets.split(" ").map(&:to_i)
    if card_a > card_b
      score_a += card_a + card_b
    elsif card_a < card_b
      score_b += card_a + card_b
    else
      score_a += card_a
      score_b += card_b
    end
  end

  # output each result
  puts "#{score_a} #{score_b}"
end

Measured memory_bytes: 8764
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
 
main = abc161c

abc161c = do
    [n, k] <- getIntList
    let init = snd (divMod n k)
    let initV = V.fromList [init]
    print $ V.foldl' min n (operation initV init k)

operation :: V.Vector Integer -> Integer -> Integer -> V.Vector Integer
operation vec n k = let abs' = abs (n-k) in
    if V.elem abs' vec
        then vec
        else operation (V.cons abs' vec) abs' k

checkSelect :: Integer -> Integer -> Integer -> Bool
checkSelect m sum prod
    | prod * 4 * m < sum  = False
    | otherwise = True


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine


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

int main() {
    int n,m,k,temp,ans=0;
    cin>>n>>m;
    vector<int> a(m,0);
    rep(i,n) {
        cin>>k;
        rep(j,k) {
            cin>>temp;
            a[temp-1]++;
        }
    }
    rep(i,m) {
        if (a[i]==n) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int a[200005],b[200005];
bool cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1,cmp);
    if(n%2) printf("%d\n",b[n/2+1]-a[n/2+1]+1);
    else printf("%d\n",b[n/2+1]-a[n/2+1]+b[n/2]-a[n/2]+1);
    return 0;
}


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

vector<int> touroku(int n){
	vector<int> menber;
	int a;
	for(int i=0;i<n;i++){
		cin>>a;
		menber.push_back(a);
	}
	return menber;
}

int main(){
	int N;
	cin>>N;
	int menber[N]={};
	int A_num,B_num,C_num;
	cin>>A_num;
	vector<int> A_men=touroku(A_num);
	cin>>B_num;
	vector<int> B_men=touroku(B_num);
	cin>>C_num;
	vector<int> C_men=touroku(C_num);
	int num=0;
	int cnt=0;
	for(int i=0;i<C_num;i++){
		menber[i]=C_men[i];
		for(int j=0;j<B_num;j++){
			if(menber[i]==B_men[j]){
				cnt++;
				menber[i]=0;
				break;
			}
		}
		if(menber[i]!=0){
			int l=1;
			for(int m=0;m<A_num;m++){
				if(A_men[m]==menber[i]){
					l=0;
				}
			}
			if(l==1){
				cnt++;
			}	
		}
	}
	cout<<cnt<<endl;
	return 0;
	}


Measured memory_bytes: 3176
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

map<int,int> ma;
int n,m;

int main(){
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		ma[x]++;
	}
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		int x;
		scanf("%d",&x);
		if(ma[x]>=1)
			ma[x]--;
		else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS  

   int n; cin>>n;

    vi mp(n+1);

   for(int i = 0; i < n-1; i++){
       int x; cin>>x;
       mp[x]++;
   }
    
    
    for(int i =1; i <= n; i++){
        cout<<mp[i]<<"\n";
    }

   


    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 4000
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int key;
    struct Node *prev;
    struct Node *next;
};
   
struct Node *note;
   
void insert(int key) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->key = key;
    note->next->prev = x;
    x->next = note->next;
    note->next = x;
    x->prev = note;
}
   
struct Node* search(int key) {
    struct Node *x = note->next;
    while(x != note && x->key != key ) {
        x = x-> next;
    }
    return x;
}
   
void deleteNode(struct Node *t) {
    if (t == note) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
   
void deleteFirst() {
    deleteNode(note->next);
}
   
void deleteLast() {
    deleteNode(note->prev);
}
void deleteKey(int key) {
    deleteNode(search(key));
}
   
void printList() {
    struct Node *x;
    x = note->next;
    int isf = 0;
    while(1) {
        if (x == note) break;
        if(isf++ > 0) printf(" ");
        printf("%d", x->key);
        x = x->next;
    }
    printf("\n");
}
   
   
int main(void) {
    int key, n;
    char order[20];
    scanf("%d", &n);
    note = (struct Node *)malloc(sizeof(struct Node));
    note->next = note;
    note->prev = note;
    for (int i = 0; i < n; i++) {
        scanf("%s%d",order, &key);
        if(order[0] == 'i') {
            insert(key);
        }else if(order[0] == 'd') {
            if(strlen(order) > 6) {
                if( order[6] == 'F') {
                    deleteFirst();
                }else if(order[6] == 'L') {
                    deleteLast();
                }
            }else {
                deleteKey(key);
            }
        }
    }
    printList();
    return 0;
}

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

int main(void){
    int n;
    cin>>n;
    unordered_map<string, int> mp;
    rep(i, n){
        string s;
        cin>>s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto p : mp){
        ll l=(ll)(p.second);
        ans+=l*(l-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

  const int MOD = 1000000007;
  

  #include <cstdint>

  template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
      return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
      return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
      return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
      return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
      a += rhs.a;
      if (a >= Modulus) {
        a -= Modulus;
      }
      return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
      if (a < rhs.a) {
        a += Modulus;
      }
      a -= rhs.a;
      return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
      a = a * rhs.a % Modulus;
      return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
      u64 exp = Modulus - 2;
      while (exp) {
        if (exp % 2) {
          *this *= rhs;
        }
        rhs *= rhs;
        exp /= 2;
      }
      return *this;
    }
  };



int main(){
  ll N,K;
  cin >> N >> K;
  
  vector<ll> S1(N);
  vector<ll> S2(N);
  
  vector<ll> A(N);
  
  rep(i,N){
    ll a;
    cin >> A[i];
  }
  
  rep(i,N){
    ll count1 = 0;
    ll count2 = 0;
    rep(j,N){
      if(A[i]>A[j]){
        count1 += 1;
        if(j>i)count2 += 1;
      }
    }
    S1[i] = count1;
    S2[i] = count2;
  }
  
  ll sum1 = 0;
  ll sum2 = 0;
  
  for(ll n: S1){
    sum1 += n;
  }
  
  for(ll n: S2){
    sum2 += n;
  }
  
  // ll ans = ( ( (sum2%MOD) * (K%MOD) )%MOD ) + ( (((sum1%MOD)*(((K-1)%MOD)*(K%MOD))%MOD)%MOD)*modinv(2, MOD)%MOD );
  ll ans = 0;
  
  modint<MOD> s1,s2,k,km1,n2;
  s1.a = sum1;
  s2.a = sum2;
  k.a = K;
  km1.a = K-1;
  n2.a = 2;

  ans = ( ( sum2 * K )%MOD ) + ( ((sum1*((K-1)/2*K)%MOD)%MOD) );
  ans = (s2 * k + s1*km1*k/n2).a;
  
  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 P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int f[100][10];
int p[100][11];
int s[10];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  REP(i,n)REP(j,10)cin>>f[i][j];
  REP(i,n)REP(j,11)cin>>p[i][j];
  ll maxn=-INF;
  ll tmp=0;
  REP(i1,2){
    REP(i2,2){
      REP(i3,2){
        REP(i4,2){
          REP(i5,2){
            REP(i6,2){
              REP(i7,2){
                REP(i8,2){
                  REP(i9,2){
                    REP(i10,2){
                      if(i1==0 && i2==0 && i3==0 && i4==0 && i5==0 && i6==0 && i7==0 && i8==0 && i9==0 && i10==0)continue;
                      int cnt=0;
                      tmp=0;
                      s[0]=i1;
                      s[1]=i2;
                      s[2]=i3;
                      s[3]=i4;
                      s[4]=i5;
                      s[5]=i6;
                      s[6]=i7;
                      s[7]=i8;
                      s[8]=i9;
                      s[9]=i10;
                      REP(i,n){
                        cnt=0;
                        REP(j,10){
                          if(s[j]==1 && f[i][j]==1){
                            cnt++;
                          }
                        }
                        tmp+=p[i][cnt];
                      }
                      maxn=max(maxn,tmp);
                      // P(maxn);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  P(maxn);
  return 0;
}


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

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

    int h[N];
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    int cost[N];
    cost[0] = 0; 
    cost[1] = abs(h[0] - h[1]);

    for(int i=2; i<N; i++){
        cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] + abs(h[i] - h[i-2]));
    }

    cout << cost[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
n, m = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(m)]

for i in range(10 ** (n - 1) if n>1 else 0, 10 ** n):
    s = str(i)
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            break
    else:
        print(i)
        break
else:
    print(-1)


Measured memory_bytes: 38384
import math

n = int(input())

def F(a, b, c, d) :
    return lambda x : a * x**3 + b * x**2 + c * x + d
    
def X(a, b, c) :
    a = 3 * a
    b = 2 * b
    
    try :
        D = math.sqrt(b**2 - 4 * a * c)
        
        if D == 0 :
            return 0
        else :
            return (-b + D) / (2 * a), (-b - D) / (2 * a)
        
    except :
        return -1
    
def boa(fz, lmax, lmin, p, n) :
    if fz > 0 :
        if lmin > 0 :
            p, n = 2, 1
        else :
            n = 3
    elif fz == 0 :
        if 0 < lmin and lmax < 0 :
            p, n = 1, 1
        elif lmax > 0 :
            p = 2
        else :
            n = 2
    else :
        if lmax > 0 :
            p = 3
        else :
            p, n = 1, 2
        
    return p, n
            
def ao(fz, lmax, p, n) :
    if fz > 0 :
        n = 2
    elif fz == 0 :
        if lmax == 0 :
            p = 1
        else :
            n = 1
    else :
        if lmax > 0 :
            p = 2
        else :
            p, n = 1, 1
        
    return p, n

def bo(fz, lmin, p, n) :
    if fz > 0 :
        if lmin > 0 :
            p, n = 1, 1
        else :
            n = 2
    elif fz == 0 :
        if lmin == 0 :
            n = 1
        else :
            p = 1
    else :
        p = 2
        
    return p, n
      
def aob(fz, p, n) :
    if fz > 0 :
        n = 1
    elif fz < 0 :
        p = 1
        
    return p, n
    
def P(x, y) :
    if x > 0 :
        print(y, 0)
    elif x < 0 :
        print(0, y)
    else :
        print(0, 0)
        
for i in range(n) :
    a, b, c, d = map(int, input().split())
    if a < 0 :
        a *= -1
        b *= -1
        c *= -1
        d *= -1
        
    f = F(a, b, c, d)
    
    p = 0
    # Positive integer
    n = 0
    # Negative integer
    
    if X(a, b, c) == -1 :
        P(-d, 1)
            
    elif X(a, b, c) == 0 :
        if f(-b / (3 * a)) == 0 :
            P(-b, 3)
        else :
            P(-d, 1)
            
    else :
        if f(X(a, b, c)[0]) < f(X(a, b, c)[1]) :
            lmax = X(a, b, c)[1]
            # Local maximum
            lmin = X(a, b, c)[0]
            # Local minimum
        else :
            lmax = X(a, b, c)[0]
            lmin = X(a, b, c)[1]
        
        fmax = f(lmax)
        fmin = f(lmin)
        fz = f(0)
        
        if lmax == lmin :
            if lmax < 0 :
                print(0, 3)
            elif lmax > 0 :
                print(3, 0)
            else :
                print(0, 0)
                
        elif fmin < 0 and 0 < fmax :
            pn = boa(fz, lmax, lmin, p, n)
            print(pn[0], pn[1])
            
        elif fmax == 0 :
            pn = ao(fz, lmax, p, n)
            print(pn[0], pn[1])
            
        elif fmin == 0 :
            pn = bo(fz, lmin, p, n)
            print(pn[0], pn[1])
            
        else :
            pn = aob(fz, p, n)
            print(pn[0], pn[1])
            


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep (i, 0, n) cin >> a[i] >> b[i];
    sort (a, a + n);
    sort (b, b + n);
    int ans;
    if (n % 2 == 0) {
        ans = ((b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1])) + 1;
    } else {
        ans = b[n / 2] - a[n / 2] + 1;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int c0 = 0;
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        for (int i = 0; i < n; i++) {
            String s = sc.nextLine();
            if(s.compareTo("AC") == 0){
                c0 ++;
            }else if(s.compareTo("WA") == 0){
                c1 ++;
            }else if(s.compareTo("TLE") == 0){
                c2 ++;
            }else if(s.compareTo("RE") == 0){
                c3 ++;
            }
        }
        System.out.println("AC x " + c0);
        System.out.println("WA x " + c1);
        System.out.println("TLE x " + c2);
        System.out.println("RE x " + c3);
    }
}

Measured memory_bytes: 50988
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	double t, x;
	cin >> t >> x;
	cout << t / x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d;
  	long long x,y,count=0;
  	cin>>n>>d;
  	while(n--){
    	cin>>x>>y;
      	long long product=0;
      	product=x*x;
      	//cout<<"<<<<"<<product<<"    >>>> ";
      	product+=y*y;
      	//cout<<product<<endl;
      	if(d>=pow(product,0.5)){
      		//cout<<"====>"<<x<<" "<<y<<" "<<d<<"   ---   "<<pow(product,0.5)<<endl;
      		count++;
		  }
    }
  cout<<count;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  i64 ans = 100000;
  rep(i, n) {
    ans = ans * 105 / 100;
    ans = (ans + 999) / 1000 * 1000;
  }
  cout << ans << '\n';
}



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

A[0]*=4
A[1]*=2
t1=10**10
for i in range(3):
   t1=min(t1,A[i])

A[0]*=2
A[1]*=2
A[2]*=2
t2=10**10
for i in range(4):
   t2=min(t2,A[i])

if(N%2==1):
    print(t2*(N//2)+t1)
else:
    print(t2*(N//2))

Measured memory_bytes: 38448
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;

int main()
{
	// 入力
	int a,b;
	cin >> a >> b;

	if(a>=13){
		cout<<b<<endl;
		return 0;
	} else if(a>=6){
		cout<<b/2<<endl;
		return 0;
	} else{
		cout<<0<<endl;
		return 0;
	}


	return 0;
}

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

using namespace std;

int arr[100011], n;

int32_t main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>arr[i];

	int ans[100011];

	ans[1] = abs(arr[1]-arr[0]);

	for(int i=2;i<n;i++)
	{
		ans[i] = min(abs(arr[i]-arr[i-1])+ans[i-1],abs(arr[i]-arr[i-2])+ans[i-2]);
	}

	cout<<ans[n-1]<<"\n";
	
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0630
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int a = ReadInt();
            int b = ReadInt();
            int c = ReadInt();
            int d = ReadInt();
            int e = ReadInt();
            Console.WriteLine(a > 0 ? (b - a) * e : b * e + d + (0 - a) * c);
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 17964
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
void solve()
{
    ll n;
    cin>>n;
    ll m;
    cin>>m;
    double a[n];
    double sum=0;
    ll x;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sum/=4;
    sum/=m;
    ll q=0;
    for(ll i=0;i<n;i++)
    {
        if(a[i]>=sum)
            q++;
    }
    if(q>=m)
        cout<<"Yes";
    else
        cout<<"No";
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n ,a[21] ,b[21] , c[21] , ans;
int main()
{
   cin >>n;
   for (int  i = 0 ; i < n ;i++)
    cin >> a[i] ;
   for (int  i = 0 ; i < n ;i++)
    cin >> b[i] ;
   for (int  i = 0 ; i < n - 1  ;i++)
    cin >> c[i] ;
    for (int  i = 0 ; i < n ;i++)
    {
        ans += b[a[i] - 1 ] ;
        //cout <<b[a[i] - 1 ] << endl;
        if (a[i]  == a[i - 1 ] + 1 && i > 0)ans += c[a[i - 1] - 1 ] ;
    }
    cout <<ans ;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;

int main() {

	long long a, b, c, k;

	cin >> a>>b >> c >> k;

	int sum = 0;

	sum += a <= k ? a : k;
	k -= (a+b);
	if (k <= 0) {
		cout << sum << endl;
		return 0;
	}

	sum -= c <= k ? c : k;

	cout << sum << endl;

	return 0;
}

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

int main(){
  int N;
  cin>> N;
  int64_t S =0;
  for(int i=1; i<N+1;i++){
    if(i%3 !=0 && i%5 !=0){
      S = S+i;
    }
  }
  cout << S << endl;
    
   
  
}



Measured memory_bytes: 3608
import java.util.Scanner;


public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        int Blength = S.length();
        boolean[] B = new boolean[Blength];
        
        for(int i=0;i<Blength;i++){
            if(S.charAt(i) == '0'){
                B[i] = true;
            }else{
                B[i] = false;
            }
        }
        
        int i = (Blength/2) -1;
        int j = Blength/2;
        
        int ans = Blength;
        
        while(i > -1 || j+1 < Blength){
            if(i > -1 && B[i]^B[i+1]){
                ans = Blength-1-i;
                break;
            }
            if(j+1 < Blength && B[j]^B[j+1]){
                ans = j+1;
                break;
            }
            i--;
            j++;
        }
        System.out.println(ans);
    }  
}


Measured memory_bytes: 25940
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll x,a,b;cin>>x>>a>>b;
  if(b<=a)cout<<"delicious"<<endl;
  else if(b<=a+x)cout<<"safe"<<endl;
  else cout<<"dangerous"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int n, k;
            ReadInt(out n, out k);
            string s = ReadString();

            StringBuilder sb = new StringBuilder(s);
            sb[k - 1] = char.ToLower(sb[k - 1]);

            Console.WriteLine(sb.ToString());
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,K,Z;
  int Y=0;
  cin >> A >> B >> K;
  for (int X=A; X<=A; X--){
    if (A%X==0 && B%X==0){
      Y++;
      if (Y==K){
        Z=X;
        break;
      }
    }
  }
  cout << Z << endl;
}

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

int main() { 
    ios_base::sync_with_stdio(false);
    long long n, i, k, sum = 0, num;
    cin >> n >> k;
    map<ll, ll> f;
    f[sum]++;
    for(i = 1; i <= n; i++) {
        cin >> num;
        sum = (sum + num%k)%k;
        f[sum]++;
    }
    sum = 0;
    for(map<ll,ll>::iterator it = f.begin(); it != f.end(); it++) {
        ll x = it->second;
        sum += (x*(x - 1))/2;
    }
    cout << sum << "\n";
    return 0; 
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#define MAX_SIZE 51

long long int max_score = 0;
int n, m, q;
std::vector<int> a(MAX_SIZE), b(MAX_SIZE), c(MAX_SIZE), d(MAX_SIZE);
std::vector<int> A(11, 1);


// 条件を満たす組み合わせを全探索
void tree_search(int depth){
	long long int score = 0;
	if(depth > n) return;
 	for(int i = 0; i < q; i++)
		if(A[b[i]-1] - A[a[i]-1] == c[i])
		       score += d[i];
	// std::cout << A[0] << A[1] << A[2] << std::endl;

	if(max_score < score) max_score = score;
	// std::cout << score << std::endl;

	
	for(int i = A[depth-1]; i <= m; i++){
		A[depth] = i;	
		tree_search(depth+1);
	}

	return;
}


int main(void){
	std::cin >> n >> m >> q;	

	for(int i = 0; i < q; i++)
		std::cin >> a[i] >> b[i] >> c[i] >> d[i];
	
	tree_search(1);
	std::cout << max_score << std::endl;
	
	return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mod=1e9+7;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n,k; cin>>n>>k;
	ll l=0, r=n-1;
	vector<ll> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	ll ret=1, sgn=1;
	if(k%2) ret=a[r], r--, k--, sgn=(ret<0 ? -1 : 1);
	while(k) {
		ll x=a[l]*a[l+1], y=a[r]*a[r-1];
		if(x*sgn>y*sgn) ret*=x%mod, ret%=mod, l+=2;
		else ret*=y%mod, ret%=mod, r-=2;
		k-=2;
	}
	cout<<(ret%mod+mod)%mod<<"\n";
	return 0;
}

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

using namespace std;

void dfs_visit(vector<int> adj[], int u, vector<bool> &v, vector<int> &top){
	v[u] = true;
	for(int i = 0; i < adj[u].size(); i++){
		if(!v[adj[u][i]])
			dfs_visit(adj, adj[u][i], v, top);
	}
	top.push_back(u);
}

void dfs(vector<int> adj[], vector<int> &top, int n){
	vector<bool> v(n, false);
	for(int i = 0; i < n; i++){
		if(!v[i])
			dfs_visit(adj, i, v, top);
	}
}

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> adj[n];
	for(int i = 0; i < m ; i++){
		int x, y;
		cin >> x >> y;
		adj[x-1].push_back(y-1);
	}
	vector<int> top;
	dfs(adj, top, n);
	int path[n];
	for(int i = 0; i < n; i++)
		path[i] = 0;
	for(auto i = top.begin(); i < top.end(); i++){
		for(int j = 0; j < adj[*i].size(); j++){
			if(path[*i] < path[adj[*i][j]] + 1){
				path[*i] = path[adj[*i][j]] + 1;
			}
		}
	}
	int max = 0;
	for(int i = 0; i < n; i++){
		if(max < path[i])
			max = path[i];
	}
	cout << max;
}

Measured memory_bytes: 9084
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n, k , q;
int a[200000];
signed main() {
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) {
		a[read()]++;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] + k - q <= 0) {
			cout << "No\n";
		}
		else {
			cout << "Yes\n";
		}
	}
}

Measured memory_bytes: 1408
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,a,b = li()
if a > b:
    print(0)
elif n == 1 and a != b:
    print(0)
elif n == 1:
    print(1)
else:
    print((a+(n-1)*b) - ((n-1)*a+b) + 1)
    

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

int main() {
    string S; cin >> S;
    if(S == "AAA" || S == "BBB") cout << "No" << '\n';
    else cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 256