akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

void solve(){
	int n,k; cin >> n >> k;
	set<int> s;
	f(i,0,k){
		int x; cin >> x;
		f(j,0,x){
			int y; cin >> y;
			s.insert(y);
		}
	}
	int ans = 0;
	f(i,1,n+1){
		if(s.find(i) == s.end()) ans++;
	} 
	cout << ans;
}

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








Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define MAX 200005
#define INF (1<<26)
 
int segN=1000000;
struct data{
  int value;
  data* ch[2];
  
  void init(){
    value=INF;
    ch[0]=(data*)malloc(sizeof(data));
    ch[1]=(data*)malloc(sizeof(data));
    ch[0]->ch[0]=NULL;
    ch[1]->ch[0]=NULL;
  }
   
  void set(int i,int x,int l,int r){
    int m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(i<l || r<=i)return;
    if(x<value)value=x;
    if(r-l==1)return;
    ch[0]->set(i,x,l,m);
    ch[1]->set(i,x,m,r);
  }
    
  void set(int i,int x){
    set(i,x,0,segN);
  }
    
  int min(int a,int b,int l,int r){
    int m=(l+r)/2;
    if(ch[0]==NULL)init();
    if(b<=l || r<=a)return INF;
    if(a<=l && r<=b)return value;
    int lc=ch[0]->min(a,b,l,m);
    int rc=ch[1]->min(a,b,m,r);
    return (lc<rc?lc:rc);
  }
  
  int min(int a,int b){
    if(0<=a&&a<b)return min(a,b,0,segN);         
    else return INF;
  }
};
  
  
    
  
  
  
  
  
 
 
int rak[MAX+1];
int tmp[MAX+1];
int n,k;
 
bool compare_sa(int i,int j){
  if(rak[i]!=rak[j])return (rak[i]<rak[j]);
  else{
    int ri=(i+k<=n?rak[i+k]:-1);
    int rj=(j+k<=n?rak[j+k]:-1);
    return ri < rj;
  }
}
 
void construct_sa(string s,int *sa){
  n=s.size();
  for(int i=0;i<=n;i++){
    sa[i]=i;
    rak[i]=(i<n?s[i]:-1);
  }
  for(k=1;k<=n;k*=2){
    sort(sa,sa+n+1, compare_sa );
    tmp[sa[0]]=0;
    for(int i=1;i<=n;i++){
      tmp[sa[i]]=tmp[sa[i-1]]+
        (compare_sa(sa[i-1],sa[i])?1:0);
    }
    for(int i=0;i<=n;i++)rak[i]=tmp[i];
  }
}
 
 
int search(string &target,int *sa,string s){
  int l=0,r=n,m;
  int size=target.size(),res;
  while(l<r){
    m=(l+r)/2;
    res=s.compare(sa[m],size,target);
    if(res>=0)r=m;
    else l=m+1;
  }
  if(s.compare(sa[l],size,target)<0)return n+1;
  return l;
}
 
int search2(string &target,int *sa,string s){
  int l=0,r=n,m;
  int size=target.size(),res;
  while(l<r){
    m=(l+r)/2;
    res=s.compare(sa[m],size,target);
    if(res>0)r=m;
    else l=m+1;
  }
  if(s.compare(sa[l],size,target)<=0)return n+1;
  return l;
}
 
data T,T2;
string s,s2;
string x,y;
int m;
int sa[MAX+1];
int sa2[MAX+1];
 
int main(){
  ios::sync_with_stdio(false);
    
  T.init();
  T2.init();

  cin>>s;
  s2=s;
  reverse(s2.begin(),s2.end());
   
  construct_sa(s2,sa2);
  construct_sa(s,sa);
 
  for(int i=0;i<=n;i++){
    //cout<<i<<' '<<sa[i]<<' '<<s.substr(sa[i])<<endl;
  }
  for(int i=0;i<=n;i++){
    //cout<<i<<' '<<sa2[i]<<' '<<s2.substr(sa2[i])<<endl;
  }
   
  for(int i=0;i<=n;i++){
    T.set(i,sa[i]);
    T2.set(i,sa2[i]);
  }
   
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    reverse(y.begin(),y.end());
    int xl=search(x,sa,s),xr=search2(x,sa,s);
    int yl=search(y,sa2,s2),yr=search2(y,sa2,s2);
    int xs=x.size();
    int X=T.min(xl,xr);
    int Y=T2.min(yl,yr);
    if(Y!=INF)Y=n-Y;
     
    //cout<<xl<<' '<<xr<<' '<<X<<endl;
    //cout<<yl<<' '<<yr<<' '<<Y<<endl;
 
    if(Y<X+xs)cout<<0<<endl;
    else if(X==INF||Y==INF)cout<<0<<endl;
    else cout<<Y-X<<endl;
     
  }
     
  return 0;
}

