akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,k;
vector<int> v[100010];
int a[200010][2];
int ans[100010],col[100010];
vector<int> vi;
int t;
void dfs(int x)
{
	col[x]=t;
	vi.push_back(x); 
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (!col[xi]) dfs(xi);
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=0;i<m+k;i++)
	{
		cin >>a[i][0]>>a[i][1];
		a[i][0]--,a[i][1]--;
		if (i<m)
		{
			v[a[i][0]].push_back(a[i][1]);
			v[a[i][1]].push_back(a[i][0]);
		}
	}
	for (int i=0;i<n;i++)
	{
		if (col[i]) continue;
		t++,vi.clear();
		dfs(i);
		for (int j=0;j<vi.size();j++) ans[vi[j]]=(int)vi.size()-1;
		//cout <<vi.size()<<" ##\n";
	}
	for (int i=0;i<m+k;i++)
	{
		if (col[a[i][0]]==col[a[i][1]])
		{
			ans[a[i][0]]--,ans[a[i][1]]--;
			//cout <<a[i][0]<<" "<<a[i][1]<<" ##\n";
		}
	}
	for (int i=0;i<n;i++) printf("%d ",ans[i]);
	return 0;
} 

Measured memory_bytes: 9588
//ABC075 - C
#include <iostream>
#include <algorithm>
using namespace std;

const int limit = 50;

int N,M;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v] = true;
    for(int v2=0;v2<N;v2++){
        if(graph[v][v2]==true && visited[v2]==false){
            dfs(v2);
        }
    }
}

