akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long long ll;

#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 2e5+5;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int main()
{
	ll x, k, d; scanf("%lld %lld %lld", &x, &k, &d);

	bool neg = false;
	if(x< 0) 
	{
		neg = true;
	}

	x = abs(x);

	ll foo = x/d;

	ll ans;

	if(k< foo)
	{
		if(neg) ans = abs(-x + k*d);
		else ans = x - k*d;
	}
	else
	{
		if(k%2 == foo%2)
		{
			ans = x - foo*d;
		}
		else ans = (foo+1)*d - x;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3864
import heapq
from collections import deque
from copy import deepcopy

n,k = map(int,input().split())
U = deque(map(int,input().split()))

Max = -10**9

for a in range(min(n,k)+1):
  for b in range(min(n,k)+1-a):
    
    V = deepcopy(U)
    Heap = []
    heapq.heapify(Heap)
    
    if a >= 1:
      for i in range(a):
        heapq.heappush(Heap,V.pop())
        
    if b >= 1:  
      for i in range(b):
        heapq.heappush(Heap,V.popleft())
        
    if k-a-b >= 1:
      for i in range(k-a-b):
        
        if len(Heap) >= 1:
          Min = heapq.heappop(Heap)
                 
          if Min >= 0:
            heapq.heappush(Heap,Min)
            break

    Max = max(Max,sum(Heap))
    
print(Max)

Measured memory_bytes: 3436
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

solve :: [Integer] -> String
solve argList = if any (\x -> 0 == (mod x 2)) argList
                then "Even"
                else "Odd" 

main = do
    argList <- getIntList
    putStrLn $ solve argList


Measured memory_bytes: 380
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<cmath>
#include<stack>
#include<cstdio>
using namespace std;
int isHuiwen(string s,int start,int end)
{
    //int len=s.length(),fin=len-1,use=len/2;
    int fin=end,use=(end+1)/2;
    
    for(int i = 0;i<use;i++,fin--)
    {
        if(s.at(i)!=s.at(fin))
            return 0;
    }
           return 1;
}
int main()
{
    int n,m,ans,flag=1;
    string s;
    cin>>s;
    int len=s.length();
    if(!isHuiwen(s,0,len-1))
        flag=0;
    if(!isHuiwen(s,0,(len-1)/2-1))
        flag=0;
    if(!isHuiwen(s,(len+3)/2-1,len-1))
        flag=0;
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define com bool operator<(const node &b)const
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;

void solve() {
    string s;
    cin >> s;
    int num = 0;
    for (auto &i:s)num = (num + i - '0') % 9;
    cout << ((num == 0)?"Yes":"No");
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>

int main() {
    std::string a, b, c;
    std::cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front()) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
 
using namespace std;

template <typename T>
class UF{
public:
	T par[10000],rank[10000];
 
    inline UF(T n){
        for(T i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
 
    inline T find(T x){
        if(par[x]==x)
            return x;
        else
            return par[x]=find(par[x]);
    }
 
    inline void unite(T x, T 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]++;
        }
    }
 
    inline bool same(T x, T y){
        return find(x)==find(y);
    }
 
};
int main(){
	int n,q;
	scanf("%d %d",&n,&q);
	
	UF<int> uf(n);
	int c,x,y;
	while(q--){
		scanf("%d %d %d",&c,&x,&y);
		
		
		if(c)printf("%d\n",uf.same(x,y));
		else uf.unite(x,y);
	}
	
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
int read();
int n, L, T;
int M(int x) { return x >= L ? x - L : x; }
int x[200005], dire[200005], q[2];
int res[200005];
vector<int> p[2];

int tmp;
int to(int a) {
    int rt = M((x[a] + (dire[a] ? 1 : -1) * T) % L + L);
    rt += L - tmp;
    return rt > L ? rt - L : rt;
}

bool cmp(int a, int b) { return b == 1 ? 0 : (a > b || a == 1); }

int dis(int a, int b) { return M((x[b] - x[a]) * (dire[a] ? 1 : -1) + L); }

int pre[2][200005];

long long calc(int i, int j) {
    return 1ll * pre[i][q[i] - 1] * (j / q[i]) +
           (j % q[i] ? pre[i][j % q[i] - 1] : 0);
}

int solve() {
    int t;
    if (!p[1].size() || (t = 2 * T - dis(1, p[1][0])) <= 0) return 1;
    for (int i = 0; i < 2; ++i) {
        if ((q[i] = p[i].size()) == 1) {
            pre[i][0] = L;
            continue;
        }
        for (int j = 0; j < q[i] - 1; ++j)
            pre[i][j] = dis(p[i][j + 1], p[i][j]);
        pre[i][q[i] - 1] = dis(p[i][0], p[i][q[i] - 1]);
        for (int j = 0; j < q[i]; ++j) pre[i][j] += pre[i][j - 1];
    }
    int l = 0, r = 1000000000, rs = 0;
    while (l <= r) {
        int mid = l + r >> 1;
        long long len = calc(0, (mid >> 1) + (mid & 1)) + calc(1, mid >> 1);
        if (len <= t)
            l = mid + 1, rs = mid;
        else
            r = mid - 1;
    }
    rs = (rs & 1) ? p[0][((rs >> 1) + 1) % q[0]] : p[1][(rs >> 1) % q[1]];
    return rs;
}

int main() {
    n = read(), L = read(), T = read();
    for (int i = 1; i <= n; ++i)
        x[i] = read(), dire[i] = read() & 1, p[dire[i] ^ dire[1]].push_back(i);
    if (dire[1])
        sort(p[0].begin(), p[0].end(), cmp), sort(p[1].begin(), p[1].end());
    else
        sort(p[0].begin(), p[0].end()), sort(p[1].begin(), p[1].end(), cmp);
    int st = solve();
    tmp = to(st);
    for (int i = 1; i <= n; ++i) res[i] = to(i);
    res[st] = 0, sort(res + 1, res + 1 + n);
    for (int i = 1; i <= n; ++i) printf("%d\n", M(res[i] + tmp));
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}


Measured memory_bytes: 3276
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
D = []
for i in range(len(X)-1):
    D.append(X[i+1]-X[i])
D.sort()
if N>=M:
    print(0)
else:
    print(sum(D[:M-N]))

Measured memory_bytes: 90744
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<vector>
#include<list>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

bool func(vector<int> ctr, vector<int> pts){
  int ans = max(ctr[2]-abs(pts[0]-ctr[0])-abs(pts[1]-ctr[1]), 0);
  return ans != pts[2];
}

void list_update(list<vector<int>>& lst, vector<int> tri){
  for(auto itr = lst.begin(); itr != lst.end(); ){
    if(func(*itr, tri))
      itr = lst.erase(itr);
    else
      ++itr;
  }
}

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

  list<vector<int>> xyh(n, vector<int>(3, 0));
  vector<int> tmp(3);
  for(auto itr = xyh.begin(); itr != xyh.end(); itr++)
    cin >> (*itr)[0] >> (*itr)[1] >> (*itr)[2];
  for(auto itr = xyh.begin(); itr != xyh.end(); itr++){
    if((*itr)[2] != 0){
      for(int j = 0; j <= 2; j++){
	tmp[j] = (*itr)[j];
      }
      break;
    }
  }

  list<vector<int>> main_list;
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j <= 100; j++){
      main_list.push_back({i, j, tmp[2] + abs(i - tmp[0]) + abs(j - tmp[1])});
    }
  }
  
  for(auto itr = xyh.begin(); itr != xyh.end(); itr++){
    list_update(main_list, *itr);
    if(main_list.size() == 1) break;
  }

  cout << (*(main_list.begin()))[0] << " "
       << (*(main_list.begin()))[1] << " "
       << (*(main_list.begin()))[2] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
fun main() {
    val (A, V) = readLine()!!.split(" ").map { it.toLong() }
    val (B, W) = readLine()!!.split(" ").map { it.toLong() }
    val T = readLine()!!.toLong()
    if(W >= V){
        println("NO")
    }else{
        val l = Math.abs(A - B)
        val v = V - W
        if(v * T >= l){
            println("YES")
        }else{
            println("NO")
        }
    }
}

Measured memory_bytes: 36452
#include<stdio.h>
using namespace std;
int main() {
	int C[3][3];

	for (int r = 0; r < 3; ++r)
		for (int c = 0; c < 3; ++c)
			scanf("%d", &C[r][c]);

	for (int a1 = 0; a1 <= 100; ++a1) {
		for (int a2 = 0; a2 <= 100; ++a2) {
			for (int a3 = 0; a3 <= 100; ++a3) {
				bool f = true;
				for (int c = 0; c < 3; ++c) {
					if (!(C[0][c] - a1 == C[1][c] - a2 && C[1][c] - a2 == C[2][c] - a3)) {
						f = false;
					}
				}
				if (f) {
					printf("Yes\n");
					return 0;
				}
			}
		}
	}

	printf("No\n");
}

Measured memory_bytes: 128
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
 
n=int(input())
c= collections.Counter(prime_factorize(n))
#ここまでで素因数分解して個数が何個あるかcheckしてる
sum=0
for i in c:
    n=1
    while n*(n+1)/2<=c[i]:
        n=n+1
    sum=sum+n-1
print(sum)
    


Measured memory_bytes: 9468
#include <iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    rep(i,n){
        cin>>a[i];
        b[i] = a[i];
    }
    sort(rng(b));
    rep(i,n){
        if(a[i] == b[n-1]){
            cout<<b[n-2]<<endl;
        }
        else cout<<b[n-1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 4736
#pragma GCC optimize("O2", "unroll-loops")
#pragma GCC target("avx")

#include <stdio.h>
constexpr int MAX_InputSize = 20000;
char Input[MAX_InputSize];

inline int getint(void){
    static char* input = Input;
    int res = 0, c; while((c = *input++ - '0') >= 0) res = 10 * res + c;
    return res;
}

constexpr int mod = 998244353;
constexpr int MAX_N = 3000;
constexpr int MAX_S = 3000;
int A[MAX_N];
int dp[MAX_S + 1];

int main(void){
    fread_unlocked(Input, 1, MAX_InputSize, stdin);
    const int n = getint(); const int S = getint(); 
    for(int i = n; i-- ; ) A[i] = getint();
    dp[0] = 1;
    for(int i = n; i-- ; ){
        for(int j1 = S, j2 = S - A[i]; j2 >= 0 ; --j1, --j2){
            dp[j1] <<= 1; if(dp[j1] >= mod) dp[j1] -= mod;
            dp[j1] += dp[j2]; if(dp[j1] >= mod) dp[j1] -= mod;
        }
        for(int j = A[i] - 1; j >= 0; --j) if((dp[j] <<= 1) >= mod) dp[j] -= mod;
    }
    printf("%d\n", dp[S]);
    return 0;
}

Measured memory_bytes: 1636
from sys import exit
s=input()
x,y=map(int,input().split())

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s=groupby(s)
a,b=[],[]
turn=True
#初めまっすぐの場合
if s[0][0]=="F":
    x-=s[0][1]
    s.pop(0)
for i in s:
    if i[0]=="F":
        if turn:
            a.append(i[1])
        else:
            b.append(i[1])
    elif i[1]%2==1:
        turn=not turn
a.sort()
b.sort()
for i in a[::-1]:
    x=abs(x)-abs(i)
if x!=0:
    print("No")
    exit()
for i in b[::-1]:
    y=abs(y)-abs(i)
if y!=0:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 42032
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
#define debugCont(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define double long double
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

signed main(){

    fastIO
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double angle = ((double)h + (double)m/60.0)*30 - (double)m*6;
	// trace(angle);
	double rad = PI * 2 * ((double)h / 12.0 + ((double)m / 60.0) / 12.0 - (double)m / 60.0);
	angle *= (PI/180);
	trace(angle, rad)
	double ans1 = sqrtl((double)(b*b + a*a) - (double)2*b*a*cosl(angle));
	// double ans2 = sqrtl((double)(b*b + a*a) - (double)2*b*a*cosl(rad));
	// printf("ans2 = %Lf\n", ans2);
	printf("%20.20Lf\n", ans1);

    return 0;
}

Measured memory_bytes: 4172
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	auto A=vecin(N);
	auto B=vecin(N);
	auto C=vecin(N);
	sort(ALL(A));
	sort(ALL(B));
	sort(ALL(C));
	
	ll sum=0;
	vector<ll> BC(N,0),S(N+1,0);
	REP(i,N){
		auto findC = lower_bound(ALL(C),B[i]+1);
		if(findC!=C.end()){
			BC[i] = distance(findC,C.end());
		}
		S[i+1] = S[i]+BC[i];
	}

	REP(i,N){
		auto findB = lower_bound(ALL(B),A[i]+1);
		if(findB!=B.end()){
			int dist = distance(B.begin(),findB);
			sum += S[N]-S[dist];
		}
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string s; cin >> s;
    int ans = 0;
    rep(i,4){
        if(s[i] == '+')++ans;
        else --ans;
    }
    cout << ans << endl;
}


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

count =0
first = True
while N >=K:
    if  first ==True:
        count +=1
        N-=K
        first =False
        
    else:
        count+=1
        N-=(K-1)
        
   
    

if N!=0:
    count+=1
print(count)


Measured memory_bytes: 20592
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
struct ival{
   int t;
   double x,yi,yf;
   bool operator <(ival a)const{
      if(x!=a.x)return x<a.x;
      if(yi!=a.yi)return yi<a.yi;
      if(yf!=a.yf)return yf<a.yf;
      return t<a.t;
   }
};
vector<ival>q;
multiset<pair<double,double> >s;
multiset<pair<double,double> >::iterator it;
double len(){
   if(s.empty())return 0;
   double ans=0;
   double lft=s.begin()->first;
   double rht=lft;
   for(it=s.begin();it!=s.end();it++){
      if(it->first>rht){
         ans+=rht-lft;
         lft=it->first;
         rht=it->second;
      }
      else rht=max(rht,it->second);
   }
   ans+=rht-lft;
   return ans;
}
int main(){
   int n,tt=0;
   while(scanf("%d",&n)==1){
      if(n==0)break;
      s.clear();
      q.clear();
      for(int i=0;i<n;i++){
         double xi,yi,r;
         scanf("%lf %lf %lf",&xi,&yi,&r);
         ival ivi={0,xi-r,yi-r,yi+r};
         ival ivf={1,xi+r,yi-r,yi+r};
         q.push_back(ivi);
         q.push_back(ivf);
      }
      sort(q.begin(),q.end());
      double ans=0.0;
      double xi=q[0].x;
      for(int i=0;i<int(q.size());i++){
         ival iv=q[i];
         ans+=(iv.x-xi)*len();
         xi=iv.x;
         if(iv.t==0){
            s.insert(make_pair(iv.yi,iv.yf));
         }
         else{
            it=s.find(make_pair(iv.yi,iv.yf));
            s.erase(it);
         }
      }
      printf("%d %.2lf\n",++tt,ans);
   }
   return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n + 1] = {};
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	map<int, int> mp;
	for (int i = 0; i <= n; i++) {
		mp[a[i]]++;
	}
	int ans = 0;
	for (auto i : mp) {
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll_t;

#define PERR(fmt, ...) \
    do { \
        fprintf(stderr, fmt, ##__VA_ARGS__); \
    } while (0) 


const int M = 1000000007;

int N;
int T[100002];
int A[100002];

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
        scanf("%d", &T[i]);
    for (int i = 1; i <= N; i++)
        scanf("%d", &A[i]);
    T[0] = 0; T[N+1] = T[N];
    A[0] = A[1], A[N+1] = 0;
    ll_t res = 1;
    for (int i = 1; i <= N; i++) {
        if (T[i] == T[i-1])  { // H[i] <= T[i]
            if (A[i] == A[i+1]) // H[i] <= A[i]
                res *= min(T[i], A[i]);
            else  // A[i] > A[i+1]
                res *= A[i] <= T[i];
        } else { // T[i] > T[i-1], H[i] = T[i]
            if (A[i] == A[i+1])
                res *= T[i] <= A[i];
            else
                res *= T[i] == A[i];
        }
        res %= M;
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1024
dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    t = a[0] // 2
    p = a[-1]
    if n == 2:
        print("%d %d" % (a[0], a[1]))
        return
    i = 1
    while a[i] > t:
        i += 1
        if i >= n:
            i -= 1
            break
    if abs(a[i - 1] - t) > abs(a[i] - t):
        p = a[i]
    else:
        p = a[i - 1]
    print("%d %d" % (a[0], p))


def main1():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


if __name__ == '__main__':
    main()


Measured memory_bytes: 14356
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,cnt=0,c,d;
    cin>>a>>b;

    
        if(b%a==0)
        {
            cout<<a+b<<endl;
        }
  else
    
    cout<<b-a<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        char ch;
        cin>>ch;
        if(ch=='a'|| ch=='e' || ch=='i' || ch=='o' || ch=='u')
          cout<<"vowel"<<endl;
        else
          cout<<"consonant"<<endl;
        return 0;
    }

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a <= 9 && b <= 9) cout << a * b << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func main() {
	sc.Split(bufio.ScanWords)
	var allSunukeCount, okahiCount = nextInt(), nextInt()
	var okashiSunukes []int
	for i := 0; i < okahiCount; i++ {
		sunukeCount := nextInt()
		for i := 0; i < sunukeCount; i++ {
			sunukeNum := nextInt()
			if !contains(okashiSunukes, sunukeNum) {
				okashiSunukes = append(okashiSunukes, sunukeNum)
			}
		}
	}
	fmt.Println(allSunukeCount - len(okashiSunukes))
}


Measured memory_bytes: 1768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.nextLine();
		String[] b = x.split(" ");
		int a = Integer.parseInt(b[0]);
		int c = Integer.parseInt(b[1]);
		if (a > c) {
			System.out.println("a > b");

		}
		if (a < c) {
			System.out.println("a < b");

		}
		if (a == c) {
			System.out.println("a == b");

		}

	}
}

Measured memory_bytes: 26120
#include<iostream>


void insert(int a[],int n){
  int i,j,k,v;
  for(i=0;i<n;i++){
    v = a[i];
    j = i-1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    for(k=0;k<n;k++){
      if(k == n-1){
	std::cout<<a[k];
      }else{
	std::cout<<a[k]<<" ";
      }
    }
    std::cout<<"\n";
  }
}

int main(){
  int i,n,a[10000];

  std::cin>>n;
  for(i=0;i<n;i++){
    std::cin>>a[i];
  }
  insert(a,n);
  return 0;
}


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF (int)1e9+7

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;

int main() {
    int ans = 0;
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    vector<vi> chm(H,vi(W,0));
    vector<vi> cha(H,vi(W,0));

    //(W方向の)障害物に当たらない長さを求める
    rep(i, H) {
        rep(j, W) {
            if(S[i][j] == '.') {
                chm[i][j]++;
                if(j > 0) chm[i][j] += chm[i][j-1];
            }
        }
        repr(j, W-1) {
            if(chm[i][j] > 0) chm[i][j] = max(chm[i][j], chm[i][j+1]);
        }
    }

    //(H方向の)障害物に当たらない長さを求める
    rep(j, W) {
        rep(i, H) {
            if(S[i][j] == '.') {
                cha[i][j]++;
                if(i > 0) cha[i][j] += cha[i-1][j];
            }
        }
        repr(i, H-1) {
            if(cha[i][j] > 0) cha[i][j] = max(cha[i][j], cha[i+1][j]);
        }
    }

    //W方向とH方向の障害物に当たらない長さを足す
    rep(i, H) {
        rep(j, W) {
            cha[i][j] += chm[i][j] - 1;
        }
    }

    //一番長いのが答え
    rep(i, H) {
        rep(j, W) {
            ans = max(ans, cha[i][j]);
        }
    }

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


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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, P[200010];

void input() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> P[i];
    return;
}

void solve() {
    int ans = 0, min_P = P[0];
    for (int i = 0; i < N; ++i) {
        if (min_P >= P[i]) {
            min_P = P[i];
            ans += 1;
        }
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 1024
fun main(args: Array<String>) = yorukatsu10d()

fun yorukatsu10d() {
    val (n, k) = readLine()!!.split(' ').map { it.toLong() }

    if (k == 0L) return println(n * n)

    var answer = 0L

    for (b in k + 1..n) {
        answer += (n / b) * (b - k) + Math.max(n % b - k + 1, 0)
    }

    println(answer)
}


Measured memory_bytes: 38360
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int k, a, b;
    cin >> k >> a >> b;
    bool ret = false;
    for(int i=a;i<=b;++i)
    {
        if(i % k == 0) ret = true;
    }

    cout << (ret ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	int N;
	cin >> N;
	if (N % 2 == 0) {
		cout << N << endl;
	}
	else {
		cout << N * 2 << endl;
	}
}



	


Measured memory_bytes: 256
#include <cstdio>

static const int maxn = 100 + 5;
int s[maxn];
char buff[100];

int get_num(){
	int sum = buff[0] - '0';
	for (int i = 1; buff[i] != '\0'; i++) {
		sum = sum * 10 + buff[i] - '0';
	}
	return sum;
}

int main(){
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	int p = 0;
	while(scanf("%s", buff) == 1) {
		if (buff[0] == '+') {
			s[p-2] += s[p-1];
			p--;
		}
		else if (buff[0] == '-') {
			s[p-2] -= s[p-1];
			p--;
		}
		else if (buff[0] == '*') {
			s[p-2] *= s[p-1];
			p--;
		}
		else {
			s[p] = get_num();
			p++;
		}
	}
	printf("%d\n", s[0]);
	return 0;
}



Measured memory_bytes: 2744
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

bool IsPrime(ll);

ll N;
vector<ll> factor;

int main() {
    cin >> N;
    //まず因数をかきだす
    //O(√N)
    ll a;
    ll ans = 0;
    for (a = 1; N >= a * a; a++) {
        if (N % a == 0) {
            factor.push_back(a);
            if (a != N / a) {
                factor.push_back(N / a);
            }
        }
    }
    //これでfactorに因数全部入った
    sort(factor.begin(), factor.end());

    //REP(i, (int)factor.size()) {
    //    cout << factor[i] << endl;
    //}
    //昇順ソート
    REP(i, (int)factor.size()) {
        if (IsPrime(factor[i]) && N % factor[i] == 0) {
            N /= factor[i];
            ans++;
        }
    }
    cout << ans << endl;

    //REP(i, 100) {
    //    if (IsPrime(i)) cout << i << endl;
    //}
}

bool IsPrime(ll a) {
    int ans = 0;
    ll A = a;
    if (A <= 1) return false;
    for (ll i = 2; A >= i * i; i++) {
        if (a % i == 0) {
            ans++;
            //if (a / i != 1 && i != a / i) ans++;
        }
        while (a % i == 0) {
            a /= i;
        }
        
    }
    //aが1でないときはfalse
    if (a != 1) ans++;
    if (ans >= 2) return false;
    return true;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> C(H, vector<char>(W));
    rep(i, H) rep(j, W) cin >> C.at(i).at(j);
    int ans=0;
    rep(i,(1<<H)) {
        rep(j,(1<<W)) {
            int B=0;
            rep(k,H) {
                rep(l,W) {
                    if((i>>k)&0==0 && (j>>l)&0==0 && C.at(k).at(l)=='#') B++;
                }
            }
            if(B==K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this string str)
    {
        return int.Parse(str);
    }

    public static long ToLong(this string str)
    {
        return long.Parse(str);
    }
    public static IEnumerable<int> ToInt(this string[] strs)
    {
        return strs.Select(x => x.ToInt());
    }

    public static IEnumerable<long> ToLong(this string[] strs)
    {
        return strs.Select(x => x.ToLong());
    }
    public static IEnumerable<int> SplToInt(this string str, char opr = ' ')
    {
        return str.Split(opr).ToInt();
    }

    public static IEnumerable<long> SplToLong(this string str, char opr = ' ')
    {
        return str.Split(opr).ToLong();
    }
    public static string CRL()
    {
        return Console.ReadLine();
    }
    public static void CWL(object obj)
    {
        Console.WriteLine(obj);
    }
    public static int Diff(int a, int b)
    {
        return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    }
    public static long Diff(long a, long b)
    {
        return Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    }
    public static int Sign(this int i)
    {
        return Math.Sign(i);
    }
    //テンプレここまで
}

public static partial class Program
{
    static void Main()
    {
        var n = CRL().ToInt();
        var ans = "";
        while (n != 0)
        {
            if (n % 2 != 0)
            {
                n--;
                ans = "1" + ans;
            }
            else
            {
                ans = "0" + ans;
            }

            n /= -2;
        }

        if (ans == "")
        {
            ans = "0";
        }
        CWL(ans);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

int dx[4] = { 0, -1, 1, 0 };
int dy[4] = { -1, 0, 0, 1 };

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  x -= a;
  int res = x % b;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
N, W = list(map(int, input().split()))
dp = [[W+1]*(100000+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    w, v = list(map(int, input().split()))
    for j in range(100000+1):
        if j+v <= 100000:
            dp[i+1][j+v] = min(dp[i+1][j+v], dp[i][j] + w)
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
i = -1
while True:
    if dp[N][i] <= W:
        print(100000+1+i)
        break
    else:
        i -= 1

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

int main() {
    int X, A;
    cin >> X >> A;
    if (X < A)
    {
        cout << 0 << endl;
    } else
    {
        cout << 10 << endl;
    }
    
    
  return 0;
}


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

int main(void)
{
  int n,k,ans=0,i,t;
  scanf("%d",&n);
  k=log10(n)+1;
  t=k/2;
  for(i=0;i<t;i++){
    ans+=9*pow(10,i*2);
  }
  if(k%2==1)
    ans+=n-pow(10,k-1)+1;
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
main(){
	int w,n;
	int amida[31],i;
	scanf("%d%d",&w,&n);
	for(i=1;i<=w;i++)	amida[i]=i;
	for(i=0;i<n;i++){
		int a,b,t;
		scanf("%d,%d",&a,&b);
		t=amida[a],amida[a]=amida[b],amida[b]=t;
	}
	for(i=1;i<=w;i++)	printf("%d\n",amida[i]);
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

using namespace std;

const uint64_t INF = static_cast<uint64_t>(-1);

struct Edge
{
  uint64_t A, B;
  Edge(uint64_t A = INF, uint64_t B = INF) : A(A), B(B) {}
};

istream& operator>>(istream &is, Edge &edge)
{
  is >> edge.A >> edge.B;
  return is;
}

struct Exchange
{
  uint64_t C, D;
  Exchange(uint64_t C = INF, uint64_t D = INF) : C(C), D(D) {}
};

istream& operator>>(istream &is, Exchange &exchange)
{
  is >> exchange.C >> exchange.D;
  return is;
}

struct SearchItem
{
  uint64_t pos, silver, time;
  SearchItem(uint64_t pos, uint64_t silver, uint64_t time)
    : pos(pos), silver(silver), time(time) {}
  bool operator>(const SearchItem &item) const {
    return time > item.time;
  }
};

int main()
{
  uint64_t N, M, S;
  cin >> N >> M >> S;

  uint64_t A_max = 0;
  vector<vector<Edge>> edges(N, vector<Edge>(N));
  N_TIMES(m, M) {
    uint64_t U, V;
    Edge E;

    cin >> U >> V >> E;
    --U; --V;
    edges[U][V] = E;
    edges[V][U] = E;
    A_max = max(A_max, E.A);
  }

  vector<Exchange> exchanges(N);
  N_TIMES(n, N) { cin >> exchanges[n]; }

  vector<vector<uint64_t>> times(N, vector<uint64_t>(A_max * N, INF));
  if (S > A_max * N) { S = A_max * N - 1; }
  times[0][S] = 0;

  minimum_heap<SearchItem> q;
  q.emplace(0, S, 0);

  while (!q.empty()) {
    SearchItem item = q.top(); q.pop();
    if (item.time == INF) { continue; }

    // 移動
    N_TIMES(v, N) {
      Edge edge = edges[item.pos][v];
      // 線路があり，かつ運賃を支払える
      if ((edge.B != INF) && (edge.A <= item.silver)) {
        SearchItem new_item(v, item.silver - edge.A, item.time + edge.B);
        if (new_item.time < times[new_item.pos][new_item.silver]) {
          times[new_item.pos][new_item.silver] = new_item.time;
          q.push(new_item);
        }
      }
    }

    // 両替
    Exchange exchange = exchanges[item.pos];
    if (item.silver + exchange.C < A_max * N) {
      SearchItem new_item(item.pos, item.silver + exchange.C, item.time + exchange.D);
      if (new_item.time < times[new_item.pos][new_item.silver]) {
        times[new_item.pos][new_item.silver] = new_item.time;
        q.push(new_item);
      }
    }
  }

  for (uint64_t n = 1; n < N; ++n) {
    uint64_t ans = INF;
    N_TIMES(s, A_max * N) { ans = min(ans, times[n][s]); }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 7308
S=input()
N=len(S)+1
llst=[0 for i in range(N)]
rlst=[0 for i in range(N)]
for i in range(N-1):
  if S[i]=='<':
    llst[i+1]=llst[i]+1
for i in range(N-2, -1, -1):
  if S[i]=='>':
    rlst[i]=rlst[i+1]+1
ans=0
for i in range(N):
  ans+=max(llst[i], rlst[i])
print(ans)

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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vector<int> t;
    vector<int> used(n + 1);
    t.push_back(1);

    int pos = 1;
    while (true) {
        pos = a[pos];
        if (used[pos])
            break;
        used[pos] = t.size();
        t.push_back(pos);
    }
    
    if (k < used[pos])
        cout << t[k];
    else {
        k -= used[pos];
        ll size = t.size() - used[pos];
        cout << t[used[pos] + k % size];
    }
        
    return 0;
}


Measured memory_bytes: 5820
#include<iostream>
using namespace std;
int main()
{
int a1,b1,c1; //declaring variables
cin>>a1>>b1>>c1; //takes input from the user
if(a1==b1 && a1!=c1)
{
cout<<"Yes";
}
else if(b1==c1 && c1!=a1)
{
 cout<<"Yes";
}
else if(a1==c1 && a1!=b1)
{
 cout<<"Yes";
}
else
{
 cout<<"No";
}
return 0;
}

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

int main()
{
	int N;
	string s, t;
	cin >> N >> s >> t;

	int cnt = 0;
	for( int i = N; i > 0; i-- ) {
		if( t.substr( 0, i ) == s.substr( N - i, i ) ) {
			cnt = i;
			break;
		}
	}
	int ans = 2 * N - cnt;

	cout << ans << endl;
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
h = III()

val = 0
while 1:
    for i in range(N):
        if h[i]!=0:
            if i==0:
                val += 1
            else:
                if h[i-1]==0:
                    val += 1
                    
    flag = True
    for i in range(N):
        if h[i]!=0:
            h[i] -= 1
            flag = False
    
    if flag:
        break

print(val)

Measured memory_bytes: 39280
#include <iostream>
using namespace std;
int main() {
    int x, y; cin >> x >> y;
    if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)) printf("%s\n", "Yes");
    else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11)) printf("%s\n", "Yes");
    else if (x == 2 && y == 2) printf("%s\n", "Yes");
    else printf("%s\n", "No");
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
char c[2][3];
int main() {
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}
	if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
}

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

int main() {
    int S;
  cin >> S;
  int y=0,m=0,i;
  i=S/100;
  if(i<=12 && i!=0) y=1;
  i *=100;
  if(S-i<=12 && S-i!=0) m=1;
  
  if(y==1 && m==1) cout << "AMBIGUOUS" << endl;
  else if(y==1 && m==0) cout << "MMYY" << endl;
  else if(y==0 && m==1) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#include <iostream>
using namespace std;

int main() {
   ll n,m;cin>>n>>m;int x=0;
   ll a[n]={0};
 
  while(m--){
       ll s,c;
       cin>>s>>c;
       if((s==1&&c==0)&&n!=1) {x=-1;}
       if(x==0){
           for(int i=0;i<n;i++){
               if(a[s-1]!=0&&a[s-1]!=c){x=-1;break;}
               else a[s-1]=c;
           }
       }
       
   }
   if(x==-1) {cout<<x;return 0;}
   if(a[0]==0&&n!=1) {cout<<1;for(int i=1;i<n;i++) cout<<a[i];return 0;}
   for(int i=0;i<n;i++) cout<<a[i];
   
  return 0;
}


Measured memory_bytes: 256
n=int(input())
c=input()
i,j=0,n-1
ans=0
while True:
    if c[i]=="W":
        while True:
            if c[j]=="R":
                ans+=1
                j-=1
                break
            j-=1
            if i>=j:
                break
    i+=1
    if i>=j: break
print(ans)

Measured memory_bytes: 9476
N, M, Q = gets.split.map(&:to_i)

a=[]
b=[]
c=[]
d=[]
Q.times do |i|
  a[i], b[i], c[i], d[i] = gets.split.map(&:to_i)
end

# 配列.repeated_combination(n)で重複蟻の配列作れる
na = []
M.times do |i|
  na[i] = i+1
end
na = na.repeated_combination(N).to_a

ans = 0
point = 0
na.each do |s|
  point = 0
  Q.times do |j|
    if s[b[j]-1] - s[a[j]-1] == c[j]
      point += d[j]
    end
  end
  ans = [ans, point].max
end
puts ans

Measured memory_bytes: 27968
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    map<vector<int>, int> m;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        vector<int> k(26);
        for (char c : s) {
            k[c - 'a']++;
        }
        if (m.count(k)) {
            ans += m[k];
        }
        m[k]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 19072
from fractions import gcd
from functools import reduce

N, M, *A = map(int, open(0).read().split())

Y = reduce(lambda a, b: a * b // gcd(a, b), A)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print(M // (Y // 2) - (M // Y))

Measured memory_bytes: 16144
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
    
using namespace std;

typedef long long ll;

int main() {
    int n,m,c,b[21],a[21][21];
    cin>>n>>m>>c;
    for(int i=0;i<m;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) cin>>a[i][j];
    }
    
    ll ans=0;
    for(int i=0;i<n;i++){
        int d=c;
        for(int j=0;j<m;j++){
            d+=a[i][j]*b[j];
        }
        if(d>0) ans++;
    }
    cout<<ans<<endl;
}

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

int main(void)
{
    int i, j;
    int n, l;
    char tmp[101];

    scanf("%d %d", &n, &l);
    char S[110][110];

    for(i = 0; i < n; i++){
        scanf("%s", S[i]);
    }

    for(i = 1; i < n; i++){
        for(j = 1; j < n; j++){
            if(strcmp(S[j - 1], S[j]) > 0){
                strcpy(tmp, S[j - 1]);
                strcpy(S[j - 1], S[j]);
                strcpy(S[j], tmp);
            }
        }
    }

    for(i = 0; i < n; i++){
        printf("%s", S[i]);
    }



    return 0;
}

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

using namespace std;

int n[2];
int deck[2][55], decksum[2][55];
int dp[55][55][55][55][2][4];
bool used[55][55][55][55][2][4];

int solve(int lp, int rp, int lo, int ro, int t, int ps)
{
  int& ret = dp[lp][rp][lo][ro][t][ps];
  if(used[lp][rp][lo][ro][t][ps]) return ret;
  used[lp][rp][lo][ro][t][ps] = true;
  if(ps == 3) return ret = 0;
  // pass
  int score = (decksum[t][rp] - decksum[t][lp]) - (decksum[!t][ro] - decksum[!t][lo]);
  ret = -solve(ro, ro, rp, rp, !t, ps+1) + score;
  // put
  if(rp < n[t]) {
    if(deck[t][rp] == -1) ret = max(ret, -solve(ro, ro, lp, rp+1, !t, 0));
    else ret = max(ret, -solve(lo, ro, lp, rp+1, !t, 0));
  }

  return ret;
}

int main()
{
  cin >> n[0] >> n[1];
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < n[i]; j++) {
      cin >> deck[i][j];
      decksum[i][j+1] = decksum[i][j] + (~deck[i][j] ? deck[i][j] : 0);
    }
  }
  cout << solve(0, 0, 0, 0, 0, 0) << endl;
  return 0;
}

Measured memory_bytes: 110088
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e5+5;

void solve(){
	int n;
	cin>>n;
	vector<double>a(n);
	rep(i,n)cin>>a[i];
	while(sz(a)>1){
		sort(all(a));
		double x=a[0],y=a[1];
		vector<double>v;
		for(int i=2;i<sz(a);i++){
			v.pb(a[i]);
		}
		v.pb((x+y)/2.0);
		a.clear();
		for(auto i:v){
			a.pb(i);
		}
	}
	printf("%.6f",a[0]);
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)solve();
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    string H = "";

    rep(i,5) {
        H += "hi";
        if (S == H) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)] 
cd=[list(map(int, input().split())) for _ in range(n)] 

ab = sorted(ab, key=lambda x:x[1]*(-1))
cd=sorted(cd)

cnt=0
for i in range(n):#ab
    for j in range(len(cd)):#cd
        if ab[i][0]<cd[j][0] and ab[i][1]<cd[j][1]:
            cnt+=1
            cd.pop(j)
            break
print(cnt)

Measured memory_bytes: 38896