akhauriyash/Code-Regression huggingface dataset:
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(lambda x: int(x) - 1, input().split())
    lr[l][r] += 1

for i in range(n):
    for j in range(1, n):
        lr[i][j] += lr[i][j-1]

for i in range(1, n):
    for j in range(n):
        lr[i][j] += lr[i-1][j]

for _ in range(q):
    p, q = map(lambda x: int(x) - 1, input().split())
    if p == 0:
        print(lr[q][q])
    else:
        print(lr[q][q]-lr[p-1][q]-lr[q][p-1]+lr[p-1][p-1])


Measured memory_bytes: 14940
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(string s)
{
  KAKA
    ll n = s.length();
    ll count = 0;
    pragi(0,n/2)
    {
        if(s[i] != s[n-i-1])
        count++;
    }
    cout<<count<<"\n";
}
int main()
{
    KAKA
    string s;
    cin>>s;
    Compute(s);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;

#define  PI 3.141592653589793238
ll T,n,m;
int main() {
	double a,b,x;
	cin>>a>>b>>x;
	if(x>(a*b*a)/2){
		double t = ((2*x)/(a*a))-b;
		t = b-t;
		double p =atan2(t,a);
		printf("%.10lf",p*180/PI);
	}
	else {
		double t = (2*x/a)/b;
		double p = atan2(b,t);
		printf("%.10lf",p*180/PI);
	}

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int maxn = 7e2 + 10;
using namespace std;

int g[maxn][maxn];
int n, m, T, kase = 1, flag;
int col[maxn], vis[maxn];
int dp[maxn][maxn];
int x[maxn], y[maxn], cnt[2]; 

void dfs(int u, int c) {
	col[u] = c; vis[u] = 1;	cnt[c]++;
	for(int i = 1; i <= n; i++) {
		if(g[u][i]) continue;
		if(!vis[i]) dfs(i, c ^ 1);
		else { if(col[i] == c) flag = -1; }
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m;
	while(m--) {
		int u, v;
		cin >> u >> v;
		g[u][v] = g[v][u] = 1;
	}
	int tot = 1;
	for(int i = 1; i <= n; i++) g[i][i] = 1;
	for(int i = 1; i <= n; i++) {
		if(vis[i]) continue;
		cnt[0] = cnt[1] = 0;
		dfs(i, 0);
		x[tot] = cnt[0]; y[tot] = cnt[1];
		tot++;
	}
	if(flag == -1) { cout << flag << endl; return 0; }
	dp[0][0] = 1;
	for(int i = 1; i < tot; i++) {
		for(int j = 0; j < n; j++) {
			if(dp[i - 1][j]) {
				dp[i][j + x[i]] = 1;
				dp[i][j + y[i]] = 1;
			}
		}
	}
	int ans = n * n;
	for(int i = 0; i <= n; i++) {
		if(!dp[tot - 1][i]) continue;
		ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str[30];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int len=strlen(str);
    if(len<26) {
        int cnt[26]={0};
        int i;
        for(i=0; i<len; i++) {
            cnt[str[i]-'a']++;
        }
        for(i=0; i<26; i++) {
            if(cnt[i]==0) {
                str[len]='a'+i;
                printf("%s\n", str);
                return 0;
            }
        }
    }
    else {
        char str2[30]={0};
        strcpy(str2, str);
        if(next_permutation(str2+0, str2+26)) {
            int i;
            for(i=0; i<26; i++) {
                if(str[i]!=str2[i]) {
                    str2[i+1]='\0';
                    break;
                }
            }
            printf("%s\n", str2);
        }
        else {
            printf("-1\n");
        }

    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define N 1005
#define MOD 1000000007
using namespace std; 

ll dp[N][N]; 
char g[N][N];  
int H, W; 


ll number_ways(int x, int y){
	if(g[x][y] == '#' || x == H || y == W ){
		return 0; 
	}

	if((x == H - 1 && y == W - 1)){
		return 1; 
	}

	if(dp[x][y] != -1){
		return dp[x][y]; 
	}

	dp[x][y] = (number_ways(x + 1, y) + number_ways(x, y + 1)) % MOD; 
	return dp[x][y]; 
	
}

int main(){
	cin >> H >> W;

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			dp[i][j] = -1; 
			cin >> g[i][j]; 
		}
	}


	cout << number_ways(0, 0) << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps (1e-8)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int a;cin>>a;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(a==i*j){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    long h;
    scanf("%ld", &h);
    int a = log(h) / log(2) + 1;
    printf("%ld\n", (long)(pow(2, a) - 1));
    return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  cin >> S;
  bool flg = false;
  rep(i, 3){
    flg = flg or S[i]==S[i+1];
  }
  if(flg)cout << "Bad";
  else cout << "Good";
  return 0;
}


Measured memory_bytes: 256
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
x=int(n/1.08)
for i in range(x-100,x+100):
    if int(i*1.08)==n:
        print(i)
        exit()
print(":(")

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using namespace std;


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

	if(N < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;

	return 0;
}

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

using namespace std;

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

	int s, w;
	cin >> s >> w;

	if (s > w) {
		cout << "safe\n";
	}
	else {
		cout << "unsafe\n";
	}
	return 0;
}

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


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

    int N,K,Q;
    cin >> N >> K >> Q;
    int array[N] = {};

    for (int i=0; i<Q; i++){
        int A;
        cin >> A;
        array[A-1]++;
    }

    for (int i=0; i<N; i++){
        int P = Q-array[i];
        if (K-P > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

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

int main() {
  int N, X, T, n;
  cin >> N >> X >> T;
  n = (N + X - 1) / X;
  cout << n * T << endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	sort(ALL(s));
	if (s == "abc")cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;
const int mod = 1e9+7;
const int limit=50;
string s, t;

bool match(int k) {
  for(int i = 0; i < t.size(); i++) {
    if(t[i] != s[i+k] && s[i+k] != '?') return false;
  }
  return true;
}

string construct(int k) {
  string ans = s;
  for(int i = 0; i < t.size(); i++) {
    ans[k+i] = t[i];
  }
  for(int i = 0; i < s.size(); i++) {
    if(ans[i] == '?') ans[i] = 'a';
  }
  return ans;
}

int main() {
  cin >> s >> t;
  string ans;
  int k = -1;
  for(int i = 0; i < s.size() - t.size() + 1; i++) {
    if(match(i)) k = i;
  }
  if(k==-1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    ans = construct(k);
    cout << ans << endl;
  }
  return 0;
}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    int ans = 0;
    int rank = 0;
    for (int i = 100; i >= 1; i--) {
        if (A%i==0 & B%i==0) rank++;
        if (rank==K) { ans = i; break; }
    }

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



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <math.h>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll H, W; cin >> H >> W;
	char m[50][50] = {};
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> m[i][j];
		}
	}
	ll x[4] = { 1,0,0,-1 };
	ll y[4] = { 0,1,-1,0 };
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (m[i][j] == '#') {
				bool ok = false;
				rep(k, 0, 4) {
					ll n_i = i - x[k];
					ll n_j = j - y[k];

					if (n_i >= 0 && n_i < H && n_j >= 0 && n_j < W) {
						if (m[n_i][n_j] == '#') {
							ok |= true;
						}
					}
				}
				if (!ok) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int max1=-99999,ans=0,n;
int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='I')
		{
			ans++;
		}
		if(s[i]=='D')
		{
			ans--;
		}
		max1=max(max1,ans);
	}
	if(max1<=0)
	{
		cout<<"0"<<endl;
	}
	else
	{
	cout<<max1<<endl;	
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int MAXN=3e5+5;
const int BASE=3137;
const int MOD1=1e9+7;
const int MOD2=1e9+9;
int N;
char s[MAXN];
pii pref[MAXN],pot[MAXN];
map<pii,int>cnt;

inline int add(int x,int y,int mod){
	x+=y;
	if(x>=mod)
		x-=mod;
	else if(x<0)
		x+=mod;
	return x;
}

inline int mul(int x,int y,int mod){
	return (ll)x*y%mod;
}

int power(int x,int y,int mod){
	int res=1;
	for(;y;y/=2){
		if(y%2)res=mul(res,x,mod);
		x=mul(x,x,mod);
	}
	return res;
}

pii operator +(const pii&l,const pii&r){
	int a=l.first,b=l.second;
	int c=r.first,d=r.second;
	return{add(a,c,MOD1),add(b,d,MOD2)};
}

pii operator*(const pii &l,const pii &r){
	int a=l.first,b=l.second;
	int c=r.first,d=r.second;
	return{mul(a,c,MOD1),mul(b,d,MOD2)};
}

ll solve(){
	int inv1=power(BASE,MOD1-2,MOD1);
	int inv2=power(BASE,MOD2-2,MOD2);
	pot[0]={1,1};
	for(int i=1;i<=N;++i){
		pot[i]=pot[i-1];
		pref[i]=pref[i-1];
		if(s[i]=='>')
			pot[i]=pot[i]*pii(BASE,BASE);
		else if(s[i]=='<')
			pot[i]=pot[i]*pii(inv1,inv2);
		else if(s[i]=='+')
			pref[i]=pref[i]+pot[i];
		else{
			int a=pot[i].first;
			int b=pot[i].second;
			pref[i]=pref[i]+pii(-a,-b);
		}
	}
	ll ans=0;
	for(int i=N;i;--i){
		++cnt[pref[i]];
		pii a=pref[N];
		ans+=cnt[(a*pot[i-1])+pref[i-1]];
	}
	return ans;
}

int main(){
	scanf("%d%s",&N,s+1);
	printf("%lld\n",solve());
	return 0;
}

Measured memory_bytes: 35968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int caseNumber = 0;
        while (true) {
            int w = Integer.parseInt(reader.readLine());
            if (w == 0) {
                break;
            }

            caseNumber++;
            int n = Integer.parseInt(reader.readLine());
            int[][] priceWeightPairs = new int[n][2];
            for (int i = 0; i < n; i++) {
                String[] values = reader.readLine().split(",");
                priceWeightPairs[i] = new int[] { Integer.parseInt(values[0]),
                        Integer.parseInt(values[1]) };
            }

            int[][][] dp = new int[n + 1][w + 1][2];
            for (int i = 0; i < n; i++) {
                int[] priceWeightPair = priceWeightPairs[i];
                for (int j = 0; j <= w; j++) {
                    int[] curr = dp[i][j];
                    int[] next = dp[i + 1][j];
                    if (j >= priceWeightPair[1]) {
                        int[] left = dp[i][j - priceWeightPair[1]];
                        int price = left[0] + priceWeightPair[0];
                        int weight = left[1] + priceWeightPair[1];
                        if (price > curr[0]
                                || (price == curr[0] && weight < curr[1])) {
                            next[0] = price;
                            next[1] = weight;
                            continue;
                        }
                    }
                    next[0] = curr[0];
                    next[1] = curr[1];
                }
            }

            out.println("Case " + caseNumber + ":");
            out.println(dp[n][w][0]);
            out.println(dp[n][w][1]);
        }
    }
}

Measured memory_bytes: 39000
N,K=(int(x) for x in input().split())
K-=1
S=input()
output=""
for i in range(0,N):
    
    if (i==K):
        if (S[K]=="A"):
            output+="a"
        elif(S[K]=="B"):
            output+="b"
        elif(S[K]=="C"):
            output+="c"
    else:
        output+=S[i]
print(output)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define inf (int)1e8
using namespace std;
int n,k;
int main(){
	cin>>n>>k;
	printf("%d\n",!!(n%k));
	return 0;
}

Measured memory_bytes: 256
m, d = map(int, input().split())
r = 0
for i in range(1, m + 1):
    for j in range(1, d + 1):
        a = j % 10
        b = j // 10
        if a >= 2 and b >= 2 and a * b == i:
            r += 1
print(r)


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, k ;
    bool dp[100005] ;
    memset(dp, false, sizeof dp) ;
    cin>> n >> k ;
    vi a(n+1) ;
    for(int i=1 ; i<=n ; i++) cin>> a[i] ;
    for(int i=1 ; i<=k ; i++)
      for(int j=1 ; j<=n ; j++)
        if(i-a[j]>=0)
          dp[i]|=(!dp[i-a[j]]) ;
    if(dp[k]) cout<< "First" ;
    else cout<< "Second" ;
  }


Measured memory_bytes: 384
/*
[abc135] E - Golf
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int K;
int X, Y;
vector<pii> ans;

bool solve() {
    int xs = 1, ys = 1;
    if (X < 0) {
        X = -X;
        xs = -1;
    }
    if (Y < 0) {
        Y = -Y;
        ys = -1;
    }
    bool swapped = false;
    if (X < Y) {
        swap(X, Y);
        swapped = true;
    }

    if (K % 2 == 0 && (X + Y) % 2 == 1) {
        return false;
    }

    if (X + Y < K && (X + Y) % 2 == 1) {
        ans.push_back({X, -K + X});
        ans.push_back({(K + 3 * X - Y) / 2, (-K + X + Y) / 2});
        ans.push_back({X, Y});
    } else if (X + Y == K) {
        ans.push_back({X, Y});
    } else {
        int n = max(2, (X + Y + K - 1) / K);
        if ((K * n - X - Y) % 2 == 1) {
            n++;
        }
        int x = (-K * (n - 2) + X + Y) / 2, y = (-K * n + X + Y) / 2;
        for (int i = 0; i < n; i++) {
            ans.push_back({x, y});
            int dx = min(X - x, K);
            x += dx;
            y += K - dx;
        }
    }

    for (auto &p : ans) {
        if (swapped) {
            swap(p.first, p.second);
        }
        p.first *= xs, p.second *= ys;
        cerr << p.first << " " << p.second << endl;
    }

    return true;
}

int main() {
    cin >> K;
    cin >> X >> Y;

    if (!solve()) {
        cout << -1 << endl;
        return 0;
    }

    cout << ans.size() << endl;
    for (auto &p : ans) {
        cout << p.first << " " << p.second << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll L, R, d;
    cin >> L >> R >> d;
    PR(R/d-(L-1)/d);


    return 0;
}

/*



*/

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

int main(){
    int N, a = 0, b = 0, c = 0, d = 0;
    cin >> N;
    vector<string>S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
        if (S.at(i) == "AC") {
            a++;
        }
        else if (S.at(i) == "WA") {
            b++;
        }
        else if (S.at(i) == "TLE") {
            c++;
        }
        else {
            d++;
        }
    }
    cout << "AC x " << a << endl << "WA x " << b << endl << "TLE x " << c << endl << "RE x " << d;
} 

Measured memory_bytes: 6348
#include<stdio.h>

int main(void)
{
   int a, b;
   int c = 1;
   
while(c){
   
   scanf("%d", &a);  scanf("%d", &b);
   
   if(a>b){
      printf("%d %d\n", b,a);}
   else if(a<b){
      printf("%d %d\n", a,b);}
   else{
      if(a==0){
         c=0;}
      else{
      printf("%d %d\n", a,b);}
      }}
   
   return 0;
}


Measured memory_bytes: 2008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max();
const ll INFLL = numeric_limits<ll>::max();

signed main() {
    ll K;
    cin >> K;
    const int N = 50;
    vector<ll> a(N, 49);
    ll plus = K / N;
    K %= N;
    for (int i = 0; i < N; i++) a[i] += plus;
    auto operation = [&](int exclude) {
        for (int i = 0; i < N; i++) if (i != exclude) a[i]--;
    };
    for (int i = 0; i < K; i++) {
        a[i] += N;
        operation(i);
    }
    cout << N << endl;
    for (int i = 0; i < N; i++) {
        cout << a[i] << (i == N - 1 ? '\n' : ' ');
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int a[200000];
int main(void)
{
	int n,i;
	ll sum=0,k=0,ans=10000000000000000LL;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	FOR(i,0,n-1){
		k+=a[i];
		ans=MIN(ans,llabs(sum-2*k));
	}
	printf("%lld\n",ans);
	return 0;
}
    
    


Measured memory_bytes: 896
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
      
       for(int i = 1; i <= K ; i++){
         if(i % 2 != 0){
           if(A % 2 != 0){
             A--;
           }
          B = B + (A / 2);
          A = A - (A / 2);
         }else{
           if(B % 2 != 0){
              B--;
           }
         A = A + (B / 2);
         B = B - (B / 2);
         }
       }
       
         System.out.println(A + " " + B);

	}

}

Measured memory_bytes: 38844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int c=0,g,k=0;
    for(int i=0;i<n;i++){
        cin>>g;
        if(k<=g){
            c++;
            
        }
        k=max(k,g);
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int sqr(int x){return x*x;}
bool sq(int x){return sqr(sqrt(x))==x;}
int p[510][510];
int main(){
	int n,k,i,j,M;
	scanf("%d",&n);
	if(!sq(n*8+1)){
		puts("No");
		return 0;
	}
	k=(1+(int)sqrt(n*8+1))/2;
	for(i=1;i<k;i++){
		for(j=1;j<=i;j++)p[i][j]=++M;
	}
	printf("Yes\n%d\n",k);
	for(i=1;i<k;i++){
		printf("%d ",k-1);
		for(j=1;j<=i;j++)printf("%d ",p[i][j]);
		for(j=i+1;j<k;j++)printf("%d ",p[j][i]);
		putchar('\n');
	}
	printf("%d ",k-1);
	for(i=1;i<k;i++)printf("%d ",p[i][i]);
}

Measured memory_bytes: 2176
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())

for _ in range(n):
    b,f,r,v = map(int,input().split())
    count[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print(" "+" ".join(map(str,count[i][j])))
    
    if i != 3:
        print("#"*20)


Measured memory_bytes: 5608
use std::cmp::*;
use std::collections::*;
use std::fmt::Debug;
use std::io::{stdin, Read};
use std::str::FromStr;

//mod lib;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    return token.parse().ok().expect("failed to parse token");
}

static MOD: i64 = 1_000_000_007;

fn read_vec1<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn read_vec2<T: FromStr>(n: usize, m: usize) -> Vec<Vec<T>> {
    return (0..n).map(|_| read_vec1(m)).collect();
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn add_by_mod(a: &i64, b: &i64) -> i64 {
    return (a % MOD + b % MOD) % MOD;
}

fn solve(n: usize, m: usize) -> i64 {
    let c: Vec<i64> = read_vec1(m);
    let x: Vec<i64> = read_vec1(n);

    let mut dp = vec![vec![1e18 as i64; 256]; 20010];
    dp[0][128] = 0;
    for i in 0..n {
        for j in 0..256 {
            if dp[i][j] == 1e18 as i64 { continue; } 
            for cc in c.iter() {
                let next = max(0, min(255, (j as i64 + *cc))) as usize;
                dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + (x[i] - next as i64).pow(2));
            }
        }
    }

    return *dp[n].iter().min().unwrap();
}

fn main() {
    let mut n: usize = read();
    let mut m: usize = read();

    while n != 0 && m != 0 {
        println!("{}", solve(n, m));
        n = read();
        m = read();
    }
}



Measured memory_bytes: 45964
N,P=map(int,input().split())
A=[int(x) for x in input().split()]
e=0
o=0
for i in range(N):
  if A[i]%2==0:
    e+=1
  else:
    o+=1 

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i)
    
