akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;


#define FOR(i,a,b) for(ll i = a ; i < b ; i++) // for i in range(a,b)
#define REP(i,n) for(ll i = 0 ; i < n ; i++) // for i in range(b)
#define FORD(i,a,b) for(ll i = a ; i > b ; i--) // for i in range(a,b,-1)
#define ALL(x) x.begin(),x.end()
#define debug(x) cerr << #x << ": " << x << '\n'

const int IINF = 1'001'001'001;
const ll INF = 1'001'001'001'001'001'001ll;
const int MOD = 1'000'000'007;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void solve(){
    com_init();
    int n,m,k; cin >> n >> m >> k;

    ll pattern_m = n*n * com(n*m-2,k-2);
    ll pattern_n = m*m * com(n*m-2,k-2);
    pattern_m%=MOD;
    pattern_n%=MOD;
    ll ans = 0;
    FOR(i,1,m){
        ans += (m-i)*pattern_m*i;
        ans %= MOD;       
    }
    FOR(i,1,n){
        ans += (n-i)*pattern_n*i;
        ans %= MOD;       
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 15580
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CantWaitForHoliday
{
	class Program
	{
		static void Main(string[] args)
		{
			string day = Console.ReadLine();
			List<string> week = new List<string>();
			week.Add("SUN");
			week.Add("MON");
			week.Add("TUE");
			week.Add("WED");
			week.Add("THU");
			week.Add("FRI");
			week.Add("SAT");

			int i = 0;
			int count = 0;
			bool flg = false;

			while (true)
			{
				if (i>6)
				{
					i = 0;
				}
				if (flg)
				{
					count++;

					if (i == 0)
					{
						break;
					}
				}
				if (week[i]==day)
				{
					flg = true;
				}

				i++;
			}
			Console.WriteLine(count);
			Console.ReadKey(true);
		}
	}
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    std::vector<char> v;
    rep(i, s.size()) {
        v.push_back(s[i]);
    }
    ll q;
    cin >> q;
    ll num[q];
    ll f[q];
    char c[q];

    ll one = 0;
    rep(i, q) {
        cin >> num[i];
        if ( num[i] == 2 ) {
            cin >> f[i] >> c[i];
        } else {
            one++;
        }
    }
/*
    int keep = 0;
    rep(i, q) {
        if ( num[i] == 1 ) {
            if ( num[i+1] != 1 || num[i-1] != 1 ) {
                reverse(ALL(v));
            }
        } else {
            if ( f[i] == 1 ) {
                v.insert(v.begin(), c[i]);
            } else {
                v.insert(v.end(), c[i]);
            }
        }
    }
*/
    ll top = 0;
    rep(i, q) {
        if ( num[i] == 1 ) {
            top = !top;
        } else {
            if (top) {
                if ( f[i] == 1 ) {
                    v.push_back(c[i]);
                } else {
                    v.insert(v.begin(), c[i]);
                }
            } else {
                if ( f[i] == 1 ) {
                    v.insert(v.begin(), c[i]);
                } else {
                    v.push_back(c[i]);
                }
            }
        }
    }

    if (top) {
        reverse(ALL(v));
    }

    rep(i, v.size()) {
        cout << v[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4472
while True:
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  c = 0
  for i in range(1, n + 1):
    for j in range(1, i):
      for k in range(1, j):
        if i + j + k == x:
          c += 1 
  print(c)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,k,m;
string s,t;

int main() {
  cin >> n;
  vector<int> a(10,0); int c;
  rep(i,n){
    cin >> c; 
    if(c<400) a[0]++;
    else if(c<800) a[1]++;
    else if(c<1200) a[2]++;
    else if(c<1600) a[3]++;
    else if(c<2000) a[4]++;
    else if(c<2400) a[5]++;
    else if(c<2800) a[6]++;
    else if(c<3200) a[7]++;
    else  a[8]++;
  }
  int cnt=0,b=0;
  rep(i,9){
    if(i!=8 && a[i]>0) cnt++;
    if(i==8 && a[8]>0) b+=a[8];
  }
  cout << max(cnt,1) << " " << cnt+b << endl; 
}

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

int main() {
    string S; cin >> S;
    string judge = "Good";
    for (int i = 0; i < S.size() - 1; i++) {
        if (S.at(i) == S.at(i + 1)) {
            judge = "Bad";
            break;
        }
    }
    cout << judge << endl;
}

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


int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int pick_A = min(A, K);
  K -= A;
  int pick_B = max(0, min(B, K));
  K -= pick_B;
  int pick_C = max(0, min(C, K));
  cout << pick_A - pick_C << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	map<ll,ll>a;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a[x]++;
		if(a[x]==2){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	// your code goes here
	return 0;
}

Measured memory_bytes: 12800
#include "bits/stdc++.h"
#include <string>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
// const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;

const int inf = 1e15;

signed main(){
  fast;
 
   int a ,  b;
   cin >> a >> b;
   cout << max(a*b , max(a + b , a-b))<< endl;








}


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

int main(void)
{
	int N;
	cin >> N;

	vector<int> A(N), B(N), C(N);
	for(int i=0; i<N; i++)
		cin >> A[i];

	for(int i=0; i<N; i++)
		cin >> B[i];

	for(int i=0; i<N; i++)
		cin >> C[i];

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	long long ret = 0;
	for(int i=0; i<N; i++){
		long long a = (long long)(lower_bound(A.begin(), A.end(), B[i]) - A.begin());
		long long c = N - (long long)(upper_bound(C.begin(), C.end(), B[i]) - C.begin());

		ret += a*c;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1536
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t;cin>>t;
    int i;
    if(t=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(t=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k,c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> one,two;
    for(int i=0;i<n;i++)
    {
        if((int)one.size()<k&&s[i]=='o')
        {
            one.push_back(i);
            i+=c;
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if((int)two.size()<k&&s[i]=='o')
        {
            two.push_back(i);
            i-=c;
        }
    }
    reverse(two.begin(),two.end());
    for(int i=0;i<k;i++) if(one[i]==two[i]) cout << one[i]+1 << "\n";
    return 0;
}


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

const int MOD = 998244353 , _ = 1 << 18;

int poww(long long a , int b){
	int times = 1;
	while(b){
		if(b & 1) times = times * a % MOD;
		a = a * a % MOD; b >>= 1;
	}
	return times;
}

int A[_] , B[_] , N , invn;
void FWT(int *arr , int tp){
	for(int i = 1 ; i < N ; i <<= 1)
		for(int j = 0 ; j < N ; j += i << 1)
			for(int k = 0 ; k < i ; ++k){
				int x = arr[j + k] , y = arr[i + j + k];
				arr[j + k] = x + y >= MOD ? x + y - MOD : x + y;
				arr[i + j + k] = x < y ? x + MOD - y : x - y;
			}
	if(tp == -1) for(int i = 0 ; i < N ; ++i) arr[i] = 1ll * arr[i] * invn % MOD;
}

int main(){
	cin >> N; N = 1 << N; int sum = 0; invn = poww(N , MOD - 2);
	for(int i = 0 ; i < N ; ++i){cin >> A[i]; sum += A[i];}
	sum = poww(sum , MOD - 2); for(int i = 0 ; i < N ; ++i) A[i] = (1ll * A[i] * sum - (i == 0)) % MOD;
	for(int i = 0 ; i < N ; ++i) B[i] = i == 0 ? N - 1 : MOD - 1;
	FWT(A , 1); FWT(B , 1);
	for(int i = 1 ; i < N ; ++i) A[0] = (A[0] + (A[i] = 1ll * poww(A[i] , MOD - 2) * B[i] % MOD)) % MOD;
	A[0] = (MOD - A[0]) % MOD; FWT(A , -1);
	for(int i = 0 ; i < N ; ++i) printf("%d\n" , A[i]);
	return 0;
}

Measured memory_bytes: 4864
/*
  C - 白昼夢 / Daydream
  <http://abc049.contest.atcoder.jp/tasks/arc065_a>
  ・ヌル文字('\0')とヌルポインタ(NULL)は違う。<http://www.kis-lab.com/serikashiki/C/C01.html>
*/

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

int main(int argc, char const *argv[]) {

  char S[100001];
  char str[4][8] = {"dream", "dreamer", "erase", "eraser"};
  char tmp;
  int len;
  int i, j;
  int pt;

  scanf("%s", S);

  len = strlen( S );
  for( j=0; j<len/2; j++){
    tmp = S[j];
    S[j] = S[len-1-j];
    S[len-1-j] = tmp;
  }

  for( i=0; i<4; i++ ){
    len = strlen( str[i] );
    for( j=0; j<len/2; j++ ){
      tmp = str[i][j];
      str[i][j] = str[i][len-1-j];
      str[i][len-1-j] = tmp;
    }
  }

  pt = 0;
  while( S[pt] != '\0'){
    i = 0;
    while( i<4 ){
      len = strlen(str[i]);
      j = 0;
      while( j<len ){
          if( S[pt+j] == str[i][j] ){
            j++;
          }else{
            break;
          }
      }
      if( j==len ){
        pt += len;
        break;
      }
      if( i==3 ){
        printf("NO");
        return 0;
      }else{
        i++;
      }
    }
  }
  printf("YES");
  return 0;
  
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(),y = sc.nextInt();
	while (x != 0 || y != 0){
		if (x < y){	System.out.println(x +" "+ y);}
		else{System.out.println(y +" "+ x);}
			x = sc.nextInt();y = sc.nextInt();
			}
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> alpha(26,50);
  string check = "abcdefghijklmnopqrstuvwxyz";
  for (int i=0; i<n; i++){
    vector<int> tmp(26,0);
    string S;
    cin >> S;
    int lenS = S.size();
    for (int j=0; j<lenS; j++){
      for (int k=0; k<26; k++){
        if (S[j] == check[k])
          tmp[k] += 1;
      }
    }
    for (int l=0; l<26; l++)
      alpha[l] = min(alpha[l],tmp[l]);
  }
  string ans = "";
  for (int m=0; m<26; m++){
    int al = alpha[m];
    for (int i=0; i<al; i++)
      ans += check[m];
  }
  cout << ans << endl;
}


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

if x == 2 :
  print ('No')

if x == 4 or x == 6 or x == 9 or x == 11 :
  if y == 4 or y == 6 or y == 9 or y == 11 :
    print ('Yes')
  else :
    print ('No')

if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12 :
  if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12 :
    print ('Yes')
  else :
    print ('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	for (int i = 0; i < b.size(); i++) {
		char ch = b[i];
		if (ch == 'A') cout << 'T';
		if (ch == 'T') cout << 'A';
		if (ch == 'G') cout << 'C';
		if (ch == 'C') cout << 'G';
	}
	cout << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n>>k;
    vector<int>v(n+1);
    for(int i=1;i<n+1 ; i++){cin>>v[i];}
    vector<int>dp(n+1);
    dp[1]=0;
    for(int i=2; i<=n ; i++)
    {
        dp[i] = INT_MAX;
        for(int j=1 ; j<i && j<=k; j++)
        {
            dp[i] = min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));

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

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

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

int main()
{
	ll n, k;
	cin >> n >> k;
	ll ans;
	ans = min(n % k, k - n % k);
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 3580
import numpy as np

x,y,a,b,c=[int(x) for x in input().split()]
p=[int(x) for x in input().split()]
q=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]

p=list(np.sort(p)[::-1][0:x])
q=list(np.sort(q)[::-1][0:y])

select=np.sort(p+q+r)[::-1][0:x+y]
print(sum(select))



Measured memory_bytes: 32148
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, opt[(int)1e5 + 5][3], val[(int)1e5 + 5][3];

int main(){
  FAST_IO  
  cin >> N;
  for(int rep = 0; rep < N; ++rep){
    for(int itr = 0; itr < 3; ++itr){
      cin >> val[rep][itr];
      opt[rep][itr] = 0;
    }
  }

  opt[0][0] = val[0][0], opt[0][1] = val[0][1], opt[0][2] = val[0][2];

  for(int day = 0; day < N - 1; ++day){
    for(int c = 0; c < 3; ++c){
      for(int p = 0; p < 3; ++p){
        if(p == c) continue;
        max_self(opt[day + 1][p],
                 opt[day][c] + val[day + 1][p]);
      }
    }
  }

  cout << max({opt[N - 1][0], opt[N - 1][1], opt[N - 1][2]});
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <vector>
using namespace std;
const int C=100001, N=101;
typedef long long ll;

int n, k, a, b, c, mw, w;
ll v, dp[N][C];

int main(){
	int j;
	scanf ("%d %d", &n, &mw);
	for (int i=1;i<=n;i++)	{
		scanf ("%d %lld", &w, &v);
		for (j=0;j<=mw;j++)	{
			if (j>=w)	dp[i][j]=max(dp[i-1][j-w]+v, dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	printf ("%lld\n", dp[n][mw]);
	
return 0;}

Measured memory_bytes: 78336
#include <iostream>
#include <string>

using namespace std;

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

  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k - 1] += 0x20;
  cout << s << endl;
  return 0;
}


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

string ans[300000];
map<string,int>mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int max1=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    for(int i=1;i<=n;i++)
    {
        max1=max(max1,mp[a[i]]);
    }
    int r=0;
    for(int i=1;i<=n;i++)
    {
        if(mp[a[i]]==max1)
        {
            mp[a[i]]=0;
            r++;
            ans[r]=a[i];
        }
    }
    sort(ans+1,ans+1+r);
    for(int i=1;i<=r;i++)
    {
        cout<<ans[i]<<'\n';
    }



}


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

int main()
{
    ll n;
    cin >> n;

    string ans;

    while (n > 0)
    {
        int t = n % 26;
        if (t == 0)
            t = 26;
        char c = 'a' + t - 1;
        ans += c;
        --n;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3628
import numpy as np
import itertools


def conv(l, n):
    a = [True]*n
    for i in l:
        a[i] = False
    return a

H, W, K = list(map(int, input().split()))
c = [input().split() for _  in range(H)]
c = np.array([list(c[i][0]) for i in range(H)])

path = 0
H_array = range(H)
W_array = range(W)
for n_i in range(H+1):
    for n_j in range(W):
        for comb_i in itertools.combinations(H_array, n_i):
            for comb_j in itertools.combinations(W_array, n_j):
                black = np.count_nonzero(c[conv(comb_i, H)][:, conv(comb_j, W)] == '#')
                if black == K:
                    path += 1

print(path)


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, t;
  cin >> n >> t;
  int a[n];
  rep(i, n) cin >> a[i];
  int b[n];
  b[n-1] = 0;
  for(int i = n-2; i >= 0; i--) b[i] = max(b[i+1], a[i+1]);
  int c[n], mxc = 0;
  rep(i, n) c[i] = b[i] - a[i], mxc = max(mxc, c[i]);
  int ans = 0;
  rep(i, n) if(c[i] == mxc) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int main() {
    int W;
    vector<int> a, v0, tmax;
    cin >> W;
    a.resize(W);
    tmax.resize(W, 0);
    for(int i=0;i<W;i++){
        cin >> a[i];
        if(a[i] == 0){
            v0.push_back(i);
        }
    }
    for(auto i : v0){
        tmax[i] = IINF;
        for(int j=i-1;j>=0;j--){
            if(a[j] == 0) break;
            else if(a[j] > 0) tmax[j] = max(tmax[j], tmax[j+1]-1);
            else tmax[j] = max(tmax[j], min(abs(a[j]), tmax[j+1]-1));
        }
        for(int j=i+1;j<W;j++){
            if(a[j] == 0) break;
            else if(a[j] > 0) tmax[j] = max(tmax[j], tmax[j-1]-1);
            else tmax[j] = max(tmax[j], min(abs(a[j]), tmax[j-1]-1));
        }
    }
    int ans = 0;
    for(int i=0;i<W;i++){
        if(a[i]>0){
            ans += min(a[i], tmax[i]);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4220
n = int(input())
S = []
for i in range(n):
    S.append(input())
color = [-1]*n #0:黒, 1:白
color[0] = 0
stack = [0]
colored = [0]*n
colored[0] = 1
while len(stack) != 0:
    temp = stack.pop()
    col = color[temp]
    cur = S[temp]
    for j in range(n):
        if cur[j] == '1':
            if colored[j] != 0:
                if color[j] == col:
                    print(-1)
                    exit()
            else:
                if col == 1:
                    color[j] = 0
                else:
                    color[j] = 1
                colored[j] = 1
                stack.append(j)
maxdist = 0
dist = []
for i in range(n):
    d = [10**10]*n
    d[i] = 0
    dist.append(d)
for i in range(n):
    for j in range(n):
        if S[i][j] == '1':
            dist[i][j] = 1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
for i in range(n):
    for j in range(n):
        maxdist = max(maxdist, dist[i][j])
print(maxdist+1)


Measured memory_bytes: 42988
"""AtCoder."""

n = int(input()[-1])

s = None

if n in (2, 4, 5, 7, 9):
    s = 'hon'
elif n in (0, 1, 6, 8):
    s = 'pon'
elif n in (3,):
    s = 'bon'

print(s)


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

int main(){
  int a,b,n,sa,sb;
  string s,t;
  cin >> a >> b >> n >> sa >> sb >> s >> t;
  bool ans=true;
  int x1=0,x2=a;
  for(int i=n-1;i>=0;i--){
    if(t[i]=='U'){
      x2=min(x2+1,a);
    }
    if(t[i]=='D'){
      x1=max(x1-1,0);
    }
    if(s[i]=='U'){
      x1=min(x1+1,a);
      if(x1==a) ans=false;
    }
    if(s[i]=='D'){
      x2=max(x2-1,0);
      if(x2==0) ans=false;
    }
  }
  if(sa<=x1||sa>x2) ans=false;
  int y1=0,y2=b;
  for(int i=n-1;i>=0;i--){
    if(t[i]=='L'){
      y2=min(y2+1,b);
    }
    if(t[i]=='R'){
      y1=max(y1-1,0);
    }
    if(s[i]=='L'){
      y1=min(y1+1,b);
      if(y1==b) ans=false;
    }
    if(s[i]=='R'){
      y2=max(y2-1,0);
      if(y2==0) ans=false;
    }
  }
  if(sb<=y1||sb>y2) ans=false;
  cout << (ans?"YES":"NO") << endl;
  //cout << x1 << " " << x2 << " " << y1 << " " << y2 << endl;
}

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

typedef long long ll;

int main() {
    int n; cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++) cin >> a[i];

    map <ll, ll> m;
    ll ans = 0;

    for(int i = 0; i < n; i++) m[i - a[i]]++;
    for(int i = 0; i < n; i++) ans += m[i + a[i]];
    
    cout << 1ll * ans;
    return 0;
}

Measured memory_bytes: 27892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans,n;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	ans=n*(n+1)/2;
	for(ll i=3;i<=n;i++){
		if(i%3==0||i%5==0) ans-=i;
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_int = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll x[n];
    rep(i, 0, n)
        cin >> x[i];
    int a1[n], b1[n];
    a1[0] = 0; b1[0] = 0;
    rep(i, 1, n)
    {
        if (x[i]- x[i - 1] < a)
            a1[i] = 1;
        else
            a1[i] = 0;
        if (x[i] - x[i - 1] < b)
            b1[i] = 1;
        else
            b1[i] = 0;
        a1[i] += a1[i - 1];
        b1[i] += b1[i - 1];
    }
    int dp[n][2];
    rep(i, 0, n)
        rep(j, 0, 2)
            dp[i][j] = 0;
    rep(i, 0, n)
    {
        int p = upper_bound(x, x + n, x[i] - a) - x;
        if (p == i)
        {
            if (i == 0)
                dp[i][0] = 1;
            else
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (b1[i - 1] - b1[p] > 0)
                dp[i][0] = 0;
            else
                dp[i][0] = dp[p][1];
        }

        p = upper_bound(x, x + n, x[i] - b) - x;
        if (p == i)
        {
            if (i == 0)
                dp[i][1] = 1;
            else
                dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (a1[i - 1] - a1[p] > 0)
                dp[i][1] = 0;
            else
                dp[i][1] = dp[p][0];
        }
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % MOD;
    return 0;
}


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

int main(){
    long long N,K;
    cin >> N>>K;
    vector<int> values;
    vector<long long> numbers(1000000,0);
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        a--;
        if(numbers[a] == 0){
        values.push_back(a);
        }
        numbers[a] += b;
    }
    sort(values.begin(),values.end());
    for(int i=0;i<N;i++){ 
        long long num = numbers[values[i]];
        // cerr << values[i] << "num=" << num << endl;
        K -= num;
        if(K<=0){
            cout << ++values[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 8448
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import           Data.IntMap.Strict    ((!))
import qualified Data.IntMap.Strict    as M
import           Data.List             (unfoldr)

main :: IO ()
main = do
  n <- readLn
  as <- readIntsLn
  putStr . unlines . map show $ solve n as

readIntsLn :: IO [Int]
readIntsLn = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine

solve :: Int -> [Int] -> [Int]
solve _ as = map f as
  where xs = M.fromListWith (+) [(a, 1) | a <- as]
        ys = M.map comb2 xs
        s = sum $ M.elems ys
        f a = s - y + comb2 (x - 1)
          where x = xs ! a
                y = ys ! a

comb2 :: Int -> Int
comb2 x = x * (x - 1) `div` 2


Measured memory_bytes: 69348
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<a-b+1<<endl;
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 100000000000000;
const double PI = acos(-1);

string s = "RYGB";

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int x = i - j;
			int y = i + j;
			cout << s[(y + 514 * d) % (2 * d) / d * 2 + (x + 514 * d) % (2 * d) / d];
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;

struct NODE{
	int to,cost;
	NODE(int to,int cost) : to(to) , cost(cost) {}
	NODE(){}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int done[110] = {};
double dp[110] = {} , rdp[110] = {};

vector<NODE> g[100];
int n,m,p;

double dfs(int x,int cst){
	if( done[x] != cst ) return 0;
	if( x == n - 1 ) return 1;
	if( dp[x] != -1 ) return dp[x];
	double ans = 0;
	for(int i = 0 ; i < g[x].size() ; i++)
		ans += dfs(g[x][i].to,cst+g[x][i].cost);
	return dp[x] = ans;
}

double rdfs(int x,int cst){
	if( done[n-1] - done[x] != cst ) return 0;
	if( x == 0 ) return 1;
	if( rdp[x] != -1 ) return rdp[x];
	double ans = 0;
	for(int i = 0 ; i < g[x].size() ; i++)
		ans += rdfs(g[x][i].to,cst+g[x][i].cost);
	return rdp[x] = ans;
}
int main(){
	while(cin >> n >> m >> p && (n||m||p) ){
		for(int i = 0 ; i < n ; i++) g[i].clear();
		for(int i = 0 ; i < m ; i++){
			int a,b,c;
			cin >> a >> b >> c;
			g[a].push_back( NODE(b,c) );
			g[b].push_back( NODE(a,c) );
		}
		for(int i = 0 ; i < 110 ; i++) done[i] = -1;
		for(int i = 0 ; i < 110 ; i++)
				dp[i] = rdp[i] = -1;
		priority_queue<NODE> Q;
		Q.push(NODE(0,0));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( done[q.to] != -1 ) continue;
			else done[q.to] = q.cost;
			for(int i = 0 ; i < g[q.to].size() ; i++)
				Q.push(NODE(g[q.to][i].to,q.cost+g[q.to][i].cost));
		}
		double all = dfs(0,0);
		//cout << all << endl;
		for(int i = 0 ; i < p ; i++){
			int a;
			cin >> a;
			if( done[a] == -1 ){
				printf("%.8lf\n",0.0);
			}else{
				double A = dfs(a,done[a]);
				double B = rdfs(a,done[n-1] - done[a]);
				printf("%.8lf\n",1.0 * A*B / all);
			}
		}
		cout << endl;
	}
	
}

Measured memory_bytes: 0
#include<cstdio>
#include<cmath> 
using namespace std;
long long n,ans;
int s;
int main(){
    scanf("%lld",&n); 
    for(int i=sqrt(n);i>0;--i)
        if(n%i==0){
            ans=n/i;
            break;
        }
    while(ans>0){
        ++s;
        ans/=10;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
icase=0
if icase==0:
    vv,e,r=map(int,input().split())
    g=[[] for i in range(vv)]
    for i in range(e):
        si,ti,di=map(int,input().split())
        g[si].append((ti,di))
elif icase==1:
    vv,e,r=4,5,0
    g = [[] for _ in range(vv)]
    g[0]=[(1,1),(2,4)]
    g[1]=[(2,2),(3,5)]
    g[2]=[(3,1)]
#ans:0 1 3 4
elif icase==2:
    vv,e,r=4,6,1
    g = [[] for _ in range(vv)]
    g[0]=[(1,1),(2,4)]
    g[1]=[(2,2)]
    g[2]=[(0,1)]
    g[3]=[(1,1),(2,5)]
#ans:3 0 2 INF

from heapq import heappop,heappush

q=[]
heappush(q,(0,r)) 

inf=float("INF")
dist=[inf]*vv
dist[r]=0
while len(q)>0:
    dd,state = heappop(q)
#    print("dd:",dd,"state:",state,"q:",q)
    for v,dv in g[state]:
#        print("v:",v,"dv:",dv,"g[state]:",g[state],"parent[v]:",parent[v])
        if dist[v]>dist[state]+dv:
            dist[v]=dist[state]+dv
            heappush(q,(dist[v],v))
#            print(" state:",state,"v:",v,"dist[v]",dist[v])

for i in range(vv):
    if dist[i]==inf:
        print("INF")
    else:
        print(dist[i])


Measured memory_bytes: 89292
#RLの間に全ての子供は存在する。
S = input()
T = []
j = 0
for i in range(len(S)-1):
    if S[i:i+2]=="LR":
        T.append(S[j:i+1])
        j = i+1
T.append(S[j:])
#リストの前処理完了

cnt = 0
Ans = [0]*(len(S))
for i in range(len(T)):
    if len(T[i])%2==0:
        for j in range(len(T[i])-1):
            if T[i][j:j+2]=="RL":
                Ans[cnt+j] = len(T[i])//2
                Ans[cnt+j+1] = len(T[i])//2
                cnt += len(T[i])
    else:
        # cnt忘れずに!
        r_num = T[i].count("R")
        l_num = len(T[i])-r_num
        if r_num > l_num:
            Ans[cnt-1+r_num] = r_num%2+len(T[i])//2
            Ans[cnt+r_num] = (r_num+1)%2+len(T[i])//2 
        else:
            Ans[cnt-1+r_num] = (l_num+1)%2+len(T[i])//2
            Ans[cnt+r_num] = l_num%2+len(T[i])//2
        cnt += len(T[i])
for i in range(len(Ans)):
    Ans[i] = str(Ans[i])
print(" ".join(Ans))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b,k;

int main(){
    cin >> a >> b >> k;
    set<ll> sl;
    FOR(i,a,min(b+1,a+k))sl.insert(i);
    for(ll i = b;i > max(a-1,b-k);i--)sl.insert(i);
    for(auto it = sl.begin();it != sl.end();it++){
        cout << *it << endl;
    }
}

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

	bool is_prime[1000000];
	int n_prime[1000000];
int main()
{
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2; i<1000000; i++){
		is_prime[i]=true;
	}
	
	for(int i=2; i*i<1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<1000000; j+=i){
				is_prime[j]=false;
			}
		}
	}


	int cnt=0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}
	while(true){
		int n;
		cin>>n;

		if(cin.eof())
			break;
	
		cout<<n_prime[n]<<endl;
	}
	
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    pair<int, int> BA[N];
    rep(i, N) {
        cin >> BA[i].second >> BA[i].first;
    }
    sort(BA, BA + N);
    string ans = "Yes";
    int now = 0;
    rep(i, N) {
        int A = BA[i].second, B = BA[i].first;
        //cout << A << " " << B << endl;
        now += A;
        if (now > B) ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int n,i,j,ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i+=2){
        int cnt=0;
        for(j=1;j<=i;j++){
            if(i%j==0) cnt++;
        }
        if(cnt==8) ans++;
    }
    printf("%d",ans);
    return 0;
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<int> P(N);
    vector<int> P_sorted(N);
    REP(i, N) {
        int p;
        std::cin >> p;
        P[i] = P_sorted[i] = p;
    }

    SORT(P_sorted);

    int diff = 0;
    REP(i, N) {
        if(P[i] != P_sorted[i]) {
            diff++;
        }
    }

    std::cout << ((2 < diff) ? "NO" : "YES") << std::endl;

    return 0;
}


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

int N,A,B,C,D; string s;

int main(){
	cin>>N>>A>>B>>C>>D>>s; bool pos=true;
	for(int i=A; i<C-1; i++){
		if(s[i]=='#'&&s[i+1]=='#')pos=false;
	}
	for(int i=B; i<D-1; i++){
		if(s[i]=='#'&&s[i+1]=='#')pos=false;
	}
	if(C>D){
		bool jump=false;
		for(int i=B-2; i<D-1; i++){
			if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')jump=true;
		}
		pos=pos&&jump;
	}
	cout<<(pos ? "Yes" : "No")<<'\n';
}

Measured memory_bytes: 3724
#include<stdio.h>
int A[100000],n;
int partition(int p,int r);
int main(){

  int i,n,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  
  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    if(i==q){
      printf("[");
    }
    printf("%d",A[i]);
    if(i==q){
      printf("]");
    }

  }
  printf("\n");
  return 0;
}

int partition(int p,int r){
  int i,j,x,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  
  return i+1;
}



Measured memory_bytes: 2120
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		char[] s=ir.next().toCharArray();
		out.println(s[0]==s[2]?"Yes":"No");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		long all = scan.nextLong(), blue = scan.nextLong(), red = scan.nextLong();
		long count = 0;
		
		count = blue * (all / (blue + red));
		
		if(all % (blue + red) <= blue) {
			count += all %(blue + red);
			
		}else {
			count += blue;
			
		}
		
		System.out.println(count);
		
	}
	
}

Measured memory_bytes: 21972
#include <iostream>

#define ll long long
using namespace std;

int main() {
	ll n, m, c, b[30], a[30][30], hoge, ans;
	ans = 0;
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++) cin >> b[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)cin >> a[i][j];
	for (int i = 0; i < n; i++) {
		hoge = 0;
		for (int j = 0; j < m; j++) hoge += a[i][j] * b[j];
		hoge += c;
		if (hoge > 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

// ABC085C - Otoshidama
int main(){
    int N, Y;
    scanf("%d %d", &N, &Y);
    int ans[3] = {-1, -1, -1};
    for(int a=0;a<=N;a++){
        for(int b=0;(a+b)<=N;b++){
            int c= N - a - b;
            if(10000*a+5000*b+1000*c==Y){
                ans[0]=a;
                ans[1]=b;
                ans[2]=c;
                break;
            }
        }
    }
    printf("%d %d %d", ans[0], ans[1], ans[2]);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=0; i<11; i++){
        sum += (n/(int)pow(10,(double)i))%10;
    }
    if(n%sum == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main() {
   long long n,a,b,ans,len;
   cin >> n >> a >> b;
   len = a+b;
   ans = (n/len)*a+min(a,n%len);
   cout << ans << endl;
   
}






Measured memory_bytes: 256
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $array = array_fill(1, $n, 0);
  for($i = 0; $i < $n; $i++){
    $m = trim(fgets(STDIN));
    $tmp = explode(" ", trim(fgets(STDIN)));
    for($j = 0; $j < $m; $j++){
      $array[$tmp[$j]] = 1;
    }
  }
  $ans = 0;
  for($i = 1; $i <= $n; $i++){
    if($array[$i] == 0){
      $ans++;
    }
  }
  echo $ans;
?>

Measured memory_bytes: 16240
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;


int main(){
    set<string>s;
    int n;
    cin >> n;
    while(n--){
        string str;
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
}




Measured memory_bytes: 19232
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, B;
	cin >> A >> B;

	cout << max({ A + B, A - B, A * B }) << "\n";

	return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np

N = int(input())
V = [int(m) for m in input().split()]
C = [int(n) for n in input().split()]

X = 0
X_ = []
Y = 0
Y_ = []

for i in range(N):
    for value in itertools.combinations(V, i+1):
        X = sum(value)
        X_.append(X)

for j in range(N):
    for cost in itertools.combinations(C, j+1):
        Y = sum(cost)
        Y_.append(Y)
if max(np.array(X_)-np.array(Y_)) > 0:
    print(max(np.array(X_)-np.array(Y_)))
else:
    print(0)


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

const int INF = 1<<29;

int N;
int DP[100010];

int main() {
    cin >> N;

    int t[12] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

    for (int i = 0; i < 100010; ++i) DP[i] = INF;
    DP[0] = 0;

    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < 12; ++j) {
            if (i >= t[j]) {
                DP[i] = min(DP[i], DP[i - t[j]] + 1);
            }
        }
    }

    cout << DP[N] << endl;
    return 0;
}

Measured memory_bytes: 640
from collections import deque

H,W = map(int,input().split())
MAP = [input() for i in range(H)]

sy = 0
sx = 0

dxy = [(-1,0),(1,0),(0,-1),(0,1)]

INF = 10**9+7

DISTANCE = [[INF for i in range(W)] for j in range(H)]
DISTANCE[sy][sx] = 0

QUEUE = deque([(sy,sx)])

flg = 0

while QUEUE :
    y,x = QUEUE.popleft()
    
    for dy,dx in dxy :
        ny = y+dy
        nx = x+dx
        if (ny < 0) or (nx < 0) or (ny >= H) or (nx >= W) :
            continue
        if MAP[ny][nx] == "#" :
            continue
        if DISTANCE[ny][nx] < INF :
            continue
        
        QUEUE.append([ny,nx])
        DISTANCE[ny][nx] = min(DISTANCE[ny][nx], DISTANCE[y][x]+1)

if DISTANCE[H-1][W-1] < INF :
    flg = 1
        
if flg == 0 :
    ans = -1
else :
    path = DISTANCE[H-1][W-1] + 1
    not_score = 0
    for y in range(H) :
        not_score += MAP[y].count("#")
    
    ans = H*W - path - not_score
print(ans)


Measured memory_bytes: 3316
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int m;
	m=b;
	b=a;
	a=m;
	m=c;
	c=a;
	a=m;
	printf("%d %d %d\n",a,b,c);
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author GYSHGX868
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int w = in.nextInt();
      int a = in.nextInt();
      int b = in.nextInt();
      if (b + w >= a && b <= a + w) {
        out.printLine(0);
      } else if (b > a + w) {
        out.printLine(b - a - w);
      } else {
        out.printLine(a - b - w);
      }
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void close() {
      writer.close();
    }

    public void printLine(int i) {
      writer.println(i);
    }

  }
}



Measured memory_bytes: 21460