akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	string s;
	cin >> s;
	bool judge = true;
	for (int i = 0; i < s.size(); i += 2) {
		if (s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D') {
			judge = false;
			break;
		}
	}

	if (judge) {
		for (int i = 1; i < s.size(); i += 2) {
			if (s.at(i) != 'L'&& s.at(i) != 'U' && s.at(i) != 'D') {
				judge = false;
				break;
			}
		}
	}
	if (judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) {
	int i = 0;
	A[n] = key;
	while ( A[i] != key ) i++;
	return i != n;
}


int main() {
	int i, n, A[10000 + 1], q, key, sum = 0;
	
	scanf ("%d" , &n);
	for ( i = 0; i < n; i++ ) {
		scanf ("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for ( i = 0; i < q; i++ ) {
		scanf ("%d", &key);
		if (search(A, n, key) ) {
			sum++;
		}
	}
	printf("%d\n", sum);
	
	return 0;
}


Measured memory_bytes: 2064
from itertools import permutations

def readinput():
    n,m=list(map(int,input().split()))
    nList=[]
    for _ in range(n+1):
        nList.append([])
    for _ in range(m):
        a,b=list(map(int,input().split()))
        nList[a].append(b)
        nList[b].append(a)
    
    return n,m,nList

def main(n,m,nList):
    permlist = permutations(range(2,n+1))
    count=0
    for perm in permlist:
        current=1
        for i in range(n-1):
            next=perm[i]
            if not next in nList[current]:
                break
            current=next
        else:
            count+=1
    return count

if __name__=='__main__':
    n,m,nList=readinput()
    ans=main(n,m,nList)
    print(ans)


Measured memory_bytes: 3064
/*
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
█████████───███─────────███───███─────────████████████───███████████████───████████████───████████████───█████████───────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
███─────────███─────────███───███─────────███──────███───███───███───███───███──────███───███──────███───███─────────────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
█████████──────███───███──────███─────────████████████───███───███───███───████████████───███──────███───█████████───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
███────────────███───███──────███─────────███──────███───███───███───███───███────────────███──────███─────────███───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
█████████─────────███─────────█████████───███──────███───███───███───███───███────────────████████████───█████████───────
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fori(n) for ( int i = 0; i < (n);i++)
#define forj(n) for ( int j = 0; j < (n);j++)
#define fork(n) for ( int k = 0; k < (n);k++)
#define forghj(n) for ( int ghj = 0; ghj < (n);ghj++)
#define fori1(n) for ( int i = (n)-1; i >= 0;i--)
#define all(vector) (vector).begin(),(vector).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define INF 1e9+7
#define EPS 1e-6
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"

int main() {
    srand(time(NULL));
    ll a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a, b); /// a < b
    }
    ll k2 = (b + a);
    if (k2 % 2 != 0) {
        cout << "IMPOSSIBLE";
        return 0;
    }
    cout << k2 / 2ll;
}






Measured memory_bytes: 256
M, D = map(int, input().split())

ans = 0
for di in range(11, D + 1):
    d10 = di // 10
    d1 = di % 10
    if d10 < 2: continue
    if d1 < 2: continue
    #
    if 1 <= (d1 * d10) <= M:
        # print("#", d1, d10)
        ans += 1

print(ans)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
  int n,d,x;
  cin >>n;int a[n+1];
  cin >> d >> x;
  int sum=0;
  for(int i=1;i<=n;i++){
    cin >>a[i];
  }
  int h=1;
  for(int i=1;i<=n;i++){
    int k=0;
    while(1){
       h=k*a[i]+1;
       if(h>d) break;
       sum++;k++;
    }

    h=1;
  }
  sum+=x;
  cout << sum <<endl;

}


Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print('#' ,end='')
            else:
                print('.' ,end='')
        print()
    print()
            


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

int main(){
  int i,x,y,a;
  for(i=0; i<3000; i++){
      cin >> x >> y;
      if((x==0)&&(y==0)) break;
      if(x>y){
          a=x; x=y; y=a;
      }
  cout << x << " " << y << endl;
  }
}


Measured memory_bytes: 2972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll x; cin >>x;
  ll now=100;
  int count=0;
  while(true){
    if(now>=x){
      cout << count << endl;
      return 0;
    }
    now*=1.01;
    count++;
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

    String a = scanner.next();
    String b = scanner.next();

    new Main().execute(a, b);
  }

  public void execute(String a, String b) {
    int number = Integer.parseInt(a + b);
    int round = (int) Math.sqrt(number);

    System.out.println(round * round == number ? "Yes" : "No");

  }
}


Measured memory_bytes: 23636
N = int(input())
S = input()

count = [0,0,0]

for c in S:
    if c == "R":
        count[0] += 1
    elif c == "G":
        count[1] += 1
    else:
        count[2] += 1

tot = count[0] * count[1] * count[2]

for i in range(N-2):
    max_n = (N-i-1)//2
    for j in range(1, max_n+1):
        if S[i]!= S[i+j] and S[i+j] != S[i+2*j] and S[i] != S[i+2*j]:
            #print(S[i], S[i+j], S[i+2*j])
            tot -= 1
print(tot)


Measured memory_bytes: 9212
#include <cstdio>
#include <tuple>
#include <vector>
static const int MAXN = 1e5 + 4;
static const int MAXQ = 1e5 + 4;
static const int MAXD = 12;

int n, m, q;
std::vector<int> e[MAXN];
// tuple<colour, remaining_steps, painted_time>
std::tuple<int, int, int> s[MAXD][MAXN];
int q_v[MAXQ], q_d[MAXQ], q_c[MAXQ];
std::vector<int> q_with_d[MAXD];

inline void cover_colour(std::tuple<int, int, int> &orig, const std::tuple<int, int, int> &upd, bool persistent = false)
{
    if (std::get<2>(orig) < std::get<2>(upd)) {
        orig = upd;
        if (!persistent) std::get<1>(orig) -= 1;
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    int u, v;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &u, &v); --u, --v;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    for (int d = 0; d < MAXD; ++d)
        for (int i = 0; i < n; ++i) s[d][i] = std::make_tuple(0, 0, -1);
    scanf("%d", &q);
    int d, c;
    for (int i = 0; i < q; ++i) {
        scanf("%d%d%d", &q_v[i], &q_d[i], &q_c[i]);
        --q_v[i];
        q_with_d[q_d[i]].push_back(i);
    }

    for (int cur_d = 10; cur_d >= 0; --cur_d) {
        for (int i : q_with_d[cur_d])
            cover_colour(s[0][q_v[i]], std::make_tuple(q_c[i], q_d[i] + 1, i));

        for (int i = 0; i <= 10; ++i) {
            for (int u = 0; u < n; ++u) cover_colour(s[i + 1][u], s[i][u], true);
            for (int u = 0; u < n; ++u) if (std::get<1>(s[i][u]) > 0) {
                for (int v : e[u]) cover_colour(s[i + 1][v], s[i][u]);
            }
        }
    }
    /*for (int r = 0; r <= 10; ++r)
        for (int i = 0; i < n; ++i) printf("%d(%d)%c", std::get<0>(s[r][i]), std::get<1>(s[r][i]), i == n - 1 ? '\n' : ' ');*/

    for (int i = 0; i < n; ++i) printf("%d\n", std::get<0>(s[11][i]));
    return 0;
}


