akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n;
	cin >> n;
	
	vector<int> index(2 * n);
	inc(i, 2 * n) { index[i] = i; }
	
	auto ask = [&](vector<int> const & v) {
		assert(SI(v) == n);
		vector<int> w;
		RF(e, v) { w.PB(index[e]); }
		sort(ALL(w));
		
		cout << "?";
		RF(e, w) { cout << " " << e + 1; }
		cout << endl;
		
		string s;
		cin >> s;
		return s[0];
	};
	auto type1 = [&](int p) {
		vector<int> v;
		inc(i, n) { v.PB(i + p); }
		return ask(v);
	};
	auto type2 = [&](int p) {
		vector<int> v = { p };
		inc(i, n - 1) { v.PB(n + i); }
		return ask(v);
	};
	auto type3 = [&](int p) {
		vector<int> v = { n + p };
		inc(i, n - 1) { v.PB(i); }
		return ask(v);
	};
	
	if(type1(0) != 'R') {
		inc(i, n) { swap(index[i], index[i + n]); }
	}
	
	int l = 0, h = n;
	while(h - l > 1) {
		int m = (l + h) / 2;
		(type1(m) == 'R' ? l : h) = m;
	}
	inc(i, l) { swap(index[i], index[i + n]); }
	swap(index[0 + l], index[0 + n - 1]);
	swap(index[n + l], index[n + n - 1]);
	
	auto ans = string(2 * n, '@');
	ans[index[0 + n - 1]] = 'R';
	ans[index[n + n - 1]] = 'B';
	inc(i, n - 1) {
		ans[index[0 + i]] = type2(i);
		ans[index[n + i]] = type3(i);
	}
	
	cout << "! " << ans << endl;
	
	return 0;
}


Measured memory_bytes: 724
n,m = map(int,input().split())
l = []
for _ in range(n):
    a = list(map(int,input().split()))
    l.append(a)

b = []

for i in range(n):
    for j in range(1,l[i][0]+1):
        b.append(l[i][j])

