akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

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

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int a[50];
ll dp[51][2];

int main(){
	int n, p;
	
	cin >> n >> p;
	
	REP(i,n){
		int num;
		
		cin >> num;
		
		a[i] = num%2;
	}
	
	dp[0][0] = 1;
	dp[0][1] = 0;
	
	REP(i,n){
		if (a[i]){
			REP(j,2){
				dp[i+1][j] = dp[i][0]+dp[i][1];
			}
		}
		else {
			REP(j,2){
				dp[i+1][j] = dp[i][j]*2;
			}
		}
	}
	
	cout << dp[n][p] << endl;
	
	return 0;
}

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

int main(){
    ll int n, i, s=0, sum=0, p;
    cin>>n;
    ll int arr[n];
    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    
    for(i=0; i<n-1; i++){
        s= (s+ arr[i])%1000000007;
        p = (arr[i+1]*s)%1000000007;
        sum=(sum + p)%1000000007;
    }
    cout<<sum;
}

Measured memory_bytes: 5176
#include <iostream>
using namespace std;
int main(void){
    
    int r, D, x2000;
    cin >> r >> D >> x2000;
    
    long long xi = (r * x2000) - D; 
    
    for(int i = 1; i <= 10; i++){
        cout << xi << endl;
        xi = (r * xi) - D;
    }

}

Measured memory_bytes: 256
import itertools

def read():
    N = str(input().strip())
    K = int(input().strip())
    return N, K

def solve(N, K):
    L = len(N)
    D = [int(N[i]) for i in range(L)]
    dp0 = [[0 for k in range(K+1)] for i in range(L+1)]
    dp1 = [[0 for k in range(K+1)] for i in range(L+1)]
    
    dp0[0][0] = 1
    for i in range(L):
        for k in range(K+1):
            if k < K and D[i] > 0:
                dp0[i+1][k+1] += dp0[i][k]
                for d in range(1, D[i]):
                    dp1[i+1][k+1] += dp0[i][k]
            if D[i] == 0:
                dp0[i+1][k] += dp0[i][k]
            else:
                dp1[i+1][k] += dp0[i][k]
            if k < K:
                for d in range(1, 10):
                    dp1[i+1][k+1] += dp1[i][k]
            dp1[i+1][k] += dp1[i][k]
    return dp0[L][K] + dp1[L][K]


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        sc.close();
        int s = 2147483646;
        for(int i = a[0] ; i <= a[n - 1] ; i++ ){
            int k = 0;
            for(int j = 0 ; j < n ; j++ ){
                k += (a[j] - i) * (a[j] - i);
            }
            s = Math.min(s , k);
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 36020
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define MP make_pair
#define pss pair<string,string>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=1e5+5;
int n,m;
int main()
{
	cin>>n>>m;
	if(n<m)
		cout<<0;
	else
		cout<<10;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.length()-1; ++i) {
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *x, const void *y) { return *(int *)y - *(int *)x; }
int main() {
	int n, a[100], alice = 0, bob = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	qsort(a, n, sizeof(int), cmpint);
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			alice += a[i];
		} else {
			bob += a[i];
		}
	}
	printf("%d\n", alice - bob);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int i,j,H,W;
	
	while (!(H==0&&W==0)){
		scanf("%d %d",&H,&W);
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
			printf("\n");
		}
		if (H==0&&W==0)break;
		printf("\n");
	}
	
	return 0;
}

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

using namespace std;
using lint = long long;

// dp[x]:重さがxのときの価値の最大値
lint dp[100005] = {};

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

    for (int i = 0; i < N; ++i) {
        lint w, v;
        cin >> w >> v;
        for (int j = Wmx; j >= w; --j) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }
    cout << dp[Wmx] << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
data = list(map(int, input().split()))

l = [0]*9
cam = 0
for d in data:
    num = d//400 if d//400 < 8 else 8
    if num==8: cam += 1
    if l[num] == 0: l[num] = 1

score = sum(l[:8])
print(max(1,score), score+cam)



Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static Stack<Character> waitStack;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {

			String n = sc.nextLine();

			if(n.equals(".")) {
				break;
			}

			 waitStack = new Stack<>();

			String ans = "yes";

			for(int i = 0; i < n.length(); i++) {
				Character c = n.charAt(i);
				if(c == '[') {
					waitStack.push(']');
				}else if(c == '('){
					waitStack.push(')');
				}else if(c==']' || c==')') {

					if(waitStack.isEmpty() || waitStack.pop()!=c) {
						ans = "no";
						break;
					}
				}
			}

			if(waitStack.size() != 0) {
				ans ="no";
			}
			System.out.println(ans);
		}
	}
}



