akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<int> dp(N + 1, INF);
    dp[N] = 0;
    REPR(i, N) {
        if (dp[i] == INF) continue;
        REP(a, 7) {
            int x = i - pow(6, a);
            int y = i - pow(9, a);
            if (x >= 0) chmin(dp[x], dp[i] + 1);
            if (y >= 0) chmin(dp[y], dp[i] + 1);
        }
    }
    cout << dp[0] << endl;
    return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

i64 f(i64 v) {
  if (v < 0) return 0;
  i64 r = 0;
  F0R(i, 60) {
    i64 a = v >> (i + 1) << i;
    i64 b = (v & (((i64)1 << (i + 1)) - 1));
    if (b > (((i64)1 << i) - 1)) b -= (((i64)1 << i) - 1);
    else b = 0;
    a += b;
    r |= (a & 1) << i;
  }
  return r;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << newl;
}
#endif


Measured memory_bytes: 3648
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] ipt = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(ipt[i]);
    }
    int count = 1, num = 0;
    for (int i = 0; i < N; i++) {
      if (arr[i] == count) {
        count++;
      } else {
        num++;
      }
    }
    Console.WriteLine(count == 1 ? -1 : num);
  }
}

Measured memory_bytes: 33116
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
int n,ans,sum;
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		int x;
		read(x);
		ans+=sum*x;
		sum+=x;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main(){
  int taro, hanako, n;
  string t_card, h_card;

  taro = 0;
  hanako = 0;

  cin >> n;

  while(n--){
    cin >> t_card >> h_card;
    if(t_card > h_card) taro += 3;
    else if(t_card < h_card) hanako += 3;
    else{
      taro++;
      hanako++;
    }
  }
  cout << taro << " " << hanako << endl;

  return 0;
}

Measured memory_bytes: 1208
def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in range(2 ** N):
        b = bin(i)[2:]
        b = b.zfill(N)
        tmp = [0] * (M + 1)
        for j, v in enumerate(b):
            if v == '0':
                continue
            tmp[0] += CA[j][0]
            for k in range(1, M + 1):
                tmp[k] += CA[j][k]
        f = 1
        for p in range(1, M + 1):
            if tmp[p] < X:
                f = 0
                break
        if f == 0:
            continue
        ans = min(ans, tmp[0])
    if ans == float('inf'):
        return '-1'
    else:
        return ans


print(m())


Measured memory_bytes: 9236
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC138A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            String s;

            s = Console.ReadLine();

            if (a >= 3200)
                Console.WriteLine(s);
            if (a < 3200)
                Console.WriteLine("red");

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int ball, cnt[n],cost=0;
    for (int i=0; i<n; i++) cnt[i]=0;
    for (int i=0; i<n; i++)
    {
        cin>>ball;
        cnt[ball-1]++;
    }
    sort(cnt, cnt+n);
    for (int i=0; i<n-k; i++) cost+=cnt[i];
    cout<<cost;
    return 0;
}

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

