akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int ctoi(char c){
    return c - 'a';
}
int main(){
    string S; cin >> S;
    vector<ll> cntAplha(26,0);
    ll ans = 0;
    for(auto& c: S){
        cntAplha[ctoi(c)]++;
    }
    ll L = S.size();
    ans = L*(L-1)/2;
    for(ll& num:cntAplha){
        ans -= num*(num-1)/2;
    }
    cout << ans+1 << endl;
    sysp;
}

Measured memory_bytes: 3760
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;




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

	int N, K, sum = 0;
	cin >> N;
	VI A(N), d(N);
	bool F = true;
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	if (sum % (N*(N + 1) / 2) != 0)F = false;
	K = sum / (N*(N + 1) / 2);



	REP(i, N) {
		if (i == N - 1) {
			d[i] = A[0] - A[i];
		}
		else {
			d[i] = A[i + 1] - A[i];
		}
	}
	REP(i, N) {
		if (K < d[i])F = false;
		if ((K - d[i]) % N != 0)F = false;
	}

	cout << (F ? "YES" : "NO") << endl;







	return 0;
}



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

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a%b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    long long i, j, k, n, m, t, x, y, z, s=0, c=0, l;
    cin >> x >> y;
    if(x%500<=y)
        cout << "Yes\n";
    else 
        cout << "No\n";
}


Measured memory_bytes: 3656
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    int count=0,index=1;
    for(i=0;i<n;i++){
        if(a[i]==index){
            index++;
        }
        else count++;
    }
    if(count==n)
    printf("-1\n");
    else 
    printf("%d\n",count);
}

Measured memory_bytes: 896
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int t = scan.nextInt();

		int[] arr = new int[t];
		for(int i = 0; i < t; i++) {
			arr[i] = scan.nextInt();
		}

		Arrays.sort(arr);

		int max = arr[arr.length-1];
		int sum = 0;
		for(int i = 0; i < t-1; i++) {
			sum += arr[i];
		}

		int result = max-sum-1;

		System.out.println((result>0)?result:0);
	}
}


Measured memory_bytes: 9740
#include <bits/stdc++.h>
using namespace std;
typedef char status;
status steps(status x){
	return ((x<<1)|(x>>2))&0x7;
}

const int maxn=1e5+9;
vector <int> Edge[maxn];
int S,T;
void init(){
	int n,m;scanf("%d%d",&n,&m);
	while(m--){
		int u,v;scanf("%d%d",&u,&v);
		Edge[u].push_back(v);
	}
	scanf("%d%d",&S,&T);
}


bool vis[maxn][8];
struct node{
	int v;
	status x;
	int step;
	node(){}
	node(int _v,status _x,int _step){
		v=_v;
		x=_x;
		step=_step;
	}
};
void solve(){
	queue <node> q;
	node c,d;
	q.push(node(S,1,0));vis[S][1]=1;
	while(!q.empty()){
		c=q.front();q.pop();
		d.x=steps(c.x);
		d.step=c.step+1;
		for(int v:Edge[c.v]){
			if(v==T&&(d.x&1>0)){//found answer
				printf("%d",d.step/3);
				return ;
			}
			if(vis[v][d.x])continue;
			vis[v][d.x]=true;
			d.v=v;
			q.push(d);
		}
	}
	printf("-1");
}
int main(){
	init();
	solve();
    return 0;
}

Measured memory_bytes: 6528
from collections import deque
import collections
import math
"""
#n = int(input())
#A = [int(i) for i in input().split()]
n = 10**5
A = [int(i)+1 for i in range(10**5,0,-1)]
A.sort()
ans = 0
ans_list = []
kaburi = {}
for i in A:
    Flag = True
    for j in ans_list:
        if i==j:
            kaburi[i]=True
            Flag = False
            break
        if i%j==0:
            Flag = False
            break
    if Flag:
        ans_list.append(i)
        ans += 1
print(ans-len(kaburi))
"""


n = int(input())
A = [int(i) for i in input().split()]
A.sort()
Max = max(A)
cnt_dict = collections.Counter(A)
#Dict[i]はi未満の約数がAに存在しなければTrue
Dict = {a:True for a in A}
for a in A:
    times = 2
    while a*times<=Max:
        Dict[a*times]=False
        times +=1
ans = 0
for a in A:
    if cnt_dict[a]==1 and Dict[a]:
        ans +=1
print(ans)