def nCr(n,r):
  return int(factorial[n]/(factorial[r]*factorial[n-r]))
  
ans=0
for i in range(1,o+1):
  if i%2==1:
    cnt=nCr(o,i)
    for j in range(0,e+1):
      ans+=cnt*(nCr(e,j))
if P==1:
  print(ans)
else:
  ans=(1<<N)-ans
  print(ans)

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

using namespace std;

int main()
{
	for (;;)
	{
		string s;
		cin >> s;
		if (s == "-")
		{
			break;
		}

		int m;
		cin >> m;

		for (int i = 0; i < m; i++)
		{
			int h;
			cin >> h;

			string t = s.substr(h, s.length() - h) + s.substr(0, h);

			s = t;
		}

		cout << s << endl;
	}
}


Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S[i] << T[i];
  }
  return 0;
}

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

dp = [float('inf')]*(n+1)

dp[0] = 0

for i in range(1, n+1):
  p = 1
  while p <= i:
    dp[i] = min(dp[i], dp[i-p]+1)
    p *= 6
  
  p = 1
  while p <= i:
    dp[i] = min(dp[i], dp[i-p]+1)
    p *= 9
print(dp[n])
  

Measured memory_bytes: 3828
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll a;
    string b;
    cin >> a >> b;
    int n = b.size();
    ll bb = 0;
    rep(i, n) {
        if (b[i] != '.') {
            bb = bb * 10 + (b[i] - '0');
        }
    }
    ll ans = a * bb;
    cout << ans / 100 << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int isPrime(long n){
	if(n==1)
	return 0;
    for(long i=2;i*i<=n; i++){
        if(n%i==0)
        return 0;
    }
    return 1;
}

