akhauriyash/Code-Regression huggingface dataset:
using System;

public static class Solution
{
  private static int[,] s_arr;
  private static int[,] s_memo;

  public static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    s_arr = new int[n, 3];
    s_memo = new int[n, 3];
    for (int i = 0; i < n; i++)
    {
      var ithDay = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      s_arr[i, 0] = ithDay[0];
      s_arr[i, 1] = ithDay[1];
      s_arr[i, 2] = ithDay[2];
      s_memo[i, 0] = -1;
      s_memo[i, 1] = -1;
      s_memo[i, 2] = -1;
    }
    if (n == 1)
    {
      Console.WriteLine(Math.Max(s_arr[0, 0], Math.Max(s_arr[0, 1], s_arr[0, 2])));
    }
    else
    {
      int max1 = s_arr[0, 0] + Solve(0, 1); // Solve(lastTakenActivity, startingDay);
      int max2 = s_arr[0, 1] + Solve(1, 1); // Solve(lastTakenActivity, startingDay);
      int max3 = s_arr[0, 2] + Solve(2, 1); // Solve(lastTakenActivity, startingDay);
      Console.WriteLine(Math.Max(max1, Math.Max(max2, max3)));
    }
  }

  private static int Solve(int lastTakenActivity, int startingDay)
  {
    if (s_memo[startingDay, lastTakenActivity] != -1)
      return s_memo[startingDay, lastTakenActivity];
    
    int option1, option2, option1Index, option2Index;
    if (lastTakenActivity == 0)
    {
      option1 = s_arr[startingDay, 1];
      option1Index = 1;
      option2 = s_arr[startingDay, 2];
      option2Index = 2;
    }
    else if (lastTakenActivity == 1)
    {
      option1 = s_arr[startingDay, 0];
      option1Index = 0;
      option2 = s_arr[startingDay, 2];
      option2Index = 2;
    }
    else
    {
      option1 = s_arr[startingDay, 0];
      option1Index = 0;
      option2 = s_arr[startingDay, 1];
      option2Index = 1;
    }

    if (startingDay == s_arr.Length / 3 - 1) return Math.Max(option1, option2); // Array length returns n * m here. We want n only, so divide by m = 3.

    return s_memo[startingDay, lastTakenActivity] =
      Math.Max(
        option1 + Solve(option1Index, startingDay + 1),
        option2 + Solve(option2Index, startingDay + 1));
  }
}

Measured memory_bytes: 56124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair <int,int> ii ;
typedef vector < ii > vii ;
typedef vector < vii > viii ;
#define rep(i,n)                   for( ll i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++) 
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define db double 
#define fi first
#define se second

string s_max="";
string s_maxi="";

void lcs(string s, string t, int m, int n) {
	int L[m+1][n+1];
	rep(i,m+1) {
		rep(j,n+1) {
			if(i==0 || j==0) L[i][j]=0;
			else if(s[i-1]==t[j-1]) L[i][j]=L[i-1][j-1]+1;
			else L[i][j]=max(L[i-1][j], L[i][j-1]);
		}
	}
	int index = L[m][n]; 
	char lcs[index+1]; 
   	lcs[index] = '\0'; 
	int i=m, j=n;
	while(i>0 && j>0) {
		if(s[i-1]==t[j-1]) {
			lcs[index-1]=s[i-1];
			i--, j--, index--;
		} else if(L[i-1][j]>L[i][j-1]) i--;
		else j--;
	}
	cout<<lcs;
} 

