akhauriyash/Code-Regression huggingface dataset:
ary = input().split(" ")
a = ary[0]
b = ary[1]
c = ary[2]

if ( a == b and ( a != c or b != c) ) or ( a == c and ( a != b or c != b ) ) or ( b == c and ( b != a or c != a ) ) :
  print("Yes") 
else :
  print("No")

Measured memory_bytes: 3060
N, T = map(int, input().split())
result_cost = 0
for n in range(N):
    c, t = map(int, input().split())
    if t <= T:
        if result_cost == 0:
            result_cost = c
        if c < result_cost:
            result_cost = c
print('TLE' if result_cost == 0 else result_cost)


Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
int main(void){
    double r, S, L;
    scanf("%lf", &r);
    S = r*r*PI;
    L = 2*r*PI;
    printf("%f %f\n", S, L);
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, k;
string s;
vector<pair<int, int> > v;

int solve();

int main() {
  cin >> n >> k >> s;
  for(int i = 0; i < n; ++i) {
    int cnt = 0;
    int now = s[i] - '0';
    while(i < n && s[i] - '0' == now) ++cnt, ++i;
    if(i != n) --i;
    v.push_back({now, cnt});
  }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int now = 0, ans = 0, id = 0, vsize = v.size(), cnt = 0,
      eraseid = 0;
  while(id < vsize) {
    now += v[id].se;
    if(!v[id].fi) ++cnt;
    while(eraseid < vsize && cnt > k) {
      now -= v[eraseid].se;
      if(!v[eraseid].fi) --cnt;
      if(++eraseid >= n) break;
    }
    ans = max(ans, now);
    if(++id >= n) break;
  }
  return ans;
}

Measured memory_bytes: 1528
import sys
from io import StringIO
import unittest

def resolve():
    s = input()

    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """ABC"""
        output = """ARC"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.size() > k) {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    } else
        cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());
	
	int ans = 0;
	int i = 0;
	while(i < n)
	{
		int ans_tmp = 0;
		int j = 0;
		while(a[i] == a[i + j])
		{
			j++;
		}
			
		int k = 0;
		while(a[i + k] - a[i] >= 0 && a[i + k] - a[i] <= 2 && (i + k) != n)
		{
			k++;
			ans_tmp++;
		}
		
		if(ans < ans_tmp)
		{
			ans = ans_tmp;
		}
		
		i += j;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

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

  int m,d; cin >> m >> d;
  int ans=0;
  rep1(i,m){
    rep1(j,d){
      int d1 = j % 10;
      int d10 = j / 10;
      if(d1>=2 && d10>=2 && d1 * d10 == i) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())

def soinsu(n):
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            S[i] += 1
    if S == {}:
        S[n]+=1
    else:
        if n != 1:
            S[n] += 1
    return S


if n==1:
    print(0)
else:
    S = defaultdict(int)
    S=soinsu(n)
    r=0
    for k,v in S.items():
        i=1
        while v>=i:
            v-=i
            r+=1
            i+=1
    print(r)

Measured memory_bytes: 66484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxN = 1e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const ull MOD = 16769023;
const ull MOD1 = 1125899839733759;
int n,x;
 
 
ll a[maxN];
ll b[maxN];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	b[1] = 0;
	int cnt = 1;
	for(int i=2;i<=n+1;i++)
	{
		b[i] = b[i-1] + a[i-1];
		if(b[i] <= x)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
	int a=0,b=0,c=0,d=1;
	while (scanf("%d %d",&a,&b)!=EOF){
		c=a+b;
		while (1){
			if (c/10>=1){
				d++;
				c/=10;
			}
			else break;
		}
		cout<<d<<endl;
		d=1;
	}
	return 0;
}

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

int main(void){
    std::string str;
    std::cin >> str;

    if(str.length() == 0 || str.length() % 2){
        std::cout << "No\n";  
        return 0;
    }

    for(int i = 0; i < str.length(); i += 2){
        if(str[i] != 'h'){
            std::cout << "No\n";
            return 0;
        }
    }

    for(int j = 1; j < str.length(); j += 2){
        if(str[j] != 'i'){
            std::cout << "No\n";
            return 0;
        }
    }

    std::cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
struct P{
    int a;
    int b;
    int c;
    P(int x, int y, int z){
        a = x;
        b = y;
        c = z;
    }
};
bool comp(const P &a, const P &b){
    if(a.a < b.a)return true;
    if(a.a > b.a)return false;
    if(a.b < b.b)return true;
    if(a.b > b.b)return false;
    return (a.c < b.c);
}
int main(void){
    int n, q, s, t, x, d, a, b, c, ans[200000];
    vector<P> v;
    set<int> closed;
    cin >> n >> q;
    for(int i=0;i<n;i++){
        cin >> s >> t >> x;
        v.push_back(P(s-x, 1, x));
        v.push_back(P(t-x, 0, x));
    }
    for(int i=0;i<q;i++){
        cin >> d;
        v.push_back(P(d, 2, i));
    }
    sort(v.begin(), v.end(), comp);
    for(int i=0;i<v.size();i++){
        b = v[i].b;
        c = v[i].c;
        if(b == 1){
            closed.insert(c);
        }else if(b == 0){
            closed.erase(c);
        }else{
            auto itr = closed.begin();
            if(itr != closed.end()){
                ans[c] = (*itr);
            }else{
                ans[c] = -1;
            }
        }
    }
    for(int i=0;i<q;i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 19688
#include<stdio.h>
#include<malloc.h>

int main() {
    int N;
    char* S;
    char stack[101];
    int stack_number = 0;
    int i, j;
    int left_count = 0;
    int right_count = 0;

    scanf("%d", &N);

    S = (char *)malloc(sizeof(char) * (N+1));

    scanf("%s", S);

    for(i = 0; i < N; i++) {
        stack[stack_number] = S[i];
        stack_number++;
        if(stack_number > 1 && stack[stack_number-1] == ')') {
            for(j = stack_number-2; j >= 0; j--) {
                if(stack[j] == '(') {
                    stack_number -= 2;
                    break;
                }
            }
        }
    }

    for(i = 0; i < stack_number; i++) {
        if(stack[i] == '(') left_count++;
        else right_count++;
    }

    for(i = 0; i < right_count; i++) putchar('(');
    printf("%s", S);
    for(i = 0; i < left_count; i++) putchar(')');

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    while(H != 0){
        int N;
        cin >> N;
        vector<int> a(N),b(N);
        vector<vector<ll>> dp(H,vector<ll> (W,0));
        for(int i=0; i<N; i++){
            cin >> a[i] >> b[i];
            a[i]--;b[i]--;
            dp[a[i]][b[i]] = -1;
        }
        dp[0][0] = 1;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(dp[i][j] == -1) continue;
                if(i+1<H and dp[i+1][j] != -1) dp[i+1][j] += dp[i][j];
                if(j+1<W and dp[i][j+1] != -1) dp[i][j+1] += dp[i][j];
            }
        }
        cout << dp[H-1][W-1] << enld;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3128
#include<cstdio>
const int maxn=100005;
int sign(int x){
  return x<0?-1:x>0;
}
int a[maxn];
int main(){
  int n;scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",&a[i]);
  int ans=0;
  int pt=1;
  while(pt<=n){
    int r=pt+1;
    int typ=sign(a[r]-a[r-1]);
    while(r<n&&sign(a[r+1]-a[r])*sign(a[r]-a[r-1])>=0){
      if(typ!=0&&typ!=sign(a[r+1]-a[r])&&sign(a[r+1]-a[r])!=0)break;
      else if(typ==0)typ=sign(a[r+1]-a[r]);
      ++r;
    }
    ans++;pt=r+1;
  }
  printf("%d\n",ans);
  return 0;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5))
		cout << "YES";
	else
		cout << "NO";

	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int testCases = 1;
   // cin >> testCases;
  
    while(testCases--)
    {
        int n,i,j;
    
       cin >> n;
       int a[n];
       
       for(i = 0;i < n;++i)
            cin >> a[i];
    
       int maxx = a[0];
       int cnt = 0;
       
       for(i = 1;i < n;++i)
       {
           if(a[i] <= maxx)
           {
               cnt += maxx - a[i];
           }
           else
           {
               maxx = a[i];
           }
       }
        cout << cnt;
        cout << '\n';
    }
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
int main()
{
    fio;
    ll n, k = 0;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
        if(a[i] % 2 == 0){
        if(a[i] % 3 != 0 && a[i] % 5 != 0) k = 1;
    }
    }
    if(k == 1){cout << "DENIED";}
    else cout << "APPROVED";

    return 0;
}


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

using namespace std;
typedef double db;

int n;
db tx[50], ty[50];

db sqr(db a) {
    return a * a;
}

db dst(db x1, db y1, db x2, db y2) {
    return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}

db get(db x, db y) {
    db mx = 0.0;
    for (int i = 0; i < n; i++) {
        mx = max(mx, dst(x, y, tx[i], ty[i]));
    }
    return mx;
}

db getradius(db x) {
    db y1 = -2e4, y2 = 2e4;
    for (int iter = 0; iter < 100; iter++) {
        db midy1 = y1 + (y2 - y1) / 3.0;
        db midy2 = y1 + (y2 - y1) / 3.0 * 2.0;

        db r1 = get(x, midy1);
        db r2 = get(x, midy2);

        if (r1 <= r2) y2 = midy2;
        else y1 = midy1;
    }
    return get(x, y1);
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tx[i] >> ty[i];
    }

    db x1 = -2e4, x2 = 2e4;
    for (int iter = 0; iter < 100; iter++) {
        db midx1 = x1 + (x2 - x1) / 3.0;
        db midx2 = x1 + (x2 - x1) / 3.0 * 2.0;

        db r1 = getradius(midx1);
        db r2 = getradius(midx2);

        if (r1 <= r2) x2 = midx2;
        else x1 = midx1;
    }
    cout << getradius(x1);
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

string s;
int q, t;
string ans;
int rev = 0;
vector<pair<pair<int, int>, char>> que;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	ans = "";
	cin >> s >> q;
	que.resize(q);
	deque<char> beg, lst;
	rep(i, 0, q)
	{
		cin >> que[i].F.F;
		if (que[i].F.F == 1)
		{
			rev++;
			continue;
		}
		cin >> que[i].F.S >> que[i].S;
		if ((rev % 2) != (que[i].F.S % 2))
		{
			beg.push_back(que[i].S);
		}
		else
		{
			lst.push_back(que[i].S);
		}
	}
	if (rev % 2 == 0)
	{
		while (sz(beg) != 0)
		{
			cout << beg.back();
			beg.pop_back();
		}
		cout << s;
		while (sz(lst) != 0)
		{
			cout << lst.front();
			lst.pop_front();
		}
	}
	else
	{
		// while (!lst.empty())
		// {
		// 	cout << lst.top();
		// 	lst.pop();
		// }
		reverse(all(s));
		// cout << s;
		// while (!beg.empty())
		// {
		// 	cout << beg.top();
		// 	beg.pop();
		// }
		while (sz(lst) != 0)
		{
			cout << lst.back();
			lst.pop_back();
		}

		cout << s;
		while (sz(beg) != 0)
		{
			cout << beg.front();
			beg.pop_front();
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5584
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n;
  string oom, mkg;
  cin>>n;
  REP(z,n){
    cin>>oom>>mkg;
    for(int j=oom.size()-1;j>=0;j--){
      char p=oom[j];
      switch(p){
      case 'J':
	for(int i=(int)mkg.size()-2;i>=0;i--)
	  swap(mkg[i],mkg[i+1]);
	break;
      case 'C':
	for(int i=0;i<=(int)mkg.size()-2;i++)
	  swap(mkg[i],mkg[i+1]);
	break;
      case 'E':{
	int offset=mkg.size()-mkg.size()/2;
	for(int i=0;i<(int)mkg.size()/2;i++)
	  swap(mkg[i],mkg[i+offset]);
	break;
      }
      case 'A':
	for(int i=0;i<(int)mkg.size()/2;i++)
	  swap(mkg[i],mkg[mkg.size()-1-i]);
	break;
      case 'P':
	for(char& c:mkg)
	  if(c>='1'&&c<='9') c--;
	  else if(c=='0') c='9';
	break;
      case 'M':
	for(char& c:mkg)
	  if(c>='0'&&c<='8') c++;
	  else if(c=='9') c='0';
	break;
      }
    }
    cout<<mkg<<endl;
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     string s;
     cin >> s;
     int n = s.length();
     vector< vector<int> > dp(n+1,vector<int>(13));
     dp[0][0] = 1;
     for(int i = 0;i<n;i++){
        for(int j = 0;j<13;j++){
            if(s[i]=='?'){
                for(int k = 0;k<10;k++) {
                        dp[i+1][(j*10+k)%13] += dp[i][j];
                        dp[i+1][(j*10+k)%13] %= mod;
            }}
            else{
                        int k = s[i] - '0';
                        dp[i+1][(j*10+k)%13] += dp[i][j];
                        dp[i+1][(j*10+k)%13] %= mod;
            }
     }}
     cout << dp[n][5];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 11916
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[100001], B[100001], C[100001];
    int N;
    cin >> N;
    rep(i,0,N){
        cin >> A[i];
    }
    rep(i,0,N){
        cin >> B[i];
    }
    rep(i,0,N){
        cin >> C[i];
    }
    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);

    ll ans = 0;
    rep(i,0,N){
        ll pos_a = lower_bound(A, A+N, B[i]) - A;
        ll pos_c = upper_bound(C, C+N, B[i]) - C;
        ans += (pos_a * (N - pos_c));

    }
    print(ans);
    
    // int arr[5] = {0,2,4,6,8};
    // int a = lower_bound(arr,arr+5, 2) - arr;
    // int b = upper_bound(arr,arr+5, 2) - arr;
    // print(a);
    // print(b);


}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void solve(){
	int n;
	cin>>n;
	queue<string> q;
	rep(i,1,10){
		q.push(to_string(i));
	}
	int cnt=0;
	while(1){
		int m = q.size();
		for(int i=0;i<m;i++){
			string s = q.front();
			q.pop();
			if(++cnt==n){
				cout<<s;
				return ; 
			}
			if(s.back()=='0')q.push(s+'0'),q.push(s+'1');
			else if(s.back()=='9')q.push(s+'8'),q.push(s+'9');
			else q.push(s+(char)(s.back()-1)),q.push(s+s.back()),q.push(s+(char)(s.back()+1));
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 13824
s = input()
a = 0
b = 0
for i in range(len(s)):
    if i %2==0:
        if s[i] == "0":
            continue
        else:
            a += 1
    else:
        if s[i] == "1":
            continue
        else:
            a += 1
for i in range(len(s)):
    if i %2==0:
        if s[i] == "1":
            continue
        else:
            b += 1
    else:
        if s[i] == "0":
            continue
        else:
            b += 1
print(min(a, b))

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

int main() {
  int N,M,x=0,y=0;
  cin >> N >> M;
  vector<int>p(M);
  vector<string>S(M);
  vector<int>check(N),count(N);
  for(int i=0;i<M;i++){
    cin >> p[i] >> S[i];
  }
  for(int i=0;i<N;i++){
    check[i]=0;
    count[i]=0;
  }
  for(int i=0;i<M;i++){
    if(check[p[i]-1]==1){
      continue;
    }else if(S[i]=="WA"){
      count[p[i]-1]++;
    }else if(S[i]=="AC"){
      check[p[i]-1]=1;
      y++;
    }
  }
  for(int i=0;i<N;i++){
    if(check[i]==1){
      x += count[i];
    }
  }
  cout << y << " " << x;
}

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

const int MOD = 1e9 + 7;

int add(ll x, ll y) {return (x+y) % MOD;}
int mul(ll x, ll y) {return (x*y) % MOD;}
int bp(ll x, ll y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y>>=1;
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	int a = bp(9, n);
	int b = bp(8, n);
	cout << add(bp(10, n), MOD-add(mul(2, a), MOD-b)) << '\n';
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>


using namespace std;

typedef struct cell {
	int t, x, y;
}CELL;

int main() {

	int N;
	vector<CELL> point;

	cin >> N;

	CELL box;
	for (int i = 0; i < N; i++) {
		cin >> box.t >> box.x >> box.y;
		point.push_back(box);
	}

	bool can = false;
	if (N != 1) {
		for (int i = 0; i < N - 1; i++) {
			int t_length = point[i + 1].t - point[i].t;
			int x_length = point[i + 1].x - point[i].x;
			int y_length = point[i + 1].y - point[i].y;

			if (t_length - (abs(x_length) + abs(y_length)) >= 0 && (t_length - (abs(x_length) + abs(y_length))) % 2 == 0)
				can = true;
			else {
				can = false;
				break;
			}
		}
	}
	if (N == 1) {
		if ((abs(point[0].x) == 1 && point[0].y == 0) || (point[0].x == 0 && abs(point[0].y) == 1))
			can = true;
	}

	if (can)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1912
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(max({a, b, c}) != c && min({a, b, c}) != c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        if (s.equals(t.substring(0,t.length() - 1))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26992
n = int(input())
sl = list(input())

ans = sl.count("R") * sl.count("G") * sl.count("B")

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k < n:
            if len({sl[i], sl[j], sl[k]}) ==  3:
                ans -= 1

print(ans)



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

bool checkA( char a[100][100], int m, int n, int x, int y );
bool checkB( char a[100][100], int m, int n, int x, int y );

int main()
{
    int m, n;
    char a[100][100];

    cin >> m >> n;

    for( int i = 0; i < m; i++ )
        for( int j = 0; j < n; j++ )
            cin >> a[i][j];

    int cnt = 0;
    for( int i = 0; i < m; i++ )
        for( int j = 0; j < n; j++ )
            if( i != 0 && a[i][j] == '-' && checkA( a, m, n, i, j ) && checkB( a, m, n, i, j ) )
                cnt++;
    
    cout << cnt << endl;

    return 0;
}

bool checkA( char a[100][100], int m, int n, int x, int y )
{
    if( x - 1 >= 0 && y - 1 >= 0 && a[x-1][y-1] == 'x' )
        return false;
    if( x - 1 >= 0 && a[x-1][y] == 'x' )
        return false;
    if( x - 1 >= 0 && y + 1 < n && a[x-1][y+1] == 'x' )
        return false;
    if( y - 1 >= 0 && a[x][y-1] == 'x' )
        return false;
    if( y + 1 < n && a[x][y+1] == 'x' )
        return false;
    if( x + 1 < m && y - 1 >= 0 && a[x+1][y-1] == 'x' )
        return false;
    if( x + 1 < m && a[x+1][y] == 'x' )
        return false;
    if( x + 1 < m && y + 1 < n && a[x+1][y+1] == 'x' )
        return false;
    return true;
}

bool checkB( char a[100][100], int m, int n, int x, int y )
{
    if( y - 1 >= 0 && a[x][y-1] == 'o' )
        return false;
    if( y + 1 < n && a[x][y+1] == 'o' )
        return false;
    return true;
}


Measured memory_bytes: 3120
n,k=map(int,input().split())
b=list(map(int,input().split()))
v=[None]*n
w=[0]*n
i,c=0,b[0]
while v[c-1] is None:
    w[i]=c
    v[c-1] = i
    i+=1
    c=b[c-1]

head = v[c-1]
loop = i-v[c-1]
if k-1 < head:
    print(w[k-1])
else:
    print(w[head + ((k-1-head)%loop)])



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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, K;
map<ll, ll> cnt;

signed main() {
    cin >> N >> K;
    REP(i, N) {
        LCIN(a, b);
        cnt[a] += b;
    }
    auto itr = cnt.begin();
    ll now = 0;
    while(1) {
        now += (*itr).second;
        if(K - now <= 0) {
            cout << (*itr).first;
            return 0;
        }
        itr++;
    }
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main(){
   string a,b,c;
    cin>>a>>b>>c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0])
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int A, B;

	cin >> A >> B;
	A--;
	int ans = 0, i = 1;

	while (i < B)
	{
		i += A;
		ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    string s,ans = "@@@";
    cin >> s;
    string tester = "abcdefghijklmnopqrstuvwxyz";
    sort(s.begin(),s.end());
    
    for(int i = 0;;i++){
        if(!s[i])break;
        for(int j = 25;j >= 0;j--){
            if(s[i] == tester[j])tester[j] = '@';
        }
    }
    for(int i = 0;i < 26;i++){
        if(tester[i] != '@'){
            ans = tester[i];
            break;
        }
    }
    if(ans == "@@@")ans = "None";
    
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N, M, kari;
  int X=0;
  cin >> N;
  M=N;
  for(int i=8;i>-1;i--){
    kari=M/pow(10,i);
    X+=kari;
    M-=kari*pow(10,i);
  }
  kari=N%X;
  if (kari==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 512
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    b=LIST()
    c=LIST()
    ans=0
    for i in range(n):
        if i==0:
            ans+=b[a[i]-1]
        else:
            ans+=b[a[i]-1]
            if a[i-1]==a[i]-1:
                ans+=c[a[i-1]-1]
    print(ans)
if __name__ == '__main__':
    do()

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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    if(n % 2 == 1 || 4 * m < n + 2) {
        for(int i = 1; i <= m; i++) {    
            printf("%d %d\n", i, n + 1 - i);
        }
    } else {
        for(int i = 1; i <= n / 4; i++) {    
            printf("%d %d\n", i, n + 1 - i);
        }
        for(int i = n / 4 + 1; i <= m; i++) {
            printf("%d %d\n", i + 1, n + 1 - i);
        }
    }

    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=85,mx=12800,mod=1e9+7;
int f[N][N][2*mx+5];
int n,m;
int a[N][N],b[N][N];
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) 
			scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&b[i][j]);
	f[1][1][a[1][1]-b[1][1]+mx]=1;
	f[1][1][-(a[1][1]-b[1][1])+mx]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(i==1&&j==1) continue;
			for(int k=-mx;k<=mx;k++) {
				if(k+a[i][j]-b[i][j]<=mx&&k+a[i][j]-b[i][j]>=-mx) 
					f[i][j][mx+k+a[i][j]-b[i][j]]|=(f[i-1][j][mx+k]|f[i][j-1][mx+k]);
				if(k-(a[i][j]-b[i][j])<=mx&&k-(a[i][j]-b[i][j])>=-mx) 
					f[i][j][mx+k-(a[i][j]-b[i][j])]|=(f[i-1][j][mx+k]|f[i][j-1][mx+k]);
			}
		}
	int ans=0x3f3f3f3f;
	for(int k=-mx;k<=mx;k++) if(f[n][m][mx+k]) {
		ans=min(ans,abs(k));
	}
	cout<<ans;
	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

static const int INF = (1<<29);
static const int MMAX = 20;
static const int NMAX = 50000;

int main() {
    int n, m;
    int C[MMAX+1];
    int T[NMAX+1];
    cin >> n >> m;
    rep(i, 1, m+1) {
        cin >> C[i];
    }
    rep(i, 1, n+1) {
        T[i] = INF;
    }
    T[0] = 0;
    rep(i, 1, m+1) {
        for (int j = 0; j+C[i] <= n; j++) {
            T[j + C[i]] = min(T[j + C[i]], T[j]+1);
        }
    }
    cout << T[n] << endl;
};



Measured memory_bytes: 3276
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

typedef pair<string,int> SI;

bool ok(string s)
{
  char c = s[0];
  for(int i=0;i<s.length();i++)
    if(c != s[i])
      return false;
  return true;
}

char getc(char c,char cc)
{
  map<char,bool> index;
  index['r'] = false,index['b'] = false,index['g'] = false;
  index[c] = true;
  index[cc] = true;
  foreach(i,index)
    if(!(*i).S)
      return (*i).F;

}

int solve(string s)
{

  queue<SI> que;
  que.push(SI(s,0));
  map<string,bool> used;
  while(!que.empty())
    {
      SI si = que.front(); que.pop();

      if(used[si.F])
	continue;

      used[si.F] = true;
 
      if(ok(si.F))
	{
	  return si.S;
	}

      if(si.S > 15)
	continue;

      rep(i,si.F.length()-1)
	{
	  if(si.F[i] == si.F[i+1])
	    continue;
	  string news = si.F;
	  news[i] = news[i+1] = getc(si.F[i],si.F[i+1]);
	  que.push(SI(news,si.S+1));
	}

    }

  return -1;
}


int main(){

  while(true)
    {
      string s;
      cin >> s;
      if(s[0] == '0')
	break;

      int ans = solve(s);
      ans != -1?cout << ans << endl:cout << "NA" << endl;

    }

return 0;
}

Measured memory_bytes: 3388
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int N = (int)1e6;

int main(void){
    vi sa, saodd;
    for(int a = 1, next; (next = a * (a + 1) * (a + 2) / 6) < N; a++){
        sa.pb(next);
        if(next % 2) saodd.pb(next);
    }

    vi dp(N, inf), dpodd(N, inf);
    dp[0] = 0; dpodd[0] = 0;
    rep(i, N){
        rep(j, sa.size()){
            if(N <= i + sa[j]) break;
            dp[i + sa[j]] = min(dp[i + sa[j]], dp[i] + 1);
        }
        rep(j, saodd.size()){
            if(N <= i + saodd[j]) break;
            dpodd[i + saodd[j]] = min(dpodd[i + saodd[j]], dpodd[i] + 1);
        }
    }

    for(int n; cin >> n, n; cout << dp[n] << " " << dpodd[n] << endl);

	return 0;
}

Measured memory_bytes: 8860
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        int t[11][11]={{0}};
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                cin>>t[i][j];
            }
        }
        for(int i=0;i<n;++i){
            int sum=0;
            for(int j=0;j<=n;++j){
                if(j!=n){
                    sum+=t[i][j];
                    t[n][n]+=t[i][j];
                }
                if(j==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int j=0;j<n;++j){
            int sum=0;
            for(int i=0;i<=n;++i){
                if(i!=n){
                    sum+=t[i][j];
                }
                if(i==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int i=0;i<=n;++i){
            for(int j=0;j<=n;++j){
                printf("%5d",t[i][j]);
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1192
import Data.List (foldl')

func :: Int -> [(Int, Int, Int)] -> Int
func x xs = foldl' (\acc (a,b,c) ->
  if a * 500 + b * 100 + c * 50 == x
  then acc + 1
  else acc) 0 xs

main = do
  contents <- getContents
  let
    [a',b',c',x] = map read $ lines contents :: [Int]
    ans = func x [(a,b,c) | a <- [0..a'], b <- [0..b'], c <- [0..c']]
  putStrLn $ show ans


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N, D, X; cin >> N;
	cin >> D >> X;
	vector<int> A(N);
	REP(i,N) cin >> A[i];
	
	int ans = X;
	REP(i,N){
		int day = 1;
		int cnt = 1;
		while(day <= D){
			day = cnt*A[i]+1;
			cnt++;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ccl main
using namespace std;
typedef long long ll;
ll n,x,a,b,ans;
int ccl(){
	cin>>n>>x;a=x;b=n-x;ans=n;
	for(;;){
		if(a<b) swap(a,b);
	//	cout<<a<<" "<<b<<" "<<ans<<endl;
	//	sysy
		if(a%b==0){
			ans+=(a/b*2-1)*b;
			break;
		}
		ans+=a/b*2*b;
		a%=b;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur,a,b,c):
    if(cur == N):
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c)>0 else INF
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b+l[cur],c)+10
    ret3 = dfs(cur + 1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[1],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[55];
long long l[3][11111][111];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
priority_queue<long long,vector<long long>,greater<long long> > q;
//queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r,r1;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}

long long f(int i,int n,int m)
{
    if(n==r.size())
    {
        if(m%a) return 0;
        return 1;
    }
    if(l[i][n][m]>=0) return l[i][n][m];
    long long x=0;
    if(i)
    for(int h='9';h>r[n];h--)
        x+=f(i,n+1,(m+h-'0')%a),x%=mod;
    x+=f(i,n+1,(m+r[n]-'0')%a),x%=mod;
    for(int h=r[n]-1;h>='0';h--)
        x+=f(1,n+1,(m+h-'0')%a),x%=mod;
    return l[i][n][m]=x;
}

int main()
{
    memset(l,-1,sizeof(l));
    cin>>r;
    scanf("%d",&a);
    printf("%lld",(mod-1+f(0,0,0))%mod);
}





Measured memory_bytes: 30080
i=int(input())
i1=i*(i+1)//2
i2=i//3
i3=i//5
i4=i2*(i2+1)//2
i5=i3*(i3+1)//2
i6=i//15
i7=i6*(i6+1)//2
print(i1-i4*3-i5*5+i7*15)

Measured memory_bytes: 9184
#include <stdio.h>

#define N 10000
#define Nil -1

typedef struct{
  int key,p,l,r;
    }Node;

Node T[N];
int n;

/*void max_heapify(Node,int)*/;
void print(int);

int main(){
  int i,l,r;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    T[i].p = T[i].l = T[i].r = Nil;

  for(i=1;i<=n;i++)
    scanf("%d", &T[i].key);

  for(i=n;i>1;i--){
    T[i].p = i/2;   
    if(i == 2*T[i].p)  T[T[i].p].l = i;    
    else if(i == 2*T[i].p + 1)T[T[i].p].r =i; 
  }

  for(i=1;i<=n;i++)
    print(i);

  return 0;
}

/*void max_heapify(Node A, int i){
  int l,r,largest,tmp;

  l = 2i;
  r = 2i +1;

  if(l<n && A[l]>A[i]) largest = l;
  else                 largest = i;
  if(r<n && A[r]>A[largest]) largest = r;
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
  }
  max_heapify(Node A, int largest);
}
*/

void print(int u){
 
  printf("node %d: key = %d, ",u,T[u].key);

  if(T[u].p != Nil)printf("parent key = %d, ",T[T[u].p].key);
  if(T[u].l != Nil)printf("left key = %d, ",T[T[u].l].key);
  if(T[u].r != Nil) printf("right key = %d, ", T[T[u].r].key);
  printf("\n");
}

Measured memory_bytes: 608
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    //   C[A[i + 1]]++;
  }
  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for(j = 1 ; j <= n ; j++) C[A[j]]++;

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for(j = n ; j >= 1 ; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8460
n = int(input())
Alist = list(map(int,input().split()))
Alist.sort()
n = Alist[-1]
if n%2 == 0:
    R = n//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R) < rmin:
            r = i
            rmin = abs(r-R)
else:
    R1 = (1+n)//2
    R2 = (n-1)//2
    r = Alist[0]
    rmin = 10**9
    for i in Alist:
        if abs(i-R1) < rmin or abs(i-R2) < rmin:
            r = i
            rmin = min(abs(r-R1),abs(r-R2))
print(n,r)

Measured memory_bytes: 19808
#include <stdio.h>

#define QUE_SIZE (7*6*5*4*3*2)
#define DIGIT 8

#define dprintf(...)

// 位置ごとの入れ替えられる位置リスト
// -1は使用しない
const int neib[DIGIT][3] = {
    {1,4,-1},
    {0,2,5},
    {1,3,6},
    {2,7,-1},
    {0,5,-1},
    {1,4,6},
    {2,5,7},
    {3,6,-1}
};


///////////////////////////コストテーブル
char cost[8][8][8][8][8][8][8]={{{{{{{0}}}}}}};

void cost_init();
int get_cost(char *data);
void set_cost(char *data,char c);

void cost_init(){
    int i;
    char *pcost;
    pcost = (char*)cost;
    for(i=0;i<8*8*8*8*8*8*8;i++){
        pcost[i]=-1;
    }
}

// 指定されたデータのコストを返す
int get_cost(char *data){
    return cost[data[0]][data[1]][data[2]][data[3]][data[4]][data[5]][data[6]];
}
// 指定されたデータにコストを設定
void set_cost(char *data,char c){
    cost[data[0]][data[1]][data[2]][data[3]][data[4]][data[5]][data[6]] = c;
}


///////////////////////////キュー
char que[QUE_SIZE][DIGIT];
int que_wp;//次回書き込み位置
int que_rp;//次回読み出し位置
int que_cnt;//格納数

void que_init();
char *que_deque(char *buf);
void que_enque(char *data);

//初期化
void que_init(){
    que_wp=que_rp=que_cnt=0;
}

// データ取り出し
// データがあれば引数に書き込みそのアドレスを返す
// データがなければNULLを返す
char *que_deque(char *buf){
    int i;
    if(que_cnt<=0)return NULL;
    que_cnt--;
    for(i=0;i<DIGIT;i++){
        buf[i]=que[que_rp][i];
    }
    que_rp=(que_rp+1)%QUE_SIZE;
    return buf;
}

// データ格納
void que_enque(char *data){
    int i;
    if(que_cnt>=QUE_SIZE)return;
    que_cnt++;
    for(i=0;i<DIGIT;i++){
        que[que_wp][i]=data[i];
    }
    que_wp=(que_wp+1)%QUE_SIZE;
}

////////////////////////その他
// 0の位置を返す
int get_zi(char *data){
    int i;
    for(i=0;i<DIGIT;i++){
        if(data[i]==0)break;
    }
    return i;
}


int main(){
    int i;
    char buf[8] = {0,1,2,3,4,5,6,7}; // 盤面情報（初期値はゴール状態）
    int zi; //zero_index 0の位置
    int mi; //move_index 0の移動先の位置
    char c; //コスト

    // コスト、キューの初期化
    cost_init();
    que_init();

    // ゴールのコスト(0)設定
    que_enque(buf);
    set_cost(buf,0);

    // すべての盤面のコストを求める
    // キューにはコストの少ない順に盤面情報が入っている
    while(que_deque(buf)!=NULL){
        c = get_cost(buf);
        zi = get_zi(buf);
        for(i=0;i<3;i++){
            mi = neib[zi][i];
            if(mi<0)break;
            // 1手進めてみる
            buf[zi]=buf[mi];
            buf[mi]=0;
            if(get_cost(buf)<0){
                // まだ見ぬ盤面になったならコストを設定し、キューに入れる
                que_enque(buf);
                set_cost(buf,c+1);
            }
            // 次の手を試すので進めた手を元に戻す
            buf[mi]=buf[zi];
            buf[zi]=0;
        }
    }

    // 入力に対するコストを表示
    while(scanf("%d",&(buf[0]))>0){
        for(i=1;i<DIGIT;i++){
            scanf("%d",&(buf[i]));
        }
        printf("%d\n",get_cost(buf));
    }

    return 0;
}



Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    int t=1;
    for(int i=0; i<3; ++i){
        if(s.at(i)==s.at(i+1)){
            t *= 0;
        }
    }
    if(t) cout << "Good" << endl;
    else cout << "Bad" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int, char**) {
  int l, r;
  std::cin >> l >> r;
  int end = std::min(l + 2019, r);

  int min{2018};
  for(int i{l}; i <= end; ++i) {
    for(int j{i + 1}; j <= end; ++j) {
      min = std::min<int>(min, (static_cast<long long>(i) * j) % 2019);
    }
  }

  std::cout << min << std::endl;

  return 0;
}


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

using namespace std;

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

vector<vector<int> > graph;
vector<int> dp;

int dfs(int fr){
  int mx = 0;
  if (dp[fr]!=-1) return dp[fr];
  for (auto itr = graph[fr].begin(); itr!=graph[fr].end(); itr++){
    int t = dfs(*itr) + 1;
    mx = MAX(mx, t);
  }
  return dp[fr] = mx;  
}

int main(){
  int n, m;
  int ans;
  
  cin >> n >> m;
  graph = vector<vector<int> >(n);
  dp = vector<int>(n);
  fill(dp.begin(), dp.end(), -1);
  for (int i=0; i<m; i++){
    int fr,to; cin >> fr >> to;
    graph[fr-1].push_back(to-1);
  }
  
  ans = 0;
  for (int i=0; i<n; i++){
    ans = MAX(ans, dfs(i));
  //  cout << i << ": " << dfs(i) << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8192