int main(void){
	long n,i,count=0;
     	scanf("%ld",&n);
	for(i=0;i<n;i++){
	 long p;
	 scanf("%ld",&p);
	if(isPrime(p))
	count++;
	}
	printf("%ld\n",count);
	
   return 0;
}



Measured memory_bytes: 2104
import math
n, k = map(int,input().split())

ans = 0
for i in range(1,n+1):
  if i < k:
    a = math.ceil(math.log(k/i, 2)) #何回表を出せば良いか
    ans += (1/n) * (1/2)**a
  else:
    ans += (1/n)
print(ans)


Measured memory_bytes: 3060
#include <atcoder/all>

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using namespace atcoder;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  using T = int;
  auto f = [](T a, T b) {
    return T(max(a, b));
  };

  // identify element
  auto e = []() {
    return T(-1e9);
  };

  segtree<int, f, e> sg(a);

  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    if (t == 1) {
      int x, v; cin >> x >> v;
      x--;
      sg.set(x, v);
    }
    if (t == 2) {
      int l, r; cin >> l >> r;
      l--;
      r--;
      cout << sg.prod(l, r + 1) << endl;
    }
    if (t == 3) {
      int x, v; cin >> x >> v;
      x--;
      auto find = [&](int val) {
        return bool((val < v));
      };

      cout << sg.max_right(x, find) + 1 << endl;
    }
  }

  return 0;
}


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

