akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
//        String s[] = new String[3];
//        String nn = String.valueOf(n);
//        for (int i  = 0;i<nn.length();++i) s[i] = nn.substring(i,i+1);
//
//        boolean sw = false;
//        for (int i = 0;i<s.length;++i)
//        {
//            if (s[i].equals("7"))
//            {
//                sw = true;
//                break;
//            }
//        }
//        if (sw) System.out.println("Yes");
//        else System.out.println("No");
        long sum = 0;
        for (int i = 1;i<=n;++i)
        {
            if (i%3 == 0 && i%5 == 0) continue;
            if (i%3 == 0 || i%5 == 0) continue;
            sum += i;
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 35764
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>


using namespace std;

int main()
{
    string s;
    
    cin>>s;
    
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes";
    }else{
        cout<<"No";
    }


}






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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    ll a = 0, b = 0, c = 0;
    ll A, B;
    cin >> A >> B;
    rep(i, N) {
        ll temp;
        cin >> temp;
        if(temp <= A) a++;
        else if(temp <= B) b++;
        else c++;
    }
    cout << min({a, b, c}) << endl;
    return 0;
}


Measured memory_bytes: 3632
N = input()
if len(N) <= 1:
  print(0)
  exit()
if int(N[-1]) %2 == 0:
    ans = int(N[:-1])
    N = int(N[:-1])
    k = 1
    while k != 0:
        k = N // 5
        N = k
        ans += k
    print(ans)
else:
    print(0)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
const int mod = 1e9+7;
const int N = 2e5+5;
string s[3005];
int ans[3005][3005];
main() {
    ios::sync_with_stdio(0);
    int r,c;
    cin >> r >> c;
    ans[0][0] = 1;
    for (int i = 0;i < r; i++)
        cin >> s[i];
    for (int i = 0; i < r; i++)
    for (int j = (i == 0 ? 1 : 0); j < c; j++) {
            if (s[i][j] == '.') {
            if (i)
        ans[i][j] = ans[i-1][j];
        if (j) ans[i][j] += ans[i][j-1];
        if (ans[i][j] > mod) ans[i][j] -= mod;
    }}
    cout << ans[r-1][c-1];



}



Measured memory_bytes: 16528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String[] SList = sc.next().split("");
        String r = "";
        for (String s:
             SList) {
            int i = alp.indexOf(s);
            i += N;
            r += alp.charAt(i%26);
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 147540
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int) n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template <class T> inline void read(T &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
	for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar());
	if (f) x = -x;
}
namespace {
    const int mo = 1e9 + 7;
    inline int add(int x, int y) { x += y; return x >= mo ? x - mo : x; }
    inline int sub(int x, int y) { x -= y; return x < 0 ? x + mo : x; }
    inline int mul(int x, int y) { return (lo) x * y % mo; }
    inline int power(int a, int k = mo - 2) {
		int ans = 1;
		for (; k; k >>= 1, a = mul(a, a))
			if (k & 1) ans = mul(ans, a);
		return ans;
    }
	inline void U(int &x, int y) { x = add(x, y); } 
}

const int N = 2333;
int n, K, a[N], C[N][N];

int main(void) {
	read(n); read(K);
	rep (i, K) read(a[i]);
	re0 (i, n + 2) C[i][0] = 1;
	rep (i, n) rep (j, i)
		C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
	vector <int> dp(n + 2, 0);
	dp[0] = 1;
	rep (i, K) {
		vector <int> new_dp(n + 2, 0);
		for (int sz = 0; sz <= n; sz++)
			for (int k = 0; k <= a[i] && k + sz <= n; k++) {
				U(new_dp[sz + k], mul(dp[sz], mul(C[n - sz][k], C[n - k][a[i] - k])));
			}
		swap(dp, new_dp);
	}
	cout << dp[n] << "\n";
			
}


Measured memory_bytes: 9472
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 60;
const ll divisors[3] = {2, 3, 5};

ll dfs(const vector<ll>& costs, map<ll, ll>& dp, ll val) {
    if (dp.count(val)) {
        return dp[val];
    }
    if (!val) {
        return 0;
    }
    if (val == 1) {
        return costs[3];
    }
    ll res = INF;
    rep(i, 0, 3) {
        ll d = divisors[i];
        if (val / d) {
            chmin(res, dfs(costs, dp, val / d) + (val % d) * costs[3] + costs[i]);
        }
        chmin(res, dfs(costs, dp, (val + d - 1) / d) + ((d - val % d) % d) * costs[3] + costs[i]);
    }
    if (res / val >= costs[3]) {
        chmin(res, val * costs[3]);
    }
    return dp[val] = res;
}

