akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

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

  string a ,b;
  cin >> a;
  b = a;
  reverse(ALL(b));
  cout << (a==b ? "Yes" : "No") << LF;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m; cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=0; i<m; ++i){
        int a,b; cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    map<int,int> mp;
    for(int i=0; i<=n; ++i){
        mp[i] = -1;
    }
    mp[1] = 0;
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int val = q.front();
        q.pop();
        for(int i=0; i<adj[val].size(); ++i){
            if(mp[adj[val][i]] == -1){
                mp[adj[val][i]] = val;
                q.push(adj[val][i]);
            }
        }
    }
    bool flg = false;
    for(int i=1; i<=n; ++i){
        if(mp[i] == -1){
            flg = true;
            break;
        }
    }
    if(flg){
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    for(int i=2; i<=n; ++i){
        cout<<mp[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int x;
string s;
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin>>n>>s;
	int ans=0;
	rep(i,sz(s)){
		if(s[i]=='I')
		x++;
		else
		x--;
		ans=max(ans,x);
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(60, vector<ll>(60, INF));
 
bool flg=0;
 
int main()
{
	cin >> s;
	REP(i,s.size())
	{
		if (s[i] == 'C') flg = 1;
		if(s[i]=='F'&&flg)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

if n >= 2:
    if a < b:
        ans = a + b * (n - 1) - (a * (n - 1) + b) + 1
    elif a == b:
        ans = 1
    else:
        ans = 0
else:
    if a < b:
        ans = 0
    elif a == b:
        ans =1
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n, x;
	cin >> n;
	int a[n + 1] = {};
	for (int i = 1; i < n; i++){
		cin >> x;
		a[x]++;
	}
	for (int i = 1; i <= n; i++){
		cout << a[i] << endl;
	}
}



Measured memory_bytes: 4404
#include<iostream>
#include<string.h>
using namespace std;
long long r[501][1001]={0};
int s[501]={0};
int ans=0,n;
void takahashi(int i){
	//cout<<i<<endl;
	for(int j=2;j<=n;j++){
		if(r[i][j]==1&&s[j]!=1&&r[1][j]!=1){
			s[j]=1;
			ans++;
		}
	}
}	
int main(){
	while(1){
		int m,a,b;
		ans=0;
		cin>>n>>m;
		if(n==0&&m==0)break;
		memset(r,0,sizeof(r));
		memset(s,0,sizeof(s));
		s[1]=1;
		for(int i=0;i<m;i++){
			cin>>a>>b;
			r[a][b]=1;
			r[b][a]=1;
		}
		/*for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<r[i][j];
			}
			cout<<endl;
		}*/
		for(int i=2;i<=n;i++){
			if(r[1][i]==1){
				s[i]=1;
				ans++;
				takahashi(i);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 6996
from itertools import permutations
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

a = 0
b = 0
for i,l in enumerate(permutations([i for i in range(1,n+1)],n)):
    if list(l)==P:
        a=i
    if list(l)==Q:
        b=i
print(abs(a-b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<int, pi> pii;
typedef set<int> si;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll MOD = 1e9+7;
#define lb lower_bound
#define ub upper_bound
#define INF 1000000000
#define SZ(x) x.size()
#define ALL(x) x.begin(),x.end()

int N,Q,a,b;
pi rng[100100];
int ans[100100];
vi adjList[100100];
int p[100100];

pi unionpair(pi a, pi b){
  if (abs(a.f)%2 != abs(b.f)%2 && a.s < INF && b.s < INF){
    cout<<"No";
    exit(0);
  }
  pi res = mp ( max(a.f,b.f) , min(a.s,b.s));
  if (res.f > res.s){
    cout<<"No";
    exit(0);
  }
  return res;
}

void dfs(int x){
  for (auto i : adjList[x]){
    if (p[i] != -1)continue;
    p[i] = x;
    dfs(i);
  }
}

void crange(int x){
  pi res = rng[x];
  for (auto i : adjList[x]){
    if (p[x] == i)continue;
    crange(i);
    pi chk = mp(rng[i].f-1, rng[i].s + 1);
    // cout<<i<<' '<<chk.f<<' '<<chk.s<<'\n';
    res = unionpair(res,chk);
  }
  rng[x] = res;
  // cout<<x<<' '<<res.f<<' '<<res.s<<'\n';
  return;
}

void fill(int x){
  if (rng[x].f != -INF){
    for (auto i : adjList[x]){
      if (p[x] == i)continue;
      rng[i] = unionpair(rng[i], mp(rng[x].f - 1, rng[x].s +1));
    }
  }
  if (ans[x] == -INF){ans[x] = rng[x].f;}
  for (auto i : adjList[x]){
    if (p[x] == i)continue;
    rng[i] = unionpair(rng[i], mp(ans[x] - 1, ans[x] + 1));
    fill(i);
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin);
  cin>>N;
  for (int i=0;i<N-1;++i){
    cin>>a>>b; 
    adjList[a].pb(b);
    adjList[b].pb(a);
  }
  for (int i=1;i<=N;++i)ans[i]=-INF;
  for (int i=1;i<=N;++i)rng[i]=mp(-INF,INF);
  cin>>Q;
  for (int i=0;i<Q;++i){
    cin>>a>>b;
    rng[a] = mp(b,b);
    ans[a] = b;
  }
  memset(p,-1,sizeof(p));
  p[1] = 0;
  dfs(1);
  crange(1);
  fill(1);
  cout<<"Yes\n";
  for (int i=1;i<=N;++i)cout<<ans[i]<<'\n';
  }

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 2e9;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, m, a[MAXN];
bool check(int pos) {
	for (int i = 2 * pos + 1, j = 2 * n; i <= j; i++, j--)
		if (a[i] + a[j] < m) return false;
	return true;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= 2 * n; i++)
		read(a[i]);
	sort(a + 1, a + 2 * n + 1);
	int l = 0, r = n;
	while (l < r) {
		int mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	int ans = 0;
	for (int i = 1, j = 2 * l; i <= j; i++, j--)
		chkmax(ans, a[i] + a[j]);
	for (int i = 2 * l + 1, j = 2 * n; i <= j; i++, j--)
		chkmax(ans, a[i] + a[j] - m);
	writeln(ans);
	return 0;
}

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

using namespace std;

const double PI = 3.14159265358979323846;

double A(double R) {
	return 2 * PI * R;
}

int main() {
	double R;
	cin >> R;
	cout << fixed << setprecision(6) << A(R);
	return 0;
}

Measured memory_bytes: 3784
d1,d2,d3,d4,d5,d6 =map(int,input().split())

a=input()

task=len(a)


for i in range(task):
	if a[i]=='E':
		d1,d2,d3,d4,d5,d6=d4,d2,d1,d6,d5,d3
	if a[i]=='N':
		d1,d2,d3,d4,d5,d6=d2,d6,d3,d4,d1,d5
	if a[i]=='S':
		d1,d2,d3,d4,d5,d6=d5,d1,d3,d4,d6,d2
	if a[i]=='W':
		d1,d2,d3,d4,d5,d6=d3,d2,d6,d1,d5,d4
print(d1)




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

void printVector(vector<int> v) {
    for (auto x : v) {
        cout << x << ' ';
    }
    cout << '\n';
}

void printArray(ll A[], int size) {
    for (int i = 0; i <= size - 1; i++) cout << A[i] << ' ';
}

int main() {
    int A[5];
    int Choice[5];
    for (int i = 0; i <= 4; i++) cin >> A[i];
    for (int i = 0; i <= 4; i++) {
        Choice[i] = (A[i] / 10) * 10 + 10 - A[i];
        if (Choice[i] == 10) Choice[i] = 0;
    }
    int escolhido = 0;
    int indiceEscolhido = 0;
    for (int i = 0; i <= 4; i++) {
        if (Choice[i] > escolhido) {
            escolhido = Choice[i];
            indiceEscolhido = i;
        }
    }
    int tot = 0;
    for (int i = 0; i <= 4; i++) {
        if (i == indiceEscolhido || A[i] % 10 == 0) tot += A[i];
        else tot += (A[i] / 10) * 10 + 10;
    }
    cout << tot << '\n';
    return 0;
}

Measured memory_bytes: 3652
import bisect
n = int(input())
nums=list(map(int,input().split()))
list2 = [pow(2,x) for x in range(31)]
total = 0
for num in nums:
  if num%2 == 0:
    tmp = bisect.bisect_right(list2,num)
    for i in range(tmp,0,-1):
      if num % list2[i] == 0:
        total += i
        break
print(total)

Measured memory_bytes: 4532
/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define INT_MIN -1000000007
#define ld  double
#define pi 3.14159265358979
#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(n) for(i=0;i<n;i++);
using namespace std;
int main()
   {harry
    ld a,b,h,m;
    cin>>a>>b>>h>>m;
    ld an=5.5*(60*h+m);
    an=((an*pi)/180.0);
    ld ans=sqrt(a*a+b*b-2*a*b*cos(an));
    cout<<fixed<<setprecision(22)<<ans;

     }






















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

int main() {
	long long  a,b;
  	int k;cin>>a>>b>>k;
  	for(int i=0;i<k;i++){
    	if(i%2==0){
        	b+=a/2;
          	a/=2;
        }
    	if(i%2==1){
        	a+=b/2;
          	b/=2;
        }
    }
  cout<<a<<" "<<b<<endl;
 }

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

#define EPS 1e-10

int main() {
  double x1,y1,x2,y2,x3,y3,x4,y4;
  
  while( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4 ) {
    if ( fabs( (x1-x2)*(x3-x4) + (y1-y2)*(y3-y4) ) < EPS ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  
  return 0;
}

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

ll n,k,m,a,b;
string s;

int main() {
  cin >> n >> k;
  cout << n-k+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int MAX = 1e5+5;

int main(){
    vector<int> d(MAX);
    for(int i = 1; i < MAX; i++){
        for(int j = i;  j < MAX; j += i){
            d[j]++;
        }
    }
    vector<int> sum(MAX+1);
    for(int i = 2; i < MAX; i++){
        if (d[i] == 2 && i % 2 == 1 && d[(i+1)/2] == 2) sum[i] = sum[i-1] + 1;
        else sum[i] = sum[i-1];
    }

    int q;
    cin >> q;
    vector<int> ans;
    rep(i,q){
        int l, r;
        cin >> l >> r;
        ans.push_back(sum[r]-sum[l-1]);
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4724
def main():
    s = list(input())
    K = int(input())

    s = list(map(lambda x: ord(x), s))
    B = [0 for _ in range(len(s))]
    for i in range(len(s)):
        b = 26 - (s[i] - ord("a"))
        if b == 26:
            B[i] = 0
        elif b <= K:
            K -= b
            B[i] = 0
        else:
            B[i] = b

    if K != 0:
        B[-1] -= K
        B[-1] %= 26

    ans = list(map(lambda c: chr(ord("a") + (26 - c) % 26), B))
    print("".join(ans))


main()


Measured memory_bytes: 5708
I,O,R,J,L,S,Z=map(int,input().split())
a=(I//2+J//2+L//2)*2
b=0
if I*J*L!=0:b=(2*((I-1)//2+(J-1)//2+(L-1)//2)+3)
print(max(a,b)+O)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-


def check_solvable_recursively(number, is_solvable, candidate_numbers):
    """exhaustively search representable as summation of numbers in candidate_numbers

    Args:
        number: representable number
        is_solvable: is solvable list
        candidate_numbers: candidate numbers to be used

    Returns:
        None
    """
    if not is_solvable[number]:
        is_solvable[number] = True
    if candidate_numbers:
        check_solvable_recursively(number + candidate_numbers[0], is_solvable, candidate_numbers[1:])
        check_solvable_recursively(number, is_solvable, candidate_numbers[1:])


def main():
    raw_input()  # pass length
    candidate_numbers = [int(x) for x in raw_input().strip().split(' ')]
    raw_input()  # pass length
    target_number_list = [int(x) for x in raw_input().strip().split(' ')]

    is_solvable_list = [False] * 2001

    check_solvable_recursively(0, is_solvable_list, candidate_numbers)

    for target_number in target_number_list:
        if is_solvable_list[target_number]:
            print "yes"
        else:
            print "no"

if __name__ == "__main__":
    main()

Measured memory_bytes: 6444
def hi():
  a = input()
  key = ""
  for i in range(len(a)):
    if a[i]=='0':
      key += '0'
    elif a[i]=='1':
      key += '1'
    elif a[i]=='B':
      if len(key) == 0:
        continue
      else:
        key = key[0:-1]
  print(key)

hi()

Measured memory_bytes: 9104
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
A = list(map(int, input().split()))
count = 1
dec = False
inc = False
if N <= 2:
    print('1')
    exit()
for i in range(N - 1):
    if (A[i + 1] - A[i]) < 0:
        dec = True
    elif (A[i + 1] - A[i]) > 0:
        inc = True
    if dec and inc:
        count += 1
        dec = False
        inc = False
print(str(count))


Measured memory_bytes: 14228
#include <iostream>
using namespace std;
int main () {
	int n;
	const int pre = 4280;
	while (cin >> n, n != -1) {
		int lv4 = max(0, n - 30);
		int lv3 = min(10, max(0, n - 20));
		int lv2 = min(10, max(0, n - 10));
		int sum = 1150 + lv2 * 125 + lv3 * 140 + lv4 * 160;
		cout << pre - sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2 + 2],R[MAX/2 + 2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0;i<n1;i++) L[i] = A[left+i];
  for(i=0;i<n2;i++) R[i] = A[mid+i];

  L[n1].value = R[n2].value = SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left +1 < right){
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;

  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}



Measured memory_bytes: 4048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		int[] a = new int[w+1];
		for(int i=1; i<=w; i++) a[i]=i;
		
		while(n-- != 0) {
			String[] s = sc.next().split(",");
			int x = Integer.parseInt(s[0]);
			int y = Integer.parseInt(s[1]);
			int std = a[x];
			a[x] = a[y];
			a[y] = std;
		}
		for(int i=1; i<=w; i++) System.out.println(a[i]);
	}
}



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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll m = a * c;
    ll n = a * d;
    ll l = b * c;
    ll k = b * d;
    ll max_1 = max(m, n);
    ll max_2 = max(l, k);
    cout << max(max_1, max_2) << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define len(x) (int)(x).size()

typedef long long ll;
typedef long double ld;

using namespace std;

const int MOD = (int)1e9 + 7;
const int N = 3001;
int dp[N][N];
int sum(int x , int y){
    x += y; if(x >= MOD)x-=MOD;
    return x;
}
signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n , m;cin >> n >> m;
    string s;cin >> s;
    vector < int > r(n);
    iota(all(r) , 0);
    for(int i = 0 ; i < m; ++i){
        int l , _r;cin >> l >> _r;
        --l , --_r;
        r[l] = max(r[l] , _r);
    }
    dp[0][0] = 1;
    int all = 0 , j = 0;
    for(int i = 0; i < n; ++i){
        while(j <= r[i])
            all += s[j] - '0' , j++;
        for(int was = 0 ;was <= i; ++was){
            /// put 1
            if(was + 1 <= all)
                dp[i + 1][was + 1] = sum(dp[i+1][was+1],dp[i][was]);
            /// put 0
            if((j - all) - (i - was))
                dp[i + 1][was] = sum(dp[i+1][was] , dp[i][was]);
        }
    }
    int answer = 0;
    for(int i = 0; i <= n; ++i)
        answer = sum(answer , dp[n][i]);
    cout << answer;
    return 0;
}


Measured memory_bytes: 31140
import math
n,d=map(int,input().split())
X=[]
for i in range(n):
    X.append(list(map(int,input().split())))

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(X[i][k]-X[j][k])**2
        cnt=math.sqrt(cnt)
        if int(cnt)==cnt:
            ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int dp[2005][2005];
int n;
vector<pii> vec;

int alpha(int i , int l)
{
	if(i >= n)return 0;
	int &sol = dp[i][l];
	if(sol != -1)return sol;
	int ans = 0;
	int r = n-1-i+l;
	ans += vec[i].ff*abs(vec[i].ss-l) +  alpha(i+1,l+1);
	ans = max(ans,vec[i].ff*abs(vec[i].ss-r)+alpha(i+1,l)); 
	return sol = ans;
}

void solve()
{
	cin >> n;
	vec.clear();
	vec.resize(n);
	loop(i,0,n)
	{
		int x;
		cin >> x;
		vec.pb({x,i});
	}
	mset(dp,-1);
	S(vec);
	R(vec);
	cout << alpha(0,0);
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N,D;
    cin >> N >> D;
    vector<vi> X(N,vi(D,0));

    REP(i,N) REP(j,D) cin >> X[i][j];
    int ans = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int dist = 0;
            for(int k=0;k<D;k++) dist += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            for(int k=0;k*k<=dist;k++){
                if(k*k==dist){
                    ans++;
                    break;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll i,j,n,m;
	 cin>>n;
	 ll s=0;
	 s+=n/500*1000;
	 n=n-n/500*500;
	 s+=n/5*5;
	 cout<<s<<endl;

}

Measured memory_bytes: 256
N = input()
str_animal = raw_input()
mat = list(str_animal)
pat = (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W'))

def judge(listSW, listox):
    matSW = listSW[-2:] + listSW[:2]
    matox = listox[-2:] + listox[:2]
    for i in xrange(1,3):
        if matSW[i] == 'S':
            if matox[i] == 'o' and matSW[i-1] != matSW[i+1]: break
            if matox[i] == 'x' and matSW[i-1] == matSW[i+1]: break
        else:
            if matox[i] == 'o' and matSW[i-1] == matSW[i+1]: break
            if matox[i] == 'x' and matSW[i-1] != matSW[i+1]: break
    else:
        return 0
    return -1

for i in pat:
    animal = list(i)
    for j in xrange(1, N-1):
        if animal[j] == 'S':
            if mat[j] == 'o':
                animal.append(animal[j-1])
            else:
                if animal[j-1] == 'S':
                    animal.append('W')
                else:
                    animal.append('S')
        else:
            if mat[j] == 'o':
                if animal[j-1] == 'S':
                    animal.append('W')
                else:
                    animal.append('S')
            else:
                animal.append(animal[j-1])
    foo = judge(animal, mat)
    if foo == 0:
        print ''.join(animal)
        break
else:
    print -1

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    ll a, b = 0;
    string s;
    cin >> a >> s;
    rep(i, s.size()) {
        if(s[i] == '.') continue;
        b *= 10;
        if('0' <= s[i] && s[i] <= '9') {
            b += (s[i] - '0');
        }
    }
    // cout << b << endl;
    if(s.size() == 1) b *= 100;
    if(s.size() == 3) b *= 10;
    cout << a * b / 100 << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */



signed main(){

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

    int a, b, c; cin >> a >> b >> c;

    rep(i,1,100000){
        if(a * i % b == c){
            print("YES");
            return 0;
        }
    }

    print("NO");


    
    
    
    







    




   

    
    



    




    




    











    

    

    



    
    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

int main() {
    int n;
    cin >> n;
    int A=pow(10,5);
    for (int i=0; i<n; i++) {
        A*=(1.05);
        A=(A+999)/1000*1000;
    }
    printf("%d\n",A);
    return 0;
}

Measured memory_bytes: 3076
N, M, C = map(int,input().split())
B = [int(_) for _ in input().split()]

count = 0
for i in range(N):
    A = [int(_) for _ in input().split()]
    
    ev = 0
    for j in range(M):
        ev += A[j] * B[j]

    if ev + C > 0:
        count += 1

print(count)

Measured memory_bytes: 3060
#bin/usr/env python3 

NT = input()
tn = input()

NT = NT.split()
tn = tn.split()

N = int(NT[0])
T = int(NT[1])
X = 0

if N == 1:
	print(T)

else:
	for i in range(N):
		if i == N-1:
			X += T
		else:
			if int(tn[i+1])-int(tn[i]) <= T:
				X += int(tn[i+1])-int(tn[i])
	
			else:
				X += T
		
	print(X)

Measured memory_bytes: 20856
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int a[N];
ll n, m, c[N+2], s[N+2];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n){
    cin >> a[i];
    c[a[i]]++;
    s[a[i]] += a[i];
  }
  FORR(i, N-1, 0){
    s[i] += s[i+1];
    c[i] += c[i+1];
  }
  int l = 0, r = N*2+1, k;
  ll ans;
  while(r-l>1){
    k = (l+r)/2;
    ll cc = 0, ss = 0;
    FOR(i, 0, n){
      ll t = max(0, min(k-a[i], N+1));
      cc += c[t];
      ss += s[t]+c[t]*a[i];
    }
    if(cc < m){
      r = k;
    }else{
      l = k;
      ans = ss-(cc-m)*k;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    di = {}
    for n in range(N):
        s = ''.join(sorted(iss()))
        if s in di:
            di[s] += 1
            ret += di[s]
        else:
            di[s] = 0
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17856
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int ans;
int main()
{
	cin>>s1>>s2;
	for(int i=0;i<s1.length();i++)
	{
		if(s1[i]!=s2[i])
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3852
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int H,W,i,j,k;
    int rec[90000][2];
    for(i=0;i<90000;i++){
        scanf("%d",&H);
        rec[i][1] = H;
        scanf("%d",&W);
        rec[i][2] = W;
        if( H*W <= 0 ){
            for(i=0;i<90000;i++){
                if( rec[i][1]*rec[i][2]<= 0 )return 0;
                for(j=0;j<rec[i][1];j++){
                    for(k=0;k<rec[i][2];k++){
                        printf("#");
                    }
                    printf("\n");
                }
                printf("\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long t=0;
    long n,d;
    cin>>n>>d;
    while(n--){
        long x=0,y=0;
        cin>>x>>y;
        if((x*x+y*y)<=d*d)
        t++;
    }
    cout<<t;
} 

Measured memory_bytes: 3648
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

for i in range(2, N):
  if D[i - 2][0] == D[i - 2][1] and D[i - 1][0] == D[i - 1][1] and D[i][0] == D[i][1]:
      print('Yes')
      exit()
      
print('No')

Measured memory_bytes: 9188
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define maxn 2010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
ll fac[maxn],inv[maxn];
int f[maxn][maxn];
int a[maxn];
int n,m;
ll power(ll a,ll b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ans=ans*a%mod;
	return ans;
}
ll C(int n,int m){return fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++)
		a[i]=read();
	fac[0]=inv[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=power(fac[i],mod-2);
	}
	f[0][0]=1;
	for(int i=1;i<=m;i++)
		for(int j=n;j>=0;j--){
			f[i][j]=0;
			for(int k=0;k<=a[i]&&k<=j;k++)
				f[i][j]=(f[i][j]+C(n-k,a[i]-k)*inv[k]%mod*f[i-1][j-k])%mod;
		}
	writeln(f[m][n]*fac[n]%mod);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;



int main(){
    ll n,ans=0,m;
    cin>>m;
    n=m-1;
    ans=n*(n+1)/2;
    cout<<ans;
}


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

public class Main {
  private static Scanner sc;

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


  private void solve() {
    int N = sc.nextInt();
    long x = sc.nextInt();
    long[] as = new long[N];
    for (int i = 0; i < N; i++) {
      as[i] = sc.nextInt();
    }
    Arrays.sort(as);

    long rest = x;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (rest >= as[i]) {
        if (i != N - 1) {
          cnt++;
          rest -= as[i];
        } else {
          if (rest == as[i]){
            cnt++;
            rest -= as[i];
          }
        }
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	long long n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	
	int i, j;
	long long m, total = 1, tmp[32] = {2}, ex[2] = {1, 1};
	for (i = 1; i < 32; i++) tmp[i] = tmp[i-1] * tmp[i-1] % 1000000007;
	for (i = 0, m = n; m > 0; i++, m = m >> 1) if (m % 2 == 1) total = total * tmp[i] % 1000000007;
	for (i = 0; i < a; i++) ex[0] = ex[0] * (n - i) % 1000000007;
	for (j = 1; j <= a; j++) ex[0] = div_mod(ex[0], j, 1000000007);
	for (ex[1] = ex[0]; i < b; i++) ex[1] = ex[1] * (n - i) % 1000000007;
	for (; j <= b; j++) ex[1] = div_mod(ex[1], j, 1000000007);
	
	printf("%lld\n", (total + 1000000007 * 2 - ex[0] - ex[1] - 1) % 1000000007);
	fflush(stdout);
	return 0;
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

vector<string> vec;

signed main(){
	int N=read(), L=read();
	REP(i,N){
		string str;
		cin >> str;
		vec.push_back(str);
	}
	sort(vec.begin(),vec.end());
	
	REP(i,N){
		cout << vec[i];
	}
}

Measured memory_bytes: 764
n = int(input())
s = list(input())
cnt = 0
cnt += s.count('R')*s.count('G')*s.count('B')
for i in range(1,n-1):
    if s[i] == 'R':
        for j in range(1,min(i,n-i-1)+1):
            if s[i-j] == 'G' and s[i+j]=='B':
                cnt -=1
            if s[i-j] == 'B' and s[i+j]=='G':
                cnt -=1
    if s[i] == 'G':
        for j in range(1,min(i,n-i-1)+1):
            if s[i-j] == 'R' and s[i+j]=='B':
                cnt -=1
            if s[i-j] == 'B' and s[i+j]=='R':
                cnt -=1
    if s[i] == 'B':
        for j in range(1,min(i,n-i-1)+1):
            if s[i-j] == 'G' and s[i+j]=='R':
                cnt -=1
            if s[i-j] == 'R' and s[i+j]=='G':
                cnt -=1
print(cnt)

Measured memory_bytes: 9216
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;


namespace AtCoder{

class Program{

static void Main(string[] args){

//int n = int.Parse(Console.ReadLine());
var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
Array.Sort(line);

int a = line[2];
int b = line[1];
int c = line[0];

int answer = a*10+b+c;

Console.WriteLine(answer);
}

}

}

Measured memory_bytes: 13268
import bisect 
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    idx = bisect.bisect(L,L[i]+L[j]-1)
    ans += idx-j-1
print(ans)


Measured memory_bytes: 43100
#include<stdio.h>
#include<stdlib.h>

#define int long long

struct TNode
{
	int data;
	struct TNode *left, *right;
};

typedef struct TNode *Tree;

Tree insert(Tree T, int x)
{
	if (T == NULL)
	{
		T = (Tree)malloc(sizeof(struct TNode));
		T->data = x;
		T->left = T->right = NULL;
	}
	if (x < T->data)
		T->left = insert(T->left, x);
	if (x > T->data)
		T->right = insert(T->right, x);
	return T;
}

int find(Tree T, int x)
{
	if (T)
	{
		if (x > T->data)
			return find(T->right, x);
		else if (x < T->data)
			return find(T->left, x);
		else return 1;
	}
	return 0;
}

void inorder(Tree T)
{
	if (T)
	{
		inorder(T->left);
		printf(" %lld", T->data);
		inorder(T->right);
	}
}

void preorder(Tree T)
{
	if (T)
	{
		printf(" %lld", T->data);
		preorder(T->left);
		preorder(T->right);
	}
}

void print(Tree T)
{
	inorder(T);
	printf("\n");
	preorder(T);
	printf("\n");
}

int main()
{
	int n, x;
	char s[20];
	Tree T;
	T = NULL;

	scanf("%lld", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", s);
		if (s[0] == 'i')
		{
			scanf("%lld", &x);
			T = insert(T, x);
		}
		if (s[0] == 'p')
			print(T);
		if (s[0] == 'f')
		{
			scanf("%lld", &x);
			if (find(T, x))
				printf("yes\n");
			else
				printf("no\n");
		}
	}
}


Measured memory_bytes: 14216
S = input()+"D"

i = 0
ans = 0
A = 0
while i < len(S)-1:
    if A > 0 and S[i] == "B" and S[i+1] == "C":
        i += 2
        ans += A
    elif S[i] == "A":
        A += 1
        i += 1
    else:
        A = 0
        i += 1
print(ans)


Measured memory_bytes: 3500
//
//  main.c
//  q_02
//
//  Created by k19104kk on 2020/08/22.
//  Copyright © 2020 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    char n[200001];
    
    scanf("%s", n);
    
    
    int count = 0;
    long long sum = 0;
    while (n[count] != '\0') {
        sum += n[count] - '0';
        count++;
    }
    if (sum % 9 == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1776
#include<stdio.h>

int main(void) {
    int a, b, c, d, p;
    scanf("%d", &a);
    scanf("%d", &b);                                                                                                                                                     
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &p);

    int x, y;
    x = a * p;
    y = b;
    if(p > c) y += (p - c) * d;

    if(x <= y) printf("%d\n", x); 
    else       printf("%d\n", y); 

    return 0;
}

Measured memory_bytes: 596
//
//  main.cpp
//  AtCoder
//
//  Copyright © 2018年 ユーマ. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    
    int a, b;
    
    std::cin >> a, std::cin >> b;
    
    if(a * b % 2 == 0){
        std::cout << "Even" << std::endl;
    }
    else{
        std::cout << "Odd" << std::endl;
    }
    
    return 0;
}


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

using namespace std;

#define For(i,a,b) for(ll i=a;i<b;i++)
#define Ford(i,a,b) for(ll i=a;i>=b;i--)
#define RET(x) { cout << x; exit(0); }
#define smin(a,b) a=min(a,b)
#define smax(a,b) a=max(a,b)
#define SZ(x) ((ll)((x).size()))
#define PB push_back
#define ER(x) cout << #x << ' ' << x << '\n';
#define X first
#define Y second

typedef long long int LL;
typedef LL ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

const ll M=1e5+5,LG=30,mod=924844033;
ll pw(ll x,ll y){ if (y==0) return 1; return pw(x*x%mod,y/2)*(y&1?x:1)%mod; }

#define MOK(x) if (x>=mod) x-=mod;


vll g[M];
ll uu[M],vv[M],ww[M];
ll n;
ll co[LG];

ll nwbk[LG],nw[LG];


ll bu(){
  ll res=0;
  For(i,1,16){
    if (nw[i]) res+=(1<<(i-1));
  }
  return res;
}

void backup(){
  For(i,1,16) nwbk[i]=nw[i];
}

void unpack(){
  For(i,1,16) nw[i]=nwbk[i];
}

ll dfs(ll x,ll p){
  ll s=0,ebab=0;
  for (ll e:g[x]){
    ll y=uu[e]^vv[e]^x;
    if (y==p){
      ebab=ww[e];
      continue;
    }
    s^=dfs(y,x);
  }
  //ER(x);ER(p);ER(s);
  co[s^ebab]++;
  return ebab;
}

vector<pll> gd[M];
ll qu[M],qh,qt;
ll vis[M];
ll dp[M];

void dpupd(){
  For(i,0,1<<15){
    For(j,1,16){
      nw[j]=(i>>(j-1)&1);
    }
    For(j,1,16){
      if (!nw[j]) continue;
      nw[j]=0;
      //ER(i);ER(bu());
      gd[bu()].PB({i,1});
      nw[j]=1;
      break;
    }
    For(a,1,16){
      if (!nw[a]) continue;
      For(b,a+1,16){
	if (!nw[a] || !nw[b]) continue;
	For(c,1,16){
	  backup();
	  nw[a]=0;
	  nw[b]=0;
	  ll ap=a^c;
	  ll bp=b^c;
	  ll r=1;
	  if (nw[ap]){
	    r++;
	    nw[ap]=0;
	  }
	  else{
	    nw[ap]=1;
	  }
	  if (nw[bp]){
	    r++;
	    nw[bp]=0;
	  }
	  else{
	    nw[bp]=1;
	  }
	  gd[bu()].PB({i,r});
	  unpack();
	}
      }
      break;
    }
  }
  memset(dp,31,sizeof dp);
  qu[0]=0;
  dp[0]=0;
  qh=0;
  qt=1;
  while (qh!=qt){
    ll u=qu[qh++];
    vis[u]=0;
    for (pll e:gd[u]){
      ll v=e.X;
      ll rd=dp[u]+e.Y;
      if (dp[v]<=rd) continue;
      dp[v]=rd;
      if (!vis[v]){
	vis[v]=1;
	qu[qt++]=v;
      }
    }
  }
  /*For(i,1,(1<<15)){
    if (dp[i]>__builtin_popcount(i)){
      ER(i);ER(dp[i]);
    }
    }*/
  //ER(qh);
}

int main(){
  ios::sync_with_stdio(0);
  cin >> n;
  For(i,1,n){
    ll u,v,w;
    cin >> u >> v >> w;
    uu[i]=u;vv[i]=v;ww[i]=w;
    g[u].PB(i);
    g[v].PB(i);
  }
  co[dfs(0,0)]--;
  ll res=0;
  ll mymsk=0;
  For(i,1,16){
    //ER(i);ER(co[i]);
    res+=co[i]/2;
    co[i]=co[i]%2;
    if (co[i])
      mymsk+=1<<(i-1);
  }
  dpupd();
  //ER(mymsk);ER(dp[mymsk]);
  res+=dp[mymsk];
  RET(res);
}


Measured memory_bytes: 92416
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = 0;
  while (k > 0) {
    if (a > 0) {
      a--;
      k--;
      ans++;
      continue;
    }

    if (b > 0) {
      b--;
      k--;
      continue;
    }

    if (c > 0) {
      c--;
      k--;
      ans--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3584
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);		
		int a = sc.nextInt();		
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
		System.out.println("YES");	
		else
		System.out.println("NO");
	}	
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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(){
  int i,j;
  deque<char> dq;
  string s;
  cin>>s;
  bool ord=0;
  for(i=0;i<s.size();i++) dq.push_back(s[i]);
  int q;
  cin>>q;
  while(q--){
    int t;
    cin>>t;
    if(t==1) ord^=1;
    else {
      int f;
      char c;
      cin>>f>>c;
      f--;
      if(f^ord) dq.push_back(c);
      else dq.push_front(c);
    } 
  }
  while(dq.size()){
    if(!ord) {
      cout<<dq.front();
      dq.pop_front();
    }
    else{
      cout<<dq.back();
      dq.pop_back();
    }
  }
  cout<<endl;


}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

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

    v_ll a(n), b(n);

    irep(i, n) {
        cin >> a[i] >> b[i];
    }
    
    ll ans = 0;
    ll pre = 0;
    irrep(i, n) {
        ll diff = (pre + a[i]) - b[i];
        if(diff % b[i] != 0) {
            ll q = ((pre + a[i]) + b[i] - 1) / b[i];
            ans += (q * b[i]) - (pre + a[i]);
            pre += (q * b[i]) - (pre + a[i]);    
        }
    }
    cout << ans << endl;
    return 0;
}   
/** atcoder **/



Measured memory_bytes: 1792
if __name__ == '__main__':
    x=list(map(int,input().split(" ")))
    while x[0]>0 and x[2]>0:
        x[2]=x[2]-x[1]
        if x[2]<=0:
            print("Yes")
            break
        else:
            x[0]=x[0]-x[3]
            if x[0]<=0:
                print("No")
                break

Measured memory_bytes: 9128
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  char nome[n+1];
  scanf("%s", nome);
  int total = 1;

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


Measured memory_bytes: 256