ans = 0
for k in range(1,m+1):
    cnt = b.count(k)
    if cnt == n:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int w,h,n,i,x[10000+1],y[10000+1],a,b,cnt;
	scanf("%d %d %d",&w,&h,&n);
	for(i=1;i<=n;i++) {
		scanf("%d %d",&x[i],&y[i]);
	}
	a=x[1];
	b=y[1];
	cnt=0;
	for(i=1;i<=n;i++) {
		while(1){
			if(a==x[i] && b==y[i]) {
				break;
			}
			if(a<x[i] && b<y[i]) {
				a++;
				b++;
				cnt++;
			}
			else if(a>x[i] && b>y[i]) {
				a--;
				b--;
				cnt++;
			}
			else if(a==x[i] && b<y[i]) {
				b++;
				cnt++;
			}
			else if(a==x[i] && b>y[i]) {
				b--;
				cnt++;
			}
			else if(a<x[i] && b==y[i]) {
				a++;
				cnt++;
			}
			else if(a>x[i] && b==y[i]) {
				a--;
				cnt++;
			}
			else if(a<x[i] && b>y[i]) {
				a++;
				cnt++;
			}
			else if(a>x[i] && b<y[i]) {
				a--;
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 612
#coding:utf-8
H = int(input())
A = list(map(int,input().split()))

def maxHeapify(A,i):
    l = 2 * i
    r = 2 * i + 1
    if l <= H and A[l-1] > A[i-1]:
        largest = l
    else:
        largest = i
    if r <= H and A[r-1] > A[largest-1]:
        largest = r
    if largest != i:
        A[i-1], A[largest-1] = A[largest-1], A[i-1]
        maxHeapify(A,largest)

def buildMaxHeap(A):
    for i in range(H // 2, 0, -1):
        maxHeapify(A,i)

buildMaxHeap(A)
A = " " + " ".join([str(num) for num in A])
print(A)



Measured memory_bytes: 64208
X, Y = map(int, input().split())
p = 2 * X - Y / 2
q = (-1) * X + Y / 2
tip = 0
ans = "No"
if p  != (p // 1):
  tip = 1
if q != (q // 1):
  tip = 1
if p < 0:
  tip = 1
if q < 0:
  tip = 1
if tip == 0:
  ans = "Yes"
print(ans)

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

int main(){
    int N,res=0;
    string A,B,C;
    cin >> N >> A >> B >> C;
    
    for (int i=0;i<N;i++){
        char a=A[i] ,b=B[i] ,c=C[i];
        if (a==b & b==c){
            res+=0;
        }
        else if (a==b | b==c | c==a){
            res += 1;
        }
        else {
            res += 2;
        }
    }

cout << res << endl;
}

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

using namespace std;
 
typedef long long ll;
 
const ll mod = 1e9+7; 

int main()
{
    int n;
    cin>>n;
    int i;
    vector<int> arr(n);
    for(i=0;i<n;++i){
        cin>>arr[i];
    }
    int j,k;
    ll ans=0;

    for(i=0;i<n;++i){
        for(j=0;j<n;++j){
            for(k=0;k<n;++k){
                if(i!=j&&j!=k&&i!=k&&arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[k]!=arr[i]){
                    if(arr[i]+arr[j]>arr[k]&&arr[k]+arr[j]>arr[i]&&arr[i]+arr[k]>arr[j]){
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans/6;
}
 

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;
    
    for(int i = 0;i < s.size();i++){
          for(int j = s.size()-i;j >=0;j--){
                string t = s;
                string u = t.replace(i,j,"");
                if(u == "keyence"){
                      cout <<"YES" << endl;
                      return 0;
                }
                
          }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 3588
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    train=[list(map(int,input().split())) for i in range(n-1)]

    for i in range(n-1):
        t=0
        for j in range(i,n-1):
            c=train[j][0]
            s=train[j][1]
            f=train[j][2]
            if t>=s:
                if t%f!=0:
                    t+=f-t%f
                t+=c
            else:
                t=s+c
        print(t)
    print(0)
if __name__=='__main__':
    main()

Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, double> P;
typedef pair<P, P> PP;


LL n;
LL d[101010];
struct edge { LL to; LL cost; };
vector<edge>vec[101010];

void serch(int v, int pre, LL D) {
	d[v] = D;
	for (int i = 0; i < vec[v].size(); i++) {
		if (vec[v][i].to == pre)continue;
		serch(vec[v][i].to, v, D + vec[v][i].cost);
	}
}

int main() {
	cin >> n;
	LL a, b, c;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b >> c;
		a--, b--;
		vec[a].emplace_back(edge{ b,c });
		vec[b].emplace_back(edge{ a,c });
	}
	int q, k;
	cin >> q >> k;
	k--;
	for (int i = 0; i < 101010; i++)d[i] = LINF;
	d[k] = 0;
	serch(k, -10, 0);

	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		a--, b--;
		cout << d[a] + d[b] << endl;
	}
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb(x) pupsh_back(x)
int32_t main() {
    int n,k;
    cin>>n>>k;
    n=n%k;
    if(n==0)
    {
        cout<<0;
        return 0;
    }
    cout<<min(abs(n),(k-n));
    
//    cout<<"Sum of x+y = " << z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int rd(int x=0) {return cin>>x,x;}

const int N=1e5+50;
char s[N];
int n,a[N],tot,rt;
vector <int> edge[N];

int main() {
	scanf("%s",s+1); n=strlen(s+1);
	if(s[n]=='1') {puts("-1"); return 0;}
	for(int i=1;i<=n;++i) a[i]=s[i]-'0';
	if(!a[1]) {puts("-1"); return 0;}
	for(int i=1;i<n;i++) if(a[i]^a[n-i]) {puts("-1"); return 0;}
	tot=rt=2;
	edge[1].push_back(2);
	for(int i=2;i<n;i++) {
		if(a[i]) edge[rt].push_back(++tot), rt=tot;
		else edge[rt].push_back(++tot);
	}
	for(int i=1;i<=n;i++) for(auto j:edge[i]) cout<<i<<' '<<j<<'\n';
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define inf 1e9
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const ll M = 1e9+7;
const int sz = 1000001;
int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    if(n%500==0){
        ans += ((n/500)*1000);
    }
    else {
        int rem = n/500;
        ans += (rem*1000);
        n -= (rem*500);
        if(n%5==0){
            ans += ((n/5)*5);
        }
        else {
            rem = n/5;
            ans += (rem*5);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;
vector<int> tree[100005];
bool removed[100005];

void dfs(int u, int p) {
  for (auto v: tree[u]) {
    if (v == p) continue;
    dfs(v, u);
  }

  if (p != -1 && !(removed[u] || removed[p]))
    removed[u] = removed[p] = true;
}

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

  cin >> N;

  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  dfs(0, -1);

  bool first = false;
  rep(i, N) first |= !removed[i];

  cout << (first ? "First":"Second") << endl;

  return 0;
}


Measured memory_bytes: 5888
import fractions
MOD = 1000000000+7

N = int(input().strip())
A = list(map(int, input().strip().split()))

def lcm(a,b):
  return a*b//fractions.gcd(a,b)

a_lcm = A[0]
for a in A[1:]:
  a_lcm = lcm(a_lcm, a)

ans = 0
for a in A:
  ans += a_lcm//a
print(ans%MOD)


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

int main(){
    int N,T;
    cin >> N >> T;
    int minC = 0;
    vector<int> c(N);
    vector<int> t(N);
    vector<int> cm;
    for(int i = 0;i< N;i++){
        cin >> c.at(i) >> t.at(i);
    }
    
    for(int i =0;i < N;i++){
        if(t.at(i) <= T){
            if(minC == 0){
                minC = c.at(i);
            }else{
                minC = min(minC,c.at(i));
            }
        }
    }
    if(minC == 0){
        cout << "TLE" << endl;
    }else{
    cout << minC;
    }

    
}

Measured memory_bytes: 256
# N = gets.chomp.to_i
N, A, B = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

## [A, B, A, ...], 
# At, first, divide by A+B.
# Then decrease by A. then decrease 
# A is blue

s = N
cnt = N / (A+B)
remain = s - (cnt * (A+B))

if (remain >= A)
  p cnt * A + A
else
  p cnt * A + remain
end

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long> a(n+1),b(n);
    for (int i = 0; i < n+1; ++i) {
        cin>>a[i];
    }
    for (int j = 0; j < n; ++j) {
        cin>>b[j];
    }
    long long ans=0;
    vector<long long> a2=a,b2=b;
    for (int i = 0; i < n; ++i) {
        if(a[i]<=b[i]){
            ans+=a[i];
            b[i]-=a[i];
            a[i]=0;
        }
        else{
            ans+=b[i];
            b[i]=0;
        }

        if(b[i]>0){
            if(a[i+1]<=b[i]){
                ans+=a[i+1];
                b[i]-=a[i+1];
                a[i+1]=0;
            }
            else{
                ans+=b[i];
                a[i+1]-=b[i];
                b[i]=0;
            }
        }
    }

    long long ans2=0;
    for (int i = n-1; i >= 0; --i) {
        if(a2[i+1]<=b2[i]){
            ans2+=a2[i+1];
            b2[i]-=a2[i+1];
            a2[i+1]=0;
        }
        else{
            ans2+=b2[i];
            b2[i]=0;
        }

        if(b2[i]>0){
            if(a2[i]<=b2[i]){
                ans2+=a2[i];
                b2[i]-=a2[i];
                a2[i]=0;
            }
            else{
                ans2+=b2[i];
                a2[i]-=b2[i];
                b2[i]=0;
            }
        }
    }
    cout<<max(ans,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>

int main()
{
    int n1, n2;
    char op;
    std::cin >> n1>>op>>n2;
    if(op == '-'){
        std::cout << n1 - n2 << std::endl;
    }
    if(op == '+'){
        std::cout << n1 + n2 << std::endl;
    }
    

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 100000000

using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << (int)sqrt(n) * (int)sqrt(n) << endl;
    return 0;
}


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

int main(){
    string s;
    cin>>s;
    if(s.at(0)=='7'||s.at(1)=='7'||s.at(2)=='7'){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3620
def main():
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]
    field = [[0] * w for _ in range(h)]

    for i, row in enumerate(grid):
        row = row + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[i][k] = idx_next - idx - 1
            idx = idx_next

    m = 0
    for i, row in enumerate(zip(*grid)):
        row = "".join(row) + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[k][i] += idx_next - idx - 1
                if field[k][i] > m:
                    m = field[k][i]
            idx = idx_next
    print(m - 1)


if __name__ == "__main__":
    main()

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

using namespace std;

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

    int sum =0;
    for(int i=0; i<N.size(); i++)
        sum += (int)(N[i]-'0');
    if(sum%9 == 0)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3732
n, m = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(n+1)]
rank = [0]*(n+1)
ans = 0

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]

def union(x, y):
  par_x = find(x)
  par_y = find(y)
  if rank[par_x] < rank[par_y]:
    par[par_x] = par_y
  else:
    par[par_y] = par_x
    if rank[par_x] == rank[par_y]:
      rank[par_x] += 1

for i in range(m):
  x, y = map(int, input().split())
  union(x, y)

for i in range(n):
  ans += (find(p[i]) == find(i+1))

print(ans)

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

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,q,a,b,c,d,e,f,g;
  cin>>n>>q>>a>>b>>c>>d>>e>>f>>g;
  using P = pair<Int, Int>;
  map<P, Int> mp;
  auto val=[&](Int y,Int x){
    if(x>y) swap(x,y);
    return ((y-n)*a+x*b)%c;
  };
  auto calc=[&](Int y,Int x){
    //cout<<y<<":"<<x<<endl;
    if(mp.count(minmax(y,x))) return mp[minmax(y,x)];
    else return val(y,x);
  };

  vector<Int> vx(n),vy(n);
  iota(vx.begin(),vx.end(),1);
  iota(vy.begin(),vy.end(),n+1);
  //for(Int i=0;i<n;i++) cout<<"vx:"<<i<<vx[i]<<endl;
  //for(Int i=0;i<n;i++) cout<<"vy:"<<i<<vy[i]<<endl;

  using It = vector<Int>::iterator;
  It px=vx.begin();
  It qx=--vx.end();
  It py=vy.begin();
  It qy=--vy.end();

  auto conv=[&](It it,Int x){
    if(it==--vx.end()||it==--vy.end()) return it-x;
    return it+x;
  }; 
  
  for(Int i=0;i<q;i++){
    string s;
    cin>>s;
    if(s=="WR"){
      Int r,c,v;
      cin>>r>>c>>v;
      r--;c--;
      mp[minmax(*conv(py,r),*conv(px,c))]=v;
    }
    if(s=="CP"){
      Int r1,c1,r2,c2;
      cin>>r1>>c1>>r2>>c2;
      r1--;c1--;r2--;c2--;
      mp[minmax(*conv(py,r2),*conv(px,c2))]=calc(*conv(py,r1),*conv(px,c1));
    }
    if(s=="SR"){
      Int r1,r2;
      cin>>r1>>r2;r1--;r2--;
      auto sy=(py<qy?py:qy);
      if(sy==vx.begin())
	swap(vx[conv(py,r1)-sy],vx[conv(py,r2)-sy]);
      else
	swap(vy[conv(py,r1)-sy],vy[conv(py,r2)-sy]);
    }
    if(s=="SC"){
      Int c1,c2;
      cin>>c1>>c2;c1--;c2--;
      auto sx=(px<qx?px:qx);
      if(sx==vx.begin())
	swap(vx[conv(px,c1)-sx],vx[conv(px,c2)-sx]);
      else
	swap(vy[conv(px,c1)-sx],vy[conv(px,c2)-sx]);
    }
    if(s=="RL"){
      It bpx=px,bqx=qx,bpy=py,bqy=qy;
      px=bpy;
      qx=bqy;
      py=bqx;
      qy=bpx;
    }
    if(s=="RR"){
      It bpx=px,bqx=qx,bpy=py,bqy=qy;
      px=bqy;
      qx=bpy;
      py=bpx;
      qy=bqx;
    }
    if(s=="RH"){
      swap(py,qy);
    }    
    if(s=="RV"){
      swap(px,qx);
    }
  }

  const Int MOD = 1e9+7;
  d--;f--;
  Int ans=314159265;
  for(Int i=d;i<e;i++)
    for(Int j=f;j<g;j++)
      ans=(ans*31+calc(*conv(py,i),*conv(px,j)))%MOD;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
typedef long double ld;
using namespace std;

int a[2020], num[2020], flake[2020];
pair<int, int> p[2020];

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	for(int i=0; i<N; ++i){
		cin >> a[i];
		p[i]=make_pair(a[i], i);
		num[i]=1;
	}
	sort(p, p+N);
	int ans=p[Q-1].first-p[0].first;
	for(int i=0; i<N; ++i){
		num[p[i].second]=0;
		int sum=0, now=1;
		for(int j=0; j<N; ++j){
			if(num[j]==0){
				sum += max(0, flake[now]-K+1);
				++now;
			}else{
				num[j]=now;
				++flake[now];
			}
		}
		sum += max(0, flake[now]-K+1);
		if(sum<Q) break;
		int d=i+1, cnt=0, mn, mx;
		while(cnt<Q){
			if(flake[num[p[d].second]]>=K){
				++cnt;
				--flake[num[p[d].second]];
				if(cnt==1) mn=p[d].first;
				if(cnt==Q) mx=p[d].first;
			}
			++d;
		}
		ans=min(ans, mx-mn);
		for(int j=0; j<=now; ++j) flake[j]=0;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

    int n, m, ans = 0;
    cin >> n >> m;

    for (int i = 1; i * i <= m; i++)
        if (m % i == 0) {
            if (1ll * n * i <= m)
                ans = max(ans, i);
            if (1ll * n * (m / i) <= m)
                ans = max(ans, m / i);
        }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,INF=1e18;
ll N,dp[MAX_N+1][2];
string S;
char c[2]={'.','#'};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>S;
	REP(i,2)dp[0][i]=0;
	REP(i,N){
		REP(j,2){
			dp[i+1][j]=INF;
			REP(k,2){
				if(k==1 && j==0)continue;
				dp[i+1][j]=min(dp[i+1][j],(c[j]!=S[i])+dp[i][k]);
			}
		}
	}
	cout<<min(dp[N][0],dp[N][1])<<endl;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<bool> seen;
vector<vector<pair<int,int>>> t;
vector<int> col;

void dfs(int x){
  seen[x] = true;
  for(int i = 0; i < t[x].size(); i++){
    int nv=t[x][i].first;
    if(seen[nv]) continue;
    if(t[x][i].second%2==0) col[nv]=col[x];
    if(t[x][i].second%2==1) col[nv]=col[x]*(-1);
    seen[nv] = true;
    dfs(nv);
  }
}

int main() {
  int N;
  cin >> N;
  t.resize(N);
  col.assign(N,1);
  seen.resize(N,false);
  for(int i = 0; i < N-1; i++) {
    int u, v, w;
    cin >> u >>v >> w;
    pair<int, int> a, b;
    a.first=u-1;
    a.second=w;
    b.first=v-1;
    b.second=w;
    t.at(u-1).push_back(b);
    t.at(v-1).push_back(a);
  }
  dfs(0);
  for(int i = 0; i < N; i++) {
    if(col[i]==-1)cout<<0<<endl;
    if(col[i]==1)cout<<1<<endl;
  }
}
  

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1);


const int maxN=102;
int arr[maxN];
int n;

ll cost(int e) {
    ll c=0;
    for(int i=0;i<n;++i) {
        c+=(arr[i]-e)*(arr[i]-e);
    }
    return c;
}

void solve(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int ans=0;
    for(int i=0;i<min(k,n);i++)ans+=x;
    for(int i=k;i<n;i++)ans+=y;
    cout<<ans;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin >> n >> t;
  vector<int> a(n),b(n);
  for (int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  int m=1001;
  for (int i=0;i<n;i++){
    bool f=false;
    if(b[i]<=t){
      f=true;
    }
    if(f){
      m=min(m,a[i]);
    }
  }
  if(m==1001){
    cout << "TLE" << endl;
  }
  else {
    cout << m << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n;

  while(scanf("%d", &n) != EOF){
    int i, rect = 0;
    for(i = n; i < 600; i += n){
      rect += (i * i) * n;
    }
    printf("%d\n", rect);
  }
  return 0;
}

Measured memory_bytes: 0
#coding: euc-jp
class Main
  def self.main
    n = read1
    h = read2
    max = 0
    count = 0
    n.times do |i|
      if max <= h[i] then
        max = h[i]
        count += 1
      end
    end
    puts count
  end
  
  def self.read1
    gets.chomp.to_i
  end

  def self.read2
    gets.chomp.split.map(&:to_i)
  end
end

Main.main


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
using namespace std;
main(){
  int m,n;
  while(cin>>m>>n,n){
    int a1[n][n],a2[n][n],q,w,e,r;
    r(i,n)r(j,n){
      if(i==j)a2[i][j]=a1[i][j]=0;
      else a2[i][j]=a1[i][j]=INF;
    }
    while(m--){
      cin>>q>>w>>e>>r;q--;w--;
      a1[q][w]=a1[w][q]=e;
      a2[q][w]=a2[w][q]=r;
    }
    r(k,n)r(i,n)r(j,n){
      a1[i][j]=min(a1[i][j],a1[i][k]+a1[k][j]);
      a2[i][j]=min(a2[i][j],a2[i][k]+a2[k][j]);
    }
    cin>>e;
    while(e--){
      cin>>q>>w>>r;q--;w--;
      if(r)cout<<a2[q][w]<<endl;
      else cout<<a1[q][w]<<endl;
    }
  }
}

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

public class Main {
	ArrayList <Integer>output = new ArrayList<Integer>(0);
	String input = null;
	char input2[] = null;
	BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	int indexno = 0;
	int state = 0;//1:Left 2:Right
	int count = 0;
	public static void main(String[]args){
		Main prob = new Main();
		prob.Run();
	}
	public void Run(){
		while(true){
			try{
				input = read.readLine();
				if(input.equals("#")){
					break;
				}
				state = 0;
				count = 0;
				input2 = input.toCharArray();
				for(int z = 0;z < input2.length;z++){
//					System.out.println(input2[z]);
					if(input2[z] == 'h' || input2[z] == 'i'
							|| input2[z] == 'j'|| input2[z] == 'k'
							|| input2[z] == 'l'|| input2[z] == 'm'
							|| input2[z] == 'n'|| input2[z] == 'o'
							|| input2[z] == 'p'|| input2[z] == 'u'
							|| input2[z] == 'y'){
						if(state == 1)count++;
						state = 2;
					}else{
						if(state == 2)count++;
						state = 1;
					}
				}
				output.add(count);
			}catch(Exception e){
				
			}
		}
		for(int z = 0;z < output.size();z++){
			System.out.println(output.get(z));
		}
	}
}

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

using namespace std;

int main() {
    long long n,d;cin>>n>>d;
    long long x,y,z=0,cnt=0;
    for(long long i=0;i<n;i++)
    {
        cin>>x>>y;
        z=(x*x)+(y*y);
        z=(long long)ceil(sqrt(z));
        if(z<=d) cnt++;
    }
    cout<<cnt;
    
}

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

string name[100];
string buy;
map<string, int> list;
int n,m;

int main(){
	while(true){

		cin >> n;
		if(!n)
			return 0;
		list.clear();

		for(int i=0; i<n; i++){
			cin >> name[i];
			cin >> list[name[i]];
		}

		cin >> m;
		for(int i=0; i<m; i++){
			int tmp;
			int price = 0;
			string temp;
			cin >> temp >> tmp;
			for(int k=0; k<tmp; k++){
				string s;
				cin >> s;
				price += list[s];
			}
			if(price < list[temp])
				list[temp] = price;
		}

		cin >> buy;
		cout << list[buy] << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    ll res = 0;
    if( h > w ){
	swap( h ,w );
    }
    res = n / w + (n % w != 0 );
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

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

void print_cd(int n) {
    set<int> st;
    for (int i = 1; i <= sqrt(n) + 1; i++) {
        if (n % i == 0) {
            st.insert(i);
            st.insert(n / i);
        }
    }
    for (int i : st) {
        cout << i << endl;
    }
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    int m;
    if (n == 2) {
        int a, b; cin >> a >> b;
        m = gcd(a, b);
    } else {
        int a, b, c; cin >> a >> b >> c;
        m = gcd(a, b);
        m = gcd(m, c);
    }
    
    print_cd(m);
    
    return 0;
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100000;
int n;
int a[N], b[N];

struct ab{
    int a, b;
    bool operator<(const ab& other) const {
        if(b != other.b) return b < other.b;
        return a < other.a;
    }
} x[N];

void ans(bool yes) {
    if(yes) cout << "Yes\n";
    else cout << "No\n";
    exit(0);
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    for(int i = 0; i < n; ++i) {
        x[i].a = a[i]; x[i].b = b[i];
    }

    sort(a, a+n);
    sort(b, b+n);
    sort(x, x+n);

    for(int i = 0; i < n; ++i) {
        if(a[i] > b[i]) ans(false);
    }
    
    for(int i = 1; i < n; ++i) {
        if(a[i] <= b[i-1]) ans(true);
    }

    for(int i = 0; i < n; ++i) {
        x[i].a = lower_bound(a, a+n, x[i].a) - a;
        x[i].b = i;
    }

    int cur = 0, dist = 0;
    do {
        cur = x[cur].a;
        dist++;
    } while(cur != 0);

    if(dist < n) ans(true);
    else ans(false);
    
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <unordered_map>

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;
    std::unordered_map<std::string, bool> items;
    for(int i = 0; i < N; i++){
        std::string S;
        std::cin >> S;
        items[S] = i;
    }
    std::cout << items.size() << std::endl;
}


Measured memory_bytes: 17740
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, l, n) for(int i=(l); i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    vector<vector<int> > dp(N, vector<int>(3));

    rep(i, 0, N) {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }
    
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    rep(i, 1, N) {
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2] + a[i]);         
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2] + b[i]); 
        dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1] + c[i]);
    }

    int ans = max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << max((h2 * 60 + m2) - (h1 * 60 + m1) - k, 0) << endl;
    return 0;
}

Measured memory_bytes: 3636
// programming education

#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);

    if(n == 1){
        printf("Hello World\n");
    }else{
        int a, b;
        scanf("%d %d", &a, &b);
        printf("%d\n", a + b);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string s="No";
  for(int i=1;i<10;i++) {
    for(int j=1;j<10;j++) {
      if(i*j==N) {
        s="Yes";
        break;
      }
    }
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int count = 0;
    for (int i = 0; i < N - 2; ++i)
    {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
        {
            ++count;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    rep(i, N)cin >> A[i];
    sort(A.begin(), A.end());
    cout << A[N - 1] - A[0] << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,c,k,i,j;
    int t[100005];
    scanf("%d%d%d",&n,&c,&k);
    for(i=1;i<=n;i++)
        scanf("%d",&t[i]);
    sort(t+1,t+n+1);
    int sum=0;
    for(i=1;i<=n;i++)
    {
        j=i;
        i=i+c-1;
        if(i>n)
            i=n;
        while(t[i]-t[j]>k)
        {
            i--;
        }
        if(t[i]-t[j]<=k)
        sum++;
    }
    printf("%d\n",sum);
    return 0;
}

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

using namespace std;

int n;
string s;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>s;
    for (int i=1;i<s.length()-1;i++)
        if (s[0]=='0'|| s[s.length()-1]=='1' || s[i]!=s[s.length()-i-2]) {
            cout<<-1;
            return 0;
        }
    cout<<1<<" "<<2<<endl;
    int last = 1;
    for (int i=1;i<=s.length()-2;i++) {
        cout<<last<<" "<<i+2<<endl;
        if (s[i]=='1') last=i+2;
    }
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int u[4][2]={1,0,0,1,-1,0,0,-1};
const int N=1005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,k,Sx,Sy,d[N][N];
char s[N][N];
queue<pii> q;

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);read(m);read(k);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
			if(s[i][j]=='S') Sx=i,Sy=j;
	}
	q.push(mp(Sx,Sy));
	d[Sx][Sy]=1;
	while(!q.empty()){
		int x=q.front().FF,y=q.front().SS;q.pop();
		if(d[x][y]==k+1) continue;
		for(int i=0;i<4;i++){
			int tx=x+u[i][0],ty=y+u[i][1];
			if(tx<1||ty<1||tx>n||ty>m||d[tx][ty]||s[tx][ty]=='#') continue;
			d[tx][ty]=d[x][y]+1;q.push(mp(tx,ty));
		}
	}
	int ans=inf;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(d[i][j]) gmin(ans,(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k+1);
	printf("%d\n",ans);
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
using namespace std;
char c[1000];
char xxx[100];
int main()
{
    memset(c,0,sizeof(c));
    long n,sa=0,sb=0;
    cin>>n;fgets(xxx,100,stdin);
    fgets(c,n+2,stdin);
    for(long i=0;i<n;i++)
    {
        if(c[i]!=')'&&c[i]!='('){c[i]=0;break;}
        if(c[i]=='(')
        for(long j=i+1,a=0;j<n;j++)
        {
            if(c[j]=='(')a--;
            else if(c[j]==')')a++;
            if(a>0)break;
            if(j==n-1)sb++;
        }
        else if(c[i]==')')
        for(long j=i-1,a=0;j>=0;j--)
        {
            if(c[j]=='(')a++;
            else if(c[j]==')')a--;
            if(a>0)break;
            if(j==0)sa++;
        }
    }
    if(c[0]==')')sa++;
    if(c[n-1]=='(')sb++;
    for(long i=0;i<sa;i++)cout<<'(';
    for(long i=0;i<n;i++)cout<<c[i];
    for(long i=0;i<sb;i++)cout<<')';
    cout<<endl;
    return 0;
}


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

#define IOS ios::sync_with_stdio(0)
#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 1;

int main () {
    IOS;
    long long int n;
    cin >> n;
    long long int ma = n%500;
    cout << ((n/500)*1000)+((ma/5)*5);
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;

struct cake{
  ll val, x, y, z;
  cake(ll val_, ll x_, ll y_, ll z_){
    val = val_, x = x_, y = y_, z = z_;
  }
};

bool comp(cake a, cake b){
  return a.val < b.val;
}

int main(){
  int n,m;
  cin >> n >> m;
  long long x[n], y[n],z[n];
  REP(i,n){
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = 0;
  REP(j,1<<3){
    vector<cake> vals;
    REP(i,n){
      ll val = ((j>>0&1) ? x[i] : -x[i]);
      val += ((j>>1&1) ? y[i] : -y[i]);
      val += ((j>>2&1) ? z[i] : -z[i]);
      vals.push_back(cake(val,x[i],y[i],z[i]));
    }
    sort(vals.begin(),vals.end(),comp);
    ll sum_x = 0, sum_y = 0, sum_z = 0;
    REP(i,m){
      sum_x += vals[i].x, sum_y+= vals[i].y, sum_z += vals[i].z;
    }
    ans = max(ans, abs(sum_x)+abs(sum_y)+abs(sum_z));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct Graph {
    struct Edge { int from; int to; lint cost; };
    struct Node {
        Node() : par(-1), done(false), dist(INF) {}
        int index;
        int par;
        bool done;
        lint dist;
        vector<Edge> edge;
    };

    int n;
    vector<Node> nodes;
    vector<Edge> edges;
    const static lint INF = 1e18;

    Graph(int n) : n(n) {
        nodes.resize(n);
        for(int i=0; i<n; i++)  nodes[i].index = i;
    }

    void add_edge(int from, int to, lint cost) {
        nodes[from].edge.push_back(Edge{from, to, cost});
        edges.push_back(Edge{from, to, cost});
    }
};

int main() {
    lint L;
    cin >> L;

    Graph g(21);
    lint k, last;
    for(k=last=1;; k*=2,last++) {
        if(L > k) {
            g.add_edge(last, last+1, 0);
            g.add_edge(last, last+1, k);
            L -= k;
        } else {
            break;
        }
    }

    bitset<100> bs(L-1);
    for(int i=0; i<100; i++) {
        if(bs[i]) {
            g.add_edge(i+1,last, k);
            k += pow(2, i);
        }
    }

    int N = 0;
    for(auto e : g.edges) {
        N = max(N, e.to);
    }

    cout << N << " " << g.edges.size() << endl;
    for(auto e : g.edges) {
        cout << e.from << " " << e.to << " " << e.cost << endl;
    }
}

Measured memory_bytes: 256
// Problem : C - Ubiquity
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;


#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define mem(ar,x) memset(ar,x,sizeof(ar))
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define mod 1000000007
#define maxn 1000003
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power(ll a, ll b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}


int main(){
	
	fastio;
	string n;
	cin>>n;
	if(n=="1"){
		cout<<0;
		rt;
	}
	
	ll r=0;
	for(auto &i:n){
		r = (r*10 + i-'0')%(mod-1);
	}
	ll ans = (power(10,r)  + power(8,r) )%mod ;
	ans  = (ans%mod - 2%mod *power(9,r)%mod +mod)%mod;
	
	cout<<ans;
	
	}


	
	
	
	



Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int main()
{
    int a,b,k;
    cin>>k>>a>>b;
    bool mark=false;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            mark=true;
            break;
        }
    }
    if(mark)    cout<<"OK";
    else    cout<<"NG";
    return 0;
}


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

int main() {
    int w, h, x, y; cin >> w >> h >> x >> y;

    cout << setprecision(10) << 1.0 * w * h / 2 << ' ';
    if (w == 2 * x && h == 2 * y) cout << 1;
    else cout << 0;
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
if n <= 2:
    print(4)
    exit()

ls = [n]
m = 0

for i in range(1, 120):
    n = int(n/2) if int(n%2) == 0 else 3*n+1
    ls.append(n)
    if n == 4:
        break

print(ls.index(4)+4)

Measured memory_bytes: 3060
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    if (m==0 || n==0){
        cout << "";
        return 0;
    }
    vector<vector<pair<int,char>>> dp(n+1,vector<pair<int,char>>(m+1,make_pair(0,'\0')));
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (s[i-1] == t[j-1]){
                dp[i][j].first = 1 + dp[i-1][j-1].first;
                dp[i][j].second = 'D';
            } else {
                if (dp[i-1][j].first > dp[i][j-1].first){
                    dp[i][j].first = dp[i-1][j].first;
                    dp[i][j].second = 'U';
                } else {
                    dp[i][j].first = dp[i][j-1].first;
                    dp[i][j].second = 'L';
                }
            }
        }
    }
    vector<char> ans;
    int p1 = n;
    int p2 = m;
    for (int i=0;i<m+n-1;i++){
        if (dp[p1][p2].second == '\0')
            break;
        if (s[p1-1] == t[p2-1]){
            ans.push_back(s[p1-1]);
        }
        if (dp[p1][p2].second == 'U'){
            p1--;
        } else if (dp[p1][p2].second == 'L'){
            p2--;
        } else if (dp[p1][p2].second == 'D'){
            p1--;
            p2--;
        } else
            break;
    }
    for (int i=ans.size()-1;i>=0;i--){
        cout << ans[i];
    }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int n = sc.intarr[0];
            int[] array = sc.intarr;

            Array.Sort(array);

            int alice = 0;
            int bob = 0;

            for(int i=0; i<n; i++)
            {
                if(i % 2 == 0)
                {
                    alice += array[i];
                }
                else
                {
                    bob += array[i];
                }
            }

            Console.WriteLine(Math.Abs(alice - bob));
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13780