int main(void){
  char s[51];
  int n,k;
  cin >> n >> k;
  cin >> s;

  if(s[k-1] == 'A') s[k-1] = 'a';
  if(s[k-1] == 'B') s[k-1] = 'b';
  if(s[k-1] == 'C') s[k-1] = 'c';

  cout << s << endl;
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int solve(int bs,vector<int>& d){
  int n=d.size();
  vector<int> v(n+1,0);
  rep(i,n){
    if(bs&(1<<i)){
      v[i]=d[i];
    }else{
      v[i]=24-d[i];
    }
  }
  sort(v.begin(),v.end());
  if(df)print(v);
  int t=v[0]-v[n]+24; if(df)print(t,"->");
  rep(i,n){
    minimize(t,v[i+1]-v[i]);
  }
  if(df)  print(t);
  return t;
}

int dist(int x,set<int>&st){
  auto itr=st.upper_bound(x);
  if(itr==st.end())itr--;
  int m=*itr-x;
  itr--;
  minimize(m,x-*itr);
  return m;
}

int main(){
  int n; cin >>n;
  vector<int> d(n);
  rep(i,n) cin >>d[i];
  sort(d.begin(),d.end());
  li ans=30;
  set<int> st;
  st.insert(0); st.insert(24);
  rep(i,n){
    int a=dist(d[i],st),b=dist(24-d[i],st); 
    if(a<b){
      st.insert(24-d[i]);
      minimize(ans,b);
    }
    else{
      st.insert(d[i]);
      minimize(ans,a);
    }
  }
  print(ans);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    ll n; cin>>n;
    ll ans = 0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll cc = 0;
            while(n%i==0){ n/=i; cc++; }
            double d = 8.0*cc + 1.0; d = sqrt(d);
            d = d-1.0; d = d/2.0;
            ll g = d;
            ans += g;
        }
    }
    if(n>1) ans++;
    cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3668