int main(){
	int n,a[4]={0,0,0,0};
	cin>>n;
	string s;
	for(int i=1;i<=n;++i){
		cin>>s;
		if(s=="AC"){
			a[0]++;
		}
		else if(s=="WA"){
			a[1]++;
		}
		else if(s=="TLE"){
			a[2]++;
		}
		else{
			a[3]++;
		}
	}
	cout<<"AC x "<<a[0]<<"\n";
	cout<<"WA x "<<a[1]<<"\n";
	cout<<"TLE x "<<a[2]<<"\n";
	cout<<"RE x "<<a[3]<<"\n";
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  int now;
  double d;
  cin >> n;
  repr(i,n,0){
    d = sqrt(i);
    now = d;
    rep(j,now-2,now+2){
      if(pow(now,2) == i) {cout << i << endl;
                           return 0;
                          }
    }
  }
}

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

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Boolean[] dislike = new Boolean[10];
        Arrays.fill(dislike, Boolean.FALSE);
        for (int i = 0; i < k; i++) {
            int tmp = sc.nextInt();
            dislike[tmp] = true;
        }

        for (int i = n; ; i++) {
            int tmp = i;
            boolean flag = true;
            while (tmp > 0) {
                int bit = tmp % 10;
                tmp /= 10;
                if (dislike[bit]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 23764
import sys
input=sys.stdin.readline

N=int(input())
Happiness=[list(map(int,input().split())) for _ in range(N)]

#dp[iまでの幸福度のmax][最終状態]
dp=[[0,0,0] for _ in range(N+1)]

for i in range(N):
    dp[i+1][0]=max(dp[i][1],dp[i][2])+Happiness[i][0]
    dp[i+1][1]=max(dp[i][0],dp[i][2])+Happiness[i][1]
    dp[i+1][2]=max(dp[i][0],dp[i][1])+Happiness[i][2]

ans=max(dp[N][0],dp[N][1],dp[N][2])
print(ans)


Measured memory_bytes: 72284
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

using Z = int;
constexpr Z INF = numeric_limits<Z>::max();

#ifdef DEBUG
# define dump(x) cerr << "dump@" << __LINE__ << " : " << #x << " = " << (x) << endl
# define mesg(m) cerr << "mesg@" << __LINE__ << " : " << m << endl
# define debug if (true)
#else
# define NDEBUG
# define dump(x)
# define mesg(m)
# define debug if (false)
#endif
#define rep(i, n) for (auto i = 0; i < n; i++)
#define rrep(i, n) for (auto i = n; i >= 0; i--)
#define all(c) begin(c), end(c)

class union_find {
  private:
    vector<Z> rank, parent;
  public:
    union_find(Z n): rank(n, 1), parent(n) {
      rep (i, n)
        parent[i] = i;
    }
    Z root(Z x) {
      auto& par = parent[x];
      if (par == x) return x;
      return par = root(par);
    }
    void unite(Z x, Z y) {
      x = root(x);
      y = root(y);
      if (x == y) return;
      if (rank[x] < rank[y])
        parent[x] = y;
      else {
        if (rank[x] == rank[y])
          rank[x]++;
        parent[y] = x;
      }
    }
    bool connected(Z x, Z y) {
      return root(x) == root(y);
    }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Z n, m;
  cin >> n >> m;
  union_find uf(n + m);
  rep (i, n) {
    Z k;
    cin >> k;
    rep (j, k) {
      Z l;
      cin >> l;
      l--;
      uf.unite(l, m + i);
    }
  }
  rep (i, n) {
    if (uf.connected(m, m + i))
      continue;
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 1792
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)
    A = tuple(geta(int))

    ans = sum([1 / ai for ai in A])

    print(1 / ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
<?php
  $tmp = explode(" ", trim(fgets(STDIN)));

  $n = $tmp[0];
  $l = $tmp[1];
  $aji = [];

  for($i=0; $i<$n; $i++){
    $aji[$i] = $l + $i;
  }

  $minIdx = 0;
  for($i=1; $i<$n; $i++){
    if(abs($aji[$i]) < abs($aji[$minIdx])){
      $minIdx = $i;
    }
    //増加していくならbreak
    if($aji[$i] > 0 && $aji[$i]>$aji[$i-1]){
      break;
    }
  }
  
  $result = 0;
  for($i=0; $i<$n; $i++){
    //echo $aji[$i].($i==$minIdx ? "-x" : "-o")."\n";
    if($i!=$minIdx){
      //echo $aji[$i]."\n";
      $result += $aji[$i];
    }
  }
  
  echo $result."\n";
?>

Measured memory_bytes: 4604
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

//ユークリッドの互除法
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x;}


int main() {
	string s;
	cin >> s;
	vector<char> key;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '0') {
			key.push_back('0');
		}
		else if (s[i] == '1') {
			key.push_back('1');
		}
		else if (s[i] == 'B' && !key.empty()) {
			key.pop_back();
		}
	}
	string ans(key.begin(), key.end());
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[])
{
	long int n,i,j,k,l;
	scanf("%ld%ld%ld",&n,&i,&j);
	if(i>j)	{printf("0");	return 0;}
	if(n==1&&i!=j)	{printf("0");	return 0;}
	k=(n-1)*i+j;
	l=(n-1)*j+i;
	printf("%ld",l-k+1);
	return 0;
}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS)
MII = lambda: list(map(int, IS.split()))

def main():
    s = IS()
    d = '2019/04/30'
    if s <= d: print('Heisei')
    else: print('TBD')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}

int d[100];
int n, k;

int gd(int n) {
	while (n) {
		int x = n % 10;
		n /= 10;
		for (int i = 0; i < k; ++i)
			if (x == d[i])
				return 0;
	}
	return 1;
}

int main() {
	cin >> n;
	cin >> k;
	for (int i = 0; i < k; ++i)
		cin >> d[i];
	while (!gd(n))
		++n;
	cout << n << "\n";
	return 0;
}




