akhauriyash/Code-Regression huggingface dataset:
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   char a;
   cin >> a;
   if(a>='A' and a<='Z'){
      cout << 'A';
   }else{
      cout << 'a';
   }
   return 0;
} 

Measured memory_bytes: 3644
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (s,t) = get!(String, String);
    let (a,b) = get!(usize, usize);
    let u = get!(String);
    if s==u {
        println!("{} {}", a-1,b);
    } else {
        println!("{} {}", a,b-1);
    }
}


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

int main() {
    int n,i,j;
    while(cin >> n,n){
        string s[n];
        int dot[n] = {};
        for (int i = 0; i < n;i++){
            cin >> s[i];
            for (j = 0; j < s[i].size();j++){
                if (s[i][j] == '.') dot[i]++;
            } 
        }
        for (i = 1; i < n + 10;i++){
            bool flag = false;
            for (j = n - 1; j >= 0;j--){
                if(dot[j]==i){
                    s[j][dot[j] - 1] = '+';
                    flag = true;
                }else if(dot[j]<i)
                    flag = false;
                else{
                    if(flag){
                        s[j][i - 1] = '|';
                    }
                }
            } 
        }
        for (i = 0; i < n;i++){
            for (j = 0; j < s[i].size();j++){
                if (s[i][j] == '.') s[i][j] = ' ';
                cout << s[i][j];
            }
            cout << endl;
        } 
    }
    return 0;
}



Measured memory_bytes: 3676
s=list(input().strip())

if int(s[0])+int(s[1])+int(s[2])+int(s[3])==7:
  print(s[0]+"+"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif int(s[0])-int(s[1])-int(s[2])-int(s[3])==7:
  print(s[0]+"-"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
elif int(s[0])+int(s[1])-int(s[2])-int(s[3])==7:
  print(s[0]+"+"+s[1]+"-"+s[2]+"-"+s[3]+"=7")
elif int(s[0])+int(s[1])+int(s[2])-int(s[3])==7:
  print(s[0]+"+"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif int(s[0])-int(s[1])+int(s[2])-int(s[3])==7:
  print(s[0]+"-"+s[1]+"+"+s[2]+"-"+s[3]+"=7")
elif int(s[0])-int(s[1])+int(s[2])+int(s[3])==7:
  print(s[0]+"-"+s[1]+"+"+s[2]+"+"+s[3]+"=7")
elif int(s[0])+int(s[1])-int(s[2])+int(s[3])==7:
  print(s[0]+"+"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
elif int(s[0])-int(s[1])-int(s[2])+int(s[3])==7:
  print(s[0]+"-"+s[1]+"-"+s[2]+"+"+s[3]+"=7")
else:
  print(-1)

Measured memory_bytes: 3192
#include <stdio.h>
int main(){
	
	int H;
	int A;
	
	scanf("%d %d", &H , &A);
	
	if(H%A == 0){
		printf("%d\n", H/A);
	}
	
	else 
	printf("%d\n", (H/A)+1);
	
	return 0;
	
}

Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int ck(int x,int n){
	int s=0;
	for(int i=0;i<n;i++){
		s+=(a[i]-1)/x;
	}
	return s;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int l=1,r=1e9,mid;
	while(l<r){
		mid=l+r>>1;
		if(ck(mid,n)<=k)r=mid;
		else l=mid+1;
	}
	printf("%d",r);
} 

Measured memory_bytes: 4428
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


int N;
int X[200001];
int Y[200001];
int X2[200001];
int Y2[200001];


signed main()
{
	cin >> N;
	REP(i, N) cin >> X[i] >> Y[i];
	//REP(i, N)
	//{
	//	X[i] += 1000000000;
	//	Y[i] += 1000000000;
	//}
	REP(i, N)
	{
		X2[i] = X[i] + Y[i];
		Y2[i] = X[i] - Y[i];
	}

	int min_x = LLONG_MAX;
	int max_x = LLONG_MIN;
	int min_y = LLONG_MAX;
	int max_y = LLONG_MIN;

	REP(i, N)
	{
		min_x = min(min_x, X2[i]);
		max_x = max(max_x, X2[i]);
		min_y = min(min_y, Y2[i]);
		max_y = max(max_y, Y2[i]);
	}

	cout << max(abs(min_x - max_x), abs(min_y - max_y));
}




Measured memory_bytes: 9848
#include <stdio.h>

#define INF 1000001
#define WHITE 0
#define BLACK 1
void dijkstra();
int c[100][100],d[100],color[100],pi[100],n;
int main(void){
int i,j,u,k,v;

scanf("%d",&n);
for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        c[i][j]=-1;
    }
}
for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
        scanf("%d",&v);
        scanf("%d",&c[u][v]);
    }
}
dijkstra();
for(i=0;i<n;i++){
printf("%d %d\n",i,d[i]);
}
return 0;
}
void dijkstra(){
    int i,mincost,v,u;
    for(i=0;i<n;i++){
        d[i] = INF;
        pi[i]=-1;
        color[i]=WHITE;
    }
    d[0]=0;
    while(1){
        mincost=INF;
        for(i=0;i<n;i++){
            if(color[i]!=BLACK && d[i] < mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost == INF) break;
        color[u]=BLACK;
        for(v=0;v<n;v++){
            if(color[v]!=BLACK && d[u]+c[u][v]<d[v] && c[u][v]>-1){
                pi[v] = u;
                d[v] = c[u][v] + d[u];
            }
        }
    }
}

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

struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) : par(N), rank(N) {
        for (int i = 0; i < N; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]) swap(rx, ry);
        par[ry] = rx;
        if (rank[rx] == rank[ry]) rank[rx]++;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

