akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
int m , f , r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if((m<0)&&(f<0)&&(r<0)){break;}
		if((m<0)||(f<0)){printf("F\n");}
		else if((m+f)>=80){printf("A\n");}
		else if((m+f)>=65){printf("B\n");}
		else if((m+f)>=50){printf("C\n");}
		else if((m+f)>=30){if(r>=50){printf("C\n");}else{printf("D\n");}}
		else {printf("F\n");}
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	double n,t,a; cin>>n>>t>>a;
	double mn=1e9,idx;
	double h;
	REP(i,1,n)
	{
		cin>>h;
		double tmp=abs(a-(t-h*0.006));
		//cout<<i<<" "<<h<<" "<<tmp<<"\n";
		if(tmp<mn)
		{
			mn=tmp;
			idx=i;
		}
	}
	cout<<idx<<"\n";
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    ll L, R; cin >> L >> R;

    ll ans = LINF;
    for (ll i = L; i < min(R, L+2019LL); i++) {
        ll l = i % 2019;
        for (ll j = i + 1; j <= min(R, L+2019LL); j++) {
            ll r = j % 2019;
            ans = min(ans, (l*r) % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int a[3];
	for (int i=0;i<3;i++){
		cin>>a[i];
	}		
	
	int c1=0,c2=0;
	for(int i=0;i<3;i++){
		if(a[i]==5)
		c1++;
		else if (a[i]==7)
		c2++;
	}
	
	//	cout<<c1<<" "<<c2<<endl;
	if (c1==2 && c2==1)
	cout<<"YES\n";
	else
	cout<<"NO\n";
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] s = new int[n + 1];
		for (int i = 0; i < n; i++) {
			s[i + 1] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] t = new int[m + 1];
		for (int i = 0; i < m; i++) {
			t[i + 1] = Integer.parseInt(sa[i]);
		}
		br.close();

		long[][] dp = new long[n + 1][m + 1];
		long[][] sum = new long[n + 1][m + 1];
		dp[0][0] = 1;
		for (int i = 0; i <= n; i++) {
			sum[i][0] = 1;
		}
		for (int j = 0; j <= m; j++) {
			sum[0][j] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				if (s[i] == t[j]) {
					dp[i][j] = sum[i - 1][j - 1];
				}
				sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
				if (sum[i][j] < 0) {
					sum[i][j] += 1000000007;
				}
				sum[i][j] %= 1000000007;
			}
		}
		System.out.println(sum[n][m]);
	}
}


Measured memory_bytes: 131540
#include<iostream>

using namespace std;

const int INF=1e9+7;