Measured memory_bytes: 47912
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	ll N;
	cin >> N;
	vec C(N,-1),V(N,-1);
	REP(i, N) {
		cin>>V[i];
	}
	REP(i, N) {
		cin>>C[i];
	}
	ll ans=0;

	REP(i,N){
		if(V[i]>C[i]) ans+=V[i]-C[i];
	}

	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut v = read_vec::<u32>();
    v.sort();
    yn(v[0] == 5 && v[1] == 5 && v[2] == 7);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;

    ll dist = abs(A - B);
    ll vdist = V - W;
    bool flag = false;
    if (vdist > 0 && dist <= vdist * T)
        flag = true;
    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 3652
x,y = map(int,input().split())

d = min(abs(y-x),abs(y-(-x)))


if abs(y) > abs(x):
	if (x == 0) and (y > 0):
		print(d)
	elif (x == 0) and (y < 0):
		print(d+1)
	elif x >= 0 and y >= 0:
		print(d)
	elif x < 0 and y < 0:
		print(d+2)
	else:
		print(d+1)
elif abs(y) < abs(x):
	if (y == 0) and (x > 0):
		print(d+1)
	elif (y == 0) and (x < 0):
		print(d)
	elif x < 0 and y < 0:
		print(d)
	elif x >= 0 and y >= 0:
		print(d+2)
	else:
		print(d+1)
else:
	if (x >= 0 and y >= 0) or (x < 0 and y < 0):
		print(0)
	else:
		print(1)




Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, k;
	cin >> n >> k;
	vll x(n);
	for (ll i = 0; i < n; i++) cin >> x[i];

	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ans += min(x[i], abs(k - x[i]));
	}
	cout << 2 * ans << endl;
}


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

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return false;
    for(int t=0;t<n;t++){
        int x[3], y[3], z[3], w[3];
        for(int i=0;i<2;i++){
            cin >> x[i] >> y[i] >> z[i] >> w[i];
        }
        x[2] = x[0]*x[1] - y[0]*y[1] - z[0]*z[1] - w[0]*w[1];
        y[2] = x[0]*y[1] + y[0]*x[1] + z[0]*w[1] - w[0]*z[1];
        z[2] = x[0]*z[1] + z[0]*x[1] - y[0]*w[1] + w[0]*y[1];
        w[2] = x[0]*w[1] + w[0]*x[1] + y[0]*z[1] - z[0]*y[1];
        cout << x[2] << " " << y[2] << " " << z[2] << " " << w[2] << endl;
    }
    return true;
}

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



Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define NINTH_POWER_OF_TEN 1000000000
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 1000;

int N, M;
int x[kMaxN], y[kMaxN], z[kMaxN];
int ans = 0;

