akhauriyash/Code-Regression huggingface dataset:
# Union-Find木（サイズ付き）
class UnionFind():
    def __init__(self, n):  # n要素で初期化　初めは全ての頂点が別々の木の根
        self.parent = [None] * n # 親
        self.rank = [None] * n   # 木の深さ
        self._size = [1] * n # 要素が属する集合の大きさ（根の要素のみ参照すること）
        for i in range(n):
            self.parent[i] = i
            self.rank[i] = 0

    # 木の根を求める
    def root_of(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root_of(self.parent[x])  # 経路圧縮して親が変わる
            return self.parent[x]

    # xとyの属する集合を併合
    def unite(self, x, y):
        rx = self.root_of(x)
        ry = self.root_of(y)
        if rx == ry:
            return
        if self.rank[rx] < self.rank[ry]: # ランクの小さい木から大きい木の根に辺を張る
            self.parent[rx] = ry  # rxをryの子とする
            self._size[ry] += self._size[rx]
        elif self.rank[rx] == self.rank[ry]:
            self.parent[ry] = rx
            self.rank[rx] += 1
            self._size[rx] += self._size[ry]
        else:
            self.parent[ry] = rx
            self._size[rx] += self._size[ry]

    # 同じ集合に属するかどうか
    def is_same(self, x, y):
        return self.root_of(x) == self.root_of(y)

    # 頂点xが属する集合のサイズ
    def size(self, x):
        return self._size[self.root_of(x)]

# 入力
N, M = [int(x) for x in input().split()]
A = [None] * M
B = [None] * M
for i in range(M):
    A[i], B[i] = [int(x) - 1 for x in input().split()]


# 島同士が全く繋がっていない状態からスタート
# M-1番目, M-2番目, ..., , 2番目, 1番目の橋の順に橋をかけていく
inconv = [-1] * (M - 1) + [N * (N - 1) // 2]    # 不便さ

uf = UnionFind(N)

for i in range(M - 1, 0, -1):
    # i番目の橋をかける
    if not uf.is_same(A[i], B[i]):
        size_a = uf.size(A[i]) # A[i]が属する集合の大きさ
        size_b = uf.size(B[i]) # B[i]が属する集合の大きさ
        inconv[i - 1] = inconv[i] - size_a * size_b
        uf.unite(A[i], B[i])
    else:
        inconv[i - 1] = inconv[i]

for i in range(M):
    print(inconv[i])


Measured memory_bytes: 109912
#include <bits/stdc++.h>
#define ll long long
#define gc getchar
#define pb push_back

using namespace std;

inline void getnum(long long &x) {
    x = 0;
    long long mnoz = 1;
    char c = gc();
    if(c == '-')
    {
        mnoz = -1;
        c = gc();
    }
    for(;c<48||c>57;c=gc());
    for(;c>47&&c<58;c=gc())
        x = ((x<<3) + (x<<1) + c-48);
    x *= mnoz;
}
inline void getnumbers(int* b, ll z)
{
    for(int i = 0; i < z; i++) cin >> b[i];
}
inline void printn(int* b, ll z)
{
    for(int i = 0; i < z; i++) cout << b[i] << " ";
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    ll x; cin >> x;
    ll n = (x/500); n *= 1000;
    x =  ((x - n/2)/5);
    n += x*5;
    cout << n;

}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) cin >> p[i];

  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
    if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
    else if ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[2000][2000],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m>>c;
    rep(i,m)cin>>b[i];
    rep(i,n){
        rep(j,m)cin>>a[i][j];
    }
    rep(i,n){
        cnt=0;
        rep(j,m){
            cnt+=a[i][j]*b[j];
        }
        cnt+=c;
        if(cnt>0)ans++;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int n;
int dp[101][4][4][4];
// 0 A 1 C 2 G 3 T
int go(int i,int pre1,int pre2,int pre3)
{
   if(i>=n){
            if(pre2==0 && pre1==2 && pre3==1)
               return 0;
            else if(pre1==0 && pre2==2 && pre3==1)
               return 0;
            else if(pre1==0 && pre2==1 && pre3==2)
                return 0; 
              return 1;
   }
   if(dp[i][pre1][pre2][pre3]!=-1)
    return dp[i][pre1][pre2][pre3];
   else
     {  int ans=0;
        for(int j=0;j<4;j++) 
        {   if(pre2==0 && pre1==2 && pre3==1)
               continue;
            if(pre1==0 && pre2==2 && pre3==1)
               continue;
            if(pre1==0 && pre2==1 && pre3==2)
                continue;
            if(pre1==0 && pre2==2 && j==1)
                continue;
            if(pre1==0 && pre3==2 && j==1)
               continue;      
            ans=(ans+go(i+1,pre2,pre3,j))%1000000007;
        }
        dp[i][pre1][pre2][pre3]=ans;
       return ans; 
     }  
}

int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){  
    cin>>n;
    int ans=0;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<4;i++)
       {
         for(int j=0;j<4;j++)
           {for(int k=0;k<4;k++)
                    ans=(ans+go(3,i,j,k))%1000000007;}
       }
     //cout<<dp[4]  
    cout<<ans<<" ";
  }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<Pll>v;