Measured memory_bytes: 105056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, ans;
int main(){
	scanf("%d", &n);
	for(; n; n/=10) if(n%10 == 2) ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>
  
#define AMAX 20
#define MMAX 200
 
int A[AMAX+1];
int n, q;

int solve_loop( int p, int t, int res )
{
	return  ( n < p ) ? res: solve_loop( p+1, t-A[p], res=!t&&!res?1:0  ) || solve_loop( p+1, t, res=!t&&!res?1:0 );
}
int solve( int p, int t )
{
	return  solve_loop( p, t, 0 );
}
 
int main( void ) 
{
    int i;
    int num;
     
    scanf( "%d", &n );  
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
    }   
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( solve( 0, num ) ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define iiUS unordered_set<ii>
#define ST stack<int>
#define MS multiset<int>
#define scan1(n) cin>>n
#define scan2(a,b) cin>>a>>b
#define scan3(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define vi vector<int>
#define vii vector<ii>
#define viii vector<iii>
#define fi first
#define se second
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,s,e) for(int i=s;i<e;++i)
#define REPS(i,s,e,st) for(int i=s;i<e;i+=st)
#define rep(i,n) for(int i=n-1;i>=0;--i)
#define repr(i,s,e) for(int i=s;i>=e;--i)
#define reps(i,s,e,st) for(int i=s;i>=e;i-=st)
#define SET(arr,k) memset(arr,k,sizeof arr)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define mp make_pair
#define pb push_back
#define Qu queue
#define Vt vector
#define Dq deque
#define prints(n) cout << n << " ";

void m1(){
  int n; cin >> n;
  map<string,int> m;
  m["AC"] = 0;
  m["WA"] = 1;
  m["TLE"] = 2;
  m["RE"] = 3;
  string s; int ans[] = {0,0,0,0};
  REP(i,n){
  	cin >> s;
    ++ans[m[s]];
  }
  cout << "AC x " << ans[0] << "\n";
  cout << "WA x " << ans[1] << "\n";
  cout << "TLE x " << ans[2] << "\n";
  cout << "RE x " << ans[3];
}
/* 
void m2(){
  int t; scan1(t);
  while(t--) m1();
}
*/
 
signed main(){
  speed;
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}

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

int main()
{
	//????¨???????
	int num1=0,num2=0,num3=0,num4=0,num5=0,num6=0,num7=0;
	cin>>num1>>num2>>num3>>num4;
	num5=num1+num2+num3+num4;
	num6=num5/60;
	num7=num5%60;
	cout<<num6;
	cout<<"\n";
	cout<<num7;
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 1164
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func b2i(b bool) int8 {
	if b {
		return 1
	}
	return 0
}

var (
	dp = make([]int, 3e5 + 1)
)

func solve(io *Io) {
	n := io.NextInt()
	s := io.Next()

	for i, c := range s {
		dp[i+1] = dp[i] + int(b2i(c == 'E'))
	}

	ans := n
	for i := 0; i < n; i++ {
		l := i - dp[i]
		r := dp[n] - dp[i+1]
		cur := l + r
		ans = intMin(ans, cur)
	}

	io.PrintLn(ans)
}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}

Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

set<int> used;
int res = 0;
int func(int x){
    res++;
    if(used.find(x)!=used.end()) return x;
    used.insert(x);
    return x%2==0 ? func(x = x/2) : func(3*x+1);
}
int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int s;
    cin >> s;
    func(s);
    cout << res << endl;
}


Measured memory_bytes: 256
def count_divisors(n):
    count = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            count += 1
            if i != n // i:
                count += 1
    return count
