akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll f(ll b,ll n) { return n < b ? n : ( f(b,n/b) + n%b ); }
ll n,s,val,ans;
inline ll check(ll a,ll b)
{
    ll low = a , high = s - a;
    if ( high < b && low < b && high >= 0 && b >= 2 )
        ans = min( ans , b );
}
int main(void)
{
    scanf("%lld%lld",&n,&s);
    if ( n < s ) return puts("-1") , 0;
    if ( n == s ) return printf("%lld\n",n+1) , 0;
    for (ll i=2;i*i<=n;i++)
        if ( f(i,n) == s ) return printf("%lld\n",i) , 0;
    val = n - s , ans = 1LL<<60;
    for (ll i=1;i*i<=val;i++)
        if ( val % i == 0 ) check( i , val/i+1 );
    printf("%lld\n", ans == 1LL<<60 ? -1 : ans );
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int i, j, k;
    int n, m, l;
    int a[100][100]={};
    int b[100][100]={};
    long long int c[100][100]={};
     
    scanf("%d%d%d", &n, &m, &l);
     
    for(i=0; i<n; i++) {
        for(k=0; k<m; k++)
            scanf("%d", &a[i][k]);
    }
    for(k=0; k<m; k++) {
        for(j=0; j<l; j++)
            scanf("%d", &b[k][j]);
    }
     
    for(i=0; i<n; i++) {
        for(j=0; j<l; j++) {
            for(k=0; k<m; k++)
                c[i][j]+=a[i][k]*b[k][j];
        }
    }
     
    for(i=0; i<n; i++) {
        for(j=0; j<l; j++) {
            printf("%lld", c[i][j]);
            if(j!=l-1) putchar(' ');
        }
        putchar('\n');
    }
     
    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

vector<int> sieve(int n) {
  vector<int> p(n);p[2]=2;
  for(int i=3;i<n;i+=2)p[i]=i;
  for(int i=3;i*i<n;i+=2)if(p[i])for(int j=i*i;j<n;j+=i)p[j]=0;
  p.erase(remove(p.begin(), p.end(), 0), p.end());
  return p;
}

void Main() {
  vector<int> p=sieve(55555);
  int n;
  R n;
  vector<int> v;
  rep(i,p.size()) {
    if(p[i]%5==1) v.pb(p[i]);
  }
  PR(v,n);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

void yes(){
  cout<<"Yes"<<endl;
}
int main(void)
{
  string s;
  cin>>s;
  if(s=="abc")
    yes();
  else if(s=="acb")
    yes();
  else if(s=="bac")
    yes();
  else if(s=="bca")
    yes();
  else if(s=="cab")
    yes();
  else if(s=="cba")
    yes();
  else
    cout<<"No"<<endl;
}

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

int main(){
    while(1){
        int n=0;
        cin>>n;
        if(n==0)break;
        int p[45]={0};
        p[0]=1;
        p[1]=1;
        p[2]=2;
        for(int i=3;i<=30;i++){
            p[i]=p[i-1]+p[i-2]+p[i-3];
        }
        int ans=p[n]/3650;
        if(p[n]%3650>0)ans++;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
# include <bits/stdc++.h>
using namespace std;
long long a1,b1;
string s;
int main()
{
	cin>>s;
	if (s[0]=='A' || s[1]=='A' || s[2]=='A')
	a1++;
		if (s[0]=='B' || s[1]=='B' || s[2]=='B')
	b1++;
	if (a1!=0 && b1!=0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}
ll n,k;
vector<int> a;    

bool check(int x){
    int sum=0;
    for(int i=1;i<n+1;i++){
        sum += (a[i]-1)/x;
    }
    return sum <= k;
}

void solve(){

    cin >> n >> k;
    a.resize(n+1);
    for(ll i=1;i<n+1;i++)
        cin >> a[i];
    int l = 1,r=1e9 , ans;
    while(l<=r){
        int mid = (l+r)/2;
        if(check(mid)){
            ans = mid;
            r = mid-1;
        }else l = mid+1;
    }
    cout << ans;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2503;
const ll INF=1LL<<50;
vector<int> S[MAX],can(MAX,0);
vector<pair<int,ll>> T[MAX];

vector<ll> dis(MAX);
int N;

bool bell(){
    for(int i=0;i<N;i++){
        dis[i]=INF;
    }
    dis[0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<T[j].size();k++){
                int a=T[j][k].first;
                ll b=T[j][k].second;
                if(dis[j]!=INF&&dis[a]>dis[j]+b){
                    dis[a]=dis[j]+b;
                    if(i==N-1) return true;
                }
            }
        }
    }
    return false;
}

void DFS(int u){
    can[u]=1;
    stack<int> ST;
    ST.push(u);
    
    while(ST.size()){
        int a=ST.top();
        ST.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(can[b]==0){
                can[b]=1;
                ST.push(b);
            }
        }
    }
    
    return;
}

int main(){
    
    int M;
    ll P;cin>>N>>M>>P;
    vector<pair<pair<int,int>,ll>> W(M);
    
    for(int i=0;i<M;i++){
        int a,b;
        ll c;cin>>a>>b>>c;
        a--;b--;
        W[i]=make_pair(make_pair(a,b),c);
        S[b].push_back(a);
    }
    
    DFS(N-1);
    
    for(int i=0;i<M;i++){
        int a=W[i].first.first;
        int b=W[i].first.second;
        ll c=W[i].second;
        
        if(can[a]&&can[b]){
            T[a].push_back(make_pair(b,-(c-P)));
        }
    }
    
    if(bell()) cout<<-1<<endl;
    else cout<<max(0LL,-dis[N-1])<<endl;
    
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int w,h,n; cin >> w >> h >> n;
    int r = w;
    int l = 0;
    int H = h;
    int L = 0;
    for(int i = 0; i < n; i ++) {
        int x, y, a; cin >> x >> y >> a;
        if(a==1) l = max(l,x);
        else if(a==2) r = min(r,x);
        else if(a==3) L = max(L,y);
        else if(a==4) H = min(H,y);
        else continue;
    }
    int ans = max(0, r-l) * max(0, H-L);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int x = sc.nextInt();
		int y = sc.nextInt();
		if ((2 * y - x) % 3 != 0 || (2 * x - y) % 3 != 0 || 2 * y - x < 0 || 2 * x - y < 0) {
			System.out.println(0);
			return;
		}
		int a = (2 * y - x) / 3;
		int b = (2 * x - y) / 3;
		COMinit(a + b + 1);
		System.out.println(COM(a + b, a));
	}
	static long[] fac;
	static long[] finv;
	static long[] inv;

	static void COMinit(int n) {
		fac = new long[n];
		finv = new long[n];
		inv = new long[n];
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < n; i++) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - inv[(int) (mod % i)] * (mod / i) % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
	static long COM(int n, int k) {
		if (n < k || (n < 0 || k < 0)) {
			return 0;
		}
		return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
	}
}



class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 46292
import java.io.*;
import java.util.*;

public class Main {

	static long m = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
//		StringBuilder sb = new StringBuilder();
//		int T = scn.nextInt(), tcs = 0;
//		A: while (tcs++ < T) {
//			int n = scn.nextInt();
//
//		}
//		System.out.println(sb);
		String s = scn.next(), t = scn.next();
		System.out.println(s.equals(t.substring(0, t.length() - 1)) ? "Yes" : "No");
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

Measured memory_bytes: 32720
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  long long n,k,i;
  cin>>k;
  cin>>s;
  n=s.length();
  if(n<=k)
  {
    cout<<s;
    return 0;
  }
    for(i=0;i<k;i++)
      cout<<s[i];
  cout<<"...";
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int min(int x, int y){return x < y ? x : y;}
int main(){
	int L, R;
	cin >> L >> R;
	int size = R - L + 1;
	if(size > 2019){
		cout << 0 << endl;
		return 0;
	}
	int v[size];
	for(int i = 0; i < size; i++) v[i] = (L + i) % 2019;
	int res = 2018;
	for(int i = 0; i < size - 1; i++)
		for(int j = i + 1; j < size; j++)
			res = min(res, (v[i]*v[j])%2019); 
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
    int n;
    cin>>n;
    vector<ll> a(n),left(n+1,0),right(n+1,0);
    for(int i=0;i<n;i++)cin>>a.at(i);
    ll x=0,y=0;
   for(int i=0;i<n;i++)left.at(i+1)=left.at(i)+a.at(i);
   for(int i=n-1;i>=0;i--)right.at(i)=right.at(i+1)+a.at(i);
   ll ans=inf;
   for(int i=1;i<n;i++){//１枚以上取る
      ll res=abs(left.at(i)-right.at(i));
      ans=min(ans,res);
   }
    cout<<ans<<endl;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a >= b && a >= c){
        cout << b+c << endl;
    }
    else if (b >= a && b >= c){
        cout << a+c << endl;
    }
    else{
        cout << a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;

/*
 * H - Grid
 */
public class Main
{
private BigInteger[][] cache;
private boolean[][] wall;

public static void main( String[] args ) throws Exception
{
	new Main().run();
}

public void run() throws Exception
{
	final BufferedReader reader = new BufferedReader( new InputStreamReader( getInputStream() ) );
	String line = reader.readLine();
	String[] array = line.split( " " );
	final int H = Integer.parseInt( array[ 0 ] );
	final int W = Integer.parseInt( array[ 1 ] );
	wall = new boolean[ H ][];
	cache = new BigInteger[ H ][];
	for( int i = 0; i < H; ++i )
	{
		cache[ i ] = new BigInteger[ W ];
		Arrays.fill( cache[ i ], null );
	}
	int h = 0;
	while( true )
	{
		line = reader.readLine();
		if( line == null )
		{
			break;
		}
		wall[ h ] = new boolean[ W ];
		for( int i = 0; i < W; ++i )
		{
			wall[ h ][ i ] = (line.charAt( i ) == '#');
		}
		++h;
	}

	h = H - 1;
	int w = W - 1;

	BigInteger count = getRouteCount( h, w );
	p( count.mod( BigInteger.valueOf( 1000000000L + 7 ) ) );
	//p( count % (1000000000L + 7) );
}

public BigInteger getRouteCount( final int h, final int w )
{
	if( h == 0 && w == 0 )
	{
		return BigInteger.valueOf( 1 );
	}
	else
	{
		BigInteger cached = cache[ h ][ w ];
		if( cached != null )
		{
			return cached;
		}
		if( wall[ h ][ w ] == true )
		{
			final BigInteger result = BigInteger.valueOf( 0 );
			cache[ h ][ w ] = result;
			return result;
		}
		else
		{
			BigInteger count = BigInteger.valueOf( 0 );
			if( h > 0 )
			{
				count = count.add( getRouteCount( h - 1, w ) );
			}
			if( w > 0 )
			{
				count = count.add( getRouteCount( h, w - 1 ) );
			}
			cache[ h ][ w ] = count;
			return count;
		}
	}
}

public static void p( Object o )
{
	System.out.println( o );
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

}


Measured memory_bytes: 217108
#include<bits/stdc++.h>
using namespace std;
typedef long long Long;

int main(){
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	Long n,m;cin>>n>>m; 
	Long resp=0;
	resp=(n*(n-1))/2+((m)*(m-1))/2,
	cout<<resp;
}

Measured memory_bytes: 256
# Contest No.: ABC169
# Problem No.: B
# Solver:      JEMINI
# Date:        20200531

import sys
import heapq

def main():
    n = int(input())
    nums = list(map(int, sys.stdin.readline().split()))
    ans = 1
    for i in nums:
        if i == 0:
            ans = 0
            break
        if ans > 10 ** 18:
            continue
        ans *= i
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 82516
package main

import (
	"fmt"
	"math"
)

var W, H, N int

func main() {
	fmt.Scan(&W, &H, &N)
	var x_left, x_right int = 0, W
	var y_up, y_down int = H, 0

	for i := 0; i < N; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)

		if c == 1 {
			x_left = max(x_left, a)
		} else if c == 2 {
			x_right = min(x_right, a)
		} else if c == 3 {
			y_down = max(y_down, b)
		} else {
			y_up = min(y_up, b)
		}
	}

	fmt.Println(max(x_right-x_left, 0) * max((y_up-y_down), 0))
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


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

signed main() {
	int n; cin >> n;
	double ans = 0;
	rep(i, n) {
		double a; string s;
		cin >> a >> s;
		if (s == "JPY")ans += a;
		else ans += a * 380000;
	}
	printf("%.9lf\n", ans);
}

Measured memory_bytes: 256
s=gets.chomp
a=s.each_char.map(&:to_i).reverse
l=[1]+[0]*2018
z=s.size
if z<5
  puts 0
  exit
else
  k=1
  ll=0
  z.times do |i|
    ll=(ll+a[i]*k)%2019
    l[ll]+=1
    k=k*10%2019
  end
end
c=0
l.each do |cc|
  if cc>1
    c+=cc*(cc-1)/2
  end
end
puts c

Measured memory_bytes: 18080
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        S = int(input())
    else:
        pass

    AA = S // 100
    BB = S % 100

    if (0 < AA <= 12) & (0 < BB <= 12):
        print("AMBIGUOUS")
    elif(0 < AA <= 12):
        print("MMYY") 
    elif(0 < BB <= 12):
        print("YYMM")
    else:
        print("NA")

if __name__ =='__main__':
    main()

Measured memory_bytes: 21504
z,r,o=lambda:raw_input().split(),range,input
while 1: 
    t={}
    c=o()
    if c==0:break
    for i in r(c):
        f,q=z()
        t[f]=int(q)
    for i in r(o()):
        f=z()
        m=sum([t[j] if j in t else 0 for j in f[2:]])
        q=t[f[0]]
        t[f[0]]=q if m>q else m
    print t[raw_input()]

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

int main()
{

  int H, W;
  string hash = "##";
  cin >> H >> W;
  vector<string> A(H);
  for (int i = 0; i < H; i++)
  {
    cin >> A[i];
    A[i] = '#' + A[i] + '#';
  }

  for (int i = 0; i < W; i++)
  {
    hash += '#';
  }

  cout << hash << endl;
  for (int i = 0; i < H; i++)
  {

    cout << A[i] << endl;
  }
  cout << hash << endl;

  return 0;
}


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

int main()
{
	string s,t;
	cin>>s>>t;
	int n=s.size();
	string m="";
	for(int i=0;i<n;i++)
	{
		m+=t[i];
	}
	if(m==s)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3632
// Originalcode: https://atcoder.jp/contests/abc175/submissions/15970101

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG

ll dp[3005][3005][5];
ll m[3005][3005];

int main(){
  int r,c,k;
  cin >> r >> c >> k;
  rep(i,k){
    int a,b;
    ll x;
    cin >>a>>b>>x;
    m[a][b]=x;
  }
  rep(i,r){
    rep(j,c){
      dp[i+1][j+1][0]=max(dp[i][j+1][4],dp[i+1][j][0]);
      for(int p=1;p<4;p++)
        dp[i+1][j+1][p+1]=max(dp[i][j+1][4]+m[i+1][j+1],max(dp[i+1][j][p]+m[i+1][j+1],dp[i+1][j][p+1]));
    }
  }
  cout << dp[r][c][4] << endl;
}


Measured memory_bytes: 425992
#pragma GCC optimize("O3")
#include<stdint.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define VIS(it,con) for(auto it=con.begin();it!=con.end();++it)
#define pob pop_back
#define pf push_front
#define pof pop_front
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mid (l+r>>1)
#define lch (idx*2+1)
#define rch (idx*2+2)
/*****************************************************************************/
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define MST(a,v) memset(a,(v),sizeof a)
#define pb push_back
#define F first
#define S second
#define endl '\n'
//																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cerr<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif
/***********************************default***********************************/
const int maxn=159;
int n,kk,m,dp[2][maxn][maxn][maxn],par[2][maxn/2];

main(){
	IOS;
	cin>>n>>kk>>m;
	const int mo=m;
	if(kk&1){
		fill(dp[0][0][0],dp[0][0][0]+n,0);
		dp[0][0][0][n]=1;
		REP(i,0,n){
			int t=i&1;
//			REP(j,0,i+1-(i+1)/2+1)REP(k,0,(i+1)/2+1)REP(l,i+1,n+1)dp[!t][j][k][l]=0;
			MST(dp[!t],0);
			REP(j,0,i-i/2+1){
				REP(k,0,i/2+1){
					REP(l,i,n+1){
						if(l!=n&&l%2!=i%2)(dp[!t][0][j][l]+=dp[t][j][k][l])%=mo;
						else(dp[!t][0][j][n]+=dp[t][j][k][l])%=mo;
//						if(i+1==6&&j==3&&n==7&&dp[t][j][k][l])cout<<j<<k<<l<<dp[t][j][k][l]<<endl;
						if(i!=l){
							int mn=l;
							if(j&&k&&i-2*k+kk<=i-1)MIN(mn,i-2*j+1+kk);
							if(j&&k&&i-2*j+1+kk<=i)MIN(mn,i-2*k+kk);
							if(mn<0)break;
//							if(i+1==6&&k+1==0&&j==3&&mn==7)cout<<j<<k<<l<<dp[t][j][k][l]<<endl;
//							if(i==5&&j==0&&k==3&&l==7)cout<<k+1<<j<<mn<<dp[t][j][k][l]<<endl;
							(dp[!t][k+1][j][mn]+=dp[t][j][k][l])%=mo;
						}
					}
				}
			}
		}
		int res=0;
		REP(i,0,n-n/2+1)REP(j,0,n/2+1)(res+=dp[n&1][i][j][n])%=mo;
		cout<<res%mo<<endl;
	}else{
		par[0][0]=1;
		REP(i,0,n/2+2){
			int t=i&1;
			fill(par[!t],par[!t]+i+2,0);
			REP(j,0,i+1){
				(par[!t][0]+=par[t][j])%=mo;
				if(j+1<kk/2+1)(par[!t][j+1]+=par[t][j])%=mo;
			}
		}
		cout<<par[(n/2+1)&1][0]*par[(n-n/2+1)&1][0]%mo<<endl;
	}
}

Measured memory_bytes: 63104
h1, m1, h2, m2, k = map(int, input().split())

h = h2 - h1

if m2 >= m1:
    m = m2 - m1
else:
    m = 60 - (m1 - m2)
    h -= 1

working_time = h*60 + m

print(working_time - k)


Measured memory_bytes: 9104
import java.util.*;
import java.io.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        try{
            while(null != (line = br.readLine()))
            {
                String[] strArr = line.split(" ");
                System.out.println((int)Math.log10(Integer.parseInt(strArr[0]) + Integer.parseInt(strArr[1]))+1);
            }
        }
        catch(Exception e){
        }
    }
}

Measured memory_bytes: 24120
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
//#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;ll tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 string s;
 cin>>s;
 ll n=s.length();
  
 if(s[0]!='A'){
  puts("WA");
  return 0;
 }
 bool flag=false;
 rep(i,1,n){
  if(s[i]=='C'){
   if(2<=i&&i<=n-2&&!flag)flag=true;
   else {
    puts("WA");
    return 0;
   }
  }
  else if(!('a'<=s[i]&&s[i]<='z')){
   puts("WA");
   return 0;
  }
 }
 if(flag)puts("AC");
 else puts("WA");
 return 0;}

Measured memory_bytes: 3552
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        k: i32, a: i32, b: i32,
    }
    for i in a..=b {
        if i % k == 0 {
            println!("OK");
            return;
        }
    }
    println!("NG");
}