Measured memory_bytes: 55260
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 
int main(){
	//in_o();
 	string s;
 	cin>>s;
 	MPII hsh;
 	int n=s.length();
 	FOR(i,0,n){
 		hsh[s[i]-'a']++;
 	}
 	FOR(i,0,26){
 		if(hsh[i]>1)
 			return cout<<"no"<<endl,0;
 	}
 	cout<<"yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
int main(){
	int given;
  	int happy=0;
  	int rem,ans;
  
  	scanf("%d",&given);
  	ans=given/500;
  	rem=given%500;
  
  	happy=ans*1000;
  
  	ans=rem/5;
  
  	happy=happy+(ans*5);
  	printf("%d",happy);
}

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

int gcd(int a, int b){

int p,q,r;
if(a<b){p=b;b=a;a=p;

}
   while((r=b%a)!=0){
   b=a;
   a=r;
   }
   return a;
}

int main(void)
{
    int a, b;
   while(cin >> b >> a) {
     int lcm = a/gcd(a,b)*b;
     cout << gcd(a,b) << " " << lcm << endl;
   }
   return 0;
}


Measured memory_bytes: 3004
import Control.Monad
solver a b c d e k = if k >= e-a then "Yay!\n" else ":(\n"

main::IO()
main=do
  [a,b,c,d,e,k]<- forM [1..6] (\_->return.read=<<getLine)
  putStr (solver a b c d e k)


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

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

    int n;
    while(cin >> n && n){
        int ans1 = 0;
        int ans2 = 0;
        for(int i = 0; i < n; ++i){
            int num;
            int d1, d2;
            cin >> num >> d1 >> d2;
            int d = d1 + d2;
            if(ans2 < d){
                ans1 = num;
                ans2 = d;
            }
        }
        cout << ans1 << " " << ans2 << endl;
    }

   return 0;
}

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

