akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
N = int(input())
P = list(map(int, input().split()))
gold = [i for i in range(1, N+1)]
err_cnt = 0
for i, j in zip(P, gold):
    if i != j:
        err_cnt += 1
if err_cnt <= 2:
    print('YES')
else:
    print('NO')

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

int main() {
    int n,k;
    set<int> ans;
    cin >> n >> k;
    for (int a = 0; a < k; ++a) {
        int l;
        cin >> l;
        for (int i = 0; i < l; ++i) {
            int tmp;
            cin >> tmp;
            ans.insert(tmp);
        }
    }
    cout << n - (int)ans.size();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------

int main(){
  int n;
  double ans;
  cin>>n;
  vector<double> a(n);
  vector<double> b(n);
  rep(i,0,n) {
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(b.begin(),b.end());
  rep(i,0,n-1){
    if(i==0){
    ans=(b.at(i)+b.at(i+1))/2;
  }
  else{
    ans=(ans+b.at(i+1))/2;
  }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    //input
    int N; 
    cin >> N; 
    vector<int> V(N); 
    for (int i = 0; i<N; ++i){
        cin >> V[i]; 
    }
    vector<int> C(N); 
    for (int i = 0; i<N; i++){
        cin >> C[i]; 
    }
    // compute
    int ans = 0;
    for (int i = 0; i< N; ++i) { 
        if (V[i] > C[i]) {
            ans += V[i] - C[i]; 
        }
    }
    // output
    cout << ans << endl;
}




Measured memory_bytes: 256
// AtCoder Educational DP Contest H - Grid 1
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define PB push_back
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define NMAX (int)(1e3+5)
#define INF 0x3f3f3f
#define MOD (int)(1e9+7)
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int N, M, dp[NMAX][NMAX];
bool G[NMAX][NMAX];


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

    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        string s; cin >> s;
        for (int j = 1; j <= M; j++) {
            if (s[j-1] == '.') {
                dp[i][j] = (i==1 && j==1);
                dp[i][j] += dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[N][M] << endl;

    return 0;
}


Measured memory_bytes: 7588
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;

#define INF 1e18
#define int long long

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

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

signed main() {
    int n, k; cin >> n >> k;
    vector<int> h(n), dp(n, INF);
    for(int i = 0; i < n; i++) cin >> h[i];

    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, W = map(int, readline().split())
    WV = np.array([[int(x) for x in readline().split()] for _ in range(N)])

    dp = np.zeros([W+1], np.int64)

    for w, v in WV:
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

    print(np.max(dp))


main()


Measured memory_bytes: 14640
CONST   fi='';
        fo='';
VAR
    f:text;
    ds,n,m:longint;
PROCEDURE input;
  begin
    Assign(f,fi);reset(f);
      readln(f,n,m);
    Close(f);
  end;

PROCEDURE main;
  begin
    if n mod m = 0 then ds:=0 else ds:=1;
  end;

PROCEDURE output;
  begin
    Assign(f,fo);rewrite(f);
       writeln(f,ds);
    Close(f);
  end;

BEGIN
   input; main; output;
END.


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

int main()
{
    int n;
    cin >> n;
    char x[3];
    int p = 0;
    while (n)
    {
        x[p++] = n%10+'0';
        n /= 10;
    }
    for (int i = 0; i < 3; ++i)
    {
        if (x[i] == '1')
        {
            x[i] = '9';
        }
        else if (x[i] == '9')
        {
            x[i] = '1';
        }
    }
    for (int i = 2; i >= 0; --i)
    {
        putchar(x[i]);
    }
    puts("");
}


Measured memory_bytes: 256
N = int(input())
t, a = 0, 0
for _ in range(N):
    T, A = map(int, input().split())
    c = max((t - 1) // T + 1, (a - 1) // A + 1)
    t = T * c
    a = A * c
    if t + a == 0:
        t += T
        a += A
    # for n in range(10 ** 18):
    #     if t <= n * T and a <= n * A:
    #         t = n * T
    #         a = n * A
    #         print('{0} {1} {2}'.format(n, t, a))
    #         break
print(int(t + a))

Measured memory_bytes: 3060
from math import log10
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = [0,2,5,5,4,5,6,3,7,6]

dp = [0]*(n+1)
for i in range(n):
    for j in range(m):
        if dp[i] == 0 and i != 0:
            continue
        x = a[j]
        t = l[x]
        if i+t > n:
            continue
        if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
        dp[i+t] = max(dp[i+t],s0,s1)
print(dp[-1])

Measured memory_bytes: 86416
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	auto c = make_v<int>(3, 3);
	for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) scanf("%d", &c[i][j]);
	
	for(int i = 0; i <= 100; i++) {
		std::vector<int> a(3), b(3);
		b = {c[0][0] - i, c[0][1] - i, c[0][2] - i};
		a = {i, c[1][0] - b.front(), c[2][0] - b.front()};
		
		bool f = true;
		for(int i = 0; i < a.size(); i++) {
			for(int j = 0; j < b.size(); j++) {
				f &= (a[i] + b[j] == c[i][j]);
			}
		}
		if(f) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

// const int INT_MAX = 2147483647;
// const ll LLONG_MAX = 9223372036854775807;
// const ull ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout << abs(H-h)*abs(W-w) << endl;
    return 0;
    
}

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

int main(void) {
  ll n, k;
  cin >> n >> k;
  n %= k;
  ll ans = min(n, k - n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
/*
Wai u read my code xD
*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    ll n, k; cin >> n >> k;
    ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n); ll s= 0;
    for (int i = 0; i < n-k; i++)
    {
        s += a[i];
    }
    nout(s);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

int main(){

	long long int n, a, b, c, d, e, mi;
	long long int dure=5;

	cin>> n >> a >> b >> c >> d >> e;

	mi=min(a, b);
	mi=min(c, mi);
	mi=min(d, mi);
	mi=min(e, mi);

	dure+=(n-1)/mi;

	cout<< dure << endl;

}

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

int w, h;
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
bool cnt[2][51][51];
char s[51][51];
char dir[]{ 'B','W' };

void dfs(int x, int y, int idx) {
	rep(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] == '.' && !cnt[idx][nx][ny]) {
			cnt[idx][nx][ny] = true;
			dfs(nx, ny, idx);
		}
	}
}
int main() {
	while (scanf("%d%d", &w, &h), w) {
		memset(cnt, 0, sizeof(cnt));
		rep(i, h)scanf("%s", s[i]);
		rep(t, 2)rep(i, h)rep(j, w) {
			if (s[i][j] == dir[t])dfs(i, j, t);
		}
		int cb = 0, cw = 0;
		rep(i, h)rep(j, w) {
			if (cnt[0][i][j] && cnt[1][i][j])continue;
			if (cnt[0][i][j])cb++;
			if (cnt[1][i][j])cw++;
		}
		printf("%d %d\n", cb, cw);
	}
}

Measured memory_bytes: 3256
#include<cstdio>
#include<algorithm>
#include<numeric>
using namespace std;
int main()
{
	int t,n,k,a[100000],i,x,y;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&k);
		for(i=0;i<n;y=x,++i)if(scanf("%d",&x),i)a[i-1]=x-y;
		k=min(--n,k-1);
		nth_element(a,a+n-k,a+n);
		printf("%d\n",accumulate(a,a+n-k,0));
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
#define ll long long
inline int read()
{
    int x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x;
}
bool vis[2][MN+5];
int n,m,head[MN+5],cnt=0,v[2][MN+5];ll s[2][MN+5],l,r;
struct edge{int to,next,w;}e[MN*2+5];
inline void ins(int f,int t,int w)
{
    e[++cnt]=(edge){t,head[f],w};head[f]=cnt;
    e[++cnt]=(edge){f,head[t],w};head[t]=cnt;
}
void Mark(int x,int k,ll V)
{
    if(!v[k][x]) v[k][x]=1,s[k][x]=V;
    else if(s[k][x]!=V) {puts("0");exit(0);}
}
void dfs(int x,int k)
{
    vis[k][x]=1;
    for(int i=head[x];i;i=e[i].next)
    {
        Mark(e[i].to,k^1,e[i].w-s[k][x]);
        if(!vis[k^1][e[i].to]) dfs(e[i].to,k^1); 
    }
}
int main()
{
    n=read();m=read();
    for(int i=1,j,k;i<=m;++i) j=read(),k=read(),ins(j,k,read());
    Mark(1,0,0);dfs(1,0);
    l=-1e18,r=1e18;
    for(int i=1;i<=n;++i)
    {
        if(v[0][i]) l=max(l,1-s[0][i]);
        if(v[1][i]) r=min(r,s[1][i]-1);
        if(v[0][i]&&v[1][i])
        {
            ll val=s[1][i]-s[0][i];
            if(val<=0||val&1) return 0*puts("0");
            l=max(l,val/2);r=min(r,val/2);
        }
    }
    printf("%lld\n",l<=r?r-l+1:0);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n <= 99 && n >= 10){
    cout << 9 <<endl;
  }
  else if (n <= 9){
    cout << n << endl;
  }
  else if(n <= 999 && n >= 100){
    cout << n - 90 << endl;
  }
  else if(n >= 1000 && n <= 9999){
    cout << 909 << endl;
  }
  else if(n >= 10000 && n <= 99999){
    cout << n - 9090 << endl;
  }
  else{
    cout << 90909 << endl;
  }
}


Measured memory_bytes: 256
// xの3乗
// 1つの整数xを読み込んで、xの3乗を計算し結果を出力するプログラムを作成せよ。
// 【入力】
// 入力として1つの整数が与えられる。
// 【出力】
// xの３乗の計算結果を１行に出力する。最後に改行を付ける。
// 【制約】
// 1 ≦ x ≦ 100
// 【例】
// 入力：2、出力：8
// 入力：3、出力：27
#include<stdio.h>

int main(void) {
  int x, cubeX;

  scanf("%d", &x);

  cubeX = x * x * x;

  printf( "%d\n", cubeX);
}



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

void _139() {
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == t[i])
            count++;
    }
    cout << count << endl;
}

void _138() {
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

void _137() {
    int a, b;
    cin >> a >> b;

    int add = a + b;
    int mult = a * b;
    int sub = a - b;

    cout << max(add, max(mult, sub)) << endl;
}

void _136() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

int main()
{
    _136();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    int l;
    cin>>l;
    double ans = l/(3*1.0);
    ans = pow(ans,3*1.0);
    cout<<fixed<<setprecision(9)<<ans<<endl;
    return 0; 
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, m, c, s, g;
ll p[50], q[50][100], r[50][100];
ll dp[50][110][110];
ll cost[110][110];
ll dc[50][20100];


int main() {
	while (cin >> n >> m >> c >> s >> g&&n + m + c + s + g) {
		s--; g--;
		rep(i, 50) {
			rep(j, 110) {
				rep(k, 110) {
					if (j == k) {
						dp[i][j][k] = 0;
						cost[j][k] = 0;
					}
					else {
						dp[i][j][k] = INF;
						cost[j][k] = INF;
					}
				}
			}
			rep(j, 20100)dc[i][j] = 0;
		}
		rep(i, m) {
			ll x, y, d, cc;
			cin >> x >> y >> d >> cc;
			x--; y--; cc--;
			dp[cc][x][y] = min(d, dp[cc][x][y]);
			dp[cc][y][x] = min(d, dp[cc][y][x]);
		}
		rep(ii, c) {
			rep(k, n) {
				rep(i, n) {
					rep(j, n) {
						dp[ii][i][j] = min(dp[ii][i][j], dp[ii][i][k] + dp[ii][k][j]);
					}
				}
			}
		}
		//cout << "!" << c << endl;
		//rep(ii, c) {
		//	rep(i, n) {
		//		rep(j, n) {
		//			cout << dp[ii][i][j] << " ";
		//		}
		//		cout << endl;
		//	}
		//	cout << endl;
		//}

		rep(i, c) {
			cin >> p[i];
		}
		rep(i, c) {
			//cout << "!" << p[i] << endl;
			rep(j, p[i] - 1)cin >> q[i][j];
			q[i][p[i] - 1] = INF;
			rep(j, p[i])cin >> r[i][j];
		}
		rep(i, c) {
			ll cnt = 0;
			rep(j, 20090) {
				dc[i][j + 1] = dc[i][j] + r[i][cnt];
				if (j + 1 == q[i][cnt])cnt++;
			}
		}
		//rep(i, c) {
		//	rep(j, 10)cout << dc[i][j] << " ";
		//	cout << endl;
		//}
		rep(i, c) {
			rep(j, n) {
				rep(k, n) {
					ll d = dp[i][j][k];
					if (d == INF)continue;
					cost[j][k] = min(cost[j][k], dc[i][d]);
				}
				//cout << endl;
			}
			//cout << endl;
		}
		//rep(i, n) {
		//	rep(j, n)cout << cost[i][j] << " ";
		//	cout << endl;
		//}

		rep(k, n) {
			rep(i, n) {
				rep(j, n)cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
		//cout << "!!!ans";
		if (cost[s][g] != INF)cout << cost[s][g] << endl;
		else cout << -1 << endl;
	}
}


Measured memory_bytes: 15736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pl;
const ll N = 2e5 + 50;
const ll MOD = 1000000000;
 
int a[N];
int n; 
 
int main() {
	cin>>n;
  int x;
	for(int i=0;i<n-1;i++) {
    	cin>>x;
      a[x] ++;
    }
  for(int i=1;i<=n;i++) {
  	cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4404
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W, D;
signed main() {
	cin >> H >> W >> D;
	N = H * W;
	vector< vector< int > > A(H, vector< int >(W));
	rep(i, H) rep(j, W) cin >> A[i][j];
	vector< pii > pos(N + 1);
	rep(i, H) rep(j, W) pos[A[i][j]] = pii(i, j);
	vector< int > S(N + 1, 0);
	vector< int > B(N + 1, 0);
	rep(i, N) {
		if (i + 1 - D <= 0)
			B[i + 1] = 0;
		else {
			pii now = pos[i + 1];
			pii prev = pos[i + 1 - D];
			B[i + 1] = abs(prev.first - now.first) + abs(prev.second - now.second);
		}
	}
	rep(i, N) S[i + 1] = (i + 1 - D >= 0 ? S[i + 1 - D] : 0) + B[i + 1];
	cin >> Q;
	while (Q--) {
		int L, R;
		cin >> L >> R;
		cout << S[R] - S[L] << endl;
	}
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, u, v;
  cin>>N>>u>>v;
  u--;
  v--;
  vector<vector<int> > edge(N);
  int A, B;
  for(int i=0;i<N-1;++i) {
    cin>>A>>B;
    A--;
    B--;
    edge[A].push_back(B);
    edge[B].push_back(A);
  }
  int tdist[N], adist[N];
  for(int i=0;i<N;++i) {
    tdist[i] = -1;
    adist[i] = -1;
  }
  queue<pair<int, int> > que;
  pair<int, int> state;
  int node, dist;
  que.push(mp(u, 0));
  while(!que.empty()) {
    state = que.front();que.pop();
    node = state.fi;
    dist = state.se;
    if(tdist[node]>-1) continue;
    tdist[node] = dist;
    for(int i=0;i<edge[node].size();++i) {
      if(tdist[edge[node][i]]>-1) continue;
      que.push(mp(edge[node][i], dist+1));
    }
  }
  que.push(mp(v, 0));
  while(!que.empty()) {
    state = que.front();que.pop();
    node = state.fi;
    dist = state.se;
    if(adist[node]>-1) continue;
    adist[node] = dist;
    for(int i=0;i<edge[node].size();++i) {
      if(adist[edge[node][i]]>-1) continue;
      que.push(mp(edge[node][i], dist+1));
    }
  }
  int ansnode = u;
  for(int i=0;i<N;++i) {
    if(tdist[i]<adist[i] && adist[i]>adist[ansnode]) ansnode = i;
  }
  cout<<adist[ansnode]-1<<endl;
}


Measured memory_bytes: 9860
n = int(input())
a = [int(n) for n in input().split()] 

rate = {}

def color_check(n):
    if 1 <= n <= 399:
        return 'gray'
    elif 400 <= n <= 799:
        return 'brown'
    elif 800 <= n <= 1199:
        return 'green'
    elif 1200 <= n <= 1599:
        return 'lightblue'
    elif 1600 <= n <= 1999:
        return 'blue'
    elif 2000 <= n <= 2399:
        return 'yellow'
    elif 2400 <= n <= 2799:
        return 'orange'
    elif 2800 <= n <= 3199:
        return 'red'
    elif 3200 <= n:
        return 'top'

for n in a:
    col = color_check(n)
    rate.setdefault(col, 0)
    rate[col] += 1

colors = len(rate)

if not 'top' in rate:
    maxl, minl = colors, colors
else:
    maxl = (colors - 1) + rate['top']
    if colors == 1:
        minl = 1
    else:
        minl = (colors - 1)

print(minl, maxl)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class P {
	int offset;
	int counter = 0;
	List<P> links = new ArrayList<>();
}

public class Main {

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

		String[] line = sc.nextLine().split(" ");
		int N = Integer.parseInt(line[0]);
		int Q = Integer.parseInt(line[1]);

		P[] tree = new P[N];
		for (int i = 0; i < N; i++) {
			tree[i] = new P();
		}

		for (int i = 0; i < N - 1; i++) {
			line = sc.nextLine().split(" ");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			tree[a - 1].links.add(tree[b - 1]);
			tree[b - 1].links.add(tree[a - 1]);
		}

		for (int i = 0; i < Q; i++) {
			line = sc.nextLine().split(" ");
			int p = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			tree[p - 1].offset += x;
		}

		dfs(null, tree[0], 0);

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < N; i++) {
			sb.append(tree[i].counter).append(" ");
		}
		System.out.println(sb.toString());
	}

	static void dfs(P parent, P node, int sum) {
		sum += node.offset;
		node.counter = sum;
		for (P n : node.links) {
			if (n != parent) {
				dfs(node, n, sum);
			}
		}
	}
}

Measured memory_bytes: 340232
N = int(input())

S=[]
for n in range(N):
    S.append(int(input()))

S.sort(reverse=True)

S_cumsum = []
S_not_10 = 10**10
s_=0
for s in S:
    if s % 10 !=0 and S_not_10 > s:
        S_not_10 = s
    s_+=s
    S_cumsum.append(s_)
    
ans=0
if s_ % 10 !=0:
    ans=s_
    
elif S_not_10 != 10**10:
    ans = s_-S_not_10
else:
    ans=0
print(ans)

Measured memory_bytes: 62572
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define eps 1e-6
#define ll long long
using namespace std;
const int N = 1e3+5;
int a[N];
bool check(string s)
{
  int l=s.size();
  int cnt=0;
  for(int i=0;i<l;i++)
  {
    if(s[i]==s[l-i-1])cnt++;
  }
  if(cnt==l)return true;
  else return false;
}
string s;
int main()
{
  cin>>s;
  int len=s.size();
  bool falg=1;
  if(check(s))
  {
    string b;
    b=s.substr(0,(len-1)/2);
    if(!check(b))
    {
      cout<<"No"<<endl;
      return 0;
    }
    else
    {
      b=s.substr((len+3)/2-1,len-(len+3)/2+1);
      if(check(b))cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
  else
  {
    cout<<"No"<<endl;
    return 0;
  }
  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,int> p;

int H[1001];

int main(){
  int N;
  double T,A;
  cin >> N;
  cin >> T >> A;
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  double mina = 1000000000;
  int ans = 0;
  for(int i=0;i<N;i++){
    mina = min(mina,fabs((double)A-(T-H[i]*0.006f)));
    if(mina >= fabs((double)A-(T-H[i]*0.006f))){
      ans = i;
    }
  }
  cout << ans+1 << endl;
  return 0;
}


Measured memory_bytes: 256
# 奇数の隣は必ず4の倍数でなくてはならない あとはどうでもよさそう
# ただし 1 4 1 は大丈夫だが 1 4 1 2 はダメ
n = int(input())
arr = list(map(int, input().split()))
dividable_four = 0
odds = 0
for a in arr:
    if a % 4 == 0:
        dividable_four += 1
    elif a % 2 == 1:
        odds += 1
if dividable_four >= odds:
    print('Yes')
elif odds - dividable_four == 1 and odds + dividable_four == n:
    print('Yes')
else:
    print('No')


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

using namespace std;
typedef long long ll;

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

    vector<double> cs(n+1);

    for (int i = 0; i < n; i++) {
        double s = p[i]*(p[i]+1)/2;
        cs[i+1] = cs[i] + s/p[i]; 
    }
    for (int i = 0; i < n+1; i++) {
    }

    double ans = 0.0;
    for (int i = 0; i <= n-k; i+=1) {
        ans = max(ans, cs[i+k] - cs[i]);
    }
    printf("%f\n", ans);


}




Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			
			int[] pArray = new int[n];
			
			for(int i = 0 ; i < n ; i++) {
				pArray[i] = sc.nextInt();
			}
			
			
			int min = pArray[0];
			int count = 1;
			for(int i = 1 ; i < n ; i++ ) {
				
				if ( pArray[i] < min) {
					//OK
					count++;
					min = pArray[i];
				}
			}

			System.out.println(count);
		}
	}
}

Measured memory_bytes: 64392
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+1;
 
typedef long long ll;
typedef long double ld;
 
void test_case()
{
    ll n,i,j;
    cin>>n;
    ll a[n];
    f(i,0,n)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            if(a[i]%3==0 || a[i]%5==0)
                continue;
            
            cout<<"DENIED\n";
            return ;
        }
    }
    cout<<"APPROVED\n";
}
int main()
{
    IOS();
    
    int tc=1;
    while(tc--)
        test_case();
    return 0;
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(abs((a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main( void ) {
    
    char a, b;
    cin >> a >> b;
    
    if( a == 'D' )
        b = ( b == 'H' ) ? 'D' : 'H';
    
    cout << b << endl;
    return 0;
}

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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while (t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.ff << " -> " << x.ss << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
	ll n; cin >> n;
	vl v(n);
	rep(i,0,n) cin >> v[i];

	rep(i,0,n) if(v[i] == 0) {cout << 0; return 0;}

	ll ans = 1;
	rep(i,0,n) {
		if(v[i] > 1000000000000000000/ans) {cout << -1; return 0;}
		ans *= v[i];
	}

	cout << ans;
}

Measured memory_bytes: 4000
#include <iostream>  
#include <vector>  
#include <string>  
#include <algorithm>  
#include <cstdio>  
#include <cstring>  
#include <ctime>  
#include <cstdlib>  
#include <set>  
#include <map>  
#include <cctype>  
#include <list>  
#include <cmath>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <sstream>  
#include <functional>  
#include <cassert>  
using namespace std;  
 
#define tmax(a, b) if (b > a) a = b  
#define tmin(a, b) if (b < a) a = b  
char inc() { char _[10]; scanf("%s", _); return _[0]; }  
int ini() { int _; scanf("%d", &_); return _; }  
long long inll() { long long _; scanf("%I64d", &_); return _; }  
double ind() { double _; scanf("%lf", &_); return _; }  
string ins() { string _; cin >> _; return _; }  
int inl(char _[]) { if (!fgets(_, (int)1e8, stdin)) return -1; int i = strlen(_); if (_[i - 1] == '\n') _[--i] = 0; return i; }  
 
typedef pair<int, int> pii;  
typedef pair<char, char> pcc;  
typedef long long LL;  
const int inf = 0x3f3f3f3f;  
const LL lnf = 0x3f3f3f3f3f3f3f3f;  
const double pi = 3.14159265358979323846;  
const double eps = 1e-8;  
const int mod = 100007;  
const int maxn = 1e5+ 10;  
 
pii x[maxn], y[maxn];
vector<pii> G[maxn];
int n;
bool vis[maxn];
 
int Prim() {
	int res = 0;
	memset(vis, false, sizeof vis);
	priority_queue<pii, vector<pii>, greater<pii> > q;
	q.push(pii(0, 0));
	while (!q.empty()) {
		pii h = q.top(); q.pop();
		if (vis[h.second]) continue;
		vis[h.second] = true;
		res += h.first;
		for (int i = 0; i < G[h.second].size(); ++i) {
			pii &e = G[h.second][i];
			if (!vis[e.first]) {
				q.push(pii(e.second, e.first));
			}
		}
	}
	return res;
}
 
int main() {  
	int CAS = 0;  
	//std::ios::sync_with_stdio(0);  
	//std::cin.tie(0);  
#ifdef NIGHT_13  
	freopen("in.txt", "r", stdin);  
	// freopen("out.txt", "w", stdout);  
	int time_night_13 = clock();  
#endif // NIGHT_13  
 
	while (scanf("%d", &n) != EOF) {
		for (int i = 0; i < n; ++i) G[i].clear();
		for (int i = 0; i < n; ++i) {
			int a, b;
			scanf("%d%d", &a, &b);
			x[i] = pii(a, i);
			y[i] = pii(b, i);
		}
		sort(x, x + n);
		sort(y, y + n);
		for (int i = 1; i < n; ++i) {
			G[x[i - 1].second].push_back(pii(x[i].second, abs(x[i - 1].first - x[i].first)));
			G[x[i].second].push_back(pii(x[i - 1].second, abs(x[i - 1].first - x[i].first)));
			G[y[i - 1].second].push_back(pii(y[i].second, abs(y[i - 1].first - y[i].first)));
			G[y[i].second].push_back(pii(y[i - 1].second, abs(y[i - 1].first - y[i].first)));
		}
		printf("%d\n", Prim());
	}
 
#ifdef NIGHT_13  
	fprintf(stderr, "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");  
	fprintf(stderr, "\t   Time: %d ms", (int)clock() - time_night_13);  
	fprintf(stderr, "\n...........................................\n\n");  
#endif // NIGHT_13  
	return 0;  
}  

Measured memory_bytes: 10616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  int N;
  cin >> N;
  vi a(N);
  ll all = 0;
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    all ^= a[i];
  }

  cout << (all ^ a[0]);
  for (ll i = 1; i < N; i++) {
    cout << ' ' << (all ^ a[i]);
  }
  cout << endl;
}


Measured memory_bytes: 4836
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<queue>
#include<ctime>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<cassert>
#include<complex>
#include<deque>
#include<stdio.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if ((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))
		cout<<"Yes";
	else if (s[0]==s[2]&&s[0]==s[3]&&s[0]==s[1])
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

patties, layers = [1], [1]
for i in range(n):
    patties += [patties[-1] * 2 + 1]
    layers += [layers[-1] * 2 + 3]

def solve(N, cur):
    if N == 0:
        return 1 if cur > 0 else 0
        
    return solve(N-1, cur-1) if cur <= (layers[N] // 2) else solve(N-1, (cur-layers[N-1])-2) + patties[N-1] + 1

print(solve(n,x))

Measured memory_bytes: 3064
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m) = parse!(it, 2);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (l, r, d): (usize, usize, i64) = parse!(it, 3);
        g[l - 1].push((r - 1, d));
        g[r - 1].push((l - 1, -d));
    }
    let mut x: Vec<Option<i64>> = vec![None; n];
    let mut dfs = |u: usize, x: &mut Vec<Option<i64>>| -> bool {
        let mut stack = vec![u];
        x[u] = Some(0);
        while let Some(u) = stack.pop() {
            let xu = x[u].unwrap();
            for &(v, d) in &g[u] {
                match x[v] {
                    Some(xv) => {
                        if xv - xu != d {
                            return false;
                        }
                    }
                    None => {
                        x[v] = Some(xu + d);
                        stack.push(v)
                    }
                }
            }
        }
        return true;
    };
    for i in 0..n {
        if x[i] == None {
            if !dfs(i, &mut x) {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 24820
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}
int main()
{

    ll t,i,j,k,n,l,x,y;
    cin>>x>>n;
    map<ll,ll>m;
    if(n==0)
    {
        cout<<x<<endl;
        return 0;
    }
    vector<pair<ll,ll> >v;
    for(i=0;i<n;i++)
    {
        ll p;
        cin>>p;
        m[p]++;
    }
    for(i=-1000;i<=1000;i++)
    {
        if(m[i]==0)
        {
            v.push_back({i,abs(i-x)});
        }
    }
    sort(v.begin(),v.end(),sortbysec);
    cout<<v[0].first<<endl;


    return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <string>
//#include <functional>

constexpr int64_t MOD = 1000000007LL;

int main(){
    std::string S;
    std::cin >> S;

    //std::cout << "S Size is: " << S.size() << std::endl;

    // brute force: repeat N+=13 from 5 to 1 x 10^100000
    // impossible within 2sec
    // use dp[i th digit][modulo 13]
    uint64_t dp[S.size()][13] = {};
    //dp[0][0] = 1;
    if (S[0] == '?'){
        for(int32_t i = 0; i <= 9; i++){
            dp[0][i] = 1;
        }
    }
    else{
        dp[0][S[0] - '0'] = 1;
    }

    for(uint32_t i = 0; i < S.size() - 1; i++){
        for(int32_t k = 0; k <= 12; k++){
            if(S[i + 1] == '?'){
                for(int32_t j = 0; j < 10; j++){
                    dp[i+1][(k*10 + j) % 13] += dp[i][k];
                }

            }
            else{
                dp[i+1][(k * 10 + (S[i+1] - '0')) % 13] += dp[i][k];

            }
        }
        for(int32_t j = 0; j <= 12; j++){
            dp[i+1][j] %= MOD;
            //std::cout << "i,j,dp = " << i+1 << "," << j << "," << dp[i+1][j] << std::endl;
        }
    }
    std::cout << dp[S.size() - 1][5];
    return 0;
}


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

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

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

  vector<int> d(N);
  rep(i,N){
    cin >> d.at(i);
  }

  int64_t ans = 0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      ans += d.at(i)*d.at(j);
    }
  }
  cout << ans;
}

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

#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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



int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin>>n;
    if(n==1) cout<<"Hello World"<<endl;
    else 
        {
        int a; cin>>a;
        int b; cin>>b;
        cout<<a+b<<endl;
        }
}

Measured memory_bytes: 896
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    long long int n,a,b;
    cin >> n >> a>> b;
    long long int amari=n%(a+b);
    if(amari<=a){
        cout << n/(a+b)*a+amari << endl;
    }else{
        cout << n/(a+b)*a+a << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3224
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf=1e9;
char s[5010],t[5010];
int s1,s2,n,ans;
vector<int> a,b;
void solve(vector<int> &a,char *s) {for(int i=1;i<n;i++) if(s[i]!=s[i+1]) a.push_back(i);}
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	solve(a,s);s1=a.size();
	solve(b,t);s2=b.size();
	ans=inf;
	for(int k=-s1-1;k<=s2+1;k++)
		if((k+(s[1]==t[1]))&1)
		{
			int tot=0;
			for(int i=min(-k,0);i<=max(s1,s2-k);i++)
			{
				int j=i+k,px,py;
				px=i<0?0:(i>=s1?n:a[i]);
				py=j<0?0:(j>=s2?n:b[j]);
				tot+=abs(px-py);
			}
			ans=min(ans,tot);
		}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

typedef long long ll;

bool isok[100 + 10];

int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++)isok[i * j] = true;
	}
	int N;
	cin >> N;
	if (isok[N])cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    priority_queue<int> pq;
    int ans = 0;
    int k = 0;
    for(int d=1; d<=m; ++d){
        while(k < n && v[k].first <= d){
            pq.push(v[k].second);
            ++ k;
        }
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1660
import sys

n = int(input())

if n > 81:
	print('No')
	sys.exit()
if n < 10:
	print('Yes')
	sys.exit()

for i in range(2,10):
	for j in range(2,10):
		if i*j == n:
			print('Yes')
			sys.exit()
print('No')


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

void solve(){
  int n, m; cin >> n >> m;
  vector <int> a(n + 1, 0);
  vector <int> b(n + 1, 0);
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < m; i++){
    int np; string s;
    cin >> np >> s;
    if (s == "AC"){
      if (a[np] >= 0){
        ans1++;
        ans2 += b[np];
      }
      a[np] = -1;
    }
    else{
      b[np]++;
    }
  }
  cout << ans1 << ' ' << ans2 << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sb.append(n).append(":");
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 2; i <= Math.sqrt(n); i++) {
            while (n % i == 0) {
                ans.add(i);
                n /= i;
            }
        }
        if (n != 1) {
            ans.add(n);
        }
        for (int x : ans) {
            sb.append(" ").append(x);
        }
        System.out.println(sb);
     }
}


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

using namespace std;

int n[4];

int sum(int *p) {
	int tmp = n[0];
	for (int i = 0; i < 3; i++) {
		if (p[i] == 1)tmp += n[i + 1];
		if (p[i] == 0)tmp -= n[i + 1];
	}
	return tmp;
}

int main()
{
	string s;
	cin >> s;

	char ans[3] = {};

	for (int i = 0; i < 4; i++)n[i] = s[i]-'0';


	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int in[3] = { i,j,k };
				if (sum(in) == 7) {
					for (int l = 0; l < 3; l++) {
						if (in[l] == 1)ans[l] = '+';
						if (in[l] == 0)ans[l] = '-';
					}
				}
			}
		}
	}

	cout << s[0];
	cout << ans[0];
	cout << s[1];
	cout << ans[1];
	cout << s[2];
	cout << ans[2];
	cout << s[3];
	cout << "=7" << endl;


	return 0;
}

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

using namespace std;
string s,t;
int main() {
	cin >> s >> t;
  	int ans = 0;
  	for (int i = 0; i < s.size(); i++) {
    	if (s[i] != t[i]) ans++;
    }
  cout << ans;
	return 0;
}

Measured memory_bytes: 3844
//xsharawi is back
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
#if !defined(ONLINE_JUDGE)
#include "C:\debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define ins insert
#define vl vector<ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
    speed;
    map <string,ll>mona;
    ll n;
    cin >> n;
    while( n-- ){
    	s ss;
    	cin >> ss;
    	mona[ss]++;
    }
    cout << "AC x " << mona["AC"] << endl;
    cout << "WA x " << mona["WA"] << endl;
    cout << "TLE x " << mona["TLE"] << endl;
    cout << "RE x " << mona["RE"] << endl;





















return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 300005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll k,fl=-1;
void dfs(ll i,ll rm){
	if(i==1e6){
		return ;
	}

	rm=(rm+7ll*power(10,i-1,k))%k;
	if(rm==0){
		fl=i; return ;
	}
	else dfs(i+1,rm);
}
int main(){

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

	cin>>k;
	dfs(1,0);
	cout<<fl<<endl;
	return 0;	
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define in(a,b,vec,n) a n; cin>>n; vector<b>vec(n);
#define gcd __gcd
using namespace std;

signed main() {
  vector<int>vec(4);
  rep(i,4) cin>>vec.at(i);
  int ans=0;
  sort(vec);
  if(vec.at(0)==1) {
    ans++;
  }
  if(vec.at(1)==4) {
    ans++;
  }
  if(vec.at(2)==7) {
    ans++;
  }
  if(vec.at(3)==9) {
    ans++;
  }
  if(ans==4) {
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
}

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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >>A >> B >> U;
  
  if (S == U ) {
    cout << A - 1 << ' ' << B << endl;
  }
  else {
    cout << A << ' ' <<  B - 1 << endl;
  }
 }


Measured memory_bytes: 256