a = Array.new(4, 0)

10.times do
  a[3] = gets.chomp.to_i
  3.times do |i|
    if a[2-i] < a[3-i]
      a[2-i], a[3-i] = a[3-i], a[2-i]
    else
      break
    end
  end
end

print a[0], "\n", a[1], "\n", a[2], "\n"



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

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<vector<int>> G(N);
  for (int i = 0; i + 1 < N; ++i) {
    int A, B;
    cin >> A >> B;
    G[A - 1].push_back(B - 1);
    G[B - 1].push_back(A - 1);
  }

  function<pair<int, int>(int, int)> count = [&](int u, int f) {
    int c0 = 1;
    int c1 = 0;
    for (int v : G[u]) if (v != f) {
      int x, y;
      tie(x, y) = count(v, u);
      c0 += y;
      c1 += x;
    }
    return make_pair(c0, c1);
  };

  int c0, c1;
  tie(c0, c1) = count(0, -1);

  vector<int> res(N);
  int a = 1;
  int b = 2;
  int c = 3;
  function<void(int, int, int)> dfs = [&](int u, int f, int d) {
    if (min(c0, c1) > N / 3) {
      int &x = d ? a : b;
      if (x <= N) {
        res[u] = x;
        x += 3;
      } else {
        res[u] = c;
        c += 3;
      }
    } else if ((c0 <= N / 3 && !d) || (c1 <= N / 3 && d)) {
      res[u] = c;
      c += 3;
    }
    for (int v : G[u]) if (v != f) {
      dfs(v, u, d ^ 1);
    }
  };
  dfs(0, -1, 0);

  for (int &x : res) if (x == 0) {
    int &y = a <= N ? a : b <= N ? b : c;
    x = y;
    y += 3;
  }

  for (int i = 0; i < N; ++i) cout << res[i] << " \n"[i + 1 == N];

  return 0;
}



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

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
    }
    sort(s.begin(),s.end());
    for(int i=1; i<n; i++){
        s.at(0)+=s.at(i);
    }
    cout << s.at(0) << endl;
}

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