int main(){
	vector<int> a(3);
    for(int i=0;i<3;i++)cin>>a[i];
    for(int i=0;i<2;i++){
        if(a[i]>=a[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> v[n+1];
    
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    
    
    bool ans=false;
   
    for(int i=0;i<v[0].size();i++){
        int next1=v[0][i];
        for(int j=0;j<v[next1].size();j++){
            if(v[next1][j]==n-1){
                ans=true;
                break;
            }
        }
        
        if(ans==true){break;}
    }
    
   
    cout<<(ans==true?"POSSIBLE":"IMPOSSIBLE")<<endl;
    return 0;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;

int n, m;

int main ()
{
  prep();
  
  cin >> n >> m;
  vector<int> graph[n+1];
  vector<int> rev[n+1];
  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      rev[b].push_back(a);
  }
  int shortest = 1000000000;
  int path[1000];
  
  for (int i=1; i<=n; i++){
      int leads[1001][1001];
      int dists[n+1];
      bool vis[n+1] = {false};
      queue<pair<int, int > > q;
      q.emplace(i, 0);
      bool did = false;
      while (!q.empty()){
          pair<int, int > p = q.front();
          q.pop();
          int node = p.first;
          int dist = p.second;
          if (node == i && dist != 0){
              if (shortest > dist){
                  shortest = dist;
                  did = true;
              }
              break;
          }
          if (vis[node]){
              continue;
          }
          vis[node] = true;
          dists[node] = dist;
          for (int j=0; j<graph[node].size(); j++){
              q.emplace(graph[node][j], dist+1);
              leads[graph[node][j]][dist] = node;
          }
      }
      if (!did){
          continue;
      }
      int len = 0;
      // recover path
      int curdist = shortest;
      int curnode = i;
      while (curdist >= 0){
          curdist--;
          path[len] = curnode;
          len++;
          curnode = leads[curnode][curdist];
      }
      
  }
  if (shortest == 1000000000){
      cout << -1;
  }else{
      cout << shortest << '\n';
      for (int i=0; i<shortest; i++){
          cout << path[i] << '\n';
      }
  }
  return 0; 
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
    int a,b=1,c;
    while(1){
        scanf("%d%d\n",&a,&b);
        if(a == 0 && b == 0){break;}
        else if(a > b)printf("%d %d\n",b,a);
        else printf("%d %d\n",a,b);
        
    }
    return 0;
}


Measured memory_bytes: 2048
from collections import deque


def solve_f(n, g):

    for i in range(n):
        parent = [-1] * n
        queue = deque([i])
        done = False
        answer = []
        # bfs
        while len(queue) > 0:
            p = queue.popleft()
            for q in g[p]:
                if q == i:
                    r_list = []
                    r = p
                    while r != -1:
                        r_list.append(r)
                        r = parent[r]
                    # check
                    check = 1
                    for r in r_list:
                        check = max(len(set(g[r]).intersection(r_list)), check)
                    if check == 1:
                        return [len(r_list)] + [r + 1 for r in r_list]
                elif parent[q] == -1:
                    parent[q] = p
                    queue.append(q)

    return [-1]


def main():
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        g[a - 1].append(b - 1)
    res = solve_f(n, g)
    for r in res:
        print(r)


if __name__ == "__main__":
    main()

Measured memory_bytes: 45420
from itertools import product
H, W, K = map(int, input().split())
G = [list(map(int, list(input()))) for _ in range(H)]

ans = float("inf")

for pattern in product([0, 1], repeat = H - 1):
    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
    rows = []
    for i in range(len(div) - 1):
        row = []
        for j in range(W):
            tmp = 0
            for k in range(div[i], div[i + 1]):
                tmp += G[k][j]
            row.append(tmp)
        rows.append(row)
        
    flag = True
    for row in rows:
        if [r for r in row if r > K]:
            flag = False
            break
    if not flag:
        continue

    tmp_ans = 0
    cnt = [0] * len(rows)
    w = 0

    while w < W:
        for r in range(len(rows)):
            cnt[r] += rows[r][w]
        if [c for c in cnt if c > K]:
            cnt = [0] * len(rows)
            tmp_ans += 1
            w -= 1
        w += 1
    
    tmp_ans += pattern.count(1)
    ans = min(ans, tmp_ans)

print(ans)

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n;
char A[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	cin >> A+1;
	int r = 0, w = 0;
	int r2 = 0, w2 = 0;
	for(int i=1; i<=n; i++) {
		if(A[i] == 'W') w2++;
		if(A[i] == 'R') r2++;
	}
	int ans = INF;
	for(int i=0; i<=n; i++) {
		if(A[i] == 'W') w++, w2--;
		if(A[i] == 'R') r++, r2--;

		int cnt = w + r2 - min(w, r2);
		ans = min(ans, cnt);
	}
	cout << ans;
}

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

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

  for(int i=0;i<n;++i){
    cout << a[i] << " ";
  }
  
  return 0;
}

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

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    for (ll y = sy; y < ty; y++) {
        cout << "U";
    }
    
    for (ll x = sx; x < tx; x++) {
        cout << "R";
    }
    
    for (ll y = sy; y < ty; y++) {
        cout << "D";
    }
    
    for (ll x = sx; x < tx; x++) {
        cout << "L";
    }
    
    cout << "L";
    
    for (ll y = sy; y <= ty; y++) {
        cout << "U";
    }
    
    for (ll x = sx; x <= tx; x++) {
        cout << "R";
    }
    
    cout << "DR";
    
    for (ll y = sy; y <= ty; y++) {
        cout << "D";
    }
    
    for (ll x = sx; x <= tx; x++) {
        cout << "L";
    }

    cout << "U" << endl;

    return 0;
}



Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto a = readints;
    int r = a[0], g = a[1], b = a[2], n = a[3];

    int ans = 0;
    for (int i = 0; i * r <= n; i++) {
        for (int j = 0; j * g <= n; j++) {
            int m = n - (i * r + j * g);
            if (m < 0) break;

            if (m % b == 0) ans++;
        }
    }
    writeln(ans);
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,T,cas=0;
    cin>>a;
    cout<<a+(a*a)+(a*a*a);
    return 0;
}

