akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    boolean[] exists1toi = new boolean[N + 1];
    Arrays.fill(exists1toi, false);
    boolean[] existsitoN = new boolean[N + 1];
    Arrays.fill(existsitoN, false);

    for (int i = 0; i < M; i++) {
      int a = scn.nextInt();
      int b = scn.nextInt();

      if (a == 1) {
        exists1toi[b] = true;
      }
      if (b == 1) {
        exists1toi[a] = true;
      }
      if (a == N) {
        existsitoN[b] = true;
      }
      if (b == N) {
        existsitoN[a] = true;
      }
    }

    boolean ans = false;
    for (int i = 1; i <= N; i++) {
      if (exists1toi[i] && existsitoN[i]) {
        ans = true;
      }

    }

    if (ans) {
      System.out.println("POSSIBLE");
    } else {
      System.out.println("IMPOSSIBLE");
    }

  }
}

Measured memory_bytes: 93588
n = int(input())

x = 7
ans = 1

#print(7%1)

for i in range(3*n):
  if x%n==0:
    break
  ans+=1
  x= x*10 + 7
  x=x%n
    
if ans < 3*n:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 62948
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

const int INF = 1001001001;

int main()
{
    int n;
    cin >> n;
    
    int sum[101][101] = {{}};
    rep(i, n) rep(j, n){
        int a;
        cin >> a;
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + a;
    }
    
    int ans = -INF;
    rep(t, n) reps(b, t, n) rep(l, n) reps(r, l, n){
        ans = max(ans, sum[b+1][r+1] - sum[b+1][l] - sum[t][r+1] + sum[t][l]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1208
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static int height = 0;
	static int weight = 0;

	public static void main(String[] args) throws Exception {
		boolean zeroFlag = true;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		while (zeroFlag) {
			String[] nyuryokuStr = line.split("[\\s]+");
			height = Integer.parseInt(nyuryokuStr[0]);
			weight = Integer.parseInt(nyuryokuStr[1]);
			if (height == 0 && weight == 0) {
				zeroFlag = false;
			} else {
				for (int h = 0; h < height; h++) {
					for (int w = 0; w < weight; w++) {
						if (((w % 2 == 0) && (h % 2 == 0))
								|| ((w % 2 == 1) && (h % 2 == 1))) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
				line = br.readLine();
			}
		}
	}
}

Measured memory_bytes: 33048
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int sum = a;
      int count = 1;

      if (b==1) {
        System.out.println(0);
        System.exit(0);
      }
      if (a==b) {
        System.out.println(1);
        System.exit(0);
      }

      for (int i = 1;sum<b ;i++ ) {
        sum = sum + a -1;
        count++;
      }
      System.out.println(count);
}
}


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

#define ll signed long long
ll x,y,a,b,c,d;
int main()
{
    scanf("%lld %lld %lld %lld",&a, &b, &c, &d);
    ll ans = max(a*c, b*c);
    ans = max(ans,a*d);
    ans = max(ans,b*d);
    cout << ans;
    return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long int x=0;
    for(long long int i=0;i<s.length();i++)
    {
        x+=(int(s[i])-48);
    }
    (x%9==0)?cout<<"Yes"<<endl:cout<<"No"<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void A(){
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
void B(){
    ll n,d;
    cin>>n>>d;
    int res=0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) res++;
    }
    cout<<res<<endl;
}
void C(){

}
void D(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    stack<int>st;
    for(int i=0;i<n;i++){
        if(s[i]=='R') st.push(i);
    }
    int l=0,r=n-1;
    int res=0;
    for(int i=0;i<n&&!st.empty();i++){
        if(i>=st.top()) break;
        if(s[i]=='W'){
            st.pop();
            res++;
        }
    }
    cout<<res<<endl;
}
void E(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n,0);
    ll ma=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ma=max(ma,a[i]);
    }
    if(k==0) {
        cout<<ma<<endl;
        return;
    }
    ll l=0,r=ma;//*1.0;
    ll ans=0;
    while(l<r){
        //cout<<l<<" "<<r<<endl;
        ll mid=l+(r-l)/2;
        if(mid==0) { 
            l=1;
            break;
        }
        ll cnt=0;
        for(ll i:a){
            cnt+=(i-1)/mid;
        }
        if(cnt<=k) {
            ans=mid;
            r=mid;
        }
        else l=mid+1;
    }
    cout<<l<<endl;
}
void F(){

}
void helper(){
    ll r=1;
    while(r<LONG_LONG_MAX/100){
        vector<ll> res;
        for(ll i=1;i*i<=r;i++){
            if(r%i==0){
                res.push_back(i);
                if(r/i!=i) res.push_back(r/i);
            }
        }
        sort(res.begin(),res.end());
        for(ll i:res) cout<<i<<" ";
        cout<<endl;
        r=r*10+1;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    helper();
    E();
    return 0;
}


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

S = '-' + input().rstrip()
N = len(S) - 1

def solve(S):
    if S[1] == '0':
        return None
    if S[N] == '1':
        return None
    prev = 1
    graph = []
    for n in range(1,N//2 + 1):
        if S[n] != S[N-n]:
            return None
        if S[n] == '0':
            continue
        for i in range(prev,n):
            graph.append((i,n))
        prev = n
    for i in range(prev,N):
        graph.append((i,N))
    return graph

graph = solve(S)

if graph is None:
    print(-1)
else:
    for x,y in graph:
        print(x,y)

Measured memory_bytes: 16592
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
/*
int main(){
  int n; cin >> n;
  for(int i = 1; i <= n; i++){
    int ans = 0;
    for(int x = 1; x <= sqrt(n); x++){
      for(int y = 1; y <= sqrt(n); y++){
        double d = (x+y)*(x+y)-4*(x*x+y*y+x*y-i);
        if(0 <= d){
          if(1 <= (-(x+y)+sqrt(d)/2.0)){
            if(-(x+y)+sqrt(d)/2.0 == floor(-(x+y)+sqrt(d)/2.0)) ans++;
          }
          if(1 <= (-(x+y)-sqrt(d)/2.0)){
            if(-(x+y)-sqrt(d)/2.0 == floor(-(x+y)-sqrt(d)/2.0)) ans++;
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
*/
int main(){
  int n; cin >> n;
  for(int i = 1; i <= n; i++){
    int ans = 0;
    for(int x = 1; x <= sqrt(n); x++){
      for(int y = 1; y <= sqrt(n); y++){
        for(int z = 1; x*x+y*y+z*z+x*y+y*z+z*x <= i; z++){
          if(x*x+y*y+z*z+x*y+y*z+z*x == i) ans++;
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 3480
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int A, B;
    cin >> A >> B;
    if (B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
rates = list(map(int, input().split(' ')))
pocket = 1000
kabu = 0

for i,rate in enumerate(rates):
  day = i+1
  if day == n:
    pocket += kabu*rate
    kabu = 0
    break
  if rate < rates[i+1]:
    #買えるだけ買う
    buy_kabu = pocket // rate
    pocket -= buy_kabu*rate
    kabu += buy_kabu
  elif rate > rates[i+1]:
    #売れるだけ売る
    pocket += kabu*rate
    kabu = 0

print(pocket)

Measured memory_bytes: 9120
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int x = 0;
		int max = 0;
		int n = scan.nextInt();
		String s = scan.next();
		String[] si = s.split("",0);
		for(int i=0; i<n; i++){
			if(si[i].equals("I")){
				x++;
			}
			else{x--;}
			if(x>max){max = x;}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21844
n=int(input())
for i in range(n):
    p=list(map(int,input().split(" ")))
    p.sort()
    a=p[0]
    b=p[1]
    c=p[2]
    if pow(a,2) + pow(b,2) == pow(c,2):
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 5600
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
D=list(map(int,input().split()))
D.sort();
for i in range(n-1,-1,-1):
    D.append(24-D[i])
# 各々が持つ変化の可能性は２通り
# 貪欲じゃあ無理


def solve_binary(mid):
    now=0; count=0
    used=[0]*(2*n)
    for i,di in enumerate(D):
        if not used[i] and now+mid<=di:
            now=di; count+=1
            used[i]=used[2*n-1-i]=1
    return count==n and now+mid<=24

def binary_search(n):
    ok=0
    ng=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid):
            ok=mid
        else:
            ng=mid
    return ok


print(binary_search(24))
# print(D)
# print(solve_binary(0))
# print(solve_binary(12))

Measured memory_bytes: 38384
#include <iostream>

typedef long long ll;

int N;

int main() {
  std::cin >> N;
  ll cur_h;  std::cin >> cur_h;
  ll ans = 0;
  for (int i = 1; i < N; ++i) {
    ll x;  std::cin >> x;
    ans += std::max(0LL, cur_h - x);
    cur_h = std::max(cur_h, x);
  }
  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3592
h,w = map(int,input().split(" "))
field = h*w
if (h*w) % 2 == 0:
  answer = (h*w)//2
else:
  answer = (h*w)//2 + 1
if h == 1:
  answer = 1
elif w == 1:
  answer = 1
print(answer)


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  while (cin >> s, s != "#") {
    reverse(begin(s), end(s));
    long long num = -1, den = 1 << 30;
    bool first = true;
    int n = 1;
    for (char c : s) {
      if (c != 'n' and c != 'w') {
        continue;
      }
      if (exchange(first, false)) {
        if (c == 'n') {
          num = 0;
        } else {
          num = 90 * den;
        }
        continue;
      }
      if (c == 'n') {
        num -= 90 * (den >> n);
        ++n;
      }
      if (c == 'w') {
        num += 90 * (den >> n);
        ++n;
      }
    }
    auto g = __gcd(num, den);
    num /= g, den /= g;
    cout << num;
    if (den > 1) {
      cout << '/' << den;
    }
    cout << '\n';
  }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

vector<int> G[1000];
vector<int> dist(1000);

void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<pii, int>> E(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        E[i] = {{a, b}, (int)G[a].size() - 1};
    }
    int k = INF;
    vector<int> ans;
    rep(i, m) {
        pii p;
        int idx;
        tie(p, idx) = E[i];
        int a, b;
        tie(a, b) = p;
        G[a].erase(G[a].begin() + idx);
        vector<int> prev(n, -1), cycle;
        queue<int> que;
        que.push(b);
        rep(j, 1000) dist[j] = INF;
        dist[b] = 0;
        while(!que.empty()) {
            int v = que.front();
            que.pop();
            for(auto nxt: G[v]) {
                if (chmin(dist[nxt], dist[v] + 1)) {
                    prev[nxt] = v;
                    que.push(nxt);
                }
            }
        }
        if (chmin(k, dist[a] + 1)) {
            int v = a;
            while(v != -1) {
                cycle.push_back(v);
                v = prev[v];
            }
            ans = cycle;
        }
        G[a].insert(G[a].begin() + idx, b);
    }
    if (k == INF) {
        cout << -1 << endl;
        return;
    }
    cout << k << endl;
    for(auto v : ans) {
        cout << v + 1 << endl;
    }
}

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



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x  first
#define y  second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(z,n)  for(int i=z;i<n;i++)

//pair<int,int> a[200002]={};
//ll b[200003]={};
ll n,m;
#define MAXNODES 200000+9
#define PB push_back
typedef vector<int> vi;
vector<vi> edges(MAXNODES);
bool visited[MAXNODES];
int dfs(int node)
{
    int ans=0;
	visited[node] = true;
	for(int neighbor: edges[node])
	{
	    if(!visited[neighbor])
        {
            ans++;
            ans+=dfs(neighbor);
        }
	}
	return ans;
}
//vector<set<int> >v(200002);
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
       cin>>n>>m;
       rep(0,m)
       {
           int u,v;
           cin>>u>>v;
            edges[u].PB(v);
            edges[v].PB(u);
       }
       ll ans=0;
       rep(1,n+1)
       {
           if(!visited[i])
            {
                ans=max(ans,(ll )dfs(i)+1);
            }
       }
       cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 23596
#include <iostream>
#include <vector>

using namespace std;



int main(){

  int x, n;

  cin >> x >> n;

  vector<int> P(102,0);

  for(int i = 0; i < n; i++){
    int t;
    cin >> t;
    P[t] = 1;
  }

  int a = 10000;
  int s = 10000;
  
  for(int i = 0; i <= 101; i++){
    int ab = abs(i - x);
    if(ab < a && P[i] == 0){
      s = i;
      a = ab;
    }
  }

  cout << s << endl;
  
  
  return 0;
  

  
}


Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        char N = sc.next().charAt(0);
        
	    p((char)((int)N+1));
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static <T> void pe(T element) {
        System.err.println(element);
        }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

int main()
{
  int N;
  ll *A,tmp;
  cin >> N;
  A = (ll*)malloc(sizeof(ll)*N);
  tmp = 0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    tmp = tmp +pow(-1,i)*A[i];
  }
  cout << tmp << " ";
  for(int i=0;i<N-1;i++){
    tmp = 2*A[i]-tmp;
    cout << tmp << " ";
  }
  return 0;
}


Measured memory_bytes: 2048
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: Chars,
        t: Chars,
    }

    if n.len() + 1 != t.len() {
        println!("No");
        return;
    }
    for i in 0..n.len() {
        if n[i] != t[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 2172
from itertools import accumulate
from bisect import bisect_left
from math import ceil

N,H = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = []
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)

# bを攻撃力の高い順に並べ替える
b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))
b_list_cum = [0] + b_list_cum
 
ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)

Measured memory_bytes: 28328
// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
void solve(){
    int n;
    cin>>n;
    n%=1000;
    cout << (n==0?0:1000-n)<< "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
} 

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
using namespace std;
struct Card {
	char suit;
	int val;
};
int partition(Card* arr, int left, int right) {
	int x = arr[right].val;
	int i, j;
	for (i = left - 1, j = left;j < right;j++) {
		if (arr[j].val <= x)
			swap(arr[++i], arr[j]);
	}
	swap(arr[++i], arr[right]);
	return i;
}
void quickSort(Card* arr, int left, int right) {
	if(left<right){
		int mid = partition(arr, left, right);
		quickSort(arr, left, mid-1);
		quickSort(arr, mid+1, right);
	}
}
void merge(Card* arr, int left, int mid, int right) {
	int len1 = mid - left + 1;
	int len2 = right - mid;
	Card* tempL = new Card[len1];
	Card* tempR = new Card[len2];
	for (int i = 0; i < len1; i++)tempL[i] = arr[left + i];
	for (int i = 0; i < len2; i++)tempR[i] = arr[mid + 1 + i];
	int i = 0, j = 0;
	for (int k = left; k <= right; k++) {
		if (i < len1 && (j >= len2 || tempL[i].val <= tempR[j].val))
			arr[k] = tempL[i++];
		else
			arr[k] = tempR[j++];
	}
}
void mergeSort(Card* arr, int left, int right) {
	int mid = (left + right) / 2;
	if (left < mid) {
		mergeSort(arr, left, mid);
		mergeSort(arr, mid+1, right);
	}
	merge(arr, left, mid, right);
}
int main() {
	int len;
	cin >> len;
	/*int* arr = new int[len];
	for (int i = 0;i < len;i++)
		cin >> arr[i];*/
	/*int p = partition(arr, 0, len - 1);
	for (int i = 0;i < len;i++) {
		if (i) {
			if (i != p)
				cout << " " << arr[i];
			else
				printf(" [%d]", arr[i]);
		}
		else
			if (i != p)
				cout << arr[i];
			else
				printf("[%d]", arr[i]);
	}
	cout << endl;*/
	Card* arr = new Card[len];
	Card* judge = new Card[len];
	for (int i = 0; i < len; i++) {
		cin >> arr[i].suit >> arr[i].val;
		judge[i] = arr[i];
	}
	quickSort(arr, 0, len - 1);
	mergeSort(judge, 0, len - 1);
	int isStable = 1;
	for (int i = 0; i < len; i++) {
		if (arr[i].suit != judge[i].suit) {
			cout << "Not stable\n";
			isStable = 0;
			break;
		}
	}
	if (isStable)
		cout << "Stable\n";
	for (int i = 0; i < len; i++)
		cout << arr[i].suit << " " << arr[i].val << endl;
	delete[]arr;
	return 0;
 }


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

using namespace std;
int main(){
	int d;
	cin>>d;
	if(d==22)cout<<"Christmas Eve Eve Eve";
	else if(d==23)cout<<"Christmas Eve Eve";
	else if(d==24)cout<<"Christmas Eve";
	else if(d==25)cout<<"Christmas";
	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[0][0] = 1;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty())
    {
        pair<int, int> v = q.front();
        q.pop();
        rep(i, 4)
        {
            pair<int, int> nv = make_pair(v.first + dy[i], v.second + dx[i]);
            if (nv.first < 0 || nv.first >= h || nv.second < 0 || nv.second >= w)
                continue;
            if (s[nv.first][nv.second] == '#')
                continue;
            if (dist[nv.first][nv.second] != -1)
                continue;
            q.push(nv);
            dist[nv.first][nv.second] = dist[v.first][v.second] + 1;
        }
    }
    int count = 0;
    rep(i, h) rep(j, w)
    {
        if (s[i][j] == '#')
            count++;
    }
    if (dist[h - 1][w - 1] == -1)
        cout << -1 << endl;
    else
        cout << h * w - count - dist[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;

  vector<int> a(N);
  for(int i=0;i<N;i++){
  cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  int x=a.size();
  
  cout<<x<<endl;


}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll ans = 9223372036854775807;
    rep(i, n - k + 1){
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
}

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

using namespace std;


int main(){
    int n;
    //cin >> n;
    scanf("%d",&n);
    int a[n + 1];
    int dp[n + 1];
    for(int i = 0; i < n; i++)     scanf("%d",&a[i]);
    /*
    dp[0] = a[0];
    dp[1] = a[0] + a[1];
    for(int i = 2; i <= n; i++){
        dp[i] = min(dp[i - 1] + a[i],dp[i - 2] + a[i]);
    }
    cout << dp[n - 1] << endl;
    */
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for(int i = 2; i <= n; i++){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]),dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    //cout << dp[n - 1] << endl;
    printf("%d\n",dp[n - 1]);
}

Measured memory_bytes: 1024
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

int A[N],B[N],C[N],id[N];
int X,Y,Z;
ll ans;

struct node{
	int val,i;
	bool operator < (const node &_) const{
		return val<_.val;
	}
};priority_queue<node> Qab,Qba,Qac,Qbc;

void gaoA(int i){
	id[i]=1;
	Qab.push((node){B[i]-A[i],i});
	Qac.push((node){C[i]-A[i],i});
}
void gaoB(int i){
	id[i]=2;
	Qba.push((node){A[i]-B[i],i});
	Qbc.push((node){C[i]-B[i],i});
}
void gaoC(int i){
	id[i]=3;
}
void gao(){
	while (id[Qab.top().i]!=1) Qab.pop();
	while (id[Qac.top().i]!=1) Qac.pop();
	while (id[Qba.top().i]!=2) Qba.pop();
	while (id[Qbc.top().i]!=2) Qbc.pop();
}

int main(){
	X=IN(),Y=IN(),Z=IN();
	For(i,1,X+Y+Z+1){
		A[i]=IN(),B[i]=IN(),C[i]=IN();
	}
	For(i,1,X+1){
		gaoA(i);
		ans+=A[i];
	}
	For(i,X+1,X+Y+1){
		ll mx=0;
		mx=max(mx,0ll+B[i]);
		mx=max(mx,0ll+Qab.top().val+A[i]);
		ans+=mx;
		if (B[i]==mx){
			gaoB(i);
		} else{
			gaoB(Qab.top().i);
			gaoA(i);
		}
		gao();
	}
	For(i,X+Y+1,X+Y+Z+1){
		ll mx=0;
		mx=max(mx,0ll+C[i]);
		mx=max(mx,0ll+Qac.top().val+A[i]);
		mx=max(mx,0ll+Qab.top().val+Qbc.top().val+A[i]);
		mx=max(mx,0ll+Qbc.top().val+B[i]);
		mx=max(mx,0ll+Qba.top().val+Qac.top().val+B[i]);
		ans+=mx;
		if (C[i]==mx){
			gaoC(i);
		} lf (0ll+Qac.top().val+A[i]==mx){
			gaoC(Qac.top().i);
			gaoA(i);
		} lf (0ll+Qab.top().val+Qbc.top().val+A[i]==mx){
			int u=Qab.top().i,v=Qbc.top().i;
			gaoA(i);
			gaoB(u);
			gaoC(v);
		} lf (0ll+Qbc.top().val+B[i]==mx){
			gaoC(Qbc.top().i);
			gaoB(i);
		} else{
			int u=Qba.top().i,v=Qac.top().i;
			gaoB(i);
			gaoA(u);
			gaoC(v);
		}
		gao();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4344
import java.util.*;
import java.io.*;

public class Main implements Runnable{
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException{
        new Thread(null, new Main(), "", 32 * 1024 * 1024).start();
        Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        out.flush();
    }

    public void run(){
        int[][] A = new int[3][3];
        boolean[][] check = new boolean[3][3];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                A[i][j] = Integer.parseInt(sc.next());
            }
        }
        int N = Integer.parseInt(sc.next());
        int[] b = new int[N];
        for(int i = 0; i < N; i++){
            b[i] = Integer.parseInt(sc.next());
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 3; k++){
                    if(A[j][k] == b[i]) check[j][k] = true;
                }
            }
        }
        if(check[0][0]&&check[0][1]&&check[0][2]){
            out.println("Yes");
        }else if(check[1][0]&&check[1][1]&&check[1][2]){
            out.println("Yes");
        }else if(check[2][0]&&check[2][1]&&check[2][2]){
            out.println("Yes");
        }else if(check[0][0]&&check[1][0]&&check[2][0]){
            out.println("Yes");
        }else if(check[0][1]&&check[1][1]&&check[2][1]){
            out.println("Yes");
        }else if(check[0][2]&&check[1][2]&&check[2][2]){
            out.println("Yes");
        }else if(check[0][0]&&check[1][1]&&check[2][2]){
            out.println("Yes");
        }else if(check[0][2]&&check[1][1]&&check[2][0]){
            out.println("Yes");
        }else{
            out.println("No");
        }
        out.flush();
    }

}

Measured memory_bytes: 27272
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int x[MAXN], sor[MAXN];
long long sum[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		read(x[i]);
		sum[i] = sum[i - 1] + x[i];
		sor[i] = sor[i - 1] ^ x[i];
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int l = i, r = n;
		while (l < r) {
			int mid = (l + r + 1) / 2;
			if ((sum[mid] - sum[i - 1]) == (sor[mid] ^ sor[i - 1])) l = mid;
			else r = mid - 1;
		}
		ans += l - i + 1;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int n;


int main(){
    int x[5];
    for(int i=0;i<5;i++) cin>>x[i];
    for(int i=0;i<5;i++){
        if(x[i]==0){
            cout<<i+1<<endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

const int N = 100001;
vector<int> graph[N];
int h[N];
int n, m;

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

    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int good = 0;
    for(int i = 1; i <= n; i++)
    {
        if(graph[i].size() == 0)
        {
            good++;
            continue;
        }
        bool ok = true;
        for(auto obs : graph[i])
        {
            if(h[obs] >= h[i])
                ok = false;
        }
        if(ok)
            good++;
    }

    cout << good;

    return 0;
}


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));
const int INF = 1e9;

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    //int ch_d = 1;
    //int cnt = 0;
    double start_temp = 50, end_temp = 10;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        // cnt++;
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 100;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        double temp = start_temp + (end_temp - start_temp) * (clock() / (double)CLOCKS_PER_SEC) / 2.0;
        double prob = exp((new_score - cur_score) / temp);
        if(prob > (rand() % INF) / (double)INF){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            // ch_d--;
            // if(ch_d == 0) ch_d = D;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}


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

void solve() {
    std::string s;
    std::cin >> s;
    for (int i = 0; i < (int)s.length(); i += 2) {
        if (s.substr(i, 2) != "hi") {
            std::cout << "No" << std::endl;
            return;
        }
    }
    std::cout << "Yes" << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 256
local s = io.read("n")
local i = 1
while true do
  if (s == 4 or s == 1 or s == 2) then
    print(i + 3)
    break
  end
  i = i + 1
  if (s % 2 == 0) then
    s = s // 2
  else
    s = s * 3 + 1
  end
end

Measured memory_bytes: 760
from math import sqrt

A, B = map(int, input().split())

def d(n):
    i = []
    while n % 2 == 0:
        i.append(2)
        n //= 2
        
    j = 3
    while j*j <= n:
        if n % j == 0:
            i.append(j)
            n //= j
        else:
            j += 2
            
    if n != 1:
        i.append(n)
    
    return i

print(len(set(d(A)) & set(d(B)))+1)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
long long n,m,poz[1000000+100],maxx,minx;
bool obidjen[1000000+100];
struct node
{
    long long l,r,d;
};
node a[1000000+100];
vector<pair<int,int>>v_l[1000000+100],v_r[1000000+100];
map<pair<int,int>,int>mapa;
void dfs(int x)
{
    obidjen[x] = 1;
    for (int i = 0;i<v_l[x].size();i++)
    {
        int y = v_l[x][i].first;
        if (obidjen[y])continue;
        obidjen[y] = 1;
        poz[y] = v_l[x][i].second+poz[x];
        maxx = max(maxx,poz[y]);
        minx = min(minx,poz[y]);
        dfs(y);
    }
    for (int i = 0;i<v_r[x].size();i++)
    {
        int y = v_r[x][i].first;
        if (obidjen[y])continue;
        obidjen[y] = 1;
        poz[y] = v_r[x][i].second+poz[x];
        maxx = max(maxx,poz[y]);
        minx = min(minx,poz[y]);
        dfs(y);
    }
}
int main()
{
    scanf("%lld %lld",&n,&m);
    for(long long i = 1;i<=m;i++)
    {
        scanf("%lld %lld %lld",&a[i].l,&a[i].r,&a[i].d);
        v_l[a[i].l].push_back({a[i].r,a[i].d});
        v_r[a[i].r].push_back({a[i].l,-a[i].d});
    }
    for (int i =1;i<=m;i++)
    {
        int p = a[i].l;
        minx = maxx = 0;
        if (!obidjen[p])poz[p] = 0,dfs(p);
        if (maxx-minx>1e9){cout<<"No"<<endl;return 0;}
    }
  //  for (int i = 1;i<=n;i++)cout<<poz[i]<<" ";cout<<endl;
    for (int i = 1;i<=m;i++)
    {
        int r = a[i].r;
        int l = a[i].l;
        int d = a[i].d;
        if (poz[r]-poz[l]!=d){cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 67584
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359

#define tMOD 998244353

ll kai(ll a,ll b){
  ll tmp=a;
  for(ll i=0;i<b-1;i++){
    tmp*=a%tMOD;
    tmp%=tMOD;
  }
  return tmp;
}


int main(){
  ll N;
  cin>>N;
  vector<ll> D(N+5);
  ll tmp;
    ll fff=0;
  cin>>tmp;
  if(tmp!=0){
   
    fff=1;
  }

  for(ll i=0;i<N-1;i++){
    cin>>tmp;
    if(tmp>N-1){
      fff=1;
    }
    D[tmp]++;
  }

    if(D[0]!=0||fff!=0){
    cout<<0<<endl;
    return 0;
  }
ll kk =0;
  for(ll i=1;i<N;i++){
 
    if(D[i]!=0){
       if(kk>0){
       kk=2;
       break;
      }
    }
    else{
       if(kk==0){
      kk++;
    }
  }
  }

    if(kk>=2){
    cout<<0<<endl;
    return 0;
  }


  ll ans =1;
 for(ll i=2;i<N+1;i++){
 
    if(D[i]!=0){
      ans = (ans*kai(D[i-1],D[i]))%tMOD;
  }


 }
 cout<<ans<<endl;

}


Measured memory_bytes: 1024
import itertools
N=int(input())
X=[str(i) for i in range(1,N+1)]
# X="1234"
s1="".join(input().split())
s2="".join(input().split())
perm=list(map("".join,itertools.permutations(X)))
print(abs(perm.index(s1)-perm.index(s2)))

Measured memory_bytes: 41840
def blackjack(A1, A2, A3):
    sum = A1 + A2 + A3
    if sum >= 22:
        return 'bust'
    elif sum <= 21:
        return 'win'


if __name__ == "__main__":
    A1, A2, A3 = map(int, input().split())
    print(blackjack(A1, A2, A3))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fatafat ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define MOD ((long long)(1e9)+7)
#define excl(i,a,b) for(int i=a;i<b;i++)
#define incl(i,a,b) for(int i=a;i<=b;i++)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define PII pair<int,int>

using namespace std;

int binexp(int a,int b)
{
    if(b)
    {
        if(b%2)
            return a*binexp(a*a,b/2);
        return binexp(a*a,b/2);
    }
    return 1;
}

int modexp(int a,int b,int m)
{
    if(b)
    {
        if(b%2)
            return (a*modexp((a*a)%m,b/2,m))%m;
        return modexp((a*a)%m,b/2,m);
    }
    return 1;
}

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

int euclidgcd,euclidx,euclidy;

void exteuclid(int a,int b)
{
    if(b==0)
    {
        euclidgcd=a;
        euclidx=1;
        euclidy=0;
    }
    else
    {
        exteuclid(b,a%b);
        int temp=euclidx;
        euclidx=euclidy;
        euclidy=temp-euclidy*(a/b);
    }
}

int modinv(int a,int m)
{
    exteuclid(a,m);
    return (euclidx%m + m)%m;
}

int pmodinv(int a,int m)
{
    return modexp(a,m-2,m);
}

bool checkprime(int a)
{
    for(int i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}

vector<bool> seive(int n)
{
    vector<bool> ret(n+1,true);
    ret[0]=ret[1]=false;
    for(int i=2;i*i<=n;i++)
        if(ret[i])
            for(int j=i*i;j<=n;j+=i)
                ret[j]=false;
    return ret;
}

vector<bool> seivelims(int l,int r)
{
    vector<bool> ret(r-l+1,true);
    for(int i=2;i*i<=r;i++)
    {
        for(int j=max(i*i,((l+i-1)/i)*i);j<=r;j+=i)
        {
            ret[j-l]=false;
        }
    }
    return ret;
}

vector<int> rootnfact(int n)
{
    vector<int> ret;
    for(long i=2;i*i<=n;i++)
        while(n%i==0)
        {
            ret.push_back(i);
            n/=i;
        }
    if(n!=1)
        ret.push_back(n);
    return ret;
}

vector<int> prelognfact(int n)
{
    vector<int> minprime(n+1,0);
    minprime[0]=minprime[1]=0;
    for(int i=2;i*i<=n;i++)
    {
        if(minprime[i]==0)
        {
            for(int j=i*i;j<=n;j+=i)
            {
                if(minprime[j]==0)
                    minprime[j]=i;
            }
        }
    }
    for(int i=2;i<=n;i++)
        if(minprime[i]==0)
            minprime[i]=i;
    return minprime;
}

vector<int> lognfact(int n,vector<int> minprime)
{
    vector<int> ret;
    while(n!=1)
    {
        ret.push_back(minprime[n]);
        n/=minprime[n];
    }
    return ret;
}

int temp,temp1,temp2;

signed main()
{
    fatafat;
    int n;
    cin>>n;
    double temp,sum=0;
    string s;
    while(n--)
    {
        cin>>temp>>s;
        if(s[0]=='J')
            sum+=temp;
        else
            sum+=(380000*temp);
    }
    cout<<fixed<<setprecision(10)<<sum;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[1000];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%d", &d[i]);
	int mini = 1000000000;
	for (int i = -100; i <= 100; i++)
	{
		int s = 0;
		for (int j = 0; j < num; j++)s += (d[j] - i)*(d[j] - i);
		mini = min(mini, s);
	}
	printf("%d\n", mini);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
#define INF 1e9
int a[50],b[50],c[50];
int dp[50][410][410];
signed main(){
    int n,m_a,m_b;
    cin>>n>>m_a>>m_b;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for (int i = 0; i < n; i++)
    {
    for (int j = 0; j < 410; j++)
    {
        for (int k = 0; k < 410; k++)
        {
           dp[i][j][k]=INF; 
        }
        
    }
    }
    for (int i = 0; i < n; i++)
    {
         dp[i][0][0]=0;
    }
    
   
    for (int i = 0; i < n; i++)
    {  // dp[i+1][a[i]][b[i]]=min(dp[i][a[i]][b[i]],c[i]);

         for (int j = 0; j <=400 ; j++)
        {
            for (int k = 0; k <= 400; k++)
            {
                dp[i+1][j][k]=dp[i][j][k];

            }
        }
        for (int j = 0; j <=400 ; j++)
        {
            for (int k = 0; k <= 400; k++)
            {
             //if(j== 0 && k==0 ) continue;
             if(dp[i][j][k]!=INF)
             dp[i+1][j+a[i]][k+b[i]]= min(dp[i][j][k]+c[i],dp[i][j+a[i]][k+b[i]]);

            }
        }
    }
    int min_ans=INF;
    for (int j = 0; j <= 400; j++)
    {
        for (int k = 0; k <= 400; k++)
        {
            if(j==0 && k==0) continue;
          //  cerr<<j<<" "<<k<<" "<<dp[n][j][k]<<endl;
            if(j*m_b-k*m_a==0 && dp[n][j][k]!=INF){
                if(dp[n][j][k]<min_ans)
                min_ans=dp[n][j][k];
            }
        }
    }
    if(min_ans!=INF)
    cout<<min_ans<<endl;
    else cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 55552
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        cs:  chars,
    }

    let ans = dfs(&cs, 0, 0, cs.len());

    println!("{}", ans);
}

fn dfs(cs: &Vec<char>, pos: usize, memo: usize, len: usize) -> usize {

    if pos == len-1 {
        let mut tmp = String::new();
        for i in 0..len {
            let mask = 2usize.pow(i as u32);    
            tmp.push(cs[i]);
            if memo & mask != 0 {
                tmp.push('+');
            }
        }
        let v: Vec<&str> = tmp.split_terminator('+').collect();
        let m: Vec<usize> = v.into_iter().map(|x| x.parse().unwrap()).collect();
        return m.iter().sum();
    }

    dfs(&cs, pos+1, memo, len) + dfs(&cs, pos+1, memo + 2usize.pow(pos as u32), len)
}

Measured memory_bytes: 4352
out = []
while True:
  n = int(raw_input())
  if n == 0: break
  trans = {}
  for i in range(n):
    k,v = raw_input().split()
    trans[k] = v.rstrip()
  cnt = int(raw_input())
  res = ""
  for j in range(cnt):
    a = raw_input().rstrip()
    if a in trans: a = trans[a]
    res += a
  out.append(res)
for o in out: print o

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

int main()
{
	int a;
	cin >> a;
	for (int i = 1; i < 10; ++i) {
		if ((a / i) < 10 && a % i == 0) {
			cout << "Yes";
			return 0;
		} 
	}
	cout << "No";
}



Measured memory_bytes: 256