signed main() {
  cin >> N >> M;
  REP(i, N) { cin >> x[i] >> y[i] >> z[i]; }

  REP(i, 2) {
    REP(j, 2) {
      REP(k, 2) {
        vector<int> v(N);
        REP(l, N) {
          v[l] = ((1-2*i)*x[l]) + ((1-2*j)*y[l]) + ((1-2*k)*z[l]);
        }
        sort(v.begin(), v.end(), greater<int>());
        int s = 0;
        REP(l, M) { s += v[l]; }
        ans = MAX(ans, s);
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  ll r, d, x; cin >> r >> d >> x;

  for (int i = 0; i < 10; ++i) {
    x = r*x - d;
    cout << x << endl;
  }

}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		ArrayList<Integer> buf = new ArrayList<Integer>();
		
		int w[] = new int[10];
		for (int i = 0; i < 10; i++)
		{
			w[i] = 1<<i;
		}
		
		while (true)
		{
			buf.clear();
			int n;
			try
			{
				n = sc.nextInt();
			}
			catch (Exception e)
			{
				break;
			}
			int index = 9;
			while (0 < n)
			{
				for (int i = index; i >= 0; i--)
				{
					if (w[i] <= n)
					{
						buf.add(w[i]);
						n -= w[i];
						index = i - 1;
						break;
					}
				}
			}
			Integer[] res = buf.toArray(new Integer[buf.size()]);
			Arrays.sort(res);
			for (int i = 0; i < res.length; i++)
			{
				System.out.print(res[i]);
				if (i != res.length - 1) System.out.print(" ");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll modpow(ll b, ll e, ll p) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = modpow(b,e/2,p);
    return (t*t)%p;
  }
  return (b*modpow(b,e-1,p))%p;
}

ll modinv(ll n, ll p) {
  return modpow(n,p-2,p);
}

ll modcomb(ll n, ll k, ll p) { // O(k)
  ll ans=1;
  for(ll i=n; i>=n-k+1; i--) {
    ans*=i;
    ans%=p;
  }
  for(ll i=1; i<=k; i++) {
    ans*=modinv(i,p);
    ans%=p;
  }
  return ans;
}

// O(1) nCk calculation
const ll p = 1e9+7;
const int MX = 2000001;
ll modFact[MX+1];
ll modFactInv[MX+1];
void precalc() {
  modFact[0]=1;
  modFactInv[0]=1;
  repeat(i,1,MX+1) {
    modFact[i]=(modFact[i-1]*i)%p;
    modFactInv[i]=modinv(modFact[i],p);
  }
}

ll fastModComb(ll n, ll k, ll p) {
  // call precalc() first.
  ll ret=modFact[n];
  ret=ret*modFactInv[n-k];
  ret%=p;
  ret=ret*modFactInv[k];
  ret%=p;
  return ret;
}

ll sum(ll r, ll c) {
  ll ret=0;
  rep(k,c+1) {
    ll t=fastModComb(k+r+1,k+1,p);
    t%=p;
    ret+=t;
    ret%=p;
  }
  //  cout << "sum(" << r << ","<<c<<")=" << ret << endl;
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  precalc();
  ll r1,c1,r2,c2;
  cin>>r1>>c1>>r2>>c2;
  
  cout << (((sum(r2,c2) - sum(r1-1,c2)+p)%p - sum(r2,c1-1)+p)%p + sum(r1-1,c1-1))%p << endl;
  return 0;
}


Measured memory_bytes: 31488
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	int r,c;
	int hyo[1000][1000];
	int ans,final_ans;

	cin>>r>>c;

	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>hyo[i][j];
		}
	}

	for(int i=0;i<r;i++){
		ans=0;
		for(int j=0;j<c;j++){
			ans+=hyo[i][j];
		}
		hyo[i][c]=ans;
	}

	final_ans=0;

	for(int j=0;j<c;j++){
		ans=0;
		for(int i=0;i<r;i++){
			ans+=hyo[i][j];
		}
		hyo[r][j]=ans;
		final_ans+=ans;
	}

	hyo[r][c]=final_ans;

	for(int i=0;i<=r;i++){
		for(int j=0;j<=c;j++){
			cout<<hyo[i][j];
			if(j!=c) cout<<" ";
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 3308
#include<iostream>
using namespace std;
int main()
{
    int x,a,b,s;
    cin>>x>>a>>b;
    if(b-a<=x && b>a)
        cout<<"safe"<<endl;
    else if(b-a>x)
        cout<<"dangerous"<<endl;
    else
        cout<<"delicious"<<endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long x, y, z;
    
    cin >> x >> y >> z;
    
    cout << (x - z) / (y + z) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n,m,c;
  int sum = 0,cnt = 0;
  cin >> n >> m >> c;
  vector<int> B(m);
  for (int i = 0; i < m; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>>num(n,vector<int>(m));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> num.at(i).at(j);
      }
    }
    for (int i = 0; i < n; i++) {
      sum = 0;
      for (int j = 0; j < m; j++) {
        sum += num.at(i).at(j) * B.at(j);
      }
      sum += c;
      if (sum > 0) {
        cnt++;
      }
    }
    cout << cnt << endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int min, max, a, b;
	long int sum;
	cin >> b >> min;
	max = min;
	sum = min;
	for (int i = 2; i <= b; i++) {
		cin >> a;
		if (a < min)
			min = a;
		if (a > max)
			max = a;
		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3104
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    D, T, S = LI()
    print("Yes" if D <= T * S else "No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 77240
// ##MohK
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    int n[x];
    int max=0;
    int res=0;
    for(int i=1;i<=x;i++)
    {
        cin>>n[i];
        if(n[i]>=max) {max=n[i];}
        res=res+n[i];

    }
    cout<<res-(max/2);
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(void){
int n[256],i,x[256],a=0,j,k=-1,m;
do{
	k++;
	scanf ("%d%d",&n[k],&x[k]);
}while((n[k]!=0)||(x[k]!=0));

for (m=0;m<k;m++){
	for (i=1;i<=n[m];i++){
		for(j=1;j<i;j++){
			if ((x[m]-i-j>=1)&&(x[m]-i-j<j)){
				a++;
			};
		};
	};
	
	printf("%d\n",a);
	a=0;
};
return 0;
}

Measured memory_bytes: 2724
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
using namespace std;

int main() {
	long long int a, b, c,k;
	long long  int sum;
	cin >> a >> b >> c >> k;
	if (k <= a) {
		sum = k;
	}
	else if (k <= a + b) {
		sum = a;
	}
	else {
		sum = a - (k - (a + b));
	}
	cout << sum;
}

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

int main() {
  int t, a = 0, b = 0;
  for (int i = 0; i < 4; i++) {
    cin >> t;
    a += t;
  }
  for (int i = 0; i < 4; i++) {
    cin >> t;
    b += t;
  }
  cout << max(a, b) << "\n";
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'
const int maxn=3004;
ll dp[maxn][maxn][4];

void solve()
{
    ll n,m;
    cin>>n>>m;

    vector<vector<ll>> a(n+1,vector<ll> (m+1,0));
    int k;
    cin>>k;
    while(k--){
        int x,y,v;
        cin>>x>>y>>v;
        a[x][y]=v;
    }

    memset(dp,0,sizeof dp);

    for (int i = 1; i < n+1; i++)
    {
        for (int j = 1; j < m+1; j++)
        {
            ll val=0;
            for (int k = 0; k < 4; k++)
            {
                val=max(val,dp[i-1][j][k]);
            }
            if(a[i][j]==0) {
                dp[i][j][0]=max(dp[i][j-1][0],val);
                dp[i][j][1]=dp[i][j-1][1];
                dp[i][j][2]=dp[i][j-1][2];
                dp[i][j][3]=dp[i][j-1][3];
            }
            else
            {
                dp[i][j][0]=max(dp[i-1][j][3],dp[i][j-1][0]);
                dp[i][j][1]=max(val+a[i][j],max(dp[i][j-1][0]+a[i][j],dp[i][j-1][1]));
                dp[i][j][2]=max(dp[i][j-1][1]+a[i][j],dp[i][j-1][2]);
                dp[i][j][3]=max(dp[i][j-1][2]+a[i][j],dp[i][j-1][3]);
            }
        }
    }
    ll ans=0;
    for (int i = 0; i < 4; i++)
    {
        ans=max(ans,dp[n][m][i]);
    }
    
    cout<<ans<<endl;

}

int main()
{
    IOS;
    ll t=1;// cin>>t;
    while (t--)
    {
        solve();
    }
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}

int m;

struct Matrix{
    ll a[101][101];
    Matrix(){
        memset(a,0,sizeof(a));
    }
    Matrix operator *(const Matrix& other){
        Matrix product=Matrix();
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                for(int k=0;k<m;k++){
                    product.a[i][k]+=a[i][j]*other.a[j][k];
                    product.a[i][k]%=MOD;
                }
            }
        }
        return product;
    }
};

Matrix expo(Matrix a,ll k)
{
    Matrix product=Matrix();
    for(int i=0;i<m;i++)
        product.a[i][i]=1;
    while(k>0){
        if(k%2)
            product=product*a;
        a=a*a;
        k/=2;
    }
    return product;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int te=1;
    //cin>>te;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(te--){
        ll n,k;
        cin>>n>>k;
        m=n;
        Matrix a=Matrix();
        for(int i=0;i<n;i++){
        	for(int j=0;j<n;j++){
        		cin>>a.a[i][j];
        	}
        }
        
        a=expo(a,k);
        ll ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                ans+=a.a[i][j],ans%=MOD;
        }
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 3928
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	double a,b,c,d,e,f;
	while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&f)){
		a+=0.000000001;
		b+=0.000000001;
		if(c<a){
			double g=a;a=c;c=g;
			g=b;b=d;d=g;
		}
		double r=atan2(d-b,c-a);
		double x=e-a;
		double y=f-b;
		double X=cos(r)*x+sin(r)*y;
		double Y=-sin(r)*x+cos(r)*y;
		Y=-Y;
		x=cos(r)*X-sin(r)*Y;
		y=sin(r)*X+cos(r)*Y;
		printf("%f %f\n",a+x,b+y);
	}
}

Measured memory_bytes: 0
import java.util.*;
import static java.lang.System.*;

import java.io.IOException;
import java.io.InputStream;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int N = sc.nextInt();
	  long[]score = new long[N+1];
	  int[] k = new int[N+1];
	  long sum = 0;
	  
	  for(int i=0; i<N; i++) {
		  int n = sc.nextInt();
		  score[n]++;
		  k[i+1] = n;
	  }
	  for(int i=1; i<=N; i++) {
		  //out.println("score[i]" +  score[i]);
		  if(score[i] > 1) sum += (score[i] * (score[i]-1)) / 2;
		  //out.println(sum);
	  }
	  //out.println(sum);
	  for(int i=1; i<=N; i++) {
		  long ans = sum - score[k[i]] + 1;
		  if (ans < 0 ) ans = 0;
		  out.println(ans);
	  }

  }
}