void solve() {
    ll N;
    cin >> N;
    vector<ll> costs(4);
    for (auto& c : costs) {
        cin >> c;
    }
    map<ll, ll> dp;
    cout << dfs(costs, dp, N) << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    rep(_, 0, T) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4400
import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

#    t = int(input())
#    t, a, b = map(int, input().split())
    t = 1
    
    for _ in range(1, t+1):
    #    print("Case #{}: ".format(_), end = '')
        
        t = input().strip()
        for x in t:
            if(x == '?'):
                print("D", end = '')
            else:
                print(x, end = '')
        
        
main()

Measured memory_bytes: 89448
import java.util.Scanner;

public class Main {
    static int n, w;
    static int[] value, weight;
    static int[][] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        w = sc.nextInt();

        value = new int[n + 1];
        weight = new int[n + 1];
        dp = new int[n + 1][w + 1];
        for (int i = 0; i < n; i++) {
            value[i + 1] = sc.nextInt();
            weight[i + 1] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= w; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j - weight[i] >= 0) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]);
                }
            }
        }
        System.out.println(dp[n][w]);
    }
}

Measured memory_bytes: 30896
#include<stdio.h>
#include<vector>
#include<iostream> //c++
/*
int main(){
	int a=0;
	char A[5];
	for (int i = 0; i < 5; i++) {
		scanf("%c\n", &A[i]);
	}
	
	for(int i = 0; i < 5; i++) {
		if (A[i] =='A' &&A[i + 1]=='C') {
			a = 1;
		
		}
	}
	if (a == 1) {
		printf("Yes");

	}
	else {
		printf("No");
	}
}*/

using namespace std;
int main() {
	int g;
	int  N,Num=0;
	vector<int>a;
	cin >> N;
	for (int i = 0; i < N;i++) {

		cin >> g;

		a.push_back(g);
	

	}
	int t,p=0;
	while (true) {
		t=a[p] ;
		a[p] = -1;
		p = t;
		if (p == -1) {
			Num = -1;
			break;
		}
			Num++;
			if (p == 2) {
				break;
			}
			p = p - 1;
	}
	cout << Num;
	

}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) { //No TLE!!
		Scanner input = new Scanner(System.in);
		int N = Integer.parseInt(input.nextLine());
		String S = input.nextLine();
		int[][] counts = counters(S,N);
		/*for (int i = 0; i < N; i++) {
			System.out.println(counts[i][0]+" "+counts[i][1]+" "+counts[i][2]);
		}*/
		long cnt=0;
		for (int gap = 1; gap <= N; gap++) {
			for (int start = 0; start < N-gap; start++) {
				int middle = start+gap;
				if (S.charAt(start)!=S.charAt(middle)) {
					if (S.charAt(start)=='R'&&S.charAt(middle)=='G'||S.charAt(start)=='G'&&S.charAt(middle)=='R') {
						cnt+=counts[N-1][2]-counts[middle][2];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='B'&& cnt>0) cnt--;
						}
					}
					if (S.charAt(start)=='R'&&S.charAt(middle)=='B'||S.charAt(start)=='B'&&S.charAt(middle)=='R') {
						cnt+=counts[N-1][1]-counts[middle][1];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='G') cnt--;
						}
					}
					if (S.charAt(start)=='B'&&S.charAt(middle)=='G'||S.charAt(start)=='G'&&S.charAt(middle)=='B') {
						cnt+=counts[N-1][0]-counts[middle][0];
						if (middle+gap<N) {
							if (S.charAt(middle+gap)=='R') cnt--;
						}
					}
				}
			}
		}
		System.out.println(cnt);
	}
	public static int[][] counters(String S, int N){ //1st slot = i; 2,3,4 slot = R,G,B cnt
		int[][] counts = new int[N][3];
		int cntR = 0;
		int cntG = 0;
		int cntB = 0;
		for (int i = 0; i < N; i++) {
			if (S.charAt(i)=='R') cntR++;
			if (S.charAt(i)=='G') cntG++;
			if (S.charAt(i)=='B') cntB++;
			counts[i][0]=cntR;
			counts[i][1]=cntG;
			counts[i][2]=cntB;
		}
		return counts;
	}
}

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

