akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate as acc
import sys

N,C=map(int,input().split())
a=[list(map(int,input().split())) for i in range(N)]

if N==1: print(max(0, a[0][1]-a[0][0], a[0][1]-(C-a[0][0]) ) ),sys.exit()

tmp=a[0][1]-a[0][0]
M=max(0,tmp)
l=[M]
for i in range(1,N):
    tmp+=a[i][1]-(a[i][0]-a[i-1][0])
    M=max(tmp,M)
    l.append(M)

tmp=a[N-1][1]-(C-a[N-1][0])
M=max(0,tmp)
r=[M]
for i in range(N-2,-1,-1):
    tmp+=a[i][1]-(a[i+1][0]-a[i][0])
    M=max(tmp,M)
    r.append(M)

r.reverse()

ans=max(l[0], r[0], l[0]-a[0][0]+r[1], l[N-1], r[N-1], r[N-1]-(C-a[N-1][0])+l[N-2])

for i in range(1,N-1):
    ans=max(ans, l[i], r[i], l[i]-a[i][0]+r[i+1], r[i]-(C-a[i][0])+l[i-1])

print(ans)

Measured memory_bytes: 36840
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main(void){
  string s;
  cin >> s;
  ll n = s.size();
  ll res = 0, i = 0, an = 0;
  while(i < n){
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
      res += an + 1;
      s[i] = 'B';
      s[i + 1] = 'C';
      s[i + 2] = 'A';
      i += 2;
    }
    else if (s[i] == 'A'){
      an++;
      i++;
    }
    else {
      an = 0;
      i++;
    }
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> p;

int main(){
    int A, B, K;
    cin >> K >> A >> B;
    
    for(int i = A; i<=B; i++){
        if(i%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
ll a[214514]; ll n, t, cnt = 0;
signed main() {
	cin >> n >> t;
	rep(i, n)cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		if (a[i + 1] - a[i] > t)cnt += t;
		else cnt += a[i + 1] - a[i];
	}
	cout << cnt + t << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 1792
import java.io.FileNotFoundException;
    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) throws FileNotFoundException {
     
    		//    	File file = new File("src/in.txt");
    		//    	Scanner sc = new Scanner(file);
     
    		Scanner sc = new Scanner(System.in);
     
    		int N = sc.nextInt();
    		int[] A = new int[N];
    		for(int i=0;i<N;i++) {
    			A[i] = Integer.parseInt(sc.next());
    		}
    		sc.close();
    		int[] B = A.clone();
    		Arrays.sort(B);
    		int max = B[N-1];
    		int nextmax = B[N-2];
    		for(int i=0;i<N;i++) {
    			if(A[i]==max) {
    				System.out.println(nextmax);
    			} else {
    				System.out.println(max);
    			}
    		}
    	}
    }

Measured memory_bytes: 61036
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define ll 	long long 
 
#define mod  1000000007
 

 
int main()
{
	FAST;
	string s;
	cin >> s;
	
	bool f = true;
	for(int i = 0; i < s.size(); i +=2){
		if(s[i] != 'h' || s[i+1] != 'i'){
			f = false;
		}
	}
	if(f){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <array>
#include <map>
#include <string>

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

using namespace std;
using ll = long long;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h.at(i);

	sort(h.begin(), h.end());

	int ans = 1000000001;
	for (int i = 0; i < n - k + 1; i++)
	{
		ans = min(h.at(i + k - 1) - h.at(i), ans);
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	bool tf = true;
	if (c - e < 0)
		tf = false;
		else if (d - e < 0)
			tf = false;
			else if (c + e > a)
				tf = false;
				else if (d + e > b)
					tf = false;
	cout << (tf?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; ll k;
	cin>>n>>k;
	ll a[200020], f[200020];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; i++) cin>>f[i];
	ll s=0;
	for(int i=0; i<n; i++){
		s+=a[i];
	}
	if(s<=k){
		cout<<0<<endl;
		return 0;
	}
	sort(a, a+n);
	sort(f, f+n, greater<ll>());
	ll l=0, r=1e12;
	while(r-l>1){
		ll m=(l+r)/2;
		ll c=0;
		for(int i=0; i<n; i++){
			c+=max(0ll, a[i]-m/f[i]);
		}
		if(c<=k) r=m;
		else l=m;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int matrix[105][105];
int lv[105];
int queue[105];
void Bfs(int n)
{
  int i;
  for(i=1;i<=n;i++)
   lv[i]=-1;
  int qHead=0,qTail=0;
  queue[qTail++]=1;
  lv[1]=0;
  while(qHead!=qTail){
   int v=queue[qHead++];
   for(i=1;i<=n;i++){
    if(lv[i]==-1 && matrix[v][i]==1){
     lv[i]=lv[v]+1;
     queue[qTail++]=i;
    }
   }
  }
}
int main()
{
    int n,i,j,u,v,fg;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&fg);
        for(j=0;j<fg;j++){
            scanf("%d",&v);
            matrix[u][v]=1;
        }
    }
    Bfs(n);
    for(i=1;i<=n;i++){
        printf("%d %d\n",i, lv[i]);
    }
    return 0;
}




Measured memory_bytes: 2084
#include <stdio.h>
int main(){
  int x,y,n;

  scanf("%d%d",&x,&y);
  n = gcd(x,y);
  printf("%d\n",n);
  
  return 0;
}

int gcd(int x,int y){
  int n,r;

  if(x<y){
    n = x;
    x = y;
    y = n;
  }
  while(y>0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;

int n, m, len;
char s[maxn], t[maxn];
int sd[5][maxn], td[5][maxn];
map<int, char> mp;

int main() {
    //freopen("in.txt", "r", stdin);
    mp[1] = 'L';
    mp[2] = 'R';
    mp[3] = 'U';
    mp[4] = 'D';
    cin >> n >> m >> len;
    int sx, sy;
    cin >> sx >> sy;
    cin >> (s + 1);
    cin >> (t + 1);
    for (int i = 1; i <= len; i++) {
        for (int j = 1; j <= 4; j++) {
            sd[j][i] = sd[j][i - 1] + (s[i] == mp[j] ? 1 : 0);
            td[j][i] = td[j][i - 1] + (t[i] == mp[j] ? 1 : 0);
        }

        while (td[2][i] - sd[1][i] >= m - sy + 1) {
            td[2][i]--;
        }
        while (td[1][i] - sd[2][i] >= sy) {
            td[1][i]--;
        }
        while (td[3][i] - sd[4][i] >= sx) {
            td[3][i]--;
        }
        while (td[4][i] - sd[3][i] >= n - sx + 1) {
            td[4][i]--;
        }
        if (sd[1][i] - td[2][i - 1] >= sy) {
            printf("NO\n");
            return 0;
        }
        if (sd[2][i] - td[1][i - 1] >= m - sy + 1) {
            printf("NO\n");
            return 0;
        }

        if (sd[3][i] - td[4][i - 1] >= sx) {
            printf("NO\n");
            return 0;
        }
        if (sd[4][i] - td[3][i - 1]>= n - sx + 1) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 7680
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

count = 0
now = 1
route = []
visited = set([1])
visit_time = [0]*N
visit_time[0] = 0

while True:
    route.append(now)
    old = now
    now = A[now-1]
    count += 1
    if count == K:
        Kth = now
    #print(now, visited)
    if now in visited:
        break
    else:
        visited.add(now)
        visit_time[now-1] = count

loop_s = now
loop_e = old

num_s = visit_time[loop_s-1]
num_e = visit_time[loop_e-1]

finish = (K-num_s)%(num_e-num_s+1)
#print(route, visit_time, loop_s, loop_e, num_e, num_s)
#print(finish)

if K < num_s:
    print(Kth)
else:
    print(route[finish+num_s])

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

int N, K;
vector<int> p;


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

  int a;
  for(int i = 0; i < N; i++){ cin >> a;  p.push_back(a);  }    //入力は最初から昇順

  int left, right;
  int minimum = 1e9;
  for(int i = 0; i+K-1 < N; i++){
    left = i; right = i+K-1;
    int ltor = abs(p[left]) + abs(p[right]-p[left]);
    int rtol = abs(p[right]) + abs(p[left]-p[right]);
    minimum = min(minimum, min(ltor, rtol));
  }

  cout << minimum << endl;

    
  return 0;
}






Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long longpow(long long a,long long b){
	long long c=1;
	for(int i=0;i<b;i++)c*=a;
	return c;
}
int main(){
	long long n,p,a[50];
	cin>>n>>p;
	bool b=false;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2)b=true;
	}
	if(b==false){
		if(p==0)cout<<longpow(2ll,n)<<endl;
		else cout<<0<<endl;
	}
	else cout<<longpow(2ll,n-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n,m;
ll num[10]={2,5,5,4,5,6,3,7,6};
string dp[11000];
void chmax2(string &a,string b){
    if(a=="-") a=b;
    if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    vl a(m);rep(i,m)cin>>a[i];
    rep(i,11000)dp[i]="-";
    dp[0]="";
    for(int i=0;i<=n;i++){
        if(dp[i]=="-") continue;
        for(auto aa:a){
            string b=dp[i]+(char)('0'+aa);
            chmax2(dp[i+num[aa-1]],b);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 44928
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define tddd tuple<double,double,double>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 800005
typedef long long int ll;
ll v[N];
int x;
ll val;
void update(int l,int h,int p)
{
    if(l>x || h<x)
        return ;
    if(l==h && l==x)
        v[p]=val;
    else
    {
        int m=(l+h)/2;
        update(l,m,2*p);
        update(m+1,h,2*p+1);
        v[p]=max(v[2*p],v[2*p+1]);
    }
    return ;
}
ll query(int a,int b,int l,int h,int p)
{
    if(a<=l && b>=h)
        return v[p];
    else if(a>h || b<l)
        return 0;
    int m=(l+h)/2;
    return max(query(a,b,l,m,2*p),query(a,b,m+1,h,2*p+1));
}
int main()
{
    int n,i;
    in(n);
    vi height(n),bet(n);
    read(height,i,n);
    read(bet,i,n);
    ll ans=0;
    rep(i,n)
    {
        val=query(0,height[i]-1,0,n-1,1)+bet[i];
        ans=max(ans,val);
        x=height[i];
        update(0,n-1,1);
    }
    outl(ans);

}









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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int num = r * 100 + g * 10 + b;
    if(num % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/abc166/tasks/abc166_c
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,m;
    cin >> n >> m;
    vector<ll> h(n+1);
    for(int i = 1;i<=n;i++){
        cin >> h[i];
    }
    vector<ll> a[100001];
    for(int i = 0;i<m;i++){
        ll e,s;
        cin >> e >> s;
        a[e].push_back(s);
        a[s].push_back(e);
    }
    ll ans = n;
    for(int i = 1;i<=n;i++){
        for(auto k : a[i]){
            if(h[k] >= h[i]){
                ans--;
                break;
            }
        }
    }

    cout << ans;
  
	return 0;
}

Measured memory_bytes: 9804
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9) + 7
R = [0 for _ in range(N+1)]
for i in range(N):
  R[i+1] = R[i] + A[i]
S = 0
for i in range(N-1):
  S += A[i] * (R[N] - R[i+1]) % mod
  S %= mod
print(S)

Measured memory_bytes: 110128
/*input
13 17
BBABBBAABABBA
7 1
7 9
11 12
3 9
11 9
2 1
11 5
12 11
10 8
1 11
1 8
7 7
9 10
8 8
8 12
6 2
13 11
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n,m;
string s;
vector<int> edge[maxn];
vector<int> q;
int pt=0;

int A[maxn],B[maxn];

bool vis[maxn];

int main()
{
	cin>>n>>m>>s;
	while(m--){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
		if(s[v]=='A') A[u]++;
		else B[u]++;
		if(s[u]=='A') A[v]++;
		else B[v]++;
	}
	REP(i,n) if(A[i]==0||B[i]==0){
		q.pb(i);
		vis[i]=1;
	}
	while(pt<SZ(q)){
		int cur=q[pt++];
		for(int v:edge[cur]) if(!vis[v]){
			if(s[cur]=='A') A[v]--;
			else B[v]--;
			if(A[v]<=0||B[v]<=0){
				q.pb(v);
				vis[v]=1;
			}
		}
	}
	REP(i,n) if(!vis[i]){
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
	return 0;
}


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

int main(void){
    char b;
    cin >> b;
    if(b=='A') cout << 'T' << endl;
    else if(b=='T') cout << 'A' << endl;
    else if(b=='G') cout << 'C' << endl;
    else cout << 'G' << endl;
}

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

int N;
int M;
bool edge[10][10] = {0};
int ans = 0;
bool mem[10] = {0};

int DFS(int v,int n)
{
    if(n == N - 1)return 1;
    mem[v] = true;
    int res = 0;
    for(int i = 0; i < N; i++)if(edge[v][i + 1] && !mem[i + 1])res += DFS(i + 1,n + 1);
    mem[v] = false;
    return res;
}

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        edge[a][b] = edge[b][a] = true;
    }
    printf("%d\n",DFS(1,0));
    return 0;
}


Measured memory_bytes: 256
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]

def f(X):
    score = 0
    L = [-1 for j in range(26)]
    A = [0 for j in range(26)]
    for i in range(d):
        score += S[i][X[i]]
        A[X[i]] += (i - L[X[i]]) * (i - L[X[i]] - 1) // 2
        L[X[i]] = i
    for j in range(26):
        A[j] += (d - L[j]) * (d - L[j] - 1) // 2
        score -= C[j] * A[j]
    return score

X = [int(input()) - 1 for i in range(d)]
m = int(input())
for k in range(m):
    i, j = map(lambda x: int(x) - 1, input().split())
    X[i] = j
    print(f(X))


Measured memory_bytes: 76824
#include<stdio.h>

int main()
{

  int a,b,c,x;
  scanf("%d %d %d %d",&a,&b,&c,&x);
  int count = 0;

  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(x == 500*i +100*j +50*k){
          count++;
          //printf("%d %d %d\n",i,j,k);
        }
      }
    }
  }

  printf("%d",count);

  return 0;

}



Measured memory_bytes: 128
N = int(input())
A_list = tuple([[int(elem) for elem in input().split(' ')] for _ in range(2)])

max_num_candies = 0
for i in range(N):
    num_candies = sum(A_list[0][:i+1]) + sum(A_list[1][i:])
    if num_candies > max_num_candies:
        max_num_candies = num_candies

print(max_num_candies)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int n, m;
  cin >> n >> m;
  vi price(m), b(m);
  vi mask(m);
  rep (i, m) {
    cin >> price[i] >> b[i];
    rep (j, b[i]) {
      int temp;
      cin >> temp;
      temp--;
      mask[i] += (1 << temp);
    }
  }

  int ma = (1 << n);
  vl dp(ma, inf);
  dp[0] = 0;

  rep (i, ma) {
    rep (j, m) {
      int ni = i | mask[j];
      chmin(dp[ni], dp[i] + price[j]);
    }
  }

  if (dp[ma - 1] == inf) {
    cout << -1 << endl;
  }
  else {
    cout << dp[ma - 1] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n);
    rep(i, n)cin >> p.at(i);
    sort(all(p));
    int cnta = 0, cntb = 0, cntc = 0;
    rep(i, n){
        if(p.at(i) <= a)cnta++;
        else if(p.at(i) <= b)cntb++;
        else cntc++;
    }
    cout << min(cnta, min(cntb, cntc));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll N,K;
ll N_MAX=1001000;
ll A[1001000];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  ll ans=0;

  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  if(K==0){
    ll op=0;
    for(int i=1;i<=N;i++){
      op+=A[i];
    }
    cout << op << endl;
    return 0;
  }
  ll B[1000]={0};
  ll a;
  ll dp=0;
  for(int i=1;i<=N;i++){
    a=A[i];
    ll cnt=0;
    while(a>0){
      if(a%2==1){
        B[cnt]++;
        cnt++;
      }else{
        cnt++;
      }
      a/=2;
    }
  }
  ll sum=0;
  ll k=K;
  while(K>0){
    dp++;
    K/=2;
  }

  for(ll i=dp-1;i>=0;i--){
    if(N-B[i]>N/2 && (sum|(1LL<<i))<=k){
      sum+=pow(2,i);
    }
  }

  for(int i=1;i<=N;i++){
    ans+=sum^A[i];
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
x, y = map(str, input().split())
d = {'A':10, 'B':11, 'C':12, 'D':13, 'E':14, 'F':15}
 
if d[x] < d[y]:
    print('<')
elif d[x] > d[y]:
    print('>')
else:
    print('=')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main() {
  ll n,k;
  ll r,s,p;
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
//  ll ans = 0;
//  rep(i,n){
//    if(t[i] == 'r'){
//      ans += r;
//    }else if(t[i] == 's'){
//      ans += s;
//    }else{
//      ans += p;
//    }
//  }
//  ll tmp = INFLONG;
//  vector<ll> cou(3,0);
//  rep(i,3){
//    REP(j,k,n){
//      if(t[i] == 's'){
//        cou[0] += r;
//      }else if(t[i] == 'p'){
//        cou[1] += s;
//      }else{
//        cou[2] += p;
//      }
//    }
//  }
//  if(t[k-1] == 's'){
//    cou[1] += s;
//    cou[2] += p;
//  }else if(t[k-1] == 'p'){
//    cou[0] += r;
//    cou[2] += p;
//  }else{
//    cou[0] += r;
//    cou[1] += s;
//  }
//  rep(i,3){
//    chmin(tmp,cou[i]);
//  }
//  cout << ans << " " <<  tmp << endl;
//  cout << ans - tmp << endl;
  vector<ll> vec(n,0);
  ll ans = 0;
  rep(i,n){
    if(i < k){
      if(t[i] == 's'){
        ans += r;
      }else if(t[i] == 'p'){
        ans += s;
      }else{
        ans += p;
      }
      vec[i] = 1;
    }else{
      if(vec[i-k] == 1 && t[i-k] == t[i]){

      }else{
        if(t[i] == 's'){
          ans += r;
        }else if(t[i] == 'p'){
          ans += s;
        }else{
          ans += p;
        }
        vec[i] = 1;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;
int a[100005];
vector<int>v;
int sum=1e9;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i+k-1<=n;i++)
	{
		int j=i+k-1;
		int cnt=1e9;
		cnt=min(cnt,(abs(0-a[j])+abs(a[i]-a[j])));
		cnt=min(cnt,(abs(0-a[i])+abs(a[i]-a[j])));
		//cout<<cnt<<" ";
		sum=min(sum,cnt);
	}	
	cout<<sum<<endl;
	return 0;
}
/*
	5 3
	-30 -10 10 20 50
	3 2
	10 20 30
	1 1
	0
	8 5
	-9 -7 -4 -3 1 2 3 4
	
	Accepted
*/

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 305
using namespace std;

int n, m, l, q, d[N][N];

void f() {
	int i, j, k;
	for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; j++) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
}

int main() {
	int i, j, u, v, w;
	memset(d, 0x3f, sizeof(d));
	cin >> n >> m >> l;
	while(m--) {
		scanf("%d%d%d", &u, &v, &w);
		d[u][v] = d[v][u] = w;
	}
	f();
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) d[i][j] = d[i][j]<=l ? 1 : 1e9;
	f();
	cin >> q;
	while(q--) {
		scanf("%d%d", &u, &v);
		printf("%d\n", d[u][v]<1e9 ? d[u][v]-1 : -1);
	}
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, K; cin >> N >> K; --K;
	
	vll arr (N);
	F0R(i, N) cin >> arr[i];

	if (N == 1) {
		if (K % 2 == 0) {
			cout << arr[0];
		}
		return 0;
	}
	vll next (N);
	map<ll, ll> leftmost;
	R0F(i, N) leftmost[arr[i]] = i;
	map<ll, ll> temp;
	R0F(i, N) {
		if (temp.find(arr[i]) == temp.end()) {
			next[i] = leftmost[arr[i]];
		} else {
			next[i] = temp[arr[i]];
		}
		temp[arr[i]] = i;
	}

	vll its (N, -1);
	ll cur = 0;
	its[0] = 0;
	ll pos = 0;
	while (K) {
		if ((next[pos] == pos && (next[pos] == N -1))) {
			K -= 2;
			cur += 2;
		} else if ((next[pos] <= pos) || (next[pos] == N - 1)) {
			--K;
			++cur;
		}
		pos = (next[pos] + 1) % N;
		if (its[pos] != -1) break;
		its[pos] = cur;
	}
	
	if (K < 0) {
		cout << endl; return 0;
	} else if (K != 0) {
		ll loops = cur - its[pos];
		K %= loops;
	}

	while (K) {
		if ((next[pos] == pos && (next[pos] == N -1))) {
			K -= 2;
			cur += 2;
		} else if ((next[pos] <= pos) || (next[pos] == N - 1)) {
			--K;
		}
		pos = (next[pos] + 1) % N;
	}

	while ((pos < N) && (next[pos] > pos)) pos = next[pos] + 1;
	vll ans;
	while (pos < N) {
		ans.push_back(arr[pos]); 
		++pos;
		while ((pos < N) && (next[pos] > pos)) pos = next[pos] + 1;
	}
	
	for (ll x : ans) cout << x << " ";
	cout << endl;
}

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

using namespace std;

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

  string s;
  cin >> s;

  size_t ans = s.size();
  for (size_t i = 0; i < s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) {
      ans = min(ans, max(i + 1, s.size() - i - 1));
    }
  }
  cout << ans << "\n";
}


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

int main()
{
	string s;
	cin>>s;
	char curr = s[0];
	std::vector<int> front, back;
	int cl = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		if (curr != s[i])
		{
			front.push_back(cl);
			curr = s[i];
		}
		cl++;
	}
	front.push_back(cl);
	reverse(s.begin(), s.end());
	curr = s[0];
	cl = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		if (curr != s[i])
		{
			back.push_back(cl);
			curr = s[i];
		}
		cl++;
	}
	back.push_back(cl);
	// front.push_back(0);
	// back.push_back(0);
	reverse(back.begin(), back.end());
	int ans = 0;
	for (int i = 0; i < front.size(); ++i)
	{
		if (min(front[i], back[i]) > ans)
		{
			ans = min(front[i], back[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
	ModInt pow(long long n){
		ModInt r=1,x2=x;
    	while(n){
    		r*=((n%2)?x2:1);
    		x2*=x2;
    		n>>=1;
    	}
    	return r;
	}
};
typedef ModInt<1000000007> mint;
vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nPr(int n, int r) {
	if (r<0)return 0;
	return r > n ? 0 : fact[n] * factinv[n-r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

/*
異なるみたいなやつは、包除原理でいける
*/

ll n,m;
mint ans;

int main(void){
	cin>>n>>m;
	nCr_computeFactinv(500010);
	reg(i,0,n){
		ans += nPr(m,i)*nPr(m-i,n-i)*nPr(m-i,n-i)*nCr(n,i) * (i%2==0?1:-1);
	}
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
using namespace std;
using ll = long long;

inline ll sum(ll n)
{
    return (n * (n + 1)) / 2;
}

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

    ll res = 0;
    for (ll d = 1; d <= n; d++)
        res += d * sum(n / d);

    cout << res << endl;
}

Measured memory_bytes: 3196
import util.control.Breaks._

object Main extends App {
  breakable(
    while (true) {
      val amount = io.StdIn.readInt()
      if (amount == 0) break()
      var change = 1000 - amount
      var count = 0
      val coins = Array(500,100,50,10,5,1)
      coins foreach {c => while (change >= c) {change -= c; count += 1}}
      println(count)
    }
  )
}


Measured memory_bytes: 43692
n,m,v[10000],w[2500],W[2500],o;x,y,r;F(a){r=1;for(a=m*m;a--;)if(~w[a]&&v[x+a%m+n*(y+a/m)]-w[a])r=0;}main(d,t,f){for(;scanf("%d%d",&n,&m)*n;printf(f<n*n?"%d %d\n":"NA\n",1+f%n,1+f/n)){for(f=0;f<n*n;f++)scanf("%d",v+f);for(x=0;x<m*m;x++)scanf("%d",w+x);for(d=4;d--;){memcpy(W,w,4*m*m);for(x=m*m;x--;o=~w[x]?x:o)w[x]=W[m-1-x/m+x%m*m];for(y=0;y+m<=n;y++)for(x=0;x+m<=n;x++)if(F(),r&&(t=x+o%m+(n+o/m)*y)<f)f=t;}}}

Measured memory_bytes: 472
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
#endif
    crap;

    int k;
    cin >> k;

    int a, b;
    cin >> a >> b;

    int largest = (b / k) * k;

    if (a <= largest)
        cout << "OK";
    else {
        cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
//reversing.cpp
#include<iostream>
using namespace std;

int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for ( i = 1; i <= n; i++) cin>>a[i];
    for ( i = n; i > 1; i--) cout<<a[i]<<" ";
    cout<<a[1]<<endl;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

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;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3==0&&i%5==0){

        }
        else if(i%3==0){

        }
        else if(i%5==0){

        }
        else{
            ans+=i;
        }
    }
    cout<<ans<<endl;
    
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int H = 105;
const int N = H * H;

int h, w;
int n;
int a[N];
int res[H][H];

void run() {
    cin >> h >> w;
    cin >> n;
    rep(i, 1, n + 1) {
        cin >> a[i];
    }
    vector<pair<int, int>> ord;
    rep(j, 0, w) {
        if (j & 1) {
            rep(i, 0, h) ord.pb({i, j});
        } else {
            per(i, h - 1, 0) ord.pb({i, j});
        }
    }
    int ptr = 0;
    assert(sz(ord) == h * w);
    rep(i, 1, n + 1) {
        rep(j, 0, a[i]) {
            auto it = ord[ptr++];
            res[it.first][it.second] = i;
        }
    }
    rep(i, 0, h) {
        rep(j, 0, w) {
            cout << res[i][j] << " ";
        }
        cout << "\n";
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <stack>
#include <string>

using namespace std;

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

    string str;
    cin >> str;

    int open_paren = 0;
    stack<char> s;
    for (int i = 0; i < n; ++i) {
        switch (str[i]) {
            case '(':
                s.push(str[i]);
                break;
            case ')':
                if (s.empty())
                    ++open_paren;
                else
                    s.pop();
                break;
        }
    }

    for (int i = 0; i < open_paren; ++i)
        cout << '(';
    cout << str;

    while (!s.empty()) {
        cout << ')';
        s.pop();
    }
    cout << '\n';
}


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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    const int MOD = 998244353;

    signed n;
    scanf("%d",&n);
    int ans=1;
    rep(i,n){
        int a;
        scanf("%lld",&a);
        if(a==0){
            printf("0\n");
            return 0;
        }
        if(ans==-1||a>1000000000000000000/ans){
            ans=-1;
        }
        else ans*=a;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3828
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}




int main(){

    ios_base::sync_with_stdio(0);

    string str;
    cin>>str;

    stack<char> st;
    int n = str.length();
    for(int i=0;i<n;i++){
        st.push(str[i]);
        while(1){
            if(st.size() < 2)   break;
            char ch = st.top();
            st.pop();
            if(st.top() == 'S' && ch == 'T'){
                st.pop();
                continue;
            }
            st.push(ch);
            break;
        }
    }

    cout<<st.size();
    return 0;
}






Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
int roundUp(int numToRound, int multiple)
{
 if(multiple == 0)
 {
  return numToRound;
 }

 int roundDown = ( (int) (numToRound) / multiple) * multiple;
 int roundUp = roundDown + multiple; 
 int roundCalc = roundUp;
 return (roundCalc);
}
int main()
{
	int n;
	scanf("%d", &n);
	if(n % 1000 != 0) {
	int temp = roundUp(n, 1000);
	int ans = temp - n;
	printf("%d\n", ans);
	}
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
const ll INF = 1e18;

int main()
{
	ll int n;
  	cin>>n;
  	n=n%10;
  if(n==2||n==4||n==5||n==7||n==9)
    cout<<"hon";
  else if(n==0||n==1||n==6||n==8)
    cout<<"pon";
  else if(n==3)
    cout<<"bon";
  
}

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

int main() {
	long long  a, b;
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
		return 0;
	}
	cout << ((b - a + 1) % 2 == 0 ? "Positive" : "Negative") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int X[100000 + 10];
vi diff;

signed main(void) {
    int N, M; cin >> N >> M;
    int ma, mi;
    rep(i, M) {
        cin >> X[i];
        if (i==0) {
            ma = X[0];
            mi = X[0];
        } else {
            if (ma < X[i]) ma = X[i];
            if (mi > X[i]) mi = X[i];
        }
    }
    sort(X, X+M);
    rep(i, M-1) {
        diff.push_back(X[i+1]-X[i]);
    }
    sort(all(diff));
    reverse(all(diff));
    // cout << ma << ", " << mi << endl;
    // for (auto e : diff) cout << e << endl;
    int ans = ma - mi;
    rep(i, N-1) {
        if (ans > 0) ans -= diff[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

const long long int llinf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

#define Endl endl
#define pr(x) cout << x << endl
#define FOR(i,a,b) for(int i = a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define atcoder int(1e9) +7;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
#define all(x) x.begin,x.end();

int main() {
	
	int n;
	cin >> n;
	ll a[100010];
	rep(i, n)cin >> a[i];

	int cnt = 0;
	bool up = false, down = false;
	rep(i, n - 1) {
		if (up) {
			if (a[i] > a[i + 1]) {
				cnt++;
				up = false;
			}
		}
		else if (down) {
			if (a[i] < a[i + 1]){
				cnt++;
				down = false;
			}
		}

		else if (a[i] < a[i + 1]) up = true;
		else if (a[i] > a[i + 1])down = true;
	}
	pr(++cnt);

	return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();

        int num = Integer.parseInt(line);
        
		if (num < 1200) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}
	}
}

Measured memory_bytes: 8148