map<Pll, Pll>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000];
string str, ss;
bool f[200][200];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
int main() {
	cin >> n;
	cin >> str;
	if (n >= 3200)cout << str << endl;
	else cout << "red" << endl;
	return 0;
}


Measured memory_bytes: 256
s = input()
p = 2019
n = len(s)
ans = 0

d = [0 for _ in range(n + 1)]
ten = 1

for i in range(n - 1, -1, -1):
    a = int(s[i]) * ten % p
    d[i] = (d[i + 1] + a) % p
    ten *= 10
    ten %= p

cnt = [0 for _ in range(p)]
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1


print(ans)


Measured memory_bytes: 16536
#include<stdio.h>
void bubble(int *ar, int len) {
	int i, j,temp,cou=0;
	for (i = len - 1; i > 0; i--)
	{
		for (j = 0; j < i;j++)
		{
			if (*(ar + j + 1) < *(ar + j))
			{
				temp = *(ar + j + 1);
				*(ar + j + 1) = *(ar + j);
				*(ar + j) = temp;
				cou++;
			}
		}
	}
	for (i = 0; i < len-1; i++)
	{
		printf("%d ", *(ar + i));
	}
	printf("%d\n%d\n", *(ar + i),cou);

}

int main() {
	int N;
	int ar[100];
	int i;
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &ar[i]);
	}
	bubble(ar, N);
	return 0;
}

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

