akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cassert>
#include <string>
#include <cstring>
#include <bitset>
#include <stack>
#include <iomanip>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};

const int N = 1e2 + 5;
const int K = 1e5 + 5;
const int MOD = 1e9 + 7;

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

int a [N], dp [N][K], prefix [N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset (dp, 0, sizeof(dp));
  memset (a, 0, sizeof(a));
  int n, k;
  cin >> n >> k;
  FOR (i, 1, n + 1) {
    cin >> a[i];
  }
  dp[0][0] = 1;
  FOR (i, 1, n + 1) {
    prefix[0] = dp[i - 1][0];
    FOR (j, 1, k + 1) {
      prefix[j] = (prefix[j - 1] + dp[i - 1][j]) % MOD;
    }
    FOR (j, 0, k + 1) {
      add (dp[i][j], (prefix[j] - (j - a[i] - 1 >= 0 ? prefix[j - a[i] - 1] : 0) + MOD) % MOD);
    }
  }
  cout << dp[n][k] << '\n';
  return 0;
}

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

const int MAXN = 300 + 21;
int a[MAXN];
long long ans;
int main() {
 int n;
  cin >> n;
  for (int i = 0; i < 2 * n; i++)
  		cin >> a[i];
  sort(a, a + (2 * n));
  for (int i = 0; i < 2 * n; i+= 2) {
   	ans += a[i]; 
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7 && b==5 && c==5 || a==5 && b==5 && c==7 || a==5 && b==7 && c==5){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
using namespace std;
#define LATTE 10000

struct Way{
	int A,B,p,q;
	bool operator<(const Way &a)const{
		return B<a.B;
	}
};
Way way[100000];

int main(){
	int N,M,H,K,S[1000];
	while(cin>>N>>M>>H>>K,N||M||H||K){
		for(int i=0;i<N;i++){
			cin>>S[i];
		}
		for(int i=0;i<M;i++){
			cin>>way[i].A>>way[i].B; way[i].A--;
		}
		
		sort(way,way+M);
		int dp[1000];
		for(int i=0;i<N;i++) dp[i]=i;
		for(int i=0;i<M;i++){
			way[i].p = dp[way[i].A];
			way[i].q = dp[way[i].A+1];
			if(way[i].p>way[i].q) swap(way[i].p,way[i].q);
			swap(dp[way[i].A],dp[way[i].A+1]);
		}
		//for(int i=0;i<N;i++) printf("%d ",dp[i]); puts("");
		int latte[1000],sum=0;
		for(int i=0;i<N;i++){
			latte[dp[i]] = S[i];
			if(dp[i]<K) sum += S[i];
		}
		//printf("\t%d\n",sum);
		//for(int i=0;i<N;i++) printf("%d ",latte[i]); puts("");
		int ans=sum;
		for(int i=0;i<M;i++){
			if(way[i].p<K && K<=way[i].q) ans = min(ans,sum-latte[way[i].p]+latte[way[i].q]);
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 2736
for i in range(3000):
  h,w=(int(a) for a in input().split())
  if w==0 and h==0:
    break
  for j in range(h):
    for k in range(w):
      if j==0 or j==h-1 or k==0 or k==w-1:
        print("#",sep="",end="")
      else:
         print(".",sep="",end="")
    print("")
  print("")


Measured memory_bytes: 7016
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s=="AKIHABARA"||s=="KIHABARA"||s=="AKIHBARA"||s=="AKIHABRA"||s=="AKIHABAR"||s=="KIHBARA"||s=="KIHABRA"||s=="KIHABAR"||s=="AKIHBRA"||s=="AKIHBAR"||s=="AKIHABR"||s=="KIHBRA"||s=="KIHBAR"||s=="KIHABR"||s=="AKIHBR"||s=="KIHBR") {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()


N,M = na()
p = na()

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)
    
    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
        
    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
tr = UnionFind(N)
for i in range(M):
    q1,q2 = na()
    tr.Unite(q1,q2)
ans =0
for i in range(N):
    #p[i]がpの中でp[i]番目にある数字と同じグループにいたらOK
    tmp = p[p[i]-1]
    if(tr.isSameGroup(p[i],tmp)):
        ans+=1

print(ans)


Measured memory_bytes: 13940
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    ans = 1
    if 0 in A:
        print(0)
        sys.exit()
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 87768
#include <stdio.h>
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define ABS(x) ((x) < 0 ? (-1*(x)) : (x))
int main()
{
  int n;
  scanf("%d",&n);
  int h[n];
  int i = 0;
  while (i < n)
  {
    scanf("%d",&h[i]);
    i++;
  }
  //一つ手前の足場までの最小値を記録し、それを利用して計算量を減らす
  i = 0;
  int dp[n];
  while (i < n)
  {
    dp[i] = 0;
    i++;
  }
  i = 0;
  dp[0] = 0;
  dp[1] = ABS(h[0] - h[1]);
  //printf("dp[1]:%d\n",dp[1]);
  if (n == 2)
  {
    printf("%d",dp[1]);
    return (0);
  }
  //i-1とi-2、足場(i-1)-iのコスト+i-1までのコストと足場i-(i-2)のコスト+i-2までのコストを比較し
  //小さい方を選択する
  dp[2] = MIN(dp[1] + ABS(h[2]-h[1]), dp[0] + ABS(h[2]-h[0]));
  if (n == 3)
  {
    printf("%d",dp[2]);
    return (0);
  }
  
  i = 3;
  while (i < n)
  {
    dp[i] = MIN(ABS(h[i]-h[i-1]) + dp[i-1], ABS(h[i]-h[i-2]) + dp[i-2]);
    i++;
  }
  printf("%d",dp[i-1]);
}

Measured memory_bytes: 2484
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  if(S=="SAT"){
    cout<<"1";
  }else if(S=="FRI"){
    cout<<"2";
  }else if(S=="THU"){
    cout<<"3";
  }else if(S=="WED"){
    cout<<"4";
  }else if(S=="TUE"){
    cout<<"5";
  }else if(S=="MON"){
    cout<<"6";
  }else if(S=="SUN"){
    cout<<"7";
  }
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int a[10001],s,d,f,g,h,i,j;
	a[1]=0;
	for(i=2;i<=10000;i++){
		a[i]=1;
	}
	for(i=2;i<=5000;i++){
		if(a[i]!=0){
			s=2;
			while(i*s<=10000){
				a[i*s]=0;
				s++;
			}
		}
	}
	/*for(i=1;i<=10000;i++){
		if(a[i]==1){
			printf("%d\n",i);
		}
	}*/
	scanf("%d",&d);
	while(d!=0){
		for(i=d;i>=1;i--){
			if(a[i-2]==1&&a[i]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	scanf("%d",&d);		
	}
	return 0;
}

Measured memory_bytes: 1064
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int ans = 0;
  static bool flag = false;

  static int Main() {

    int cnt = 0;

    int n = int.Parse(Console.ReadLine());

    int[] h = new int[n];
    string[] nyu = Console.ReadLine().Split(' ');
    for (int i = 0; i < n;  i ++) {
      h[i] = int.Parse(nyu[i]);
    }
    // ここまで入力

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        if (h[j] > h[i]) {
          flag = true;
        }
      }
      if (!flag) {
        cnt++;
      }
      flag = false;
    }

    ans = cnt;

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;

  int n; cin >> n;
  string s[n]; REP(i,n) cin >> s[i];
  map<string, int> m;
  REP(i,n) m[s[i]]++;

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
  return 0;
}


Measured memory_bytes: 6788
let () = Scanf.scanf "%d\n" @@ fun n ->
  let fss =
    Array.to_list @@ Array.init n @@ fun _ ->
      Array.init 10 @@ fun _ ->
        Scanf.scanf "%d " @@ fun f -> f in
  let pss =
    Array.to_list @@ Array.init n @@ fun _ ->
      Array.init 11 @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  Array.init 1023 (fun opening ->
    let opening = opening + 1 in
    List.map2 (fun fs ps ->
      ps.(Array.fold_left ( + ) 0
        (Array.mapi (fun i f ->
          if f = 1 && (opening land (1 lsl i)) <> 0 then 1 else 0) fs))) fss pss
    |> List.fold_left ( + ) 0)
  |> Array.fold_left max min_int
  |> Printf.printf "%d\n"


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  int N;    cin>>N;
  vector<ll> v(N), v2(N);
  rep(i,0,N) cin>>v[i];
  sort(all(v), greater<ll>());
  ll ans = 0;
  int now = 0;
  rep(i,1,N){
    ans += v[now];
    if(i%2 == 1) now++;
  }
  cout << ans << endl;
  return 0;
}   

Measured memory_bytes: 6436
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, a, b;

    cin >> n >> a >> b;

    cout << n / (a + b) * a + min(n % (a + b), a) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<int>price(N);
  for(int i=0;i<N;i++){
    cin >> price[i];
  }
  
  sort(price.begin(), price.end());
  
  int ans = 0;
  
  for(int i=0;i<K;i++){
    ans += price[i];
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int total = 0;
    for(int i = 0; i < K; i++){
        total += p[i];
    }
    cout << total << endl;
    return 0;
}


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


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vec(n);
    int sum = 0;
    rep(i,n) {
        cin >> vec.at(i);
        sum += vec.at(i);
    }
    int ans = 0;
    if(sum%(4*m) == 0) {
    rep(i,n) {
        if(vec.at(i) >= sum/(4*m)) ans++;
        if(ans >= m) break;
    }
    } else {
        rep(i,n) {
            if(vec.at(i) > sum/(4*m)) ans++;
            if(ans >= m) break;
        }
    }
    if(ans >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
 
 
 
int main() {
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    int M[H+1][W+1];
    rep3(i,H){
        rep3(j,W){
            if(((i<=B)&&(j<=A))||((i>B)&&(j>A))){
                M[i][j]=1;
            }
            else{
                M[i][j]=0;
            }
        }
    }
    rep3(i,H){
        rep3(j,W){
            if(j!=W){
                cout<<M[i][j];
            }
            else{
                cout<<M[i][j]<<endl;
            }
        }
    }
    
 
    
   
return 0;
}


Measured memory_bytes: 7472
#!/usr/bin/env python
# coding: utf-8

def main():
	a, b = [int(x) for x in raw_input().split(" ")]
	d = a / b
	r = a % b
	f =  round(float(a) / b, 5)
	print d, r, f

if __name__ == '__main__':
	main()

Measured memory_bytes: 4252
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();

    if s == "ARC".to_string() {
        println!("ABC");
    }else{
        println!("ARC");
    }
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 5000 + 5 ;
int n, q, d[N], sum[N], pre[N], c[N] ; 
signed main()
{
	n = gi(), q = gi() ;
	rep( i, 1, n ) d[i - 1] = gi() ; 
	while( q-- ) {
		int l = gi(), x = gi(), M = gi() ;
		int Ans = 0, sum = 0, ans = 0 ; x %= M ;
		for( re int i = 0; i < n; ++ i ) {
			c[i] = d[i] % M, sum += c[i] ; 
			if( c[i] != 0 ) ++ ans ;
		}
		int mt = ( l - 1 ) / n ;
		int sumx = ( x + mt * sum ) ;
		Ans = ans * mt - ( sumx / M ) ;
		sumx %= M ; 
		for( re int i = 0; i < ( l - 1 ) % n; ++ i ) {
			sumx += c[i] ; 
			if( c[i] != 0 ) ++ Ans ; 
			if( sumx >= M ) sumx -= M, -- Ans ;
		}
		cout << Ans << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}
 

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<P> vp;

    rep(i, n){
        P tmp;
        tmp.first = 1;
        cin >> tmp.second;
        vp.push_back(tmp);
    }

    rep(i, m){
        P tmp1;
        cin >> tmp1.first;
        cin >> tmp1.second;
        vp.push_back(tmp1);
    }

    sort(all(vp), pairCompare);

    ll ans = 0;
    ll cnt = 0;
    rep(i, n){
        rep(j, vp[i].first){
            ans += vp[i].second;
            cnt++;
            if(cnt == n) break;
        }
        if(cnt == n) break;
    }
    cout << ans;


}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
int main()
{ 
  char ch[10000];
  int count = 0;
  cin>>ch;
  for(int i = 0;i<4;i++)
  {
    if(ch[i]=='2')
    count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3596
#include<stdio.h>


using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
}



Measured memory_bytes: 2588
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int asc(const void *a,const void *b);

int main(void)
{
  int N,M,count1,count2,room1,max,min,move,pa;
  scanf("%d %d",&N,&M);

  int X[M],def[M-1];
  for(count1=0;count1<M;count1++){
    scanf("%d",&X[count1]);
  }

  qsort(X,sizeof(X)/sizeof(int),sizeof(int),asc);

  max=X[M-1];
  min=X[0];

  for(count1=0;count1<M-1;count1++){
    def[count1]=X[count1+1]-X[count1];
  }

  qsort(def,sizeof(def)/sizeof(int),sizeof(int),asc);

  move=0;

  if(N>=M){
    move=0;
  }else{
    pa=M-N;
    for(count1=0;count1<pa;count1++){
      move+=def[count1];
    }
  }
  printf("%d\n",move);

  return 0;
}

int asc(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}


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


int f(int n, int b){
  int ans = 0;
  while( n > 0 ){
    ans += n % b;
    n /= b;
  }
  return ans;
}
void solve(long long N) {
    int ans = 1e9;
	for(int i = 0 ; i <= N ; i++){
		int j = N - i;
        ans = min(ans, f(i, 6) + f(j, 9));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]

G1 = [0]*C
G2 = [0]*C
G3 = [0]*C
a = int(0)

for i in range(N):
    for j in range(N):
        if (i + j) % 3 ==2:
            G1[c[i][j]-1] += 1
        elif (i + j) % 3 == 0:
            G2[c[i][j]-1] += 1
        else:
            G3[c[i][j]-1] += 1
ans_candi = []


for i1 in range(C):
    for i2 in range(C):
        for i3 in range(C):
            t = int(0)
            if i1!=i2 and i2!=i3 and i3!=i1:
                for j in range(C):
                    t += D[j][i1]*G1[j]
                for j in range(C):
                    t += D[j][i2]*G2[j]
                for j in range(C):
                    t += D[j][i3]*G3[j]
                ans_candi.append(t)


print(min(ans_candi))


Measured memory_bytes: 6512
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int a;
  int b;
  int c;
  cin >>a>>b>>c;
  if((a==b+c) ||(b==c+a) ||(c==a+b)) {
    cout << "Yes" << endl;
  }
else {
cout << "No" << endl;
}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

char const *const kYes = "Yes";
char const *const kNo = "No";
int const kMaxN = 8000 + 1;

char g_commands[kMaxN];

enum Direction { DIRECTION_HORIZONTAL, DIRECTION_VERTICAL };

Direction Turn(Direction d) {
  return static_cast<Direction>(1 - static_cast<int>(d));
}

bool Possible(int sum, vector<int> const &parts) {
  vector<int> prev;
  prev.push_back(0);

  vector<int> u;
  vector<int> v;
  vector<int> curr;

  auto push = [&](int value) {
    if (curr.empty() || curr.back() != value)
      curr.push_back(value);
  };

  for (auto const &part : parts) {
    u.clear();
    v.clear();
    for (auto const p : prev) {
      u.push_back(p + part);
      v.push_back(p - part);
    }

    size_t i = 0, j = 0;
    curr.clear();
    while (i < u.size() && j < v.size()) {
      if (u[i] < v[j]) {
        push(u[i]);
        ++i;
      } else if (u[i] > v[j]) {
        push(v[j]);
        ++j;
      } else {
        push(u[i]);
        push(v[j]);
        ++i;
        ++j;
      }
    }
    for (; i < u.size(); ++i)
      push(u[i]);
    for (; j < v.size(); ++j)
      push(v[j]);
    curr.swap(prev);
  }

  return binary_search(prev.begin(), prev.end(), sum);
}

bool Solve(int n, char const *commands, int targetX, int targetY) {
  int curX = 0;
  int curY = 0;
  int i = 0;
  for (; i < n && commands[i] == 'F'; ++i)
    ++curX;

  auto direction = DIRECTION_HORIZONTAL;

  vector<int> hors;
  vector<int> vers;
  while (i < n) {
    while (i < n && commands[i] == 'T') {
      direction = Turn(direction);
      ++i;
    }

    int j = i;
    while (j < n && commands[j] == 'F')
      ++j;

    auto const sum = j - i;
    if (sum != 0) {
      if (direction == DIRECTION_HORIZONTAL)
        hors.push_back(sum);
      else
        vers.push_back(sum);
    }
    i = j;
  }

  return Possible(targetX - curX, hors) && Possible(targetY - curY, vers);
}

int main() {
  int targetX, targetY;
  scanf("%s%d%d", g_commands, &targetX, &targetY);

  auto const possible = Solve(strlen(g_commands), g_commands, targetX, targetY);
  printf("%s\n", possible ? kYes : kNo);
  return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	string s; cin >> s;
	s = "ABC" + s;
	cout << s << 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 all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define intt int64_t

int main() {
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(t.begin(), t.end());
    if(s < t) printf("Yes\n");
    else printf("No\n");
}

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

int main() {
  string s, ss;
  cin >> s;
  for (int i = s.size() - 2; i >= 2; i -= 2) {
    ss = s.substr(0, i);
    if (ss.substr(0, ss.size() / 2) ==
        ss.substr(ss.size() / 2, ss.size() / 2)) {
      cout << ss.size() << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import math

N = int(input())
X = list()
Y = list()
for i in range(N):
    x, y = list(map(int, input().split()))
    X.append(x)
    Y.append(y)

dis = 0

for i in range(N):
    for j in range(N):
        dis += math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)

print(dis / N)


Measured memory_bytes: 3064
#from collections import deque
#from math import gcd
#MOD = 10**9 + 7
#N = int(input())
a, b, c, d= map(int, input().split())
#A = list(map(int, input().split()))
#ans = 0
#print(ans)

if b < 0 and c > 0:
  print(max(a*c, b*c, a*d, b*d))
elif a > 0 and d < 0:
  print(max(a*c, b*c, a*d, b*d))
else:
  print(max(a*c, b*c, a*d, b*d, 0))



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

int main() {
  int64_t a, b, x;
  cin >> a >> b >> x;

  int64_t ans = 0;
  if( a == 0 ){
    ans = b/x + 1;
  }else{
    ans = ( b/x + 1 ) - ( (a-1)/x + 1 );
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

bool iscomp[114514];
int like[114514];
int imos[114514];

int main(void)
{
	iscomp[0] = iscomp[1] = true;
	for (int i = 2; i < 114514; ++i) {
		if (!iscomp[i]) {
			for (int j = i + i; j < 114514; j += i) {
				iscomp[j] = true;
			}
		}
	}
	for (int i = 1; i < 114514; ++i) {
		if (!iscomp[i] && !iscomp[(i + 1) / 2]) {
			like[i] = true;
		}
	}
	for (int i = 1; i < 114514; ++i) {
		imos[i] = imos[i - 1] + like[i - 1];
	}
	int Q;
	cin >> Q;
	for (int q = 0; q < Q; ++q) {
		int l, r;
		cin >> l >> r;
		r++;
		cout << imos[r] - imos[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

//=================================================================
//Grand Contest 029 A
int main(){
    string S;
    cin >> S;
    ll b=0;
    ll ans;

    for(ll i=0; i< S.length(); i++){
        if(S[i]=='B'){
            b++;
        }else{
            ans += b;
        }
    }
    cout << ans << endl;
}


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

int a, b;
ll ans = 0;

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


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

#define ll long long int

int main()
{

    ll a,b,c;
    cin>>a>>b>>c;
    ll c1 = 0;
    while (true){
        if ((a&1) || (b&1) || (c&1)) break;
        c1 += 1;
        ll a1[5];
        a1[0] = a/2, a1[1] = b/2, a1[2] = c/2;
        a = 0, b = 0, c = 0;
        a += a1[1]+a1[2];
        b += a1[0]+a1[2];
        c += a1[0]+a1[1];
        if (c1>5000000){
            cout << "-1\n";
            return 0;
        }
    }
    cout << c1 << "\n";

    return 0;
}



Measured memory_bytes: 256
import numpy as np
import math
import scipy
import itertools

def score(arr):
    hoge = 0
    for ai,bi,ci,di in zip(a, b, c, d):
        if arr[bi-1]-arr[ai-1] == ci:
            hoge += di
    return hoge

def dfs(arr):
    if len(arr) == n:
        return score(arr)
    last = arr[-1] if len(arr) > 0 else 0
    res = 0
    for i in range(last, m):
        arr.append(i)
        res = max(res, dfs(arr))
        arr.pop()
    return res

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 31156
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main() {
    int x;

    scanf("%d", &x);

    if (x == 3 || x == 5 || x == 7) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1628
#include<stdio.h>
int main(void)
{
	char a[4],b[4];
	int i,j;
	scanf("%s",a);
	scanf("%s",b);
	j=0;
	for(i=0;i<3;i++){
		if(a[i]==b[i]){
			j++;
		}
	}
	printf("%d",j);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


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

    int n,m;
    cin>>n>>m;
    vector<bool> red(n,false);
    vector<ll> num(n,1);
    red[0]=true;
    int x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--;
        y--;
        if(red[x]){
            red[y]=true;
        }
        num[x]--;
        num[y]++;
        if(num[x]==0){
            red[x]=false;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(red[i])ans++;
    }
    fin(ans);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
  int n,a[200005];
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
  int z=1;
  for(int i=0;i<n;i++)
    if(a[i]==z) z++;
  if(z==1) printf("-1\n");
  else printf("%d\n",n-z+1);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

int main() {

    int S, tmp1, i=0, ans = 0;

    std::cin >> S ;

    //abcd
    int d = S%10;
    S = S - d;

    int c = (S%100)/10;
    S = S - c*10;

    if(d == c){
        std::cout << "Bad" << std::endl;
        return 0;
    }

    int b = (S%1000)/100;
    S = S - b * 100;

    if(b == c){
        std::cout << "Bad" << std::endl;
        return 0;
    }

    int a = S/1000;
    if(a == b){
        std::cout << "Bad" << std::endl;
        return 0;
    }

    std::cout << "Good" << std::endl;
    return 0;
}

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

int main () {
  string S ; 
  cin >> S ; 
  
  if (S.at(0) == 'S'){
    cout << "Cloudy" << endl ; 
  }
  
  else if (S.at(0) == 'C'){
    cout << "Rainy" << endl ; 
  }
  else {
    cout << "Sunny" << endl ; 
  }
  
}

Measured memory_bytes: 3564
(* swapping two numbers *)
open Scanf
open Printf

(* `a->`b->list *)
let sort lst = 
  match lst with
    [a;b] -> if a<b then [a;b] else [b;a]
  | _ -> [];;

(* list->() *)
let rec print_list a_list =
  match a_list with
    [] -> ()
  | fst::[] -> printf "%d" fst;print_newline()
  | fst::rest -> printf "%d " fst;print_list rest;;
(* `a->`b->list *)
let make_list a b = [a;b];;
(* () -> list *)
let read_two_nums () = sort @@ (scanf "%d %d\n" make_list);;
(* main *)
let rec loop () =
  match read_two_nums () with
    [0;0] -> ()
  | _list -> loop( print_list _list);;

loop();;

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    char c[2][3];
    rep(i, 2)rep(j, 3) cin >> c[i][j];
    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto && (i) : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
// constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int mod_pow(int x, int n, int mod) {
  int res = 1;
  while (n > 0) {  //最下位ビットが立っている時にx^(2^i)を掛ける
    if (n & 1) res = res * x % mod;
    x = x * x % mod;  // xを順次二乗していく
    n >>= 1;          // nを1ビット右へ
  }
  return res;
}

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

  int n;
  cin >> n;
  int ans = mod_pow(10, n, mod1) - mod_pow(9, n, mod1) - mod_pow(9, n, mod1) +
            mod_pow(8, n, mod1);
  ans %= mod1;
  ans = (ans + mod1) % mod1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<mod> mint;

int n,m,_,x,y,q;
string s,sb;
bool ok;

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

  cin>>s; mint ans=0,l=1; n=s.size();
  rep(i,n){
    if(s[i]=='1'){
      ans+=((mint)3^(n-i-1))*l;
      l*=2;
    }
  }
  pri1((ans+l).get());
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{

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

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a ,b ,x;
        a = sc.nextInt();
        b = sc.nextInt();

        x = gcd(a ,b);

        System.out.printf("%d\n",x);
    }
}


Measured memory_bytes: 26292
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,m,a,p[100];

int main(){
	while(cin>>n>>m){
		if(n+m==0)return 0;
		for(int i=0;i<m;i++)p[i]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin>>a;
				p[j]+=a;
			}
		}
		int f=0;
		for(int i=n;i>=0;i--){
			for(int j=0;j<m;j++)if(p[j]==i){
				if(f)cout<<" ";
				cout<<j+1;
				f=1;
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 0
import queue
q=queue.Queue()

K=int(input())
for i in range(1,10):q.put(i)
while(not q.empty()):
    a=q.get()
    K-=1
    if K==0:
        print(a)
        exit()
    for i in range(a%10-1,a%10+1+1):
        if i<0 or i>9:continue
        q.put(a*10+i)







Measured memory_bytes: 52308
MOD = 10**9 + 7

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs

def getCombKs(n, k, invs, MOD):
    combKs = [0] * (n+1)
    combKs[k] = 1
    for x in range(k+1, n+1):
        combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD
    return combKs

N, K = map(int, input().split())
As = list(map(int, input().split()))

As.sort()

invs = getInvs(N, MOD)
combKs = getCombKs(N, K-1, invs, MOD)

ans = 0
for i, A in enumerate(As):
    numMax = combKs[i]
    numMin = combKs[N-1-i]
    ans += A * (numMax - numMin) % MOD
    ans %= MOD

print(ans)


Measured memory_bytes: 65576
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top(); S.pop();
		for (int i = 0; i < G[u].size(); ++i) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n; ++i) color[i] = NIL;
	for (int u = 0; u < n; ++u) {
		if (color[u] == NIL) dfs(u, id++);
	}
}

int main() {
	int s, t, m, q;

	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for (int i = 0; i < q; ++i) {
		cin >> s >> t;
		if (color[s] == color[t]) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
}


Measured memory_bytes: 8980
#define
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0
countlist=[]
#sorting
for e in range(0,a+1):
    if e*500 <= x:
        y=x-e*500
        for f in range(0,b+1):
            if f*100 <= y:
                z=y-100*f
                for g in range(0,c+1):
                    if g*50 == z :                                            
                        count = count +1

print(count)
                
 



Measured memory_bytes: 3060
#include <iostream>
using namespace std ;
int main () {
string S , T ; cin >> S >> T ;
bool ans = false ;
for ( int i = 0; i < S . size (); ++ i ) {
if ( S == T ) {
ans = true ;
break ;
}
S = S . back () + S . substr (0 , S . size () -1);
}
if ( ans ) {
cout << " Yes " << endl ;
}
else {
cout << "No" << endl ;
}
}

Measured memory_bytes: 3556
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9 + 7

fac = [1, 1]     # 元テーブル
f_inv = [1, 1]   # 逆元テーブル
inv = [0, 1]     # 逆元テーブル計算用テーブル
def prepare(n, mod):
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod//i)) % mod)
        f_inv.append((f_inv[-1] * inv[-1]) % mod)


def cmb(n, r, mod):
    if n < 0 or r < 0:
        return 0
    if r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def prime_factorization(n):
    d = {}
    i = 2
    while i * i <= n:
        if n % i == 0:
            d[i] = 1
            n //= i
            while n % i == 0:
                n //= i
                d[i] += 1
        i += 1
    if n > 1:
        d[n] = 1
    return d


def main():
    N,M = map(int, readline().split())

    prepare(N+100, MOD)
    d = prime_factorization(M)

    ans = 1
    for v in d.values():
        ans *= cmb(N-1+v, v, MOD)
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 15248
//Atcoder 177A
#include <bits/stdc++.h>
#define endl "\n"
#define int long long 

using namespace std;

int32_t main(){
	int k;
	cin >> k;
	int seven=7;
	for(int i=1;i<k+5;i++){
		if(seven%k==0){
			cout << i << endl;
			return 0;
		}
		seven=(seven*10+7)%k;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 998244353;
int N, S;
vector<int> v;
int dp[3005][3005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N >> S;
	v.resize(N);
	for (int i = 0; i < N; i++) cin >> v[i];

	//f(i, j)=k인 0 <= j <= i의 개수
	// 점화식 dp[i][j] = dp[i-1][j] + dp[i-1][j-v[i]] % MOD
	// 기저사례 dp[i][0] = 1

	int ans = 0;
	for (int i = 0; i < N; i++) dp[i][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= S; j++) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= MOD;
		}
		for (int j = v[i]; j <= S; j++) {
			dp[i + 1][j] += dp[i][j - v[i]];
			dp[i + 1][j] %= MOD;
		}
//		cout << dp[i + 1][S] << '\n';

		ans += dp[i + 1][S];
		ans %= MOD;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 35456