Measured memory_bytes: 2136
#include <iostream>
#include <set>

using namespace std;

int main(){
    int n, temp;
    set<int> A;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> temp;
        decltype(A)::iterator it = A.find(temp);
        if(it != A.end()){
            A.erase(temp);
        }else{
            A.insert(temp);
        }
    }

    cout << A.size() << endl;

    return 0;
}



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

int main() {
  string s, t;
  int count = 0;
  cin >> s >> t;
  size_t l = s.length();
  int n = l;
  for (int i = 0; i<n; i++){
    if (s[i] != t[i]) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;
#define endl '\n'
#define SIGMA 128
const ld PI=3.14159265358979;
#define fr(i,n) for(i=1;i<=n;i++)
#define rep(i,k,n) for(i=k;i<=n;i++)
#define w(x) int x;cin>>x;while(x--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ps(x,y) cout<<fixed<<setprecision(y)<<x<<endl
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define vvl vector<vll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll binpow(ll x, ll y, ll p){  ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}  
ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } 
bool parity(ll x,ll y){ bool f = ((x ^ y) < 0);return !f;}


int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    IOS

    ll n,a,b;
    cin>>n>>a>>b;
    
    if((b-a)%2==0)
    {
        cout<<(b-a)/2<<endl;
    }
    else
    {
        ll ans;
        ll newa=1;
        ll newb=b-a+1;
        if((newb-newa)%2==0)
        {
            ans=(a-1+(newb-newa)/2);
        }
        else
        {
            ans=(a-1+(newb-newa)/2+1);
        }

        newa=a+n-b;
        newb=n;
        if((newb-newa)%2==0)
        {
            ans=min(ans,(n-b+(newb-newa)/2));
        }
        else
        {
            ans=min(ans,(n-b+(newb-newa)/2+1));
        }
        cout<<ans<<endl;
    }
    

    return 0;  
}



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