int main() {
    cin >> N >> M;
    int a[M], b[M];
    for(int i=0;i<M;i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int answer = 0;
    for(int i=0;i<M;i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int j=0;j<N;j++) visited[j] = false;

        dfs(0);

        bool bridge = false;
        for(int j=0;j<N;j++){
            if(visited[j]==false) bridge = true;
        }
        if(bridge) answer++;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    cout << answer <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int n, d;
    cin >> n >> d;

    vector< vector<lint> > x(n, vector<lint>(d));
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }

    int ans = 0;
    rep(i, n){
        REP(j, i + 1, n){
            lint t = 0;
            rep(k, d){
                t += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            lint s = sqrt(t);
            if(s * s == t){
                ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    };
    let x = x.abs();
    let alpha = x / d;
    // let beta = x % d;
    let beta = x - alpha * d;
    println!(
        "{}",
        if k <= alpha {
            x - k * d
        } else {
            if (k - alpha) % 2 == 0 {
                beta
            } else {
                d - beta
            }
        }
    )
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int P[250000];
int dist[550][550];
bool absent[550][550];
void dfs(int y, int x) {
    dist[y][x]--;
    rep(i, 4) {
        int ny = y + DY[i], nx = x + DX[i];
        if (ny < 0 || nx < 0 || ny >= N || ny >= N) { continue; }
        if ((dist[ny][nx] == dist[y][x] + 1 && absent[ny][nx]) || (dist[ny][nx] == dist[y][x] + 2 && !absent[ny][nx])) {
            dfs(ny, nx);
        }
    }
}
signed main() {
    cin >> N;
    rep(i, N * N) {
        cin >> P[i];
        P[i]--;
    }
    rep(i, N) {
        rep(j, N) {
            dist[i][j] = min({i + 1, j + 1, N - i, N - j});
        }
    }
    int ans = 0;
    rep(i, N * N) {
        int y = P[i] / N, x = P[i] % N;
        ans += dist[y][x] - 1;
        dfs(y, x);
        absent[y][x] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 23468
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll       long long
#define ull       unsigned long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		string s;
		cin >> s;
		int cnt = 0,res = 0, length;
		for (int i=0 ; i<(int)s.length() ; i++)
		{
			length = 0;
			for (int j=i ; j<(int)s.length() ; j++)
			{
			if ((s[j] == 'A') || (s[j] == 'C') || (s[j] == 'G') || (s[j] == 'T'))
			length++;	
			
			else
			break;
		}
		if (length > res) res = length;
		}
		cout << res << endl;
		return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define endstring std::string::npos
#define prtarr(n,len) {for(int i=0;i<len;i++) cout<<n[i]<<" "; cout<<"\n";}
#define prtpair(n) {cout<<n.fr<<" "<<n.sc<<"\n";}
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;
int judge(int x,int y){
    cout<<"? "<<x+1<<" "<<y+1<<endl;
    int a; cin>>a;
    return a;
}

int n;
vector<int64_t> lists;
int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    cin>>n;
    int judge= (n==1) ? 0:1;
    cout<<judge;

    return 0;
}




Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct w{string s;long p;
w(string s_,long p_):s(s_),p(p_){}
};
class cm{
public:
bool operator()(const w& a,const w& b){
if(a.s==b.s)return a.p<b.p;
else return a.s<b.s;
}
};
int main(){
vector<w> ww;
long p,i,j,n,f;
string s;
while(cin>>s>>p){
ww.push_back(w(s,p));
}
sort(ww.begin(),ww.end(),cm());
n=ww.size();
for(i=0;i<n;i++){
cout<<ww[i].s<<endl;f=0;
for(;i<n;i++){
if(f>0)cout<<" ";cout<<ww[i].p;f=1;
if(i<n-1&&ww[i].s!=ww[i+1].s){cout<<endl;break;}
}
}
cout<<endl;
return 0;
}

Measured memory_bytes: 1232
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

H, W =LI()
N = I()
a = LI()
c = [[0]*W for i in range(H)]
k = int(0)
cur = int(0)
kin = int(0)
for i,anum in enumerate(a):
#    print(k,cur)
    for j in range(anum):
#        print(k,j)
        if cur%2==0 and (k+j)==W:
            cur +=1
            k = j-1
        if cur%2==1 and (W-j+k)==-1:
            cur +=1
            k = -j
        if cur%2==0:
            c[cur][k+j] = i+1
        else:
            c[cur][W-j+k] = i+1

    if cur % 2 == 0:
        k = k+j+1
    else:
        k = -j+k-1

for v in c:
    print(" ".join(map(str,v)))



Measured memory_bytes: 40688
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll K; cin >> K;
	ll sev = 7, cnt = 1;
	bool flag = 0;
	map<ll, int> mp;
	for (int i = 0; i < 1e7 && !flag; i++) {
		if (sev % K == 0)break;
		if (mp[sev] != 0)flag = true;
		mp[sev]++;
		sev *= 10;
		sev += 7;
		sev %= K;
		cnt++;
		//cout << sev << endl;
	}

	cout << (flag ? -1 : cnt) << endl;
}



Measured memory_bytes: 65992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	//static int coins[];
	static int coin_hash[] = {1, 5, 10, 50, 100, 500};
	static int min_coin;
	static int coins[];

	public static void main(String args[]){
		// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		while(true){
			int price = scanner.nextInt();
			if(price == 0) return;

			coins = new int[6];
			int all_sum = 0;
			for(int i = 0; i < 6; i++){
				coins[i] = scanner.nextInt();
				all_sum += coin_hash[i] * coins[i];
			}

			min_coin = 0;
			//System.out.println(all_sum);
			//System.out.println(priceToCoins(price));
			//System.out.println(priceToCanCoins(price));

			int max_change = Math.min(500, all_sum - price);
			//System.out.println("Max change: " + max_change);

			for(int i = 0; i <= max_change; i++){
				// ここでコインの数数える
				int pay_coin = priceToCanCoins(price + i);
				//System.out.println("pay cpin:" + pay_coin);
				if(pay_coin == -1) continue;

				int change_coin = priceToCoins(i);
				int sum_coin = pay_coin + change_coin;

				if(min_coin == 0){
					min_coin = sum_coin;
				}else if(min_coin > sum_coin){
					min_coin = sum_coin;
				}
			}
			System.out.println(min_coin);
		}
	}

	static int priceToCoins(int price){
		int count = 0;
		while(price >= 500){
			count++;
			price -= 500;
		}
		while(price >= 100){
			count++;
			price -= 100;
		}
		while(price >= 50){
			count++;
			price -= 50;
		}
		while(price >= 10){
			count++;
			price -= 10;
		}
		while(price >= 5){
			count++;
			price -= 5;
		}
		count += price;
		return count;
	}

	static int priceToCanCoins(int price){
		int count = 0;
		int c = 0;
		while(price >= 500 && c < coins[5]){
			c++;
			price -= 500;
		}
		count += c;
		c = 0;
		while(price >= 100 && c < coins[4]){
			c++;
			price -= 100;
		}
		count += c;
		c = 0;
		while(price >= 50 && c < coins[3]){
			c++;
			price -= 50;
		}
		count += c;
		c = 0;
		while(price >= 10 && c < coins[2]){
			c++;
			price -= 10;
		}
		count += c;
		c = 0;
		while(price >= 5 && c < coins[1]){
			c++;
			price -= 5;
		}
		count += c;
		if(price > coins[0]) return -1;
		count += price;
		return count;
	}


	static void print(int a[]){
		for(int i = 0; i < a.length; i++){
			System.out.print(a[i] + "\t");
		}
		System.out.println();
	}

	static void print(int m[][]){
		for(int i = 0; i < m.length; i++){
			for(int j = 0; j < m[i].length; j++){
				System.out.print(m[i][j] + "\t");
			}
			System.out.println();
		}
	}

	static void print(ArrayList<StringBuilder> array){
		for(int i = 0; i < array.size(); i++){
			System.out.println(array.get(i));
		}
	}
}

Measured memory_bytes: 21448
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
import itertools as it
import collections as cl
from collections import deque
import math
from functools import reduce
from collections import defaultdict
MOD = 10 ** 9 + 7

def li():
    return [int(x) for x in input().split()]


# dp[y][x]: (x, y)マスに行く経路の数

H, W = li()
maze = [list(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]

dp[0][0] = 1

for y in range(H):
    for x in range(W):
        if maze[y][x] == '#':
            continue
        if y > 0:
            dp[y][x] += dp[y-1][x]
        if x > 0:
            dp[y][x] += dp[y][x-1]
        dp[y][x] %= MOD

print(dp[H-1][W-1])

Measured memory_bytes: 120140
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    rep(i, S.size()) {
        if (S[i] == '?')
            S[i] = 'D';
    }

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	if ((N + 1) / 2 >= K) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if(a[0] == 5 &&  a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double eps=1e-12;
typedef struct point{
    double x,y;
    void input(){
        cin>>x>>y;
    }
}Point,Vector;

typedef struct line{
    Point x;
    Vector k;
}Line;

typedef struct sugment{
    Point x,y;
    void input(){
        x.input();
        y.input();
    }
}Sug;

//点积
double dot(Vector x,Vector y){
    return x.x*y.x+x.y*y.y;
}

//叉积
double cross(Vector x,Vector y){
    return x.x*y.y-x.y*y.x;
}

double getlen(Vector x){
    return sqrt(dot(x,x));
}

Vector getV(Point x,Point y){
    Vector v;
    v.x=y.x-x.x;
    v.y=y.y-x.y;
    return v;
}
//点在直线的投影
Point Projection(Line x,Point y){
    Point answ;
    answ = x.x;

    double len = dot(x.k,getV(x.x,y));
    len/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    Vector temp  = x.k;
    temp.x /=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    temp.y/=sqrt(x.k.x*x.k.x+x.k.y*x.k.y);
    answ.x+=temp.x*len;
    answ.y+=temp.y*len;
    return answ;
}
//点与直线的对称点
Point Reflection(Line x,Point y){
    Point half = Projection(x,y);
    Point answ;
    answ.x=y.x+2*(half.x-y.x);
    answ.y=y.y+2*(half.y-y.y);
    return answ;
}
//获取线段交点
Point getCP(Sug x,Sug y){
    Point a,b,c,d,z;
    a=x.x;
    b=x.y;
    c=y.x;
    d=y.y;
    z.x=((b.x - a.x) * (c.x - d.x) * (c.y - a.y) -
         c.x * (b.x - a.x) * (c.y - d.y) + a.x * (b.y - a.y) * (c.x - d.x)) /
        ((b.y - a.y) * (c.x - d.x) - (b.x - a.x) * (c.y - d.y));
    z.y=((b.y - a.y) * (c.y - d.y) * (c.x - a.x) -
         c.y * (b.y - a.y) * (c.x - d.x) + a.y * (b.x - a.x) * (c.y - d.y))
        / ((b.x - a.x) * (c.y - d.y) - (b.y - a.y) * (c.x - d.x));
    return z;
}

bool check_Intersection(Sug x,Sug y){
    return cross(getV(x.x,y.x),getV(x.x,y.y))*cross(getV(x.y,y.x),getV(x.y,y.y))<=0 && cross(getV(y.x,x.x),getV(y.x,x.y))*cross(getV(y.y,x.x),getV(y.y,x.y))<=0;
}

Point a[110];
int n;

double getArea(){
    double answ=0;
    for(int i=1;i<n;i++){
        answ+=cross(a[i],a[i+1]);
    }
    answ+=cross(a[n],a[1]);
    return answ/2.0;
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        a[i].input();
    }
    cout<<setprecision(1)<<setiosflags(ios::fixed)<<getArea()<<endl;
    return 0;
}


Measured memory_bytes: 3292
#coding: utf-8
import math

n = int(input())
x = [int(i) for i in input().split(" ")]
y = [int(i) for i in input().split(" ")]

d1 = d2 = d3 = di = 0
for i in range(n):
    d1 += abs(x[i] - y[i])
    d2 += abs(x[i] - y[i])**2
    d3 += abs(x[i] - y[i])**3
    if di < abs(x[i] - y[i]):
        di = abs(x[i] - y[i])

print(d1)
print(math.pow(d2, 1.0/2.0))
print(math.pow(d3, 1.0/3.0))
print(di)


Measured memory_bytes: 5712
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b&&a<c)
    {
        if(b<c)
        cout<<a<<" "<<b<<" "<<c<<endl;
        else
        cout<<a<<" "<<c<<" "<<b<<endl;
    }
    else if(b<c)
    {
        if(c<a)
        {
            cout<<b<<" "<<c<<" "<<a<<endl;
        }
        else
        cout<<b<<" "<<a<<" "<<c<<endl;
    }
    else
    {
        if(a<b)
        cout<<c<<" "<<a<<" "<<b<<endl;
        else
        cout<<c<<" "<<b<<" "<<a<<endl;
    }
    return 0;

}



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

int main(){
  int N, A, B, ans = 0;
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++){
    int sum = 0;
    sum += (i + 1) % 10
        + ((i + 1) / 10) % 10
        + ((i + 1) / 100) % 10
        + ((i + 1) / 1000) % 10
        + ((i + 1) / 10000) % 10;
    if(sum <= B && sum >= A) ans += i + 1;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        s: chars,
    }
    let arr = vec![
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
        'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
    ];
    let ans = s
        .iter()
        .map(|x| {
            let index = arr.iter().position(|a| a == x).unwrap();
            let index = (index + n) % 26;
            arr[index]
        })
        .collect::<String>();
    println!("{}", ans);
}