int main() {
    vector<multiset<int>> v;
    for (int i = 0; i < 3000; ++i) {
        int x, y;
        cin >> x >> y;
        if (x <= 0 && y <= 0) break;
        multiset<int> s{x, y};
        v.push_back(s);
    }
    
    for (int i = 0; i < (int)v.size(); ++i) {
        auto iter = v[i].begin();
        cout << *iter << " ";
        ++iter;
        cout << *iter << endl;
    }
    
    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b){
    cout << "a == b\n";
  }else if(a<b){
    cout << "a < b\n";
  }else{
    cout << "a > b\n";
  }
  return 0;
}



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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  int n1 = N / 1000 % 10;
  int n2 = N / 100 % 10;
  int n3 = N / 10 % 10;
  int n4 = N /1 % 10;
  
  if((n1 == n2 && n2 == n3) || (n2 == n3) && (n3 == n4))
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 998244353;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n;
  cin >> n;
  vector<vector<int>> x(n),y(n);
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    x.at(i) = vector<int>(a);
    y.at(i) = vector<int>(a);
    for(int j=0;j<a;j++){
      cin >> x.at(i).at(j) >> y.at(i).at(j);
      x.at(i).at(j)--;
    }
  }
  int ans = 0;
  for(int i=0;i<(1<<15);i++){
    bool flag1 = false;
    bitset<15> bit(i);
    int tmp = 0;
    for(int j=0;j<n;j++){
      bool flag2 = false;
      if(bit.test(j)){
        for(int k=0;k<x.at(j).size();k++){
          if(bit.test(x.at(j).at(k)) != y.at(j).at(k)){
            flag1 = true;
            flag2 = true;
            break;
          }
        }
        if(flag2)break;
        tmp++;
      }
    }
    if(!flag1)ans = max(ans,tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
def u(o,p):
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    return c[1]
    
if 4 >= len(x_list) >= 3:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  print(u(a[1],a[0]))

elif len(x_list) > 4:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  u = u(a[1],a[0])
  for i in a:
    if i/u == int(i/u):
      pass
    else:
      u = i%u
  print(u)
else:
  print(x_list[1]-x_list[0])

Measured memory_bytes: 14480
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<bitset<10>> f(n);
    rep(i,n){
        rep(j,10){
            int x;cin>>x;
            f[i].set(j,x);
        }
    }
    vector<vector<ll>> p(n,vector<ll>(11));
    rep(i,n)rep(j,11)cin>>p[i][j];
    ll res=-1e+18;
    for(int tmp=1;tmp<(1<<10);tmp++){
        bitset<10> s(tmp);
        ll now=0;
        rep(i,n){
            int k=0;
            rep(j,10)k+=s[j]&f[i][j];
            now+=p[i][k];
        }
        chmax(res,now);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m,x;
    cin >> n >> m >> x;
    vi c(n);
    vvi a(n,vi(m));
    rep(i,n) {
        cin >> c[i];
        cin >> a[i];
    }
    int ans = inf;
    rep(bit,1<<n) {
        vi un(m,0);
        int cnt = 0;
        rep(i,n) {
            if(!(bit>>i&1)) continue;
            rep(j,m) un[j] += a[i][j];
            cnt += c[i];
        }
        bool ok = true;
        rep(i,m) if(un[i] < x) ok = false;
        if(ok) chmin(ans,cnt);
    }
    cout << (ans == inf ? -1 : ans) << endl;
}


Measured memory_bytes: 3664
Q, H, S, D = list(map(int, input().split()))
N = int(input())

if 2*Q < H:
    H = 2*Q

if 2*H < S:
    S = 2*H

if 2*S < D:
    D = 2*S


print(N//2*D + N%2*S)


Measured memory_bytes: 2940
using System;

class main
{
    public static int n = 1000001;
    static void Main()
    {
        string s;
        int[] p = new int[n];
        for (int i = 2; i < 1001; ++i)
            for (int j = i * 2; j < n; j += i)
                p[j] = 1;
        while ((s = Console.ReadLine()) != null)
        {
            int q = 0;
            for (int i = 2; i <= int.Parse(s); ++i)
                if (p[i] != 1) ++q;
            Console.WriteLine("{0}", q);
        }
    }
}

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

int main(){

  string a, b, c;
  int ca=0, cb=0, cc=0;
  char x='a';

  cin>>a>>b>>c;

  while(1){
    if(x=='a'){
      if(ca==a.size()){
        cout<<'A'<<endl;
        break;
      }
      x=a[ca++];
    }
    if(x=='b'){
      if(cb==b.size()){
        cout<<'B'<<endl;
        break;
      }
      x=b[cb++];
    }
    if(x=='c'){
      if(cc==c.size()){
        cout<<'C'<<endl;
        break;
      }
      x=c[cc++];
    }
  }

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = [int(input()) for i in range(N)]

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(max(B))
    else:
        print(mx)

Measured memory_bytes: 24180
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        int Y = cin.nextint;

        for (int i = 0; i <= N; i++)
        {
            for (int j = 0; j <= N; j++)
            {
                int sum = i * 10000 + j * 5000;
                if (sum > Y) continue;
                int k = (Y - sum) / 1000;
                if(i + j + k == N)
                {
                    WriteLine($"{i} {j} {k}");
                    return;
                }
            }
        }
        WriteLine("-1 -1 -1");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
# coding: utf-8
import heapq
n,k = [int(x) for x in input().split()]
h = sorted([int(x) for x in input().split()])
#print(h)
s = 0
if k >= n:
    print(0)
else:
    h = h[:n-k]
    for j in h:
        s += j
    print(s)

Measured memory_bytes: 25896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define F first
#define S second
typedef vector<pli> vpli;
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end() 
#define tests int t; cin>>t; while(t--)
#define take(a,b,c) for(b=0;b<c;b++) cin>>a[b];
#define INF 1e18
// https://codeforces.com/problemset/page/3?tags=1500-1800
map <int,stack<int> > m;
int main()
{	
  int k;
  int a,b;
  cin>>k;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0) {
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
}


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

#define fi first
#define se second
#define sz(v) (int)((v).size())
#define pb push_back

#define int long long

signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vector<int> d(n), f(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i] >> f[i];
		f[i] *= -1;
	}
	sort(d.begin(), d.end());
	sort(f.begin(), f.end());
	if (n%2==1)
		cout << -f[n/2]-d[n/2]+1 << "\n";
	else{
		int dl=d[n/2-1], dr=-f[n/2];
		int fr=-f[n/2-1], fl=d[n/2];
		cout << dr+fr - (fl+dl) + 1 << "\n";
	}
}


Measured memory_bytes: 6344
N,X = map(int,input().split())


eat = 0

def eat(n,x):
    if x == 0:
        return 0
    elif n== 0:
        return 1
    elif 2**(n+2)-3 <= x:
        return 2**(n+1)-1
    elif 2**(n+2)-3 > x and 2**(n+1)-1 <=x :
        return 2**n-1 + 1 + eat(n-1,x-(2**(n+1)-1))
    else:
        return eat(n-1,x-1)

print(eat(N,X))   


Measured memory_bytes: 3060
x, n = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
np = (-101..101).to_a - p
min = 101
ans = 0
np.each do |i|
  d = (x - i).abs
  if d < min
    min = d
    ans = i
  end
end
puts ans


Measured memory_bytes: 14380
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define pb push_back
#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=1000000;
void fns(){
	int k=100;
	int cnt=0;
	int ans=0;
	for(ll i=1;i*i<=k;i++){
			if(k%i==0){
				if(i!=k/i){
					cnt+=2;
				}
				else
					++cnt;
			}
		}
		ans+=(cnt);
}
void solve()
{
	ll n;cin>>n;
	ll k=n;
	ll ans=0;
	for(int i=1;i<n;i++){
		k=n-i;
		ll cnt=0;
		ll temp=1;
		for(ll j=2;j*j<=k;++j){
			cnt=0;
			if(k%j==0){
				while(k%j==0)k/=j,++cnt;
			}
		//	cout<<i<<" "<<j<<" "<<cnt<<"\n"
			temp*=(cnt+1);
		}
		if(k>1)temp*=2;
		ans+=temp;
	}
	cout<<ans<<'\n';
}
int main()
{	Fast;
//	int t;cin>>t;
//	while(t--)
	solve();
}

Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<math.h>
int main()
{
    int a,j;
    while(scanf("%d",&a)==1)
    {
        j=sqrt(2*a);
        if(j*(j+1)/2>=a)
            printf("%d\n",j);
        else if((j+1)*(j+2)/2>=a)
            printf("%d\n",j+1);
    }
    return 0;
}


Measured memory_bytes: 256
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
accum = [[0, 0] for _ in range(N + 1)]
for i in range(N):
    accum[i+1][0] += accum[i][0] + A[i]
    accum[i+1][1] += accum[i][1] + max(A[i], 0)
ans = 0
for i in range(N-(K-1)):
    cand = accum[i+K][0] - accum[i][0] + accum[i][1] - accum[0][1] + accum[N][1] - accum[i+K][1]
    ans = max(ans, cand, accum[i][1] - accum[0][1] + accum[N][1] - accum[i+K][1])
print(ans)


Measured memory_bytes: 34444
from collections import Counter

def print_0():
  print(0)
  exit()

MOD = 998244353
N = int(input())
inputD = list(map(int,input().split()))
D = Counter(inputD)
if inputD[0] != 0 or D[0]!=1: print_0()

max_rank = max(D.keys())
ans = 1
for i in range(max_rank+1):
  if i not in D:
    print_0()
  elif i not in [0,1]:
    ans *= D[i-1]**D[i]
print(ans%MOD)

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

int main(void) {
	int n, m, x;
	cin >> n >> m >> x;
	int a[m];
	int l = 0, r = 0;
	for ( int i = 0; i < m; i++ ) {
		cin >> a[i];
		if ( a[i] < x ) l++;
		else r++;
	}
	cout << min(l, r);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
#define mk make_pair
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int N, M;
priority_queue<pair<ll,int>> q;

int main(){
	cin >> N >> M;
	ll A;
	rep(i,N){
		cin >> A;
		q.push(mk(A,1));
	}
	int B; ll C;
	rep(i,M){
		cin >> B >> C;
		q.push(mk(C,B));
	}

	ll ans = 0;
	rep(i,N){
		auto p = q.top();
		q.pop();
		//cout << "p: " << p.first << endl;
		ans += p.first;
		if(p.second > 1){
			p.second--;
			q.push(p);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6128
N = int(input())
s = []
t = []
sum = 0
for i in range(N):
    s.append(input())
M = int(input())
for i in range(M):
    t.append(input())

for i in range(M):
    if t[i] in s:
        s.remove(t[i])

for i in range(len(s)):
    if sum < s.count(s[i]):
        sum = s.count(s[i])
print(sum)


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

int main(){
	int n, k, i, ans=0;
	cin>>n>>k;
	int l[n];
	for(i=0; i<n; i++) cin>>l[i];
	sort(l, l+n, greater<int>());
	for(i=0; i<k; i++) ans+=l[i];
	cout<<ans<<endl;
	return 0;
}

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


int Test;


void input(){

cin>>Test;

}

void solve(){

input();

    string N,T;
    
    cin>>N>>T;
    
    for(int i=0;i<Test;i++){
            
    cout<<N[i]<<T[i];
    
    }
}


int main()
{

    solve();


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool even(string s)
{
	int x=s.size();
	if(x%2)
		return false;
	string t=s.substr(0,x/2),u=s.substr(x/2);
	if(t==u)
		return true;
	return false;
}
int main(void)
{
	string s;
	cin>>s;
	int n=s.size(),ans;
	for(int i=2;i<n;i+=2)
		if(even(s.substr(0,i)))
			ans=i;
	cout<<ans;
}


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

count, state = 0, 0
for n in range(1, N):
	d = A[n] - A[n - 1]
	#print(d, state)
	if d == 0:
		continue
	if d < 0 and state <= 0:
		state = -1
		continue
	if 0 < d and 0 <= state:
		state = 1
		continue
	count += 1
	state = 0
print(count + 1)


Measured memory_bytes: 14252
#include<stdio.h>

int main(void){
	double x=0,y=0;
	double a=0,b=0,c=0,d=0,e=0,f=0,i=0,j;
    
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF)
	{
		y = ( c * d - a * f ) / ( b * d - e * a );

        x = ( c - ( b * y ) ) / a;

		printf("%.3lf %.3lf\n",x,y);
	}
  return 0;
}

Measured memory_bytes: 1076
n=int(input())
p=[list(map(int,input().split()))for _ in range(n)] #[ax,ay,ah]をひとつの要素とする二重リスト
ax,ay,ah=list(filter(lambda x:x[2],p))[0] #x[2]がTrue、つまりahが0以外のリストの先頭の要素を取得
for x in range(101):
    for y in range(101):
        H=ah+abs(ax-x)+abs(ay-y) #Hの予測値
        if all([max(H-abs(t[0]-x)-abs(t[1]-y),0)==t[2]for t in p]): #ahのリストを生成し、予測したHから正しいかどうか判定
            print(x,y,H)

Measured memory_bytes: 49244
#include <bits/stdc++.h>
using namespace std;
long long a,b;
long long gcd(long long x,long long y)
{
	if(y==0)
	return x;
	return gcd(y,x%y);
}
int main()
{
	cin>>a>>b;
	cout<<a*b/gcd(a,b);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223000000000000000
#define INF 2147000000
#define MOD 1000000007
using namespace std;

long   valid[10][100005];
string dp[10][10005];

int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld%ld", &n, &m);

    long num[9]={2,5,5,4,5,6,3,7,6};

    vector<pair<long, long> > zz(m);
    long i,j;
    for(i=0; i<m; i++) {
        long a;
        scanf("%ld", &a);
        zz[i]=make_pair(a, num[a-1]);
    }
    sort(zz.rbegin(), zz.rend());

    for(i=0; i<m; i++) {
        valid[i][0]=1;
    }
    for(j=0; j<=n; j++) {
        for(i=0; i<m; i++) {
            if(i>0) {
                dp[i][j] = dp[i-1][j];
            }
            if(j-zz[i].second>=0 && (valid[i][j-zz[i].second] || !dp[i][j-zz[i].second].empty()) ) {
                char str[5]={0};
                sprintf(str, "%ld", zz[i].first);
                string tmpstr = dp[i][j-zz[i].second] + string(str);
                if(dp[i][j].size() < tmpstr.size() ) {
                    dp[i][j] = tmpstr;
                }
                else if(dp[i][j].size() == tmpstr.size() && tmpstr.compare(dp[i][j])>0 ) {
                    dp[i][j] = tmpstr;
                }
            }
        }
    }

    printf("%s\n", dp[m-1][n].c_str());

    return 0;
}


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

void solve(int s, const Graph &gph, const vector<int> &data, vector<int> *ans, vector<int> *dp){
  auto itr= lower_bound(dp->begin(), dp->end(), data.at(s));
  int idx= distance(dp->begin(), itr);
  int prev= dp->at(idx);
  dp->at(idx)= data.at(s);
  auto itr_ans= lower_bound(dp->begin(), dp->end(), INT_MAX);
  ans->at(s)= distance(dp->begin(), itr_ans);

  for(auto v:gph.at(s)){
    if(ans->at(v)==0){
      solve(v, gph, data, ans, dp);
    }
  }
  dp->at(idx)= prev;
}

int main(){
  int N;
  cin >> N;
  const int M= N-1;

  vector<int> data(N);
  Graph gph(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }
  int buf1,buf2;
  for(int j=0; j<M; j++){
    cin >> buf1 >> buf2;
    buf1--; buf2--; // 1-indexed -> 0-indexed

    gph.at(buf1).emplace_back(buf2);
    gph.at(buf2).emplace_back(buf1);
  }

  vector<int> ans(N);
  vector<int> dp(N, INT_MAX);
  solve(0, gph, data, &ans, &dp);

  for(auto elem:ans){
    cout << elem << endl;
  }
}

Measured memory_bytes: 30864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	/*
	 * n*m A // A[n][m]
	 *
	 * m*1 b // b[m*1]
	 *
	 * A+=b = sysout
	 *
	 * A[ni][mj]
	 *
	 * b[mi]
	 */

	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// ???????????????
		String[] line  = br.readLine().split(" ");
		int n=0,m=0;
		n = Integer.parseInt(line[0]); // 3
		m = Integer.parseInt(line[1]); // 4

		int[][] vector_A = new int[n][m]; // [3][4]

		int[] vector_B = new int[m]; // [4*1]


		// ?????±?????\??????


		for (int i = 0; i < n; i++) {

			// * 1 2 0 1 0 3 0 1 4 1 1 0

			String [] data = br.readLine().split(" ");// ??????????????????????????¶
			for	(int j= 0; j < m; j++){
				vector_A[i][j] = Integer.parseInt(data[j]);
			}
		}

		for (int i = 0; i < m; i++) {// 1230
			String data2 = br.readLine();
			vector_B[i] = Integer.parseInt(data2);
		}

		/*
		 * 1201 0301 4110
		 *
		 * 1230
		 *
		 * 1*1=1, 2*2=4, 0*3=0, 1*0=0 tot=5 ...
		 *
		 *
		 */

		for (int i = 0; i < n; i++) {
			int tot = 0;
			for (int j = 0; j < m; j++) {
				tot += vector_A[i][j] * vector_B[j];

			}
			System.out.println(tot);
		}

		// sc.close();

	}

}

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

int main(){
  int n,ans=100,a[110],sum=0;
  bool flag=false;
  cin>>n;
  for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; }
  if(sum%10!=0){ cout<<sum; return 0; }
  for(int i=0;i<n;i++){
    if(a[i]%10==0) continue;
    else {
      flag=true;
      ans=min(ans,a[i]);
    }
  }
  if(flag) cout<<sum-ans;
  else cout<<"0";

}


Measured memory_bytes: 256
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var n, m int
	fmt.Fscan(read, &n, &m)

	cnt := make([]int, n)
	for i := 0; i < n; i++ {
		cnt[i] = 0
	}

	ac, wa := 0, 0
	for i := 0; i < m; i++ {
		var p int
		var s string
		fmt.Fscan(read, &p, &s)
		p--
		if s == "AC" && cnt[p] != -1 {
			ac++
			wa += cnt[p]
			cnt[p] = -1
		}
		if s == "WA" && cnt[p] != -1 {
			cnt[p]++
		}
	}
	fmt.Fprintln(write, ac, wa)
}


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

int main() {
  int64_t a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if (k % 2 == 0) {
    cout << a - b << endl;
  }
  else {
    cout << b - a << endl;
  }
}


Measured memory_bytes: 256
// 2009à\IA ú¬·
#include <iostream>

using namespace std;

int main(){
	int n, p;
	while(cin >> n >> p, n){
		int num = p, pos = 0;
		int s[50] = {};
		while(true){
			pos %= n;
			if(num==0) swap(num, s[pos]);
			else       num--, s[pos]++;
			if(s[pos]==p){
				cout << pos << endl;
				break;
			}
			pos++;
		}
	}
}

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

int n;
string s;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> s;
    string str;
    for(int i = 0; i < n / 2; i++) str += s[i];
    if(str + str == s) cout << "Yes\n";
	else cout << "No\n";
    return 0;
}

Measured memory_bytes: 380
<?php
fscanf(STDIN,'%d%d%d',$a,$b,$c);
$K=fgets(STDIN);
$array=[$a,$b,$c];
rsort($array);
for ($i=1; $i <=$K ; $i++) {
  // code...
  $array[0] = $array[0]*2;
}
echo $array[0]+$array[1]+$array[2];



 ?>


Measured memory_bytes: 3576
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;
#define int long long

signed main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<int> > mp;
  vector<pair<int, int> > pa;
  for(int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    mp[p].push_back(y);
    pair<int, int> ip = make_pair(p, y);
    pa.push_back(ip);
  }
  
  for(int i = 1; i <= n; i++) {
    if(mp[i].size() > 0) sort(mp[i].begin(), mp[i].end());
  }
  
  for(int i = 0; i < m; i++) {
    auto p = pa[i];
	auto idx = lower_bound(mp[p.first].begin(), mp[p.first].end(), p.second);
	printf("%012lld\n", p.first * 1000000 + 1 + distance(mp[p.first].begin(), idx));
  }
  
  return 0;
}


