akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  vector<int> a;
  for(int i=0; i*i<=n; i++){
    a.push_back(i*i);
  }

  cout << *(upper_bound(all(a), n)-1) << endl;

  return 0;
}


Measured memory_bytes: 512
//abc092_c.cpp
//Sun Mar 25 21:10:19 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

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

	int one[n+1];
	int two[n+1];

	int a[n+1];
	a[0] = 0;
	int total = 0;
	for (int i=1;i<n+1;i++){
		cin >> a[i];
		if (i>1){
			one[i-1]=abs(a[i]-a[i-1]);
			two[i-2]=abs(a[i]-a[i-2]);
		}else if (i==1){
			one[0]=abs(a[1]-a[0]);
		}
		total = total+one[i-1];
	}

	total = total+ abs(a[n]);
	one[n] = abs(a[n]);
	two[n-1] = abs(a[n-1]);


	for (int i=1;i<n+1;i++){
		int ans = total-one[i]-one[i-1]+two[i-1];
		cout << ans << endl;
	}

}

Measured memory_bytes: 2432
#include<cstdio>
int main()
{
	long long a,b,ans;
	char c;
	scanf("%lld %c %lld",&a,&c,&b);
	if(c=='+')
	ans=a+b;
	else
	ans=a-b;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int K,N;
    int A[2*1000000];
    scanf("%d%d",&K,&N);
    
    int i;
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    int max = 0;
    
    for(i=0;i<N-1;i++){
        if(max<A[i+1]-A[i]){
            max = A[i+1]-A[i];
        }
    }
    if(max<K-A[N-1]+A[0]){
        max = K-A[N-1]+A[0];
    }
    
    printf("%d\n",K-max);
}


Measured memory_bytes: 2944
class UnionFind:
    def __init__(self, n):
        self.sz = [ -1 for i in range(n)]

    def find(self, x):
        if self.sz[x] < 0:
            return x
        else:
            self.sz[x] = self.find(self.sz[x])
            return self.sz[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.sz[x] > self.sz[y]:
            x,y = y,x
        self.sz[x] += self.sz[y]
        self.sz[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self,x):
        return -self.sz[self.find(x)]

N,M = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    uf.union(x,y)

l = []
for i in range(N):
    l.append(uf.find(i))
print(len(set(l)))


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

int panjang,pnjg;
string s;
string t;
string u;

int main(){
	cin>>s;
	panjang=s.length();
	for(int i=panjang-1;i>=0;i--){
		s.erase(i,1);
		pnjg=s.length();
		if(pnjg%2==0){
			t=s.substr(0,pnjg/2);
			u=s.substr(pnjg/2,pnjg-1);
			if(t==u){
				i=-1;
				cout<<pnjg<<endl;
			}
		}
	}
}
		

Measured memory_bytes: 3492
package main

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

func main() {
	scanInit()

	x := nextInt()
	y := nextInt()
	z := nextInt()

	x -= z

	fmt.Println(x / (y + z))

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
from collections import deque
from heapq import heappush,heappop

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def main():
    H,W = ints_raw()
    DFST = [[-1 for i in range(W)]for i in range(H)]
    qu = deque()
    dirs = [[1,0,1],[0,1,1],[-1,0,1],[0,-1,1]]
    ans = 0
    for h in range(H):
        S = input()
        for w in range(W):
            if S[w]=="#":
                DFST[h][w]=0
                qu.append([h,w,0])
    while len(qu)!=0:
        cpos = qu.popleft()
        for dir in dirs:
            
            ny,nx,nt = [cpos[0]+dir[0],cpos[1]+dir[1],cpos[2]+dir[2]]
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if DFST[ny][nx]!=-1:
                continue
            DFST[ny][nx]=nt
            ans = max(ans,nt)
            qu.append([ny,nx,nt])
    return ans

print(main())


Measured memory_bytes: 147548
import java.util.*
import kotlin.math.floor

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var (a,b,n) = scan.nextLine().split(" ").map{ it.trim().toLong() }.toTypedArray()

    var ans : Long= 0
    if(n<b)
        ans= ((a*n)/b)
    else if(n==b)
        ans = ((a*(n-1))/b)
    else
    {
        var x = (b-1)
        var k1 = ((a*x)/b)
        var k2 = (a*(x/b))
        ans=k1-k2
    }
    println(ans)
}


Measured memory_bytes: 38404
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=(k);i++)
#define INF ((int)1.e6)
#define mk(i,j) make_pair(i,j)
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(!n)break;
		vector< pair<double, string> > v;
		rep(i,n){
			string t;
			int p,a,b,c,d,e,f,g,h;
			cin >> t;
			cin >> p >> a >> b >> c >> d >> e >> f >> g >> h;
			a += b + c;
			b = d + e;
			c = f * g * h - p;
			d = a + b * h;
			v.push_back(mk(-c/(double)d,t));
		}
		sort(v.begin(), v.end());
		rep(i,n){
			cout << v[i].second << endl;
		}
		cout << "#" << endl;
	}
}