Measured memory_bytes: 4476
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

signed main() {
    //宣言
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        a -= d;
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        else if (a <= 0) {
            cout<<"No"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;


int main(){
    int C=1e6;
    vector<int> p;
    while(true){
        int x;cin>>x;
        if(!x)break;
        p.push_back(x);
    }
    int n=p.size();
    vector<int> bnum;
    for(int i=1;;++i){
        int x=i*(i+1)*(i+2)/6;
        if(x>=C)break;
        bnum.push_back(x);
    }
    int m=bnum.size();
    int dp[C+1];rep(i,C+1)dp[i]=mod;
    dp[0]=0;
    rep(i,C){
        rep(j,m){
            if(bnum[j]>i+1)break;
            chmin(dp[i+1],dp[i+1-bnum[j]]+1);
        }
    }
    vector<int> onum;
    rep(i,m){
        if(bnum[i]%2)onum.push_back(bnum[i]);
    }
    m=onum.size();
    int odd[C+1];rep(i,C+1)odd[i]=mod;
    odd[0]=0;
    rep(i,C){
        rep(j,m){
            if(onum[j]>i+1)break;
            chmin(odd[i+1],odd[i+1-onum[j]]+1);
        }
    }
    rep(i,n){
        cout<<dp[p[i]]<<" "<<odd[p[i]]<<endl;
    }
}



Measured memory_bytes: 10888
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

int gcd(int n, int m)
{
  if (n%m == 0) return m;
  else return (gcd(m, n%m));
}

long long lcm(int n, int m)
{
  return ((long long)n * m / gcd(n, m));
}

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

  if (A < B)
  {
    int C = B;
    B = A;
    A = C;
  }

  cout << lcm(A, B) << endl;
}

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

int primeCheck(int x)
{
	int a = 1;
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0) a = 0;
	}
	return a;
}