Measured memory_bytes: 13936
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXN 51
long long n, x, i, j, k, ans;
vector<long long> sz(MAXN), p(MAXN);

long long solve(long long n, long long x) {
	if (x <= 0) return 0;
	if (n == 0) return 1;
	if (x >= sz[n]) return p[n];

	long long a = 0;
	if (x <= 1 + sz[n - 1]) a = solve(n - 1, x - 1);
	else {
		a = 1 + p[n - 1] + solve(n - 1, x - 2 - sz[n - 1]);
	}
	return a;	
}

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

	sz[0] = 1; p[0] = 1;
	for (i = 1; i < MAXN; i++) {
		sz[i] = 3 + sz[i - 1] * 2;
		p[i] = p[i - 1] * 2 + 1;
	}

	cin >> n >> x;
	ans = solve(n, x);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())

c =[]
s =[]
f =[]

for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        if t <= s[j]:
            w = s[j]-t
        else:
            w = (f[j] - (t-s[j])%f[j])%f[j]
        t+=w
        t+=c[j]
    print(t)

print(0)

Measured memory_bytes: 41708
n,m=map(int,input().split())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
r.sort(reverse=True)
c.sort(reverse=True)
dict1={}
dict2={}
for i in range(n):
    dict1.setdefault(r[i],0)
    dict1[r[i]]+=1