Measured memory_bytes: 22392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    stack<char>q;
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        if(q.empty() || q.top()!=s[i])q.push(s[i]);
    }
    co(q.size()-1);
}

Measured memory_bytes: 3760
n=int(input())
s=list(map(int,input().split()))
cnt=1
u=False
d=False
for i in range(n-1):
    if s[i]<s[i+1]:
        u=True
    elif s[i]>s[i+1]:
        d=True
    if u and d:
        cnt+=1
        u=False
        d=False
print(cnt)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    ll h,n,i;
    cin>>h>>n;
    ll a[n];
    ll s=0;
    for(i=0;i<n;i++)
        {cin>>a[i];
    s+=a[i];}
    if(s>=h)
        cout<<"Yes"<<e;
    else
        cout<<"No"<<e;

}



Measured memory_bytes: 1024
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    max_self(c,a);
    min_self(b,d);
    cout<<max(b-c,0)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    cin >> s;
    bool f[2];
    fill(f,f+2,false);
    for (ll i=0;i<s.size();i++){
        if (s[i]=='A'){
            f[0]=true;
        }else{
            f[1]=true;
        }
    }
    if (f[0] and f[1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  string s;
  cin >> s;
  map<char, int> mp;

  REP(i, s.size()) {
    char c = s[i];
    if(mp[c] == 1) {
      cout << "no" << endl;
      return 0;
    }
    mp[c]++;
  }
  cout << "yes" << endl;
  return 0;

  return 0;
}


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

int main(){
    int a, b, C;
    cin >> a >> b >> C;

    double S, L, h;
    double PI = acos(-1.0);

    S = a * b * sin(C / 180.0 * PI) / 2.0;
    L = a + b + sqrt(a*a + b*b - 2*a*b*cos(C / 180.0 * PI));
    h = 2 * S / a;
    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int mina = 0, maxa = 0;
    int indmi = 0, indma = 0;
    for(int i = 0; i < N; i++){
        if(mina >= a[i]){
            mina = a[i];
            indmi = i;
        } 
        if(maxa <= a[i]){
            maxa = a[i];
            indma = i;
        }
    }
    long long temp = 0;
    int flag = 0;
    vector<int> l, r;
    if(abs(mina) > maxa){
        l.push_back(indmi + 1);
        r.push_back(indmi + 1);
        temp = mina * 2;
        a[indmi] *= 2;
        flag = 1;
    }
    else{
        l.push_back(indma + 1);
        r.push_back(indma + 1);
        temp = maxa * 2;
        a[indma] *= 2;
        flag = 2;
    }
    if(flag == 1){
        for(int i = N - 2; i >= 0; i--){
            while(a[i] > a[i + 1]){
                l.push_back(i + 1);
                r.push_back(indmi + 1);
                a[i] += temp;
                if(temp > a[i]){
                    indmi = i;
                    temp = a[i];
                }
            }
        }
    }
    else{
        for(int i = 1; i < N; i++){
            while(a[i - 1] > a[i]){
                l.push_back(i + 1);
                r.push_back(indma + 1);
                a[i] += temp;
                if(temp < a[i]){
                    indma = i;
                    temp = a[i];
                }
            }
        }
    }
    int n = (int)l.size();
    cout << n << endl;
    for(int i = 0; i < n; i++){
        cout << r[i] << ' ' << l[i] << endl;
    }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
int q[110000];
pair<int,int>s[110000];
int R[110000];
int v[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d%d",p+i,q+i);p[i]--;
		s[i]=make_pair(-q[i],p[i]);
	}
	std::sort(s,s+a);
	priority_queue<int>Q;
	int sz=0;
	long long cur=0;
	for(int i=0;i<a;i++){
		if(sz==b||v[s[i].second]){
			Q.push(-s[i].first);
		}else{
			v[s[i].second]=1;
			R[sz]=-s[i].first;
			sz++;
			cur-=s[i].first;
		}
	}
	long long ret=0;
	int req=b-sz;

	for(int i=sz;i>=1;i--){
		while(req){
			req--;
			cur+=Q.top();
			Q.pop();
		}
		ret=max(ret,(long long)i*i+cur);
		cur-=R[i-1];
		req++;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 2940
#include <iostream>
#include <set>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	int x,y,a,b,c;
	ll ans = 0;
	std::cin >>a>>b>>c>>x>>y;;
	if(x*a+y*b>(x+y)*c) {
		if (x>y) {
			if ((x-y)*a>2*(x-y)*c) ans = 2*x*c;
			else ans = 2*y*c + (x-y)*a;
		}else{
			if ((y-x)*b>2*(y-x)*c) ans = 2*y*c;
			else ans = 2*x*c + (y-x)*b;
		}
	}else{
		ans = x*a + y*b;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
a = [ 0 ] + list(map(int, input().split())) + [ 0 ]
acc = 0
for i in range(n + 1):
    acc += abs(a[i + 1] - a[i])
for i in range(n):
    result = acc
    result -= abs(a[i + 1] - a[i])
    result -= abs(a[i + 2] - a[i + 1])
    result += abs(a[i + 2] - a[i])
    print(result)


Measured memory_bytes: 14040
#include <stdio.h>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B

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

int main(int argc, char **argv) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", gcd(a, b));
    return 0;
}


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

const int MAXN = 1e5 + 21;

int n;
int a[MAXN][3], p[MAXN], t[2];

bool chck() {
    for (int i = 1; i <= n; i++) {
        p[i] = a[i][1] / 3 + 1;
        
        if (!(a[i][1] - a[i][0] == 1 && a[i][2] - a[i][1] == 1 && a[i][0] % 3 == 1 || a[i][0] - a[i][1] == 1 && a[i][1] - a[i][2] == 1 && a[i][2] % 3 == 1))
            return 0;
        
        if (abs(i - p[i]) & 1) 
            return 0; 
        t[(i & 1)] ^= (a[i][0] > a[i][2]);
    }

    for (int i = 1; i <= n; i++) {
        while (p[i] != i) {
            t[((i & 1) ^ 1)] ^= 1;
            swap(p[i], p[p[i]]);
        }
    }
    
    return !t[0] && !t[1];
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int k = 0; k < 3; k++)
        for (int i = 1; i <= n; i++)
            cin >> a[i][k];

    if (chck())
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 1792
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)
#define UPC(a) (a>='A' && a<='B')
#define LWC(a) (a>='a' && a<='b')

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void sctd(LL &a,LL &b,LL &c){scanf("%I64d %I64d %I64d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

inline void prd(int a){printf("%d",a);};
inline void prdd(int a,int b){printf("%d %d",a,b);};
inline void prtd(int a, int b, int c){printf("%d %d %d",a,b,c);};
inline void prtlld(LL a, LL b, LL c){printf("%I64d %I64d %I64d",a,b,c);};
inline void prdlld(LL a, LL b){printf("%I64d %I64d",a,b);};
inline void prtlld(LL a){printf("%I64d",a);};

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int n,m;
	scd(n);
	int a[200000],b[200000];
	forin(i,0,n)
	scd(a[i]);
	sort(a,a+n);
	scd(m);
	forin(i,0,m)
	scd(b[i]);
	int d=0;
	forin(i,0,m)
	{
		int lo=0,hi=n,mid;
		while(lo<=hi)
		{
			mid=(lo+hi)/2;
			if(b[i]==a[mid])
			{
				d++;
				break;
			}
			else if(b[i]<a[mid])
			{
				hi=mid-1;
			}
			else if(b[i]>a[mid])
			{
				lo=mid+1;
			}
		}		
	}
	printf("%d\n",d);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  long long A = 0;
  for (int i = 0; i < S.size(); i++){
    int B = S.at(i) - 48;
    A += B;
  }
    
  if (A%9 == 0 ) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  
}


Measured memory_bytes: 3748
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll a[100005],val[5];
int main(){
	std::ios::sync_with_stdio(false);
	ll n,i,j,k,maxx,l,r,ans;
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}	
	if(n==2){
		cout<<abs(a[0]-a[1])<<endl;
	}
	else{
		sort(a,a+n);
		ans=a[n-1]-a[0];
		j=n-2;
		i=1;
		l=a[n-1];
		r=a[0];
		while(i<=j){
			maxx=0;
			val[0]=abs(r-a[j]);
			val[1]=abs(r-a[i]);
			val[2]=abs(l-a[j]);
			val[3]=abs(l-a[i]);
			rep(k,4){
				maxx=max(maxx,val[k]);
			}
			if(val[0]==maxx){
				r=a[j];
				j--;
			}
			else if(val[1]==maxx){
				r=a[i];
				i++;
			}
			else if(val[2]==maxx){
				l=a[j];
				j--;
			}
			else if(val[3]==maxx){
				l=a[i];
				i++;
			}
			ans+=maxx;
			//cout<<l<<" "<<r<<endl;
		}
		cout<<ans<<endl;
	}
} 
	

Measured memory_bytes: 1024
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num
    
def main():
    n = ni()
    s = set([alpha2num(ns()) for i in range(n)])
    print(len(s))
    return

if __name__ == '__main__':
  main()

Measured memory_bytes: 111892
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

using ll = __int128_t;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t[2], a[2], b[2];
    cin >> t[0] >> t[1];
    cin >> a[0] >> a[1];
    cin >> b[0] >> b[1];
    if(a[0] > b[0]){
        swap(a[0], b[0]);
        swap(a[1], b[1]);
    }
    ll diff[2];
    diff[0] = (a[0] - b[0]) * t[0];
    diff[1] = (a[1] - b[1]) * t[1];
    if(diff[0] + diff[1] < 0){
        cout << 0 << endl;
        return 0;
    }
    if(diff[0] + diff[1] == 0){
        cout << "infinity" << endl;
        return 0;
    }
    int q = -diff[0] / (diff[0] + diff[1]);
    int r = -diff[0] % (diff[0] + diff[1]);
    int ans = 1 + q * 2;
    if(r == 0) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  if (A + B < C * 2) {
    cout << X * A + Y * B << endl;
  } else {
    int n, m, a;
    n = min(X, Y);
    m = max(X, Y) - n;
    a = (X > Y) ? A : B;
    a = min(a, C * 2);
    cout << n * C * 2 + m * a << endl;
  }
  return 0;
}


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;

int main()
{
    ll n, a[300000], ans = 0;
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    for (int i = 1; i < n; i++)
        ans += a[n-i/2-1];
    // rep(i, n) cout << a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5224
# https://atcoder.jp/contests/abc119/tasks/abc119_a

def main():
    S = list(map(int, input().split("/")))
    if S[0] < 2019:
        print("Heisei")
    elif S[1] < 4:
        print("Heisei")
    elif S[1] == 4 and S[2] <= 30:
        print("Heisei")
    else:
        print("TBD")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h> 
int main(void){
   int n,i;
 
   scanf("%d",&n);
   char s[n][11];
   for(i=0; i<n; i++){
       scanf("%s",&s[i]);
   }
   int cnt=1;
   qsort(s,n,11,strcmp);
 
   for(i=1;i<n;i++){
      if(strcmp(s[i],s[i-1])!=0) 
        cnt++;    
   }
   
   printf("%d",cnt);
   return 0;
}

Measured memory_bytes: 5740
N=int(input())
A=list(map(int,input().split()))
print(*A)
for i in range(1,N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j+1] = A[j]
    j-=1
  A[j+1] = v
  print(*A)


Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,M,K;

#include <vector>
using namespace std;

struct UnionFind {
  vector<int> par_;
  vector<int> rank_;

  void init(int size) {
    par_.resize(size, 0);
    rank_.resize(size, 0);
    for (int i = 0; i < size; i++) {
      par_[i] = i;
      rank_[i] = 0;
    }
  }
  int root(int x) { return par_[x] == x ? x : par_[x] = root(par_[x]); }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return true;

    if (rank_[x] < rank_[y]) {
      par_[x] = y;
    } else {
      par_[y] = x;
      if (rank_[x] == rank_[y]) rank_[x]++;
    }
    return false;
  }
  bool same(int x, int y) { return root(x) == root(y); }
};

vector<int> bu(101010,-1);

int main(){
  cin >> N >> M >> K;
  UnionFind uf;
  uf.init(N);
  rep(i,0,K - 1){
    int c,a,b;
    cin >> c >> a >> b;
    a--;
    b--;
    if(c == 1){
      int ra = uf.root(a);
      int rb = uf.root(b);
      if(ra == rb) continue;
      if((bu[ra] == -1 || bu[rb] == -1) || bu[ra] == bu[rb]){
        uf.unite(ra,rb);
        int r = uf.root(ra);
        if(bu[ra] == -1){
          bu[r] = bu[rb];
        }
        if(bu[rb] == -1){
          bu[r] = bu[ra];
        }
      }
      else{
        cout << i + 1 << endl;
        return 0;
      }
    }
    else{
      int r = uf.root(a);
      if(bu[r] == -1 || bu[r] == b){
        bu[r] = b;
      }
      else{
        cout << i + 1 << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}



Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define forsn(i, s, n) for (tint i = (s); i < (tint)(n); i++)
#define forn(i, n) forsn(i, 0, n)
typedef long long tint;
using namespace std;
int main()
{
    tint n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<tint> d(n);
    forn(j, n)
        forn(i, j)
            d[min(j - i, abs(i - x) + 1 + abs(j - y))]++;
    forsn(r, 1, n)
    cout<<d[r]<<endl;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

que = deque([i for i in range(1, 10)])
ans = []
while len(ans) <= K + 10:
    now = que.popleft()
    ans.append(now)

    b = now % 10
    for i in range(max(0, b - 1), min(10, b + 2)):
        que.append(now * 10 + i)

ans.sort()
print(ans[K - 1])


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

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> dish(N, 0);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    dish[i] = a * 10000 + b;
  }
  sort(dish.begin(), dish.end());
  int dp[6001] = {0};
  for (auto d : dish) {
    int a = d / 10000;
    int b = d % 10000;
    for (int t = T - 1; t > 0; t--) {
      if (dp[t] == 0) continue;
      dp[t + a] = max(dp[t + a], dp[t] + b);
    }
    dp[a] = max(dp[a], b);
  }
  int ans = 0;
  for (int t = 0; t < 6000; t++) {
    ans = max(ans, dp[t]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    
    int H,W;
	while(true){
		cin>>H>>W;
		if(H == 0 && W == 0) break;
	
		for(int i = 0; i < H; i++){
		    
		    	if(i%2 == 0){
		          for(int j = 0; j < W; j++){
			               if(j%2 ==0){
			                cout << "#";

			                 }else{
			             cout << ".";
			                  }
	
			           }
		        }else{
		           for(int j = 0; j < W; j++){
			            if(j%2 ==0){
			                   cout << ".";

			               }else{
			                   cout << "#";
			               }   
	
			        }
		        }
		    
			
			cout<<endl;
		}
		cout<<endl;
	}
    return 0;
}


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

typedef long long ll;
typedef int keytype;

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }

    return flag;
}

int main(){
    int n;
    char s[50];
    char t[] = {"ABC"};

    scanf("%d %s", &n, s);

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(is_substr(s, t, i)) cnt++;
    }

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

    return 0;
}


Measured memory_bytes: 1732
N = int(input())
l = [None]*N
s = []
for i in range(N):
    k = list(map(int,input().split()))
    if k[0]==k[1]:
        s.append(k)
        l[i] = [0,0]
    else:
        l[i] = k

if len(s)>1:
    print("No")
else:
    l = sorted(l, key=lambda x: x[1])
    cnt = 0
    if len(s)==1:
        cnt += s[0][1]

    flag = True
    for j in l:
        if j==[0,0]:
            continue
        else:
            cnt += j[0]
        if cnt>j[1]:
            print("No")
            flag = False
            break
    if flag:
        print("Yes")

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ws(x) cerr << #x << " is " << x << endl
#define pb push_back
#define ats(x) cout << x << "\n"
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef vector<pii> vii;
typedef tuple<int, int, int> tiii;

const int INF = INT_MAX;

#define PI 3.14159265358979323846

int main()
{
    FAST_IO;
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double hdegrees = h * 30 + ((30*m)/60);
    double mindegrees = 6 * m;
    double angle = min(hdegrees - mindegrees, mindegrees - hdegrees);
    double ans = sqrt(a * a + b * b - 2 * a * b * cos((angle * PI )/ 180.0));
    cout << fixed << setprecision(15) << ans << "\n";
    return 0;
}



Measured memory_bytes: 4232
/**
    B  -  Red or Blue	C++14 (GCC 5.4.1)
	Accepted
**/
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int in[5];
    int sub = 0;
    int sum = 0;
    int mlos = 0;
    for(int i = 0; i < 5; i++){
        cin >> in[i];
        if(in[i] % 10 != 0){
            sub += 10 - (in[i] % 10);
            if(mlos < 10 - (in[i] % 10) ){
                mlos = 10 - (in[i] % 10);
            }
        }
        sum += in[i];
    } 
    cout <<  sum + sub - mlos << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()

	d := b - a
	e := c - b

	if d == e {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
	return
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int L, D;
	static char[][] str = new char[3][];
	static int[][] count;

	public static void main(String[] args) {
		while (true) {
			L = sc.nextInt();
			D = sc.nextInt();
			if (L == 0) break;
			for (int i = 0; i < 3; ++i) {
				str[i] = sc.next().toCharArray();
			}
			String ans = solve();
			System.out.println(ans == null ? "-1" : ans);
		}
	}

	static String solve() {
		count = new int[L + 1][5];
		char[] ret = new char[L];
		for (int i = 0; i < L; ++i) {
			if (str[0][i] == str[1][i] && str[0][i] == str[2][i]) {
				count[i][4]++;
			} else if (str[1][i] == str[2][i]) {
				count[i][0]++;
			} else if (str[0][i] == str[2][i]) {
				count[i][1]++;
			} else if (str[0][i] == str[1][i]) {
				count[i][2]++;
			} else {
				count[i][3]++;
			}
		}
		for (int i = L - 2; i >= 0; --i) {
			for (int j = 0; j < 5; ++j) {
				count[i][j] += count[i + 1][j];
			}
		}
		int[] rem = { D, D, D };
		for (int i = 0; i < L; ++i) {
			char[] cand = { 'A', str[0][i], str[1][i], str[2][i] };
			Arrays.sort(cand);
			boolean ok = false;
			for (int j = 0; j < cand.length; ++j) {
				char ch = cand[j];
				if (j > 0 && ch == cand[j - 1]) continue;
				for (int k = 0; k < 3; ++k) {
					if (str[k][i] != ch) rem[k]--;
				}
				if (ok(rem, i + 1)) {
					ok = true;
					ret[i] = ch;
					break;
				}
				for (int k = 0; k < 3; ++k) {
					if (str[k][i] != ch) rem[k]++;
				}
			}
			if (!ok) return null;
		}
		return String.valueOf(ret);
	}

	static boolean ok(int[] rem, int pos) {
		int[] num = new int[3];
		for (int i = 0; i < 3; ++i) {
			if (rem[i] < 0) return false;
			if (rem[i] < count[pos][i]) {
				num[i] += rem[i];
				for (int j = 0; j < 3; ++j) {
					if (j != i) num[j] += count[pos][i] - rem[i];
				}
			} else {
				num[i] += count[pos][i];
			}
		}
		for (int i = 0; i < 3; ++i) {
			if (num[i] > rem[i]) return false;
			num[i] = rem[i] - num[i];
		}
		Arrays.sort(num);
		int use = num[1] - num[0];
		num[1] -= use;
		num[2] -= use;
		if (num[0] + num[1] < num[2]) {
			use += num[0] + num[1];
		} else {
			use += (num[0] + num[1] + num[2]) / 2;
		}
		return count[pos][3] <= use;
	}

}

Measured memory_bytes: 102300
D = int(input())
C = list(map(int,input().split()))
 
s = [[] for _ in range(D)]
last = [0]*26
 
for i in range(D):
    s[i] = list(map(int,input().split()))

t = [0]*D
v_day = [0]*D

for d in range(D):
    P = [0]*26
    for i in range(26):
        P[i] += s[d][i]
        for j in range(26):
            if i == j:
                continue
            P[i] -= C[j] * (d+1 - last[j])
    d_maxP = P.index(max(P))
    print(d_maxP + 1)
    last[d_maxP] = d+1
    t[d] = d_maxP + 1
    v_day[d] = s[d][t[d] - 1] - sum([C[k]*(d+1 - last[k]) for k in range(26)])

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

const int mod = 998244353;
const int maxF = 200005;

int P(int a, int b) {
	if(b == 0) return 1;
	if(b & 1) return (long long)P(a, b - 1) * a % mod;
	long long t = P(a, b / 2);
	return t * t % mod;
}

int D(int a, int b) {
	return (long long)a * P(b, mod - 2) % mod;
}

int FC[maxF] = {1}, FDG = 0;
int F(int a) {
	while(FDG < a) {
		++FDG, FC[FDG] = (long long)FC[FDG - 1] * FDG % mod;
	}
	return FC[a];
}

int C(int a, int b) {
	return D(F(a), (long long)F(b) * F(a - b) % mod);
}

int n, m, k, fp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 0; i <= k; ++i) {
		(fp += (long long)C(n - 1, i) * P(m - 1, n - 1 - i) % mod) %= mod;
	}
	fp = (long long)fp * m % mod;
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 4384
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

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


        //  -> migi ue hidari sita
        vector<vector<bitset<4> > > Field(h,vector<bitset<4> >(w));

        rep(i,2*h-1){
            if(i % 2 == 0){
                rep(j,w-1){
                    int x;
                    cin >> x;
                    Field[i/2][j][0] = x==0;
                    Field[i/2][j+1][2] = x==0;
                }
            }else{
                rep(j,w){
                    int x;
                    cin >> x;
                    Field[i/2][j][3] = x==0;
                    Field[i/2+1][j][1] = x==0;
                }
            }
        }
        //y,x,depth
        queue<pair<pair<int,int>,int> > Q;
        Q.push(mp(mp(0,0),0));
        vector<vector<char> > ALR(h,vector<char>(w,0));
        ALR[0][0] = true;
        int gg = -1;
        while(!Q.empty()){
            pair<pair<int,int>,int> p = Q.front();
            if(p.first.first == h-1 and p.first.second == w-1){
                gg = p.second;
                break;
            }
            Q.pop();
            rep(i,4){
                if(!Field[p.first.first][p.first.second][i]) continue;
                int ny = p.first.first + dy[i];
                int nx = p.first.second + dx[i];
                if(ALR[ny][nx]) continue;
                ALR[ny][nx] = true;
                Q.push(mp(mp(ny,nx),p.second+1));
            }
        }
        if(gg == -1){
            cout << 0 << endl;
        }else{
            cout << gg+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1236
# 順位を入力として、賞金を返す
def prize(r):
    return int(r<=3)*(4-r)*100000    

X,Y=list(map(int,input().split(" ")))

# もし両部門で1位の場合、40,0000円上乗せ
if X==1 and Y==1:
    print(prize(X)+prize(Y)+400000)
else: # それ以外の場合
    print(prize(X)+prize(Y))

Measured memory_bytes: 3060
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int loadable_num(const int cap, int qty, const int *arr, const int N) {
    int i = 0;
    while(qty--) {
        int now = 0;
        while(arr[i] + now <= cap) {
            now += arr[i];
            if(++i == N) return N;
        }
    }
    return i;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int k = get_uint();
    int w[100001];
    for(int i = 0; i < n; ++i) w[i] = get_uint();

    int left = 0;
    int right = 10000 * 100000;
    int mid;
    while(right - left > 1) {
        mid = left + (right - left) / 2;
        if(n > loadable_num(mid, k, w, n)) left = mid;
        else right = mid;
    }
    printf("%d\n", right);
}



Measured memory_bytes: 2240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
 * 整数同士の割り算は整数に丸められるのでdoubleでキャストする
*/

/* ===== コーナーケースに気をつけろ ===== */

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

    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;
int a[200005];
int main()
{
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
        cin>>a[i];
    int t=a[0];
    int sum=1;
    for(int i=1;i<m;i++)
    {
        if(a[i]<t)
        {
            t=a[i];
            sum++;
        }
    }

    cout<<sum<<endl;
    return 0;
}


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

int main(){
    int n,x = 0;
    cin >> n;
    double a;
    for(int i = 1;i <= n;i++){
        a = 1.08*i;
        x = a;
        if(x == n){
            x = i;
            break;
        }
        x = 0;
    }
    if(x > 0)cout << x;
    else cout << ":(";
}


Measured memory_bytes: 256
import sys, math


def main():
    N = input()
    days = [map(int, raw_input().split()) for i in range(N)]

    dpMax = [[0, 0, 0] for i in range(N)]
    dpMax[0] = days[0]
    
    for i in range(1, N):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dpMax[i][j] = max(dpMax[i][j], dpMax[i - 1][k] + days[i][j])
            
    print max(max(dpMax[N - 1][0], dpMax[N - 1][1]), dpMax[N - 1][2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 42228
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
int dp[3005][3005];
pii from[3005][3005];
int main(){
    char c1[3005],c2[3005];
    scanf("%s %s",c1+1,c2+1);
    MEM(dp);
    for(int i=1;c1[i]!=0;i++){
        for(int j=1;c2[j]!=0;j++){
            if(c1[i]==c2[j]){
                dp[i][j]=dp[i-1][j-1]+1;
                from[i][j]=mp(i-1,j-1);
            }
            if(dp[i][j]<=dp[i-1][j]){
                dp[i][j]=max(dp[i][j],dp[i-1][j]);
                from[i][j]=mp(i-1,j);
            }
            if(dp[i][j]<=dp[i][j-1]){
                dp[i][j]=max(dp[i][j],dp[i][j-1]);
                from[i][j]=mp(i,j-1);
            }
        }
    }
    pii now=mp(strlen(c1+1),strlen(c2+1));
    string s="";
    while(now.x&&now.y){
        if(from[now.x][now.y]==mp(now.x-1,now.y-1)){
            s+=c1[now.x];
        }
        now=from[now.x][now.y];
   //     printf("%d %d\n",now.x,now.y);
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    //printf("%d\n",dp[strlen(c1+1)][strlen(c2+1)]);
}


Measured memory_bytes: 106112