int main(){
	int n;
	cin>>n;
	int mi=INF;
	int ans=0;
	for(int i=0;i<n;i++){
		int s;
		cin>>s;
		ans+=s;
		if(s%10!=0)mi=min(s,mi);
	}
	if(ans%10==0){
		if(mi!=INF)ans-=mi;
		else ans=0;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
nice_yaku = []
for i in range(1,N+1) :
	if i % 2 == 0 :
		# 偶数は除外する
		continue

	yaku = []
	for j in range(1,i+1) :
		if i % j == 0 :
			yaku.append(j)

	if len(yaku) == 8 :
		nice_yaku.append(i)

print(len(nice_yaku))


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

int main()
{
	int a, b;
	cin >> a >> b;
	while (a != b && a != 1 && b != 1)
	{
		if (a > b)
		{
			a = a - b;
		}
		else
		{
			b = b - a;
		}
	}
	if (a == b)
	{
		cout << a << endl;
		return 0;
	}
	else
		cout << "1" << endl;
	return 0;
}

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

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

    ll ans = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

int res[200005];
int c[200005];
bool vist[200005];
vector<int> adj[200005];

void bfs(int root, int sum) {
    queue<pii> q;
    q.push(make_pair(root, sum));
    while (!q.empty()) {
        pii e = q.front();
        q.pop();
        int u = e.first;
        int s = e.second;
        int m = adj[u].size();
        s += c[u];
        res[u] = s;
        vist[u] = true;
        for (int k = 0; k < m; ++k) {
            int v = adj[u][k];
            if (!vist[v]) {
                q.push(make_pair(v, s));
            }
        }
    }
}

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u - 1].push_back(v - 1);
        adj[v - 1].push_back(u - 1);
    }

    for (int i = 0; i < q; ++i) {
        int p, x;
        scanf("%d %d", &p, &x);
        c[p - 1] += x;
    }

    bfs(0, 0);

    for (int i = 0 ;i < n; ++i) {
        printf("%d", res[i]);
        if (i == n - 1) {
            printf("\n");
        } else {
            printf(" ");
        }
    }
    return 0;
}



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

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

    int res = 0;
    for(int i=0; i<S.size(); ++i) {
        for(int n=res+1; i+n<=S.size(); ++n) {
            string T = S.substr(i, n);
            bool ok = true;
            for(int k=0; k<n; ++k) {
                if(T[k] == 'A' || T[k] == 'C' || T[k] == 'G' || T[k] == 'T') continue;
                ok = false;
            }
            if(ok) res = n;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
h, w = (int(i) for i in input().split(' '))


a=[]
for i in range(h):
    a.append([int(j) for j in input().split(' ')])

j = 0
p = []
tr = []
picked = False

for i in range(h):
                
    step = -1 if i%2 else 1
    j = w-1 if i%2 else 0
    while j >=0 and j < w:
        if a[i][j] % 2:
            if picked == False:
                picked = True
            else:
                tr.append([i,j])
                picked = False
                for t_index in range(len(tr)-1):
                    p.append((tr[t_index], tr[t_index+1]))
                tr = []

        if picked:
            tr.append([i,j])
        j = j + step

print(len(p))
for ans in p:
    print(ans[0][0]+1,ans[0][1]+1,ans[1][0]+1, ans[1][1]+1)


Measured memory_bytes: 44000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(max(a,d),max(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(long long int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define inp(a,start,len) for(long long int i = start;i < len;i++) cin>>a[i]
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}


int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll T = 1;
	// cin>>T;
	while(T--){
		ll n,x,t;
		cin>>n>>x>>t;
		ll ans;
		if(n%x == 0){
			ans = (n/x)*t;
		}
		else{
			ans = (n/x+1)*t;
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int res = 1 << 29;
int N;
bool dame[20];

void dfs(int now){
  if(now >= N){
    res = min(res, now);
    return;
  }
  for(int i=0;i<10;i++)if(!dame[i]){
    if(now == 0 && i == 0)continue;
    dfs(now * 10 + i);
  }
}

int main(){
  cin >> N;
  int K;
  cin >> K;
  for(int i=0;i<K;i++){
    int n;
    cin >> n;
    dame[n] = true;
  }
  dfs(0);
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        A: usize, B: usize,
    }
    let mut ans = 0;
    let mut tmp = 1;
    while tmp < B {
        ans += 1;
        tmp += A-1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
from collections import deque
d = [[1, 0], [-1, 0], [0, -1], [0, 1]]
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [list(input()) for i in range(h)]
visited = [[-1] * w for i in range(h)]
visited[x1 - 1][y1 - 1] = 0
Q = deque([(x1 - 1, y1 - 1)])
while Q:
    nx, ny = Q.popleft()
    if nx == x2 - 1 and ny == y2 - 1:
        exit(print(visited[nx][ny]))
    for dx, dy in d:
        for i in range(k):
            p, q = nx + dx * (i + 1), ny + dy * (i + 1)
            if not (0 <= p < h and 0 <= q < w) or c[p][q] == "@":
                break
            if 0 <= visited[p][q] <= visited[nx][ny]:
                break
            if visited[p][q] == -1:
                Q.append((p, q))
            visited[p][q] = visited[nx][ny] + 1
print(-1)

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

using namespace std;

int main()
{
	string S, C;
	int Q;
	char str[500001];
	int front, rear;
	int com1, com2;
	int reverse = 0;

	cin >> S;
	int moji_count = S.length();

	// strの中央らへんに突っ込む
	int mid = 200001;
	for(int i = mid, j = 0; i < mid + moji_count; i++, j++)
		str[i] = S[j];
	front = mid - 1;
	rear = mid + moji_count;

	cin >> Q;
	for(int i = 0; i < Q; i++){
		cin >> com1;

		if(com1 == 1){
		// 反転
			if(reverse)
				reverse = 0;
			else
				reverse = 1;
		}else if(com1 == 2){
		// 追加
			cin >> com2 >> C;

			if(com2 == 1){
			// 先頭に追加
				if(reverse)
					str[rear++] = C[0];
				else
					str[front--] = C[0];
			}else if(com2 == 2){
			// 末尾に追加
				if(reverse)
					str[front--] = C[0];
				else
					str[rear++] = C[0];
			}
		}
	}

	// print
	if(reverse){
		for(int i = rear - 1; i > front; i--)
			printf("%c", str[i]);
		printf("\n");
	}else{
		for(int i = front + 1; i < rear; i++)
			printf("%c", str[i]);
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<int> dp(n+1,0);
    dp[0] = 1;
    for(int i=0; i<=n; i++){
        for (int next=i+1; next<=min(i+2,n); next++){
            dp[next] += dp[i];
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	int n,ball[10],under;
	cin >> n;
	for (int data = 0; data < n; ++data) {
		for (int i = 0; i < 10; ++i) cin >> ball[i];
		under = ball[0];
		ball[0] = 0;
		for (int i = 1; i < 10; ++i) {
			if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
		}
		int k;
		for (k = 1; k < 10; ++k) {
			if (ball[k] == 0)continue;
			else {
				under = ball[k];
				ball[k] = 0;
				break;
			}
		}
		char bo = true;
		for (int i = k + 1; i < 10; ++i) {
			if (ball[i] == 0)continue;
			else if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
			else {
				bo = false;
				break;
			}
		}
		if (bo)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int sum[19][19]={};

int main() {
	int N;
	cin >> N;
	ll ans=0;
	for(int i=0; i<N; ++i){
	    string S;
	    cin >> S;
	    bool flag=false;
	    ll s=0LL;
	    int u=9;
	    for(int j=0; j<S.size(); ++j){
	        if(flag) --u;
	        if(S[j]=='.') flag=true;
	        else (s *= 10) += S[j]-'0';
	    }
	    while(u){
	        s *= 10;
	        --u;
	    }
	    int t=0, f=0;
	    while(s%2==0 && t<18){
	        ++t;
	        s /= 2;
	    }
	    while(s%5==0 && f<18){
	        ++f;
	        s /= 5;
	    }
	    ans += sum[18-t][18-f];
	    for(int j=0; j<=t; ++j){
	        for(int k=0; k<=f; ++k){
	            ++sum[j][k];
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int M, D;
  cin >> M >> D;
  int count = 0;
  REPS(i, M) {
    REPS(j, D) {
      int d1 = j % 10;
      int d10 = j / 10;
      if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
        count++;
      }
    }
  }
  print(count);
  // print();
}

Measured memory_bytes: 256
while True:
   h,w = map(int, raw_input().split())
   if h == w == 0:
       break
   ret = '#'*w+'\n'
   ret += ('#' + '.' * (w-2) + '#\n') * (h - 2)
   ret += '#'*w+'\n\n'
   print ret,

Measured memory_bytes: 6416
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
  for j in range(i+1, n):
    k = 2*j - i
    if k < n and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)


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

#define rep(v,c) for(int v=0; v<(int)c; ++v)

using pint=pair<int,int>;

pint solve(int n){
  int A=0,B=0;
  rep(i,n){
    int a,b; cin>>a>>b;
    if(a>b) A+=a+b;
    else if(a<b) B+=a+b;
    else A+=a,B+=b;
  }
  return pint(A,B);
}

int main(void){
  int n;
  vector<pint> ans;
  while(1){
    cin>>n;
    if(n==0) break;
    auto rec=solve(n);
    ans.push_back(rec);
  }
  rep(i,ans.size()){
    int a,b; tie(a,b)=ans[i];
    cout<<a<<" "<<b<<endl;
  }
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
int h,w;
char a[1500][1500];
int dp[1500][1500];
signed main(){
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
		}
	}

	dp[h-1][w-1]=1;
	for(int i=h-1;i>=0;i--){
		for(int j=w-1;j>=0;j--){
			if(i==h-1&&j==w-1)continue;
			if(a[i][j]=='#')continue;
			if(i==h-1)dp[i][j]=dp[i][j+1];
			else if(j==w-1)dp[i][j]=dp[i+1][j];
			else dp[i][j]=dp[i+1][j]+dp[i][j+1];
			dp[i][j]%=mod;
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}


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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int snakeY(int i, int w) {
    return i / w;
}

int snakeX(int i, int w) {
    int y = snakeY(i, w);
    if (y % 2 == 0) {
        return i % w;
    }
    return (w - 1) - (i % w);
}


int main() {

    int h, w, n;
    cin >> h >> w >> n;

    vector<vector<int>> board(h, vector<int>(w, -1));

    int k = 0;
    rep(i, n) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            board[snakeY(k, w)][snakeX(k, w)] = i + 1;
            k++;
        }
    }

    rep(y, h) {
        rep(x, w) {
            cout << board[y][x] << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n,m, k;
int main() {
	io
	int x, y;
	cin>>x>>y;
	if(y == x*4) cout<<"Yes";
	else if(y == x*2) cout<<"Yes";
	else {
		bool can = false;
		for(int i = 1; i<x; i++) {
			if(i*2 + (x-i)*4 == y) can = true;
		}
		cout<<(can ? "Yes" : "No");
	}
}



Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,sum=0;
  cin >> n;
  vector<int>l(n);
  for(int i=0; i<n; i++){
    cin >> l.at(i);
    sum+=l.at(i);
  }
  sort(l.begin(),l.end());
  if(l.at(n-1)>=sum-l.at(n-1)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
double EPS = 1e-9;
constexpr ll MOD =  1e9+9;
using namespace std;
vector<int> node[2][29];

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int res = 0;
    for(int i = 0;i < n;i++){
        cin >> b[i];
        res ^= b[i];
    }
//    cout << res << endl;
    for(int i = 0;i < 29;i++)
        for(int j = 0;j < n;j++){
            node[(b[j]&(1<<i)) ? 1 : 0][i].push_back(((1 << i) - 1) & b[j]);
        }
    for(int i = 0;i < 29;i++){
        sort(node[0][i].begin(), node[0][i].end());
        sort(node[1][i].begin(), node[1][i].end());
    }

    int bts[29] = {0};
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 29;j++){
            if(j == 0){
                if(a[i] & 1){
                    bts[0] ^= (node[0][0].size())&1;
                }else{
                    bts[0] ^= (node[1][0].size())&1;
                }
                continue;
            }

            if(a[i]&(1<<j)){
                auto it = lower_bound(node[0][j].begin(), node[0][j].end(), (1<<j) - (((1<<j)-1) & a[i]));
                bts[j] ^= (it - node[0][j].begin())&1;
                it = lower_bound(node[1][j].begin(), node[1][j].end(), (1<<j) - (((1<<j)-1) & a[i]));
                bts[j] ^= (node[1][j].end() - it)&1;
            }else{
                auto it = lower_bound(node[0][j].begin(), node[0][j].end(), (1<<j) - (((1<<j)-1) & a[i]));
                bts[j] ^= (node[0][j].end() - it)&1;
                it = lower_bound(node[1][j].begin(), node[1][j].end(), (1<<j) - (((1<<j)-1) & a[i]));
                bts[j] ^= (it - node[1][j].begin())&1;
            }
        }
    }
    ll ans = 0;
    for(int i = 0;i < 29;i++){
        ans |= (bts[i] << i);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 30800
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;

	vector<ULL> F, iF, I;

	ULL Solve2(UL R, UL C) {
		ULL ans = 1;
		ans = ans * F[R + C + 2] % M;
		ans = ans * iF[R + 1] % M;
		ans = ans * iF[C + 1] % M;
		return ans;
	}

	void Solve() {
		UL r1, r2, c1, c2; cin >> r1 >> c1 >> r2 >> c2;
		UL S = r2 + c2 + 10;
		{
			F.resize(S + 1); iF.resize(S + 1); I.resize(S + 1);
			F[0] = 1; rep(i, S) F[i + 1] = F[i] * (i + 1) % M;
			I[1] = 1; for (UL i = 2; i <= S; i++) I[i] = M - M / i * I[M % i] % M;
			iF[0] = 1; rep(i, S) iF[i + 1] = iF[i] * I[i + 1] % M;
		}
		ULL ans = Solve2(r2, c2) + Solve2(r1 - 1, c1 - 1) +
			(M - Solve2(r1 - 1, c2)) + (M - Solve2(r2, c1 - 1));
		cout << (ans % M) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 47104
package main

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

type Reader struct {
	reader *bufio.Reader
}

func toInt(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

func (reader *Reader) read() (int, int, int) {
	line, _, _ := reader.reader.ReadLine()
	stringLine := string(line)
	slitted := strings.Split(stringLine, " ")
	return toInt(slitted[0]), toInt(slitted[1]), toInt(slitted[2])
}


func sum(splitted[]string) int {
	sum := 0
	for _, v := range splitted {
		sum += toInt(v)
	}
	return sum
}


func numSum(num int) int {
	strNum := strconv.Itoa(num)
	splitted := strings.Split(strNum, "")
	return sum(splitted)
}

func main() {
	reader := &Reader{}
	reader.reader = bufio.NewReader(os.Stdin)



	N, A, B := reader.read()

	var result = 0
	for i := 1; i <= N; i += 1 {
		tmpSum := numSum(i)
		if tmpSum >= A && tmpSum <= B {
			result += i
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll n=ii()%10;
    if(n==3){
        ose("bon");
    }else if(n==0||n==1||n==6||n==8){
        ose("pon");
    }else{
        ose("hon");
    }
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                tmp = [L[i], L[j], L[k]]
                tmp.sort()
                if tmp[0]+tmp[1] > tmp[2]:
                    ans += 1

print(ans)

Measured memory_bytes: 68204
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int H = sc.nextInt();
			final int W = sc.nextInt();
			
			boolean[][] isBlock = new boolean[H][W];
			for(int i = 0; i < H; i++) {
				final char[] chs = sc.next().toCharArray();
				
				for(int j = 0; j < W; j++) {
					isBlock[i][j] = chs[j] == '#';
				}
			}
			
			int[][] LS = new int[H][W];
			int[][] RS = new int[H][W];
			int[][] US = new int[H][W];
			int[][] DS = new int[H][W];
			
			for(int i = 0; i < H; i++) {
				for(int j = 1; j < W; j++) {
					LS[i][j] = (isBlock[i][j] || isBlock[i][j - 1] ? 0 : LS[i][j - 1] + 1); 
				}
				for(int j = W - 2; j >= 0; j--) {
					RS[i][j] = (isBlock[i][j] || isBlock[i][j + 1] ? 0 : RS[i][j + 1] + 1); 
				}
			}
			
			for(int j = 0; j < W; j++) {
				for(int i = 1; i < H; i++) {
					US[i][j] = (isBlock[i][j] || isBlock[i - 1][j] ? 0 : US[i - 1][j] + 1);
				}
				for(int i = H - 2; i >= 0; i--) {
					DS[i][j] = (isBlock[i][j] || isBlock[i + 1][j] ? 0  :DS[i + 1][j] + 1);
				}
			}
			
			int answer = 0;
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					if(isBlock[i][j]) { continue; }
					
					answer = Math.max(answer, US[i][j] + LS[i][j] + DS[i][j] + RS[i][j] + 1);
				}
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 110120
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back 
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int> 
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second 
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0); 
const int32_t mod = 1e9+7;
const int32_t maxn=1e5+1;

int n,w,dp[100][maxn];
vpi v;

void solve(){
    cin>>n>>w; v.resize(n);
    rep(i,0,n) cin>>v[i].x>>v[i].y;
    rep(i,0,n) rep(j,0,maxn) dp[i][j]=mod;
    dp[0][0]=0;
    dp[0][v[0].y]=v[0].x;

    rep(i,1,n){
        dp[i][0]=0;
        rep(j,1,maxn){
            dp[i][j]=dp[i-1][j];
            if(j>=v[i].y){
                dp[i][j]=min(dp[i][j],dp[i-1][j-v[i].y]+v[i].x);
            }
        }
    }

    for(int i=maxn-1;i>=0;i--){
        if(dp[n-1][i]<=w){
            cout<<i;return;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;                                                                                                                  
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 81716
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, A, B; cin >> N >> A >> B;
    vec p(N); readv(p);

    mat dp(N + 1, vec(N + 1, INF));
    dp[0][0] = 0;
    REP(i, N){
        //REP(j, N + 1) dp[i + 1][j] = dp[i][j];
        REP(j, N + 1){
            if(j < p[i]) Min(dp[i + 1][p[i]], dp[i][j]);
            if(j < p[i]) Min(dp[i + 1][j], dp[i][j] + A);
            else Min(dp[i + 1][j], dp[i][j] + B);
        }
    }
    int ans = INF;
    REP(j, N + 1) Min(ans, dp[N][j]);
    cout << ans << endl;

    return 0;
}


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

class Edge{
public:
    LL from,to,value;
    Edge(){

    }
    Edge(LL f, LL t, LL v){
        from = f;
        to = t;
        value = v;
    }
};

std::vector<LL> dijkstra(int s,int N,vector<Edge> E){
    std::vector<LL> ans(N, 1e9);
    std::vector<std::vector<Edge>> Edges(N);
    for(auto e : E){
        Edges.at(e.from).push_back(e);
    }
    priority_queue<pair<LL,LL>, std::vector<pair<LL,LL>>, greater<pair<LL,LL>>> que;
    ans.at(s)= 0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        pair<LL,LL> p = que.top();que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
                if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}

class UnionFind {
public:
    vector<int> data;
 	UnionFind(int size) : data(size, -1) { }
 	bool connect(int x, int y) {
  		x = root(x); y = root(y);
  		if (x != y) {
   			if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

void solve(long long N, long long u, long long v, std::vector<long long> A, std::vector<long long> B){
    vector<Edge> E;
    v--,u--;
    for(int i = 0;i < N-1;i++){
        A[i]--,B[i]--;
        E.push_back(Edge(A[i], B[i], 1));
        E.push_back(Edge(B[i], A[i], 1));
    }
    LL w = v,h = u;
    LL q = N;
    vector<LL> d1 = dijkstra(w, q, E);
    vector<LL> d2 = dijkstra(h, q, E);
    UnionFind Uni(N);
    LL ans = 0;
    for(int i = 0;i < N;i++){
        if(d1[i] > d2[i]){
           // cout<<i<<endl;
            ans = max(ans, d1[i] - 1);
        }
    }
    cout<<ans<<endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long u;
    scanf("%lld",&u);
    long long v;
    scanf("%lld",&v);
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, u, v, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 23352
# include <bits/stdc++.h>
# define int long long
# define fi first
# define se second

using namespace std ;

const int N = 200;
int wr[N], vr[N], dp[N][100001] ;

int32_t main() {
    //freopen("haybales.in", "r", stdin ) ;
    //freopen("haybales.out", "w", stdout ) ;
    int n, W;cin >> n >> W;
    for( int i = 0 ; i < n ; i ++ ) {
        cin >> wr[i] >> vr[i] ;
    }
    for( int i = 1 ; i <= n ; i ++ ) {
        for( int w = 1 ; w <= W ; w ++ ) {
            if( wr[i-1] <= w ) {
                dp[i][w] = max( dp[i-1][w], vr[i-1] + dp[i-1][w-wr[i-1]] );
            }
            else {
                dp[i][w] = dp[i-1][w] ;
            }
        }
    }
    cout << dp[n][W] ;
}


Measured memory_bytes: 81724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string c;
  cin >> c;
  if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o"){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

long long int mod(long long int a) {
	return a % (long long int) (1e9 + 7);
}


long long int possibleCombination(long long int n, long long int i) {
	long long int min;
	long long int max;
	if (i % 2) {
		min = ((i-1) / 2) * i;
		max = ((2 *n - i + 1)/2) * i;
	} else {
		min = (i-1) * (i/2);
		max = (2 *n - i + 1) * (i/2);
	}

	return max - min + 1;

}


int main() {
	int N, K;

	std::cin >> N >> K;

	long long int sum = 0;
	for (int i = K; i <= N +1; i++) {
		sum = mod(mod(sum) + mod(possibleCombination((long long int) N, (long long int) i))); 
	}


	std::cout << sum << std::endl;


}


Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

struct Pair{
    int a;
    int b;

    Pair(int x, int y) {
        this->a = x;
        this->b = y;
    }
};

int main() {
    int t;
    std :: cin >> t;

    std :: map < std :: string , int > hash;

    while(t--) {
        std :: string str;
        std :: cin >> str;

        hash[str]++;
    }

    std :: string arr[] = {"AC", "WA", "TLE" , "RE"};

    for(auto& i : arr) {
        std :: cout << i << " x " << hash[i] << '\n';
    }
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
   int h, n, temp;
   cin >>h >>n;
   for(int i =0; i <n; ++i){
       cin >> temp;
       h -= temp;
   }
   if(h>0){
       cout<<"No";
   }
   else{
       cout<< "Yes";
   }
}

Measured memory_bytes: 256
from sys import stdin
import heapq
K,T = [int(x) for x in stdin.readline().rstrip().split()]
data = [(-int(b),a) for a,b in enumerate(stdin.readline().rstrip().split())]
heapq.heapify(data)
ans = 0
cake_num = -1
cake_count = 0
flag = True
 
if T == 1:
  ans = K-1
else:
  while flag:
    c_c,c_n = heapq.heappop(data)
    if c_n == cake_num:
        c_c2,c_n2 = heapq.heappop(data)
        if c_c2 == 0:
            ans = abs(c_c)
            flag = False
        else:
            heapq.heappush(data,(c_c2+1,c_n2))
        cake_num = c_n2
        heapq.heappush(data,(c_c,c_n))
        #flag = False
    else:
        heapq.heappush(data,(c_c+1,c_n))
        cake_num = c_n
    if c_c == 0:
      ans = 0
      flag = False
    
print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt(), m = sc.nextInt();
            if ((n | m) == 0) {
                break;
            }
            int[] l = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = sc.nextInt();
            }
            Arrays.sort(l);
            int sum = 0;
            for (int i = n - 1, j = 1; i >= 0; i--, j++) {
                if (j % m != 0) {
                    sum += l[i];
                }
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 59332
N = int(input())
T = [int(input()) for i in range(N)]


def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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

print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template <class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iterator i=(c).begin();i!=(c).end();++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS=1e-10;
const double PI=acos(-1.0);

int main(){
	int N;

	while(cin >> N, N) {
		int W, H;
		cin >> W >> H;

		vvi field(H, vi(W, 0));

		REP(i, N) {
			int x, y;
			cin >> x >> y;
			field[y-1][x-1] = 1;
		}

		int S, T;
		cin >> S >> T;

		int num, max = 0;
		FOR(a, 0, H-T+1) {
			FOR(b, 0, W-S+1) {
				num = 0;
				FOR(c, a, a+T) {
					FOR(d, b, b+S) {
						num += field[c][d];
					}
				}
				if(num > max) {
					max = num;
				}
			}
		}

		cout << max << endl;
	}
}

Measured memory_bytes: 0
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])




Measured memory_bytes: 55136
a, b, c, x, y = map(int, input().split())
p = c * 2 * max(x, y)
q= a * x + b * y
r = s = 10 ** 10
if x >= y:
    r = c * 2 * y + a * (x - y)
else:
    s = c * 2 * x + b * (y - x)
print(min(p, q, r, s))

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

using ll = long long;
using pii = pair<int, int>;

int main(int argc, char **argv) {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

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

  double a, b, x; cin >> a >> b >> x;
  auto vol = [&](double ang) {
    ang = acos(-1)/2.0-ang;
    if(atan2(a,b) >= ang) {
      return b*tan(ang)*b/2;
    }
    else {
      double ang2 = acos(-1)/2.0-ang;
      return a*b - a*tan(ang2)*a/2;
    }
  };

  double l = 0, r = acos(-1)/2.0;
  int iter = 200;
  while(iter--) {
    double m = (l+r)/2;
    if(vol(m)*a <= x) r = m;
    else l = m;
  }

  cout << fixed;
  cout.precision(9);
  cout << l*180/acos(-1) << endl;

  return 0;
}


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

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

  if (A+B>C+D){
    cout<<"Left"<<endl;
  }
  
  else if (A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  
  else{
    cout<<"Right"<<endl;
  }
}

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

const int MAX = 200005;
long long A[MAX];

int main() {
    int N;
    long long a;
    scanf("%d", &N);
    A[0] = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &a);
        A[i] = A[i-1] + a;
    }

    long long ans;
    ans = 2000000000;
    for (int i = 1; i < N; i++) {
        long long b;
        b = abs(A[i] - (A[N] - A[i]));
        ans = min(ans, b);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

    long int resA,resB;
    double resC;
    resA = a / b;
    resB = a % b;
    resC = (double)a / (double)b;

    cout << resA << " " << resB << " " << fixed << resC << endl;

    return 0;
}

Measured memory_bytes: 1244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
 * 0007:Debt Hellの解答
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = BigDecimal.valueOf(100000L);

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = new BigDecimal("0.05");

    /** \1000未満の繰り上げ計算用 */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000);

    /**
     * n 週間後の借金の残高を出力する。<br>
     * ※n は 100 以下とする。
     * 
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        System.out.println(calcDebt(weeks));
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     * @throws IOException 標準入力読取り失敗時
     */
    private static int getWeeks() throws IOException {
        
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
        
        int weeks = Integer.parseInt(bufferedReader.readLine());
        
        bufferedReader.close();
        streamReader.close();
        
        return weeks;
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     * @return n週間後の借金額
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }

        return finalDebt;
    }

}

Measured memory_bytes: 16956
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  ll K , T;

  cin >> K >> T;
  vector<ll> a;
  rep(i,T) {
    ll inp; cin >> inp;
    a.pb(inp);
  }

  sort(all(a));

  ll MAX = a[a.size()-1];
  MAX--;
  rep(i,a.size()-1){
    MAX-=a[i];
  }

  if(MAX < 0) cout << 0 << endl;
  else cout << MAX << endl;
  
  return 0;
}


Measured memory_bytes: 256