def main():
    n = int(input())
    ans = 0
    for i in range(1, n + 1, 2):
        if count_divisors(i) == 8:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    int D, X;
    cin >> D >> X;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll sum = X;
    for(int i = 0; i < N; i++){
        for(int j = 0;;j++){
            if(j * A[i] + 1 > D) break;
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int x,y,t=1;
	scanf("%d",&x);
	char a[x+1];
	scanf("%s",a);
	if(x%2==1){
		puts("No");
	}
	else{
		int t=1;
		for(int i=0;i<x/2;i++){
			if(a[i]!=a[i+x/2]){
				t-=1;
			}
		}
		if(t==0){
		puts("No");	
		}
		if(t==1){
		puts("Yes");
	}
}

	return 0;
}
	

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef long long ll;

void solve() {
  string S;
  cin >> S;
  string rev = S;
  int N = S.size(), ans = 0;
  for (int i = 0; i < N / 2; i++) {
    if (S[i] != rev[N - i - 1]) ans++;
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
/*ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}
ll modInverse(ll a, ll m)
{
    ll g = gcd(a, m);
    return(power(a,m-2,m));
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
bool isprime(ll x)
{
    if(x==1)
        return(false);
    for(ll i=2;i*i<=x;i++)
    {
        if(x%i==0)
            return(false);
    }
    return(true);
}
void solve()
{
    ll n,k;
    cin>>n>>k;
    bool vis[n+1]={false};
    for(ll i=0;i<k;i++)
    {
        ll d,c;
        cin>>d;
        for(ll j=0;j<d;j++)
        {
            cin>>c;
            vis[c]=true;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(vis[i]==false)
            ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 3644
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		//complete the following
		for (int i = 0; i < adjMatrix.length; i++) {
		    for (int j = 0; j < adjMatrix[i].length; j++) {
		        LinkedList<Integer> edges = adjList.get(i);
		        if(edges.contains(j)) {
		        	adjMatrix[i][j] = 1;
		        }
		        else {
		        	adjMatrix[i][j] = 0;
		        }
		    }
		}
		
		
		for (int i = 0; i < adjMatrix.length; i++) {
		    for (int j = 0; j < adjMatrix[i].length; j++) {
		    	if(j == adjMatrix[i].length - 1) {
		    		System.out.print(adjMatrix[i][j]);
		    	}
		    	else {
		        System.out.print(adjMatrix[i][j] + " ");
		    	}
		    }
		    System.out.println();
		}
	}
}

public class Main {

	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}

}



Measured memory_bytes: 35320
#include <cstdio>
#include <array>
using namespace std;

typedef array<int, 10001> v;

static inline int in()
{
    int c, n = 0;
    while ((c = getchar_unlocked()) >= '0' && c <= '9')
		n = 10 * n + (c - '0');
    return n;
}

static inline void out(int n)
{
	static char buf[20];
	char *p = buf;
	if (!n)
		*p++ = '0';
	else
		while (n)
			*p++ = n % 10 + '0', n /= 10;
	while (p-- != buf)
		putchar_unlocked(*p);
}

int main()
{
	int n = in(), c = n;

	v b = {};

	while (n--)
		b[in()]++;

	for (int i = 0; c; i++)
		while (b[i]--) {
			out(i);
			if (--c) putchar_unlocked(' ');
		}
	puts("");
}



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

using namespace std;

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

	vector<vector<int>> mat(n + 1);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		mat[u].push_back(v);
		mat[v].push_back(u);
	}

	vector<int> o;
	o.push_back(1);

	vector<int> visited(n + 1);
	visited[1] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < mat[o[i]].size(); j++) {
			int p = mat[o[i]][j];
			if (!visited[p]) {
				visited[p] = o[i];
				o.push_back(p);
			}
		}
	}

	if (o.size() == n) {
		cout << "Yes" << endl;
		for (int i = 2; i <= n; i++) {
			cout << visited[i] << endl;
		}
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 10688
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<n1<<"\n"
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=1;
    rep (i,0,n-1)
    {
        if (s[i]!=s[i+1])
        {
            ans++;
        }
    }
    cout<<ans<<"\n";
}


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

int main(){
  int strlength;
  bool flag=true;
  string S;
  cin >> S;
  strlength = S.length();
  for(int i=0;i<(strlength+1)/2;i++){
    if(S[i] != S[strlength-i-1]){
      flag = false;
      break;
    }
  }
  for(int i=0;i<((strlength-1)/2+1)/2;i++){
    if(S[i] != S[(strlength-1)/2-i-1]){
      flag = false;
      break;
    }
  }
  for(int i=(strlength+3)/2-1;i<((strlength+3)/2+strlength)/2;i++){
    if(S[i] != S[strlength-i-1]){
      flag = false;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "algorithm"
 
using namespace std;
 
int main()
{
  int n, m;
  cin >> n >> m;
  int p[100100], y[100100];
  for (int i = 0; i < m; i++)
  {
    cin >> p[i] >> y[i];
  }
  vector<int> yd[100100];
  for (int i = 0; i < m; i++)
  {
    yd[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < n + 1; i++)
  {
    sort(yd[i].begin(), yd[i].end());
  }
  for (int i = 0; i < m; i++)
  {
    int ans_first = p[i];
    int ans_second = lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin() + 1;
    printf("%06d", ans_first);
    printf("%06d", ans_second);
    cout << '\n';
  }
}

Measured memory_bytes: 7808
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
  let r: f64 = read();
  
  println!("{}", 2.0 * r * std::f64::consts::PI);
}

Measured memory_bytes: 2192
N,A,B,C=map(int,input().split())
mod=10**9+7

#factorial,facotiralの逆数を事前計算.
#N=10**5あたりまで有効

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()
    
 
def Combi(N,K):
    return FACT[N]*FACT_INV[N-K]*FACT_INV[K]%mod


ANS=0
SUM=A+B
A_n=pow(A,N,mod)*pow(pow(SUM,mod-2,mod),N,mod)%mod
B_n=pow(B,N,mod)*pow(pow(SUM,mod-2,mod),N,mod)%mod
SUMINV=pow(SUM,mod-2,mod)

for i in range(N):
    ANS=(ANS+(A_n*pow(B,i,mod)+B_n*pow(A,i,mod))*Combi(N-1+i,i)*pow(SUMINV,i,mod)*(N+i))%mod

print(ANS*100*pow(100-C,mod-2,mod)%mod)

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

const int B = 1e9+7, H = 1e9+9;
//Hash(C) = (C1*B^(n-1)+...+Cn*B^0) mod H
//aはbに含まれているか
int contain(string a,string b){
  if(a.size() > b.size()) return false;

  int t = 1,ah = 0,bh = 0;
  for(int i = 0; i < a.size(); i++) ah = ah*B + a[i],t *= B;
  for(int i = 0; i < a.size(); i++) bh = bh*B + b[i];

  int cnt = 0;
  for(int i = a.size(); i <= b.size(); i++){
    if(ah == bh) cnt++,cout << i-a.size() << endl;
    if(i >= b.size()) break;
    bh = bh*B + b[i] - b[i-a.size()]*t;
  }
  return cnt;
}

signed main(){

  string s,t; cin >> s >> t;
  contain(t,s);

  return 0;
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1245678912346
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_VAL 0


signed main(){
	int N, l, K, ans = 0;
	vector<int> L;
	cin>>N>>K;
	rep(i,N){
		cin>>l;
		L.push_back(l);
	}
	sort(L.begin(),L.end());
	
	for(int i = 1; i <= K; i++){
		ans += L[N-i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

cnt = 0
sw = 0
while sw == 0:
  for i in range(n):
    if l[i] % 2 == 0:
      l[i] = l[i]/2
    
    else:
      print(cnt)
      sw += 1
      break
  
  cnt += 1

Measured memory_bytes: 3060
type SortDataType=Longint;
function SortCmp(const a,b:SortDataType):Boolean;forward;
procedure SortImpl(var A:Array of SortDataType;L,R:Longint);
var
	tmp:SortDataType;
	mid,il,ir:Longint;
begin
	if R-L<20 then begin
		for ir:=R-1 downto L+1 do for il:=L to ir-1 do if SortCmp(A[il+1],A[il])then begin
			tmp:=A[il];
			A[il]:=A[il+1];
			A[il+1]:=tmp;
		end;
	end else begin
		mid:=(L+R)div 2;
		if SortCmp(A[mid],A[L])then begin
			tmp:=A[mid];
			A[mid]:=A[L];
			A[L]:=tmp;
		end;
		if SortCmp(A[R-1],A[mid])then begin
			tmp:=A[R-1];
			A[R-1]:=A[mid];
			A[mid]:=tmp;
			if SortCmp(A[mid],A[L])then begin
				tmp:=A[mid];
				A[mid]:=A[L];
				A[L]:=tmp;
			end;
		end;
		il:=L;
		ir:=R-1;
		while il<=ir do begin
			while SortCmp(A[il],A[mid])do inc(il);
			while SortCmp(A[mid],A[ir])do dec(ir);
			if il<ir then begin
				tmp:=A[il];
				A[il]:=A[ir];
				A[ir]:=tmp;
				if mid=il then mid:=ir else if mid=ir then mid:=il;
				inc(il);
				dec(ir);
			end else if il=ir then begin
				inc(il);
				dec(ir);
			end;
		end;
		SortImpl(A,L,il);
		SortImpl(A,il,R);
	end;
end;
procedure Sort(var A:Array of SortDataType;size:Longint);
begin
	SortImpl(A,0,size);
end;
function SortCmp(const a,b:SortDataType):Boolean;
begin
	SortCmp:=a>b;
end;
var
	N,K,i:Longint;
	H:Array[1..200000]of Longint;
	ans:int64;
begin
	read(N,K);
	for i:=1 to N do read(H[i]);
	Sort(H,N);
	for i:=K+1 to N do inc(ans,H[i]);
	writeln(ans);
end.


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

int main(void) {
	int N;
	cin >> N;
	bool approved = true;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if ((A%2)==0) {
			if ((A%5==0) || (A%3==0)) {
				;
			} else {
				approved = false;
			}
		}
	}
	if (approved) {
		cout << "APPROVED" << endl;
	} else {
		cout << "DENIED" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
struct custom {
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=(y>>1);
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j,k,w,s=0,c;
    cin>>n>>w;
    ll arr[n+1][2];
    for(i=1;i<=n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
        s=s+arr[i][1];
    }
    ll dp[s+1][n+1];
    for(i=0;i<=n;i++)dp[0][i]=0;
    for(i=1;i<=s;i++)dp[i][0]=inf;
    c=0;
    for(i=1;i<=s;i++)
    {
        for(j=1;j<=n;j++)
        {
            dp[i][j]=dp[i][j-1];
            if(i-arr[j][1]>=0)
                dp[i][j]=min(dp[i][j-1],dp[i-arr[j][1]][j-1]+arr[j][0]);
        }
        if(dp[i][n]<=w)c=max(c,i);
    }
    cout<<c<<endl;
}


Measured memory_bytes: 79104
import sys

def convert(x):
    return 1 if x == 'H' else 0

a, b = sys.stdin.readline().split()
a = convert(a)
b = convert(b)

def main():
    ans = 'D' if a ^ b else 'H'
    print(ans)
    
if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    string ans = a == b && b == c && c == a ? "No" : "Yes"; 
  	if(a != b && b != c && c != a) ans = "No";
    cout << ans<< endl;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = input()
ans = ''
for t in s:
    st = ord(t) + n
    if(st > ord('Z')):
        st = ord('A') + st - ord('Z') - 1
    ans = ''.join([ans, chr(st)])
print(ans)



Measured memory_bytes: 70088
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String number = scanner.next();
        int n = Integer.parseInt(number);
        ArrayList<Integer> aveList = new ArrayList<Integer>();

        while (n != 0) {
            ArrayList<Integer> numList = new ArrayList<Integer>();
            int sum = 0;
            String input;
            int num;
            for (int i = 1; i <= n; i++) {
                input = scanner.next();
                num = Integer.parseInt(input);
                numList.add(num);
                sum += num;
            }

            // 最大値、最小値を求める
            Integer max = Collections.max(numList);
            Integer min = Collections.min(numList);

            sum = sum - max - min;

            int ave = sum / (numList.size() - 2);
//            System.out.println(ave);

            aveList.add(ave);

            number = scanner.next();
            n = Integer.parseInt(number);
        }

        for(Integer value : aveList)
        {
            System.out.println(value);
        }
        }

}



Measured memory_bytes: 29048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 100000000000000;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int nCr(int n, int r) {
	int ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
bool is_even(ll x) { return x % 2 == 0 ? 1 : 0; }
bool is_odd(ll x) { return x % 2 == 1 ? 1 : 0; }
int main() {
	ll n;
	cin >> n;
	ll i;
	ll ans = inf;
	for (i = 1; i * i <= n; i++) {
		if (n % i != 0) continue;
		ans = min(ans, (i + n / i) - 2);
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
num = []
i = 0
roop = gets.to_i

while i < roop
  a = gets
  num = []
  num = a.split(nil)
  num = num.map{|n| n.to_i}
  num.sort!

  if(num[2]**2) == ((num[1]**2)+(num[0]**2))
    puts "YES"
  else
    puts "NO"
  end
  
  i +=1
end

Measured memory_bytes: 8808
import java.util.*;

import static java.lang.System.*;

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

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int minA = Integer.MAX_VALUE;
        int maxA = Integer.MIN_VALUE;
        int maxDiff = 0;   //高橋くんの最大稼ぎ
        int cnt = 0;       //高橋くんが最大稼ぎ出来る区間数
        for (int i = 0; i < N; i++) {
            boolean change = false;

            if (A[i] <= minA) {
                minA = A[i];
                maxA = minA;
                change = true;
            }

            if (A[i] >= maxA) {
                maxA = A[i];
                change = true;
            }

            if (maxDiff < maxA - minA) {
                maxDiff = maxA - minA;
                cnt = 1;
            } else if ((maxDiff == maxA - minA) && change) {
                cnt++;
            }
        }

        out.println(cnt);
    }
}

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


h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

xy = {}
for x, ai in enumerate(a):
    for y, aij in enumerate(ai):
        xy[aij] = (x, y)

acc = [[0] for _ in range(d)]
for num in range(d + 1, h * w + 1):
    (x, y), (i, j) = xy[num - d], xy[num]
    cost = abs(x - i) + abs(y - j)
    acc[num % d].append(acc[num % d][-1] + cost)

for l, r in lr:
    ans = acc[r % d][(r - 1) // d] - acc[l % d][(l - 1) // d]
    print(ans)


Measured memory_bytes: 106736
#include<bits/stdc++.h>
using namespace std;
int main(){long long p=0;string s;cin>>s;long S=s.size();
             while(S){char c=s[S-1];p+=(c-'0');S--;s.pop_back();
                    }p%=9;
if(p)cout<<"No"<<endl;else cout<<"Yes"<<endl;}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

double n;

double dp[550][550][550];

double dfs(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  if (i == 0 && j == 0 && k == 0) return 0;  // 定義より
  if (dp[i][j][k] != 0) return dp[i][j][k];
  dp[i][j][k] += dfs(i - 1, j, k) * (i / n);
  dp[i][j][k] += dfs(i + 1, j - 1, k) * (j / n);
  dp[i][j][k] += dfs(i, j + 1, k - 1) * (k / n);
  dp[i][j][k]++;
  dp[i][j][k] *= n / (i + j + k);
  return dp[i][j][k];
}

// ====================================================================

int main() {
  cin >> n;
  vector<int> v(3);
  for (int x = 0; x < n; x++) {
    int a;
    cin >> a;
    v[a - 1]++;
  }

  cout << fixed << setprecision(15) << dfs(v[0], v[1], v[2]) << endl;
}


Measured memory_bytes: 695808
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
$T = $key->A[1];
$tot = 0;
$du = 0;
foreach($key->X[0] as $t) {
  //終了より早く押されたら短くなる
  if ($t < $du) {
    $tot = $tot - ($du - $t);
  }
  $tot += $T;
  //次の終了位置
  $du = $t+$T;
}
printf("%d\n",$tot);


Measured memory_bytes: 62324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int fir,sec,n,x; cin>>n;
  int c[n];
  rep(i,n) cin>>c[i];
  fir=0; sec=0;
  rep(j,n){
    if(c[j]>fir){x=fir; fir=c[j]; sec=x;}
    else if(c[j]>sec){sec=c[j];}
  }
  
  if(fir==sec) {rep(k,n) cout<<fir<<endl;}
  
  else{
  
  rep(k,n){
    if(c[k]==fir) cout<<sec<<endl;
    else cout<<fir<<endl;
   }    
  }
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    for (int i=1; i<n-1; i++){
        int common=0;
        int cnt_f[26], cnt_b[26];
        for (int j=0; j<26; j++) cnt_f[j] = cnt_b[j] = 0; 
        for (int j=0; j<i; j++) cnt_f[s[j]-'a'] += 1;
        for (int j=0; j<n-i; j++) cnt_b[s[n-1-j]-'a'] += 1;
        for (int j=0; j<26; j++) {if (cnt_f[j]*cnt_b[j] > 0) common += 1;}
        ans = max(ans, common);
    }
    cout << ans << endl;
    return 0;    
}

Measured memory_bytes: 3648
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		Graph g = new Graph(n, true);
		for(int i = 0; i < m; i++){
		    int from = sc.nextInt()-1;
		    int to = sc.nextInt()-1;
		    int w = sc.nextInt()*(-1);
		    g.add(from, to, w);
		}
		
		// 計算
		long result = 0;
		if(g.bf(0)){
		    System.out.println("inf");
		    return;
		}else{
		    result = g.dist[n-1]*(-1);
		}
		
		// 出力
		System.out.println(result);
	}
}

class Graph {
	int n;
	boolean directed;
	ArrayList<Edge>[] adjList;
	int m;
	long[] dist;
	long[][] distWF;
	int start;
	int[] prev;
	ArrayList<Integer> path;
	long INF = 1001001001001001001L;

	public Graph (int n, boolean directed) {
		this.n = n;
		this.m = 0;
		this.directed = directed;
		this.adjList = new ArrayList[n];
		for(int i = 0; i < n; i++){
			adjList[i] = new ArrayList<Edge>();
		}
	}
	
	public void add(int from, int to) {
		add(from, to, 1);
	}
	public void add(int from, int to, int w) {
		adjList[from].add(new Edge(from, to, w));
		this.m++;
		if(!directed){
			adjList[to].add(new Edge(to, from, w));
			this.m++;
		}
	}
	
	public boolean bf(int start) { // O(NM)
		this.start = start;
		this.prev = new int[n];
		Arrays.fill(prev, -1);
		prev[start] = start;
		this.dist = new long[n];
		Arrays.fill(dist, INF);
		dist[start] = 0;
		boolean hasNegativeLoop = false;
		for(int i = 0; i < n*2; i++){
			for(int j = 0; j < n; j++){
				for(Edge e : adjList[j]){
					if(dist[e.to] <= dist[e.from] + e.w) continue;
					dist[e.to] = dist[e.from] + e.w;
					prev[e.to] = e.from;
					if(i == n-1) dist[e.to] = -INF;
				}
			}
		}
		if(dist[n-1] <= -INF) hasNegativeLoop = true;
		return hasNegativeLoop;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		for(ArrayList<Edge> list : adjList){
			for(Edge e : list){
				sb.append(e.toString());
				sb.append("\n");
			}
		}
		return sb.toString();
	}
	
	public String distToString(){
		if(dist != null) return Arrays.toString(dist);
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(distWF[i][j] == INF){
					sb.append("from:" + i + " to:" + j + " dist:INF" + "\n");
				}else{
					sb.append("from:" + i + " to:" + j + " dist:" + distWF[i][j] + "\n");
				}
			}
		}
		return sb.toString();
	}
	
	class Edge {
		int from;
		int to;
		int w;
		
		Edge(int from, int to, int w){
			this.from = from;
			this.to = to;
			this.w = w;
		}
		
		public String toString(){
			return "from:" + from + " to:" + to + " w:" + w;
		}
	}
	
	class Vertex {
		int id;
		long distance;
		
		Vertex(int id, long distance){
			this.id = id;
			this.distance = distance;
		}
		
		public String toString(){
			return "id:" + id + " distance:" + distance;
		}
	}
}



Measured memory_bytes: 48596
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  string S;
  cin >> N >> S;
  int q_left = 0;
  int q_right = 0;
  for(int i=0; i<N; i++){
    if(S[i] == '(') q_left++;
    else{
      if(q_left >= 1) q_left--;
      else q_right++;      
    }
  }
  string ret = S;
  for(int i=0; i<q_left; i++) ret = ret + ')';
  for(int i=0; i<q_right; i++) ret = '(' + ret;
  cout << ret << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	int N, x;
	cin >> N >> x;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, N) {
		x -= a[i];
		if (x < 0)break;
		if(i!=N-1)ans++;
		if (i == N - 1 && x == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
t=input()

if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

c=len(s)-len(t)
flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1
if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
	if (u == NIL)return;
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u) {
	if (u == NIL)return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}

void postParse(int u) {
	if (u == NIL)return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
}

int main() {
	int i, v, l, r, root;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		T[i].p = NIL;
	}

	for (i = 0; i < n; i++) {
		scanf("%d %d %d ", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL)T[l].p = v;
		if (r != NIL)T[r].p = v;
	}

	for (i = 0; i < n; i++)if (T[i].p == NIL)root = i;

	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");

	return 0;
}


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


#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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 long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

ll a,b,c;

int main()
{
    cin>>a>>b>>c;

    // sqrt(a)+sqrt(b)<sqrt(c)を
    // c-a-b>0 and (c-a-b)^2>4ab に分解する

    ll one,two;
    one=c-a-b;
    two=one*one-4*a*b;

    if(one>0 and two>0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;

}





Measured memory_bytes: 256
values = input().split()
int_values = [int(value) for value in values]
w = int_values[0]
h = int_values[1]
x = int_values[2]
y = int_values[3]
r = int_values[4]
print("Yes" if x - r >= 0 and y + r >= 0 and x + r <= w and y + r <= h else "No")



Measured memory_bytes: 5604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <limits>
#include <math.h>
#include <cassert>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

struct UnionFind
{
    vector<int> par;

    UnionFind(int N) : par(N)
    {
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

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

    void unite(int x, int y)
    {                    
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);

    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        tree.unite(x - 1, y - 1);
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (!tree.same(0, i))
        {
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3724
import sys
from collections import Counter
from math import atan2, pi
readline = sys.stdin.readline
def cross(o, a, b):
    return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])

Prob = Counter()
N = int(readline())
Points = [tuple(map(int, readline().split())) for _ in range(N)]
Pointsorig = Points[:]
Points.sort()

lower = []
for p in Points:
    while len(lower) >= 2 and cross(lower[-2], lower[-1], p) < 0:
        lower.pop()
    lower.append(p)
upper = []
for p in Points[::-1]:
    while len(upper) >= 2 and cross(upper[-2], upper[-1], p) < 0:
        upper.pop()
    upper.append(p)

convexhull = lower[1:-1] + upper
M = len(convexhull)
convexhull += [convexhull[0]]
convexhull += [convexhull[1]]

for i in range(1, M+1):
    pn = convexhull[i]
    A = (convexhull[i-1][1] - pn[1] , convexhull[i-1][0] - pn[0])
    B = (convexhull[i+1][1] - pn[1] , convexhull[i+1][0] - pn[0])
    theta = abs(pi - abs(atan2(*A) - atan2(*B)))
    Prob[pn] = theta/(2*pi)
Ans = [0]*N
for i in range(N):
    Ans[i] = Prob[Pointsorig[i]]
print('\n'.join(map(str, Ans)))

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define x first
#define y second

namespace oo
{
	typedef std::pair<int,int> pii;

	const int N=2010;

	int begin[N],next[N*2],to[N*2];

	pii s[N];

	int n,m,e;

	int fa[N],vis[N],cnt[N];
	void predfs(int p=1,int h=0)
	{
		fa[p]=h;
		for(int i=begin[p],q;i;i=next[i])
			if((q=to[i])!=h)predfs(q,p);
	}
	int calculate()
	{
		predfs();
		for(int i=1;i<=m;i++)
		{
			int u=s[i].x,v=s[i].y;
			memset(vis,0,sizeof(vis));
			while(u!=1)vis[u]^=1,u=fa[u];
			while(v!=1)vis[v]^=1,v=fa[v];
			for(int j=2;j<=n;j++)cnt[j]+=vis[j];
		}
		int ret=0;
		for(int i=2;i<=n;i++)ret+=std::min(2,cnt[i]);
		return ret;
	}

	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int i=1,u,v;i<n;i++)
			scanf("%d%d",&u,&v),add(u,v);
		for(int i=1;i<=m;i++)
			scanf("%d%d",&s[i].x,&s[i].y);
	}

	bool fucked[N];
	int f[N][N],g[N][N];

	inline void ins(int u,int v){f[u][v]++,f[v][u]++;}
	inline void del(int u,int v){f[u][v]--,f[v][u]--;}

	int find()
	{
		int ret=0;
		for(int p=1;p<=n;p++)
		{
			if(fucked[p])continue;

			int deg=0;
			for(int i=begin[p];i;i=next[i])
				if(!fucked[to[i]])deg++;
			if(deg==1)ret=p;
		}
		return ret;
	}
	int adj(int p)
	{
		int ret=0;
		for(int i=begin[p];i;i=next[i])
			if(!fucked[to[i]])ret=to[i];
		return ret;
	}

	void work()
	{
		int p=find();
		if(!p)return;

//		printf("work : %d\n",p);

		std::vector<int> seq;

		while(f[p][p]>0)del(p,p),g[p][p]++;
		for(int q=1;q<=n;q++)
			while(f[p][q]>0)
				del(p,q),seq.push_back(q);

		int spl=0,q=0;

		for(int i=0;i+1<(int)seq.size();i+=2)
		{
			del(p,seq[i]),del(p,seq[i+1]);
			ins(seq[i],seq[i+1]);
		}
		if(seq.size()%2!=0)
		{
			spl=seq.end()[-1],q=adj(p);
			del(p,spl),ins(q,spl);
		}

		fucked[p]=1,work();

		for(int i=0,u,v;i+1<(int)seq.size();i+=2)
		{
			u=seq[i],v=seq[i+1];
			if(!g[u][v])std::swap(u,v);

			g[u][v]--,g[u][p]++,g[p][v]++;
		}
		if(seq.size()%2!=0)
		{
			if(g[q][spl])g[q][spl]--,g[p][spl]++;
			else g[spl][q]--,g[spl][p]++;
		}
	}
	void solve()
	{
		initialize();

		for(int i=1;i<=m;i++)
			ins(s[i].x,s[i].y);

		work();

		printf("%d\n",calculate());

		for(int i=1;i<=m;i++)
		{
			if(!g[s[i].x][s[i].y])std::swap(s[i].x,s[i].y);

			printf("%d %d\n",s[i].x,s[i].y);

			g[s[i].x][s[i].y]--;
		}
	}
}

int main()
{
//	freopen("E.in","r",stdin);

	oo::solve();
	return 0;
}


Measured memory_bytes: 31360