int main() {
   string s,t; cin>>s>>t;
   lcs(s,t,s.length(),t.length());
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define forn(i,a,b) for(long long i=a;i<=b;i++)
#define fork(i,a,b,k) for(long long i=a;i<=b;i+=k)
using namespace std;
typedef long long ll;
ll n,G,w[105],v[105],dp[105][100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>G;
	for(ll i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(ll i=0;i<=G;i++)dp[0][i]=0;
	for(ll i=0;i<=n;i++)dp[i][0]=0;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=G;j++){
			if(w[i]<=j){
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			} else {
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[n][G];
}

Measured memory_bytes: 80128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c = inpl()
print('YES' if b-a == c-b else 'NO') 

Measured memory_bytes: 67436
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
print("Yay!" if e-a<=k else ":(")
    
    
        
        
    
    
    
    
        

        
   
    
    
    
        
        
    
    
    
    
        

      
    
    
        
        
    
    
    
    
        


Measured memory_bytes: 9168
N,K = map(int,input().split())
height = [int(input()) for i in range(N)]

sort_height = sorted(height)
dif_height = [abs(sort_height[i] - sort_height[i+K-1]) for i in range(N-K+1)]

#print(dif_height)
print(min(dif_height))

Measured memory_bytes: 12060
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(void) {
  int n;
  scanf("%i", &n);
  
  int m = 3 * n;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    scanf("%i", &a[i]);
  }
  
  long long sum = 0;
  priority_queue<int> pq;
  vector<long long> dp(m);
  for (int i = 0; i < n; i++) {
    pq.push(-a[i]);
    sum += a[i];
  }
  
  dp[n-1] = sum;
  for (int i = n; i < m; i++) {
    if (-pq.top() <= a[i]) {
      sum += a[i] + pq.top();
      pq.pop();
      pq.push(-a[i]);
    }
    dp[i] = sum;
  }
  
  sum = 0;
  while (!pq.empty()) {
    pq.pop();
  }
  
  for (int i = m-n; i < m; i++) {
    pq.push(a[i]);
    sum += a[i];
  }
  
  long long ans = dp[m-n-1] - sum;
  for (int i = m-n-1; i >= n; i--) {
    if (pq.top() >= a[i]) {
      sum += a[i] - pq.top();
      pq.pop();
      pq.push(a[i]);
    }
    ans = max(ans, dp[i-1] - sum);
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;

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

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; 
static const long long INF = 1e18;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vvll g(n, vll(n)); rep(i, n) g[i][i] = INF;

    rep(i, m) {
        ll u, v, f; cin >> u >> v >> f; u--, v--;
        g[u][v] = g[v][u] = f;
    }

    vll vs;
    function<ll(vll&)> f = [&](vll& vs) {
        ll ret = 0;
        rep(i, vs.size()) {
            ll min_f = INF;
            rep(j, vs.size()) 
                chmin(min_f, g[vs[i]][vs[j]]);
            ret += min_f != INF ? min_f : 0;
        }
        repi(i, vs.size() ? vs.back()+1 : 0, n) {
            for (auto v : vs) if (!g[v][i]) goto next;
            vs.pb(i);
            chmax(ret, f(vs));
            vs.pop_back();
            next:;
        }
        return ret;
    };
    cout << f(vs) << endl;
    return 0;
}

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

const int N = 1e5 + 5;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin>>n>>s;
    int r = 0, b = 0;
    for (int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'B') b++;
    }
    if(r>b)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n;
    cin >> n;
    vector<ll> x(n);
    for(int i = 0; i < n; i++)  cin >> x[i];
    
    vector<ll> v(n+5);
    v[1] = 1;
    ll fact = 1;
    for(int i = 1; i+1 < n+2; i++){
        v[i+1] = ((i+1)*v[i]+fact)%mod;
        (fact *= (i+1)) %= mod;
    }
    ModComb mc(n+5);
    
    vector<ll> f(n+2);
    f[0] = 1;
    for(int i = 1; i <= n+1; i++)   f[i] = f[i-1]*i%mod;

    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += (x[i]-x[i-1])*v[i]%mod*mc.nCk(n-1, n-1-i)%mod*f[n-1-i]%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    string result = "Yes";

   for(int i = 0; i < S.length() && result == "Yes"; i++){
        if(i % 2 == 0 && S[i] == 'L')
            result = "No";
        else if(i % 2 == 1 && S[i] == 'R')
            result = "No";
   }

    cout << result << endl;
    
}

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


int main() {
  int x,y;cin >> x >> y;
  int xflag,yflag;
  
  if (x == 2){
    xflag = 1;
  }else if(x == 4 || x == 6 || x == 9 || x == 11){
    xflag = 2;
  }else{
    xflag = 3;
  }
  if (y == 2){
    yflag = 1;
  }else if(y == 4 || y == 6 || y == 9 || y == 11){
    yflag = 2;
  }else{
    yflag = 3;
  }

  if (xflag == yflag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


}       

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w;
    cin >> h >> w;
    dump(h);
    VS s(h);
    REP(i,0,h) cin >> s[i];
    int c[2000][2000][4] = {};
    REP(i,0,h) {
        dump(i);
        int cnt = 0;
        REP(j,0,w) {
            dump(j);
            if (s[i][j] == '#') cnt = 0;
            else {
                c[i][j][0] = cnt;
                ++cnt;
            }
        }
    }
    REP(i,0,h) {
        int cnt = 0;
        RREP(j,0,w) {
            if (s[i][j] == '#') cnt = 0;
            else {
                c[i][j][1] = cnt;
                ++cnt;
            }
        }
    }
    REP(j,0,w) {
        int cnt = 0;
        REP(i,0,h) {
            if (s[i][j] == '#') cnt = 0;
            else {
                c[i][j][2] = cnt;
                ++cnt;
            }
        }
    }
    REP(j,0,w) {
        int cnt = 0;
        RREP(i,0,h) {
            if (s[i][j] == '#') cnt = 0;
            else {
                c[i][j][3] = cnt;
                ++cnt;
            }
        }
    }
    int ans = 0;
    REP(i,0,h) REP(j,0,w) ans = max(ans, c[i][j][0] + c[i][j][1] + c[i][j][2] + c[i][j][3]);
    cout << ans + 1 << endl;
}

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

Measured memory_bytes: 66816
#include<bits/stdc++.h>                
using namespace std;
int i, N, A, B, tmp, P[3];
int main(void){
	cin >> N >> A >> B;

	for(i = 0; i < N; i++){
		cin >> tmp;
		if(tmp <= A) P[0]++;
		else if(tmp <= B) P[1]++;
		else P[2]++;
  }

	sort(P, P+3);
	cout << P[0] << endl;
	return 0;
}


Measured memory_bytes: 256
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int n, m;
    cin >> n >> m;

    priority_queue<int> pq;

    for (int i = 0; i < n; i++)
    {
        int aux;
        cin >> aux;
        pq.push(aux);
    }

    for (int i = 0; i < m; i++)
    {
        int aux = pq.top();
        pq.pop();

        aux /= 2;

        pq.push(aux);
    }

    ll sol = 0;

    while (!pq.empty())
    {
        sol += pq.top();
        pq.pop();
    }
    cout << sol;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int h,w;
int dp[1005][1005];
char a[1005][1005];
const int MOD=1000000007;
int main()
{
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>a[i][j];
    }
  }
  dp[1][1]=1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(a[i][j]!='#'){
	dp[i][j]+=dp[i-1][j]%MOD+dp[i][j-1]%MOD;
      }
    }
  }
  cout<<dp[h][w]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 5120