int main()
{
	int n, q = 0;
	cin >> n;
	int a[10000];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (primeCheck(a[i]) == 1) q++;
	}
	cout << q << endl;

}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int jouken = 0;

        while (jouken == 0) {
            int n = scanner.nextInt();
            int x = scanner.nextInt();
            int kazu = 0;
            if (n == 0 && x == 0) {
                break;
            }
            for (int i = 1; n >= i; i++) {
                for (int j = 1; n >= j; j++) {
                    for (int k = 1; n >= k; k++) {
                        int goukei = i + j + k;
                        if (i != k && k != j && j != i && goukei == x&&i>j&&j>k) {
                            kazu++;
                        }
                    }
                }
            }
            System.out.println(kazu);
        }
    }
}

Measured memory_bytes: 26536
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def gcd(a, b):
    return gcd(b, a % b) if b else a


def solve():
    n = f()[0]
    a = []
    for i in range(n):
        a.append(f()[0])

    lcm = a[0]

    for i in range(1,n):
        lcm = lcm*a[i]//gcd(lcm, a[i])

    print(lcm)


solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        int len=0;
        len=s.size();
        for(int i=0;i<len;i++)
        {
            if(s[i]==',')
            {
                cout<<" ";
            }
            else
            {
                cout<<s[i];
            }
        }
        cout<<endl;
    }
   return  0;
}



