akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  if(a+b>9)cout<<"error"<<endl;
  else cout<<a+b<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N = -1000000009;
int main(void){
    int n,*A,max= N,k;
    cin >> n;
    A = new int[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(i!=0 && A[i]>A[k]){
                break;
            }
            else if(A[j]-A[i]>max){
                max = A[j] - A[i];
                k = i;
            }
        }
    }
    cout << max << endl;
    delete[] A;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
using namespace std;
double calc(int r, double before) {
    if(r % 2 == 0) return((double)before / 3.0);
    else           return((double)before * 2.0);
}

int main(void) {
    double a;
    while(cin >> a) {
        double ary[10]; ary[0] = a;
        double sum = a;
        for(int r = 1; r < 10; r++) {
            ary[r] = calc(r, ary[r - 1]); sum += ary[r];
        }
        printf("%.8f\n", sum);
    }
    return(0);
}

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int arr[10];
	for (int i = 1; i <= 5; ++i) {
		cin >> arr[i];
		if (arr[i] == 0) {
			cout << i;
		}
	}
}

Measured memory_bytes: 3640
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};
use std::collections::BTreeMap;

#[fastout]
fn main() {
   input! {
      n: usize,
      ma: usize,
      mb: usize,
      abc: [(usize, usize, usize); n]
   }

   let mut map = BTreeMap::new();
   map.insert((0, 0), 0);
   for &(a, b, c) in abc.iter() {
      let mut map2 = map.clone();
      for (&(an, bn), &cn) in map.iter() {
         map2
            .entry((an + a, bn + b))
            .and_modify(|v| *v = std::cmp::min(*v, cn + c))
            .or_insert(cn + c);
      }
      map = map2;
   }
   let inf = 1001001001001;
   let mut ans = inf;
   for (&(a, b), &c) in map.iter() {
      if a * b == 0 {
         continue;
      }
      if a * mb == b * ma {
         ans = std::cmp::min(ans, c);
      }
   }
   if ans != inf {
      println!("{}", ans);
   } else {
      println!("-1");
   }
}


Measured memory_bytes: 4096
class UnionFind:
    def __init__(self, n: int):
        self.nodes = n
        self.parents = [-1] * n
        self.rank = [0] * n

    # retrun the root of element x
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # unite the group include element x and group include element y
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # get size of the gourp which element x belongs
    def get_size(self, x):
        return -self.parents[self.find(x)]

    # check if element x and element y is same group
    def same(self, x, y):
        return self.find(x) == self.find(y)


def kruskal(n: int, edges: list):
    """
    n: count of nodes
    edges: list of edges, format: (node1,node2,weight)
    """
    union = UnionFind(n + 1)  # 1-indexed
    mst_sum = 0
    mst = []
    for edge in edges:
        n1, n2, w = edge
        if not union.same(n1, n2):
            union.unite(n1, n2)
            mst_sum += w
            mst.append(edge)
    return mst, mst_sum


n = int(input())
graph_table = []

for _ in range(n):
    graph_table.append([int(i) for i in input().split()])

edges = []
# edge一覧を取得
for i in range(n - 1):
    for j in range(i + 1, n):
        if graph_table[i][j] != -1:
            edges.append((i, j, graph_table[i][j]))  # node1,node2,weight

# edgeを重みの昇順にソート
edges = sorted(edges, key=lambda x: x[2])

_, mst_sum = kruskal(n, edges)
print(mst_sum)



Measured memory_bytes: 6292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int shortest_length(int sy, int sx, int gy, int gx, vector<string> field, char block) {
    int h = field.size();
    int w = field[0].size();
    vector<vector<int>> d(h, vector<int> (w, INF));
    d[sy][sx] = 0;
    deque<P> que;
    que.push_back(make_pair(sy, sx));
    while (que.size()) {
        P p = que.front();
        que.pop_front();
        int y = p.first;
        int x = p.second;
        // if (x == gx && y == gy) break;

        for (int dy = -2; dy <= 2; dy++) {
            for (int dx = -2; dx <= 2; dx++) {
                if ((dy == 0 && dx == 0) || (dy == 0 && dx == -1) || (dy == 1 && dx == 0) || (dy == 0 && dx == 1) || (dy == -1 && dx == 0)) {
                    int ny = y + dy;
                    int nx = x + dx;
                    if (nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] != block && d[ny][nx] > d[y][x]) {
                        d[ny][nx] = d[y][x];
                        que.push_front(make_pair(ny, nx));
                        
                    }
                }
                else {
                    int ny = y + dy;
                    int nx = x + dx;
                    if (nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] != block && d[ny][nx] > d[y][x] + 1) {
                        d[ny][nx] = d[y][x] + 1;
                        que.push_back(make_pair(ny, nx));
                    }
                }
            }
        }
    }
    if (d[gy][gx] == INF) return -1;
    return d[gy][gx];
}