for i in range(m):
    dict2.setdefault(c[i],0)
    dict2[c[i]]+=1
x,y=0,0
ans=1
mod=10**9+7
for i in range(n*m,0,-1):
    dy=dict1.get(i,0)
    dx=dict2.get(i,0)
    if dx*dy==1:
        x+=1
        y+=1
    elif dx==0 and dy==1:
        ans*=x
        y+=1
    elif dy==0 and dx==1:
        ans*=y
        x+=1
    else:
        ans*=(x*y-(n*m-i))
        ans%=mod
print(ans%mod)

Measured memory_bytes: 3316
n = int(input())
arr = [int(input()) for _ in range(n)]

ans = 0
for i in range(n):
    ans += arr[i] // 2
    arr[i] %= 2
    if i != n - 1:
        if arr[i] == 1 and arr[i + 1] >= 1:
            arr[i] -= 1
            arr[i + 1] -= 1
            ans += 1

print(ans)

Measured memory_bytes: 13036
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

int main() {

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
        cout<<"Yes";
        return 0;

    } else
        cout<<"No";
    return 0;
}







Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101
#define INF 1000000000

int M[MAX][MAX];
int n;

void matrixChainOrder(int *p){
  int i,l,j,k,q=0;
 
  for(i=1;i<=n;i++) M[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j]=INF;
      for(k=i;k<=j-1;k++){
	q=M[i][k]+M[k+1][j]+p[i-1]*p[k]*p[j];
	if(M[i][j]>q) M[i][j]=q;
	else M[i][j]=M[i][j];
      }
    }
  }
}

