akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let mut s = sc.chars();
    let n = s.len();
    for i in 0..n {
        if s[i] == '?' {
            s[i] = 'D';
        }
    }

    for i in 0..n {
        print!("{}", s[i]);
    }

    println!();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

//     String nyu=sc.nextLine();
//int[] num=new int[6];
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu);
//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/


System.out.println(A*B-A-B+1) ;

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    ll ans=INF;
    rep(i, 110) {
        ll res=0;
        rep(j, n) {
            res += pow(x[j] - i, 2);
        }
        chmin(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
    return int(input())
def stin():
    return input()
def spin():
    return map(int,stin().split())
def lin():                           #takes array as input
    return list(map(int,stin().split()))
def matrix(n):
    #matrix input
    return [list(map(int,input().split()))for i in range(n)]

################################################
def calculate_sum(a, N): #sum of a to N
    # Number of multiples 
    m = N / a 
    # sum of first m natural numbers 
    sum = m * (m + 1) / 2
    # sum of multiples 
    ans = a * sum
    return ans
def series(N):
    return (N*(N+1))//2

def count2Dmatrix(i,list):
    return sum(c.count(i) for c in list)

def modinv(n,p):
    return pow(n,p-2,p)

def GCD(x, y): 
    x=abs(x)
    y=abs(y)
    if(min(x,y)==0):
        return max(x,y)
    while(y): 
        x, y = y, x % y 
    return x
def LCM (x, y):
    return (x * y) // GCD(x, y)
    
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l
def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
prime=[]
def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
q=[]       
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j
# d = {}
 
"""*******************************************************"""
n = inin()
a = lin()

a = sorted((a))

if len(a)<3:
    print(0)
    exit()

trio = []; c = 0

for i in range(0, len(a)):
    for j in range(0, len(a)):
        for k in range(0, len(a)):
            # m = max([a[i], a[j], a[k]])
            # s = sum([a[i], a[j], a[k]])
            if a[i]<a[j]<a[k]:
                if a[i]+a[j]>a[k]:
                    # trio.append([a[i], a[j], a[k]])
                    c += 1

print(c)
# print(len(trio))

Measured memory_bytes: 9316
#include<iostream>
#include<cstdio>

using namespace std;

int main(){

int n,k;
int i,j;
	while(cin>>n>>k){
		if(n==0 && k==0){break;}
	
	int s[100];
	int b[100][100];
		for(i=0;i<k;i++){
		cin>>s[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<k;j++){
				cin>>b[i][j];
			}
		} 
		for(i=1;i<n;i++){
			for(j=0;j<k;j++){
				b[0][j]+=b[i][j];
			}
		}
		bool futo=true;	
		for(j=0;j<k;j++){
			if(s[j]-b[0][j]>=0){
			}else{ 
				futo=false;
			}
			
		}
		if(futo)
			cout<<"Yes";
		else cout<<"No";
		cout<<endl;
	}

}

Measured memory_bytes: 1188
#include <stdio.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;

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


  int W, H, N;

  cin >> W >> H >> N;


  int u=0, d=H, l=0, r=W;
  rep(i, 0, N-1) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a==1) {
      l = max(l, x);
    }
    if (a==2) r = min(r, x);
    if (a==3) u=max(u, y);
    if (a==4) d=min(d, y);
  }

  if (u <= d && l <= r) cout << (d-u) * (r-l) << endl;
  else cout << 0 << endl;


}


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

using namespace std;

typedef long long ll;

ll f(ll a)
{
    if(a == 0) return 0;
    if(a == 1) return 1;
    if(a == 2) return 3;
    if(__builtin_popcountll(a) == 1) return a;
    if(__builtin_popcountll(a) == (64 - __builtin_clzll(a))) return 0;
    if(!(a % 2)) return (1LL << (64 - __builtin_clzll(a) - 1)) + f(a - (1LL << (64 - __builtin_clzll(a) - 1)));
    else return f(a - (1LL << (64 - __builtin_clzll(a) - 1)));
}