Measured memory_bytes: 1220
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))

d1 = {}
for d in D:
    if d not in d1:
        d1[d] = 1
    else:
        d1[d] += 1
d2 = {}
for t in T:
    if t not in d2:
        d2[t] = 1
    else:
        d2[t] += 1

for k2, v2 in d2.items():
    if k2 not in d1:
        print('NO')
        exit()
    else:
        v1 = d1[k2]
        if v1 < v2:
            print('NO')
            exit()
else:
    print('YES')


Measured memory_bytes: 127568
def nl(): return list(map(int, input().split()))
# print('Yes' if a else 'No')

N, M, X, Y = nl()
x = nl()
y = nl()

flg = False
for i in range(X + 1, Y + 1):
    if max(x) < i and i <= min(y):
        flg = True
        break

print('No War' if flg else 'War')





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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int gcd(int a, int b)
{
  return (b == 0 ? a : gcd(b, a % b));
}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N)
  cin >> A[i];
  int ans = A[0];
  REP(i, N)
  ans = gcd(ans, A[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
a, b, c = list(map(int, input().split()))
k = int(input())

def fun(i, k, s, t, u):
    if i == k:
        #print(s, t, u, s < t < u)
        return s < t < u
    else:
        f1 = fun(i + 1, k, s, t * 2, u)
        f2 = fun(i + 1, k, s, t, u * 2)
        return f1 or f2

t = fun(0, k, a, b, c)
print(['No', 'Yes'][t])



Measured memory_bytes: 9184
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<int> C,S,F;
void input(){
    fast_io();
    cin >> N;
    C.resize(N);
    S.resize(N);
    F.resize(N);
    for (int i = 0; i < N-1; i++)
    {
        cin >> C[i] >> S[i] >> F[i];
    }
}

int solve(){
    for (int start = 0; start < N; start++)
    {
        ll t = 0;
        for (int j = start; j < N-1; j++)
        {
            if(t<=S[j]) t=S[j];
            else {
                int a = (t-S[j]+F[j]-1)/F[j];
                t = S[j]+a*F[j];
            }
            t += C[j];
        }
        cout << t << "\n";
        
    }
    
    return 0;
}   

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;bool state=1;
    for(int i=0;i<s.size();i++){
        if(i&1&&s[i]=='R')state=0;
        if(i%2==0&&s[i]=='L')state=0;
    }
    if(state)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
const int N = 1e5 + 10,MOD = 7+1e9;
int n, a[N];
struct edge
{
    int to, next;
}e[2*N];
int tot, head[N];
int cnt, p[N], K, vis[N];
void init()
{
    tot = K = 0;
    memset(head, -1, sizeof head);
    memset(vis, -1, sizeof vis);
}
void addeage(int u, int v)
{
    e[tot].to = v, e[tot].next = head[u];
    head[u] = tot ++;
    e[tot].to = u, e[tot].next = head[v];
    head[v] = tot ++;
}
void dfs(int u)
{
    vis[u] = K;
    p[cnt ++] = a[u];
    for(int i = head[u];i != -1;i = e[i].next)
    {
        int v = e[i].to;
        if(vis[v] == -1) dfs(v);
    }
}
int main()
{
    int n, m;
    init();
    scanf("%d%d", &n, &m);
    for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
    for(int i = 0;i < m;i ++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        addeage(u, v);
    }
    int ans = 0;
    K = 0;
    for(int i = 1;i <= n;i ++)
    {
        if(vis[i] == -1)
        {
            cnt = 0;
            dfs(i);
            for(int j = 0;j < cnt;j ++)
            {
                if(vis[p[j]] == K)
                {
                    ans ++;
                }
            }
            K ++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4352
def main():
    n, x, m = map(int, input().split())
    inlis = list()
    inlis.append(x)
    mae = x
    kaisuu = 0

    for j in range(n-1):
        tsugi = mae ** 2 % m
        #print(tsugi)
        if tsugi not in inlis:
            inlis.append(tsugi)
            mae = tsugi
        else:
            inlis.append(tsugi)
            kaisuu = j+1
            bangou = inlis.index(tsugi)
            loop = len(inlis[bangou:-1])
            #print(kaisuu, bangou, loop)
            break
    #print(inlis)
    if kaisuu == 0:
        print(sum(inlis))
    else:
        #print(loop, n, bangou)
        loopnum = (n - bangou) // loop
        amari = (n - bangou) % loop
        if amari > 0:
            #print(inlis[:bangou],loopnum,inlis[bangou:-1],inlis[bangou:bangou+amari])
            print(sum(inlis[:bangou])+loopnum*sum(inlis[bangou:-1])+sum(inlis[bangou:bangou+amari]))
        else:
            print(sum(inlis[:bangou])+loopnum*sum(inlis[bangou:-1]))

        



if __name__ == "__main__":
    main()


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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    bool is10n = true;
    REP(i, n) {
        cin >> s[i];
        if(s[i] % 10 > 0)is10n = false;
    }
    if(is10n){
        cout << 0 << endl;
        return 0;
    }
    sort(s.begin(), s.end());
    int ans = accumulate(s.begin(), s.end(), 0);
    int i = 0;
    while(ans % 10 == 0 && i < n) {
        if(s[i] % 10 > 0)ans -= s[i];
        i++;
    }
    cout << ans << endl;
}


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

  int N;cin>>N;
  string S,T;cin>>S>>T;
  
  for(int i=0;i<N;i++){
    cout<<S.at(i)<<T.at(i);
  }
  cout<<endl;
}


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

int main(void){
	int h,w;
	while(cin >> h >> w,h){
		const int norm_hw = h*h + w*w;
		int norm_nhw = 1 << 20, nh = -1, nw = -1;
		rep(a,151)rep(b,151){
			if(a == 0 or b ==0 ) continue;
			if(b <= a) continue;
			const int norm_ab = a*a + b*b;
			if(norm_hw < norm_ab or (norm_hw == norm_ab and h < a)){
				
				if(norm_ab < norm_nhw or (norm_ab == norm_nhw and a < nh)){
					norm_nhw = norm_ab,nh = a,nw = b;
				}
			}
		}

		cout << nh << " " << nw << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {
    static final int UNCALC = -1;
    static final int INF = (int) 1e9;
    static int n, k;
    static int[] memo;
    static int[] h;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        k = sc.nextInt();
        h = sc.nextIntArray(n);
        memo = new int[n];
        Arrays.fill(memo, UNCALC);
        out.println(dp(0));
        out.flush();
        out.close();

    }

    static int dp(int i) {
        if (i == n - 1) return 0;
        if (memo[i] != UNCALC) return memo[i];
        int min = INF;
        for (int j = 1; j <= k; j++) {
            int to = i + j;
            if (to == n) break;
            min = Math.min(min, Math.abs(h[to] - h[i]) + dp(to));
        }
        return memo[i] = min;
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}

Measured memory_bytes: 47684
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int h,w,n;
  cin >> h >> w >> n;
  int paint=max(h,w);
  cout << ru(n,paint) << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
n_list = list(range(1, n+1))
p = list(map(int, input().split()))
count = 0

for i in range(n):
  if n_list[i] != p[i]:
    count += 1

if count == 0 or count == 2:
  ans = "YES"
else:
  ans = "NO"
  
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n,i,t=0;
  cin>>n;
 int a[n+1];
 for(i=1;i<=n;i++) { cin>>a[i]; if(a[i]!=i) t++;}
 if(t>2) cout<<"NO";
 else cout<<"YES";
  return 0;
   
  
}


Measured memory_bytes: 256
n = int(input())
s = []
d = {}
for _ in range(n):
    s.append("".join(sorted(str(input()))))
for si in s:
    if si not in d.keys():
        d[si] = 1
    else: d[si] += 1
ans = 0
val = d.values()
for v in val:
    ans += v*(v-1)/2
print(int(ans))

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

long long dp[1<<20] = {0};
int h[1<<20];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	for(int i = 1; i < n; i++) {
		dp[i] = LLONG_MAX;
		for(int j = max(0, i - 2); j < i; j++) {
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << endl;
} 

Measured memory_bytes: 2688
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

d1 = t1 * (a1 - b1)
d2 = t2 * (a2 - b2)

if d1 > 0:
    d1 *= -1
    d2 *= -1

if d1 + d2 == 0:
    print("infinity")
elif d1 + d2 < 0:
    print(0)
else:
    cnt = -d1 // (d1 + d2)
    t = -d1 % (d1 + d2)
    ans = 2 * cnt + int(t != 0)
    print(ans)


Measured memory_bytes: 62000
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0)break;
			int max=0,min=1000,sum=0;
			for(int i=0;i<n;i++){
				int s=sc.nextInt();
				if(max<s)max=s;
				if(min>s)min=s;
				sum+=s;
			}
			System.out.println((sum-max-min)/(n-2));
		}
	}
}

Measured memory_bytes: 19120
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int gcd(int x,int y){
    if(y == 0)return x;
    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x/gcd(x,y)*y;
}

signed main(){
    int n;cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    if(n == 1){
        cout << a[0] << endl;
        return 0;
    }

    int ret = a[n-1];
    int ans = 1;
    rep(i,n-1){
        ret = lcm(ret,a[i]);
        
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, j, judge=1;

    cin >> N;

    vector<ll> a, b(N);

    for(i=0; i<N; i++){
        cin >> b[i];
    }

    while(b.size() >= 1){
        for(i=b.size()-1; i>=0; i--){
            if(b[i] == i+1){
                a.push_back(b[i]);
                b.erase(b.begin()+i);
                break;
            }
            if(i==0){
                judge = 0;
                break;
            }
        }
        if(judge==0) break;
    }

    if(judge==1){
        for(i=a.size()-1; i>=0; i--){
            cout << a[i] << endl;
        }
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
dic = {}
for i in range(N):
    s = str(input())
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

S = sorted(dic.values())
t = S[-1]

X = []
for key in dic:
    if dic[key] == t:
        X.append(key)
x = sorted(X)

for i in range(len(X)):
    print(x[i])

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= 1000000; i++) {
        for (int j = (1000000 / i) + 1; j >= 1; j--) {
            if (i * j < n) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  
  for(int i=0; i<N; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  
  int count = 0;
  for(int i=0; i<N; i++) {
    if(x >= a.at(i)) {
      x -= a.at(i);
      count++;
    }
    else break;
  }
  if(count == N && x != 0) count--;

  cout << count << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define mid ((left + right) >> 1)
#define lson rt << 1, left, mid
#define rson rt << 1 | 1, mid + 1, right

const int N = 1e4 + 2;
int dp[1000 + 2][4 * N];
int h, n, a[N], b[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> h >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2 * N; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        for (int j = a[i]; j < 2 * N; j++) {
            dp[i][j] = min(dp[i][j], dp[i][j - a[i]] + b[i]);
        }
        //cout << *(dp[1] + 100) << endl;
    }
    cout << *min_element(dp[n] + h, dp[n] + 2 * N - 1) << endl;
    return 0;
}


Measured memory_bytes: 156928
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            int A = int.Parse(line[0]), B = int.Parse(line[1]);
            int max = A + B;
            if(max < A - B)
            {
                max = A - B;
            }
            if(max < A * B)
            {
                max = A * B;
            }
            Console.WriteLine(max);
        }
    }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

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

    int n;
    cin >> n;
    set<string> st;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << "\n";

    return 0;
}


Measured memory_bytes: 19204
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 100
#define MAX_W 100000

ll dp[MAX_N + 1][MAX_W + 1];

signed main(){
	int N,W;
	cin >> N >> W;
	int w[N];
	ll v[N];
	REP(i,N){
		cin >> w[i] >> v[i];
	}
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= W; j++){
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if(j - w[i] >= 0){
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

template<typename T>
vector<vector<T>> warshall(matrix<T> &g){
  vector<vector<T>> dist(g.size());
  rep(i,g.size()){
    dist[i].resize(g.size());
    rep(j,g.size())dist[i][j] = (i == j ? 0 : g[i][j]);
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        if(dist[i][k] == INF || dist[k][j] == INF)continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}

#define warshall warshall<int>// matの初期化でINFを詰めておく



////////////////////////////////////////////////////////////////////

int n,c;priority_queue<P, vector<P>, greater<P>> stq[35];
stack<P> st[35];priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> que;
signed main(){
  cin>>n>>c;
  rep(i,n){
    int s,t,cc;cin>>s>>t>>cc;cc--;
    stq[cc].push(P(s,t));
  }
  rep(i,n){
    rep(cc,c){
      while(!stq[cc].empty()){
        int s = stq[cc].top().first,t = stq[cc].top().second;stq[cc].pop();
        if(st[cc].empty() || st[cc].top().second != s){
          st[cc].push(P(s,t));
        }else{
          P p = st[cc].top();st[cc].pop();
          st[cc].push(P(p.first, t));
        }
      }
    }
  }
  rep(i,c){
    while(!st[i].empty()){
      P p = st[i].top();st[i].pop();
      que.push(P((double)p.first-0.5, 1));
      que.push(P(p.second, 0));
    }
  }
  int ans = 0, cnt = 0, s = -1, t = -1;
  while(!que.empty()){
    P p = que.top();que.pop();
    if(p.second){
      cnt++;
    }else{
      cnt--;
    }
    chmax(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 13932
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	vector<int> v[1407];
  int p=37;
  int n=p*(p+1)+1, k=p+1;
  for(int i=0; i<k; i++){
    v[i].push_back(1);
    for(int j=0; j<p; j++){
      v[i].push_back(2+i*p+j);
    }
  }
  for(int i=0; i<p; i++){
    for(int j=0; j<p; j++){
      v[k+i*p+j].push_back(i+2);
      for(int t=0; t<p; t++){
        v[k+i*p+j].push_back(p+2+t*p+(i*t+j)%p);
      }
    }
  }
  cout<<n<<" "<<k<<endl;
  for(int i=0; i<n; i++){
    for(auto x:v[i]) cout<<x<<" ";
    cout<<endl;
  }
	return 0;
}

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


int f(int x){
    int y = 1;
    for(int i=1; i<=x; i++){
        y *= i;
    }
    return y;
}
double func(int n, int* x, int* y, int t, int px, int py, int z){
    double buf = 0.0;
    int k = t;
    int cnt = 0;
    if(z == 0){
        return 0;
    }
    for(int i=0; i<n; i++){
        if(k % 2 == 0){
            buf += sqrt(pow(px-*(x+i), 2) + pow(py-*(y+i), 2)) * f(z-1) + func(n, x, y, (int)(t + pow(2, i)), *(x+i), *(y+i), z-1);
        }
        k = k/2;
    }
    return buf;
}


int main(){
    int n;
    scanf("%d", &n);
    int x[n], y[n];
    for(int i=0; i<n; i++){
        scanf("%d%d", &x[i], &y[i]);
    }
    double ans = 0.0;
    for(int i=0; i<n; i++){
        ans += func(n, x, y, (int)pow(2, i), x[i], y[i], n-1);
    }
    ans = ans / f(n);
    printf("%lf", ans);

    return 0;
}

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

using namespace std;

typedef long long  ll;

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

    int n;

    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int ans = 200 * 200 * 101;
    for (int i = -100; i <= 100; ++i) {
        int sum = 0;
        for (auto x : a)
            sum += (x - i) * (x - i);
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] c = in.nextString().toCharArray();
            for (int i = 0; i < 2; i++) {
                if (c[i] == c[i + 1] && c[i] == c[i + 2]) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <cmath>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;

int main(){
    int x,y,z;
    cin >> x >> y >> z;

    for(int i = 0; i < 1e5; ++i)
    {
        if(x < y*i + z * (i+1))
        {
            cout << i - 1 << endl;
            return 0;
        }
    }

    return 0;    
}



Measured memory_bytes: 256
#include <stdio.h>
void trace(int N, int A[]) {
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void BubbleSort(int N, int A[]) {
	int i, j, temp;
	int count = 0;
	for (i = 0; i < N - 1; i++) {
		for (j = N - 1; j > i; j--) {
			if (A[j] < A[j - 1]) {
				temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
				count++;
			}
		}
	}
	trace(N, A);
	printf("%d\n", count);
}

int main() {
	int i;
	int N, A[100];

	scanf("%d", &N);

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

	BubbleSort(N, A);

	return 0;
}


Measured memory_bytes: 2092
import math
a,b,C=map(int,input().split(' '))
h=b*math.sin(math.radians(C))
S=a*h/2
c2=a**2+b**2-2*a*b*math.cos(math.radians(C))
c=math.sqrt(c2)
L=a+b+c

print(S)
print(L)
print(h)




Measured memory_bytes: 5712
import java.util.Scanner;

public class Main {
	
	public static int search(int[] S, int[] T) {
		int counter = 0;
		for (int t : T) {  // iterates through each value in T
			for (int s : S) {
				if (t == s) {  // and checks against each value in S
					counter++;
					break;  // as soon as the value in T is found in S, it moves on to the next value in T
				}
			}
		}
		return counter;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int sizeS = in.nextInt();
		int[] S = new int[sizeS];
		for (int i = 0; i < sizeS; i++) {
			S[i] = in.nextInt();
		}
		int sizeT = in.nextInt();
		int[] T = new int[sizeT];
		for (int i = 0; i < sizeT; i++) {
			T[i] = in.nextInt();
		}
		in.close();
		int result = search(S,T);
		System.out.println(result);
	}

}



Measured memory_bytes: 40404
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

//C++17
template<typename Type>
Type GCD(Type a,Type b){ return b ? GCD(b,a%b) : a ;}
template<typename Type>
Type LCM(Type a,Type b){ return a*b / GCD(a,b) ;}

template<typename Type>//文字列の置換/Boost:replace_all()
Type replace_str(Type str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    vector<vector<int>> a(n,vector<int>(3));
    vector<vector<int>> dp(n+1,vector<int>(3));
    rep(i,n)rep(j,3)cin >> a[i][j];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                dp[i+1][j] = max(dp[i+1][j],dp[i][k]+a[i][j]);
            }
        }
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
    return 0;
}


Measured memory_bytes: 11136
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n");

const binarySearch = (key, arr, N) => {
  let mid;
  let left = 0;
  let right = N;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr[mid]) {
        right = mid;
    } else if (key > arr[mid]) {
        left = mid + 1;
    } else {
      return 1;
    }
  }
  return 0;
}


(function() {
  const N1 = Number(Arr[0]);
  const arr1 = Arr[1].split(" ").map(Number);
  // const N2 = Number(Arr[2]);
  const arr2 = Arr[3].split(" ").map(Number);
  console.log(arr2.map(e => binarySearch(e, arr1, N1)).reduce((a, b) => a + b, 0));
})();



Measured memory_bytes: 34880
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0;v < n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE) dfs_visit(v);
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u = 0;u < n;u++) color[u] = WHITE;
  tt = 0;
  for(u = 0;u < n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u = 0;u < n;u++) printf("%d %d %d\n",u + 1,d[u],f[u]);
}

int main(){
  int i,j,k,u,v;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++) M[i][j] = 0;
  }
  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
ll a[220000],x[220000],y[220000];
int main(){
    ll n;
    cin>>n;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n)x[i]=(i>1?x[i-2]:0)+a[i];
    rep(i,1,n){
        if(i%2==0)y[i]=max(y[i-1],(i>2?y[i-2]:0)+a[i]);
        else y[i]=max(x[i-1],(i>2?y[i-2]:0)+a[i]);
    }
    cout<<y[n-1];
}

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

