akhauriyash/Code-Regression huggingface dataset:
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	int Q;
	scan(S>>Q);
	int flag=0;
	deque<char> d;
	rep(i,S.size()) d.push_back(S[i]);
	rep(i,Q){
		int T;
		scan(T);
		if(T==1){
			flag^=1;
		}
		else{
			int F;
			char C;
			scan(F>>C);
			F--;
			if(flag^F) d.push_back(C);
			else d.push_front(C);
		}
	}
	if(flag==0) rep(i,d.size()){
		printf("%c",d[i]);
	}
	else brep(i,d.size()){
		printf("%c",d[i]);
	}
	kaigyo;
	return 0;
}


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

#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)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);

	struct testimony { testimony(int x, int y) : x(x), y(y) {}; int x, y; };
	int n; std::cin >> n;
	vector<vector<testimony>> testimonies(n);
	rep(i, n) {
		int a; std::cin >> a;
		rep(j, a) {
			int x, y; std::cin >> x >> y;
			x--;
			testimonies[i].eb(x, y);
		}
	}
	int ma = 1 << n;
	int ans = 0;
	rep(s, ma) {
		bool ok = true;
		rep (i, n) if ((s >> i) & 1)
			for (auto &t : testimonies[i])
				if (((s >> t.x) & 1) != t.y)
					ok = false;
		if (ok) {
			int cnt = 0;
			rep(i, n) cnt += ((s >> i) & 1);
			chmax(ans, cnt);
		}
	}
	std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAXi 1000
#define MAXc 100

void push(int a);
int pop(void);

int top;
int stack[MAXc];


int main(void)
{
  int a,b;
  char *stack;

  stack=calloc(MAXi,sizeof(char));

  while(scanf("%s",stack)!=EOF)
    {
      if(stack[0]=='+')
	{
	  a=pop();
	  b=pop();
	  push(a+b);
	}
      else if(stack[0]=='-')
	{
	  b=pop();
	  a=pop();
	  push(a-b);
	}
      else if(stack[0]=='*')
	{
	  a=pop();
	  b=pop();
	  push(a*b);
	}
      else
	{
	  push(atoi(stack));
	}

      
    }
  printf("%d\n",pop());

  return 0;
}

void push(int a)
{
  stack[++top]=a;
}

int pop(void)
{
  top--;

  return stack[top+1];
}



Measured memory_bytes: 2104
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}


int main(){
	ll k ; cin >> k ;
	vector<int> s = {1,1,1,2,3,4,5,6,7,8,9,10,10,11} ;
	vector<int> g = {9,9,19,29,39,49,59,69,79,89,99,99,109,119} ;
	for(int i=0;i<=15;i++){
		for(int j=s.at(i);j<=g.at(i);j++){
			cout << j ;
			for(int k=0;k<i;k++) cout << 9 ;
			cout << endl ;
			k-- ;
			if(k==0) return 0 ;
		}
	}
}


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