int main(){
  int i,r,c;
  int p[MAX];

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    if(i==0) p[i]=r;
    p[i+1]=c;
  }

  matrixChainOrder(p);

  printf("%d\n",M[1][n]);

  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static vector<bool> s;
static vector<int> exp;
static long long int res = 0;

void sum(){
	int i = 0;
	long long int tmp = exp[i];
	i++;
	while(i != exp.size()){
		if(s[i-1] == false)
			tmp = tmp * 10 + exp[i];
		else{
			res += tmp;
			tmp = exp[i];
		}
		i++;
	}
	res += tmp;

	//cout << "log:" << res << endl;
}

void backtrack(int a, int b){
	if(a == b){
		//cout << "log: went sum()" << endl;
		sum();
		return;
	}

	s[a] = true;
	backtrack(a+1, b);
	s[a] = false;
	backtrack(a+1, b);
}

int main(){
	
	string sexp;
	cin >> sexp;

	for(int i = 0;i < sexp.length(); i++)
		exp.push_back(sexp[i]-'0');
	
	int space = exp.size() - 1;
	s.resize(space, false);

	backtrack(0,space);

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

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

    ll n = 0;
    while (H > 0)
    {
        H /= 2;
        n++;
    }

    // ans = 1 + 2 + 2^2 + 2^3 + ... + 2^(n - 1)

    ll ans = pow(2, n) - 1;

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

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int p, q, r;
    cin >> p >> q >> r;
    cout << min(p + min(q, r), q + r) << endl;
}

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

