akhauriyash/Code-Regression huggingface dataset:
// Sorting Five Numbers

#include <iostream>
using namespace std;

int main() {
    int array[5];
    int tmp;

    for (int i = 0; i < 5; i++)
        cin >> array[i];

    for (int i = 0; i < 5; i++) {
        for (int j = 4; j > i; j--) {
            if (array[j-1] < array[j]) {
                tmp = array[j-1];
                array[j-1] = array[j];
                array[j] = tmp;
            }
        }
    }

    for (int i = 0; i < 5; i++) {
        if (i) cout << ' ';
        cout << array[i];
    }
    cout << '\n';
    return 0;
}


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

int main() {
    long long A, B, K;
    cin >> A >> B >> K;
    if(K <= A) cout << A - K << ' ' << B << endl;
    else cout << 0 << ' ' << max(0LL, B - (K - A)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n;
    cin >> n;
    ll res = 2; //n,n-1
    if (n == 2) {
        --res;
    }
    for (ll i = 2; i * i <= n - 1; i++) {
        if ((n - 1) % i == 0) {
            res++;
            if ((n - 1) / i != i) {
                res++;
            }
        }
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ll x = n;
            while (x % i == 0) {
                x /= i;
            }
            if ((x - 1) % i == 0) {
                res++;
            }
            if (i == n / i) continue;
            x = n;
            while (x % (n / i) == 0) {
                x /= (n / i);
            }
            if ((x - 1) % (n / i) == 0) {
                res++;
            }
        }
    }
    cout << res << endl;
}

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