int main()
{
    int n,x;cin>>n>>x;
    vector<int> a(n);
    int i;
    long long ans=0;
    for(i=0;i<n;i++)cin>>a.at(i);
    for(i=0;i<n-1;i++)
    {
        if(a.at(i)+a.at(i+1)>x)
        {
            ans+=(a.at(i)+a.at(i+1)-x);
            if(a.at(i)>x)
            {
                a.at(i+1)=0;
                a.at(i)=x;
            }
            else
            {
                a.at(i+1)-=(a.at(i+1)+a.at(i)-x);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l.sort(key=lambda x:x[1])
c=[l[0][1]]
for i,j in l[1:]:
    if i<c[-1]<=j:pass
    else:c.append(j)
print(len(c))

Measured memory_bytes: 29080
import java.util.*;

class Main {
	public static void main(String[] arg) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int count = 0;
		for (char ch : str.toCharArray()) {
			if(ch =='o')count++;
		
			}
		System.out.println(700+100*count);
	}
}


Measured memory_bytes: 22868
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );

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


Measured memory_bytes: 256
#include<stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
const int N = 2e5+10;
int a[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
	 } 
	int maxv = -2000000000;
	int minv = a[0];
	for(int i = 1 ; i < n ; i++)
	{
		maxv = max(maxv,a[i]-minv);
		minv = min(minv,a[i]);
	}
	cout << maxv << endl;
	return 0;
}


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


int main()
{
	int n;
	int taroPoint=0,hanakoPoint=0;
	string taroCard,hanakoCard;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>taroCard>>hanakoCard;
		if(taroCard > hanakoCard){
			taroPoint += 3;
		}else if(taroCard < hanakoCard){
			hanakoPoint += 3;
		}else{
			taroPoint += 1;
			hanakoPoint += 1;
		}
	}
	cout<<taroPoint<<" "<<hanakoPoint<<endl;

	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll H,W,b=0,w=0;
	cin >> H >> W;
	FOR(i,0,H*W){
		char x;
		cin >> x;
		if(x=='.')w++;
		else b++;
	}
	if(b==H+W-1){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 764
ch = input()
stk1 = []
stk2 = []
ttlar = 0
for i, c in enumerate(ch):
    if c == '\\':
        stk1.append(i)
    elif c == '/' and stk1 != []:
        j = stk1.pop()
        ttlar += i - j
        lar = i - j
        while stk2 != [] and stk2[-1][0] > j:
            lar += stk2.pop()[1]
        stk2.append([j, lar])
print(ttlar)
ans = [len(stk2)]
ans[1:1] = [stk2[i][1] for i in range(len(stk2))]
print(' '.join(map(str, ans)))


Measured memory_bytes: 6244
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def print(self):
        print('', ' '.join(map(str, self.root.inwalk())))
        print('', ' '.join(map(str, self.root.prewalk())))

    def find(self, x, k):
        while x != None and k != x.key:
            if k < x.key:
                x = x.left
            else:
                x = x.right
        return x

    def delete(self, k):
        z = self.find(tree.root, k)
        y = self.successor(z) if z.left and z.right else z
        x = y.left if y.left else y.right

        if x:
            x.parent = y.parent
        if y.parent == None:
            self.root = x
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x
        if y != z:
            z.key = y.key

    def successor(self, x):
        if x.right:
            return self.minimum(x.right)

    def minimum(self, x):
        while x.left:
            x = x.left
        return x

class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None

    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret

    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret

tree = Tree()
n = int(input())
for i in range(n):
    com = input().split()
    if com[0] == "insert":
        tree.insert(int(com[1]))
    elif com[0] == "find":
        ans = tree.find(tree.root, int(com[1]))
        if ans != None:
            print("yes")
        else:
            print("no")
    elif com[0] == "delete":
        tree.delete(int(com[1]))
    else:
        tree.print()



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

int main(){
  int n, j;
  char i;
  int cards[4][14] = {};
  cin >> n;
  
  for ( int k = 0; k < n; k++ ){
  	cin >> i >> j;
  	if ( i == 'S' ) cards[0][j] = 1;
  	if ( i == 'H' ) cards[1][j] = 1;
  	if ( i == 'C' ) cards[2][j] = 1;
  	if ( i == 'D' ) cards[3][j] = 1;
  }
  
  for ( int k = 0; k < 4; k++){
  	for ( int l = 1; l < 14; l++){
  	  if ( cards[k][l] == 0 ){
  	  	if ( k == 0 ) cout << "S" << " " << l << endl;
  	  	if ( k == 1 ) cout << "H" << " " << l << endl;
  	  	if ( k == 2 ) cout << "C" << " " << l << endl;
  	  	if ( k == 3 ) cout << "D" << " " << l << endl;
  	  }
  	}
  }

return 0;  
}


Measured memory_bytes: 3084
#include<cmath>
#include<vector>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	int count = 0;
	for (int i = 0; i < N; i++) {
		int height = 0;
		cin >> height;
		height >= K ? ++count: false;
	}
	cout << count << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    ll n; cin>> n;
    vector<ll> a(n);
    cin>> a[0];
    ll ans=0;
    for(int i=1; i<n; i++){
        cin>> a[i];
        if(a[i] < a[i-1]){
            ans += a[i - 1] - a[i];
            a[i] += a[i - 1] - a[i];
        }
    }
    cout<< ans << endl;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

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

const int N = 111;

int kpw[N];

int solve(int n, int k) {
    static int d[N][N*N];
    for (int i = 1; i <= n; ++i) {
        for (int cnt = 0; cnt < N*N; ++cnt) {
            ll cd = 0;
            for (int w = 0; w <= k; ++w) {
                if (w > i) {
                    cd += d[i-1][cnt];
                } else {
                    int nc = cnt + (cnt + w) / i;
                    if (nc < N*N) {
                        cd += d[i-1][cnt + (cnt + w) / i] + 1LL * kpw[i-1] * ((cnt + w) / i);
                        cd %= MOD;
                    }
                }
            }
            d[i][cnt] = cd % MOD;
        }
    }
    return d[n][0];
}

int main() {
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    kpw[0] = 1;
    for (int i = 1; i < N; ++i)
        kpw[i] = (1LL * (k+1) * kpw[i-1]) % MOD;
    int a = solve(n, k);
    a = (1LL * kpw[n-1] * (k*(k+1) / 2) * n) % MOD - a;
    if (a < 0)
        a += MOD;
    cout << a << "\n";

    return 0;
}


Measured memory_bytes: 5120
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let ans = if a.contains(&0) {
        0
    } else {
        a.iter()
            .fold(Some(1i64), |acc, a_i| {
                acc.map(|x| x.checked_mul(*a_i)).flatten()
            })
            .filter(|x| x <= &10i64.pow(18))
            .unwrap_or(-1)
    };

    println!("{}", ans);
}


Measured memory_bytes: 4524
#include <bits/stdc++.h>
using namespace std;
vector <int> vec;
void gao(int a,int b,int pl,int pr,int u,int v)
{
	int n=a+b,k=n/(b+1),l=0,r=a/k+1,x,y;
	while (r-l>1)
	{
		int mid=(l+r)>>1;
		if (k*mid+(b-mid)/k<=a) l=mid;else r=mid;
	}
	x=l;y=(b-x)/k;a-=k*x+y;
	for (int i=pl;i<=pr;++i)
	{
		if (i<=x*(k+1))
		{
			if (i%(k+1)) vec.push_back(u);
			else vec.push_back(v);
		}
		else if (n-i+1<=y*(k+1))
		{
			if ((n-i+1)%(k+1)) vec.push_back(v);
			else vec.push_back(u);
		}
		else
		{
			if (i<=x*(k+1)+a) vec.push_back(u);
			else vec.push_back(v);
		}
	}
}
int work()
{
	int a,b,pl,pr;
	cin>>a>>b>>pl>>pr;vec.clear();
	if (a>b) gao(a,b,pl,pr,0,1);
	else if (a<b)
	{
		gao(b,a,a+b+1-pr,a+b+1-pl,1,0);
		reverse(vec.begin(),vec.end());
	}
	else for (int i=pl;i<=pr;++i) vec.push_back(!(i&1));
	for (int i=0;i<vec.size();++i) putchar(vec[i]+'A');
	putchar('\n');
}
int main() {
	int T;cin>>T;while (T--) work();
	
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <strings.h>

using namespace std;

int global_block;
int global_agents[16][9];

int north(int x) {
  if (x < 3 || global_block == x - 3)
    return x;
  else
    return x - 3;
}
int east(int x) {
  if (x % 3 == 2 || global_block == x + 1)
    return x;
  else
    return x + 1;
}
int south(int x) {
  if (x >= 6 || global_block == x + 3)
    return x;
  else
    return x + 3;
}
int west(int x) {
  if (x % 3 == 0 || global_block == x - 1)
    return x;
  else
    return x - 1;
}

double compute(int energy, int start, int target, int block)
{
  global_block = block;
  bzero(global_agents, sizeof(int) * 16 * 9);
  global_agents[0][start] = 1;

  for (int i=0; i < energy; i++) {
    for (int pos=0; pos < 9; pos++) {
      if (global_agents[i][pos] != 0) {
        global_agents[i+1][north(pos)] += global_agents[i][pos];
        global_agents[i+1][west (pos)] += global_agents[i][pos];
        global_agents[i+1][south(pos)] += global_agents[i][pos];
        global_agents[i+1][east (pos)] += global_agents[i][pos];
      }
    }
  }
  
  return pow(0.25, energy) * global_agents[energy][target];
}

int main(void) 
{
  while (true) {

    int energy;
    cin >> energy;
    if (energy == 0) break;
    char start, target, block;
    cin >> start >> target >> block;
    int s = start  - 'A';
    int t = target - 'A';
    int b = block  - 'A';
    //cout << "start = " << s << ", target = " << t << ", block = " << b << endl;
    cout << compute(energy, s, t, b) << endl;
  }
  
  return 0;
}

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

int main(void) {
	string O, E;
	cin >> O >> E;
	for (int i = 0;i<=O.size()-1; ++i) {
		cout << O[i];
		if (E[i] != '\0') {
			cout << E[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    string brackets;
    cin >> brackets;
    string right="",left="";
    int nR=0;
    int nL=0;
    int nT=0;
    for (int i=0;i<n;i++){
        if (brackets[i]==')'){//right
            nT++;
            if(nT>nL){
                nR++;
                nT--;
            }
        }
        if (brackets[i]=='('){//left
            nT--;
            if(nT>nR){
                nL++;
                nT++;
            }
        }
    }
    for (int i=0;i<abs(nT);i++){
        if (nT>0){
            right+="(";
        }
        if (nT<0){
            left+=")";
        }
    }
    for (int i=0;i<(nR);i++){
        right+="(";
    }
    for (int i=0;i<(nL);i++){
        left+=")";
    }
    cout << right << brackets << left << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string S;

set<int> X[3] = {{1,4,7},{2,8},{3,6,9}};

void solve() {
  int N = S.size();
  int ans = inf;
  rep(o, 2) {
    int res = 0;
    int s = 0;
    rep(i, N-1) {
      if((i+o+s)&1) {
        if(S[i] == 2 && X[0].count(S[i+1])) { res ++; s++; }
        if(S[i] == 8 && X[0].count(S[i+1])) { res ++; s++; }
        if(S[i] == 3 && X[0].count(S[i+1])) { res ++; s++; }
        if(S[i] == 6 && X[0].count(S[i+1])) { res ++; s++; }
        if(S[i] == 9 && X[0].count(S[i+1])) { res ++; s++; }
        if(S[i] == 3 && X[1].count(S[i+1])) { res ++; s++; }
        if(S[i] == 6 && X[1].count(S[i+1])) { res ++; s++; }
        if(S[i] == 9 && X[1].count(S[i+1])) { res ++; s++; }
      } else {
        if(S[i] == 1 && X[1].count(S[i+1])) { res ++; s++; }
        if(S[i] == 4 && X[1].count(S[i+1])) { res ++; s++; }
        if(S[i] == 7 && X[1].count(S[i+1])) { res ++; s++; }
        if(S[i] == 1 && X[2].count(S[i+1])) { res ++; s++; }
        if(S[i] == 4 && X[2].count(S[i+1])) { res ++; s++; }
        if(S[i] == 7 && X[2].count(S[i+1])) { res ++; s++; }
        if(S[i] == 2 && X[2].count(S[i+1])) { res ++; s++; }
        if(S[i] == 8 && X[2].count(S[i+1])) { res ++; s++; }
      }
    }
    minimize(ans, res);
  }
  cout << ans << endl;
}

int main() {

  for(; cin >> S;) {
    if(S == "#") { break; }
    rep(i, S.size()) S[i] -= '0';
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 3312
#include <stdio.h>
#define MAX(x,y)	((x)>(y)?(x):(y))
int main(){
  int a,b,x=0;
  scanf("%d%d",&a,&b);
  x+=MAX(a,b);
  if(x==a){ a--; }
  else	  { b--; }
  x+=MAX(a,b);
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 1700
import numpy as np
N = int(input())
h_list = list(map(int, input().split()))

sort_h_list = sorted(h_list)
h_array = np.array(h_list)
sort_h_array = np.array(sort_h_list)

diff_array = sort_h_array - h_array

if max(abs(diff_array)) >= 2:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 23120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pint b[32];
		rep (i, n)
			scanf("%d%d", &b[i].second, &b[i].first);
		sort(b, b + n);

		bool ok = true;
		int s = 0;
		for (int i = 0; i < n; ++i)
		{
			s += b[i].second;
			ok &= s <= b[i].first;
		}
		puts(ok ? "Yes" : "No");
	}
}

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

int main() {
  int a,b; cin >> a >> b;
  string s; cin >> s;
  vector<char> v = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  vector<char> w = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  
  rep(j, v.size())
    if(s[b-1] == v[j]) s[b-1] = w[j];
  
  cout << s << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, m; scanf("%d%d", &n, &m);
	printf("%d", --n*--m);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

int main(){
	double bitCoin = 380000.0;
	
	int N; cin >> N;
	
	double ans = 0;
	for(int i = 0; i < N; i++){
		double x; string u;
		cin >> x >> u;

		if(u == "BTC"){
			ans += bitCoin * x;
		} 
		else{
			ans += x;
		}
	}

	cout << ans;
	return 0;
}

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


int main(){
  int x;
  cin >> x;
  int cnt500=0,cnt5=0;
  if(x>=500){
    cnt500=x/500;
    x-=500*cnt500;
    cnt5=x/5;
  }
  else cnt5=x/5;
  cout << cnt500*1000+cnt5*5 << endl;

}

  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        string order,mes;
        cin>>order>>mes;
        for(int i=order.size()-1;i>=0;i--) {
            if(order[i]=='C') {
                mes=mes.substr(1)+mes.substr(0,1);
            }else if(order[i]=='J') {
                mes=mes.substr(mes.size()-1,1)+mes.substr(0,mes.size()-1);
            }else if(order[i]=='E') {
                if(mes.size()%2) {
                    mes=mes.substr(mes.size()/2+1)+mes.substr(mes.size()/2,1)+mes.substr(0,mes.size()/2);
                }else {
                    mes=mes.substr(mes.size()/2)+mes.substr(0,mes.size()/2);
                }
            }else if(order[i]=='A') {
                reverse(mes.begin(),mes.end());
            }else if(order[i]=='P') {
                for(int i=0;i<mes.size();i++) {
                    if(isdigit(mes[i])) {
                        mes[i]=(mes[i]-'0'+9)%10+'0';
                    }
                }
            }else if(order[i]=='M') {
               for(int i=0;i<mes.size();i++) {
                    if(isdigit(mes[i])) {
                        mes[i]=(mes[i]-'0'+1)%10+'0';
                    }
                }
            }
        }
        cout<<mes<<endl;
    }
}

Measured memory_bytes: 3056
def solve():

    X = list(map(int, input().split()))

    X = sorted(X, reverse=True)

    X_max = max(X) #A~Cの内、最大のもの
    n = 0

    while X[0] > X[1]:
        X[1] += 1
        n += 1
    while X[0] > X[2]:
        X[2] += 1
        n += 1
    if n%2 == 1:
        n += 3

    ans =int(n / 2)

   # print(X)
    print(ans)
    
    

if __name__ == "__main__":
    solve()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll a,k;
		cin>>a>>k;
		ll ans=1e18+5,ans1;
		ans=a-(a/k)*k;
		ans1=(((a/k)+1)*k)-a;
		ans=min(ans,ans1);
		cout<<ans;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B;
    cout << 6 / A / B;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define MOD ll(1000000007)

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

	ll d, i, n, j, t, m, x, y, z, k;

	ll ans=0;

	cin>>x>>k>>d;
	x=abs(x);

	ll quo = x/d;
	if(quo>=k)
		ans=x-(k*d);
	else{
		m=x%d;
		if((k-quo)&1)
			ans=abs(d-m);
		else
			ans=abs(m);
	}
	
	cout<<ans;
	cout<<"\n";



	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if((a - b) * (b - c) * (c - a) != 0) cout << 3 << endl;
  else if (a == b && b == c) cout << 1 << endl;
  else cout << 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll dp[1003][1003];
int n;
ll A, B, C, D;
ll mod = 1e9 + 7;
ll fact[1003], inv[1003];

ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	ll res = mpow(a, b / 2);
	res *= res;
	res %= mod;
	if (b%2LL == 1) {
		res *= a;
		res %= mod;
	}
	return res;
}

ll comb(ll a, ll b) {
	ll res = fact[a];
	res *= inv[b];
	res %= mod;
	res *= inv[a - b];
	return res%mod;
}

int main() {
	cin >> n >> A >> B >> C >> D;
	fact[0] = inv[0] = 1;
	for (ll i = 1; i < 1003; ++i) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
		inv[i] = mpow(fact[i], mod - 2);
	}
	for (ll i = 0; i <= B; ++i) dp[i][0] = 1;
	for (ll i = A; i <= B; ++i) {
		for (ll j = 1; j <= n; ++j) {
			dp[i][j] = dp[i - 1][j];
			for (ll t = C; t <= D; ++t) {
				if (j - i*t < 0) break;
				ll w = dp[i - 1][j - i*t];
				w *= fact[n - j + i*t]*inv[n - j] % mod;
				w %= mod;
				w *= inv[t];
				w %= mod;
				w *= mpow(inv[i], t);
				w %= mod;
				dp[i][j] += w;
				dp[i][j] %= mod;
			}
		}
	}
	cout << dp[B][n] << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    string s, t; cin>>s>>t;
    int n=s.size(), m=t.size();
    int j=0;
    bool iseven=true, isodd=true;
    for(int i=0; i<n; i++){ // S even
        if(i%2==0) continue;
        while(j<m){
            if(s[i]==t[j]){
                j++;
                if(j==m){
                    iseven=false;
                    goto END1;
                }
                break;
            }
            j++;
            if(j==m){
                iseven=false;
                goto END1;
            }
        }
    }
    END1:;
    
    j=0;
    for(int i=0; i<n; i++){ // S odd
        if(i%2==1) continue;
        while(j<m){
            if(s[i]==t[j]){
                j++;
                if(j==m){
                    isodd=false;
                    goto END2;
                }
                break;
            }
            j++;
            if(j==m){
                isodd=false;
                goto END2;
            }
        }
    }
    END2:;
    //cout << iseven << " " << isodd << endl;
    if(iseven || isodd) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3232
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int kazu = int.Parse(input[0]);
        int kona = int.Parse(input[1]);
        int total = 0,min=1000000;
        
        for(int i=0;i<kazu;i++){
            int a = int.Parse(ReadLine());
            min = Min(min,a);
            total += a;
        }
        kona -= total;
        kona /= min;
        WriteLine(kazu+kona);
    }
}


Measured memory_bytes: 13140
import std.array;
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main(){
  string[] input;
  input.length = 10;
  for(int j=0;j<10;++j){
    input[j] = chomp(readln());
  }
  int[] num;
  num.length = 10;
  for(int i=0;i<10;++i){
    num[i] = to!int(input[i]);
  }
  sort(num);
  writeln(num[9]);
  writeln(num[8]);
  writeln(num[7]);
}

Measured memory_bytes: 2476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
void solve(long long N, std::vector<long long> A){
    std::sort(A.begin(),A.end());
    int positive_start_idx = 0;
    for (int i=0;i<N;i++){
        if(A[i]>0) break;
        positive_start_idx++;
    }
    ll n_pos = N-positive_start_idx;
    ll n_neg = N -n_pos;
    if (n_pos==0LL){
        n_pos=1;
        n_neg=N-1;
    }else if (n_neg==0LL){
        n_neg=1;
        n_pos=N-1;
    }
    vector<pair<ll,ll> > ret_print;
    ll x = A[0];
    for (int i = n_neg;i<N-1;i++){
        ret_print.push_back(make_pair(x,A[i]));
        x = x- A[i];
    }
    ret_print.push_back(make_pair(A[N-1],x));
    x = A[N-1] -x ;
    for (int i=1;i<n_neg;i++){
        ret_print.push_back(make_pair(x,A[i]));
        x = x - A[i];
    }
    printf("%lld\n",x);
    for (auto itr=ret_print.begin();itr!=ret_print.end();itr++ ){
        printf("%lld %lld\n",(*itr).first,(*itr).second);
    }
 
}
 
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}

Measured memory_bytes: 4336
#include <algorithm>
#include <iostream>

using namespace std;

template <typename T, typename U>
inline bool chmax(T &x, const U &v) {
  if (x < v) {
    x = v;
    return true;
  }
  return false;
}

int dp[20200];

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

  for (int i = 0; i < N; i++) {
    int v, w;
    cin >> v >> w;
    for (int j = W; j >= 0; j--) {
      chmax(dp[j + w], dp[j] + v);
    }
  }
  cout << max_element(dp, dp + W + 1)[0] << endl;

  return 0;
}

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

bool is_prime[1000001];
bool dp[1000001];
int a[31];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 1000000; i++) {
		if (is_prime[i]) {
			for (int j = i * 2; j <= 1000000; j += i)is_prime[j] = false;
		}
	}
	int n, x;
	while (cin >> n >> x, n) {
		rep(i, n)scanf("%d", &a[i]);
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		rep(i, x + 1) {
			rep(j, n)
				if (dp[i] && i + a[j] <= x)dp[i + a[j]] = true;
		}
		bool flag = true;
		for (int i = x; i > 0; i--) {
			if (dp[i] && is_prime[i]) {
				printf("%d\n", i);
				flag = false;
				break;
			}
		}
		if (flag)printf("NA\n");
	}
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define All(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const ll mod = 1e9 + 7;
const int N = 4e6 + 10;
const db pi = acos(-1);
stack<int> a[1010];
int main()
{
	int n = read();
	int Q = read();
	
	while(Q --)
	{
		int op = read();
		if(op == 0) {int x = read();a[x].push(read());}
		if(op == 1) 
		{
			int x = read();
			if(a[x].size() != 0) printf("%d\n", a[x].top());
		}
		if(op == 2) 
		{
			int x = read();
			if(a[x].size() != 0) a[x].pop();
		}
	}
	return 0;
}



Measured memory_bytes: 4180
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<string> W(N);
    rep(i, N) cin >> W.at(i);

    bool isOk1 = true;
    rep(i, N - 1) {
        if (W.at(i).back() != W.at(i + 1).front()) isOk1 = false;
    }

    bool isOk2 = true;
    rep(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (W.at(i) == W.at(j)) isOk2 = false;
        }
    }

    string ans = (isOk1 && isOk2) ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,Alice=0,Bob=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int j=n%2;
    for(int i=n-1;i>=0;i--){
        if((i+1)%2==j)Alice+=a[i];
        else Bob+=a[i];
    }
    cout<<Alice-Bob<<endl;
    
    
    
}