#define LL long long

using namespace std;

#define gc getchar()
inline LL read() {
	LL x = 0; char c = gc;
	while(c < '0' || c > '9') c = gc;
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
	return x;
}

#define Rep(i, a, b) for(int i = a; i <= b; i ++) 

const int N = 1e5 + 10;

struct Node {
	LL A, B, C, A_B;
} Num[N];
LL L[N], R[N];

priority_queue <LL, vector<LL>, greater<LL> > Q;
priority_queue <LL, vector<LL>, less<LL> > Qu;

bool Cmp(Node a, Node b) {
	return a.A > b.A;
}

int main() {
	
	LL X, Y, Z, n;
	LL Sum_C = 0, Sum_B = 0, Sum = 0;
	
	X = read(), Y = read(), Z = read();
	n = X + Y + Z;
	Rep(i, 1, n) {
		Num[i] = (Node) {read(), read(), read(), 0};
		Sum_C += Num[i].C; 
		Num[i].A -= Num[i].C, Num[i].B -= Num[i].C;
		Num[i].A_B = Num[i].A - Num[i].B;
		Sum_B += Num[i].B;
	}
	
	sort(Num + 1, Num + n + 1, Cmp);
	
	Rep(i, 1, X) Q.push(Num[i].A_B), Sum += Num[i].A_B;
	L[X] = Sum;
	Rep(i, X + 1, X + Y) {
		int a_b = Num[i].A_B, tp = Q.top();
		if(a_b > tp) {
			Q.pop(); Q.push(a_b); Sum += a_b - tp;
		}
		L[i] = Sum;
	}
	
	Sum = 0;
	for(int i = n; i > X + Y; i --) Qu.push(Num[i].B), Sum += Num[i].B;
	R[X + Y + 1] = Sum;
	for(int i = X + Y; i >= X; i --) {
		int b = Num[i].B, tp = Qu.top();
		if(b < tp) {
			Qu.pop(); Qu.push(b); Sum += b - tp;
		}
		R[i] = Sum;
	}
	
	LL Answer = - 1e18;
	
	Rep(i, X, X + Y) {
		Answer = max(Answer, L[i] - R[i + 1]);
	}
	
	cout << Answer + Sum_C + Sum_B;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  string t;
  cin>>t;
  for (int i = 0; i < t.size(); ++i)
  {
    if(t[i]=='?') t[i]='D';
  }
  cout<<t<<endl;
}

Measured memory_bytes: 3732
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
win = []
ans = 0
for i in range(n):
    if t[i] == "r":
        win.append("p")
    elif t[i] == "s":
        win.append("r")
    else:
        win.append("s")
for i in range(n):
    if i >= k:
        if win[i] == win[i - k]:
            if i + k >= n:
                pass
            elif win[i + k] != t[i]:
                win[i] = t[i]
            else:
                if win[i] != r and [i + k] != r:
                    win[i] = r
                elif win[i] != s and [i + k] != s:
                    win[i] = s
                elif win[i] != p and [i + k] != p:
                    win[i] = p
        else:
            if win[i] == "r":
                ans += r
            elif win[i] == "s":
                ans += s
            else:
                ans += p
    else:
        if win[i] == "r":
            ans += r
        elif win[i] == "s":
            ans += s
        else:
            ans += p