Measured memory_bytes: 101260
S = list(input())
f_list = [k for k in range(len(S)) if S[k] == "W"]    
S.sort(reverse=True)
s_list = [k for k in range(len(S)) if S[k] == "W"]
ans = 0
for i in range(len(f_list)):
    ans += f_list[i]-s_list[i]
print(ans)

Measured memory_bytes: 20640
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    string s;
    cin>>s;
    ll n=s.size()-1;
    if(n==0) {
        cout<<(s[0]-48)<<endl;
        return 0;
    }
    //n個についてbit全探索
    //t[i]をtrue,falseで判断
    ll ans=0;
    vector<int> t(n);
    for(int bit=0; bit <(1<<n); ++bit) {
        for(int i=0;i<n;i++) {
            if(bit & (1<<i))    t[i]=true;
            else    t[i]=false;
        }
        ll tmp=0;
        rep(i,n) {
            tmp+=(s[i]-48);
            if(t[i]==true) {
                ans+=tmp;
                tmp=0;
                if(i==n-1) {
                    ans+=(s[i+1]-48);
                    tmp=0;
                }
            }
            else if(i==n-1) {
                tmp=tmp*10+(s[i+1]-48);
                ans+=tmp;
                tmp=0;
            }
            else {
                tmp=tmp*10;
            }
        } 
    }

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

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 
 */