int calcLength(int a, int b) {
	return a * 2 + b * 2;
}

int calcArea(int a, int b) {
	return a * b;
}

int main() {
	int a, b;
	cin >> a >> b;
	int l = calcLength(a, b);
	int s = calcArea(a, b);
	cout << s << " " << l << endl;
	return 0;
}

Measured memory_bytes: 3112
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

from itertools import product,permutations as p, combinations as c

n = inp()
#x = list(set(ip()))
x = ip()
ct = 0
for i in c(x,3):
    #print(i)
    a,b,c = list(sorted(i))
    if len(set(i)) == 3 and a+b > c:
        ct += 1
print(ct)


Measured memory_bytes: 73948
// AOJ 	0598: JOI Emblem
// 2018.1.26 bal4u

#include <stdio.h>
#include <string.h>

char s[1005][1005];
char e[4];

int calc(int r, int c)
{
	int k = 0;
	if (s[r-1][c-1] == e[0] && s[r-1][c] == e[1] && s[r][c-1] == e[2] && s[r][c] == e[3]) k++;
	if (s[r-1][c] == e[0] && s[r-1][c+1] == e[1] && s[r][c] == e[2] && s[r][c+1] == e[3]) k++;
	if (s[r][c-1] == e[0] && s[r][c] == e[1] && s[r+1][c-1] == e[2] && s[r+1][c] == e[3]) k++;
	if (s[r][c] == e[0] && s[r][c+1] == e[1] && s[r+1][c] == e[2] && s[r+1][c+1] == e[3]) k++;
	return k;
}