int main() {
  int N,K,i,j,p=0;
  cin >> N >> K;
  for(i=0;i<N;i++){
    cin >> j;
    if(j<K-j){
      p=p+j;
    }else{
      p=p+K-j;
    }
  }
  cout << p*2 << endl;
}

Measured memory_bytes: 256
/*
  * author: said_v15
  * created with web_programmer
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int cnt=0;
        for(int j=i;j<n;j++)
        {
            if(s[j]=='A' || s[j]=='C' || s[j]=='G' || s[j]=='T') {cnt++;ans=max(ans,cnt);}
            else { break;}
            
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <limits.h>
using namespace std;



int a[55][2], b[55][2];
int main(){
	// freopen("input.txt", "r", stdin);
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i][0] >> a[i][1];
	}
	for (int i = 0; i < M; ++i)
	{
		cin >> b[i][0] >> b[i][1];
	}
	for (int i = 0; i < N; ++i)
	{
		int mm = INT_MAX;
		int id;
		for (int j = 0; j < M; ++j)
		{
			int dis = abs(a[i][0]- b[j][0]) + abs(a[i][1]- b[j][1]);
			if(mm > dis){
				id = j + 1;
				mm = dis;
			}
		}
		cout << id << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

/*
 memory????????±???????????§??±????????????????????£?????????
*/