int main(void)
{
    ll a, b; cin >> a >> b;
    cout << (f(b) ^ f(a - 1));
    cout << "\n";
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2016-qual-a_c / Link: https://code-festival-2016-quala.contest.atcoder.jp/tasks/codefestival_2016_qualA_c?lang=en  ----- */
/* ------問題------

高橋君は、英小文字のみからなる文字列 s を持っています。 高橋君は s に対して、次の操作をちょうど K 回行います。
s から好きな位置の文字をひとつ選び、その文字を次のアルファベットへ変える。 ただし、z の次のアルファベットは a であるとする。
例えば、aaz の 2 文字目を選んで操作を行うと、aaz → abz となります。 続けて、abz の 3 文字目を選んで操作を行うと、abz → aba となります。
高橋君は、操作をちょうど K 回行った後の s を、辞書順でできるだけ小さくしたいと考えています。 操作をちょうど K 回行った後の s のうち、辞書順で最小のものを求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	string S; int K;
	cin >> S >> K;
	string ans;


	FOR(i, 0, SZ(S)) {
		if (S[i] == 'a')continue;
		int diff = 'z' - S[i] + 1;
		if (diff <= K) {
			S[i] = 'a';
			K -= diff;
		}
	}
	int diff = S[SZ(S)-1]-'a';
	if (K)K %= 26;
	diff += K;
	diff %= 26;
	S[SZ(S) - 1] = 'a'+ diff ;

	ans = S;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;

int h[100055],dp[100055];
const int inf=0x3f3f3f;

int main(){
    int n,k;
    memset(dp,inf,sizeof(dp));
    dp[0]=dp[1]=0;
    scanf("%d%d",&n,&k);
    h[0]=inf;
    for(int i=1;i<=n;++i)
        scanf("%d",h+i);
    for(int i=2;i<=n;++i){
        for(int j=1;j<=k&&i-j>0;++j){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

ll exponential(ll num, ll base){
    ll ret = 0;
    while(num > 0){
        ret += num%base;
        num /= base;
    }
    return ret;
}

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

    // 最小回数を全探索
    ll ans = n;
    // 6の冪乗円で引き出す金額をiと置き、9の冪上円て引き出す金額をn-iとする
    for(ll i=0; i<=n; i++){
        ll tmp = exponential(i, 6) + exponential(n-i, 9);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #define ll long long
 #define ii pair<int,int>
 #define endl '\n'
using namespace std;

void solve()
{ 
    int n;
    cin >> n;
    int a[10001]= {0,};
    for(int i=1; i<=100; i++)
        for(int j=1; j<=100; j++)
            for(int k=1; k<=100; k++)
            {
                int t =i*i + j*j + k*k + i*j + j*k + k*i;
                if(t<=10000)
                a[t]++;
                else
                    break;
            }
    for(int i=1; i<=n; i++)
    cout << a[i]<<endl;
}

int main(){
    std::ios_base::sync_with_stdio(false); 
    std::cin.tie(nullptr); std::cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 3668
import math 
N = int(input())
rootN = math.ceil(math.sqrt(N))
yakusuu = []
for i in range(1,rootN+1):
    if N % i == 0:
        yakusuu.append(i)

hitoketaFLG = 0
for j in yakusuu:
    if len(str(int(N / j))) == 1:
        hitoketaFLG = 1
print('Yes' if hitoketaFLG == 1 else 'No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<ll>().max()

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

	ll s = 0;
	ll f = 1;
	while (n > 0) {
		s += f;
		n /= 2;	
		f *= 2;
	}
	cout << s << endl;

}


Measured memory_bytes: 256
a = raw_input()
ans = 0
for i in range(len(a)):
  if a[i] == "0" and i != len(a) - 1:
    continue
  a1 = int(a[:i]) if i else 0
  a2 = int(a[i:])
  if a1 <= a2 and a1 % 2 == a2 % 2:
    ans += 1
print ans

Measured memory_bytes: 4212
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
from functools import reduce
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,a,b=mii()

if a%2 == b%2:
    print("Alice")
else:
    print("Borys")

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

using namespace std;

int n;
char str[300100];
int main() {
	scanf("%d%s",&n,str);

	int sum=0,ans=0;
	for(int i=0;i<n;i++) if(str[i]=='E') sum++;
	ans=sum;
	
	for(int i=0;i<n;i++) {
		if(str[i]=='E') sum--;
		ans=min(ans,sum);
		if(str[i]=='W') sum++;
	}
	printf("%d\n",ans);
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 1, max = h[0];
    rep(i,n-1) if(max <= h[i+1]){
        ans++;
        max = h[i+1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int a,b;cin>>a>>b;
  int sum=1,ans=0;
  while(sum<b)
  {
      sum+=a-1;
      ans++;
  }
  cout<<ans;
}
      


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


int main() {
	while (1) {
		int a, b;
		vector<int>nums(10000);
		while (1) {
			if (!(cin >> a >> b)) {
				return 0;
			}
			else {
				if (!a)break;
				nums[a - 1]++;
				nums[b - 1]++;
			}
		}
		bool ok = true;
		for (int i = 0; i < 2; ++i) {
			if (nums[i] % 2 == 0)ok = false;
		}
		for (int i = 2; i < 10000; ++i) {
			if (nums[i] % 2 == 1)ok = false;
		}
		if (ok)cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e17;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n, m;
    cin >> n >> m;
    vector<Int> a(m + 1, 0);
    for (Int i = 0; i < n; i++) {
        Int k;
        cin >> k;
        for (Int j = 0; j < k; j++) {
            Int x;
            cin >> x;
            a[x]++;
        }
    }
    Int res = 0;
    for (Int i = 1; i <= m; i++) {
        if (a[i] == n) res++;
    }
    dump(res);
    return 0;  
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  bool ok1 = false;
  // 1
  if (S[0] == 'A') {
    ok1 = true;
  }
  // 2
  bool ok2 = false;
  int ok2_index = 0;
  for (int i = 2; i <= S.length() - 2; i++) {
    // まだ一度もCが出てきてない時だけ受け入れることに注意
    if (!ok2 && S[i] == 'C') {
      ok2 = true;
      ok2_index = i;
    }
  }
  //3
  bool ok3 = true;
  for (int i = 1; i < S.length(); i++) {
    // 2でCがでてきたものはスキップする
    if (i == ok2_index) {
      continue;
    }
    else {
      // ひつでも大文字が来たらNG
      if (isupper(S[i])) {
        ok3 = false;
        break;
      }
    }
  }
  if (ok1 && ok2 && ok3) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b;
	ll k;
	//string s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	cin >> n;

	l_ans = 800 * n - 200 * (n / 15);

	cout << l_ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}

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

std::vector<int> graph[200005];
int N,M;
int main(){
  std::cin>>N>>M;
  for(int i=0;i<M;++i){
    int temp1,temp2;
    std::cin>>temp1>>temp2;
    graph[temp1-1].emplace_back(temp2-1);
    graph[temp2-1].emplace_back(temp1-1);
  }
  
  for(auto& gra:graph[0])
    for(auto& gra2:graph[gra])
      if(gra2==N-1){
        std::cout<<"POSSIBLE"<<std::endl;
        return 0;
      }
  
  std::cout<<"IMPOSSIBLE"<<std::endl;
  return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;    
    
    vector<vector<P>> G(n);  // 辺の重みがすべて0以上のグラフ
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(make_pair(b, 1));
    }
 
    ll sv, gv;
    cin >> sv >> gv;
    sv--;  gv--;
    
    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    vvl dp(n, vl(3, INF));  // dp[v][x] : 頂点svから頂点vへの3で割った余りがxとなる最短距離
    dp[sv][0] = 0;
    priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> prQ;
    prQ.push(make_pair(dp[sv][0], make_pair(sv, 0)));  // (頂点vまでの余りがxのときの距離, (いまいる頂点v, 余りx))
    while(!prQ.empty()) {
        auto p1 = prQ.top();
        prQ.pop();
        ll v = p1.second.first;
        ll x = p1.second.second;
        if(dp[v][x] < p1.first) {
            continue;
        }
        for(auto p2 : G[v]) {
            ll u = p2.first;
            ll cost = p2.second;
            ll nx = (x + cost)%3;
            if(dp[u][nx] > dp[v][x] + cost) {
                dp[u][nx] = dp[v][x] + cost;
                prQ.push(make_pair(dp[u][nx], make_pair(u, nx)));
            }
        }
    }
    
    if(dp[gv][0] == INF) {
        out(-1);
    }
    else {
        out(dp[gv][0]/3);
    }
 
    re0;
}

Measured memory_bytes: 11136
a, b = map(float, input().split())
lowest = max([-(-a // 0.08), -(-b // 0.1)])
highest = min([-(-(a+1) // 0.08), -(-(b+1) // 0.1)])
answer = -1
for target in range(int(lowest), int(highest+1)):
	cand = [(target*0.08)//1, (target*0.1)//1]
	if cand == [a, b]:
		answer = int(target)
		break
print(answer)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 数値
		int n1 = sc.nextInt();
		double d1 = 0.0;
		int n1list[] = new int[n1];
		for (int i = 1; i <= n1; i++) {
			int n2 = sc.nextInt();
			n1list[i - 1] = n2;
			d1 += (double) n2 / (double) n1;
		}

		// 開催場所
		int intd1 = (int) Math.round(d1);
		int score = 0;
		for (int i = 1; i <= n1; i++) {
			score += Math.pow(n1list[i - 1] - intd1, 2);
		}

		System.out.println(score);

	}
}


Measured memory_bytes: 23764
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = unsigned long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


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

int main(){
   int h, w;
   cin >> h >> w;
   vector<string> fld(h);
   rep(i, h)cin >> fld[i];
   bool all = true;
   rep(i, h)rep(j, w)if(fld[i][j] != '#')all = false;
   if(all){
      cout << 0 << endl;
      return 0;
   }
   vector<vector<int>> num(h, vector<int>(w, INF));


   rep(i, h){
      rep(j, w){
         if(fld[i][j] == '#')num[i][j] = 0;
         rep(d, 4){
            int ny = i + dy[d], nx = j + dx[d];
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(fld[ny][nx] == '#')num[i][j] = 1;
            else num[i][j] = min(num[i][j], num[ny][nx] + 1);
         }
      }
      for(int j = w - 1; j >= 0; j--){
         rep(d, 4){
            int ny = i + dy[d], nx = j + dx[d];
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(fld[ny][nx] == '#')num[i][j] = 1;
            else num[i][j] = min(num[i][j], num[ny][nx] + 1);
         }
      }
   }

   for(int i = h - 1; i >= 0; i--){
      rep(j, w){
         rep(d, 4){
            int ny = i + dy[d], nx = j + dx[d];
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(fld[ny][nx] == '#')num[i][j] = 1;
            else num[i][j] = min(num[i][j], num[ny][nx] + 1);
         }
      }
      for(int j = w - 1; j >= 0; j--){
         rep(d, 4){
            int ny = i + dy[d], nx = j + dx[d];
            if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
            if(fld[ny][nx] == '#')num[i][j] = 1;
            else num[i][j] = min(num[i][j], num[ny][nx] + 1);
         }
      }
   }

   int res = 0;
   rep(i, h){
      rep(j, w){
         //cout << num[i][j] << " ";
         res = max(res, num[i][j]);
      }
      //cout << endl;
   }
   cout << res << endl;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    string s1 = S.substr(0, N / 2);
    string s2 = S.substr(N / 2 + 1, N / 2);
    if (s1 == s2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <complex>
#include <algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

typedef complex<double> P;
const double EPS = 1e-8;
const double INF = 1e6;

double cross(P a,P b){
    return imag(conj(a)*b);
}


int main(){
    double x1, y1, x2, y2, x3, y3, xp, yp;
    while(cin >>x1>> y1>> x2>> y2>> x3>> y3>> xp>> yp){
        P v1=P(x1,y1),v2=P(x2,y2),v3=P(x3,y3),vp=P(xp,yp);
        if((cross(vp-v1,vp-v2)>0)&&(cross(vp-v2,vp-v3)>0)&&(cross(vp-v3,vp-v1)>0)){
            cout << "YES"<<endl;
        }else if((cross(vp-v1,vp-v2)<0)&&(cross(vp-v2,vp-v3)<0)&&(cross(vp-v3,vp-v1)<0)){
            cout << "YES"<<endl;
        }else{
            cout << "NO"<<endl;
        }

    }
}

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

int n;
int w;
int items_weight[102];
int items_value[102];
ll memo[102][100005];

ll dp(int idx, int total_weight){
    ll &res = memo[idx][total_weight];
    if(res != -1){
        return res;
    }
    if(idx == n){
        return res = 0;
    }
    res = dp(idx + 1, total_weight);
    if(total_weight + items_weight[idx] <= w){
        res = max(res, dp(idx + 1, total_weight + items_weight[idx]) + items_value[idx]);
    }
    return res;
}
int main(){
    memset(memo, -1, sizeof memo);
    scanf("%d%d", &n, &w);
    for(int i = 0; i < n ;i++){
        scanf("%d%d", &items_weight[i], &items_value[i]);
    }
    printf("%lld", dp(0, 0));
}


Measured memory_bytes: 83520
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

bool compare_second(pii a, pii b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<pii> islands(M);
    for (int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        islands[i] = make_pair(a, b);
    }
    sort(islands.begin(), islands.end(), compare_second);

    vector<int> bridges;
    for (int i=0; i<M; i++) {
        bool solved = false;
        int left, right;
        left = islands[i].first; right = islands[i].second;
        for (auto b: bridges) {
            if (left <= b && b < right) {
                solved = true;
                break;
            }
        }
        if (solved) continue;
        bridges.push_back(right-1);
    }
    cout << bridges.size() << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define N 305

using namespace std;
typedef pair<int,int> Pair;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }

template <class T> inline T	input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, m, ans = inf;
int a[N][N];
int cnt[N];
bool vis[N];

void calc() {
	memset(cnt, 0, sizeof cnt);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (vis[a[i][j]]) {
				++cnt[a[i][j]];
				break;
			}
}

int main() {
	read(n, m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			read(a[i][j]);

	for (int i = 1; i <= m; ++i) vis[i] = true;
	calc();

	for (int i = 1; i <= m; ++i) {
		int pos = max_element(cnt + 1, cnt + m + 1) - cnt;
		ans = min(ans, cnt[pos]);
		vis[pos] = false;
		calc();
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
import math
from decimal import Decimal

def main():
  
  a, b, c = list(map(int, input().split()))
  a2 = Decimal(a) ** Decimal(0.5)
  b2 = Decimal(b) ** Decimal(0.5)
  c2 = Decimal(c) ** Decimal(0.5)
  
  return 'Yes' if a2 + b2 < c2 else 'No'

print(main())


Measured memory_bytes: 5076
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

string s;
queue<int> q;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	if (s.back() != '0' || s[0] == '0' || s[s.size() - 2] == '0')
	{
		cout << -1;
		return 0;
	}
	
	for(int i=0; i<s.size()/2; i++)
	{
		if (s[i] != s[s.size() - 2 - i])
		{
			cout << -1;
			return 0;
		}
	}
	
	for(int i=0; i<s.size() - 1; i++)
	{
		if (s[i] == '1')
		{
			while(!q.empty())
			{
				cout << i + 1 << " " << q.front() << "\n";
				q.pop();
			}
		}
		
		q.push(i + 1);
	}
	while(!q.empty())
	{
		cout << s.size() << " " << q.front() << "\n";
		q.pop();
	}
	
	return 0;
}

Measured memory_bytes: 2000
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	x = x - a;
	a = x / b;
	x = x - (a * b);
	cout << x << endl;
} 

Measured memory_bytes: 3608
def bubbleSort(A, N):
    cnt = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                cnt = cnt + 1
    return cnt


N = int(input())
A = [int(i) for i in input().split()]
cnt = bubbleSort(A, N)
for i in range(len(A)):
    if i:
        print(" ", end = "")
    print(A[i], end = "")
print()
print(cnt)


Measured memory_bytes: 5632
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int card[20000],i,j,a=0,b=0,c=1,n;
cin>>n;
while(n!=0){
for(i=0;i<2*n;i++){
cin>>card[i];
}
for(i=0;i<2*n;i=i+2){
if(card[i]>card[c]){
a=a+card[i]+card[c];
}
else if (card[i]==card[c]){
a=a+card[i];
b=b+card[c];
}
else{
b=b+card[i]+card[c];
}
c=c+2;
}
cout<<a<<" "<<b<<endl;
c=1;
a=0;
b=0;
cin>>n;
}
return 0;
}

Measured memory_bytes: 1236
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;




int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ll h;
	ll res = 0;
	ll cnt = 1;
	cin >> h;
	while (h)
	{
		res += cnt;
		h /= 2;
		cnt *= 2;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int gcd(int a, int b) {
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%lld\n", (long long)a / gcd(a, b) * b);
}


Measured memory_bytes: 128
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length == 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function slove() {
    const sc = new Scanner();
    const S = (await sc.getLine()).split('/');
    if (Number(S[0]) > 2019) {
      console.log('TBD');
    } else {
      if (Number(S[1]) > 4) {
        console.log('TBD');
      } else if (Number(S[1]) === 4 && Number(S[2]) <= 30) {
        console.log('Heisei');
      } else {
        console.log('Heisei');
      }
    }
    sc.close();
  }

  slove();
}


Measured memory_bytes: 11596
# https://juppy.hatenablog.com/entry/2019/02/20/ARC64_-E_Cosmic_Rays-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder
# 写経

import sys

input = sys.stdin.readline

inf = float('inf')


# 単一始点最短路
def dijkstra(s):
    # 始点sから各頂点への最短距離
    d = [inf] * N
    used = [False] * N
    d[s] = 0
    while True:
        v = -1
        # まだ使われていない頂点の中から最小の距離のものを探す
        for i in range(N):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and (d[i] < d[v]):
                v = i
        if v == -1:
            break
        used[v] = True
        # 隣接頂点までの距離を更新する
        for j in range(N):
            d[j] = min(d[j], d[v] + cost[v][j])
    return d


xs, ys, xt, yt = map(int, input().split())
N = int(input())

p = list()
p.append((xs, ys, 0))
p.append((xt, yt, 0))
for _ in range(N):
    p.append(tuple(map(int, input().split())))  # (x,y,r)

cost = [[0] * (N + 2) for _ in range(N + 2)]
# cost[u][v] : 辺uvのコスト（存在しないときはinf）


for i in range(N + 2):
    for j in range(i, N + 2):
        cost[i][j] = cost[j][i] = max(
            ((p[i][0] - p[j][0]) ** 2 + (p[i][1] - p[j][1]) ** 2) ** 0.5 - p[i][2] - p[j][2], 0)

cost = tuple(cost)
N += 2

res = dijkstra(0)
print(res[1])


Measured memory_bytes: 24948
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main() {

	int a;
	int m = 1000, M = 0;
	for (int i = 0; i < 3; i++) {
		cin >> a;
		m = min(m, a);
		M = max(M, a);
	}
	cout << M - m << endl;





	return(0);
}

Measured memory_bytes: 256
mod = 998244353
N,K = map(int,input().split())

D = [list(map(int,input().split())) for _ in range(K)]
D.sort()

dp = [0]*N
dp[0] = 1
if D[0][0]<N:
    dp[D[0][0]] = 1

    for n in range(D[0][0],N-1):
        dp[n+1] = dp[n]
        for i in range(K):
            L,R = D[i]
            if n-L+1>=0:
                dp[n+1] += dp[n-L+1]
            if n-R+1>0:
                dp[n+1] -= dp[n-R]
            dp[n+1] %= mod
print(dp[N-1])

Measured memory_bytes: 69888
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
int main(){
    string s,t;
    map<char,char> mp;
    set<char> sti, sto;
    cin >> s >> t;
    int n = s.size();
    for(int i = 0; i < n; ++i){
        char c = s[i];
        if(sti.count(c) == 1){
            if(mp[c] != t[i]){
                puts("No");
                return 0;
            }
        }
        else{
            sti.insert(c);
            if(sto.count(t[i]) == 1){
                puts("No");
                return 0;
            }
            mp[c] = t[i];
            sto.insert(t[i]);
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 3928
words = lambda t : list(map(t, input().split()))
n,k = words(int)
a = words(int)

accum = [0] * n
adding = [0] * n

for i in range(n-1):
    for j in range(i,n):
        if a[i] > a[j]:
            adding[i] += 1

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            accum[i] += 1

MOD = 10**9 + 7
sum_accum = sum(accum)
sum_adding = sum(adding)
ans = 0

ans = (((k-1) * k) // 2) * sum_accum + k * sum_adding
ans %= MOD
'''
for i in range(k):
    ans += sum_accum * i + sum_adding
    ans %= MOD
'''
print(ans)


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

B = list(map(int, input().split()))
A = []
for index, b in enumerate(B):
    if(index == 0):
        A.append(b)

    if(index+1 < N-1):
        if(B[index+1] > B[index]):
            A.append(B[index])
        else:
            A.append(B[index+1])
    else:
        A.append(B[index])

print(sum(A))


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

using namespace std;

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

    unsigned long long a, b;
    cin >> a >> b;

    //a<b
    if(b<a) swap(a,b);

    unsigned long long gcd = a;

    while(a!=0){
        unsigned long long mod=b%a;
        if(mod==0)
            gcd = a;
        b=a;
        a=mod;
    }

    unsigned long long cnt = 1;

    for(unsigned long long x=2; x*x<=gcd; x++){
        if(gcd%x == 0){
            cnt++;

            while(gcd % x == 0)
                gcd /= x;
        }
    }

    if(gcd > 1)
        cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
def make_divisors(div, n):
    divisors = []
    mx = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if n // i >= div:
                mx = max(mx, i)
            if i != n // i:
                divisors.append(n//i)
                if i >= div:
                    mx = max(mx, n // i)
    return divisors, mx

n,m = map(int, input().split())
divisors, mx = make_divisors(n, m)
print(mx)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; string s; cin>>n>>s;
	stack<int> stk;
	int left=0, right=0;
	for (int i=0; i<n; i++) {
		if(s[i]=='(') stk.push('(');
		else {
			if(stk.empty()) left++;
			else stk.pop();
		}
	}
	while(!stk.empty())
		stk.pop();
	for (int i=n-1; i>=0; i--) {
		if(s[i]==')') stk.push(')');
		else {
			if(stk.empty()) right++;
			else stk.pop();
		}
	}
	cout<<string(left,'(')<<s<<string(right,')')<<"\n";
	return 0;
}

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

// input
int N, Y;


void input() {
    cin >> N >> Y;
}


int main() {
    input();
    rep(x, N + 1) rep(y, N + 1) {
        int s = Y - (10000 * x + 5000 * y);
        if (s < 0) continue;
        int z = s / 1000;
        if (x + y + z == N) {
            printf("%d %d %d\n", x, y, z);
            return 0;
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, P ;
    cin >> A >> P;
    int res = (A * 3 + P) / 2;
    cout << res << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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 main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,a,b;cin>>k>>a>>b;
    if((b-a)/2<2||a>k+1){
        cout << k+1 << endl;
        return 0;
    }else{
        ll remain = k;
        ll res = a;
        remain -= a-1;
        res += (b-a)*(remain/2);
        res += remain%2;
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
a = LI()

ANS = [0]*(10**5+1)
for i in range(N):
    b = a[i]
    if b == 0:
        ANS[b] += 1
        ANS[b+1] += 1
    else:
        ANS[b-1] += 1
        ANS[b] += 1
        ANS[b+1] += 1
print(max(ANS))


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

class Hello
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = (Console.ReadLine());
        var dest = s;
        Stack<char> stack = new Stack<char>(n);


        foreach (var c in s)
        {
            if (c == '(')
            {
                {
                    stack.Push(c);
                }
            }
            else
            {
                if (stack.Any())
                {
                    stack.Pop();
                }
                else
                {
                    dest = '(' + dest;
                }
            }
        }

        foreach (var item in stack)
        {
            dest += ')';
        }

        Console.WriteLine(dest);
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

void swap(int *a, int *b)
{
	int c;
	c = *a;
	*a = *b;
	*b = c;
}
int selectionsort(int a[], int N, int count)
{
	int mini;
	for (int i = 0; i < N; i++)
	{
		mini = i;
		for (int j = i; j < N; j++)
		{
			if (a[j] < a[mini])
			{
				mini = j;
			}
		}
		if (a[i] != a[mini])
		{
			swap(&a[i], &a[mini]);
			++count;
		}
		
	}
	return count;
}

void print(int a[], int N)
{
	for (int i = 0; i < N; i++)
	{
		printf("%d", a[i]);
		if (i != N - 1)
		{
			printf(" ");
		}
	}
	printf("\n");
}
int main()
{
	int count = 0;
	int a[100];
	int N;
	scanf("%d", &N);


	for (int i = 0; i < N; i++)
	{
		scanf("%d", &a[i]);
	}



	count = selectionsort(a, N, count);
	print(a, N);
	printf("%d\n", count);


	return 0;
}


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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int a,b;   
    cin>>a>>b;
    int ans=(a+b)/2;
    if((a+b)%2==0) cout<<ans<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, a, b, ans, sum, tmp;

	scanf("%d %d %d", &n, &a, &b);
	ans = 0;
	while (n)
	{
		sum = 0;
		tmp = n;
		while (tmp)
		{
			sum += tmp % 10;
			tmp /= 10;
		}
		if (a <= sum && sum <= b)
		{
			ans += n;
		}
		n--;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0;i<N;i++) {
        ll a;
        cin >> a;
        a--;  //0-index, town
        A.at(i) = a; //A[i] = town i から行ける街
    }
    vector<ll> loop;
    vector<ll> visit(N);
    for (ll i = 0;i<N;i++) visit.at(i) = 0;

    ll town = 0; //0start
    bool is_loop = false;
    vector<ll> before_loop;
    for (ll i = 0;i<N*2;i++) {
        //cout << town << endl;
        if (visit.at(town) == 1) {
            is_loop = true;
        }
        if (is_loop) {
            if (visit.at(town) == 2) break; //loop終了
            else {
                loop.push_back(town);
                visit.at(town) = 2;
                town = A.at(town); //次の町へ
            }
        }
        else {
            before_loop.push_back(town);
            visit.at(town) = 1;
            town = A.at(town);
        }
    }
    //for (ll i = 0;i<loop.size();i++) cout << before_loop.at(i) << endl;
    if (K < before_loop.size()) {
        cout << before_loop.at(K) + 1<< endl;
    }
    else {
        ll a = K - before_loop.size();
        cout << loop.at(a%loop.size()) + 1 << endl;
    }
}

Measured memory_bytes: 10860
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
d=sorted(lmp())
print(d[n//2]-d[n//2-1])

Measured memory_bytes: 16016
import math
ab=list(map(int, input().split()))
a=ab[0]
b=ab[1]
a0=12.5*a
a1=12.5*(a+1)
b0=10*b
b1=10*(b+1)
answer=0
if(a0>=b1):
    answer=-1
elif(a1<=b0):
    answer=-1
else:
    if(a0<b0):
        answer=math.ceil(b0)
    else:
        answer=math.ceil(a0)
print(int(answer))

Measured memory_bytes: 3188