//Kruskalを適応したいが辺の数が多すぎるので減らす。
//x軸方向にソートして隣接している部分のみエッジを入れる
//y軸方向にソートして隣接つしている部分のみエッジを入れる
//こうすると，不必要なエッジを省ける。計算量はO(N)。

int main() {
    int N; cin >> N;
    using P = pair<int, int>;
    using Edge = pair<int, P>;
    vector<Edge> edges;
    vector<P> grids;
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        grids.push_back(P(x, y));
    }
    grids.erase(unique(grids.begin(), grids.end()), grids.end()); //重複ノードは消す
    //indexを保存
    map<P, int> idx;
    for (int i = 0; i < grids.size(); i++) {
        idx[grids[i]] = i;
    }

    //x軸方向にソートして隣接してるもののみエッジに組み込む
    sort(grids.begin(), grids.end());
    for (int i = 0; i < grids.size()-1; i++) {
        int a = grids[i].first, b = grids[i].second;
        int c = grids[i+1].first, d = grids[i+1].second;
        int cost = min(abs(a-c), abs(b-d));
        edges.push_back(Edge(cost, P(idx[grids[i]], idx[grids[i+1]])));
        edges.push_back(Edge(cost, P(idx[grids[i+1]], idx[grids[i]])));
    }
    //y軸方向も同様
    sort(grids.begin(), grids.end(), [](P a, P b) {
        return a.second < b.second;
    });
    for (int i = 0; i < grids.size()-1; i++) {
        int a = grids[i].first, b = grids[i].second;
        int c = grids[i+1].first, d = grids[i+1].second;
        int cost = min(abs(a-c), abs(b-d));
        edges.push_back(Edge(cost, P(idx[grids[i]], idx[grids[i+1]])));
        edges.push_back(Edge(cost, P(idx[grids[i+1]], idx[grids[i]])));
    }

    //Kruskal
    sort(edges.begin(), edges.end());
    UnionFind uf(grids.size());
    ll res = 0;
    for (auto e : edges) {
        int u = e.second.first, v = e.second.second;
        if (uf.same(u, v)) continue;
        uf.unite(u, v);
        res += e.first;
    }
    cout << res << endl;
}

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