constexpr int MAX = 20;

string program[MAX];
int log[MAX][MAX][4][16];

int R, C;
bool stop;

struct State {
    State(int r, int c, int m, int d) 
        : row(r), col(c), memory(m), dir(d) {}

    int row;
    int col;
    int memory;

    /*  
        1

    2       0
        
        3
    */
    int dir;
};

void analyzer(char symbol, int& dir, int& memory) {
    switch (symbol) {
        case '<':
            dir = 2;
            break;

        case '>':
            dir = 0;
            break;

        case '^':
            dir = 1;
            break;

        case 'v':
            dir = 3;
            break;

        case '_':
            if (memory == 0) dir = 0;
            else dir = 2;
            break;

        case '|':
            if (memory == 0) dir = 3;
            else dir = 1;
            break;

        case '?':
            break;

        case '.':
            break;

        case '@':
            stop = true;
            break;

        case '+':
            if (memory == 15) memory = 0;
            else memory++;
            break;

        case '-':
            if (memory == 0) memory = 15;
            else memory--;
            break;

        default: 
            int num = atoi(&symbol);
            memory = num;
            break;
    }
}

bool dfs(int row, int col, int dir, int memory) {
    int nx, ny;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, -1, 0, 1};

    if (log[col][row][dir][memory]) return false;
    else log[col][row][dir][memory] = true;

    analyzer(program[row][col], dir, memory);

    if (stop) return true;

    if (program[row][col] == '?') {
        for (int i = 0; i < 4; i++) {
            nx = col + dx[i];
            ny = row + dy[i];
            nx = (nx + C) % C;
            ny = (ny + R) % R;
            if (dfs(ny, nx, i, memory)) return true;
        }
        return false;
    }else {
        nx = col + dx[dir];
        ny = row + dy[dir];
        nx = (nx + C) % C;
        ny = (ny + R) % R;
        return dfs(ny, nx, dir, memory);
    }
}