Measured memory_bytes: 256
def solve(n, k):
    ans = 0
    mod = int(1e9 + 7)
    for i in range(k, n + 2):
        lb = (i - 1) * i // 2
        ub = (n + n - i + 1) * i // 2
        ans += ub - lb + 1
        ans %= mod
        # print(ub-lb+1, ub, lb, i)
    return ans


def main():
    # print(solve(3, 2))
    # print(solve(200000, 200001))
    # print(solve(141421, 35623))
    print(solve(*[int(v) for v in input().split()]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63440
m = int(input())
a = list( map( int, input().split() ) )
b1 = a[0]
b2 = a[0]
for i in range(m):
  if a[i] > b1:
    b1 = a[i]
  elif a[i] < b2:
    b2 = a[i]
print(b1-b2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
 vector<ll> A(N);
  for(ll i=0;i<N;i++) {
cin>>A[i];
  }
  
double t=1;
  for(ll x:A) {
t*=x;
  }
  
double k=0;
  
  for(ll x:A) {
k+=t/x;
  }
  
  cout<<fixed<<setprecision(10);
  cout<<t/k<<endl;
}
  


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    int a[1040],b[1040],d[1040]={};
    int c[1040][15];
    int dp[5000][1140];
    cin >> N >> M;
    REP(i,M){
        cin >> a[i] >> b[i];
        REP(j,b[i]){
            cin >> c[i][j];
            c[i][j]--;
            d[i]+=(1<<(c[i][j]));
        }
        //cout << d[i] << endl;
    }
    
    REP(i,(1<<N)){
        REP(j,M+1){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    REP(j,M){
        REP(i,(1<<N)){
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
            dp[i|d[j]][j+1]=min(dp[i|d[j]][j+1],dp[i][j]+a[j]);
        }
    }
    //REP(j,M+1){REP(i,(1<<N)){cout << dp[i][j] << " ";}cout << endl;}
    int Ans=dp[(1<<(N))-1][M-1];
    if(Ans==INF)Ans=-1;
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 38784
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int h = scan.nextInt();
		int w = scan.nextInt();
		int oppai = scan.nextInt();
		int ans = 0;
		char c[][] = new char[h][w];
		
		for(int i=0;i<h;i++) {
			String s = scan.next();
			for(int j=0;j<w;j++) {
				c[i][j] = s.charAt(j);
			}
		}
		
		
		
		
		for (int i=0; i<(Math.pow(2,h)); i++) {
			ArrayList<Integer> pop_h = new ArrayList<Integer>();
			
			for (int j=0; j<h; j++) {
				if ((1&i>>j) == 1)  {
					pop_h.add(j);
				}
			}
			for (int k=0; k<(Math.pow(2,w)); k++) {
				ArrayList<Integer> pop_w = new ArrayList<Integer>();
				
				for (int l=0; l<w; l++) {
					if ((1&k>>l) == 1)  {
						pop_w.add(l);
					}
				}
				
				int now_check = 0;
				
				for(int l : pop_h) {
					for(int n : pop_w) {
						if(c[l][n] == '#') {
							now_check += 1;
						}
					}
				}
				
				if(now_check == oppai) {
					ans += 1;
				}
				
					
				
				
			}
			
			
			
			
		}
		
		System.out.println(ans);
		
		
		
	}
	
	
	public static int gcd(int x,int y) {
		if(x%y == 0) {
			return y;
		}else {
			return gcd(y,x%y);
		}
	}
}
 


Measured memory_bytes: 37368
n,m = map(int,input().split())
dic = {}
for i in range(m):
    s = list(map(int,input().split()))[1:]
    dic[i] = s
P = list(map(int,input().split()))
# print(dic)

ans = 0

# ON/OFFをbit全探索
for i in range(2**n):
    on_off = [False]*n
    for j in range(n):
        if ((i>>j)&1):
            on_off[j] = True
    flag = True
    for k in range(m):
        cnt = 0
        for l in dic[k]:
            if on_off[l-1]:
                cnt += 1
        if cnt % 2 != P[k]:
            flag = False
    if flag:
        ans += 1
print(ans)

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

int main(){
  int N;cin>>N;
  vll L(N);rep(i,N)cin>>L[i];
  sort(all(L));
  ll ans=0;
  for(int i=0;i<N-2;++i){
    for(int j=i+1;j<N-1;++j){
      for(int k=j+1;k<N;++k){
        if(L[i]==L[k] || L[i]==L[j] || L[k]==L[j]) continue;
        if(L[i]+L[j]>L[k] ) ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
	public static void main (String [] args){
		Scanner s = new Scanner (System.in);
		String inter = s.nextLine().trim();
		String [] interArr = inter.split(" ");
		int H = Integer.parseInt(interArr[0]);
		int W = Integer.parseInt(interArr[1]);
		ArrayList <String> strings = new ArrayList <String>();
		for (int i = 0; i < H; i++){
			strings.add(s.nextLine());
		}
		char [][] matrix = new char [H][W];
		for (int x = 0; x < H; x++){
			for (int y = 0; y < W; y++){
				matrix[x][y] = strings.get(x).charAt(y);
			}
		}
		String [][] matrixOut = new String[H][W];
		for (int x = 0; x < H; x++){
			for (int y = 0; y < W; y++){
				int counter = 0;
				if (matrix[x][y] == '.'){
					if (x - 1 >= 0){
						if (matrix [x-1][y] == '#') counter++;
					}
					if (y - 1 >= 0){
						if (matrix [x][y-1] == '#') counter++;
					}
					if (x -1 >= 0 && y - 1 >= 0){
						if (matrix [x-1][y-1] == '#') counter++;
					}
					if (x + 1 < H){
						if (matrix [x+1][y] == '#') counter++;
					}
					if (y + 1 < W){
						if (matrix [x][y + 1] == '#') counter++;
					}
					if (x + 1 < H && y + 1 < W){
						if (matrix [x+1][y+1] == '#') counter++;
					}
					if (x + 1 < H && y - 1 >= 0){
						if (matrix [x+1][y-1] == '#') counter++;
					}
					if (y + 1 < W && x - 1 >= 0){
						if (matrix [x-1][y+1] == '#') counter++;
					}
					matrixOut[x][y] = Integer.toString(counter);
				} else {
					matrixOut[x][y] = Character.toString(matrix[x][y]);
				}
			}
		}
		// print matrix
		for (int x = 0; x < H; x ++){
			String out = "";
			for (int y = 0; y < W; y ++){
				out += (matrixOut[x][y]);
			}
			System.out.println(out);
		}
		
	}
	
}


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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
#define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out( 
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cout << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    stringstream ss; ss << H;
    cout << args[idx] << "- " << ss.str() << ", ";
    debug_out(args, idx + 1, LINE_NUM, T...);
}


void doit(){
	ll n,i,j,k,ans=0;
	cin >> n;
	rep(i,1,n+1){
		rep(j,1,n+1){
			rep(k,1,n+1){
				 ans +=__gcd(__gcd(i,j) , k);
			}
		}
	}
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

// int ten[20][20];

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;

	vector<vector<int> > ten(20, vector<int>(20, 0));
	ll cnt = 0;
	REP(i, n) {
		double x; cin >> x;
		ll tmp = x * 1e9 + 0.1;
		int two = 0;
		int five = 0;
		while (tmp % 2 == 0) {
			tmp /= 2;
			two++;
		}
		while (tmp % 5 == 0) {
			tmp /= 5;
			five++;
		}
		if (two > 18) two = 18;
		if (five > 18) five = 18;
		for (int j = 18 - two; j <= 18; j++)
			for (int k = 18 - five; k <= 18; k++)
				cnt += ten[j][k];
		ten[two][five]++;
	}

	cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long A[200000];
long B[200000];
void Calc(){
	int N = rei()*2;
	int Q = rei();
	for(int i=0;i<N;i++){
		A[i] = rel();
	}
	for(int i=0;i<N;i++){
		B[i] = rel();
	}
	priority_queue<long,vector<long>,greater<long>> Abigger;
	priority_queue<long,vector<long>,greater<long>> Abiggerdelete;
	priority_queue<long,vector<long>,greater<long>> Bbigger;
	priority_queue<long,vector<long>,greater<long>> Bbiggerdelete;
	int Anum = 0;
	int Bnum = 0;
	long sum = A[0] + A[N-1];
	for(int i=1;i<N-1;i++){
		if(A[i] >= B[i]){
			Abigger.push(A[i]-B[i]);
			Anum++;
			sum += A[i];
		}
		else{
			Bbigger.push(B[i]-A[i]);
			Bnum++;
			sum += B[i];
		}
	}
	for(int query=0;query<Q;query++){
		int p = rei()-1;
		if(p == 0 || p == N-1){
			sum -= A[p];
		}
		else{
			if(A[p] >= B[p]){
				sum -= A[p];
				Abiggerdelete.push(A[p]-B[p]);
				Anum--;
			}
			else{
				sum -= B[p];
				Bbiggerdelete.push(B[p]-A[p]);
				Bnum--;
			}
		}
		A[p] = rel();
		B[p] = rel();
		if(p == 0 || p == N-1){
			sum += A[p];
		}
		else{
			if(A[p] >= B[p]){
				Abigger.push(A[p]-B[p]);
				Anum++;
				sum += A[p];
			}
			else{
				Bbigger.push(B[p]-A[p]);
				Bnum++;
				sum += B[p];
			}
		}
		long ans = sum;
		if(Anum % 2){
			while(!Abiggerdelete.empty() && Abigger.top() == Abiggerdelete.top()){
				Abigger.pop();
				Abiggerdelete.pop();
			}
			while(!Bbiggerdelete.empty() && Bbigger.top() == Bbiggerdelete.top()){
				Bbigger.pop();
				Bbiggerdelete.pop();
			}
			ans -= min(Abigger.top(),Bbigger.top());
		}
		cout << ans << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 8932
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	char c;
	int a=0;
	fori(4){
		cin>>c;
		if(c=='+'){
			++a;
		}else{
			--a;
		}
	}
	cout<<a;
}

Measured memory_bytes: 256
M, D = map(int, input().split(' '))
c = 0
for m in range(1,M+1):
  for d in range(22,D+1):
    d_1 = int(str(d)[1])
    d_10 = int(str(d)[0])
    if d_1>=2:
      if d_1*d_10==m:
      	c += 1
        
print(c)

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

int main()
{
    cout << fixed << setprecision(10);
    long long n,m;
    cin >> n >> m;
    
    if(n%m==0) {
        cout << 0 << endl;
    }
    else {
        long long x = n%m;
        long long y = abs(x-m);
        cout << min(x,y) << endl;
    }
     

    
    return 0;
}

Measured memory_bytes: 256
// Try DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let h = get!(usize);
    let w = get!(usize);
    let k = get!(usize);
    let mut cake = vec![];
    for _ in 0..h {
        cake.push(get().as_bytes());
    }
    let mut ans = vec![vec![0; w]; h];
    let mut id = 1;
    for (i, row) in cake.iter().enumerate() {
        let count = row.iter().filter(|c|**c==b'#').count();
        if count == 0 {
            continue;
        }
        let mut tmp = 0;
        for (j, ch) in row.iter().enumerate() {
            ans[i][j] = id;
            if *ch == b'#' {
                tmp += 1;
                if tmp < count && id < k {
                    id += 1;
                }
            }
        }
        id += 1;
    }
    for i in 1..h {
        if ans[i][0] != 0 || ans[i-1][0] == 0 {
            continue;
        }
        for j in 0..ans[i].len() {
            ans[i][j] = ans[i-1][j];
        }
    }
    for i in 1..h {
        let i = (h-1) - i;
        if ans[i][0] != 0 || ans[i+1][0] == 0 {
            continue;
        }
        for j in 0..ans[i].len() {
            ans[i][j] = ans[i+1][j];
        }
    }
    for i in 0..h {
        for j in 0..w {
            if j > 0 { print!(" "); }
            print!("{}", ans[i][j]);
        }
        println!();
    }
    
}

Measured memory_bytes: 4860
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(), M=sc.nextInt(),X=sc.nextInt(),Y=sc.nextInt();
		int x[] = new int[N];
		int y[] = new int[M];
		for(int i=0;i<N;i++)x[i]=sc.nextInt();
		for(int i=0;i<M;i++)y[i]=sc.nextInt();
		sc.close();
		String ans = "No War";
		
		Arrays.sort(x);
		int Zmin = x[N-1]+1;
		
		Arrays.sort(y);
		int Zmax = y[0];
		
		if(X>=Zmax) ans = "War";
		if(Y<Zmin) ans = "War";
		if(Zmax<Zmin) ans = "War";
	
		System.out.println(ans);
 	}
}


Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ar[100006];
    for(int i=0; i<n; i++)
    {
        cin>>ar[i];
    }
    int count=0,ans =0,hey= ar[0];
    for(int i=1; i<n; i++)
    {
    	if(hey>=ar[i]) count++;
    	else count=0;
    	ans = max(ans,count);
    	hey = ar[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

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

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

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, a, b = 0, ans = 0;
	stack<int> sta;
	
	cin>>N;
	
	sta.push(0);
	
	for(int i = 0; i < N; i++){
		cin>>a;
		while(sta.top() > a) sta.pop();
		
		if(sta.top() < a){
			ans++;
			sta.push(a);
		} 
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 4364
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = input()
    if N[-1] == "3":
        print("bon")
    elif N[-1] in ["0","1","6","8"]:
        print("pon")
    else:
        print("hon")

if __name__ == '__main__':
    main()


Measured memory_bytes: 10340
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        long sum = 0;
        for(int i=0; i<n; i++) {
            int num = sc.nextInt();
            map.put(num, map.getOrDefault(num, 0) + 1);
            sum += num;
        }
        int q = sc.nextInt();
        for(int i=0; i<q; i++) {
            int b = sc.nextInt();
            int c = sc.nextInt();

            if(!map.containsKey(b)) {
                System.out.println(sum);
                continue;
            }

            int count = map.get(b);
            long diff = ((long)c - b) * (long)count;
            sum += diff;
            System.out.println(sum);
            map.remove(b);
            map.put(c, map.getOrDefault(c, 0) + count);
        }

    }




}

Measured memory_bytes: 67188
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n, k, sum, l[55];
	while (cin>>n>>k)
	{
		sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> l[i];
		}
		sort(l, l + n, cmp);
		for (int i = 0; i < k; i++)
		{
			sum += l[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vll xs(n), vs(n);
    vll sum(n + 1);
    rep(i, n) cin >> xs[i] >> vs[i], sum[i + 1] = sum[i] + vs[i];
    int sqn = sqrt(n);

    vll tbl(sqn+1);
    auto calc = [&](int l, int r){ return sum[r] - sum[l]; };

    vi idxs;
    rep(i, n){
        int idx = i / sqn;
        if(i % sqn == 0) idxs.emplace_back(i);
        chmax(tbl[idx], calc(idx*sqn, i+1) - (xs[i] - xs[idx*sqn]));
    }
    int m = idxs.size();

    ll res = 0;
    rep(i, n){
        ll cur = 0;
        int tmp = i;
        while(tmp < n and tmp % sqn != 0){
            cur += vs[tmp];
            chmax(res, cur - (xs[tmp] - xs[i]));
            tmp++;
        }
        if(tmp == n) continue;
        cur -= (xs[tmp] - xs[i]);
        rep(j, tmp / sqn, m){
            chmax(res, cur + tbl[j]);
            if(j < m - 1){
                cur += calc(idxs[j], idxs[j + 1]) - (xs[idxs[j + 1]] - xs[idxs[j]]);
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5120