print(ans)

Measured memory_bytes: 54412
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	strs := strings.Split(sc.Text(), " ")
	a, _ := strconv.ParseFloat(strs[0], 64)
	b, _ := strconv.ParseFloat(strs[1], 64)
	deg, _ := strconv.ParseFloat(strs[2], 64)

	fmt.Println(a * b / 2 * math.Sin(deg*math.Pi/180))
	fmt.Println(math.Sqrt(a*a + b*b - 2*a*b*math.Cos(deg*math.Pi/180)) + a + b)
	fmt.Println(b * math.Sin(deg*math.Pi/180))
}



Measured memory_bytes: 1100
div=10**9+7
def modinv(a, m=1000000007): return pow(a, m-2, m)

N,A,B,C=list(map(int,input().split()))
fact=[1]*(2*N+1)
res = 0
invAB = modinv(A+B)
reveven = (modinv(100-C)*100) % div
memoA = [1]*(N+1)
memoB = [1]*(N+1)

for i in range(1, 2*N+1): fact[i] = fact[i-1]*i % div
def ncr(n, r): return fact[n]*modinv(fact[r]*fact[n-r]%div) % div

for i in range(1, N+1): 
    memoA[i] = (memoA[i-1]*A*invAB) % div
    memoB[i] = (memoB[i-1]*B*invAB) % div

for i in range(N, 2*N): res += (((ncr(i-1, N-1)*memoA[N] % div)*memoB[i-N] + (ncr(i-1, N-1)*memoB[N] % div)*memoA[i-N]) % div)*reveven*i % div

print(res % div)


Measured memory_bytes: 64220
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

vector<vector<int>> G;
vector<int> d;
bool visit[1000];
void bfs(int s) {
    queue<int> que;
    visit[s] = 1;
    d[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (visit[nv]) {
                continue;
            }
            visit[nv] = 1;
            d[nv] = d[v] + 1;
            que.push(nv);
        }
    }
}
int main(void) { 
    int N;
    cin >> N;
    G.resize(N);
    d.assign(N, -1);
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int i = 0; i < k; i++) {
            int v;
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    bfs(0);
    for(int i = 0; i < N; i++) {
        cout << i + 1 << ' ' << d[i] << endl;
    }
}


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

const double EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = 2e5;
const double PI = acos(-1.0);

using namespace std;


struct UnionFind {
    static const int Max = 100010;
    int par[Max];
    int rank[Max];

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

const int MAXE = 100010 * 2;
struct edge { int u, v, cost; bool operator<(const edge& e) { return cost < e.cost; } };

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

edge es[MAXE];
int V, E;
//
ll kruskal() {
    sort(es, es+E*2, comp);
    UnionFind uf;
    uf.init(V);
    ll res = 0;
    for (int i=0; i<E*2; ++i) {
        edge e = es[i];
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    cin >> V >> E;
    int cur = 0;
    rep(i, E) {
        int s, t, w;
        cin >> s >> t >> w;
        es[cur++] = edge{s, t, w};
        es[cur++] = edge{t, s, w};
    }
    cout << kruskal() << endl;
}



Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <iostream>

typedef long long int ll;
#define test int t; cin >> t; while(t--) 
using namespace std;

int main (){
    // problem code - A FROG 1, Author - gamerrk1004
  
  ll h[100007];
    ll n;
  cin >> n;
  for(ll i=1;i<=n;i++){
    
    cin >> h[i];
  }
  ll r[100007];
  r[1]=0;
  r[2]=abs(h[2]-h[1]);
  for(ll i=3;i<=n;i++){
    
    r[i]=min(r[i-2] + abs(h[i]-h[i-2]),r[i-1] + abs(h[i]-h[i-1]));
}
  
  cout << r[n] << endl;

}

Measured memory_bytes: 1792
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (n, x, t) = toTuple(readInts())
var ans = n / x * t
if n % x != 0 {
  ans += t
}
print(ans)

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

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

    int n, h;
    cin >> n >> h;

    vector<pair<int, bool>> A(n), B(n + 1);
    REP(i, n){
        cin >> A[i].first >> B[i].first;
        A[i].second = true;
        B[i].second = false;
    }

    sort(A.begin(), A.end(), greater<pair<int, bool>>());

    B[n].first = A[0].first;
    B[n].second = A[0].second;

    sort(B.begin(), B.end(), greater<pair<int, bool>>());

    int cnt = 0, idx = 0;
    while(h > 0){
        if(B[idx].second){
            cnt += (h + B[idx].first - 1) / B[idx].first;
            break;
        }else{
            h -= B[idx].first;
            cnt++;
        }
        idx++;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1920
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

getString = BS.unpack <$> BS.getLine

main = do
  a <- getInt
  s <- getString
  putStrLn $ if a >= 3200 then s else "red"


Measured memory_bytes: 3772