Measured memory_bytes: 3648
/*
 *
 * Copyright(c) 2016 Taikai Takeda <297.1951@gmail.com> All rights reserved.
 *
 */
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string text;
    cin >> text;

    vector<int> dp(text.size()+1, 0);
    dp[0] = 1;
    string pat[] = {"dream", "dreamer", "erase", "eraser"};
    int n_pat = 4;

    for (int i = 0; i < text.size(); i++) {
        if(dp[i] == 1){
            for (int j = 0; j < n_pat; j++) {
                if (pat[j].size() + i <= text.size() &&
                    text.compare(i, pat[j].size(), pat[j]) == 0)
                    dp[i+pat[j].size()] = 1;
            }
        }
    }

    if (dp[text.size()])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;


    return 0;
}


Measured memory_bytes: 848
//
//  single_source_shortest_path.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/10.
//

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

#define MAX 3000
#define INF 20000000

using namespace std;

typedef long long ll;

int main()
{
    int V,E,r;
    ll s[MAX],t[MAX],d[MAX];
    cin>>V>>E>>r;
    for(int i=0;i<E;i++) cin>>s[i]>>t[i]>>d[i];
    
    ll min[MAX];
    for(int i=0;i<V;i++) if(i!=r) min[i]=INF;
    
    min[r]=0;
    
    bool flag;
    for(int cnt=0;cnt<V;cnt++)
    {
        flag=false;
        for(int i=0;i<E;i++)
        {
            if(min[s[i]]!=INF&&min[t[i]]>min[s[i]]+d[i])
            {
                min[t[i]]=min[s[i]]+d[i];
                flag=true;
            }
        }
    }
    
    if(flag) cout<<"NEGATIVE CYCLE"<<endl;
    else
    {
        for(int i=0;i<V;i++)
        {
            if(min[i]==INF) cout<<"INF"<<endl;
            else            cout<<min[i]<<endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    //1 0 1 0 1 という形にする
    vector<int> v;
    if (s[0] == '0') v.push_back(0);
    int c = 1;
    rrep(i, 1, s.size()) {
        if (s[i] != s[i - 1]) {
            v.push_back(c); //前の分を
            c = 1;
        } else {
            c++;
        }
    }
    if (c) v.push_back(c);
    if (s[s.size() - 1] == '0') v.push_back(0);
    //rep(i, v.size()) cout << v[i] << " "; cout << endl;
    int add = 2 * k + 1; //半開区間
    int ans = 0;
    for (int i = 0; i < v.size(); i += 2) {
        int right = min((int)v.size(), i + add);
        int tmp = 0;
        rrep(j, i, right) {
            tmp += v[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	string s[3];
	rep(i, 3) cin >> s[i];
	rep(i, 3) cout << s[i][0];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll ans=n*n*n;
    cout<<ans;
}


Measured memory_bytes: 256
import itertools
import math
n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

A = list(itertools.permutations(list(range(1, n+1))))
A.sort()
p = None
q = None
for i in range(math.factorial(n)):
    if P == list(A[i]):
        p = i+1
    if Q == list(A[i]):
        q = i+1
    if p and q:
        print(abs(p - q))
        exit()

Measured memory_bytes: 79996
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;



int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    sort(a.begin(),a.end(),greater<ll>());
    vector<int> cnt(n,2);
    cnt[0] = 1;
    int id = 0;
    rep(i,n-1){
        ans += a[id];
        cnt[id] --;
        if(cnt[id]==0) ++ id;
    }

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

Measured memory_bytes: 5576
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-23 14:48:50
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=10010;
const i64 inf=1ll<<50;
i64 n,a,b,p[N],f[N],F[N],ans;
int main()
{
	n=read(); a=read(); b=read(); ans=inf;
	fr(i,1,n) p[read()]=i;
	fr(i,1,n*2+1) f[i]=i<p[1]*2?b:i==p[1]*2?0:a;
	fr(i,2,n)
	{
		fr(j,1,n*2+1){ F[j]=f[j]; f[j]=inf; }
		i64 mf=inf;
		fr(j,1,n*2+1)
		{
			if(j&1) mf=std::min(mf,F[j]);
			f[j]=mf+(j<p[i]*2?b:j==p[i]*2?0:a);
			if(!(j&1)) mf=std::min(mf,F[j]);
		}
	}
	fr(i,1,n*2+1) ans=std::min(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <iomanip>

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

using namespace std;

int main() {
  int D, N;
  cin >> D >> N;

	int ans = 1;
	for (int i = 0; i < D; i++) ans *= 100;
	if (N == 100) cout << ans * N + 1 * ans << endl;
	else cout << ans * N << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[105];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){
				int temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
	}
	}
	int sum=0;
	for(int i=0;i<n;i++){
		if(a[i]!=a[i+1]){
			sum++;
		}
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
n, m, l = gets.chomp.split(' ').map(&:to_i)

array_a = []
array_b = []
array_c = Array.new(n) { Array.new(l, 0) }
n.times do |i|
  array_a[i] = gets.chomp.split(' ').map(&:to_i)
end
m.times do |j|
  array_b[j] = gets.chomp.split(' ').map(&:to_i)
end

n.times do |i|
  l.times do |j|
    m.times do |k|
      array_c[i][j] += array_a[i][k] * array_b[k][j]
    end
  end
end

array_c.each do |c_row|
  puts c_row.join(' ')
end


Measured memory_bytes: 8908
#include<iostream>
using namespace std;
int f(int x){
    return x*x;
}
int g(int k,int d){
    int s = f(k*d) * d;
    //cout << s <<endl;
    return s;
}
int main(){
    int n = 0;
    int d[20];
    int s[20];
    while(cin >> d[n]){
        n++;
    }
    for(int i = 0;i < n ;i++){
        s[i] = 0;
        for(int j = 1;j < 600 / d[i] ;j++ ){
            s[i] += g(j,d[i]);
        }
        cout << s[i] << endl; 
    }
    return 0;

}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	
  return 0;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"

using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 10000000;
const ll inf = 5e18-1;
	
	
	
int main() {
	fastio;
	
	ll n;
    cin >> n;

    vi h(n);
    f(i, 0, n) {
        cin >> h[i];
    }
    ll ans = 0;
    ll cnt = 0;
    f(i,0, n-1) {
        if (h[i] >= h[i+1]) {
            cnt++;
            ans = max(ans, cnt);
        } else {
            cnt = 0;
        }
    }
    ans = max(ans, cnt);

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

Measured memory_bytes: 1024
def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r,1):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp

    A[r] = A[i+1]
    A[i+1] = x
    return i+1

def main():
    n = int(input())
    A = list(map(int,input().split()))

    q = partition(A,0,n-1)

    #A = map(str,A)
    A[q] = '[' + str(A[q]) + ']'
    A = map(str,A)
    print(' '.join(A))


main()



Measured memory_bytes: 16388
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
 
#ifdef TOAD
#define IOS()
#define bug(x) cerr<<"Line "<<__LINE__<<": "<<#x<<" is "<<x<<endl
#else 
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define bug(x)
#endif 
const ll inf=(1ll<<60);
const double PI=acos(-1);
const int iinf=2147483647;
const ll mod=1e9+7;
const ll maxn=1e5+5;
ll pw(ll x, ll p){
	ll ret=1;
	while(p>0){
		if (p&1){
			ret*=x;
			ret%=mod;
		}
		p>>=1;
		x*=x;
		x%=mod;
	}
	return ret;
}
int op(int a, int qq){
	if (qq==0){
		return a;
	}
	else if (qq==1){
		return (a*3+1)%mod;
	}
	int x=a*pw(3,qq)%mod;
	int y=pw(3,qq-1)*qq%mod;
	return (x+y)%mod;
}
signed main(){
	IOS();
	string str; cin>>str;
    int n=SZ(str);
	int sum=0;
	int as=0, qs=0;
	vector<pii> vc(n);
	RREP(i,n){
		if (i==n-1) {
			vc[i]={0,0};
		}
		else{
			vc[i]={vc[i+1].f+(str[i+1]=='C'), vc[i+1].s+(str[i+1]=='?')};
		}
	}
	FOR(i,0,n){
		//cout<<vc[i].f<<' '<<vc[i].s<<endl;
 
		int va=op(as, qs);
		int vb=op(vc[i].f, vc[i].s);
		if (str[i]=='?'||str[i]=='B') sum+=va*vb%mod;
		sum%=mod;
		if (str[i]=='A'){
			as++;
		}
		else if (str[i]=='?') qs++;
		
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 4972
#include<string>
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		int cnt=0;
		while(s.size()!=1){
			string t=s.substr(s.size()-2);
			//cout<<t<<endl;
			int x=atoi(t.c_str());
			//cout<<x<<endl;
			s=s.substr(0,s.size()-2);
			//cout<<" "<<x<<endl;
			int a=x%10;
			int b=(x-a)/10;
			a+=b;
			if(a/10){
				s+='1';
			}
			a%=10;
			s+=('0'+a);
			//cout<<s<<endl;
			cnt++;
		}
		if(cnt%2){
			cout<<"Fabre wins."<<endl;
		}else
		cout<<"Audrey wins."<<endl;
		//cout<<cnt<<endl;
	}
	return 0;
}

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

int even(unsigned long *A,int N);

int main(){
    int N;
    unsigned long A[200];
    int o=0;

    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    while(even(A,N)){
        for(int i=0;i<N;i++) A[i]=A[i]/2;
        o++;
    }
    cout << o;
    return 0;
}

int even(unsigned long *A,int N){
    int even=0;
    for(int i=0;i<N;i++){
        even+=A[i]%2;
    }
    if(even==0){
        return 1;
    }
    else{
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,x,m;
	int min = 10000;
	int sum = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++){
		cin >> m;
		if (m < min) min = m;
		sum += m;
	}
	cout << n + (x-sum)/min << endl;
}

Measured memory_bytes: 256
s = int(input())
a = s
aList = [a]
for m in range(2, 10**6 + 1):
    if a % 2 == 0:
        a = a//2
    else:
        a = 3*a + 1
    if a in aList:
        print(m)
        break
    aList.append(a)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> X(N),Y(N);
    rep(i,N) cin >> X[i] >> Y[i];

    vector<pll> A(N);
    rep(i,N) {
        A[i].first = X[i]+Y[i];
        A[i].second = X[i]-Y[i];
    }
    sort(all(A));
    ll L = -1e18;
    int ans = 0;
    rep(i,N) {
        if (L<=A[i].second) {
            ans++;
            L = A[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, l := nextInt(), nextInt()

	apps := make([]int, 0, n)

	c := 99999

	var re int
	for index := 1; index <= n; index++ {
		v := l + index - 1
		k := int(math.Abs(float64(v)))
		if k < int(math.Abs(float64(c))) {
			c = v
		}

		apps = append(apps, l+index-1)
	}

	for _, item := range apps {
		if item == c {
			continue
		}
		re += item
	}

	fmt.Printf("%#v\n", re)
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w; cin >> h >> w;
    int ans = 0;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(si,h) rep(sj,w) {
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w,INF));
        queue<pint> q;
        auto update = [&](int i, int j, int x) {
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(pint(i,j));
        };
        update(si,sj,0);
        while(!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir,4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
                if(s[ni][nj] == '#') continue;
                update(ni,nj,dist[i][j]+1);
            }
        }
        rep(i,h) rep(j,w) {
            if(dist[i][j] == INF) continue;
            ans = max(ans,dist[i][j]);
        }
    }
    cout << ans << 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 rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
typedef long long ll;
const int INF=1e+09;
ll A,B,C,D;

ll rec(ll c){
    ll ans;
    ans=B/c-A/c;
    if(A%c==0) ans++;
    return ans;
}
int main(){    
    //入力
    cin >> A >> B >> C >> D;
    ll ans=B-A+1;
    ll CD=C/__gcd(C,D)*D;
    ans-=(rec(C)+rec(D)-rec(CD));
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;

	if (B >= A * C)
		cout << C << endl;
	else
		cout << B / A << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
s = []
for i in range(N):
    tmp = input().split()
    tmp .append(i+1)
    tmp[1] = int(tmp[1])
    s.append(tmp)

s.sort(key=lambda x: x[1], reverse=True)
s.sort(key=lambda x: x[0])
for x in s:
    print(x[2])

Measured memory_bytes: 3060
n = int(input())
A = list(map(int,input().split()))
ans = 1
for a in A:
  if a % 2 == 0:
    if not(a % 3 == 0 or a % 5 == 0):
      ans = 0
      break
      
if ans == 1:
  print("APPROVED")
else:
  print("DENIED")
  




Measured memory_bytes: 9108
def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 119500
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
using namespace std;
typedef long long ll;
ll ans=0;
ll a[100004],b[100004];
int main(){
	int n,m;cin>>n;
	for (int i=0;i<n+1;i++) cin>>a[i];
	for (int i=0;i<n;i++){
		cin>>b[i];
		if (b[i]<=a[i]) a[i]-=b[i],ans+=b[i];
		else{
			ll o=b[i]-a[i];
			if (o>=a[i+1]){
				ans+=a[i]+a[i+1];a[i+1]=0; 
			}else{
				a[i+1]-=o;
				ans+=b[i];
			}
			a[i]=0;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<string> result;

  while (true) {
    cin >> n;
    if (n == 0)
      break;

    map<string, long long> m;
    bool hoge = true;
    for (int i = 0; i < n; i++) {
      string id;
      long long a, b;
      cin >> id >> a >> b;
      if (m[id] < 1000000 && m[id] + a * b >= 1000000) {
        result.push_back(id);
        hoge = false;
      }
      m[id] += a * b;
    }
    if (hoge)
      result.push_back("NA");
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 1340
#include"stdio.h"

int main() {
	int n, y,i,j,sum=0,count=0,a,b,c;
	scanf("%d %d",&n,&y);
	for(i = 0; i <= n; i++){
		for(j = i; j <= n; j++){
			sum = 10000 * i + 5000 * (j - i) + 1000 * (n - j);
			if(sum == y){
				count++;
				a=i;
				b=j-i;
				c=n-j;
			}
		}
	}
	if(count>0)printf("%d %d %d\n",a,b,c);
	else printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int a[10];
  for(int i=0;i<10;i++){
    cin>>a[i];
  }

  int temp;
  for(int i=9;i>=7;i--){
    for(int j=0;j<i;j++){
        if(a[i]<a[j]) {
          temp=a[i];
          a[i]=a[j];
          a[j]=temp;}
    }
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    int n;
    ArrayList<ArrayList<Edge>> ns;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ns = new ArrayList<>(n+1);
        for (int i = 0; i < n+1; i++)
            ns.add(new ArrayList<>());
    }

    private void solve() {
        for (int i = 0; i < n+1; i++) {
            int nxt = (i + 1) % n;
            int nxt2 = (i * 10) % n;
            ns.get(i).add(new Edge(i, nxt, 1));
            ns.get(i).add(new Edge(i, nxt2, 0));
        }
        int[] ds = new int[n+1];
        Arrays.fill(ds, n+1);
        Deque<Edge> deq = new ArrayDeque<>();
        ds[1] = 1;
        for (Edge e: ns.get(1))
            if (e.c == 0) deq.addFirst(e);
            else deq.addLast(e);
        while (!deq.isEmpty()) {
            Edge e = deq.pollFirst();
            int dist = ds[e.cur] + e.c;
            ds[e.to] = Math.min(dist, ds[e.to]);
            for (Edge nxt: ns.get(e.to)) {
                if (ds[nxt.to] > ds[e.to] + nxt.c) {
                    if (nxt.c == 0)
                        deq.addFirst(nxt);
                    else
                        deq.addLast(nxt);
                }
            }
        }
        System.out.println(ds[0]);
    }

    private class Edge {
        int cur;
        int to;
        int c;
        Edge (int cur, int to, int c) {
            this.cur = cur;
            this.to = to;
            this.c = c;
        }
    }
}


Measured memory_bytes: 56404
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct Area {
  ll area;
  bool visited;
  bool cango[4];
  Area(){
    area = 0;
    visited = false;
    rep(i,4) cango[i] = true;
  }
};

//down, up, right, left
int vx[4] = {1,-1,0,0};
int vy[4] = {0,0,1,-1};

Area field[3005][3005];


int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<ll>> v, w;

  map<ll,int> zx, zy;
  zx[-1000000005] = 1;
  zx[0] = 1;
  zx[1000000005] = 1;
  zy[-1000000005] = 1;
  zy[0] = 1;
  zy[1000000005] = 1;
  
  rep(i,N){
    ll a, b, c;
    cin >> a >> b >> c;
    v.push_back({a,b,c});
    zx[a] = 1;
    zx[b] = 1;
    zy[c] = 1;
  }
  rep(i,M){
    ll d, e, f;
    cin >> d >> e >> f;
    w.push_back({d,e,f});
    zx[d] = 1;
    zy[e] = 1;
    zy[f] = 1;
  }
  
  map<int,ll> rzx, rzy;
  int height = 0, width = 0;
  {
    FOR(it,zx){
      rzx[height] = it->first;
      it->second = height++;
    }
  }
  {
    FOR(it,zy){
      rzy[width] = it->first;
      it->second = width++;
    }
  }
  
  rep(i,height){
    rep(j,width){
      if(i==0 || j==0 || i==height-1 || j==width-1){
        field[i][j].area = -1;
      }else{
        ll x = rzx[i];
        ll y = rzy[j];
        ll xx = rzx[i+1];
        ll yy = rzy[j+1];
        field[i][j].area = (xx-x) * (yy-y);
      }
    }
  }

  rep(i,N){
    int x = zx[v[i][0]];
    int xx = zx[v[i][1]];
    int y = zy[v[i][2]];
    REP(j,x,xx){
      if(y-1>=0) field[j][y-1].cango[2] = false;
      field[j][y].cango[3] = false;
    }
  }
  rep(i,M){
    int x = zx[w[i][0]];
    int y = zy[w[i][1]];
    int yy = zy[w[i][2]];
    REP(j,y,yy){
      if(x-1>=0) field[x-1][j].cango[0] = false;
      field[x][j].cango[1] = false;
    }
  }
  
  queue<pair<int,int>> que;
  int zero_x = zx[0], zero_y = zy[0];
  que.push(make_pair(zero_x-1, zero_y-1));
  que.push(make_pair(zero_x-1, zero_y));
  que.push(make_pair(zero_x, zero_y-1));
  que.push(make_pair(zero_x, zero_y));

  ll ret = 0;
  while(!que.empty()){
    /*
    rep(i,height){
      rep(j,width){
        if(field[i][j].visited) cout << "*";
        else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
      */

    pair<int,int> p = que.front(); que.pop();
    if(p.first < 0 || p.second < 0){
      ret = -1;
      break;      
    }
    if(field[p.first][p.second].visited) continue;
    field[p.first][p.second].visited = true;
    if(field[p.first][p.second].area < 0){
      ret = -1;
      break;
    }
    ret += field[p.first][p.second].area;
    rep(k,4){
      int nx = p.first + vx[k];
      int ny = p.second + vy[k];
      if(nx<0 || ny<0) continue;
      if(field[p.first][p.second].cango[k]){
        if(!field[nx][ny].visited){
          que.push(make_pair(nx, ny));
        }
      }
    }
  }

  if(ret < 0){
    cout << "INF" << endl;
  }else{
    cout << ret << endl;
  }
  
  return 0;
}



Measured memory_bytes: 145568
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

using li = long long;
using ld = long double;

#define all(v) (v).begin(), (v).end()

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cerr << endl << endl << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

// 5 10 10 40

void solve(__attribute__((unused)) bool read) {
    int n, m;
    cin >> n >> m;

    string s;
    cin >> s;

    vector<set<int>> e(n);

    vector<array<int, 2>> deg(n);
    set<pair<int, int>> minDegV;

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;

        if (e[u].insert(v).second) {
            deg[u][s[v] == 'B']++;
        }
        if (e[v].insert(u).second) {
            deg[v][s[u] == 'B']++;
        }
    }

    for (int i = 0; i < n; ++i) {
        minDegV.emplace(min(deg[i][0], deg[i][1]), i);
    }

    set<int> erased;

    while (!minDegV.empty() && minDegV.begin()->first == 0) {
        int v = minDegV.begin()->second;
        erased.insert(v);
        minDegV.erase(minDegV.begin());

        for (int u : e[v]) {
            if (erased.count(u)) {
                continue;
            }

            int oldMinDeg = min(deg[u][0], deg[u][1]);

            e[u].erase(v);
            --deg[v][s[u] == 'B'];
            --deg[u][s[v] == 'B'];
            assert(deg[u][s[v] == 'B'] >= 0);

            int curMinDeg = min(deg[u][0], deg[u][1]);

            if (curMinDeg != oldMinDeg) {
                assert(minDegV.erase(make_pair(oldMinDeg, u)));
                assert(minDegV.insert(make_pair(curMinDeg, u)).second);
            }
        }
    }

    //cout << "erased " << erased.size() << " out of " << n << endl;

    /*for (int i = 0; i < n; ++i) {
        if (!erased.count(i)) {
            //cout << "not erased " << i << " " << deg[i][0] << " " << deg[i][1] << endl;

            for (int x : e[i]) {
                cout << x  << endl;
            }
        }
    }*/

    cout << ((erased.size() != n) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 37584