int Euclid_gcd(int x,int y){
    if(x<y) swap(x,y);
    while(y>0){
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int x,y;
    cin >> x >> y;
    //cout << __gcd(x,y) << endl;
    cout << Euclid_gcd(x,y) << endl;
    return 0;
}


Measured memory_bytes: 3084
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    int i = 0;
    while(7 * i <= N) {
        int r = N - 7 * i;
        int j = 0;
        while(4 * j <= r) {
            if (4 * j == r) {
                print("Yes");
                return 0;
            }
            ++j;
        }

        ++i;
    }

    print("No");

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    dic = defaultdict(lambda: 0)
    count = 0
    for _ in range(n):
        s = input()
        dic[s] += 1
        count = max(count, dic[s])

    candidates = []
    for key in dic.keys():
        if dic[key] == count:
            candidates.append(key)

    candidates.sort()
    for c in candidates:
        print(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 97624
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M;
	int ans = 0;
	vector<pair<int,int>> in;
	// priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;
	priority_queue<pair<int,int>> Q;
	
	cin>>N>>M;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].first>>in[i].second;
		// in[i].second *= -1;
	}
	
	sort(in.begin(), in.end());
	
	// cout<<"<><>< "<<endl;
	// for(pair<int,int> x : in){
		// cout<<x.first<<" "<<x.second<<endl; 
	// }
	
	for(int i = 1, j = 0; i <= M; i++){
		
		for(; j < in.size(); j++){
			if(in[j].first > i) break;
			Q.push(make_pair(in[j].second,0));
		}
		
		if(Q.size()){
		pair<int,int> p = Q.top();Q.pop();
		ans += p.first;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

//106_C

string S;
int k;

int main(){
    cin>>S;
    cin>>k;
    for(int i=0;i<k;i++){
        if(S[i]-'0'>1){
            cout<<S[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
long long int s[100005];
int main() {
	for (int i = 1; i <= 10000; i++) if (i*i+2*i>10000) break;
		else for (int j = i; j <= 10000; j++) if (j*j+i*i+i*j+i+j>10000) break;
			else for (int k = j; k <= 10000; k++) {
				if (i*i+j*j+k*k+i*j+i*k+j*k>10000) break;
				else {
					if (i == j && j == k) s[i*i+j*j+k*k+i*j+i*k+j*k]++;
					else if (i == j || j == k) s[i*i+j*j+k*k+i*j+i*k+j*k]+=3;
					else s[i*i+j*j+k*k+i*j+i*k+j*k]+=6;
				}
			}
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) cout << s[i] << endl;
	return 0;
}

Measured memory_bytes: 3768
//LETS START AGAIN
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    map<int,int> mp;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    vector<pii> vp;
    priority_queue<pii> pq;
    for(auto it:mp)
    {
        pq.push({it.second,it.first});
    }
    while(!pq.empty())
    {
        vp.push_back(pq.top());
        pq.pop();
    }
    int ans = n;
   /* for(auto it:vp)
    {
        cout<<it.second<<" "<<it.first<<endl;
    }*/
    for(int i=0;i<vp.size()-1;i++)
    {
        int x = vp[i].second;
        int cnt = vp[i].first;
        if(cnt%2==0 && cnt>=2)
        {
            vp[i+1].first--;
            ans-=cnt;
        }
        else if(cnt%2 && cnt>=3)
        {
            ans-=(cnt-1);
        }
    }
    int cnt = vp[vp.size()-1].first;
    int x = vp[vp.size()-1].second;
    if(cnt>1)
    {
        if(cnt%2==0)
            ans-=cnt;
        else
        {
            ans-=(cnt-1);
        }
    }
    cout<<ans;
} 



Measured memory_bytes: 11124
#include <iostream>
#include <utility>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(void){

  pair<double, double> p0, p1, p;
  pair<double, double> ans;
  int n;
  cin >> p0.first >> p0.second >> p1.first >> p1.second;
  cin >> n;

  while(n--){
    cin >> p.first >> p.second;
    double a;
    if(p1.second - p0.second == 0){
      ans.first = p.first;
      ans.second = p1.second;
    }else if(p1.first - p0.first == 0){
      ans.first = p1.first;
      ans.second = p.second;
    }else{
      a = (p1.second - p0.second) / (p1.first - p0.first);
      ans.first = (a / (a*a + 1) ) * (-p0.second + p.second + a*p0.first + p.first/a);
      ans.second = (-1/a) * (ans.first - p.first) + p.second;
    }
    printf("%.10f ", ans.first);
    printf("%.10f", ans.second);
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
lista = [1, 3, 5, 7, 8, 10, 12]
lista2 = [4, 6, 9, 11]
x, y = map(int, input().split())
if x in lista and y in lista:
    print('Yes')
elif x in lista2 and y in lista2:
    print('Yes')
elif x == 2 and y == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};



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

    int n,m;
    cin >> n >> m;
    vector<pair<int,char>> sc(m);
    rep(i,m){
        int x;
        char y;
        cin >> x >> y;
        sc[i] = make_pair(x,y);
    }
    ll ans = INF;
    for(int i = 1;i < 1000;++i){
        bool f = true;
        string s = to_string(i);
        rep(j,m){
            if(s[sc[j].first-1] != sc[j].second){
                f = false;
            }
        }
        if(f) {
            ans = i;
            if(s.length() == n) break;
            else {
                ans = INF;
                continue;
            }
        }
    }
    if(n == 1) {
        bool flag = true;
        rep(i,m){
            if(sc[i].second != '0') {
                flag = false;
            }
        }
        if(flag) {
            cout << 0 << endl;
            return 0;
        }
    }
    if(ans == INF) cout << -1 << endl;
    else cout<< ans << endl;
    cout << endl;
    return 0;
}


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

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    ll araiguma = accumulate(a.begin(),a.end(),0LL);
    ll sunuke = 0, ans = 1e18;
    for(int i = 0; i < n-1; i++){
        sunuke += a[i];
        araiguma -= a[i];
        ans = min(ans, abs(sunuke - araiguma));
    }
    put(ans);
}

Measured memory_bytes: 4836
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	ll x;
	cin >> x;
	cout << (x / 500) * 1000 + (x % 500) / 5 * 5;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll xor_sum(ll num)
{
    switch(num%4)
    {
        case 0:
            return num;
        case 1:
            return 1;
        case 2:
            return num^1;
        case 3:
            return 0;
    }
}
int main()
{
    ll a, b;
    cin >> a >> b;
    ll ans = xor_sum(a-1) ^ xor_sum(b);
    cout << ans << "\n";    
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
	char ch;
	int num;
} card;

card temp,output1[37],output2[37];
int N;

void bubble();
void select();

int main(void){
	int i,j,cnt=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf(" %c%d",&output1[i].ch,&output1[i].num);
		output2[i]=output1[i];
	}
	bubble();
	select();
	for(i=0;i<N;i++){
		if(output1[i].ch==output2[i].ch) cnt++;
	}
	for(i=0;i<N;i++){
		printf("%c%d",output1[i].ch,output1[i].num);
		if(i!=N-1) printf(" ");
		if(i==N-1) printf("\n");
	}
	puts("Stable");
	for(i=0;i<N;i++){
		printf("%c%d",output2[i].ch,output2[i].num);
		if(i!=N-1) printf(" ");
		if(i==N-1) printf("\n");
	}
	if(cnt==N)	puts("Stable");
	else	puts("Not stable");
	return 0;
}

void bubble(){
	int i,j;
	for(i=0;i<N;i++){
		for(j=N-1;j>i;j--){
			if(output1[j-1].num>output1[j].num){
				temp=output1[j-1];
				output1[j-1]=output1[j];
				output1[j]=temp;
			}
		}
	}
	return ;
}

void select(){
	int mini,i,j;
	for(i=0;i<N;i++){
		mini=i;
		for(j=i;j<N;j++){
			if(output2[j].num<output2[mini].num) mini=j;
		}
		temp=output2[i];
		output2[i]=output2[mini];
		output2[mini]=temp;
	}
	return ;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#pragma comment(linker, "/STACK:16000000")
//#define map gp_hash_table
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
namespace Geometry{
	struct point{
		double x;double y;
		void print(){
			printf("Point:x:%.8lf,y:%.8lf",x,y);
		}
	};
	struct line{
		double x;double c;
		void print(){
			printf("Line:x:%.8lf,c:%.8lf\n",x,c);
		}
	};
	line make_line(point a,point b){
		double x=(a.x-b.x)/(a.y-b.y);
		double c=a.y-(a.x)*(x);
		return (line){x,c};
	}
}
#define int long long
using namespace Geometry;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
const int MAX_N=1e6;
struct BIT{
	int bit[MAX_N+1],BITN=1e6;
	//sum a[1,i]
	void init1(){
		for(int i=0;i<MAX_N;i++)bit[i]=0;
	}
	void init(vector<int> v){
		for(int i=0;i<v.size();i++)add(i+1,v[i]);
	}
	int sum(int i){
		int s=0;
		while(i>0){
			s+=bit[i];
			i=(i)&(i-1);
		}
		return s;
	}
	//a[i]+=x
	void add(int i,int x){
		while(i<=BITN){
			bit[i]+=x;
			i+=(i)&(-i);
		}
	}
}bit;
int n;
int a[111111];
int cmp[111111];
int pre[111111];
bool check(int x){
	bit.init1();
	int sum=0;
	memset(pre,0,sizeof(pre));
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]>=x?1:-1);
	for(int i=0;i<=n;i++){
		sum+=bit.sum(pre[i]+5e5);
		bit.add(pre[i]+5e5,1);
	}
	return sum>=1ll*(n+1)*n/4;
}
signed main(){
	scanf("%d",&n);
	if(n==1){
		int x;
		cin>>x;
		cout<<x<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int l=-1,r=2e9;
	while(r-l>1){
		int mid=l+r>>1;
		bool data=check(mid);
		if(data)l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}
/*
10
5 9 5 9 8 9 3 5 4 3
*/


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

int main(){
 int n,ch=0,i;
 string s;
 cin >> n;
 for(i=0;i<n;i++){
  cin >> s;
  if(s=="A")ch++;
  else ch--;
  if(ch<0){
   cout << "NO" << endl;
   return 0;
  }
 }
 if(ch==0)cout << "YES" << endl;
 else cout << "NO" << endl;
 return 0;
} 


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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

multiset<int> ss;
int n, m;
int l, r;
vector<int> go[210000];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> r >> l;
        go[l].push_back(r);
    }
    int ans = 0;
    for (int it = 0; it < 5; ++it) {
        for (int i = 0; i <= m + 1; ++i) {
            for (int j: go[i])
                ss.insert(j);
            go[i].clear();
            if (i >= 1 && i <= m) {
                auto it = ss.lower_bound(i);
                int x = -1;
                if (it != ss.end()) {
                    x = *it;
                }
                else if (!ss.empty()) {
                    x = *ss.begin();
                    it = ss.begin();
                }
                if (x != -1) {
                    go[i].push_back(x);
                    ss.erase(it);
                }
            }
            ans += ss.count(i);
            ss.erase(i);
        }
    }
    ans += ss.size();
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 15488
from itertools import permutations 
inf=10**9
n, m, r1 = map(int, input().split())
r=list(map(int, input().split()))
abc=[list(map(int, input().split())) for _ in range(m)]
d=[[inf]*n for i in range(n)]
for ai, bi, ci in abc:
    d[ai-1][bi-1]=ci
    d[bi-1][ai-1]=ci
for k in range(n):
    for i in range(n-1):
        for j in range(i, n):
            dk=d[i][k]+d[k][j]
            if d[i][j]>dk:
                d[j][i]=dk
                d[i][j]=dk
permutations(r)
ans=inf
p=list(permutations(r))
for pi in p:
    res=0
    for i in range(r1-1):
        res+=d[pi[i]-1][pi[i+1]-1]
    if ans>res:
        ans=res
print(ans)

Measured memory_bytes: 13108
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n, x, y;
    cin >> n >> x >> y;

    vector<int> ans(n);
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            int d = min({j-i, abs(x-i)+abs(y-j)+1});
            ans[d]++;
        }
    }

    for(int i=1; i<n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  string ans;
  for(int i = 0; i < 3; ++i){
    string s;cin >> s;
    ans += s[i];
  }
  cout << ans << endl;
}


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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)