#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;

/* constant */

const int MAX_C = 100;

/* typedef */

/* global variables */

bool cs[MAX_C + 1];

/* subroutines */

/* main */

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  cs[a] = cs[b] = cs[c] = true;

  int cnt = 0;
  for (int i = 0; i <= MAX_C; i++)
    if (cs[i]) cnt++;

  printf("%d\n", cnt);
  return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

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

    ll dp[n][2];
    rep(i,n) rep(j,2) dp[i][j] = 0;
    dp[0][1] = -INF;

    rep(i,n){
        if(i == n-1){
            dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
            dp[i+1][1] = -INF;
        }
        else{
            dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
            dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
        }
    }

    cout << dp[n][0] << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 059 B / Link: http://abc059.contest.atcoder.jp/tasks/abc059_b  ----- */


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

	string A, B; cin >> A >> B;

	// A==B:2 A<B.
	auto compare_string_num = [](const string& A,const string& B) {
		if (SZ(A) != SZ(B))return (int)(SZ(A) < SZ(B));
		FOR(i, 0, SZ(A)) {
			if (A[i] == B[i])continue;
			else return (int)(A[i] < B[i]);
		}
		return 2;
	};


	LL ans = compare_string_num(A,B);
	if (ans == 0)cout << "GREATER" << endl;
	else if (ans == 1)cout << "LESS" << endl;
	else cout << "EQUAL" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {


	public static void main (String [] args) {
		
		
		int a,b;
		
		Scanner sc = new Scanner(System.in);
		
		do {
			a = sc.nextInt();			
		}while(!((a >= 1)&&(a <= 20)));
		
		do {
			b = sc.nextInt();			
		}while(!((b >= 1)&&(b <= 20)));
		
		
		if((a>=1 && a<=9) && (b>=1 && b<=9) ) {
			
			System.out.println(a*b);
			
		}else {
			System.out.println(-1);
		}
		
		
	}
}
		

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