Measured memory_bytes: 256
N = int(input())
c = input()
len_r = 0
len_w = 0
for i in range(N):
    if c[i] == 'R':
        len_r += 1
len_w = N - len_r
n_r = 0
for j in range(len_r):
    if c[j] == 'R':
        n_r += 1
ans = len_r - n_r
print(ans)

Measured memory_bytes: 9468
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n;
        ll ans= LLONG_MIN;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        ll lowmax=LLONG_MIN;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            if(rui[i]<=0)lowmax=max(lowmax,rui[i]);
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        dbg cout <<endl;
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        rui[0]=min(rui[0],rui[1]);
        ll nmin=rui[0],nmax=rui[0];
        bool nmflag=false;
/*        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans=max(rui[j]-rui[i-1],ans);
            }
        }*/
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                    nmflag=true;
                }
            }
            dbg cout <<nmax<<" "<<nmin<<" "<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        if(nmflag)cout<<ans<<endl;
        else cout<<lowmax<<endl;
        //cout <<ans<<endl;
    }

    return 0;
}



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

signed main()
{
	int K;
	cin >> K;
	cout << a[K - 1];
}




Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();

        sc.close();

        System.out.println(t / a * b);
    }
}

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

const int64_t MOD = 998244353;
struct mint
{
    int64_t x;
    mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx)
{
    fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1), inv = vector<mint>(mx + 1);
    fac.at(0) = fac.at(1) = 1;
    fac_inv.at(0) = fac_inv.at(1) = 1;
    inv.at(1) = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac.at(i) = fac.at(i - 1) * i;
        inv.at(i) = -inv.at(MOD % i) * (MOD / i);
        fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
    }
}
mint comb(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

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

    init_comb(2 * 1e5);
    mint res = 0;
    for (int i = 0; i < K + 1; i++)
    {
        res += mint(M) * comb(N - 1, i) * mint(M - 1).pow(N - 1 - i);
    }
    cout << res.x << endl;
}