int main() {
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  REP(i, N) {
    cin >> V[i];
  }
  REP(i, N) {
    cin >> C[i];
  }
  int ans = 0;
  REP(i, N) {
    if(V[i] - C[i] > 0) {
      ans += V[i] - C[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gc() getchar()
using namespace std;
const int N = 4010;
int sta[N],top,a,b,ans[N],t,n;
bool ask(int x,int y) {
  static char tmp;
  printf("? %d %d\n",x,y);
  fflush(stdout);
  for (tmp = gc() ; tmp != 'Y' && tmp != 'N' ; tmp = gc());
  return (tmp == 'Y');
}
int main() {
  scanf("%d%d",&a,&b);
  if (a <= b) return 0 * puts("Impossible\n");
  n = a + b;
  for (int i = 0 ; i < n ; ++ i) {
    if (!top) sta[++top] = i;
    else {
      if (ask(sta[top],i))
        sta[++top] = i;
      else top--;
    }
  }
  t = sta[top];
  for (int i = 0 ; i < n ; ++ i)
    ans[i] = ask(t,i);
  printf("! ");
  for (int i = 0 ; i < n ; ++ i)
    printf("%d",ans[i]);
  puts("");
  return 0;
}

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

class DICE_MODEL
{

public:
    int l1, l2, l3, l4, l5, l6;

    DICE_MODEL()
    {
        std::cin >> l1 >> l2 >> l3 >> l4 >> l5 >> l6;
    }

    DICE_MODEL(DICE_MODEL& dice)
    {
        l1 = dice.l1;
        l2 = dice.l2;
        l3 = dice.l3;
        l4 = dice.l4;
        l5 = dice.l5;
        l6 = dice.l6;
    }

    void turnNorth()
    {
        int temp = l2;
        l2 = l6;
        l6 = l5;
        l5 = l1;
        l1 = temp;
    }

    void turnEast()
    {
        int temp = l4;
        l4 = l6;
        l6 = l3;
        l3 = l1;
        l1 = temp;
    }

    void turnSouth()
    {
        int temp = l5;
        l5 = l6;
        l6 = l2;
        l2 = l1;
        l1 = temp;
    }

    void turnWest()
    {
        int temp = l3;
        l3 = l6;
        l6 = l4;
        l4 = l1;
        l1 = temp;
    }

    void turnClock()
    {
        int temp = l2;
        l2 = l3;
        l3 = l5;
        l5 = l4;
        l4 = temp;
    }

    void turnCounterClock()
    {
        int temp = l2;
        l2 = l4;
        l4 = l5;
        l5 = l3;
        l3 = temp;
    }

    void printTop()
    {
        std::cout << l1 << std::endl;
    }

    void printRight()
    {
        std::cout << l3 << std::endl;
    }
};

int main()
{
    DICE_MODEL dice;

    int num;
    std::cin >> num;

    int top, fwd;
    DICE_MODEL tempDice(dice);
    for (int i = 0; i < num; i++)
    {
        std::cin >> top >> fwd;

        if      (dice.l1 == top) ;
        else if (dice.l2 == top) dice.turnNorth();
        else if (dice.l3 == top) dice.turnWest();
        else if (dice.l4 == top) dice.turnEast();
        else if (dice.l5 == top) dice.turnSouth();
        else
        {
            dice.turnNorth();
            dice.turnNorth();
        }

        if      (dice.l2 == fwd) ;
        else if (dice.l3 == fwd) dice.turnClock();
        else if (dice.l4 == fwd) dice.turnCounterClock();
        else
        {
            dice.turnClock();
            dice.turnClock();
        }

        dice.printRight();
        
        dice = tempDice;
    }
}


Measured memory_bytes: 3092
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t,w,q;main(){for(;;){scanf("%d",&n);if(!n)break;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);scanf("%d",&m);for(i=0;i<m;i++)scanf("%d%d",&c[i],&d[i]);for(i=0;i<m;i++){w=c[i]-a[0];q=d[i]-b[0];for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+w==c[k]){if(b[j]+q==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",w,q);t=0;break;}t=0;}}return 0;} 

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
ll a[N];ll p;int n;
ll b[N];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>p;
	ll ans=0;
	for(int i=1;i<=n;i++){
	cin>>a[i]>>b[i];}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);	
	for(int i=n;i>=1;i--){
		if(b[i]<=a[n]) break;
		ans++;p-=b[i];
		if(p<=0){
			cout<<ans<<endl;return 0;
		}
	}
	if(p%a[n]==0) ans+=(p/a[n]),cout<<ans<<endl;
	else ans+=(p/a[n]+1),cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0075
"""
import sys


def is_overweight(weight, height):
    bmi = weight / height**2
    if bmi >= 25.0:
        return True
    else:
        return False


def main(args):
    result = []
    for line in sys.stdin:
        id, weight, height = [float(x) for x in line.strip().split(',')]
        # print(id, weight, height)
        if is_overweight(weight, height):
            result.append(int(id))

    for id in result:
        print(id)

if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7484
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(){
  long N, M, X, C[20], A[20][20], i, j, k, num = 1, c, a[20], ans = -1;
  scanf("%ld %ld %ld", &N, &M, &X);
  for (i = 0; i < N; i++) {
    scanf("%ld", C + i);
    for (j = 0; j < M; j++) {
      scanf("%ld", A[i] + j);
    }
  }
  for (i = 0; i < N; i++) num *= 2;
  for (i = 1; i < num; i++) {
    c = 0;
    for (j = 0; j < M; j++) a[j] = 0;

    for (j = 0; j < N; j++) {
      if (i & (1 << j)) {
        c += C[j];
        for (k = 0; k < M; k++) a[k] += A[j][k];
      }
    }
    for (j = 0; j < M; j++) if (a[j] < X) break;
    if (j == M) {
      if (ans == -1 || ans > c) ans = c;
    }
  }
  printf("%ld", ans);
  return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

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

int a,b,c;
int main(void) {
    string s;
    cin >> s;
    REP(i, s.size()){
        if(s[i]=='a'){
            a = 1;
        }else if(s[i]=='b'){
            b = 1;
        }else if(s[i]=='c'){
            c = 1;
        }
    }
    if(a==1 && b==1 && c==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    int n,ai;
    cin>>n;
    int ans=1,t=1;
    rep(i,n){
        cin>>ai;
        t*=3;
        if(ai%2==0) ans*=2;
    }
    cout<<t-ans<<endl;
    return 0;
}

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

struct Output {
	int tag,a,b,c;
}o[202020];
int tail = 0;
int base = 100000;
int st = 200;
inline void Add(int A,int B,int C) {
	tail++;
	o[tail].tag = 0;
	o[tail].a = A;
	o[tail].b = B;
	o[tail].c = C;
}

inline void cmp(int A,int B,int C) {
	tail++;
	o[tail].tag = 1;
	o[tail].a = A;
	o[tail].b = B;
	o[tail].c = C;
}

inline void Mul(int A,int B,int C) {
	base++;
	Add(base,A,base);
	for (int i = 1;i <= B; i++) {
		Add(base,base,base+1);
		base++;
	}
	Add(base+1,base,C);
}

int main() {
	//freopen("1.out","w",stdout);
	Add(0,1,++st);
	cmp(st+1,st,st+1);
	st++;
	Add(st+1,st,8);
	st++;
	for (int i = 0;i < 60; i++)
		Add(8+i,8+i,8+i+1);
	Add(0,8,5);
	for (int i = 30;i >= 0; i--) {
		Add(4,8+i,4);
		cmp(4,5,++st);
		int stmp = st;
		Mul(st,i,st+1);
		++st;
		Add(3,st,3);
		Add(3,st+1,4);
		Mul(1,i,st+1);
		++st;
		Add(st,8,st+1);
		++st; 
		int tmp2 = st;
		Add(st+1,st+1,6);
		Add(st+1,st+1,7);
		for (int j = 60;j >= 0; j--) {
			Add(7,8+j,7);
			cmp(7,tmp2,++st);
			int tmp3 = st;
			Add(stmp,tmp3,++st);
			cmp(8,st,st+1);
			++st;
			Mul(st,j,st+1);
			++st;
			Add(st,6,6); 
			Add(6,st+1,7);
		}
		Add(2,6,2);
	} 
	printf("%d\n",tail);
	for (int i = 1;i <= tail; i++) {
		if (o[i].tag == 0)
			printf("+ ");
		else
			printf("< ");
		printf("%d %d %d\n",o[i].a,o[i].b,o[i].c);
	}
	return 0;
}

Measured memory_bytes: 4780
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";

	static int count(int r1, int c1, int r2, int c2)
	{
		out.printf("? %d %d %d %d\n", r1, c1, r2, c2);
		out.flush();
		return ni();
	}
	
	static void end(boolean[][] map, int mod)
	{
		long h = 0;
		long t = 1;
		for(int i = 0;i < map.length;i++){
			for(int j = 0;j < map[0].length;j++){
				h += (map[i][j] ? 1 : 0) * t;
				h %= mod;
				t = t * 2 % mod;
			}
		}
		out.println("! " + h);
		out.flush();
	}
	
	static void solve()
	{
		int h = ni(), w = ni(), n = ni(), K = ni();
		boolean[][] map = new boolean[h][w];
		for(int i = 0;i < h;i+=2){
			for(int j = 0;j < w;j+=2){
				int lc = count(i, j, i+1, j+1);
				if(lc == 0)continue;
				if(lc == 4){
					for(int k = 0;k < 2;k++){
						for(int l = 0;l < 2;l++){
							map[i+k][j+l] = true;
						}
					}
					continue;
				}
				if(lc == 1){
					int llc = count(i, j, i+1, j);
					int q = llc^1;
					int lruc = count(i, j+q, i, j+q);
					map[i+(lruc^1)][j+q] = true;
					continue;
				}
				if(lc == 3){
					for(int k = 0;k < 2;k++){
						for(int l = 0;l < 2;l++){
							map[i+k][j+l] = true;
						}
					}
					int llc = count(i, j, i+1, j);
					int q = 2-llc^1;
					int lruc = count(i, j+q, i, j+q);
					map[i+(1-lruc^1)][j+q] = false;
					continue;
				}
				for(int k = 0;k < 2;k++){
					for(int l = 0;l < 2;l++){
						map[i+k][j+l] = count(i+k, j+l, i+k, j+l) == 1;
					}
				}
			}
		}
		end(map, K);
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 20420
N = raw_input()

digit_num = len(str(N))
digit_counter = 2
minus_val = 0

while True:
  if digit_counter >= digit_num:
    if digit_num % 2 == 0:
      minus_val += (int(N) - pow(10, digit_num - 1) + 1)
    break
  minus_val += 9 * pow(10, digit_counter - 1)
  digit_counter += 2

print int(N) - minus_val

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

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

    map<string, long> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    
    long long cnt = 0;
    for (auto& kv : mp) {
        cnt += kv.second * (kv.second - 1) / 2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 11136
n,m=map(int,input().split())
a={int(input()) for _ in range(m)}
mod=10**9+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
      dp[1]=1
for i in range(2,len(dp)):
      if i not in a:
            dp[i]=dp[i-1]+dp[i-2]
      
print(dp[-1]%mod)

Measured memory_bytes: 460020
N = int(input())
A = list(map(int, input().split()))

SUM_A = A[0]
rev = -1
for i in range(N - 2):
    SUM_A += rev*A[i+1]
    rev *= -1

X = [0]*N

X[0] = SUM_A + A[N-1]
for i in range(1, N):
    X[i] = 2 * A[i - 1] - X[i - 1]
print(*X)

Measured memory_bytes: 64356
#include <stdio.h>

int main(){
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n", d, r, f);
    return 0;
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e4+5;
int dp[N][100][2];
const int mod = 1e9+7;
int32_t main()
{
	string str;
	cin>>str;
	int d;
	cin>>d;
	for(int i=0;i<str[0]-'0';i++)
		dp[0][i%d][0] += 1;
	dp[0][(str[0]-'0')%d][1] = 1;

	for(int i=1;i<str.size();i++)
	{
		for(int j=0;j<d;j++)
		{
			for(int k=0;k<10;k++){
				dp[i][(j+k)%d][0] = (dp[i][(j+k)%d][0] + dp[i-1][j][0])%mod;
				if(k < str[i]-'0')
					dp[i][(j+k)%d][0] = (dp[i][(j+k)%d][0] + dp[i-1][j][1])%mod;
			}

			dp[i][(j + str[i]-'0')%d][1] = (dp[i][(j + str[i]-'0')%d][1] + dp[i-1][j][1])%mod;

		}
	}

	cout<<(dp[str.size()-1][0][0] + dp[str.size()-1][0][1]-1 + mod)%mod;

}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B;
    int ans;
    cin >> A >> B;
    ans = max(((A*25+1)/2),(B*10));
    if ((ans*2/25==A) && (ans/10==B)) cout << ans << endl;
    else cout << -1 << endl;
}

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

int main(){
    string a ,c;
    a = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int b,i,d,m;
    cin >> m >> c;
    b = c.size();
    d = 0;
    while(b  > d){
        while(i <= 26){
            if(c.at(d) == a.at(i)){
                cout << a.at(i+m);
                break;
                
            }
            i = i + 1;
        }
        d = d + 1;
        i = 0;
    }
    cout << endl;




}

Measured memory_bytes: 256
from queue import Queue

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
#%%
q = Queue()

dist = [[10**5]*W for _ in range(H)]

dx = [0,1]
dy = [1,0]
c = 0
f = 0
if S[0][0]=='#':
    c = 1
    f = 1
q.put([c,f,0,0])
while not(q.empty()):
    c,f,x,y = q.get()
    for i in range(2):
        nc = c
        nx = x+dx[i]
        ny = y+dy[i]
        if nx>=H or ny>=W:
            continue
        
        if f==0 and (S[nx][ny]=='#'):
            nc = c+1
        
        if nc < dist[nx][ny]: 
            dist[nx][ny] = nc
            nf = S[nx][ny]=='#'
            q.put([nc,nf,nx,ny])
        
print(dist[H-1][W-1])
        
    

Measured memory_bytes: 65620
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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 T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int ans = 0;
    REP(i,4){
        char a; cin >> a;
        if(a=='+')ans++;
        else ans--;
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int h, w;

		Scanner stdIn = new Scanner(System.in);

		while (true) {

			h = stdIn.nextInt();
			w = stdIn.nextInt();

			if((h+w) == 0) {
				System.exit(0);
			}

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					System.out.print('#');
				}
				System.out.println();
			}
			System.out.println();
		}

	}

}

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

int main() {
  int N, x, y;
  cin >> N;
  y = 0;
  vector<int> button(N);
  
  for (int i = 0; i<N; i++) {
    cin >> button.at(i);
  } 
  
  for (int j = 1; j <= N; j++) {
    x = button.at(y);
    if (x==2) {
      cout << j << endl;
      break;
    }
    y=x-1;
    if (j==N) cout << "-1" << endl;
  }
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main(){
    int N, K, R, S, P;
    cin >> N >> K >> S >> P >> R;
    string T;
    cin >> T;
    int res = 0;
    for(int i = 0; i < K; i++) {
        int flag = 0;
        for(int j = i; j < T.size(); j+=K) {
            if(flag) {
                if(T[j] == T[j-K]) {flag = 0; continue;}
            }
            flag = 1;
            if(T[j] == 'r') res += R;
            else if (T[j] == 's') res += S;
            else if(T[j] == 'p') res += P;
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int S, W;
	cin >> S >> W;

	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

	return 0;
}


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

const int N = (int) 1e5 + 5;

int n;
int h[N];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> h[i];
	h[1]--;
	for (int i = 2; i <= n; i++) {
		if (h[i] > h[i - 1]) {
			h[i]--;
		}
	}
	bool ok = true;
	for (int i = 1; i < n; i++)
		if (h[i] > h[i + 1]) {
			ok = false;
			break;
		}
	if (ok) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3944