Measured memory_bytes: 256
n = int(input())
edge = [[int(i) for i in input().split()] for j in range(n-1)]
graph = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = edge[i][0], edge[i][1], edge[i][2] % 2
    graph[u].append((v,w))
    graph[v].append((u,w))

color = [-1] * (n+1)
dist = [0] * (n+1)    
stack = [1]
color[1] = 0

while stack:
    x = stack.pop()
    cx = color[x]
    dx = dist[x]
    for y, w in graph[x]:
        if color[y] >= 0:
            continue
        dist[y] = dist[x] + w
        if dist[x] ^ dist[y] == 0:
            color[y] = color[x]
        else:
            color[y] = (color[x] + 1) % 2
        stack.append(y)
print('\n'.join([str(n) for n in color[1:]]))

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

int main()
{
  int n,a,v,maxa=-1,maxv=-1;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>v;
    if(maxv<v){
      maxa=a;
      maxv=v;
    }
    else if(maxv==v && a<maxa){
      maxa=a;
      maxv=v;
    }
  }
  cout<<maxa<<" "<<maxv<<endl;
  return 0;
}

Measured memory_bytes: 1168
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

class Card {
public:
   char mark;
   int number;
   string name;

   Card(string str) {
      name = str;
      mark = str[0];
      number = stol(str.substr(1));
   }

   Card() {};

   Card(const Card &other) {
      name = other.name;
      mark = other.name[0];
      number = stol(other.name.substr(1));
   };
};

bool operator < (const Card &left, const Card &right) {
   return left.number < right.number;
}

bool operator > (const Card &left, const Card &right) {
   return right.number < left.number;
}

bool operator == (const Card &left, const Card &right) {
   return left.name == right.name;
}

bool operator != (const Card &left, const Card &right) {
   return !(left == right);
}

int main() {
   int N; cin >> N;
   V<Card> cards = V<Card>(N); rep(i, N) {
      string buff; cin >> buff;
      cards[i] = Card(buff);
   }
   V<Card> stable_cards = V<Card>(cards);
   sort(stable_cards.begin(), stable_cards.end());

   V<Card> bubble_cards = V<Card>(cards);
   bool ok = false;
   while (!ok) {
      ok = true;
      rep(i, N-1) {
         REP(j, i, N-1) {
            if (bubble_cards[j] > bubble_cards[j+1]) {
               swap(bubble_cards[j], bubble_cards[j+1]);
               ok = false;
            }
         }
      }
   }
   cout << bubble_cards[0].name; REP(i, 1, N) cout << " " << bubble_cards[i].name; cout << endl;
   cout << "Stable" << endl;

   V<Card> choose_cards = V<Card>(cards);
   rep(i, N-1) {
      int min_i = i;
      REP(j, i, N) {
         if (choose_cards[j] < choose_cards[min_i]) min_i = j;
      }
      swap(choose_cards[min_i], choose_cards[i]);
   }
   cout << choose_cards[0].name; REP(i, 1, N) cout << " " << choose_cards[i].name; cout << endl;
   bool all_true = true;
   rep(i, N) {
      if (choose_cards[i] != stable_cards[i]) {
         all_true = false;
         break;
      }
   }
   if (all_true) cout << "Stable" << endl;
   else cout << "Not stable" << endl;

   return 0;
}



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

int main() {
  int num_query; cin >> num_query;
  set<int> integers;
  
  for (int loop = 0; loop < num_query; loop++) {
    int command, x; scanf("%d %d", &command, &x);
    
    switch (command) {
      case 0:
        integers.insert(x);
        printf("%d\n", integers.size());
        break;
        
      case 1:
        printf("%d\n", integers.count(x));
        break;
    }
  }
}


Measured memory_bytes: 12520
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
def sum2d(i1,j1,i2,j2):
    A[i1][j1] += 1
    A[i1][j2] -= 1
    A[i2][j1] -= 1
    A[i2][j2] += 1


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,K = map(int,input().split())
XYC = [list(input().split()) for _ in range(N)]

A = [[0 for _ in range(K*2+1)] for _ in range(K*2+1)]