int a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;
    while (1){
        c -= b;
        if (c <= 0){
            cout << "Yes\n";
            break;
        }
        a -= d;
        if (a <= 0){
            cout << "No\n";
            break;
        }
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 30
#define u32d unsigned int
#define LL   long long
#define INF  0x7FFFFFFF
using namespace std;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl; 
	return 0;
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	cout << "? 1 2" << endl;
	int d; cin >> d;
	using P = pair<int, int>;
	vector<P> v;
	v.emplace_back(0, 1);
	v.emplace_back(d, 2);
	rep(i, 3, N + 1) {
		int d1, d2;
		cout << "? 1 " << i << endl;
		cin >> d1;
		cout << "? 2 " << i << endl;
		cin >> d2;
		// 1 i 2
		if (d1 + d2 == d) {
			v.emplace_back(d1, i);
		}
		// i 1 2
		else if (d1 + d == d2) {
			v.emplace_back(-d1, i);
		}
		// 1 2 i
		else if (d2 + d == d1) {
			v.emplace_back(d1, i);
		}
	}
	sort(all(v));
	cout << "!";
	rep(i, 0, N) {
		cout << " " << v[i].second;
	}
	cout << endl;
	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A,B;
    cin >> A >> B;
    if(A > 8 || B >8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

lcm_A = A[0]
for i in range(1, N):
    lcm_A = lcm_A * A[i] // gcd(lcm_A, A[i])

ans = 0
for i in range(N):
    ans += lcm_A // A[i]

print(ans % mod)

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("?tc????");
            WillReturn.Add("coder");
            //atcoder
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("??p??d??");
            WillReturn.Add("abc");
            //UNRESTORABLE
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        string T = InputList[1];

        var KouhoList = new List<string>();

        //始点のループ
        for (int I = 0; I <= S.Length - T.Length; I++) {
            bool IsOK = true;
            for (int J = 0; J <= T.Length - 1; J++) {
                if (S[I + J] == '?') continue;
                if (S[I + J] == T[J]) continue;
                IsOK = false;
                break;
            }
            if (IsOK) {
                string WillAdd = S.Remove(I, T.Length);
                WillAdd = WillAdd.Insert(I, T);
                WillAdd = WillAdd.Replace('?', 'a');
                KouhoList.Add(WillAdd);
            }
        }
        if (KouhoList.Count > 0) {
            Console.WriteLine(KouhoList.Min());
        }
        else Console.WriteLine("UNRESTORABLE");
    }
}


Measured memory_bytes: 13408
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n;cin >> n;
	cout << (1000-n%1000==1000?0:1000-n%1000) << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    long long m=0,s=0,l=0;
    for(long long i=0;i<S.size();i++){
        if(S.at(i)=='<'){
            m++;
            s+=m;
            l=m;
        }
        else{
            m--;
            if(m<0){
                s+=(l-m);
                m=0;
                l++;
            }
            else if(i==S.size()-1){
                s-=(l-m-1)*m;
                m=0;
            }
            else if(S.at(i+1)=='<'){
                s-=(l-m-1)*m;
                m=0;
            }
            else{
                s+=m;
            }
        }
    }
    cout <<s<<endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, A, B, Ans = 0;cin >> N >> A >> B;

if(A > B){cout << 0;exit(0);}

if(N == 1){
    
    if(A != B){cout << 0;exit(0);}

    else {cout << 1;exit(0);}
    
    }

cout << (B - A)*(N - 2) + 1;


}


Measured memory_bytes: 3584
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = (a-1)/(b-1);
    int d = ((a-1)%(b-1)==0) ? 0 : 1;
    System.out.println((c+d));
  }
}


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

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;

int N, K;
int A[500];

bool f(int d) {
    //cout << "[d=" << d << "]\n";
    vector<ll> r(N);
    rep(i,N) r[i] = A[i] % d;
    std::sort(r.begin(), r.end());
    //cout << "r="; rep(i,N) cout << r[i] << ' '; cout << endl;
    rep(i,N) if (r[i] > K && ((d - r[i]) % d) > K) continue;
    for (ll i = 0LL; i < N; i++) {
	ll sum = 0LL;
	ll j;
	for (j = 0LL; j <= i; j++) sum += r[j];
	//cout << "i=" << i << ",sum=" << sum << ',';
	ll sum2 = 0LL;
	for (; j < N; j++) sum2 += (d - r[j]);
	//cout << "sum2=" << sum2 << endl;
	if (sum <= K && sum2 <= K) {
	    //cout << "sum=" << sum << ",sum2=" << sum2 << endl;
	    return true;
	}
    }
    return false;
}