#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#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--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

vector<pair<ll, ll>> directions = {
  {+0, +1},
  {+0, -1},
  {+1, +0},
  {-1, +0},
};
ll bfs(ll sy, ll sx, vector<vector<char>> &grid) {
  struct Value {
    ll y, x, cost;
  };

  queue<Value> que;
  que.push({sy, sx, 0});

  while (!que.empty()) {
    Value node = que.front();
    que.pop();

    // --- 終端 ---
    if (node.y == grid.size() - 1 && node.x == grid[0].size() - 1) {
      return node.cost + 1;
    }

    if (grid[node.y][node.x] != '.') continue;
    grid[node.y][node.x] = '@';

    for(auto d: directions) {
      ll ny = node.y + d.first, nx = node.x + d.second;
      if (0 <= ny && ny < grid.size() && 0 <= nx && nx < grid[ny].size() && grid[ny][nx] == '.') {
        que.push({ny, nx, node.cost + 1});
      }
    }
  }
  return 0;
}

int main() {
  ll input(h, w);
  vector<vector<char>> grid(h, vector<char>(w));
  ll white = 0;
  REP(i, h) REP(j, w) {
    cin >> grid[i][j];
    if (grid[i][j] == '.') white++;
  }

  ll cnt = bfs(0, 0, grid);
  if (cnt == 0) cout << -1 << endl;
  else cout << white - cnt << endl;
}


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