for x,y,c in XYC:
    # 白はそのまま, 黒はx軸方向にKずらして白として扱う
    i = (int(x) if c=="W" else int(x)+K) % (K*2)
    j = int(y) % (K*2)
    i0 = i%K
    j0 = j%K

    # 分割区画の左下が白の場合 (白は5箇所)
    #   a * b
    #   * c *
    #   d * e
    if (i<K and j<K) or (i>=K and j>=K):
        sum2d(0,0,i0,j0) # (a)左上
        sum2d(i0+K,0,K*2,j0) # (b)右上
        sum2d(i0,j0,i0+K,j0+K) # (c)真ん中
        sum2d(0,j0+K,i0,K*2) # (d)左下
        sum2d(i0+K,j0+K,K*2,K*2) # (e)右下

    # 分割区画の左下が黒の場合 (白は4箇所)
    #   * a *
    #   b * c
    #   * d *
    else:
        sum2d(i0,0,i0+K,j0) # (a)上
        sum2d(0,j0,i0,j0+K) # (b)左
        sum2d(i0+K,j0,K*2,j0+K) # (c)右
        sum2d(i0,j0+K,i0+K,K*2) # (d)下
 
# 2次元累積和
AA = np.array(A)
for i in range(K*2):
    AA[i+1, :] += AA[i, :]
for j in range(K*2):
    AA[:, j+1] += AA[:, j]
 
print(AA.max())
 