Measured memory_bytes: 7992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll l, r;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> l >> r;
    if (r - l >= 2019)
    {
        cout << 0 << "\n";
        return 0;
    }
    if (l % 2019 >= r % 2019)
    {
        cout << 0 << "\n";
        return 0;
    }
    else
    {
        ll ans = 10000000;
        for (int i = l % 2019; i <= r % 2019 - 1; i++)
        {
            for (int j = i + 1; j <= r % 2019; j++)
            {
                ll temp = i * j % 2019;

                ans = min(ans, temp);
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define no_of_test(x)   int x; cin>>x; while(x--)

const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}

int32_t main()
{
	very_fast();
	//no_of_test(x)
	{
		int n, x, t, ans = 0;
		cin >> n >> x >> t;
		int k = n / x;
		if (k == 0)
		{
			cout << t << endl;
			return 0;
		}
		else
		{	if (n % x == 0)
				cout << k*t << endl;
			else
				cout << (k + 1)*t << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int euku(int,int);

int main(){
  int i;
  long long n,m;
  long long p;
  long long q;
  int l=0;

  scanf("%lld %lld",&n,&m);

  unsigned char s[1000000];
  unsigned char t[1000000];

  scanf("%s",s);
  scanf("%s",t);

  if(s[0]!=t[0]){
    l++;
  }
  q = euku(n,m);
  p = n*m/euku(n,m);

    for(i=0; i<=q; i++){
      if(s[i*n/q]!=t[i*m/q]){
        l++;
      }
    }

  if(l==0){
    printf("%lld\n",p);
  }else if(l>0){
    printf("-1\n");
  }

  return 0;
}

int euku(int a,int b){
  int r;
  if(a>=b){
    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    return b;
  }else{
    r = b % a;
    while(r!=0){
      b = a;
      a = r;
      r = b % a;
    }
    return a;
  }
}


Measured memory_bytes: 384