//1,000,000,007
//1000000007
int main(void)
{
	long int l, r;
	long int i, j, k;
	long int min = 2019;
	
	scanf("%ld%ld", &l, &r);
	
	if(l % 2019 == 0) {
		printf("0\n");
		return 0;
	}
	
	if(r - l >= 2019) {
		printf("0\n");
		return 0;
	}
	
	if( (l % 2019) > (r % 2019) ) {
		printf("0\n");
		return 0;
	}
	
	for(i = l; i <= r; i++) {
		for(j = i + 1; j <= r; j++) {
			if(min > (i * j) % 2019) {
				min = (i * j) % 2019;
			}
		}
	}
	
	printf("%ld\n", min);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int search( int, int );

int main( void ) {
	int h, w, dSq, d, ans;

	for ( ; scanf( "%d %d", &h, &w ), h; printf( "%d %d\n", ans / 151, ans % 151 ) ) {
		dSq = h * h + w * w;

		if ( ans = search( h + 1, dSq ) )
			continue;

		for ( d = dSq + 1; !( ans = search( 1, d++ ) );  ) ;
	}

	return 0;
}

int search( int ini, int d ) {
	int h, w;

	for ( h = ini; h * h * 2 < d; h++ ) {
		w = sqrt( d - h * h );

		if ( w * w == d - h * h )
			return h * 151 + w;
	}

	return 0;
}

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

int main(){
    int n ,m, k, l;
    cin >> n >> m;
    if(n < m) {
        cout << "No" << "\n";
        return 0;
    } else {
        string a[50];
        string b[50];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < m; i++)
            cin >> b[i];
        for(int ly = 0; ly < n-m+1; ly++) {
            for(int lx = 0; lx < n-m+1; lx++) {
                bool flag = true;
                for(int y = 0; y < m; y++) {
                    for(int x = 0; x < m; x++) {
                        if(a[ly+y][lx+x] != b[y][x]) {
                            flag = false;
                            break;
                        }
                    }
                    if(!flag) break;
                }
                if(flag) {
                    cout << "Yes" << "\n";
                    return 0;
                }
            }
        }
    }
    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=0
l=[[0]*10 for i in range(10)]
for i in range(1,n+1):
    i=str(i)
    l[int(i[0])][int(i[-1])]+=1
for i in range(10):
    for j in range(10):
        ans+=l[i][j]*l[j][i]
print(ans)

Measured memory_bytes: 40428
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans=INF;
  for(ll i=0;i<=max(x,y);++i){
    ll cul=2*c*i+a*max(0LL,x-i)+b*max(0LL,y-i);
    //cerr<<cul<<endl;
    chmin(ans,cul);
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 256
# AliceのスコアAとBobのスコアBを整数で入力
A,B = map(int,input().split())
# AとBが同じならDrawを出力
if A == B:
    print("Draw")
# Aが1がBより大きいならAliceを出力
elif A == 1 or A > B and B!= 1 :
    print("Alice")
# Bの方が強ければBobを出力
else:
    print("Bob")

Measured memory_bytes: 9160
from itertools import product


H, W = map(int, input().split())
s = [input() for _ in range(H)]
for i, j in product(range(H), range(W)):
    if s[i][j] == ".":
        continue
    is_ok = False
    for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if s[ni][nj] == "#":
            is_ok = True
    if not is_ok:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 3004;
int dp[2][N][N], a[N];

int solve(int turn, int i, int j){
    if(i > j) 
        return 0;
    
    int &ans = dp[turn][i][j];
    if(ans != -1)
        return ans;
    
    if(turn){
        ans = max(a[i] + solve(turn ^ 1, i + 1, j), solve(turn ^ 1, i, j - 1) + a[j]);
    } else{
        ans = min(-a[i] + solve(turn ^ 1, i + 1, j), -a[j] + solve(turn ^ 1, i, j - 1));
    }
    return ans;
}

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


Measured memory_bytes: 144840
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll dp[5][110000];
int main(){
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    rep(i,2){
        rep(j,n) dp[i][j]=-inf;
    }
    dp[0][0]=v[0]+v[1];
    dp[1][0]=-v[0]-v[1];
    rep(j,n-2){
        rep(i,2){
            //cout<<"step "<<i<<" "<<j<<endl;

            if(i==0){
                /*
                cout<<"pettern 1"<<endl;
                cout<<dp[i][j]+v[j+2]<<" "<<dp[i+1][j]<<endl;
                cout<<dp[i][j]-2*v[j+1]-v[j+2]<<" "<<dp[i+1][j+1]<<endl;*/
                dp[i][j+1]   =   max(   dp[i][j]+v[j+2] , dp[i][j+1]   );
                dp[i+1][j+1]   =    max(dp[i][j]   -2*v[j+1]   -v[j+2]  , dp[i+1][j+1]);
                //cout<<dp[i][j+1]<<" "<<dp[i+1][j+1]<<endl;
            }else{
                /*cout<<"pettern2"<<endl;
                cout<<dp[i+1][j-1]<<" "<<dp[i][j]+v[j+2]<<endl;
                cout<<dp[i+1][j]<<" "<<dp[i][j]+2*v[j+1]-v[j+2]<<endl;*/
                dp[i-1][j+1]=max(dp[i-1][j+1],dp[i][j]+v[j+2]);
                dp[i][j+1]=max(dp[i][j+1],dp[i][j]+2*v[j+1]-v[j+2]);
                //cout<<dp[i-1][j+1]<<" "<<dp[i][j+1]<<endl;
            }
        }
        //cout<<endl;
    }
    /*
    rep(i,2){
        rep(j,n-1) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<max(dp[0][n-2],dp[1][n-2])<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int N,tem,counter=0;
	cin>>N;
	REP(i,N){
		cin>>tem;
		if(tem%2==1) counter++;
	}
	
	if(counter%2==1) print("NO");
	else print("YES");
		
	
}


Measured memory_bytes: 256
#include <iostream>

const int days = 365;
int c[26];
int s[days][26];

int main()
{
	int d;
	std::cin >> d;


	for (int i = 0; i < 26; ++i)
		std::cin >> c[i];

	for (int i = 0; i < days; ++i)
		for (int j = 0; j < 26; ++j)
			std::cin >> s[i][j];

	int t[days];
	for (int i = 0; i < days; ++i)
	{
		std::cin >> t[i];
		t[i]--;
	}

	// 満足度の計算
	//int score = 0;
	for (int i = 0; i < days; ++i)
	{
		int maxDelta = 0;

		for (int f = 0; f < 26; ++f)
		{
			int delta = s[i][f];
			//score += s[i][t[i]];

			for (int j = 0; j < 26; ++j)
			{
				for (int k = i; k >= 0; --k)
				{
					if (t[k] != j)
						delta -= c[j];
				}
			}

			if (maxDelta == 0 || maxDelta < delta)
			{
				maxDelta = delta;
				t[i] = f;
			}
		}
	}

	// 最適化
	for (int se = 0; se < 10; ++se)
	{
		for (int i = 0; i < days; ++i)
		{
			// デメリットの計算
			int unDelta = s[i][t[i]];

			{
				// 前に何日分あるか
				int cnt1 = 0;
				for (int k = i - 1; k >= 0; --k)
				{
					if (t[k] != t[i])
						cnt1++;
					else break;
				}

				// 後に何日分あるか
				int cnt2 = 0;
				for (int k = i + 1; k < days; ++k)
				{
					if (t[k] != t[i])
						cnt2++;
					else break;
				}

				// 増加量
				int sum = (cnt2 + 1) * (cnt1 + 1);

				// 合計の削減量
				unDelta += sum * c[t[i]];
			}


			// メリットの計算
			int maxDelta = 0;
			int maxT = 0;
			for (int f = 0; f < 26; ++f)
			{
				if (f == t[i]) continue;

				// もともとの増える量
				int delta = s[i][f];

				{
					// 前に何日分あるか
					int cnt1 = 0;
					for (int k = i; k >= 0; --k)
					{
						if (t[k] != f)
							cnt1++;
						else break;
					}

					// 後に何日分あるか
					int cnt2 = 0;
					for (int k = i; k < days; ++k)
					{
						if (t[k] != f)
							cnt2++;
						else break;
					}

					// 削減出来る量
					int sum = cnt2 * cnt1;

					// 合計の削減量
					delta += sum * c[f];
				}

				if (maxDelta == 0 || maxDelta < delta)
				{
					maxDelta = delta;
					maxT = f;
				}
			}

			if (maxDelta > unDelta)
			{
				t[i] = maxT;
			}
		}
	}

	for (int i = 0; i < days; ++i)
		std::cout << t[i] + 1 << std::endl;
}

Measured memory_bytes: 3660
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>


using namespace std;


using namespace std;

int main() {
 int A,B;
 cin>>A>>B;

 if(A>B&&B!=1&&B!=0){

     cout<<A-B<<endl;

 }

 if(B>A){

     cout<<"0"<<endl;


 }


 if(B==1||B==0){

     cout<<"0"<<endl;
 }

 if(A==B&&B!=1){

     cout<<"0"<<endl;
 }


   }


Measured memory_bytes: 256
import math
A,B,C,D = map(int, input().split())

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

betweenAandB = B-A+1

cA = (A-1)//C
cB = B//C
cDiv = cB - cA

dA = (A-1)//D
dB = B//D
dDiv = dB - dA

GCD = gcd(C,D)
LCM = C*D//GCD

lcmA = (A-1)//LCM
lcmB = B//LCM
lcmDiv = lcmB - lcmA

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c && a % 2 == 0){
        cout << -1 << endl;
        return 0;
    }else{
        long ans = 0;
        while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
            ans++;
            long aa = (b + c) / 2, bb = (c + a) / 2, cc = (a + b) / 2;
            a = aa;
            b = bb;
            c = cc;
        }
        cout << ans << endl;
        return  0;
    }
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x_temp = x2 - x1
y_temp = y2 - y1

x3 = x2 - y_temp
y3 = y2 + x_temp

x4 = x3 - x_temp
y4 = y3 - y_temp

print(x3, y3, x4, y4)

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = RArInt();
            int ap = vs[0] * 3 + vs[1];
            Console.WriteLine(ap / 2);

        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


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

int classNameIndex(double weight) {
    int ret;
    if (weight <= 48) ret = 0;
    else if (weight <= 51) ret = 1;
    else if (weight <= 54) ret = 2;
    else if (weight <= 57) ret = 3;
    else if (weight <= 60) ret = 4;
    else if (weight <= 64) ret = 5;
    else if (weight <= 69) ret = 6;
    else if (weight <= 75) ret = 7;
    else if (weight <= 81) ret = 8;
    else if (weight <= 91) ret = 9;
    else ret = 10;
    return ret;
}

int main() {
    const char* className[] = {
        "light fly", "fly", "bantam", "feather", "light", "light welter",
        "welter", "light middle", "middle", "light heavy", "heavy",
    };
    double weight;
    while (cin >> weight) {
        cout << className[classNameIndex(weight)] << endl;
    }
}

Measured memory_bytes: 0
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<map>
#include<set>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=110;
ll x,k,d;
int main()
{
    cin>>x>>k>>d;
    
    ll cnt=abs(x)/d;
    if(k<=cnt) cout<<abs(x)-d*k<<endl;  
    else
    {
        ll now=abs(x)-d*cnt;
        if((k-cnt)&1) cout<<abs(now-d)<<endl;
        else cout<<now<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<p2,int> p3;
typedef vector<ll> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 5 + 1e18;
const ll MAX = 5+ 1e5;
int N,M,dp[MAX];
vi G[MAX];
int DFS(int u,int pre)
{
    if( dp[u] != -1 )
        return dp[u];
        dp[u] = 0;
    for(int v : G[u])
        if( v != pre )
            dp[u] = max( dp[u] ,DFS(v,u) +1);
    return dp[u];
}
int main()
{
    cin >> N >> M;
    while(M--){
        int u,v;
        cin >> u >> v;
        G[u].push_back(v);
    }
    memset(dp,-1,sizeof(dp));
    int ans = 0;
    for(int i=1;i<=N;i++)
    if( dp[i] == -1 ){
        ans = max( ans, DFS(i,i) );
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <cstdio> 
#include <vector>
using namespace std;

 
int main(void) { 
    int n;
    int x;
    vector<int> lst(n);
    cin>>n;

    for (int i=0;i<n;i++){
        cin>>x;
        if (x %2==0){
            lst.push_back(x);
        }
    }
    for (int j =0;j<lst.size();j++){
        if (lst.at(j) %2==0 && (lst.at(j) %3!=0 && lst.at(j) % 5!=0)){
            cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
    return 0;
}

Measured memory_bytes: 35072
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val list = List.fill(n)(sc.nextInt)
  
  def check(list: Seq[Int], count: Int): Int = {
    val index = list.indexOf(count)
    if (index == -1) count - 1
    else check(list.drop(index + 1), count + 1)
  }
  
  val leftNum = check(list, 1)
  
  println(if (leftNum == 0) -1 else n - leftNum)
}

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

m = [0]*N

for i in range(N):
    k, v = input().split()
    m[i] = [k, int(v), i+1]

m.sort()

for j in range(N):
    for i in range(N-1):
        if m[i][0] == m[i+1][0] and m[i][1] < m[i+1][1]:
            m[i], m[i+1] = m[i+1], m[i]


for i in m:
    print(i[2])


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

#define INF INT_MAX
#define ll long long

using namespace std;

int main(){
	int a,b,c;
	int ans = 3;
	cin >> a >> b >> c;
	if(a == b){
		if(a == c)
			ans = 1;
		else
			ans = 2;
	}else if(b == c){
		if(b == a)
			ans = 1;
		else
			ans = 2;
	}else if(c == a){
		if(c == b)
			ans = 1;
		else
			ans = 2;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {
	int n;
	double t, a;

	cin >> n;
	cin >> t >> a;

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

	double ans = 10000000;
	int ans_i;
	for (int i = 0; i < n; i++) {
		double tem = t - h[i] * 0.006;
		
		if (fabs(a - tem) < ans) {
			ans = fabs(a -tem);
			ans_i = i;
		}
	}
	
	cout << ans_i + 1 << endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
ok=[w*[0]for _ in range(h)]
ok[0][0]=1
for i in range(h):
  for j in range(w):
    if i==0:
      if j!=0:
        if s[i][j]=="#":ok[i][j]=ok[i][j-1]
    else:
      if s[i][j]=="#":ok[i][j]|=ok[i-1][j]
      if j==0:continue
      if s[i][j]=="#":ok[i][j]|=ok[i][j-1]
co=sum(i.count("#")for i in s)
if co!=h+w-1:print("Impossible")
elif ok[-1][-1]:print("Possible")
else:print("Impossible")

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

#define rep(i, n) for(int i=0; i<n; i++) 

int main() {
    int n, k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i, n) cin>>h[i];

    if(n<=k){
        cout<<0<<endl;
    }else{
        sort(h.begin(), h.end());

        long long int cnt=0;

        rep(i, n-k){
            cnt+=h[i];
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <bitset>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=4000;
const int mod=998244353;
int n,m,len,a[9][N+1],f[N+1][N+1],s[N+1],ans;
bool ex[N+1];
void inc(int d){
	ans=(ans+s[d])%mod;
}
int main(){
	s[0]=1;
	ref(i,1,N)s[i]=s[i-1]*2%mod;
	scanf("%d",&n);
	ref(i,0,n){
		char c=getchar();while(c<'0'||c>'1')c=getchar();
		m=-1;
		while(c>='0'&&c<='1')a[i][++m]=c-48,c=getchar();
		ref(j,0,m/2)swap(a[i][j],a[i][m-j]);
		while(m>=0&&!a[i][m])m--;
		if(!i){len=m;continue;}
		while(m>=0&&m<=N){
			while(m>=0&&ex[m]){
				ref(j,0,m)a[i][j]^=f[m][j];
				while(m>=0&&!a[i][m])m--;
			}
			if(m<0)break;
			ref(j,0,m)f[m][j]=a[i][j];ex[m]=1;
			def(j,m,0)a[i][j+1]=a[i][j];a[i][0]=0;m++;
		}
	}
	m=N+1;
	while(m>0&&ex[m-1])m--;
	if(m>N){printf("0\n");return 0;}
	def(i,len,m){
		if(a[0][i]==1)inc(i-m);
		if(a[8][i]!=a[0][i])ref(j,0,i)a[8][j]^=f[i][j];
	}
	bool flag=1;
	def(i,m-1,0)if(a[8][i]>a[0][i]){flag=0;break;}
		else if(a[8][i]<a[0][i])break;
	if(flag)inc(0);
	printf("%d\n",ans);
}

Measured memory_bytes: 61440
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = n - 1; i >= 1; i--) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[0]);
        sc.close();
    }
}


Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i,j,n) for (int i = (j); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using ll =long long;

int main() {
  int ans=0;
  int n;
  cin>>n;
  FOR(i,1,n+1){
    if(to_string(i).length()%2==1){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int digits(long S) {
  int digit = 0;
  while (S != 0) {
    S /= 10;
    ++digit;
  }
  return digit;
}

int main() {
  long S;
  cin >> S;
  
  int digit = digits(S);
  
  vector<int> A(digit);
  long S_sub = S;
  for (int i = 0; i < digit; ++i) {
    A.at(i) = S_sub % 10;
    S_sub /= 10;
  }
  
  long ans = 0;
  for (int bit = 0; bit < (1 << digit - 1); ++bit) {
    vector<int> B(digit - 1, 0);
    for (int i = 0; i < digit - 1; ++i) {
      if (bit & (1 << i)) B.at(i) = 1;
    }
    
    long sum = 0;
    long memo = A.at(digit - 1);
    
    for (int i = 0; i < digit - 1; ++i) {
      if (B.at(digit - 2 - i) == 0) {
        memo *= 10;
        memo += A.at(digit - 2 - i);
      } else {
        sum += memo;
        memo = A.at(digit - 2 - i);
      }
    }
    sum += memo;
    ans += sum;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//				new Main().solveA();
		//		new Main().solveA2();
		new Main().solveB();
		//		new Main().solveC();
		//		new Main().solveC2();
		// new Main().solveD();
	}

	/*
	 * なんでこんな複雑なソースを書いたのだろう？
	 */
	private void solveA() {

		try (Scanner scanner = new Scanner(System.in)) {
			int numA = 0;
			int numB = 0;
			int numC = 0;
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			numC = scanner.nextInt();

			int wk = numB;
			int res = 0;
			while (wk >= numA && res < numC) {
				wk -= numA;
				res++;
			}

			System.out.println(res);

		}
	}

	/*
	 * こちらでもAC
	 */
	private void solveA2() {

		try (Scanner scanner = new Scanner(System.in)) {
			int numA = scanner.nextInt();
			int numB = scanner.nextInt();
			int numC = scanner.nextInt();

			int res = 0;
			if (numB / numA > numC) {
				res = numC;
			} else {
				res = numB / numA;
			}

			System.out.println(res);

		}
	}

	private void solveB() {

		try (Scanner scanner = new Scanner(System.in)) {
			int numA = scanner.nextInt();
			int numB = scanner.nextInt();
			int numK = scanner.nextInt();

			List<Integer> wk = new ArrayList<Integer>();
			int cnt = 0;
			for (int i = Math.max(numA, numB); i >= 1; i--) {
				if (numA % i == 0 && numB % i == 0) {
					cnt++;
				}
				if (cnt == numK) {
					System.out.println(i);
					return;
				}
			}

		}
	}

	private int getList(List<Character> wk) {

		if (wk.size() < 2) {
			return 0;
		}

		int res = 0;
		int i1 = 0;
		int i2 = 1;
		for (int i = 1; i < wk.size(); i++) {
			if (wk.get(i) != wk.get(i - 1)) {
				i1 = i - 1;
				i2 = i;
				break;
			}
			if (i == wk.size() - 1) {
				return 0;
			}
		}
		while (i2 < wk.size()) {

			char c1 = wk.get(i1);
			char c2 = wk.get(i2);
			if (c1 != c2) {
				wk.remove(i2);
				wk.remove(i1);
				res += 2;
			} else {
				i1 = i2;
				i2 = i2 + 1;
			}
		}
		return getList(wk) + res;
	}

	private void solveC() {

		try (Scanner scanner = new Scanner(System.in)) {
			char[] wkS;
			wkS = scanner.next().toCharArray();

			List<Character> wk = new ArrayList<Character>();
			for (char c : wkS) {
				wk.add(c);
			}

			System.out.println(getList(wk));

		}
	}

	private void solveC2() {

		try (Scanner scanner = new Scanner(System.in)) {
			char[] wkS;
			wkS = scanner.next().toCharArray();

			int cnt0 = 0;
			int cnt1 = 0;
			for (char c : wkS) {
				if (c == '0') {
					cnt0++;
				} else if (c == '1') {
					cnt1++;
				}
			}

			System.out.println(Math.min(cnt0, cnt1) * 2);

		}
	}

	private void solveD() {

		try (Scanner scanner = new Scanner(System.in)) {
			int numN = 0;
			int numK = 0;
			int numS = 0;
			numN = scanner.nextInt();

			System.out.println("");

		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int MOD = 1e9+7;
int p[N],mu[N],tot,n,k,ans,op;
bool flg[N];
void getMu(){
    tot=0; mu[1]=1;
    for(int i=2;i<N;++i){
        if(!flg[i]){
            p[++tot]=i;
            mu[i]=-1;
        }
        for(int j=1;j<=tot&&i*p[j]<N;++j){
            flg[i*p[j]]=true;
            if(i%p[j]==0){
                mu[i*p[j]]=0;
                break;
            }
            else mu[i*p[j]]=-mu[i];
        }
    }
    for(int i=1;i<N;++i) mu[i]+=mu[i-1];
}
int fpow(int x,int p){
    int rs=1;
    while(p){
        if(p&1) rs=1LL*rs*x%MOD;
        x=1LL*x*x%MOD; p>>=1;
    }
    return rs;
}
int cal(int n){
    int rs=0;
    for(int i=1,j=0;i<=n;i=j+1){
        j=n/(n/i);
        rs=(rs+1LL*fpow(n/i,k)*(mu[j]-mu[i-1]+MOD))%MOD;
    }
    return rs;
}
int main(){
    getMu(); scanf("%d %d",&k,&n);
    for(int i=1,j=0;i<=n;i=j+1){
        j=n/(n/i); op=1LL*(i+j)*(j-i+1)/2%MOD;
        ans=(ans+1LL*op*cal(n/i))%MOD;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 4348
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 200001
 
#define ll long long int
 vector<int> wav;
 int m;vector<int> q;
 //int dp[22][11][1002]
 
int main(){
	int n;
	cin>>n;
	if(n>=30){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
 
}


Measured memory_bytes: 3556
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
ans = 0
for n in Counter(accumulate([0]+A)).values():
    ans += n*(n-1)//2
print(ans)


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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = "NG";
        for (int i = ab[0]; i <= ab[1]; i++)
        {
            if (i % k == 0)
            {
                ans ="OK";
                break;
            }
        }
        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28296
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
	ll coin, ans = 0;
	cin >> coin;
	while(coin >= 5){
		if(coin >= 500){
			ans += 1000;
			coin = coin - 500; 
		}
		else if(coin >= 5){
			ans += 5;
			coin -= 5;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int ar[200005];
int32_t main(){
	int n;
	cin>>n;
	int mn = 1e9;
	int ans = 0;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		if(ar[i]<mn){
			ans++;
			mn = ar[i];
		}
	}
	cout<<ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int h, w;
vstr s(51);
vint dx = {1, 0, -1, 0};
vint dy = {0, 1, 0, -1};

bool check(int x, int y) {
    bool res = false;
    rep(i, 4) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx >= 0 && h > nx && ny >= 0 && w > ny) {
            if (s[nx][ny] == '#') res = true;
        }
    }
    
    return res;
}

int main() {
    cin >> h >> w;
    s.resize(h);
    rep(i, h) cin >> s[i];
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#' && check(i, j) == false) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
/* 167b.c */
#include <stdio.h>

int main(void){
    int a,b,c=0;
    int k=0;
    int count=0;
    int k2=0;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    for(int i=0;i<a;i++){
        count=count+1;
        k2++;
        if(k2==k){
            printf("%d",count);
            return 0;
        }
    }
    for(int i=0;i<b;i++){
        count=count+0;
        k2++;
        if(k2==k){
            printf("%d",count);
            return 0;
        }
    }
    for(int i=0;i<c;i++){
        count=count-1;
        k2++;
        if(k2==k){
            printf("%d",count);
            return 0;
        }
    }
}

Measured memory_bytes: 1684