Measured memory_bytes: 101888
from fractions import gcd
def lcm(nums):
    ret = 1
    for i in nums:
        ret = ret*i//gcd(ret, i)
        if ret>m:
            return m+1
    return ret

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [i//2 for i in a]
g = lcm(b)
if any((g//i)%2==0 for i in b):
    ans = 0
else:
    ans = (m//g+1)//2
print(ans)

Measured memory_bytes: 89580
def solve():
    K = int(input())
    A,B = [int(i) for i in input().split()]
    qA,rA = divmod(A, K)
    qB,rB = divmod(B, K)
    if rA == 0 or rB == 0:
        print("OK")
    elif qB - qA > 0:
        print("OK")
    else:
        print("NG")

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9196
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint,
       std.ascii,
       std.typecons;
// }}}
// tbh.scanner {{{
class Scanner {
  import std.stdio;
  import std.conv : to;
  import std.array : split;
  import std.string : chomp;

  private File file;
  private dchar[][] str;
  private uint idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  private dchar[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    dchar[] s;
    while (s.length == 0) {
      s = file.readln.chomp.to!(dchar[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(uint len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {}
  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int w, h;
  dchar c;
  cin.scan(w, h, c);
 
  writeln("+" ~ "-".repeat(w - 2).join ~ "+");
  foreach (i; 0 .. h - 2) {
    if (i == (h - 2) / 2) {
      writeln("|" ~ ".".repeat((w - 2) / 2).join ~ cast(char)c ~ ".".repeat((w - 2) / 2).join ~ "|");
    } else {
      writeln("|" ~ ".".repeat(w - 2).join ~ "|");
    }
  }
  writeln("+" ~ "-".repeat(w - 2).join ~ "+");
}



Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e10;

long long N, A, B;
vector<long long> h;

//K回の爆発で全モンスターを倒せるかどうか
bool f(long long K){
    long long tmp = 0;
    for(int i = 0; i < N; i++){
        long long ret = h[i] - B * K;
        if(ret > 0)tmp += (ret + (A - B - 1)) / (A - B);
    }
    return (tmp <= K);
}

long long binary_search(long long ok, long long ng){
    while(abs(ok - ng) > 1){
        long long mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N >> A >> B;
    h.resize(N);
    for(int i = 0; i < N; i++)cin >> h[i];
    cout << binary_search(INF, 0) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>	
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define int long long

// random_device rd; mt19937 g(rd());

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
 
int id[100][100];
int cur[100];
vector <int> what;
int ans;
int k[100], p[100];
set <vector <int> > s;

main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) 
	{
		cin >> k[i];
		for(int j = 1; j <= k[i]; j++) cin >> id[i][j], id[i][j]--;
	}
	for(int i = 1; i <= m; i++) cin >> p[i];
	for(int mask = 0; mask < (1 << n); mask++)
	{
		memset(cur, 0, sizeof cur);
		int cnt = 0;
		for(int i = 0; i < n; i++)
			for(int j = 1; j <= m; j++) 
				for(int l = 1; l <= k[j]; l++) 
					if(id[j][l] == i) cur[j] += ((mask >> i) & 1);
		for(int i = 1; i <= m; i++) if(p[i] == cur[i] % 2) cnt++;
		if(cnt == m) ans++;
	}	
	cout << ans;
}                                

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <string>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    rep(i, n) a[i] = 0;
    rep(i, q) {
        int b;
        cin >> b;
        a[b-1]++;
    }
    rep(i, n){
        if(a[i]>q-k) cout << "Yes" <<endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3780
use proconio::input;

// use std::cmp::*;
// use std::collections::*;
// use proconio::marker::Chars;

fn main() {
    input! {
        // s: String
        // n: isize
        a:char,
        b:char
    }
    let ans: char;

    if a == 'H' {
        ans = b;
    } else {
        ans = if b == 'H' { 'D' } else { 'H' }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds_;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds;


int binomialCoeff(int n,int r){
    int res=1;
    if(r>n-r)r=n-r;
    for(int i=0;i<r;i++){
        res*=(n-i);
        res/=(i+1);
    }
    return res;
}



int power(int x,int n,int mod){
//(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){

return power(x,mod-2,mod);
}



int32_t main() {

    simplify
    int n;
    cin>>n;
    vector<int>arr(n);

    int xori=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        xori^=arr[i];
    }
    for(int i=0;i<n;i++){
        cout<<(xori^arr[i])<<" ";
    }



    return 0;
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int N,M;

int dfs(const Graph &G,int v,vector<bool> visited){

    bool all_visited = true;
    for(auto x: visited){
        if(!x) all_visited = false;
    }
    if(all_visited){
        return 1;
    }
    int ret = 0;
    for(auto nt :G.at(v)){
        if(visited.at(nt)) continue;
        visited.at(nt) = true;
        ret += dfs(G,nt,visited);
        visited.at(nt) = false;
    }
    return ret;
}
int main(){

    cin >> N >> M;
    Graph G(N);
    vector<bool> visited(N);
    for(int i = 0;i < M;i++){
        int a,b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    for(int i = 0; i < N ;i++){
        visited.at(i) = false;
    }

    visited.at(0) = true;
    cout << dfs(G,0,visited) << endl;
}


Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let tbl = Hashtbl.create ~random:true n in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if Hashtbl.mem tbl s then "yes" else "no")
    | [_; s] -> Hashtbl.add tbl s ()
    | _ -> assert false
  done

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
    int water = 100, sugar = 0;
    for(int i = 0; i < 30; i++){
        for(int j = 0; j < 30; j++){
            int now_water = 100*A*i + 100*B*j;
            if(now_water == 0) continue;
            int lim = E*(A*i+B*j); //溶ける砂糖の最大
            for(int k = 0; k*C <= lim; k++){
                //n*D <= (lim-k*C) && now_water+k*C+n*D <= F
                if(now_water + k*C > F) continue;
                int op_d = min((lim-k*C)/D, (F-now_water-k*C)/D);
                int now_sugar = k*C + op_d*D;
                if(now_sugar + now_water > F) continue;
                //now_sugar/(now_sugar + now_water) >= sugar/(sugar+water)
                if(now_sugar*(sugar+water) >= sugar*(now_sugar+now_water)){
                    water = now_water;
                    sugar = now_sugar;
                }
            }
        }
    }
    cout << water+sugar << " " << sugar << endl;
    return 0;
}

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

int main() {
  long long n,d;  cin>> n >> d;
  int count=0;
  for(int i=0;i<n;i++){
    long long x,y; cin >> x >> y;
    if(abs(x*x+y*y)<=d*d) {
      count++;
    }
  }
  cout<<count<<endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6 +1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ll binpow(ll a, ll b) {
	ll x = 1;
	while (b) {
		if (b & 1) x = x * a;
		a = a * a;
		b >>= 1;
	}
	return x;
}

ll mult(ll a, ll b) {
	ll x = 0;
	while (b) {
		if (b & 1) x = (x + a);
		a = (a + a);
		b >>= 1;
	}
	return x;
}

ll gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here

	int t = 1;
	//cin >> t;
	while (t--) {
		ll a, b, x, y;
		cin >> a >> b;
		ll g = gcd(4, 2, x, y);
		if (b % g != 0) {
			cout << "No\n";
			return 0;
		} else {
			x = x * b / g;
			y = y * b / g;
			while (y >= 0) {
				if (x + y == a) {
					cout << "Yes\n";
					return 0;
				}
				x = x + 1;
				y = y - 2;
			}
		}
		cout << "No\n";
	}


	return 0;
}

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

using namespace std;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0.0, double y = 0.0) : x(x), y(y) {
    }

    Point operator+(Point p) {
        return Point(x + p.x, y + p.y);
    }

    Point operator-(Point p) {
        return Point(x - p.x, y - p.y);
    }

    Point operator*(double k) {
        return Point(x * k, y * k);
    }

    Point operator/(double k) {
        return Point(x / k, y / k);
    }

    double norm() {
        return x * x + y * y;
    }

    double abs() {
        return sqrt(norm());
    }

    bool operator<(const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator==(const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

double norm(Vector a) {
    return a.x * a.x + a.y * a.y;
}

double absv(Vector a) {
    return sqrt(norm(a));
}

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}

struct Segment {
    Point p1, p2;
};

typedef Segment Line;

class Circle {
public:
    Point c;
    double r;

    Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {
    }
};

typedef vector<Point> Polygon;

bool isOrthgonal(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

bool isOrthgonal(Point a1, Point a2, Point b1, Point b2) {
    return isOrthgonal(a1 - a2, b1 - b2);
}

bool isOrthgonal(Segment s1, Segment s2) {
    return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
    return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
    return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / norm(base);
    return s.p1 + base * r;
}

Point reflect(Segment s, Point p) {
    return p + (project(s, p) - p) * 2.0;
}

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

    Point p[2];
    cin >> p[0].x >> p[0].y >> p[1].x >> p[1].y;
    Line l;
    l.p1 = p[0], l.p2 = p[1];

    int q;
    cin >> q;
    while (q--) {
        Point pp;
        cin >> pp.x >> pp.y;
        Point proj = project(l, pp);
        cout << fixed << setprecision(10) << proj.x << " " << proj.y << endl;
    }

    return 0;
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  int ans=0;
  
  
  if(N<105){
    ans=0;
  }
  else if(N<135){
    ans=1;
  }
  else if(N<165){
    ans=2;
  }
  else if(N<189){
    ans=3;
  }
  else if(N<195){
    ans=4;
  }
  else{
    ans=5;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define ll  long long 

int main(){
    ll n, a, ans = 0, min = pow(10, 15);
    cin >> n;
    for(int i = 0; i < 5; i++){
        cin >> a;
        if(min > a) min = a;
    }
    ans = (long long) (n-1)/(long long)min + 5;
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
X, Y = map(int, input().split())

prize = 0

if X == 1:
    prize += 300000
elif X == 2:
    prize += 200000
elif X == 3:
    prize += 100000
if Y == 1:
    prize += 300000
elif Y == 2:
    prize += 200000
elif Y == 3:
    prize += 100000

if X == 1 and Y == 1:
    prize += 400000
print(prize)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>

int main() {
  char buf[8];
  scanf("%s", buf);
  std::string s = buf;
  if (s[2] == s[3] && s[4] == s[5]) return puts("Yes"), 0;
  puts("No");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] L = new int[N];
		
		for(int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		
		int[] D = new int[N + 1];
		int count = 0;
		
		for(int i = 0; i < N + 1; i++) {
			if(i == 0) {
				D[i] = 0;
			} else {
				D[i] = D[i - 1] + L[i - 1];
			}
			if(D[i] <= X) {
				count++;
			}
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 21840
N = int(input())
s = [int(input()) for i in range(N)]
s.sort()
ans = sum(s)

if ans % 10 == 0:
    for i in range(N):
        if s[i] % 10 != 0:
            ans -= s[i]
            break
    if ans % 10 == 0:
        ans = 0
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    bool restore = false;
    for (int i = s.size() - t.size(); i >= 0; i--)
    {
        bool replace = true;
        for (int j = 0; j < t.size(); j++)
        {
            if (s[i + j] != '?' && s[i + j] != t[j])
            {
                replace = false;
                break;
            }
        }
        if (replace == true)
        {
            restore = true;
            for (int j = 0; j < t.size(); j++)
                s[i + j] = t[j];
            break;
        }
    }
    if (restore == true)
    {
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] == '?') cout << 'a';
            else cout << s[i];
        }
    }
    else cout << "UNRESTORABLE";
}


Measured memory_bytes: 3588
# 2019-11-17 10:52:21(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, q = [int(x) for x in sys.stdin.readline().split()]
    AB = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        AB[a].append(b)
        AB[b].append(a)
    # 無向グラフとして考える

    ans = [0 for _ in range(n+1)]
    for _ in range(q):
        p, x = [int(x) for x in sys.stdin.readline().split()]
        ans[p] += x
    
    stack = [1]
    parent = [0 for _ in range(n+1)]
    while stack:
        x = stack.pop()
        for y in AB[x]:
            if y != parent[x]: # yがxの親でなければ
                parent[y] = x # xがyの親
                stack.append(y)
                ans[y] += ans[x]
 
    
    print(' '.join(map(str, ans[1:])))

if __name__ == "__main__":
    main()



Measured memory_bytes: 66864
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		int [] x = new int[n];
		
		for(int i = 0; i < n; i++) {
			x[i] = stdIn.nextInt();
		}
		
	
		
		long minmin = Long.MAX_VALUE;
		
		for(int i = 0; i < n-k+1; i++) {
			int min = Math.min(Math.abs(x[i]), Math.abs(x[i+k-1]));
			int max = Math.max(Math.abs(x[i]), Math.abs(x[i+k-1]));
			
			if(x[i+k-1] < 0) {
				minmin = Math.min(Math.abs(x[i]),minmin);
			}else if(0 < x[i]) {
				minmin = Math.min(x[i+k-1], minmin);
			}else {
				minmin = Math.min(minmin,2 * min + max);								
			}
			
		}
		
		System.out.println(minmin);
		
	}

}


Measured memory_bytes: 49836
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
     String []wd=sc.nextLine().split(" ");
 int m2=0,m1=0,a2=0,a1=0; 
     for(int i=0;i<wd.length;i++){
    	 int temp=0;
    	 for(int k=i+1;k<wd.length;k++){
    		 if(wd[i].equals(wd[k]))temp++;
    	 }
    	 if(m1<temp){
    		 m1=temp; a1=i; 
    	 }
    	 if(m2<wd[i].length()){
		 m2=wd[i].length(); a2=i;
	 }
     }
     System.out.println(wd[a1]+" "+wd[a2]);
    }
}

Measured memory_bytes: 17132
import sys
import os
import math
import numpy as np
# f = open("input.txt", 'r')
# sys.stdin = f

li = []
li4 = []
for i in range(5):
    li.append(int(input()))

for i in li:
    if i%10 != 0:
        li4.append(10-i%10)
    else:
        li4.append(0)
# print(li4)
np.array(li4)
# print(np.argmax(li4))
atodetasu = li[np.argmax(li4)]
li.pop(np.argmax(li4))
lli = []
for i in li:
    if i % 10 != 0:
        i = i + (10- i % 10)
    lli.append(i)
# print(lli)
print(sum(lli) + atodetasu)


Measured memory_bytes: 20404
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    
    int n;
    cin >> n;
    
    ll ans=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
        {
            for (int k=1;k<=n;k++)
            {
                ans=ans+__gcd(__gcd(i,j),k);
            }
        }
    }

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


Measured memory_bytes: 3640
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	ll tmp = min(x, y);
	ll ans = min(a + b, 2 * c) * tmp;
	tmp = max(x, y) - min(x, y);
	if (x > y) ans += min(a, 2 * c) * tmp;
	else ans += min(b, 2 * c) * tmp;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int m = Integer.parseInt(sc.next());
	if(n>=13)	System.out.println(m);
	else if(n>=6) System.out.println(m/2);
	else System.out.println(0);

    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int k;
string s, ans;

typedef string::const_iterator State;

int number(State& p){
	int res = 0;
	while(isdigit(*p)){
		res *= 10;
		res += *p - '0';
		p++;
	}
	return res;
}

string expr(State& p){
	string res;
	while(true){
		if(p == s.end()) break;
		if(res.size() > k) break;

		if(isdigit(*p)){
			int loop = number(p);

			string tmp;
			if(*p == '('){
				p++;
				tmp = expr(p);
				p++;
			}else{
				tmp += *p;
				p++;
			}
			rep(i,loop){
				if(res.size() > k) break;
				res += tmp;
			}
		}else if(isupper(*p)){
			res += *p;
			p++;
		}else{
			break;
		}
	}
	return res;
}

int main(){
	while(cin >> s >> k, s != "0"){
		State tmp = s.begin();
		string t = expr(tmp);
		if(t.size() - 1 < k) cout << 0 << endl;
		else cout << t[k] << endl;
	}
}



Measured memory_bytes: 8540
A = []
B = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())

test = [[0]*3 for _ in range(3)]

for i in range(N):
    B.append(int(input()))

for b in B:
    for m in range(3):
        for n in range(3):
            if b == A[m][n]:
                test[m][n] =1

ans = 'No'

for i in range(3):
    if sum(test[i]) == 3:
        ans = 'Yes'
    if test[0][i]+test[1][i]+test[2][i] == 3:
        ans = 'Yes'

if test[0][0]+test[1][1]+test[2][2] == 3:
    ans = 'Yes'

if test[2][0]+test[1][1]+test[0][2] == 3:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 62120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt(), h = sc.nextInt(), c = sc.nextInt();
        System.out.println(w * h / gcd(w, h) * c);
    }
    static int gcd(int a, int b) {
        return a % b == 0 ? b * b : gcd(b, a % b);
    }
}


Measured memory_bytes: 26376
#include <bits/stdc++.h>
 
typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout<<i<<endl;
#define AS(i) cout<<i<<" ";
 
const int INF = 1001001001;
 
using namespace std;
 
int main() {

    int n, r;
    cin >> n >> r;

    int ans = r;

    if (n < 10) {
        ans = r + 100 * ( 10 - n);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    if(n<1200)
    {
        cout<<"ABC"<<endl;
    }
    else if(n>=1200&&n<2800)
    {
        cout<<"ARC"<<endl;
    }
    else
    {
        cout<<"AGC"<<endl;
    }

    return 0;
}


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

int main()
{
  int a,b ;
  cin>>a>>b ;
  string S=to_string(a)+to_string(b) ;
  int N=stoi(S) ;
  
  for(int i=1;i*i<=N;i++){
    if(i*i==N){
      cout<<"Yes"<<endl ;
      return 0 ;
    }
  }
  cout<<"No"<<endl ;
  return 0 ;
}

Measured memory_bytes: 256
A = input()
B = input()
C = input()
D = input()
E = input()
K = input()

if B-A<=K and C-A<=K and D-A<=K and E-A<=K and C-B<=K and D-B<=K and E-B<=K and D-C<=K and E-C<=K and E-D<=K:
  print "Yay!"
else:
  print ":("

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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

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

    vector<ll> over_lines;

    {
        vector<ll> ts(n);
        vector<ll> vs(n);
        rep(i, n) {
            cin >> ts[i];
        }
        rep(i, n) {
            cin >> vs[i];
        }

        ll ts_sum = 0;
        for (ll i : ts) {
            ts_sum += i;
        }
        over_lines.resize(ts_sum + 2, 0);

        ll index = 1;
        for (ll i = 0; i < n; i++) {
            for (ll j = 0; j < ts[i]; j++) {
                over_lines[index] = vs[i];
                index++;
            }
        }

    }
    for (ll i = 1; i < over_lines.size(); i++) {
        over_lines[i] = min(over_lines[i], over_lines[i - 1] + 1);
    }

    for (ll i = over_lines.size() - 2; i >= 0; i--) {
        over_lines[i] = min(over_lines[i], over_lines[i + 1] + 1);
    }

    ll ans = 0;

    for (ll i = 1; i < over_lines.size() - 1; i++) {
        ll a = over_lines[i - 1];
        ll b = over_lines[i];
        ll c = over_lines[i + 1];
        assert(b > 0);
        assert(abs(a - b) <= 1);
        assert(abs(b - c) <= 1);
        if (a == b && b == c) {
            ans += b * 100ll;
        } else if (a > b && b < c) {
            ans += b * 100ll;
        } else if ((a > b && b == c) || (a == b && b < c)) {
            ans += b * 100ll;
        } else if ((a == b && b > c) || (a < b && b == c)) {
            ans += ((b - 1) * 100ll) + 50;
        } else if (a < b && b > c) {
            ans += ((b - 1) * 100ll) + 25;
        } else if ((a < b && b < c) || (a > b && b > c)) {
            ans += ((b - 1) * 100ll) + 50;
        } else {
            assert(false);
        }
    }

    cout << setprecision(10) << ((long double) ans) / 100 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define inf    0x3f3f3f3f
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef vector<int>      vi;
typedef vector<bool>     vb;
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  ll x,k,d;
  cin>>x>>k>>d;

  x = abs(x);

  if(x > 0 && x/d >= k){
      x = x - k*d;
      cout<<abs(x)<<endl;
      return 0;
  }

  ll y = x/d;
  x -= y*d;
   k -= y;

   if(k%2 == 0)
      cout<<abs(x)<<endl;
   else if(k%2== 1){
      ll ans = min(abs(x+d),abs(x-d) );
      cout<<ans<<endl;
   }

return 0;
 }



Measured memory_bytes: 3596