#define pr16 

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl; 
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}
 
#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif



int main()
{
  long long x,k,d;
  cin >> x >> k >> d;

  x = abs(x);
  if (k <= x/d) {
    cout << x - k*d;
    return 0;
  }
  long long s = x / d;
  x -= s*d;
  k -= s;
  if (k %2 == 0)
    cout<<x;
  else 
    cout<<(d-x);

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll e[51];
    e[0] = 1;
    rep2(i, 1, 50) e[i] = 2*e[i-1];
    vector<pii> edge[N];
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].pb(pii(b, i));
        edge[b].pb(pii(a, i));
    }
    int M = 1;
    cin >> M;
    ll es[M];
    fill_n(es, M, 0);
    rep(i, M){
        int u, v;
        cin >> u >> v;
        u--, v--;
        queue<int> que;
        vector<int> path[N];
        bool used[N];
        fill_n(used, N, false);
        que.push(u);
        used[u] = true;
        while(!que.empty()){
            int j = que.front();
            que.pop();
            rep(k, edge[j].size()){
                int p = edge[j][k].first;
                if(!used[p]){
                    used[p] = true;
                    que.push(p);
                    path[p] = path[j];
                    path[p].pb(edge[j][k].second);
                }
            }
        }
        rep(j, path[v].size()){
            es[i] |= 1ll<<path[v][j];
        }
    }
    ll ans = 0;
    rep(bit, 1<<M){
        ll eset = 0;
        rep(i, M){
            if(bit & 1<<i) eset |= es[i];
        }
        int white = 0;
        rep(i, N-1){
            if(eset%e[i+1] >= e[i]) white++;
        }
        ll now = 1ll<<(N-1-white);
        int num = 0;
        rep(i, M){
            if(bit%e[i+1] >= e[i]) num++;
        }
        if(num%2) ans -= now;
        else ans += now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Hi = Slist();

            --Hi[0];
            for (var i = 1; i < N; ++i)
            {
                if (Hi[i] < Hi[i - 1])
                {
                    WriteLine("No");
                    return;
                }
                if (Hi[i - 1] < Hi[i])
                    --Hi[i];
            }
            WriteLine("Yes");

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 28636
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    input<int>();
    string s = input<string>();

    vector<vector<pair<int, int>>> go(SZ(s));
    for (int i = 2; i != SZ(s); ++i)
        if (s[i - 2] == '1' and s[i - 1] == '0' and s[i] == '1') {
            int j = i - 2;
            while (j >= 0 and s[j] == '1') {
                go[i].eb(j, i - 1 - j);
                --j;
            }

            j = i;
            while (j != SZ(s) and s[j] == '1') {
                go[j].eb(i - 2, j - i + 1);
                ++j;
            }
        }

    vector<int> dp(SZ(s), 0);
    for (int i = 0; i != SZ(s); ++i) {
        if (i != 0)
            dp[i] = dp[i - 1];

        for (pair<int, int> j: go[i])
            dp[i] = max(dp[i], j.second + (j.first == 0 ? 0 : dp[j.first - 1]));
    }

    cout << dp.back() << "\n";
    
    return 0;
}


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
string ss ="ABC";
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    init();
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt =0;
    int ans=0;
    for(int i=0;i+2<n;i++){
       if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
    }
    cout<<ans;
    return 0;
}

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

int main(){
  bool w[5][5][4]={};
  char a;
  rep(i,5){
    rep(j,4){
      cin>>a;
      w[i][j][0]=a-'0';
      w[i][j+1][2]=a-'0';
    }
    if(i==4)continue;
    rep(j,5){
      cin>>a;
      w[i][j][1]=a-'0';
      w[i+1][j][3]=a-'0';
    }
  }
  assert(w[0][0][0]);
  int py=0,px=0;
  int dir=0;
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  string ans="";
  string ch[]={"R","D","L","U"};
  do{
    for(int i=-1;i<=2;i++){
      int nd=(dir+i+4)%4;
      if(w[py][px][nd]){
        ans+=ch[nd];
        py+=dy[nd];
        px+=dx[nd];
        dir=nd;
        break;
      }
    }
  }while(py!=0||px!=0);
  cout<<ans<<endl;
}



Measured memory_bytes: 2984