int main() {
    int h, w;
    int cx, cy, dx, dy;
    cin >> h >> w >> cy >> cx >> dy >> dx;
    cx--, cy--, dy--, dx--;
    vector<string> field(h);
    rep(i,h) {
        cin >> field[i];
    }
    int ans = shortest_length(cy, cx, dy, dx, field, '#');
    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int t[N<<1],nxt[N<<1],lst[N],l;
void add(int x,int y) {t[++l]=y;nxt[l]=lst[x];lst[x]=l;}

int n,m,u,v,deg[N],cnt;
bool vis[N];

void dfs(int x) {
	if (x==v) {cnt++;return;}
	vis[x]=1;
	rep(i,x) if (!vis[t[i]]) dfs(t[i]);
}

int main() {
	n=read();m=read();
	fo(i,1,m) {
		int x=read(),y=read();
		add(x,y);add(y,x);
		deg[x]++;deg[y]++;
	}
	fo(i,1,n) if (deg[i]&1) {puts("No");return 0;}
	int mx=0;fo(i,1,n) mx=max(mx,deg[i]);
	if (mx>=6) {puts("Yes");return 0;}
	if (mx<=2) {puts("No");return 0;}
	u=0,v=0;
	fo(i,1,n) 
		if (deg[i]==4) {
			if (!u) u=i;
			else if (!v) v=i;
			else {puts("Yes");return 0;}
		}
	if (!v) {puts("No");return 0;}
	cnt=0;dfs(u);
	puts(cnt==2?"Yes":"No");
	return 0;
}

Measured memory_bytes: 2944
# ABC135A-137B.py

SELECT = "13" + "567"[0] + "ABC"[2]


if SELECT == "135A":  # Harmony

    a, b = map(int, input().split())  # Ex. (6,10)
    c = abs(a - b)  # 4
    if c % 2 == 0:  # 2
        print(c // 2 + min((a, b)))  # 8. OK.
    else:
        print("IMPOSSIBLE")


if SELECT == "135B":  # 0 or 1 Swap

    input()
    nums = list(map(int, input().split()))

    # ソート検査
    count = 0
    for i in range(len(nums)):
        if nums[i] != (i + 1):
            count += 1
    if count < 3:
        print("YES")
    else:
        print("NO")


if SELECT == "135C":  # CitySaver

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = 0
    for i in range(n):
        if a[i] < b[i]:
            count += a[i]
            d = b[i] - a[i]

            if a[i + 1] < d:
                count += a[i + 1]
                a[i + 1] = 0
            else:
                count += d
                a[i + 1] -= d

        else:
            count += b[i]

    print(count)


Measured memory_bytes: 18752
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
typedef long long ll;
using namespace std;
double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	ll X,N,K1=0,K2=101;
	vector<ll>V(102,0);
	cin>>X>>N;
	rep(i,N){
		ll t;
		cin>>t;
		V[t]=1;
	}
	for(ll i=X;i>=1;i--){
		if(V[i]==0){
			K1=i;
			break;
		}
	}
	for(ll i=X;i<=100;i++){
		if(V[i]==0){
			K2=i;
			break;
		}
	}
	if(abs(X-K1)<=abs(X-K2)){
		cout<<K1<<endl;
	}
	else{
		cout<<K2<<endl;
	}
}


Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main( void ){
    int l,n;
    int p;
    string a;
    cin >> n;
    cin >> a;
    l = a.length();

    for(int i=0;i<l;i++){
        p = a[i] - 'A';
        p += n;
        while(p>25) p -= 26;
     
        p = p + 'A';
        a[i] = (char) p;

    }

    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int L[200005];
int R[200005];
int D[200005];

vector<pair<int,int>> E[100005];
vector<pair<int,int>> EE[100005];

int visit[100005];
int x[100005];

void dfs(int pos,int value){
	if(visit[pos] == 1){return;}

	visit[pos] =1;
	x[pos]  = value;

	int i;

	for(i = 0;i < E[pos].size();i++){
		dfs(E[pos][i].first,value+E[pos][i].second);
	}

	for(i = 0;i < EE[pos].size();i++){
		dfs(EE[pos][i].first,value + EE[pos][i].second);
	}

}

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i;

	for(i = 0;i < M;i++){
		 scanf("%d %d %d",&L[i],&R[i],&D[i]);
		 E[L[i]].push_back(make_pair(R[i],D[i]));
		 EE[R[i]].push_back(make_pair(L[i],-D[i]));
	}

	for(i = 0;i < M;i++){
		dfs(L[i],0);
	}

	for(i = 0;i < M;i++){
		if(x[R[i]] - x[L[i]] != D[i]){
			cout<<"No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 18048
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_C() {}
#else

#endif

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

    int N, M;  cin >> N >> M;

    int x = 1900 * M + 100 * (N - M);
    int one_over_p = 0x01 << M;

    int ans = x*one_over_p;
    cout << ans << endl;

    return 0;
}

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

int N, h[100000];
int dp[100000];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<long> L(N+1);
    L.at(0) = 2;
    L.at(1) = 1;

    for (int i = 2; i <= N;i++){
        L.at(i) = L.at(i - 1) + L.at(i - 2);
    }
    cout << L.at(N) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    ll cnt0 = 0, cnt1 = 0;
    rep(i, n) {
        if(s[i] == '0') {
            cnt0++;
        }
        else {
            cnt1++;
        }
    }

    out(2*min(cnt0, cnt1));
    re0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.TreeSet;

public class Main {
	@SuppressWarnings("unchecked")
	void run() {
		MyScanner sc = new MyScanner();

		L: while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int[][] f = new int[n][31];
			for (int i = 0; i < n; i++) {
				int m = sc.nextInt();
				for (int j = 0; j < m; j++) {
					f[i][sc.nextInt()] = 1;
				}
			}

			TreeSet<Integer>[] set = new TreeSet[n];
			for (int i = 0; i < n; i++) {
				set[i] = new TreeSet<Integer>();
				set[i].add(i);
			}
			for (int day = 0; day < 31; day++) {
				for (int i = 0; i < n; i++) {
					if (f[i][day] == 0) continue;
					for (int j = 0; j < n; j++) {
						if (f[j][day] == 0) continue;
						set[i].addAll(set[j]);
						set[j].addAll(set[i]);
					}
				}

				for (int i = 0; i < n; i++) {
					if (set[i].size() == n) {
						System.out.println(day);
						continue L;
					}
				}
			}
			System.out.println(-1);
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1125899906842624
#define MAX_L 1'000'000
i64 dp[MAX_L + 2][2];

int main() {
    string N; cin >> N;
    i64 L = N.length();
    reverse(N.begin(), N.end());

    REP(i, L + 2) REP(j, 2) dp[i][j] = INF;
    dp[0][0] = 0;
    REP(i, L + 1) {
        i64 n = 0;
        if (i < L) n = N[i] - '0';
        REP(j, 2) {
            if (dp[i][j] == INF) continue;
            for (i64 a = 0; a <= 9; a++) {
                i64 b = a - j - n;
                if (b < 0) {
                    b += 10;
                    chmin(dp[i + 1][1], dp[i][j] + a + b);
                } else {
                    chmin(dp[i + 1][0], dp[i][j] + a + b);
                }
            }
        }
    }

    cout << dp[L + 1][0] << endl;

    return 0;
}

Measured memory_bytes: 17052
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

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

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	lli n,a,b;
	cin>>n>>a>>b;
	lli ans=(n/(a+b))*a;
	n%=(a+b);
	ans+=min(n,a);
	cout<<ans;

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int min(int a,int b){
  return a > b ? b : a;
}

int main(){
 
  int N,L;
  cin >> N >> L;
  
  int sum = 0;
  int minimum = abs(L);
  bool flg = true;
  if(0 > L && N <= abs(L)) flg = false;
  for(int i = 0; i < N; ++i){
    int num = L + i;
    minimum = min(minimum,abs(num));
    sum += num;
  }
  if(flg) cout << sum - minimum << endl;
  else cout << sum + minimum << endl;
  
  return 0;
}

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

ll ans = 0;

ll dfs(ll n, ll d, ll point, vector<vector<ll>> g, vector<ll> check){
    if(d == n){
        ans++;
        return 0;
    }
    if(d > n) return 0;
    for(auto x:g[point]){
        vector<ll> tmp = check;
        if(check[x] < 0){
            tmp[x] = 1;
            dfs(n, d+1, x, g, tmp);
        }
    }
    return 0;
}

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

    vector<vector<ll>> g(n+1);
    for(int i = 0; i < m; i++){
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    vector<ll> check(n+1,-1);
    check[1] = 1;
    dfs(n,1,1,g,check);
    put(ans);
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    long n, r;
    cin >> n >> r;
    if (n < 10) {
        r += 100 * (10 - n);
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 888
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll dat[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
            1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

  cin >> n;
  n--;
  Cout(dat[n]);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

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

    int A[100][100];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            A[i][j] = 0;
        }
    }

    for(int i=0; i<n; i++){
        int u, k;
        scanf("%d %d", &u, &k);
        u--;
        for(int j=0; j<k; j++){
        int v;
        scanf("%d", &v);
        v--;
        A[u][v] = 1;    //uとvに辺を張る
        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j) printf(" ");
            printf("%d", A[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2772
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

int main() {
    int n;
    cin >> n;
    int x;
    x = n / 1000;
    if(n - x * 1000 > 0){
        cout << (x + 1) * 1000 - n << endl;
    } else {
        cout << 0 << endl;
    }
}



Measured memory_bytes: 3632
#include<iostream>
using namespace std;
const long long p = 1000000007;
int n;
long long inverse[100100];
long long a[100100];
long long comb[100010][2];
long long beki(long long i, long long k)
{
    if(k == 0){
        return 1;
    }
    if(k % 2 == 0){
        long long c = beki(i, k / 2);
        c = c % p;
        c = c * c;
        c = c % p;
        return c;
    } else {
        long long c = beki(i, k / 2);
        c = c % p;
        c = c * c;
        c = c % p;
        c = c * i;
        c = c % p;
        return c;
    }
}


long long combi(long long r, long long k)
{
    if(r < k){
        return 0;
    }
    int check = 0;
    if(r != n + 1){
        check = 1;
    }
    if(comb[k][check] != -1){
        return comb[k][check];
    }
    comb[k][check] = (combi(r, k - 1) * (r - k + 1)) % p;
    comb[k][check] = (comb[k][check] * inverse[k]) % p;
    return comb[k][check];
}

int main()
{
    comb[0][0] = 1;
    comb[0][1] = 1;
    for(int i = 1; i <= 100005; i++){
        comb[i][0] = -1;
        comb[i][1] = -1;
    }
    int invalid = 0;
    cin >> n;
    int position[100100];
    for(int i = 1; i <= n + 1; i++){
        cin >> a[i];
        position[i] = -1;
    }
    for(long long i = 1; i <= n + 1; i++){
        inverse[i] = beki(i, p - 2);
    }
    for(int i = 1; i <= n + 1; i++){
        if(position[a[i]] != -1){
            invalid = i - position[a[i]] + 1;
            break;
        }
        position[a[i]] = i;
    }
    for(int k = 1; k <= n + 1; k++){
        long long answer = combi(n + 1, k) - combi(n + 1 - invalid, k - 1);
        if(answer < 0){
            answer += p;
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int h,w,i,j;
    cin>>h>>w;
    char a[h][w];
    int row[h]={0},col[w]={0};
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
        {
            cin>>a[i][j];
            if (a[i][j]=='#')
            {
                row[i]++;
                col[j]++;
            }
        }
    }
    for (i=0;i<h;i++)
    {
        if (row[i]!=0)
        {
            for (j=0;j<w;j++)
            {
                if (col[j]!=0)
                    cout<<a[i][j];
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] S = new String[H];
        char[][]t = new char[H][W];
        String a = "#";
        char b = a.charAt(0);
        int[] dx = {1, 0, -1, 0, 1, -1, -1, 1};
        int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};

        for(int i=0; i<H; i++){
            S[i] = sc.next();
            for(int j=0; j<W; j++){
                t[i][j] = S[i].charAt(j);
            }
        }
        String[][] ans = new String[H][W];
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(t[i][j]!=b){
                    int sum = 0;
                    for(int k=0; k<8; k++){
                        int x = i + dx[k];
                        int y = j + dy[k];
                        if(x<0 || x>=H){
                            continue;
                        }
                        if(y<0 || y>=W){
                            continue;
                        }
                        if(t[x][y]==b){
                            sum += 1;
                        }
                    }
                    ans[i][j] = String.valueOf(sum);
                }
                else{
                    ans[i][j] = a;
                }
            }
        }
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                System.out.print(ans[i][j]);
            }
            System.out.print("\n");
            
        }
    }
}

Measured memory_bytes: 24404
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, n, m, k);
    make(int, x1, y1, x2, y2);
    x1--, y1--, x2--, y2--;
    vector<string> a(n);
    for (auto &s : a) {
        cin >> s;
    }
    if (a[x1][y1] == '@') {
        cout << -1;
        return 0;
    }
    VVI dist(n, VI(m, -1));
    dist[x1][y1] = 0;
    queue<PII> q;
    q.emplace(x1, y1);
    VI dx = {-1, 0, 0, 1};
    VI dy = {0, -1, 1, 0};
    while (!q.empty()) {
        auto p = q.front();
        int x = p.first;
        int y = p.second;
        q.pop();
        for (int i = 0; i < 4; ++i) {
            for (int j = 1; j <= k; ++j) {
                int xx = x + dx[i] * j;
                int yy = y + dy[i] * j;
                if (xx < 0 || xx >= n || yy < 0 || yy >= m || a[xx][yy] == '@') {
                    break;
                }
                if (dist[xx][yy] == -1){
                    dist[xx][yy] = dist[x][y] + 1;
                    q.emplace(xx, yy);
                } else if (dist[xx][yy] == dist[x][y]){
                    break;
                }
            }
        }
    }
    cout << dist[x2][y2];

    return 0;
}

Measured memory_bytes: 19880
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    
    ll d,g;
    cin >> d >> g;
    vector<ll> p(d,0),c(d,0);
    ll ans = 1e12;
    rep0(i, d)cin >> p[i] >> c[i];
    rep0(i, (1 << (d + 1))){
        ll sum = 0, cnt = 0;
        rep0(j, d){
            if((i >> j) & 1){
                sum += p[j] * (j + 1) * 100 + c[j];
                cnt += p[j];
            }
        }
        
        if(sum >= g)ans = min(ans,cnt);
        else{
            rrep0(j, d){
                if((i >> j) & 1)continue;
                if(sum >= g)continue;
                ll q = min((g - sum)/((j+1) * 100), (ll)p[j]);
                cnt += q;
                sum += (j+1) * 100 * q;
            }
        }
        
        if(g <= sum)ans = min(ans, cnt);
    }
    pf(ans)
    return 0;
}


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

int main(){
	int n;
	long sum = 0;
	long ans = 9223372036854775807;
	cin >> n;
	long aSum[200005];
	for (int i = 0; i < n; i++) {
		long temp;
		cin >> temp;
		sum += temp;
		aSum[i] = sum;
	}
	for (int i = 0; i < n - 1; i++) {
		if (labs(aSum[i] * 2 - aSum[n - 1]) < ans) {
			ans = labs(aSum[i] * 2 - aSum[n - 1]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dp[100005];

int main() {
  int N, W;
  cin >> N >> W;
  rep(i, N) {
    int w, v;
    cin >> w >> v;
    for (int j = W-1; j >= 0; j--) {
      if (j+w > W) continue;
      dp[j+w] = max(dp[j+w], dp[j] + v);
    }    
  }
  ll ans = 0;
  for (int i = 0; i <= W; i++) {
    if (dp[i] > ans) ans = dp[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

ll Euclidean(ll A, ll B)
{
    if(A < B) swap(A, B);
    ll r = A % B;
    while(r > 0) {
        A = B;
        B = r;
        r = A % B;
    }
    return B;
}

ll Main(ll A, ll B)
{
    ll r = Euclidean(A, B);
    // cout<<r<<endl;
    ll ans = 1;
    ll mx = r;
    for(ll i = 2; i*i <= mx; i++) {
        if(r%i) continue;
        else {
            ans++;
            while(!(r%i)) r/=i;
        }
    }
    if(r>1) ans++;
    return ans;
}

int main(void){
    ll A, B;
    cin >> A >> B;
    cout << Main(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int jdz(int a){
	if(a>0){
		return a;
	}else{
		return 0-a;
	}
}
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	b=a-b;
	c=a-c;
	if(jdz(b)>jdz(c)){
		cout<<"B";
	}else{
		cout<<"A";
	}
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		long A = scan.nextLong();
		long B = scan.nextLong();
		long sum = 0;
		for (int i = 0; i <= N; i++) {
			if(!func(i,A,B)){
				sum+=i;
			}
			
		}
		System.out.println(sum);
	}
	
	public static boolean func(long num,long A,long B){
		long temp = 0;
		do {
			temp += num % 10;
			num/=10;
		} while (num != 0);
		
		if(temp < A || temp > B){
			return true;
		}else{
			return false;
			
		}
		
		
	}

}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int z = 0, o = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != ('0' + i % 2)) {
      z++;
    }
    if (s[i] != ('1' - i % 2)) {
      o++;
    }
  }
  cout << min(z, o) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll dp[1002][1002];
ll func(string mat[],ll i, ll j,ll ans , ll n , ll m){
	
	if (dp[i][j]!=-1) return dp[i][j];
	if(i==n-1 && j==m-1)
		return 1;
	
	if(i>=n ||j>=m ||mat[i][j]=='#')
		return dp[i][j] = 0;

	return dp[i][j]= (func(mat , i, j+1 , ans,n,m) + func(mat ,i+1  ,j , ans,n,m) )%mod;
	
}
int main()
{
  	ll n , m ,i;
  	scanf("%lld %lld",&n, &m);
	memset(dp, -1, sizeof(dp));
  	string mat[n];
  	for(i=0;i<n;i++)
  		cin>>mat[i];
  	printf("%d",func(mat , 0 , 0 , 0 , n, m));
  	return 0;
  	
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

vvll hoge = {
  {0, 1},
  {1, 0}
};

vvll tmp(0);

string str;

void search(void){
  cin >> str;

  tmp.push_back(hoge[1]);
  tmp.push_back(hoge[0]);
}

int main(void){
  search();
  assert(tmp.size()>0);
  if(str=="ABC"){
    cout << "ARC";
  }else{
    cout << "ABC";
  }
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

template <typename T>
T mod_expt(T a, std::int64_t n, T mod){
    T power {1};
    while(n > 0){
        if(n & 1){power = power * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return power;
}

std::string S;
int cnt[2019];

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

  std::cin >> S;

  cnt[0] += 1;

  int n = S.size(), s = 0;
  ll res = 0;

  for(int i=n-1;i>=0;--i){
      s = (s + mod_expt<int>(10, (n-1)-i, 2019) * (S[i] - '0')) % 2019;
      res += cnt[s];
      cnt[s] += 1;
  }

  std::cout << res << std::endl;
}


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

int main() {

ll n; cin>>n;
 vector<ll>a(n); rep(i,n)cin>>a.at(i);
  sort(all(a));
  ll c=0;
  
  rep(i,n-2){
  REP(j,i+1,n-1){
  REP(k,j+1,n){
   
     if(a.at(k)<a.at(i)+a.at(j))
     { if(a.at(k)!=a.at(i)&&a.at(i)!=a.at(j)&&a.at(j)!=a.at(k))c++; }
  }
  }
  }
    cout<<c<<endl;
  
  
  
}


Measured memory_bytes: 3636
#include <atcoder/lazysegtree>
#include <iostream>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
ll mod = 998244353,pw1[200010],pw2[200010];
struct S{ll a,len,dig;};
struct F{ll x;};
S op(S l,S r){
    if(l.len>=r.len) return S{(l.a *pw1[l.len - r.len]+ r.a)%mod,r.len,l.dig + r.dig};
    return S{(r.a*pw1[r.len - l.len] + l.a)%mod,l.len,l.dig + r.dig};
}
S e(){return S{0,0,0};}
S mapping(F l,S r){
    if(l.x==-1) return r;
    return S{l.x*pw2[r.dig - 1]%mod,r.len,r.dig};
}
F composition(F l,F r){
    if(l.x==-1) return r;
    return l;
}
F id(){return F{-1};};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,n,q; cin >> n >> q;
    pw1[0] = 1;
    for(i=1;i<=n;i++) pw1[i] = pw1[i - 1]*10%mod;
    pw2[0] = 1;
    for(i=1;i<=n;i++) pw2[i] = (pw2[i - 1]*10 + 1)%mod;
    vector<S> v(n);
    for(i=0;i<n;i++) v[i] = {1,n - 1 - i,1};
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(v);
    for(i=0;i<q;i++){
        int l,r,d; cin >> l >> r >> d; l--;
        seg.apply(l,r,F{d});
        cout << seg.prod(0,n).a << "\n";
    }
}

Measured memory_bytes: 25356
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;


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

	ll n, a, b;
	cin >> n >> a >> b;

	if ((b - a - 1) & 1) {
		cout << (b - a) / 2 << "\n";
	}
	else {
		cout << min(b + a - 1, n - a + 1 + n - b) / 2 << "\n";
	}

	return 0;
}


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

int main(void)
{
  int group[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
  int x, y;
  cin >> x >> y;
  x--;
  y--;
  if (group[x] == group[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

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

using ll = long long;
#define INF 1e9

int N;
vector<int> ABC, l;
int main(){
  cin >> N;
  ABC.resize(3), l.resize(N+3);
  REP(i, 3){
    cin >> ABC[i];
  }
  REP(i, N){
    cin >> l[i];
  }
  l[N] = l[N+1] = l[N+2] = -1;
  sort(l.begin(), l.end());
  int ans = INF;
  while(next_permutation(l.begin(), l.end())){
    int cost = 0;
    vector<int> take(3, 0);
    int idx = 0, cnt = 0;
    bool flag = true;
    REP(i, N+3){
      if(l[i] != -1){
        take[idx]+= l[i];
        if(cnt != 0){
          cost += 10;
        }
        cnt++;
      }
      else{
        if(cnt == 0){
          flag = false;
          break;
        } 
        else{
          idx++;
          cnt = 0;
          if(idx == 3) break;
        }
      }
    }
    if(flag){
      REP(i, 3){
        cost += abs(take[i] - ABC[i]);
      }
      ans = min(cost, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007
#define INF 1<<30

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

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

int main(){
    int H, W, K;
    int x1, y1, x2, y2;
    cin >> H >> W >> K;
    //cin >> x1 >> y1 >> x2 >> y2;
    cin >> y1 >> x1 >> y2 >> x2;
    vector<string> c(H+2);
    REP(i, H) cin >> c[i+1];
    c[0] = string(W, '@');
    c[H+1] = string(W, '@');
    for(int i=0; i<H+2; i++){
        c[i] = "@" + c[i] + "@";
    }
    //REP(i, H+2)
    //    cerr << c[i] << endl;

    vector<vector<int>> dp(H+2, vector<int>(W+2, INF));
    dp[y1][x1] = 0;
    queue<pair<int, int>> que;
    que.emplace(y1, x1);
    while(!que.empty()){
        int y = que.front().first;
        int x = que.front().second;
        que.pop();
        for(int d=0; d<4; d++){
            int yy = y + dy[d];
            int xx = x + dx[d];
            if(c[yy][xx] == '@') continue;
            if(dp[yy][xx] <= dp[y][x]) continue;
            if(dp[yy][xx] == INF){
                dp[yy][xx] = dp[y][x] + 1;
                que.emplace(yy, xx);
            }
            for(int k=0; k<K-1; k++){
                yy += dy[d];
                xx += dx[d];
                if(c[yy][xx] == '@') break;
                if(dp[yy][xx] <= dp[y][x]) break;
                if(dp[yy][xx] == INF){
                    dp[yy][xx] = dp[y][x] + 1;
                    que.emplace(yy, xx);
                }
            }
        }
    }
    //for(int i=1; i<=H; i++){
    //    for(int j=1; j<=W; j++){
    //        cerr << dp[i][j] << " ";
    //    }
    //    cerr << endl;
    //}

    if(dp[y2][x2]==INF) cout << -1 << endl;
    else cout << dp[y2][x2] << endl;
    return 0;
}

Measured memory_bytes: 22824