int main(int argc, char const *argv[]) {
    cin>>R>>C;
    for (int row = 0; row < R; row++) {
        cin>>program[row];
    }

    dfs(0, 0, 0, 0);

    if (stop) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 5344
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=b;i<=c;i++)
            {
        if(i%a==0){
            printf("OK\n");
            return 0;
        }


        }
        printf("NG\n");

            return 0;
    }




Measured memory_bytes: 1620
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
c = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(H)]

def dfs(i, j) :
    magi = c[i][1] + j
    for k in range(10) :
        if visited[k] == 0 and c[i][k] < c[i][1] :
            visited[k] = 1
            magi = min(magi, dfs(k, c[i][k] + j))
            visited[k] = 0
    return magi

ans = [10**5 for _ in range(10)]
for i in range(10) :
    visited = [0 for _ in range(10)]
    visited[i] = 1
    ans[i] = dfs(i, 0)

ans2 = 0
for ai in A :
    for aii in ai :
        if aii == -1 :
            continue
        else :
            ans2 += ans[aii]

print(ans2)


Measured memory_bytes: 49884
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    // 入力の処理
    ll N, K;
    cin >> N >> K;
    ll noreruCount = 0;
    ll h;
    for (int i = 0; i < N; i++)
    {
        cin >> h;
        if (h >= K)
        {
            noreruCount++;
        }
    }

    cout << noreruCount << endl;

    return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU 

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