int main() {
    cin >> N >> K;
    int S = 0LL; rep(i,N) { cin >> A[i]; S += A[i]; }
    //cout << "S=" << S << endl;
    int ans = 0;
    for (int d = 1; d * d <= S; d++) {
	if (S % d != 0) continue;
	if (f(d)) {
	    //cout << d << endl;
	    ans = max(ans, d);
	}
	if (f(S / d)) {
	    ans = max(ans, S / d);
	    //cout << d << endl;
	}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define LEN 100005
#define true 1
#define false 0
typedef struct {
  char name[100];
  int t;
} P;
P Q[LEN+1];
int head, tail, n;
void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

int main()
{
  int time, q, i, now_time = 0;
  /*timeはクオンタムをカウントし、now_time
はプロセスを行なっている現在の時刻をカウント
する。*/
  P Q2;

  scanf("%d%d",&n,&q);
  for(i = 0 ; i < n ; i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
    enqueue(Q[i]); }

  while(n > 0){ 
    Q2 = dequeue();
    time = q;
    while(Q2.t > 0 && time > 0){ 
      now_time++;
      Q2.t--;
      time--; }
    if(Q2.t > 0) enqueue(Q2);
    else{
      printf("%s %d\n",Q2.name,now_time);
      n--; }
  }
      
  return 0;
}

void  initialize(void)
{
  head = tail = 0;
}

int isEmpty(void)
{
  if(head == tail) return true;
  else return false;
}

int isFull(void)
{
  if(head == (tail + 1) % (LEN + 1)) return true;
  else return false;
}

void enqueue(P x)
{
  if(isFull() == true) printf("オーバーフロー\n");

  Q[tail] = x;

  if(tail + 1 == LEN + 1) tail = 0;
  else tail++;
}

P dequeue(void)
{
  P x;
  
  if(isEmpty() == true) printf("エラー（アンダーフロー）\n"); 

  x = Q[head];

  if(head + 1 == LEN + 1) head = 0;
  else head++;

  return x;
}


Measured memory_bytes: 11924
var n,i:longint;
    f,a:array[1..100000] of integer;
begin
	readln(n);
	for i:=1 to n do read(a[i]);
	// 0 la co the thay doi... 1 la khong thay doi duoc
	fillchar(f,n,0);
	for i:=2 to n do 
	  if a[i] < a[i-1] then
	    begin
	      if (a[i] = a[i-1] - 1) and (f[i-1] = 0) then f[i]:=1
	      else 
	        begin
	          write('No');
	          halt;
	        end;
	    end
	  else if (a[i] = a[i-1]) and (f[i-1] = 1) then f[i]:=1;
	write('Yes');
end.

Measured memory_bytes: 896
result = []

def combination(n, x):
    count = 0
    for i in range(1, n + 1):
        for j in range(1,i):
            for k in range(1, j):
                if i + j + k == x:
                    count += 1
    result.append(count)


while True:
    (n, x) = [int(i) for i in input().split()]

    if n == x == 0:
        break

    combination(n, x)

[print(result[x]) for x in range(len(result))]

Measured memory_bytes: 6720
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main(){
	
	int n,t;
	cin>>n>>t;
	pair<string,int>y[15];
	int g=0;
	int ans=0;
	for(int i=0;i<n;i++){
		string a,b,c,d;
		cin>>a>>b>>c>>d;
		int w=0,z=0;
		w=(a[0]-'0')*10+(a[1]-'0');
		w*=60;
		w+=(a[3]-'0')*10+(a[4]-'0');
		z=(c[0]-'0')*10+(c[1]-'0');
		z*=60;
		z+=(c[3]-'0')*10+(c[4]-'0');
		if(i){
			if(w-g>=t){
				y[ans].first=b;
				y[ans].second=w-g;
				ans++;

			}
		}
		g=z;
		
	}
	cout<<ans<<endl;
	for(int i=0;i<ans;i++){
		cout<<y[i].first<<" "<<y[i].second<<endl;
	}
	

	return 0;
}

Measured memory_bytes: 1220
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
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};

struct State {
	int lx, ly, rx, ry;
	State(int _lx, int _ly, int _rx, int _ry) : lx(_lx), ly(_ly), rx(_rx), ry(_ry) {}
};

int W, H;
int srx, sry, slx, sly;
string roomL[55], roomR[55];

bool visit[55][55][55][55];

void solve() {
	minit(visit, 0);
	
	bool flag = false;
	
	queue< State > q;
	q.push(State(slx, sly, srx, sry));
	
	while (!q.empty()) {
		State s = q.front(); q.pop();
		int lx = s.lx, ly = s.ly, rx = s.rx, ry = s.ry;
		
		if (visit[ly][lx][ry][rx]) continue;
		visit[ly][lx][ry][rx] = true;
		
		char cL = roomL[ly][lx], cR = roomR[ry][rx];
		
		if ((cL == '%' && cR != '%') || (cL != '%' && cR == '%')) continue;
		if (cL == '%' && cR == '%') {
			flag = true;
			break;
		}
		
		for_(d,0,4) {
			int nlx = lx + DX[d], nly = ly + DY[d];
			int nrx = rx, nry = ry;
			if (d != 0 && d != 2) nrx += DX[(d + 2) % 4], nry += DY[(d + 2) % 4];
			else nrx += DX[d], nry += DY[d];
	
			if (!in_range(nlx, nly, W, H)) {
				nlx = lx;
				nly = ly;
			} else if (roomL[nly][nlx] == '#') {
				nlx = lx;
				nly = ly;
			}
			
			if (!in_range(nrx, nry, W, H)) {
				nrx = rx;
				nry = ry;
			} else if (roomR[nry][nrx] == '#') {
				nrx = rx;
				nry = ry;
			}

			q.push(State(nlx, nly, nrx, nry));
		}
	}
	
	if (flag) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

int main() {
	while (cin >> W >> H, W) {
		for_(i,0,H) {
			cin >> roomL[i] >> roomR[i];
			for_(j,0,W) {
				if (roomL[i][j] == 'L') slx = j, sly = i;
				if (roomR[i][j] == 'R') srx = j, sry = i;
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 13848
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    
    int ans = 0;
    forn(i, 1, n+1) {
        int x = i, sum = 0;
        while (x) {
            sum += x%10;
            x /= 10;
        }
        if (sum >= a && sum <= b) ans += i;
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int n;
vector<int> b;

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  cin >> n;
  b.resize(n);
  for(int i=0;i<n;++i) {
    cin >> b[i];
    b[i]--;
    if(b[i] > i) {
      cout << -1 << endl;
      return 0;
    }
  }
  // printv(b);

  vector<int> res;
  for(int cnt=0;cnt<n;++cnt) {
    for(int i=(int)(b.size())-1;i>=0;--i) {
      if(i == b[i]) {
        res.push_back(b[i]);
        b.erase(b.begin() + i);
        break;
      }
    }
  }
  reverse(res.begin(), res.end());
  for(int i=0;i<n;++i) {
    cout << res[i]+1 << endl;
  }

}


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

vector<vector<int>>v,dp;
int maxhappiness(int n,int idx){
    if(dp[n][idx]!=-1){
        return dp[n][idx];
    }

    if(idx==0){
        dp[n][idx] = max(maxhappiness(n-1,1),maxhappiness(n-1,2))+v[n][idx];
    }else if(idx==1){
        dp[n][idx] = max(maxhappiness(n-1,0),maxhappiness(n-1,2))+v[n][idx];
    }else if(idx==2){
        dp[n][idx] = max(maxhappiness(n-1,1),maxhappiness(n-1,0))+v[n][idx];
    }
    return dp[n][idx];
}

void solve(){
	int n;cin>>n;
	v.resize(n,vector<int>(3));
	dp.resize(n,vector<int>(3,-1));
	for(int i=0;i<n;i++){
        cin>>v[i][0]>>v[i][1]>>v[i][2];
	}
	dp[0][0]=v[0][0];
	dp[0][1]=v[0][1];
	dp[0][2]=v[0][2];
	cout << max(maxhappiness(n-1,0),max(maxhappiness(n-1,1),maxhappiness(n-1,2)))<<"\n";

}
int main(){
	int t=1;//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 15872
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool f = false;
  for (int n = 1; n < B; n++) {
    int m = (A * n) % B;
    if (m == C) {
      f = true;
      break;
    }
  }

  if (f) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    double a,b;
    cin>>a>>b;
    //bool ans=true;
    rep(i,1000){
        if(a+1>(i+1)*0.08&&(i+1)*0.08>=a&&b+1>(i+1)*0.1&&(i+1)*0.1>=b){
            cout<<i+1<<endl;
            //ans==false;
            //break;
            return 0;
        }
    }
    //if(ans)
    cout<<-1<<endl;
}
   



Measured memory_bytes: 256