int main(){
    string s; cin>>s;
    int x=s.length(),ans=0;
    for(int i=0;i<x/2;++i){
        if(s.at(i)!=s.at(x-i-1)) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
base = [int(input()) for i in range(m)]
i= 0
j = 0

dp = [0]*(n+1)
if m == 0:
  base = [n+1]

if 1 == base[j]:
  dp[1] = 0
  if j < m-1:
    j = j + 1
else:
  dp[1] = 1

dp[0] = 1

for i in range(2,n+1):
  if not (i == base[j]):
    dp[i] = dp[i-1] + dp[i-2]
  elif i == base[j]:
    if j < m-1:
      j = j + 1
  
  
print(int(dp[n]%1000000007))

Measured memory_bytes: 460020
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
	int m,n;
	const string Fizz("Fizz"),Buzz("Buzz"),FizzBuzz("FizzBuzz");
	string str;
	vector<int> player;
	vector<int>::iterator it;

	while( cin >> m >> n && m ){
		getchar();
		player.clear();
		for( int i = 1;i <= m;i++ ) player.push_back( i );

		it = player.begin();
		for( int i = 1;i <= n;i++ ){
			if( it == player.end() ) it = player.begin();
			getline( cin, str );
			if( player.size() == 1 ) continue;
			
			if( !(i % 15) ){ if( FizzBuzz != str ){ it = player.erase( it ); continue;}}
			else if( !(i % 3) ){ if( Fizz != str ){ it = player.erase( it ); continue;}}
			else if( !(i % 5) ){ if( Buzz != str ){ it = player.erase( it ); continue;}}
			else{
				int j;
				for( j = 0;j < str.size();j++ ){
					if( str[j] > '9' || str[j] < '0' ){
						break;
					}
				}
				if( j == str.size() ){ if( atoi( str.c_str() ) != i ){ it = player.erase( it ); continue;}}
				else {it = player.erase( it ); continue;}
			}
			it++;
		}

		for( int i = 0;i < player.size();i++ ){
			cout << (( i == 0 ) ? "" : " ") << player[i];
		}
		cout << endl;
	}
	return 0;
}

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

constexpr ll mod = 1000000007;
ll dp[110][5][5][5];

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

  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0] = 1;

  for (int n = 0; n < N; n++) { // dp[i文字][3文字前][2文字前][1文字前]
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 5; k++) {
          for (int l = 1; l < 5; l++) {
            if (i == 1 && j == 2 && l == 3) continue;
            if (i == 1 && k == 2 && l == 3) continue;
            if (j == 1 && k == 2 && l == 3) continue;
            if (j == 2 && k == 1 && l == 3) continue;
            if (j == 1 && k == 3 && l == 2) continue;

            dp[n + 1][j][k][l] += dp[n][i][j][k];
            dp[n + 1][j][k][l] %= mod;
          }
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i < 5; i++) {
    for (int j = 1; j < 5; j++) {
      for (int k = 1; k < 5; k++) {
        ans += dp[N][i][j][k];
        ans %= mod;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 384
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    l = len(S)
    S = S[::-1] + "ppppppp"
    W = ["maerd", "remaerd", "esare", "resare"]
    idx = 0
    while idx < l:
        no_flag = True
        for w in W:
            if S[idx: idx+len(w)] == w:
                idx += len(w)
                no_flag = False

        if no_flag:
            print("NO")
            exit()

    if idx == l:
        print("YES")
    else:
        print("NO")



if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    for(int i=1;i<=3500;i++){
        for(int j=1;j<=3500;j++){
            if(4*i*j-n*i-n*j <= 0){
                continue;
            }
            if(n*i*j % (4*i*j-n*i-n*j) == 0){
                cout << i << " " << j << " " << n*i*j / (4*i*j-n*i-n*j) << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

using namespace std;
int main(){
    int INF = 10100;
    int N;
    cin >> N;
    int W[N];
    for(int i = 0; i < N; ++i) cin >> W[i];
    int s1 = 0, s2 = 0;
    int res = INF;

    for(int t = 0; t < N; ++t){
        for(int i = 0; i < t; ++i) s1 += W[i];
        for(int i = t; i < N; ++i) s2 += W[i];
        res = min(res, abs(s2 - s1));
        s1 = s2 = 0;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
from sys import stdin

def f():
     n,m = [int(x) for x in stdin.readline().split()]
     a = [int(x) for x in stdin.readline().split()]
     min_a = min(a)
     a = [(1,i) for i in a]
     b_c = [tuple(map(int,x.split())) for x in stdin.readlines()]
     a += b_c
     a.sort(key=lambda x:x[1])
     ans = 0
     while True:
          if n>a[-1][0]:
               ans += a[-1][0]*a[-1][1]
               n -= a[-1][0]
               a.pop()
          else:
               ans += a[-1][1]*n
               break
     print(ans)

f()

Measured memory_bytes: 35504
#include <iostream>
#include <math.h>
#include <string>
#include <climits>

using namespace std;
#define number 100

int main()
{	
	int ans, i, j, k, a[number] = {0};
	string S;
	cin >> S;

	int len = S.length();
	ans = INT_MAX;
	j = 0;
	for (i = 0; i < len - 2; i++){
		j = (S[i]-'0') * 100 + (S[i + 1]-'0') * 10 + (S[i + 2]-'0');
		if(abs(753-j)<ans)
			ans = abs(753 - j);
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

//calculate p!
vector<int64_t> fact(300000,1);

//calculate a^n
int64_t bin_pow(int64_t a,int64_t n){
  int64_t ans=1;
  while(n>0){
    if(n & 1) ans=ans*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ans;
}

//calculate mod inverse 
//by Fermat little theorem and Binary Power
int64_t inv_mod(int64_t p){
  return bin_pow(p,mod-2);
}

//calculate pCq
int64_t comb(int64_t p, int64_t q){
  return fact[p]%mod*inv_mod(fact[q]%mod*fact[p-q]%mod)%mod;
}

int main()
{
  int64_t h,w,a,b;
  cin>>h>>w>>a>>b;

  for (int i = 1; i < fact.size(); ++i)
  {
    fact[i]=fact[i-1]*i%mod;
  }
  
  int64_t ans=0;
  for (int i = b+1; i <= w; ++i)
  {
    ans+=comb(h-a-1+i-1,h-a-1)%mod*comb(a-1+w-i,a-1)%mod;
    ans%=mod;
  }
  cout<<ans;
}

Measured memory_bytes: 2560
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Measured memory_bytes: 9240
S = input()
#S = "????C?????B??????A???????"
N = len(S)
mod = 10**9+7

num_q = [1]
res = 1
for i in range(N):
    if S[i] == "?":
        res = res*3 % mod
    num_q.append(res)
    

# それぞれi番目までのa,a-b,a-b-cの数
dp_a = [0]*(N+1)
dp_ab = [0]*(N+1)
dp_abc = [0]*(N+1)

for i in range(1,N+1):
    if S[i-1] == "A":
        dp_a[i] = dp_a[i-1] + num_q[i-1]
        dp_ab[i] = dp_ab[i-1]
        dp_abc[i] = dp_abc[i-1]
        
    elif S[i-1] == "B":
        dp_a[i] = dp_a[i-1]
        dp_ab[i] = dp_ab[i-1] + dp_a[i-1]
        dp_abc[i] = dp_abc[i-1]
        
    elif S[i-1] == "C":
        dp_a[i] = dp_a[i-1]
        dp_ab[i] = dp_ab[i-1]
        dp_abc[i] = dp_abc[i-1] + dp_ab[i-1]
        
    elif S[i-1] == "?":
        dp_a[i] = dp_a[i-1] * 3 + num_q[i-1]
        dp_ab[i] = dp_ab[i-1] * 3 + dp_a[i-1] 
        dp_abc[i] = dp_abc[i-1] * 3 + dp_ab[i-1]
        
    dp_a[i] %= mod
    dp_ab[i] %= mod
    dp_abc[i] %= mod
        
print(dp_abc[N])


Measured memory_bytes: 19044
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;

  cin >> N;

  int ans = 0;

  int counter[4] = {};

  for(int i=0;i<N;i++){
    string s;
    cin >> s;

    for(int j=0;j<s.size()-1;j++)
      ans += s[j] == 'A' && s[j+1] == 'B';

    int p = (s[0] == 'B') + (s.back() == 'A') * 2;

    counter[p]++;
  }

  debug(ans);

  bool f = false;

  while(1) {

    if(!f && counter[2]) {
      counter[2]--;
      f = true;
      continue;
    }

    if (counter[3]) {
      counter[3]--;
      ans += f;
      f = true;
      continue;
    }

    if (f && counter[1]){
      counter[1]--;
      f = false;
      ans++;
      continue;
    }

    break;
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int x,y,z;
    cin>>x>>y>>z;
    cout<<(x-z)/(y+z)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <numeric>
#include <functional>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define INF 1e9
#define MOD 1e9+7
#define ll long long

using namespace std;
int main(void){
    string s;
    cin>>s;
    while(1){
        s.erase(s.end()-1);
        if(s.length()%2==1)continue;
        bool judge=true;
        rep(i,0,s.length()/2){
            if(s[i]!=s[i+s.length()/2])judge=false;
        }
        if(judge){
            cout<<s.length()<<endl;
            break;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> H >> W >> K;
	int sx, sy, gx, gy;
	cin >> sy >> sx >> gy >> gx;
	sy--, sx--, gy--, gx--;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	int dir[] = { -1,0,1,0,-1 };
	vector<vector<vector<pair<int, int>>>>dis(H, vector<vector<pair<int, int>>>(W, vector<pair<int, int>>(4, { MOD,MOD })));
	queue<pair<pair<int, int>, int>>Q;
	for (int i = 0; i < 4; i++) {
		dis[sy][sx][i] = { 0,K };
	}
	Q.push({ {sy,sx},0 });
	while (!Q.empty()) {
		int cy = Q.front().first.first;
		int cx = Q.front().first.second;
		int d = Q.front().second;
	//	cout << cy << " " << cx << " " << d << endl;
	//	cout <<"dis "<< dis[cy][cx][d].first << " " << dis[cy][cx][d].second << endl;
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i], nx = cx + dir[i + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			//cout << ny << " " << nx << endl;
			if (s[ny][nx] == '@')continue;
			if (i == d && dis[cy][cx][d].second != K) {
				if (dis[ny][nx][i] > make_pair(dis[cy][cx][d].first, dis[cy][cx][d].second + 1)) {
					dis[ny][nx][i] = make_pair(dis[cy][cx][d].first, dis[cy][cx][d].second + 1);
					Q.push({ {ny,nx},i });
				}
			}
			else {
				if (dis[ny][nx][i] > make_pair(dis[cy][cx][d].first + 1, 1)) {
					dis[ny][nx][i] = make_pair(dis[cy][cx][d].first + 1, 1);
					Q.push({ { ny,nx },i });
				}
			}
		}
	}
	int ans = MOD;
	for (int i = 0; i < 4; i++) {
		ans = min(ans, dis[gy][gx][i].first);
	}
	if (ans == MOD)ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 144956
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] sp = Console.ReadLine().Split(' ');
        long x = long.Parse(sp[0]), k = long.Parse(sp[1]), d = long.Parse(sp[2]);

        if (x > 0)
        {

            long min = (x - (x % d)) / d;
            if (x % d != 0) min++;

            long a = (k - min) % 2;

            x -= Math.Min(min, k) * d;
            a = Math.Min(a, k - min);


            for (long i = 0; i < a; i++)
            {
                if (x > 0)
                    x -= d;
                else
                    x += d;
            }
        }
        else
        {
            long min = (x - (x % d)) / d;
            min = Math.Abs(min);
            if (x % d != 0) min++;

            long a = (k + min) % 2;

            x += Math.Min(min, k) * d;
            a = Math.Min(a, k - min);


            for (long i = 0; i < a; i++)
            {
                if (x > 0)
                    x -= d;
                else
                    x += d;
            }
        }

        Console.WriteLine(Math.Abs(x));
    }
}


Measured memory_bytes: 27512
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
 
int main(){
    int R[MAX], n;
     
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> R[i];
    }
     
    int maxv = -2000000000;
    int minv =R[0];
     
    for (int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
     
    cout << maxv << endl;
     
    return 0;
}


Measured memory_bytes: 3884
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int d = scan.nextInt();
    int sum = 0;
    if (d<=a){
      System.out.println(d);
      return;
    }
    sum = a;
    d -= a;
    if(d<=b){
      System.out.println(sum);
      return;
    }
    d-=b;
    sum -= d;
    System.out.println(sum);
  }
}


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

long long int A[3], a;

int main(){
    scanf("%lld%lld%lld", A, A + 1, A + 2);
    sort(A, A + 3);
    while(A[2] > *A + 1){
        ++a;
        *A += 2;
    }
    while(A[2] > A[1] + 1){
        ++a;
        A[1] += 2;
    }
    sort(A, A + 3);
    if(A[2] == *A)return 0 % printf("%lld", a);
    if(A[2] == A[1])return 0 % printf("%lld", a + 2);
    printf("%lld", a + 1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        sum+=2*min(x,k-x);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import collections

# input
N = int(input())
S = []

for _ in range(N):
  S.append(input())

cnt = collections.Counter(S)
cnt_sorted = sorted(cnt.items(), key=lambda x:x[1], reverse=True)
#print(cnt_sorted)

max = 0
pre = 0
ans = []
for v in cnt_sorted:
  max = v[1]
  if max >= pre:
    ans.append(v[0])
    pre = max
  else:
    break

ans.sort()
for a in ans:
  print(a)


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

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

    int n;
    cin >> n;
    vector<string> S(n);
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> S[i] >> A[i];
    }
    string target;
    cin >> target;

    bool f = false;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(f){
            ans += A[i];
        }
        if(S[i] == target){
            f = true;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

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

int main(){
    ll h,w;cin>>h>>w;
    string s[h];rep(i,0,h-1)cin>>s[i];
    ll a[h][w];memset(a,0,sizeof(a));
    ll c=1;
    ll ans=0;
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(a[i][j]==0){
                queue<i_i>q;
                q.push(i_i(i,j));
                a[i][j]=c;
                ll bla=0,whi=0;
                while(!q.empty()){
                    i_i t=q.front();q.pop();
                    if(s[t.first][t.second]=='#')bla++;
                    else whi++;
                    rep(k,0,3){
                        int nx=t.first+dx[k];
                        int ny=t.second+dy[k];
                        if(0<=nx&&nx<=h-1&&0<=ny&&ny<=w-1){
                            if(a[nx][ny]==0&&s[nx][ny]!=s[t.first][t.second]){
                                a[nx][ny]=c;
                                q.push(i_i(nx,ny));
                            }
                        }
                    }
                }
                ans+=bla*whi;
                c++;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}






Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef long long LL;
LL a[3];
int main()
{
	scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	if(!(a[0]&1)||!(a[1]&1)||!(a[2]&1)) puts("0");
	else printf("%lld\n",a[0]*a[1]);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String word;
        try {
            word = reader.readLine();
            int num = Integer.parseInt(word);
            int ans = num * num * num;
            System.out.println(ans);
        } catch (IOException e) {
            // TODO ????????????????????? catch ????????????
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // TODO ????????????????????? catch ????????????
                e.printStackTrace();
            }
        }
         
         
    }
}

Measured memory_bytes: 24324
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}


int N, M;
int d[12][12];
int l[12];
int p[12];


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

  Rep(i, M) {
    int K;
    cin >> K;
    l[i] = K;
    Rep(j, K) {
      int tmp;
      cin >> tmp;
      d[i][j] = tmp - 1;
    }
  }

  Rep(i, M) cin >> p[i];

  int ans = 0;

  Rep(i, 1 << N) {
    int res[12];

    Rep(j, N) {
      //cout << (i >> j) % 2; 
      res[j] = (i >> j) % 2;
    }
    //cout << "\n";

    bool flg = true;

    Rep(j, M) {
      int tmp = 0;
      Rep(k, l[j]) {
        //cout << d[j][k] << "\n";
        if (res[d[j][k]] == 1) {
          tmp++;
        }
      }
      if ((tmp % 2) != p[j]) {
        flg = false;
        break;
      }
    }

    if (flg) {
      //cout << i << "\n";
      //Rep(j, N) {
      //  cout << res[j];
      //}
      //cout << "\n";
      // cout << i << "\n";
      ans++;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
using System;

namespace abc135B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            int[] stl = new int[N];
            for(int m = 0; m < N; m++)
            {
                stl[m] = int.Parse(str[m]);
            }
            int Ans = 0;
            for(int i = 0; i < N; i++)
            {
                if(stl[i] != (i + 1))
                {
                    Ans = Ans+1;
                }
            }
            if (Ans == 2 || Ans == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>

typedef long long int ll;
int numSize, K;
ll memo[110][2][110];
char num[110];

ll dp(int pos, int small, ll noZeros) {
    if (pos == numSize) {
        if (noZeros == K) 
            return 1;
        else 
            return 0;
    }
    if (memo[pos][small][noZeros] != -1) return memo[pos][small][noZeros];
    ll ans = 0;
    int d, limit = (small ? 9 : num[pos] - 48);
    for (d = 0; d <= limit; d++) {
        if (d < limit)
            ans += dp(pos + 1, 1, noZeros + (d ? 1 : 0));
        else
            ans += dp(pos + 1, small, noZeros + (d ? 1 : 0));
    }
    return memo[pos][small][noZeros] = ans;
}

int main() {

    scanf("%s %d", num, &K);
    numSize = strlen(num);
    memset(memo, -1, sizeof(memo));
    printf("%lld\n", dp(0, 0, 0));   
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

void reverse(char str[]) {
  int i, j;
  char ch;
  int length = strlen(str);

  for (i = 0, j = length - 1; i < j; i++, j--) {
    ch = str[i];
    str[i] = str[j];
    str[j] = ch;
  }
}

int main(void)
{
  char str[20 + 1];

  scanf("%s", str);
  reverse(str);
  printf("%s\n", str);

  return 0;
}

Measured memory_bytes: 524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        string temp = System.Console.ReadLine();
        int N = int.Parse(temp);
        string[] temp1 = System.Console.ReadLine().Split(' ');
        int[] H = new int[N];
        int plusnum = 0;
        for (int i = 0; i < N; i++)
        {
            H[i] = int.Parse(temp1[i]);
            if (i == 0) { plusnum = H[i]; }
            else if (i >= 1&&(H[i]-H[i-1])>0)
            {
                plusnum += H[i] - H[i - 1];
            }
        }
        Console.WriteLine(plusnum);
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(void) {
  
  int N;
  int H[101];
  
  scanf("%d", &N);
  for(int i = 0; i < N; ++i) scanf("%d", &H[i]);
  
  int max_height = H[0];
  int view_count = 1;
  for(int i = 1; i < N; ++i) {
    if(max_height <= H[i]) {
      view_count++;
      max_height = H[i];
    }
  }
 
  printf("%d", view_count);
  
  return 0;
  
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int n,w,d; cin >> n >> w >> d;

    while(n!=0 || w!=0 || d!=0){
        vector<P> v; v.emplace_back(w,d);
        REP(i,n){
            int p,s; cin >> p >> s;
            p--;
            P piece = v[p], push1, push2;
            s %= piece.first + piece.second;
            if(s < piece.first){
                push1.first = min(s, piece.first-s);
                push2.first = max(s, piece.first-s);
                push1.second = piece.second;
                push2.second = piece.second;
            }
            else{
                s -= piece.first;
                push1.second = min(s, piece.second-s);
                push2.second = max(s, piece.second-s);
                push1.first = piece.first;
                push2.first = piece.first;
            }
            v.erase(v.begin()+p);
            v.emplace_back(push1); v.emplace_back(push2);
        }
        VI ans; REP(i,v.size()) ans.push_back(v[i].first*v[i].second);
        SORT(ans);
        REP(i,ans.size()-1) cout << ans[i] << " ";
        cout << ans[ans.size()-1] << en;
        cin >> n >> w >> d;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;

const int N=1e5+100,mod=1e9+7;
/*b*/
ll h[N];

ll dp[N];

int32_t main(){
    ll n,k;
    cin >> n >> k;
    for (int i=0;i<n;i++){
        cin >> h[i];
    }

    memset(dp,69,sizeof dp);
    dp[n-1]=abs(h[n-1]-h[n-2]);
    dp[n]=0;
    for (int i=n-2;i>0;i--){
        for (int j=i+1;j<=min(n,i+k);j++){
            dp[i]=min(dp[i],dp[j]+abs(h[i-1]-h[j-1]));
        }

    }
    cout << dp[1];
}


Measured memory_bytes: 1792
n=gets.to_i
a=[]
a = gets.split.map(&:to_i)
ans=0
num=1
for i in (0..n-1)
	if a[i]%2==1 then
		ans+=2*(3**(n-1-i))*num
	else
		ans+=(3**(n-1-i))*num
		num*=2
    end
end
puts ans

Measured memory_bytes: 1788
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

typedef pair<int, int> P;

int main() {
  ll n, t; cin >> n >> t;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  ll cur = -1; 
  ll total = 0;
  for (auto start: A) {
    ll end = start + t;
    if (cur < start) total += t;
    else if (cur < end) total += end-cur;
    cur = max(cur, end);
  }
  cout << total << endl;
  return 0;
}


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

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static int Modpow(int a,int p,int m){int res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;
public static void main(String[] args) throws  IOException{
                assign();
                char[] c=read().toCharArray();
                int xx=0;
                for(char cc:c){xx+=cc-'0';}
                if(xx%9==0) out.write("Yes");
            else out.write("No");
                out.flush();

    }
}

Measured memory_bytes: 36332
def main():
    A, B, K = [int(x) for x in input().split()]

    nokori = A - K
    if nokori > 0:
        print(nokori, B)
        return

    B += nokori
    if B > 0:
        print(0, B)
        return

    print(0, 0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import java.util.*;

public class Main{
    public void main(Scanner sc){
        int N=sc.nextInt();
        int M=sc.nextInt();
        int[] a=new int[N];
        long sum[]=new long[N+1];

        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
            sum[i+1]=sum[i]+a[i];            
        }
        Map<Integer,Long>map=new HashMap<>();
        for(int i=0;i<=N;i++){
            int mod=(int)(sum[i]%M);
            map.compute(mod,(k,v)->(v==null)?1:v+1);
        }

        long ans=0;
        for(Map.Entry<Integer,Long> entry:map.entrySet()){
            long v=entry.getValue();
            if(v>=2){
                ans+=v*(v-1)/2;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}

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

using namespace std;

int main(){
  vector<int> abc(3);
  std::cin >> abc[0] >> abc[1] >> abc[2];

  sort(abc.begin(), abc.end());

  int diff = abc[2] - abc[1];
  abc[0] += diff;
  int ans = diff;
  ans += (abc[2] - abc[0]) / 2;

  if((abc[2] - abc[0]) % 2 == 1){
    ans += 2;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 200005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;

int A[SIZE];

ll solve(vector <P> vec,int L)
{
	int n=vec.size();
	ll ret=0,sum=0;
	for(int i=L-1;i<n;i++)
	{
		sum+=vec[i-L+1].first;
		ret+=sum*vec[i].second;
	}
	return ret;
}
int main()
{
	int n,L;
	scanf("%d %d",&n,&L);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	if(L==1)
	{
		printf("%lld\n",(ll) n*(ll) (n+1)/2);
		return 0;
	}
	vector <P> all;
	for(int i=0;i<n;i++) all.push_back(P(A[i],i));
	sort(all.begin(),all.end());
	int now=-1,pos=0;
	vector <PP> vec;
	ll ret=n;
	while(1)
	{
		if(vec.empty())
		{
			if(pos==all.size()) break;
			now=all[pos].first;
		}
		while(pos<all.size()&&all[pos].first==now)
		{
			int v=all[pos++].second;
			vec.push_back(PP(P(v,v),P(1,1)));
		}
		sort(vec.begin(),vec.end());
		//printf("%d : ",now);
		//for(int i=0;i<vec.size();i++) printf("[%d %d : %d %d] ",vec[i].first.first,vec[i].first.second,vec[i].second.first,vec[i].second.second);puts("");
		vector <PP> nxt;
		for(int i=0;i<vec.size();)
		{
			int f=i++;
			for(;i<vec.size()&&vec[i].first.first==vec[i-1].first.second+1;i++);
			vector <P> now;
			for(int j=f;j<i;j++) now.push_back(vec[j].second);
			if(now.size()>=L)
			{
				ret+=solve(now,L);
				int c=now.size()/L;
				vector <P> v1,v2;
				for(int j=0;j<c;j++)
				{
					int s=vec[f].first.first+j,t=s;
					if(j==c-1) t=vec[i-1].first.second;
					v1.push_back(P(s,t));
					v2.push_back(P(0,0));
				}
				for(int j=f;j<i;j++)
				{
					int l=j-f+1,r=i-j;
					if(l>=L)
					{
						v2[l/L-1].second+=vec[j].second.second;
					}
					if(r>=L)
					{
						v2[c-r/L].first+=vec[j].second.first;
					}
				}
				ret-=solve(v2,L);
				for(int j=0;j<c;j++) nxt.push_back(PP(v1[j],v2[j]));
			}
		}
		vec=nxt;
		now++;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 11884
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for(int i = 0; i < b; i++){
        	int total = a * (i + 1);
            if(total % b == c){
        		System.out.println("YES");
                return;
        	}
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 35784
A,B,C,D,E,F=map(int,input().split())

w=[]
s=[]
for i in range(F):
    for j in range(F):
        a=100*A*i
        b=100*B*j
        if (a+b)>F:
            continue

        w.append(a+b)

for i in range(F):
    for j in range(F):
        c=C*i
        d=D*j
        if (c+d)>F:
            continue
        s.append(c+d)
ans=0.0
l=[100*A,0]
for water in w:
    for sugar in s:
        p=water+sugar
        if p==0:
            continue
        if p>F:
            continue 
        val=sugar/p
        if val<=(E/(100+E)):
            if ans<val:
                ans=val
                l=[p,sugar]

print(*l)

Measured memory_bytes: 49500
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MaxN = 1e9;
int X;
long long  ans;

int main()
{
	scanf("%d",&X);
	for(int i = 1; i <= MaxN;i++)
	{
		ans += i;
		if(ans >= X)
		{
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll N,K;
const ll MOD=1e9+7,MAX_K=1e5;
ll mpw(ll n,ll m){
	ll r=1;
	while(m){
		if(m&1){
			r*=n;
			r%=MOD;
		}
		m>>=1;
		n*=n;
		n%=MOD;
	}
	return r;
}
ll dp[MAX_K+1];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>N>>K;
	for(ll i=K;i>0;i--){
		dp[i]=mpw(K/i,N);
		for(ll j=2*i;j<=K;j+=i){
			dp[i]+=MOD-dp[j];
			dp[i]%=MOD;
		}
	}
	ll ans=0;
	FOR(i,1,K+1){
		ans+=dp[i]*i;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4404
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MAXN 100000
#define Inf 100000000000000000ll
#define ll long long
using namespace std;

ll H[MAXN+2];
ll HH[MAXN+2];

bool Can(int N, int A, int B, ll k) {
    
    for(int i=0;i<N;i++) {
        
        // H[i]-B*k <= 0
        // k >= H[i]/B
        
        if (k >= (H[i]+B-1)/B)
            HH[i]=0;
        else
            HH[i]=H[i]-(ll)B*(ll)k;
    }
    
    ll num_reqd=0;
    
    for(int i=0;i<N;i++) {
        // A-B is needed.
        if (HH[i]>0)
            num_reqd  += (HH[i]+A-B-1)/(A-B);
    }
    
    return (num_reqd <= k);
    
}

int main() {
    int N;
    cin>>N;
    int A,B;
    cin>>A>>B;
    for(int i=0;i<N;i++)
        cin>>H[i];
    
    
    ll low = 1;
    ll high = Inf;
    
    while(low < high) {
        ll mid = (low + high)/2;
        
        if (Can(N, A, B, mid)) {
            high = mid;
        } else {
            low = mid+1;
        }
    }
    cout << low << endl;
    
}

Measured memory_bytes: 1792
using System;

class Program
{
    static void Main()
    {
        var K = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();

        if (S.Length > K)
        {
            Console.WriteLine(S.Substring(0, K) + "...");
        }
        else
        {
            Console.WriteLine(S);
        }
    }
}


Measured memory_bytes: 27520