typedef pair<ll, ll> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<P> V(N);
	REP(i, N)cin >> V[i].first >> V[i].second;
	so(V);
	vll S(N);
	ll sum = 0;
	REP(i, N) {
		sum += V[i].second;
		S[i] = sum;
	}
	ll left = 0;
	ll ans = 0;
	REP(i, N) {
		if (i != 0) {
			left -= V[i].first;
			left += V[i - 1].first;
			left = max(left, -S[i - 1]);
		}
		ans = max(ans,S[i] + left);
	}
	cout << ans << endl;
	PAU;
	return 0;
}



Measured memory_bytes: 14452
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int  a = s.nextInt();
        int  b = s.nextInt();
        int  x = s.nextInt();

        if(a<=x&&x<a+b){
        	System.out.println("YES");
        }
        else{
        	System.out.println("NO");
        }
        s.close();
    }
}


Measured memory_bytes: 21844
from collections import deque
n, m, k =map(int, input().split())

fd = dict()
directcount = [0] * n
visited = [[-1, -1] for i in range(n)]
q = deque(list())
g = []
for _ in range(n):
    g.append(deque(list()))

for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1 # 1origin -> 0 origin
    g[a].append(b)
    g[b].append(a)
    directcount[a] += 1
    directcount[b] += 1

colorcount = [-1] * n
# dfs
for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        #print(q)
        nextnode = q.popleft() # 次の探索
        if visited[nextnode][0] != -1:
            continue
        visited[nextnode] = [color, cnt]
        q.extend(g[nextnode]) # nextnodeの辺を足す
        cnt += 1
    colorcount[color]  = cnt - 1

res = [[visited[i][0], colorcount[visited[i][0]]] for i in range(n)]

for i in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    if res[c][0] == res[d][0]:
        res[c][1] -= 1
        res[d][1] -= 1

for i in range(n):
    res[i][1] -=  (directcount[i] + 1)
print(" ".join(list(map(lambda x: str(x[1]), res))))

Measured memory_bytes: 138460