int main()
{
	int m, n, i, r, c, f1, f2, ans, cnt;
	char buf[15], cc, a[4] = "JOI";

	fgets(buf, 15, stdin), sscanf(buf, "%d%d", &m, &n);
	for (r = 1; r <= m; r++) fgets(s[r]+1, 1005, stdin); memset(s[r], 0, n);
	fgets(e, 4, stdin), fgets(buf, 4, stdin), e[2] = buf[0], e[3] = buf[1];

	ans = 0;
	for (r = 1; r < m; r++) for (c = 1; c < n; c++) {
		if (s[r][c] == e[0] && s[r][c+1] == e[1] && s[r+1][c] == e[2] && s[r+1][c+1] == e[3]) ans++;
	}
	
	cnt = 0;
	for (r = 1; r <= m; r++) for (c = 1; c <= n; c++) {
		cc = s[r][c];
		f1 = calc(r, c);
		for (i = 0; i < 3; i++) {
			s[r][c] = a[i], f2 = calc(r, c);
			if (f2 - f1 > cnt) cnt = f2 - f1;
		}
		s[r][c] = cc;
	}
	printf("%d\n", ans + cnt);
	return 0;
}



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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                int total = 500*a + 100*b + 50*c;
                if (total == X) ++res;
            }
        }
    }
    cout << res << endl;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            if (N == "1")
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var A = int.Parse(Console.ReadLine());
                var B = int.Parse(Console.ReadLine());

                Console.WriteLine(A + B);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x=i,c=0;
		while(x)x/=10,c++;
		if(c&1)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

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