signed main(){
	int N;
	int ans=0;
	string S,T,U;
	cin>>N>>S>>T>>U;
	REP(i,N){
		int cnt=0;
		map<char,int> w;
		w[S[i]]++;
		w[T[i]]++;
		w[U[i]]++;
		int sum=0,Max=0,Maxsum=0;
		for(auto x:w){
			sum+=x.second;
			int t=x.second;
			Max=max(Max,t);
		}
		ans+=sum-Max;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
mod = 1000000007
n = int(input())

if n == 1:
  print(0)
elif n == 2:
  print(2)
else:
  a = pow(10,n) % mod
  b = pow(9,n) % mod
  c = pow(9,n) % mod
  d = pow(8,n) % mod
  print((a-b-c+d)%mod)

Measured memory_bytes: 10588
w,h,n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]

a1,a2,a3,a4 = 0,w,0,h
for i in range(n):
    if l[i][2] == 1:
        a1 = max(l[i][0], a1)
    elif l[i][2] == 2:
        a2 = min(l[i][0], a2)
    elif l[i][2] == 3:
        a3 = max(l[i][1], a3)
    elif l[i][2] == 4:
        a4 = min(l[i][1], a4)

if a2-a1 <= 0 or a4-a3 <= 0:
    print(0)
else:
    print((a2-a1)*(a4-a3))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll a,b,c;

void solve(){
    cin >> a >> b >> c;
    if (a%2==1 || b%2==1 || c%2==1) {
        cout << 0 << endl;
        return;
    }
    ll ma=max(max(a,b),c);
    ll k=1,cnt=0;
    while (ma>=k) {
        k*=2;
        if (a%k!=b%k || a%k!=c%k) {
            cout << cnt << endl;
            return;
        }
        cnt+=1;
    }
    cout << -1 << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 305;
const long long mod = 998244353ll;

int n, K, num[N], pre[N], cnt = 0;
char str[N];
long long f[N][N << 1], g[N][N << 1], tmp[N][N << 1];

int main () {
	scanf("%s%d", str, &K), n = strlen(str);
	int pos = -1;
	for (int i = 0; str[i]; i++) {
		if (str[i] == '0') {
			num[++cnt] = i - pos - 1;
			pos = i;
		}
	}
	num[++cnt] = n - 1 - pos;
	pre[0] = 0;
	for (int i = 1; i <= cnt; i++) pre[i] = pre[i - 1] + num[i];

	for (int i = 0; i <= pre[cnt]; i++) {
		for (int j = 0; j <= (pre[cnt] << 1); j++) f[i][j] = 0ll;
	}
	f[0][0] = 1ll;
	for (int i = 1; i <= cnt; i++) {
		for (int j = 0; j <= (pre[cnt] << 1); j++) {
			tmp[0][j] = f[0][j];
			for (int k = 1; k <= pre[cnt]; k++) tmp[k][j] = (tmp[k - 1][j] + f[k][j]) % mod;
		}
		for (int j = 0; j <= pre[cnt]; j++) {
			for (int k = 0; k <= (pre[cnt] << 1); k++) {
				g[j][k] = 0ll;
				if (j >= pre[i]) {
					g[j][k] = j > num[i] ? tmp[j - num[i] - 1][k] : 0ll;
					for (int l = 0; l <= min(num[i], j); l++) {
						if (k + l >= num[i]) g[j][k] = (g[j][k] + f[j - l][k + l - num[i]]) % mod;
					}
				}
			}
		}
		for (int j = 0; j <= pre[cnt]; j++) {
			for (int k = 0; k <= (pre[cnt] << 1); k++) f[j][k] = g[j][k];
		}
	}

	long long ans = 0ll;
	for (int i = 0; i <= min(pre[cnt] << 1, K); i++) ans = (ans + f[pre[cnt]][i]) % mod;
	printf("%lld\n", ans);
	return 0;
}

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

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {

		for (;;) {
			int m = sc.nextInt();
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();

			if (m == 0 && t == 0 && p == 0 && r == 0) {
				break;
			}

			int score[][] = new int[t][p];
			int solved[][] = new int[t][p];
			for (int i = 0; i < r; i++) {
				int mm = sc.nextInt();
				int tt = sc.nextInt()-1;
				int pp = sc.nextInt()-1;
				int jj = sc.nextInt();
				
				if(jj == 0){
					score[tt][pp] += mm;
					solved[tt][pp] = 1;
				}else{
					score[tt][pp] += 20;
				}
			}
			
			E[] ee = new E[t];
			for(int i = 0; i < t; i++){
				E e = new E();
				e.sol = 0;
				e.pen = 0;
				e.id = i+1;
				for(int j = 0 ; j < p ;j++){
					e.sol += solved[i][j];
					e.pen += solved[i][j] * score[i][j];
				}
				ee[i] = e;
			}
			Arrays.sort(ee,Main::compare);
			
			for(int i =0 ; i< t-1;i++){
				System.out.print(ee[i].id);
				System.out.print(ee[i].sol == ee[i+1].sol && ee[i].pen == ee[i+1].pen ?"=":",");
			}
			System.out.println(ee[t-1].id);
		}
	}
	class E{
		int sol;
		int pen;
		int id;
	}
	static int compare(E a, E b){
		return a.sol == b.sol? a.pen == b.pen? b.id-a.id:a.pen-b.pen:b.sol-a.sol;
	}
	
}



Measured memory_bytes: 69772
import sys
input = sys.stdin.readline

s = input().rstrip()
ans = 0
for i in range(1, len(s)):
    if i % 2 == 1:
        continue
    s_ = s[:len(s) - i]
    #print(s_, i)
    if s_[:len(s_)//2] == s_[len(s_)//2:]:
        ans = len(s_)
        break
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,d,c=0;
    cin>>n>>d;
    while(n--)
    {
        long long int x,y,z;
        cin>>x>>y;
        double j=0;
        z=x*x+y*y;
        j=sqrt(z);
        if(j<=d)
        {
            c++;
        }

    }
    cout<<c;

    
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int INF = 50001;

	int n, m;
	scanf("%d %d", &n, &m);

	int T[n + 1];
	int C[m];
	for (int i = 0; i < m; ++i) {
		int coin;
		scanf("%d", &coin);
		C[i] = coin;
	}
//15 6
//1 2 7 8 12 50
	for (int i = 1; i < n + 1; ++i) {
		T[i] = INF;
	}
	T[0] = 0;

	for (int i = 0; i < m; ++i) {
		for (int j = C[i]; j <= n; ++j) {
			T[j] = min(T[j], T[j - C[i]] + 1);
		}
	}

	cout << T[n] << endl;

	return 0;
}

Measured memory_bytes: 3360
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T=1, n;
    while (T--){
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cout << "ACL";
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (count(a.begin(), a.end(), 0)) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i] > 1000000000000000000LL / ans) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4064
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
bool comp(const pair<int,int>p1,const pair<int,int>p2){
    return (p1.s<p2.s);
}
void solve()
{
    int n;
    cin>>n;
    vector<pair<int,int>>v;
    rep0(i,n){
        int x,y;
        cin>>x>>y;
        int l=x-y;
        int r=x+y;
        v.pb({l,r});
    }
    sort(v.beg,v.en,comp);
    ll an=1;
    int mx=v[0].second;
    rep1(i,n-1){
        if(v[i].first>=mx){
            an++;
            mx=v[i].second;
        }
    }
    pr(an);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> S(N);
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  long long ans = 0;
  for(int i = 1; i < N; i++) {
    if(S.at(i - 1) > S.at(i)) {
      ans += S.at(i - 1) - S.at(i);
      S.at(i) = S.at(i - 1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;

int ret(char m,int x,int y,int z){
  if(m=='r') return z;
  else if(m=='s') return x;
  else return y;
}

int main(){
  int x,y,z,n,k;
  cin>>n>>k>>x>>y>>z;
  vector<char> a(n);
  rep(i,n) cin>>a.at(i);
  int ans=0;
  
  for(int i=0;i<n;i++){
     if(i<k){
       ans += ret(a.at(i),x,y,z);
       continue;
     }
    if(a.at(i)==a.at(i-k)){
       a.at(i)='m';
      continue;
    }
    ans += ret(a.at(i),x,y,z);
  }
  cout<<ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> bite(N);

	for (int i = 0; i < N; i++) {
		cin >> bite[i].first >> bite[i].second;
	}

	sort(bite.begin(), bite.end());
	long long ans = 0;
	int i = 0;
	priority_queue<int> queue;


	for (int rem = 1; rem <= M; rem++) {
		while (bite[i].first <= rem) {
			queue.push(bite[i].second);
			i++;
		}
		if (!queue.empty()) {
			ans += queue.top();
			queue.pop();
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1660
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = -1;
    int b = -1;
    for(int i = 0; i < s.length() - 2; i++) {
      if(s.charAt(i) == s.charAt(i + 1)) {
        a = i + 1;
        b = i + 3;
      } else if(s.charAt(i) == s.charAt(i + 2)) {
        a = i + 1;
        b = i + 3;
      } else if(s.charAt(i + 1) == s.charAt(i + 2)) {
        a = i + 1;
        b = i + 3;
      }
    }
    if((s.length() == 2) && (s.charAt(0) == s.charAt(1))) {
      a = 1;
      b = 2;
    }
    System.out.println(a + " " + b);
  }
}

Measured memory_bytes: 25556
num_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
num = input()
num = int(num)
print(num_list[num-1])

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

int main(){

    int n,m;
    cin >> n >> m;

    ll mo=1e+9+7;
    ll ans=1;

    if(abs(n-m)>=2){
        ans=0;
    }else{
        for(int i=1;i<=n;i++){
            ans*=i;
            ans%=mo;
        }
        for(int i=1;i<=m;i++){
            ans*=i;
            ans%=mo;
        }
        if(n==m){
            ans*=2%mo;
            ans%=mo;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  std::vector<int64_t> v(2);
  v.at(0) = 2;
  v.at(1) = 1;
  for (int i = 0; i < n-1; i++) {
    v.push_back(v.at(i)+v.at(i+1));
  }
  cout << v.at(n) <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;
static const int MAX = 50;

int main() {
    int N;
    double v[MAX];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> v[i];

    for (int i = 0; i < N - 1; ++i) {
        sort(v, v + N);
        v[0] = (v[0] + v[1]) / 2;
        v[1] = 1001;
    }

    cout << v[0];

    return 0;
}

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

a = [list(map(str, input().rstrip())) for x in range(n)]
b = [list(map(str, input().rstrip())) for x in range(m)]

ans = []
for i in range(n - m + 1):
    for j in range(n - m + 1):
        tmp = []
        for x in range(m):
            for y in range(m):
                if a[i + x][j + y] == b[x][y]:
                    tmp.append(True)
                else:
                    tmp.append(False)
        ans.append(all(tmp))

print("Yes" if any(ans) else "No")

Measured memory_bytes: 3064
n, k = map(int, input().split())
s_1 = 0
s_2 = 0
s_3 = 0
mod = 1000000007
ans = 0
for i in range(k, n + 2):
    s_1 = (n + n + 1 - i) * i // 2
    s_2 = (0 + i - 1) * i // 2
    s_3 += s_1 + 1 - s_2
ans = s_3 % 1000000007
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  string S; cin >> S;
  int N = S.size();
  int d[N];
  rep(i,N) d[i] = (int)(S[i]-'0');
  
  vector<int> powmod(N); //powmod[i]: 10^iを2019で割った余り
  powmod[0] = 1;
  rep(i,N){
    if (i==0) continue;
    powmod[i] = (powmod[i-1]*10)%2019;
  }

  vector<int> acum(N,0);
  vector<int> cnt(2019,0);
  cnt[0] = 1;
  for (int j=0;j<N;j++){
    if (j==0) acum[j] = d[N-1-j];
    else acum[j] = (acum[j-1] + d[N-1-j]*powmod[j])%2019;
    
    cnt[acum[j]]++;
  }

  int retval = 0;
  rep(i,2019) retval += cnt[i]*(cnt[i]-1)/2;
  cout << retval << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 5900
import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_left(L,L[i]+L[j],j+1)
        #print(index)
        ans += (index - 1) - (j + 1) + 1
print(ans)

Measured memory_bytes: 45412
#include <stdio.h>

int main(){
	int n,a,b,i,x=0;
	int sum,dig;
	
	scanf("%d",&n);
	scanf("%d",&a);
	scanf("%d",&b);
	
	for(i=1;i<=n;i++){
		sum=0;
		sum+=(i/10000)%10;
		sum+=(i/1000)%10;
		sum+=(i/100)%10;
		sum+=(i/10)%10;
		sum+=i%10;
		if(sum>=a&&sum<=b)
			x+=i;
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break 
    for y in range(0, a):
        for x in range(0, b):
            if (y + x)%2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
import scala.io.StdIn._
object Main extends App {
  val s = readLine

  def dp(rems: Array[Long], d: Char): Array[Long] = {
    val ret = new Array[Long](13)
    val is = if (d == '?') (0 to 9) else Seq((d - '0').toInt)
    for {
      i <- is
      j <- (0 to 12)
    } {
      ret((j * 10 + i) % 13) += rems(j)
      ret((j * 10 + i) % 13) %= 1000000007
    }
    ret
  }

  val init = Array.tabulate(13)(i => if (i == 0) 1L else 0L)
  val result = s.foldLeft(init)(dp)
  println(result(5))
}

Measured memory_bytes: 46860
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll d;
    cin >> d;
    d*=d;
    ll count=0;
    rep(i,n){
        ll x;
        cin >> x;
        ll y;
        cin >> y;
        if(x*x+y*y<=d) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3640
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    char v[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> v[i][j];
        }
    }
    int ans[h][w];
    if (v[0][0] == '.') ans[0][0] = 0;
    else ans[0][0] = 1;
    for (int j = 1; j < w; j++){
        if (v[0][j] == '.') ans[0][j] = ans[0][j-1];
        else ans[0][j] = ans[0][j-1] + (int)(v[0][j-1] == '.');
    }
    for (int i = 1; i< h; i++){
        if (v[i][0] == '.') ans[i][0] = ans[i-1][0];
        else ans[i][0] = ans[i-1][0] + (int)(v[i-1][0] == '.');
    }
    for (int i = 1; i < h; i++){
        for (int j = 1; j < w; j++){
            if (v[i][j] == '.') ans[i][j] = min(ans[i-1][j], ans[i][j-1]);
            else ans[i][j] = min(ans[i-1][j] + (int)(v[i-1][j] == '.'), ans[i][j-1] + (int)(v[i][j-1] == '.'));
        }
    }
    cout << ans[h-1][w-1];
    return 0;
}




Measured memory_bytes: 256
//we'll get thru it believe me 
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
void max_self(long long&a, long long b){
	a=max(a, b);
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long long N, W, ans=0;
	cin>>N>>W;
	vector<vector<long long>>dp(N+1, vector<long long>(W+1, 0));
	vector<long long>ws(N), vs(N);
	for(int i=0; i<N; i++)cin>>ws[i]>>vs[i];
	for(int i=0; i<N; i++){
		for(int w=0; w<W; w++){
			if(i<N){
				max_self(dp[i+1][w], dp[i][w]);
			}
			if(w+ws[i]<=W){
				max_self(dp[i+1][w+ws[i]], dp[i][w]+vs[i]);
			}
			//~ cout<<i<<" "<<w<<" "<<dp[i][w]<<"\n";
		}
	}
	for(int w=0; w<=W; w++){
		max_self(ans, dp[N][w]);
		//~ cout<<N<<" "<<w<<" "<<dp[N][w]<<"\n";
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 80256
a=gets.chomp.split.map(&:to_i)
b=0
if a[0]==1||a[1]==1
  puts 1

else
   if a[0]%2==0&&a[1]%2==0
    puts a[0]*a[1]/2
    elsif a[0]%2==0&&a[1]%2!=0
     puts (a[0]*(a[1]-1)/2)+(a[0]-a[0]/2)
   elsif a[1]%2==0&&a[0]%2!=0
    puts (a[1]*(a[0]-1)/2)+(a[1]-a[1]/2)
   else  puts (a[1]-1)*(a[0]-1)/2+(a[1]-a[1]/2)+(a[0]-a[0]/2)-1
   end
end


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

int main(){
	int n,s,c;
	string m;
	while(1){
		cin>>n;
		if(n==0) break;
		s=c=0;
		for(int i=0;i<n;i++){
			cin>>m;
			if(s==1&&(m=="lu"||m=="ru")) c++;
			if(s==0&&(m=="ld"||m=="rd")) c++;
			if(m=="lu"||m=="ru") s=1;
			if(m=="ld"||m=="rd") s=0;
		}
		cout<<c<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(){
	int n, k;
	if(scanf("%d %d", &n,&k)==EOF){return 0;}
	int i = 1;
	int ki = 1;
	while(1){
		ki *= k;
		if( ki > n){
			printf("%d\n", i);
			break;
			}
		i++;
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template<uint32 MOD>
class modint {
public:
	uint32 a;
	modint() :a(0) {}
	modint(int64 x) :a(norms(x%MOD + MOD)) {}
	static uint32 norms(const uint32 &x) { return (x < MOD) ? x : x - MOD; }
	static modint make(const uint32 &x) { modint ret;ret.a = x;return ret; }
	const modint operator+(const modint &o) const { return make(norms(a + o.a)); }
	const modint operator-(const modint &o) const { return make(norms(a + MOD - o.a)); }
	const modint operator*(const modint &o) const { return make((uint64)a*o.a%MOD); }
	const modint operator/(const modint &o) const { return make((uint64)a*~o%MOD); }
	modint &operator+=(const modint &o) { return *this = *this + o; }
	modint &operator-=(const modint &o) { return *this = *this - o; }
	modint &operator*=(const modint &o) { return *this = *this * o; }
	modint &operator/=(const modint &o) { return *this = *this / o; }
	modint &operator^=(const uint32 &o) { return *this = *this^o; }
	const modint operator~() const { return *this ^ (MOD - 2); }
	const modint operator-() const { return make(norms(MOD - a)); }
	const modint operator++() { return *this = make(norms(a + 1)); }
	const modint operator--() { return *this = make(norms(a + MOD - 1)); }
	const bool operator!() const { return !a; }
	const bool operator==(const modint &o) const { return a == o.a; }
	const bool operator!=(const modint &o) const { return a != o.a; }
	const bool operator<(const modint &o) const { return a < o.a; }
	const bool operator<=(const modint &o) const { return a <= o.a; }
	const bool operator>(const modint &o) const { return a > o.a; }
	const bool operator>=(const modint &o) const { return a >= o.a; }
	const modint operator^(const uint32 &x) const {
		uint64 t = (uint64)a;uint32 u = 0;
		for (uint32 i = 0;i < 31;++i) { if (x >> i & 1) u = norms(u + t);t = (t*t) % MOD; }
		return make(u);
	}
};

using mint = modint<1000000007>;
int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n;
	std::string s;
	std::cin >> n >> s;
	mint dp[5003][5003] = {};
	dp[0][0] = 1;
	for (uint32 i = 1;i <= n;++i) {
		dp[i][0] = dp[i - 1][1] + dp[i - 1][1] + dp[i - 1][0];
		for (uint32 j = 1;j <= i;++j) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j + 1];
		}
	}
	std::cout << dp[n][s.length()].a << "\n";
	return 0;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    int X = max(A,B);
    int Y = min(A,B);
    ans += X;
    X--;
    ans += max(X,Y);
    cout << ans << endl;
}


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

int main(){
	lint n,k;
	cin>>n>>k;
	pair<lint,double> memo = make_pair(0,0);
	vector<int> p(n);
	rep(i,n)cin>>p.at(i);
	vector<double> s(n+1,0);
	rep(i,n)s.at(i+1)=s.at(i)+(p.at(i)+1)/2.0;
	rep(i,n-k+1){
		if(memo.second<(s.at(i+k)-s.at(i))){
			memo.first=i;
			memo.second=s.at(i+k)-s.at(i);
		}
	}
	printf("%3.7f\n",memo.second);
}


Measured memory_bytes: 2560
import java.util.*;
import java.math.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    double[] num = new double[n];
    int start = 0;
    double res = 0;
    for(int i = 0; i < k; ++i) {
      double cur = sc.nextDouble();
      num[i] = (1 + cur) / 2;
      res += num[i];
    }
    double mid = res;
    for(int i = k; i < n; ++i, ++start) {
      double cur = sc.nextDouble();
      num[i] = (1 + cur) / 2;
      mid = mid + num[i] - num[start];
      if( mid - res > (double)1e-6) res = mid;
    }
    System.out.println(res);
  }
}

Measured memory_bytes: 159156
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def imp():
        print("No")
        exit()

    n=II()
    to=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=MI1()
        to[u].append(v)
        to[v].append(u)
    k=II()
    pp=[-1]*n
    for _ in range(k):
        v,p=MI()
        pp[v-1]=p

    dp=[[-1,-1,-1] for _ in range(n)]

    def dfs(u=0,pu=-1):
        par=mn=mx=-1
        for v in to[u]:
            if v==pu:continue
            dfs(v,u)
            pv, mnv, mxv = dp[v]
            if pv==-1:continue
            if par==-1:par,mn,mx=1-pv,mnv-1,mxv+1
            else:
                if par^pv==0:imp()
                mn=max(mn,mnv-1)
                mx=min(mx,mxv+1)
                if mn>mx:imp()
        p=pp[u]
        if p==-1:dp[u]=[par,mn,mx]
        elif par!=-1 and (p&1!=par or p<mn or p>mx):imp()
        else:dp[u]=[p&1,p,p]

    dfs()
    #print(dp)
    for p0 in range(dp[0][1],dp[0][2]+1):
        if p0&1==dp[0][0]:
            pp[0]=p0
            break
    else:imp()

    def dfs2(u=0,pu=-1):
        if pp[u]==-1:
            p=pp[pu]
            for d in [1,-1]:
                if dp[u][0]==-1 or dp[u][1]<=p+d<=dp[u][2]:
                    pp[u]=p+d
                    break
        for v in to[u]:
            if v==pu:continue
            dfs2(v,u)

    dfs2()
    #print(pp)
    print("Yes")
    for p in pp:print(p)

main()

Measured memory_bytes: 212160
import java.util.Scanner;
     
     
    public class Main {
        public static void main(String[] args) {
     
            Scanner sc = new Scanner(System.in);
            String s = sc.next();
            String s3 =s.substring(2,3);
            String s4 =s.substring(3,4);
            String s5 =s.substring(4,5);
            String s6 =s.substring(5,6);
            if (s3.equals(s4)&&s5.equals(s6)){
                System.out.println("Yes");

            }else{
                System.out.println("No");

            }
        }
    }

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, K;
int A[2200], B[2200];
vint G[2200];

int m, c;
int dfs(int idx, int pre, int depth) {
    int ret = depth > K / 2;
    if (K & 1 && depth == K / 2 + 1) { c++; }
    for (int i = 0; i < G[idx].size(); i++) {
        if (depth == 0) { c = 0; }
        int nex = G[idx][i];
        if (nex == pre) { continue; }
        ret += dfs(nex, idx, depth + 1);
        chmax(m, c);
    }
    return ret;
}
signed main() {
    cin >> N >> K;
    for (int i = 0; i < N - 1; i++) {
        cin >> A[i] >> B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    int ans = LLONG_MAX;
    for (int i = 1; i <= N; i++) { m = 0, chmin(ans, dfs(i, 0, 0) - m); }
    cout << ans << endl;
}


Measured memory_bytes: 512
import bisect
from math import ceil
N,H=map(int, input().split())

A=[]
B=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

A=sorted(A)
B=sorted(B)

idx=bisect.bisect_right(B,A[-1])
throw=sum(B[idx:])
if throw<=H:
    ans=N-idx
    res=H-throw
    ans+=ceil(res/A[-1])
    #print(res/A[-1], throw)
else:
    res=H
    ans=0
    for i in range(N):
        ans+=1
        res-=B[-(i+1)]
        if res<=0:
            break
print(ans)


Measured memory_bytes: 12176
#include <stdio.h>

int hi[44];
void fibonatti(int p);
int main(){
  int i,n;

  scanf("%d",&n);
   
  fibonatti(n);
  printf("%d\n",hi[n]);

  return 0;
}

void fibonatti(int p){
  int i,n;
  hi[0]=1;
  hi[1]=1;

  for(i=2;i<=p;i++){
    hi[i]=hi[i-2]+hi[i-1];
    
  }
    
}



Measured memory_bytes: 2132
#include "bits/stdc++.h"

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<double> figure(N);
    for(int i = 0; i < N; i++) cin >> figure.at(i);

    double sum = 0.0;
    for(int i = 0; i < N; i++){
        sum += 1 / figure.at(i);
    }
    cout << setprecision(10) << 1 / sum << endl;
}

Measured memory_bytes: 256
<?php
# 入力
list($l, $r) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$min = 2019;
for ($i = $l; $i <= $r - 1; $i++) {
    for ($j = $i + 1; $j <= $r; $j++) {
        $n = ($i * $j) % 2019;
        if ($min > $n) {
            $min = $n;
        }
        if ($min === 0) {
            break 2;
        }
    }
}
echo $min.PHP_EOL;
?>

Measured memory_bytes: 4604
#include <iostream>
#include <cstring>

using namespace std;

int main(){
  int n;
  cin>> n;
  int d[400],u[400],s[400];
  for(int i=0;i<n;i++) cin>>d[i]>>u[i]>>s[i];
  
  int dp[400]={};
  memset(dp,-1,sizeof(dp));
  dp[0]=0;

  for(int i=0;i<n;i++)
    for(int j=0;j<400;j++)
      for(int k=d[i];k<=u[i];k++)
	if(j+k<400 && dp[j]!=-1) dp[j+k] = max(dp[j+k],dp[j]+s[i]);
  
  int q,flg=0,m[400];
  cin>> q;
  for(int i=0;i<q;i++){
    cin >> m[i];
    if(dp[m[i]] == -1) flg= 1;
  }
  if(flg) cout << -1<<endl;
  else 
    for(int i=0;i<q;i++) cout << dp[m[i]]<<endl;
  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}


signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int N;
    cin >> N;
    int m = N % 10;
    if(m == 3){
        cout << "bon" << endl;
    }else if(m == 0  || m == 1 || m == 6 || m == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}


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

int main() {
    int n, k, R, S, P, ans = 0;
    cin >> n >> k >> R >> S >> P;
    string t;
    cin >> t;
    for (int i = 0; i < k; i++) {
        for (int j = i; j < n; j += k) {
            int cnt = 1;
            while (j + k < n && t[j] == t[j + k]) {
                cnt++;
                j += k;
            }
            if (t[j] == 'r') ans += (cnt + 1) / 2 * P;
            if (t[j] == 's') ans += (cnt + 1) / 2 * R;
            if (t[j] == 'p') ans += (cnt + 1) / 2 * S;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

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

int main(){

	int n,m,data;
	cin >> n >> m;
	
	int res[n],t[n],game[m];
	
	rep(i,n) res[i] = 0;
	
	rep(i,m){	
		cin >> data;
		game[i] = data;
	}

	rep(i,m){
		rep(j,n){
			cin >> t[j];
			if(t[j] == game[i]) res[j]++;
			else res[game[i] - 1]++;
		}
	}

	rep(i,n) cout << res[i] << endl;
	
	return 0;	
}

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

int main() {
  int x;
  cin>>x;
  if(x<600) cout<<"8"<<endl;
  else if (x<800) cout<<"7"<<endl;
  else if(x<1000) cout<<"6"<<endl;
  else if(x<1200) cout<<"5"<<endl;
  else if (x<1400) cout<<"4"<<endl;
  else if(x<1600) cout<<"3"<<endl;
  else if(x<1800) cout<<"2"<<endl;
  else if(x<2000) cout<<"1"<<endl;

}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 1000;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	ll a[N], b[N], c[N];
	for(int i = 0; i < x; i++) cin >> a[i];
	for(int i = 0; i < y; i++) cin >> b[i];
	for(int i = 0; i < z; i++) cin >> c[i];

	vector<ll> v;
	for(int i = 0; i < x; i++) {
		for(int j = 0; j < y; j++) {
			v.push_back(a[i] + b[j]);
		}
	}
	sort(v.begin(), v.end(), greater<ll>());

	vector<ll> ans;
	for(int i = 0; i < min(k, x * y); i++) {
		for(int j = 0; j < z; j++) {
			ans.push_back(v[i] + c[j]);
		}
	}
	sort(ans.begin(), ans.end(), greater<ll>());

	for(int i = 0; i < k; i++) cout << ans[i] << endl;
}


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

int main()
{
    int n{};
    std::string s{};

    std::cin >> n >> s;
    int cnt = 0;
    std::string str = "ABC";
    for (int i = 0; i < s.size() - str.size() + 1; i++)
    {
        if (s.substr(i, str.size()) == str)
            cnt++;
    }
    std::cout << cnt;
}

Measured memory_bytes: 256
n = int(raw_input())
ta_list = []
x, y = 1, 1
for i in range(n):
    # ta_list.append(map(int, raw_input().split()))
    t, a = map(int, raw_input().split())
    k = max((x+t-1)/t, (y+a-1)/a)
    x = k*t
    y = k*a

print x + y


Measured memory_bytes: 2568
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

N,K = map(int,input().split())

# ある線を、左にまたぐ数の集合、右にまたぐ数の集合など

MOD = 10 ** 9 + 7

dp = np.zeros((N+1,N*N+1), dtype = np.int64) # ある線をまたぐ（左右）個数、これまでの合計点、場合の数
dp[0,0] = 1
for n in range(1,N+1):
    prev = dp
    dp = np.zeros_like(prev)
    for m in range(N):
        dp[m,m:] += prev[m,:N*N+1-m] # その点を不動点にしてそのまま
        dp[m,m:] += prev[m,:N*N+1-m] * m # どれかをそこに留めてのこりを右に
        dp[m+1,m+1:] += (m+1) * prev[m,:N*N-m] # その点ごと全部右に。左に流す方をどれか残す
        dp[m,m:] += prev[m,:N*N+1-m] * m # xを左に、左から来たのは全て右に
        dp[m,m:] += (m+1) * prev[m+1,:N*N+1-m] # その点ごと全部右に。左に流す方をどれか残す
    dp %= MOD

if K&1:
    answer = 0
else:
    answer = dp[0,K//2]

print(answer)

Measured memory_bytes: 15024
#include <iostream>
#include <string>
#include <queue>
#include <utility>
//#include <>
using namespace std;

long long ans = 0, N;

void solve(long long x, int t, int f, int s){
    if(x > N) return;
    if(t*f*s)ans++;
    solve(x*10 + 7, t, f, s+1);
    solve(x*10 + 5, t, f+1, s);
    solve(x*10 + 3, t+1, f, s);
}

int main() {
    cin >> N;
    solve(0ll, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,i,a,b,c,d=1,s;
  char w;
  scanf("%d",&n);
  while(n--){
    scanf("%d\n",&m);
    s=3*m+2;
    d=1;
    for(i=0;i<4*m;i++){
      scanf("%c",&w);
      if(w=='N')a=1;
      else      a=0;
      if     (i==0)b=a;
      else if(i==2*m-1)c=a;
      else if(i==2*m){//printf("\n");
	if(a){
	  s--;
	  if(b)s--;
	}
      }
      else if(i==4*m-1){
	if(a){
	  s--;
	  if(c)s--;
	}
      }
      else{
	d*=a;
	if(i%2==0){
	  if(d)s--;
	  d=1;
	}
      }//printf("%c",w);
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int l = sc.nextInt();
        int sum = 0;
        int[] azi = new int[n];
        for(int i=0; i<n; i++){
            azi[i] = l+i;
          
        }
      
      if(l<0&&n+l>0||l==0){ 
        for(int i=0; i<n; i++){
            sum = sum + azi[i];
//          System.out.println(azi[i]);
        }
      }else if(l>0){
        for(int i=1; i<n; i++){
            sum = sum + azi[i];
//          System.out.println(azi[i]);
        }
      }else{
          for(int i=0; i<n-1; i++){
            sum = sum + azi[i];
//            System.out.println(azi[i]);
        }
      } 
        System.out.println(sum);
	}
}


Measured memory_bytes: 22868
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
      	char ss[] = new char[3];
      
      	if(s.length() == 3){
      		for(int i = 0; i < 3; i++) ss[i] = s.charAt(3-i-1);
          	for(int i = 0; i < 3; i++) System.out.print(ss[i]);
          	System.out.println();
        } else System.out.println(s);      	
        
	}
}

Measured memory_bytes: 35604
# https://atcoder.jp/contests/abc127/tasks/abc127_e
# 自分の計算画像を参考に
# ポイントは二点
# 1. 通りを決定してからpairwiseの和→pairを先に決定してから条件を満たす通りを加算 というΣの入れ替え
# 2. 二点の全通りの差を加算は無理→二点の差は何回現れるか を加算


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod), self.mod)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod), self.mod)
        else:
            return ModInt(pow(self.x, other, self.mod), self.mod)

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod), self.mod)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod), self.mod)
        else:
            return ModInt(pow(other, self.x, self.mod), self.mod)


def combination(n, r):
    # 上記のModIntを用いた通りの数の実装
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = ModInt(1)
    for i in range(r):
        nf = nf * (n - i)
        rf = rf * (i + 1)
    return nf / rf


N, M, K = map(int, input().split())
C = combination(N * M - 2, K - 2)
x_term = ModInt(0)
for dx in range(1, N):
    x_term += (N - dx) * dx
x_term *= M**2

y_term = ModInt(0)
for dy in range(1, M):
    y_term += (M - dy) * dy
y_term *= N**2

print(C * (x_term + y_term))


Measured memory_bytes: 72980
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans = 0;
  rep(cut, N - 1) {
    set<char> l;
    repp(i, 0, cut) { l.insert(S[i]); }
    set<char> r;
    repp(i, cut + 1, N - 1) { r.insert(S[i]); }

    int temp = 0;
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (l.find(ch) != l.end() && r.find(ch) != r.end()) temp++;
    }

    chmax(ans, temp);
  }
  cout << ans << endl;
}

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

typedef long long ll;
using namespace std;

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

	vector <int > diff;
	for(int i=0;i < n;i++){
		diff.push_back(a[i]-b[i]);
	}

	sort(diff.rbegin(), diff.rend());
	int sum = 0;
	int i=0;
	while(diff[i] > 0){
		sum += diff[i++];
	}

	cout << sum <<endl;

}

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

int main() {
  
  int ans = 0; int tmp = 10;
  
  for (int i = 0; i < 5; i++) {
    
    int d; cin >> d;
    
    if (d % 10 == 0) ans += d;
    
    else {
      tmp = min(tmp, d % 10);
      d = (d / 10 + 1) * 10;
      ans += d;
    }
    
  }
  
  cout << ans - 10 + tmp << endl;
  
}

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

int main(){
    int a, b, c, t;
    cin >> a >> b >> c;
    
    if (a>b){t=a;a=b;b=t;}
    if (b>c){t=b;b=c;c=t;}
    if (a>b){t=a;a=b;b=t;}
    
    cout << a << " " << b << " " <<c <<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

ll f( ll A, ll B ) {
  std::ostringstream oss1, oss2;
  oss1 << A;
  oss2 << B;

  return std::max( oss1.str().size(), oss2.str().size() );
}

int main()
{
  std::cin >> N;

  ll ans = INF;

  for( ll i = 1; i*i <= N; ++i ) if( N % i == 0 )
    chmin( ans, f( i, N/i ) ); 

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3564