using namespace std;


int main(void)
{
    double h,x;
    double answer[1000] = {0};
    int i,j,k,l = 0;
    
    while(cin >> x >> h ,x+h)
    {
        double trih = sqrt((x /2)*(x/2)+(h*h));
        //cout << trih << endl;
        double tris = ((trih)*x) /2;
        //cout << tris << endl;
        double answers = 4*tris+(x*x);
        //cout << answers << endl;
        answer[l] = answers;
        l++;
    }
    REP(i, l)
    printf("%f\n",answer[i]);
    return 0;
}

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

int main() {
 
  int n, m;
  cin >> n >> m;
  vector<pair<long,int>> d(n);
  for(int i = 0; i < n; i++) {
    cin >> d.at(i).first >> d.at(i).second;
  }
  sort(d.begin(), d.end());
  
  long sum = 0;
  for(int i = 0; i < n; i++) {
    if(m > 0) {
      sum += d.at(i).first * min(d.at(i).second, m);
      m -= d.at(i).second;
      //cout << sum << endl;
    } else {
      break;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 1792
n = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
cnt = 0

for i in range(n):
  for j in range(i+1,n):
	# j-i == k-j <=> k == 2j-i
    k = 2*j-i
    if k >= n or k <= j:
      break
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      cnt += 1
print(r*g*b - cnt)

Measured memory_bytes: 73584
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000000000000

int main(){
  int n,c;
  cin >> n >> c;
  int s[n],t[n],ch[n];
  for(int i=0;i<n;i++){
    cin >> s[i] >> t[i] >> ch[i];
  }
  int prog[c+1][100001];
  for(int i=1;i<c+1;i++){
    for(int j=0;j<100001;j++){
      prog[i][j] = 0;
    }
  }
  vector<pair<int,int> > record[c+1];
  int l,r;
  for(int i=0;i<n;i++){
    record[ch[i]].push_back(make_pair(s[i],t[i]));
  }
  for(int i=1;i<c+1;i++){
    sort(record[i].begin(),record[i].end());
  }
  for(int i=1;i<c+1;i++){
    for(int j=0;j<record[i].size();j++){
      l = record[i][j].first;
      r = record[i][j].second-1;
      for(int tt=l;tt<r+1;tt++){
        prog[i][tt] = 1;
      }
    }
  }

  for(int i=1;i<c+1;i++){
    for(int j=1;j<100001;j++){
      if(prog[i][j] == 1){
        prog[i][j-1] = 1;
      }
    }
  }
  int ans = 0;
  for(int i=0;i<100001;i++){
    int count = 0;
    for(int j=1;j<c+1;j++){
      count += prog[j][i];
    }
    ans = max(ans,count);
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c=='A'){
    cout << 'T';
  }else if(c=='T'){
    cout << 'A';
  }else if(c=='G'){
    cout << 'C';
  }else{
    cout << 'G';
  }
  
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = list(input().rstrip())

limit = A+B
cnt = 0

for s in S:
    if s=="c":
        print("No")
    elif (s=="a") & (cnt<limit):
        print("Yes")
        cnt += 1
    elif (s=="b") & (cnt<limit) & (B>0):
        print("Yes")
        cnt += 1
        B -= 1
    else:
        print("No")

Measured memory_bytes: 4712
minimam = float("inf")
sum_ = 0
     
N,X = map(int,input().split())
     
for i in range(N):
  m = int(input())
  sum_ += m
  if m < minimam:
    minimam = m
        
n = N
X_1 = X-sum_
n += X_1 // minimam
     
print(n)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  in(s);
  vector<ll> a(26, 0);
  char f = 'a';
  rep(i, 26){
    rep(j, s.size()){
      if(f == s[j])
        a[i]++;
    } 
    if(i != 25)
      f++;
  }
  ll t = 0;
  rep(i, 26){
    if(a[i] % 2 == 1)
      t++;
  }
  if(t)
    out("No");
  else
    out("Yes");
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int dp[k+1];
    for(int i=0;i<=k;i++){
        dp[i]=0;
        if(i==0)dp[i]=0;
        else{
        for(int j=0;j<n;j++){
            if(a[j]<=i){
                if(dp[i-a[j]]==0){dp[i]=1;break;}
        }
            }
        }
    }
    if(dp[k])cout<<"First";
    else cout<<"Second";
    return 0;
}

Measured memory_bytes: 640
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        String[] s = next().split("");

        boolean flag = false;
        for(int i=0; i<s.length; i++){
            if(!(s[i].equals("U") || s[i].equals("D") || s[i].equals(i%2==0 ? "R" : "L"))){
                flag = true;
                break;
            }
        }

        println(flag ? "No" : "Yes");
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a;
	cin >> b;
	if (a >= 13) {
		cout << b << endl;
	} else if (6 <= a && a < 13) {
		cout << b / 2 << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#coding:utf-8

n = int(input())
h = list(map(int,input().split()))

def all_under0(data):
  res = 1
  for d in data:
    if d > 0:
      res = 0
      break
  return res

def count_0(data):
  res = 0
  if data[0] > 0:
    res += 1
  for i in range(1,len(data)):
    if data[i] > 0 and data[i-1] <= 0:
      res += 1
  return res

ans = 0
while all_under0(h) == 0:
  ans += count_0(h)
  for i in range(len(h)):
    h[i] -= 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n/2]-a[(n/2)-1]<<"\n";
    return 0;
}

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

int	main()
{
    int N, K;
    cin >> N >> K;
    vector<int> H_vec(N);
    for (int i = 0; i < N; ++i)
        cin >> H_vec.at(i);
    sort(H_vec.begin(), H_vec.end());
    int64_t cnt = 0;
    for (int i = 0; i < N - K; ++i)
        cnt += H_vec.at(i);
    cout << cnt << endl;
}


Measured memory_bytes: 4028
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        min_c=j+1
        max_c=bisect.bisect_left(l, l[j]+l[i])-1
        num=max_c-min_c+1
#        print(str(l[i])+" "+str(l[j])+":"+str(min_c)+" "+str(max_c)+":"+str(num))
        ans += num if num > 0 else 0
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define _GLIBCXX_DEBUG
     
int main() {
  ll ans=0;
  int n, m, x;
  cin >> n >> m >> x;
  int val[n];
  int add[n][m];
  rep (i, n) {
    cin >> val[i];
    for (int j=0; j<m; ++j) {
      cin >> add[i][j];
    }
  }

/*
  rep (i, n) {
    cout << val[i] << ' ';
    rep (j, m) cout << add[i][j] << ' ';
    cout << endl;
  }
  */

  rep (i, n) ans += val[i];
  ++ans;
  ll pepepe = ans;

  for (int tmp=0; tmp<(1 << n); ++tmp) {
    vector<int> skill(m,0);
    ll count=0;
    rep(i, n) {
     if (tmp & (1<<i)) {
       rep (j, m) {
         skill[j] += add[i][j];
         //printf("skill=%d ", skill[j]);
       }
       count += val[i];
     }
    }

    int flag=1;
    rep (j, m) {
      if (skill[j] < x) flag = 0; 
    }
    if (flag && count<ans) {
      ans = count;
      //printf("found\n");
    }
  }
  if (pepepe == ans) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000


int main(){
  char buf[1024];
  int N,M;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &M);


  int *K=(int *)malloc(sizeof(int)*N);
  int **A=(int **)malloc(sizeof(int *)*N);
  rep(i,N){
    A[i]=(int *)malloc(sizeof(int)*M);
  }
  rep(i,N){
    scanf("%d",&K[i]);
    rep(j,K[i]){
      scanf("%d",&A[i][j]);
      A[i][j]--;
    }
  }

  int **matrix=(int **)malloc(sizeof(int *)*N);
  rep(i,N){
    matrix[i]=(int *)malloc(sizeof(int)*M);
    rep(j,M){
      matrix[i][j]=0;
    }
  }

  rep(i,N){
    rep(j,K[i]){
      matrix[i][A[i][j]]++;
    }
  }

  int count=0;
  rep(j,M){
    int flag=1;
    rep(i,N){
      if(matrix[i][j]==0){
        flag=0;
      }
    }
    if(flag==1){
      count++;
    }
  }

  printf("%d\n", count);

  return 0;
}


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

//
// 素因数分解 (単体のNに対して、sqrt(N)まで試し割り)
//
vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for(ll i = 2; i*i <= n; i++) {
        if (n%i != 0) continue;
        res.emplace_back(i,0);
        while (n%i == 0) {
            n/=i;
            res.back().second++;
        }
    }
    if (n!=1) res.emplace_back(n,1);
    return res;
}

int f(int x) {
    int res = 0;
    while (x >= res+1) {
        x -= (res+1);
        res++;
    }
    return res;
}

int main() 
{
    ll n;
    cin >> n;
    if (n==1) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    for (auto p : factorize(n)) {
        ans += f(p.second);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

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

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

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

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


int main()
{
	int n, m, s;
	while (scanf("%d%d%d", &n, &m, &s), n | m | s)
	{
		int nn = n * n;

		// dp[iÈºðgÁ½][j(a_jÜÅ)][s] = sum|k=[1..i-1](dp[k][j-1][s-k])
		static int dp[50][3001];
		const int mod = 100000;

		rep (i, nn + 1)
			rep (j, s + 1)
				dp[i][j] = 0;

		dp[0][0] = 1;
		for (int i = 1; i <= m; ++i)
			for (int j = nn; j > 0; --j)
				for (int k = i; k <= s; ++k)
					(dp[j][k] += dp[j - 1][k - i]) %= mod;

		printf("%d\n", dp[nn][s]);
	}
}

Measured memory_bytes: 1456
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	string s;
	cin >> s;
	for(char &c : s) {
		if(c == '?')
		c = 'D';
	}
	cout << s;
}


Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    }
    else {
        cout<<min(a+(b-a-1)/2,n-b+1+(b-a-1)/2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def solve(S: str):

    if S[0] != "A":
        print("WA")
        return

    if S[2:-1].count("C") != 1:
        print("WA")
        return

    flag = False
    for i, c in enumerate(S):
        if i == 0:
            continue
        if ord("a") <= ord(c) and ord(c) <= ord("z"):
            continue
        elif 1 < i and i < len(S)-1 and c == "C" and flag == False:
            # print("ga")
            flag = True
            continue
        else:
            print("WA")
            return
    print("AC")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4192