akhauriyash/Code-Regression huggingface dataset:
#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	int n;cin>>n;
	int ans;cin>>ans;
	REP(i,0,n-2)
	{
		int t ;cin>>t;ans=__gcd(ans,t);
	}
	cout<<ans<<"\n";
	
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private struct Pair
    {
        public long x, y;
        public Pair(long x, long y) { this.x = x; this.y = y; }
        public long Max() { return Math.Max(x, y); }
        public long Min() { return Math.Min(x, y); }
    }
    public static void Solve()
    {
        int N = NextInt();
        Console.WriteLine((N-2)*180);
    }
    private static int LowerBound(long[] list, long n)
    {
        int a = 0, b = list.Count();
        if (list[b - 1] <= n) return b - 1;
        else if (list[a] > n) return -1;
        while (b - a != 1)
        {
            int x = (a + b) / 2;
            if (list[x] <= n) a = x;
            else b = x;
        }
        return a;
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

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

    map<string, int> m;

    for (int i = 0; i < n; i++) {

        string tmp_s; cin >> tmp_s;

        m[tmp_s] = -1;

    }

    cout << m.size() << endl;
    return 0;
}

Measured memory_bytes: 19204
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, sum1, sum2, sum3;
    cin >> a >> b >> c;
    
    sum1 = a + b;
    sum2 = b + c;
    sum3 = a + c;
    if(sum1 == c)
        cout << "Yes";
    else if(sum2 == a)
        cout << "Yes";
    else if(sum3 == b)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

void print(int n, vector< vector<int > > S){
	for (int i = 0; i < S.size(); i++){
		for (int j = 0; j < S.size(); j++){
			printf("%4d", S[i][j]);
		}
		cout << endl;
	}
}

void MagicSquare(int n){
	vector< vector<int > > S(n, vector<int > (n, 0));
	int gyo, retu, nowS=1;
	gyo = (n / 2) + 1;
	retu = (n / 2);
	
	S[gyo][retu] = nowS;
	nowS++;

	while (nowS <= n*n){
		// 右斜め下へ
		gyo++;
		retu++;
		while (1){
			if (gyo == n)	gyo = 0;
			if (retu == n)	retu = 0;
			else if (retu == -1)	retu = n - 1;

			if (S[gyo][retu] == 0)	break;
			else {
				// 左斜め下へ
				gyo++;
				retu--;
			}
		}
		// 格納してnowS++
		S[gyo][retu] = nowS;
		nowS++;
	}
	print(n, S);
}

int main(){
	int n;
	while (cin >> n, n){
		MagicSquare(n);
	}
	return 0;
}

Measured memory_bytes: 1248
s=input()
lists=list(s)
ans=[]
for i in range(len(s)):
    
    if s[i]=="0":
        ans.append("0")
        
    elif s[i]=="1":
        ans.append("1")
        
    elif s[i]=="B":
        if len(ans)==0:
            pass
        else:
            del ans[-1]
print("".join(ans))

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

using namespace std;
using ll = long long;

using Graph = vector<vector<pair<int, ll>>>;

vector<ll> dijkstras(const Graph &g, int start) {
  int n = g.size();
  const ll inf = 1e18;
  vector<ll> d(n, inf);

  auto compare = [](const auto &l, const auto &r) {
    return l.second > r.second;
  };
  priority_queue<pair<int, ll>, vector<pair<int, ll>>, decltype(compare)> q{
      compare};
  d[start] = 0ll;
  q.push({start, 0ll});

  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    if (p.second > d[p.first])
      continue;
    d[p.first] = p.second;
    for (const auto &pp : g[p.first]) {
      if (d[pp.first] != inf)
        continue;
      ll cost = p.second + pp.second;
      q.push({pp.first, cost});
    }
  }

  return d;
}

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

  int h, w;
  cin >> h >> w;
  vector<vector<int>> c(10, vector<int>(10));
  Graph g(10);
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      int c;
      cin >> c;
      g[j].emplace_back(i, c);
    }
  }

  // cost[i] := 数字iを1に変えるのに必要な魔力
  auto cost = dijkstras(g, 1);

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a;
      cin >> a;
      if (a == -1)
        continue;
      ans += cost[a];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

ll D, G, p[10], c[10];

double roundup(double X, int Z) {
	ll Y = X / Z;
	if (X == Y * Z)return X;
	else return X + Z;
}

int main() {
	cin >> D >> G;
	for (int i = 0; i < D; i++)cin >> p[i] >> c[i];
	ll ans = 1145141919810;
	for (int bit = 0; bit < (1 << D); bit++) {
		ll score = 0, num = 0;
		for (int i = 0; i < D; i++) {
			if ((bit >> i) & 1) {
				score += (p[i] * (i + 1) * 100) + c[i];
				num += p[i];
			}
		}
		if (score >= G)goto update;
		for (int i = D - 1; i >= 0; i--) {
			if (!((bit >> i) & 1)) {
				;
				num += min(p[i], ((ll)(roundup((G - score) / 100, i + 1)) / (i + 1)));
				score += min(p[i] * 100 * (i + 1),
					((ll)(roundup((G - score) / 100, i + 1)) / (i + 1)) * 100 * (i + 1));
				if (score >= G)goto update;
			}
		};
	update:

		ans = min(ans, num);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){

    int A,B,C,D,E;
    cin >> A >> B >> C >> D >> E;

    int answer;
    if(A < 0){
        answer = -A * C + D + B * E;
    }
    if(A > 0){
        answer = (B - A) * E;
    }

    cout << answer << endl;

}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

vector<int> adj[100005];

int helper(int node, int prev = -1){

    int tot = 0, equipped = 0, deg = adj[node].size();

    for(int nx : adj[node]){
        if(nx == prev) continue;
        int v = helper(nx, node);
        if(v) --deg;
        tot += v;
    }

    return tot + max(0, deg - 2);

}


int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a, b, root = 0; cin >> n;

    for(int i = 1; i < n; ++i){
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for(int i = 0; i < n; ++i)
        if(adj[root].size() < adj[i].size())
            root = i;

    cout << helper(root) + 1 << "\n";

    return 0;

}


Measured memory_bytes: 11904
n, m = gets.chomp.split(" ").map(&:to_i)

if n == 1 and m == 1
  puts 1
  exit
end
if n == 1
  puts m - 2
  exit
end
if m == 1
  puts n - 2
  exit
end
puts (n - 2) * (m - 2)


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

int N;
int A[20];
int x[20][20];
bool y[20][20];

int solve(int d, vector<bool> syoujiki) {
  if (d == N) {
    rep(i, N) {
      if (syoujiki[i] == false) continue;
      rep(j, A[i]) {
        if ((syoujiki[x[i][j] - 1] && !y[i][j]) ||
            (!syoujiki[x[i][j] - 1] && y[i][j]))
          return 0;
      }
    }
    int ans = 0;
    rep(i, N) if (syoujiki[i]) ans++;
    return ans;
  } else {
    vector<bool> next = syoujiki;
    next[d] = true;
    return max(solve(d + 1, syoujiki), solve(d + 1, next));
  }
}

int main() {
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    rep(j, A[i]) { cin >> x[i][j] >> y[i][j]; }
  }
  vector<bool> init(N);
  cout << solve(0, init) << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

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

  for (int i = 0; i < n; i++)
  {
    cin >> a;
    if (a == 'Y')
    {
      cout << "Four" << endl;
      exit(0);
    }
  }

  cout << "Three" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<ll> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(all(a));
	sort(all(b));
	sort(all(c));
	vector<ll> res1(n), res2(n);
	rep(i, n) {
		int it = lower_bound(all(b), a[i] + 1) - b.end();
		res1[i] = abs(it);
	}
	rep(i, n) {
		int it = lower_bound(all(c), b[i] + 1) - c.end();
		res2[i] = abs(it);
	}
	vector<ll> sum(n + 1);
	sum[0] = 0;
	rep(i, n) sum[i + 1] = sum[i] + res2[i];
	ll ans = 0;
	rep(i, n) {
		if (res1[i] == 0) continue;
		ll tmp = sum[n] - sum[n - res1[i]];
		ans += tmp;
	}
	dunk(ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > AB(N);
    for (auto &ab : AB) cin >> ab.first >> ab.second;
    sort(AB.begin(), AB.end());
    priority_queue<int> Q;
    int ans = 0, j = 0;
    for (int i = 1; i <= M; i++) {
        while (j < N && AB[j].first == i) {
            Q.push(AB[j].second);
            j++;
        }
        if (!Q.empty()) {
            ans += Q.top();
            Q.pop();
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static int[] dx = new int[] { 0, 0, 1, -1 };
    static int[] dy = new int[] { -1, 1, 0, 0 };
    static void Solve()
    {
        var h = sc.Int();
        var w = sc.Int();

        var s = new string[h];

        var visited = new bool[h][];
        for (int i = 0; i < h; i++)
        {
            s[i] = sc.Str();
            visited[i] = new bool[w];
        }

        var bcnt = 0;
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (s[i][j] == '#')
                    bcnt++;

        int cnt = 0;
        var q = new Queue<Coord>();
        q.Enqueue(new Coord { x = 0, y = 0 });

        while (!visited[h-1][w-1] && q.Count != 0)
        {
            var nq = new Queue<Coord>();
            cnt++;
            while (!visited[h-1][w-1] && q.Count != 0)
            {
                var tc = q.Dequeue();
                visited[tc.y][tc.x] = true;

                for (int i = 0; i < 4; i++)
                {
                    var nx = tc.x + dx[i];
                    var ny = tc.y + dy[i];

                    if (nx < 0 || w <= nx || ny < 0 || h <= ny || visited[ny][nx] || s[ny][nx] == '#')
                        continue;
                    
                    nq.Enqueue(new Coord { x = nx, y = ny });
                    visited[ny][nx] = true;
                }
            }

            q = nq;
        }

        if (visited[h-1][w-1])
            pr.WriteLine(w * h - cnt - bcnt - 1);
        else
            pr.WriteLine(-1);
    }

    class Coord
    {
        public int x;
        public int y;
    }
    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
    }

    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}

#region IO
class Scanner
{
    private int _i = 0;
    private string[] line = new string[0];

    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }

    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }

        return line[_i++];
    }

    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}

class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = int.Parse(Console.ReadLine());
            const int INF = (int)1e9 + 7;
            var dp = new int[s + 1];
            dp[0] = 1;

            for(int i = 3; i <= s; i++)
            {
                for(int j = 0; j <= i - 3; j++)
                {
                    dp[i]  = (dp[i] + dp[j]) % INF;
                }
            }
            Console.WriteLine(dp[s]);
        }
    }
}


Measured memory_bytes: 27432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 998244353
#define inf -1000000000000000000
int n,k;
// vector<int>a;
int main() {
	io
	string s;
	cin>>s;
	if(s[1] == 'B') cout<<"ARC";
	else cout<<"ABC";
}


Measured memory_bytes: 3648
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        System.out.println((x-a)%b);
        
    }
    
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string day[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    string s;
    cin >>s;
    ll ans;
    for (int i = 0; i < 7; ++i) {
        if(s==day[i]){
            ans=i;
        }
    }
    if(6-ans==0){
        cout <<7<<endl;
    }
    else {
        cout << 6 - ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)

ans = 0

while [a, b, c].all?(&:even?)
  if a == b && b == c
    ans = "-1"
    break
  end
  a, b, c = [(b + c) / 2, (c + a) / 2, (a + b) / 2]

  ans += 1
end

puts ans


Measured memory_bytes: 1788
n=int(input())
cards=[]
for i in range(1, 14):
    cards.append("S "+str(i))
for i in range(1, 14):
    cards.append("H "+str(i))
for i in range(1, 14):
    cards.append("C "+str(i))
for i in range(1, 14):
    cards.append("D "+str(i))
for i in range(n):
    a, b=map(str, input().split())
    cards.remove(a+" "+b)
for v in cards:
    print(v)


Measured memory_bytes: 5596
N = int(input())
L = list(map(int,input().split()))
M = list(filter(lambda x: x % 2 == 0 , L))
M_len = len(M)
N = list(filter(lambda x: (x % 3 ==0 or x % 5 == 0) ,M))
N_len = len(N)
if(M == N):
    print("APPROVED")
else:
    print("DENIED")

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

using namespace std;

typedef long long ll;

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

    int n;

    cin >> n;

    int ones = n % 10;

    // vector<int> hon = {2,4,5,7,9}
    // vector<int> pon = {0,1,6,8}
    // vector<int> bon = {3}

    if (ones == 3){
        cout << "bon"<<"\n";
    } else if (ones == 0 || ones == 1 || ones == 6 || ones == 8){
        cout << "pon"<<"\n";

    } else if (ones == 2 || ones == 4 || ones == 5 || ones == 7 || ones == 9){
        cout << "hon"<<"\n";
    } else{
        cout << ""<<"\n";
    }

    return 0;
} 

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

using namespace std;

const int MAX_V = 100000;
const int INF = 100000000;

int root;
vector<int> G[MAX_V];
int depth[MAX_V], l[MAX_V], r[MAX_V], num[MAX_V];

bool dfs(int v, int p, int d) {
	bool res = true;
	if (num[v] != INF) {
		l[v] = max(l[v], num[v]);
		r[v] = min(r[v], num[v]);
	}
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i] == p) continue;
		res &= dfs(G[v][i], v, d + 1);
		if (!res) return false;
		l[v] = max(l[v], l[G[v][i]] - 1);
		r[v] = min(r[v], r[G[v][i]] + 1);
	}
	if (l[v] == r[v]) {
		res &= (abs(num[root] - l[v]) % 2 == d % 2);
	}
	res &= (l[v] <= r[v]);

	return res;
}

void dfs2(int v, int p, int n) {
	num[v] = n;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i] == p) continue;
		if (l[G[v][i]] <= n + 1 && r[G[v][i]] >= n + 1) {
			dfs2(G[v][i], v, n + 1);
		} else {
			dfs2(G[v][i], v, n - 1);
		}
	}	
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		l[i] = -INF;
		r[i] = INF;
		num[i] = INF;
		if (i == N - 1) break;
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}

	int K;
	cin >> K;

	for (int i = 0; i < K; i++) {
		int V, P;
		cin >> V >> P;
		V--;
		num[V] = P;
		if (i == 0) root = V;
	}

	if (!dfs(root, -1, 0)) {
		cout << "No" << endl;
		return 0;
	}

	dfs2(root, -1, num[root]);

	cout << "Yes" << endl;
	for (int i = 0; i < N; i++) {
		cout << num[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define ll long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
void solve() {
  ll N, A, B;
  cin >> N >> A >> B;
  if ((B-A) % 2 == 0) {
    cout << (B-A) / 2 << endl;
    return;
  } else {
    ll aaa = min(A-1, N-B);
    ll ans = aaa + 1 + (B-A) / 2;
    cout << ans << endl;
    return;
  }
}
 
int main() {
  fio;
  cout << fixed;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a , b , t , g;
  
     for( g=1; g<=3000; g++)
    {
          cin >> a >> b;
    if (a== 0 && b== 0){
    break;
    }
    
    if (a > b)
    {
    t=b;
    b=a;
    a=t;
    }
    cout << a << " " << b << endl;
   
    }

    
    
}


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

using namespace std;

int main() {
	long long a, b;
	char c;
	scanf("%lld %c %lld", &a, &c, &b);
	if (c == '+')
		printf("%d\n", a+b);
	else 
		printf("%d\n", a-b);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n,m,S;
vec U(100),V(100),A(100),B(100),C(50),D(50);
struct edge{ll to,cost,money;};
vector<edge> G[200001];
ll d[51][2501],INF=1e18;
int main(){
    cin>>n>>m>>S;
    rep(i,m) cin>>U[i]>>V[i]>>A[i]>>B[i],G[U[i]].push_back({V[i],B[i],A[i]}),G[V[i]].push_back({U[i],B[i],A[i]});
    rep(i,n) cin>>C[i+1]>>D[i+1];
    priority_queue<pair<ll,P>,vector<pair<ll,P>>,greater<pair<ll,P>>> que;
    rep(i,n) fill(d[i+1],d[i+1]+2501,INF);
    if(S>2500) S=2500;
    d[1][S]=0;
    que.push(make_pair(0,P(1,S)));
    while(!que.empty()){
        pair<ll,P> p=que.top();que.pop();
        ll v=p.second.first,money=p.second.second;
        if(d[v][money]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(money>=e.money&&d[e.to][money-e.money]>d[v][money]+e.cost){
                d[e.to][money-e.money]=d[v][money]+e.cost,que.push(make_pair(d[e.to][money-e.money],P(e.to,money-e.money)));
            }
        }
        for(ll i=1;true;i++){
            if(money+C[v]*i>2500) break;
            if(d[v][money+C[v]*i]>d[v][money]+D[v]*i) d[v][money+C[v]*i]=d[v][money]+D[v]*i,que.push(make_pair(d[v][money+C[v]*i],P(v,money+C[v]*i)));
        }
    }
    rep(i,n-1){
        ll x=INF;
        rep(j,2501) x=min(x,d[i+2][j]);
        cout<<x<<"\n";
    }
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int num[n] = {};
    bool count[n] = {};
    for(int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        
        //先頭が0の場合は作成不可能
        if(y == 0 && x == 1 && n != 1){
            cout << -1 << endl;
            return 0;
        }

        // すでに数字が指定されていて、別な数字が入るときを除く
        if(count[x-1] == 1 && num[x-1] != y){
            cout << -1 << endl;
            return 0;
        }else{
            num[x-1] = y;
            count[x-1] = 1;
        }
    }
    
    //先頭の文字が空白であれば１を入れる
    if(num[0] == 0 && n != 1){
        num[0] = 1;
    }
    for(int i = 0; i < n; i++){
        cout << num[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let mut v:Vec<(String, u32, u32)> = (0..n).map(|i| (read(), read(), i as u32)).collect();

    v.sort_by(|a,b| {
        if a.0 != b.0 {a.0.cmp(&b.0)}
        else {b.1.cmp(&a.1)}
    });
    //println!("{:?}", v);
    for x in v.iter() {
        print!("{} ", &x.2+1);
    }
    println!("");
}


Measured memory_bytes: 4352
<?php
    fgets(STDIN);
    $r = array_map('intval', explode(' ', fgets(STDIN)));
    sort($r);

    for($i = 0; $i < count($r) - 1; $i++) {
        if ($r[$i] == $r[$i+1]) {
            echo "NO";
            return;
        } 
    }
echo "YES";

Measured memory_bytes: 31216
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#define inf 0x3fffffff

int n,m,k,f[100010],res,ans[100010],num[100010],a[100010];
vector<int> e[100010];
unordered_map<int,int> ma[100010];

void dfs(int x,int y)
{
    f[x]=y;res++;
    for (auto z:e[x])
        if (!f[z]) dfs(z,y);
}

int main()
{
    cin>>n>>m>>k;
    int x,y;
    for (int i=1;i<=m;i++)
        cin>>x>>y,
        e[x].push_back(y),
        e[y].push_back(x),
        a[x]++,a[y]++,
        ma[x][y]=1,
        ma[y][x]=1;
    memset(f,0,sizeof(f));
    for (int i=1;i<=n;i++)
        if (!f[i]) res=0,dfs(i,i),num[i]=res;
    for (int i=1;i<=n;i++)
        ans[i]=num[f[i]]-a[i]-1;
    for (int i=1;i<=k;i++)
    {
        cin>>x>>y;
        if (f[x]==f[y]&&ma[x].find(y)==ma[x].end()) ans[x]--,ans[y]--;
    }
    for (int i=1;i<n;i++)
        printf("%d ",ans[i]);
    printf("%d\n",ans[n]);
    return 0;
}

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

const int INF = 1000000007;
const int MX = 200010;
int dp[MX];

int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];
    rep(i, n) dp[i] = INF;
    dp[0] = 0;
    rep(i, n){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[n - 1] << endl;
}

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

using namespace std;

typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	if(a == b)cout << a+b << endl;
	else{
		int c = max(a, b);
		cout << 2*c-1 << endl;
	}
    return 0;
}

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

int main() {

    int x1, y1, x2, y2, x3, y3, x4, y4;



	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);


	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);

	x4 = x1 - (y2 - y1);
	y4 = y1 + (x2 - x1);

	printf("%d %d %d %d\n", x3, y3, x4, y4);

	return 0;
}



Measured memory_bytes: 128
#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>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a * b, c) << endl;


    return 0;
}



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

const int MAX = 1000005;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int x,y;
  cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  else{
    int n1 = x-(x+y)/3;
    int n2 = y-(x+y)/3;
    if(n1<0||n2<0){
      cout << 0 << endl;
      return 0;
    }
    COMinit();
    cout << COM(n1+n2,n1) << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    long n,m;
    cin>>n>>m;
    long h[n+1];
    for(int i = 1;i<=n;i++)
        cin>>h[i];
    // for(int i = 1;i<=n;i++)
    //     cout<<h[i]<<" ";
    // cout<<endl;
    long p[n+1] ={0},q[n+1]={0};
    vector<int> v[n+1];
    while(m--)
    {
        long a,b;
        cin>>a>>b;
        if(h[a] > h[b])
            p[a]++;
        else if(h[b]>h[a])
            p[b]++;
        q[a]++;
        q[b]++;
    }
    long cnt = 0;
    for(int i = 1; i<=n;i++)
    {
        if(p[i]==q[i])
            cnt++;
        //cout<<p[i]<<" "<<q[i]<<endl;
    }
    cout<<cnt<<endl;
    
}

Measured memory_bytes: 8312
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  G = [[] for _ in range(N)]
  dic = {}
  for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)
    dic[(a, b)] = i
    dic[(b, a)] = i

  color = [0]*(N-1)
  upcol = [0]*(N)
  upcol[0] = None
  visited = set()
  q = deque([0])
  max_col = 0

  while len(q):

    now = q.popleft()
    visited.add(now)
    c = 0

    for next_ in G[now]:
      if next_ in visited:
        continue
      c += 1
      if upcol[now] == c:
        c += 1

      color[dic[(now, next_)]] = c
      upcol[next_] = c

      q.append(next_)

    max_col = max(max_col, c)

  print(max_col)
  print(*color, sep='\n')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 129816
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

long long N, A[100];
long long money = 1000, stock = 0;

int main()
{
	cin >> N;
	for(int i = 1;i <= N;++i)
		cin >> A[i];
	for(int i = 1;i <= N;++i)
	{
		if(stock > 0)
		{
			money += stock * A[i];
			stock = 0;
		}
		if(A[i] < A[i + 1])
		{
			stock = money / A[i];
			money = money % A[i];
		}
	}
	printf("%lld\n", money);

	return 0;
}

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

int main(){
    ll b[100000];
    ll n;
    cin >> n;
    for (ll i = 0; i < n-1;i++)
        cin >> b[i];
    ll sum = b[0];
    for (ll i = 0; i < n-1;i++)
    {
        sum += min(b[i], b[i + 1]);
    }
    sum += b[n - 2];
    cout << sum;
}

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

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

  vector<int> vec(n);
  for (int i = 1; i < n; i++)
    cin >> vec.at(i);

  map<int, int> hoge;
  for (int x : vec) {
    if (hoge.count(x)) {
      hoge[x] += 1;
    } else {
      hoge[x] = 1;
    }
  }

  for (int i = 1; i - 1 < n; i++) {
    if (hoge.count(i)) {
      cout << hoge[i] << endl;
    } else {
      cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 13428
#include<iostream>

using namespace std;

int main(void){

    int n;
    int value[] = {111, 222, 333, 444, 555, 666, 777, 888, 999};

    cin >> n;

    for(int i = 0;i < 9;i++){
        if(n <= value[i]) {
            cout << value[i];
            break;
        }
    }


    return 0;
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define Mp make_pair
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)


// ************* MAIN *******************

#define MOD 1000000007
ll N, K;


void solve() {
    cin>>N>>K;
    ll res=0;
    for(ll i=K; i<=N+1;i++) {
        res = (res + (AritSum(N,-1,i) - AritSum(0,1,i) + 1)) % MOD;
    }
    cout << res << endl;
}
/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test
*/
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    // cin>>T;
    for (int t = 1; t <= T; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
回数 = int(input())
最大値 = 0
i = 0
合計 = 0
while( i < 回数 ):
    価格 = int(input())
    合計 += 価格
    if ( 価格 > 最大値 ):
        最大値 = 価格
    i = i + 1
合計 = 合計 - 最大値/2
print(int(合計))

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
	FASTIO;
	ll s,x;
	cin>>s>>x;
	if(x>=s)
        cout<<"unsafe"<<"\n";
    else
        cout<<"safe"<<"\n";

}


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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  auto f = [&](int x) { return T - x * 0.006; };
  int ans = 1;
  double mn = abs(A - f(H[0]));
  for (int i = 1; i < N; i++) {
    if (mn > abs(A - f(H[i]))) {
      ans = i + 1;
      mn = abs(A - f(H[i]));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;cout<<(n+1)/2<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3572
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
near_a=100100
place=0
for i in range(n):
    if abs(a-(t-(h[i]*0.006)))<near_a:
        place=i+1
        near_a=abs(a-(t-(h[i]*0.006)))
print(place)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;
 
ll a[100000+50],b[100000+50];
 
int main ()
{
	ll n,k,i;
	cin>>n>>k;
	for(i=0;i<n;i++)
		scanf("%lld %lld",&a[i],&b[i]);
	ll r=2999999999999999999,l=0,now;
	while(l+1<r)
	{
		now=(r+l)/2;
		ll ans=0;
		for(i=0;i<n;i++)
			if(now>=a[i])
			ans+=(now-a[i]+b[i])/b[i];
		if(ans>=k)
			r=now;
		else
			l=now;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<pii> qpii;


void test_case() {
	int x, y; cin >> x >> y;
	for (int i = 0; i <= 100; i ++) {
		for (int j = 0; j <= 100; j ++) {
			if (i*2 + j*4 == y && i + j == x) {
				cout << "Yes\n";
				return;
			}
		}
	}
	cout << "No\n";
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; 
	//cin >> q;
	while (q--) {
		test_case();
	}
	return 0;
}


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

#define MAX_N 100001

bool prime[MAX_N];

void eratosthenes(long long N){
    for(long long i = 2; i <= N; i++) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for(long long i = 2; i <= N; i++){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

int main(){
    //input
    int Q;
    cin >> Q;
    int left[Q], right[Q];
    int i;
    for(i=0; i<Q; i++){
        cin >> left[i] >> right[i];
    }

    //calc
    eratosthenes(MAX_N -1);

    //1~i made no num_nitakazu
    int nitakazu[MAX_N];
    nitakazu[1] = 0;
    for(i=3; i< MAX_N ; i += 2){
        if(prime[i] && prime[(i+1)/2]){
            nitakazu[i] = nitakazu[i-2] + 1;
        }else{
            nitakazu[i] = nitakazu[i-2];
        }
    }

    //answer
    for(i=0; i<Q; i++){
        if(left[i]>1){
            cout << nitakazu[right[i]] - nitakazu[left[i]-2] << endl;
        }else{
            cout << nitakazu[right[i]] << endl;
        }
    }
    system("pause");
    return 0;
}

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

const int MAX_N = 1000;

class UnionFind {
public:
  int par[MAX_N];                 // 親
  int rank[MAX_N];                // 木の深さ

  // n要素で初期化
  UnionFind(int n){
    for(int i=0;i<n;++i){
      par[i]=i;
      rank[i]=0;
    }
  }

  // 木の根を求める
  int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  // xとyの属する集合を併合
  void unite(int x, int y){
    x = find(x); y = find(y);
    if(x==y) return;

    if(rank[x]<rank[y])
      par[x]=y;
    else {
      par[y]=x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y){
    return find(x) == find(y);
  }
};

int main() {
  int v,d;
  while(cin>>v>>d){
    int f[v];
    for(int i=0;i<v;++i){
      if(i==0) f[i]=1+1;
      else if(i==1) f[i]=f[i-1]+1;
      else f[i]=(f[i-1]+f[i-2])%1001;
    }

    UnionFind u(v);
    for(int i=0;i<v-1;++i)
      for(int j=i+1;j<v;++j)
        if(abs(f[i]-f[j])<d) u.unite(i,j);

    int ans=0;
    for(int i=0;i<v;++i)
      if(u.find(i)==i) ans++;
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
n,m,d = map(int,input().split())
#n,m,d = map(int, [1000000000,180707,0])
#n,m,d = map(int, [2,3,1])

res=0
res=(m-1)*2*(n-d)/pow(n,2)
if d==0:
    res/=2

print(res)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int x,y,sx,sy,gx,gy,n,b[110][110],c,d,p[2],i,j,m[2]={2,4},mv[5]={0,1,0,-1,0},tag;

int df(int px,int py)
{
	int i;
	if(px==gx&&py==gy)
		return 1;
	else
	{
		b[py][px]=0;
		for(i=0;i<4;i++)
			if(b[py+mv[i]][px+mv[i+1]]==tag&&df(px+mv[i+1],py+mv[i]))
				return 1;
	}
	return 0;
}

int main()
{
	for(;scanf("%d%d",&x,&y),x;)
	{
		memset(b,0,sizeof(b));
		scanf("%d%d",&sx,&sy);
		scanf("%d%d",&gx,&gy);
		scanf("%d",&n);
		for(;n--;)
		{
			scanf("%d%d%d%d",&c,&d,&p[0],&p[1]);
			for(i=0;i<m[d];i++)
				for(j=0;j<m[!d];j++)
					b[p[1]+i][p[0]+j]=c;
		}
		tag=b[sy][sx];
		printf("%s\n",tag&&df(sx,sy)?"OK":"NG");
	}
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	ll n, we;
	cin >> n >> we;
	int i, j;
	VL w(n);
	VL v(n);
	for (i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	VVL dp(n + 1, VL(we + 1, 0));
	for (i = 0; i < n; i++) {
		for (j = 0; j < we; j++) {
			if (j + w[i] <= we) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
			chmax(dp[i + 1][j], dp[i][j]);
		}
	}
	ll ans = 0;
	for (i = 0; i <= we; i++) chmax(ans, dp[n][i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

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

    ll ans = 1000;
    rep(i, n - 1) {
        ll pre = ans / a[i];
        if (a[i] < a[i + 1])
            ans += (a[i + 1] - a[i]) * pre;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars,
        k: usize,
    }
    let mut n = '1';
    let mut ni = s.len() + 1;
    for i in 0..s.len() {
        if s[i] != '1' {
            n = s[i];
            ni = i + 1;
            break;
        }
    }
    if ni <= k {
        println!("{}", n);
    } else {
        println!("{}", '1');
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;



int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> s(h+2,vector<int>(w+2));
    rep(i,h){
        string s_elem;
        cin >> s_elem;
        rep(j,w){
            if(s_elem[j]=='#'){
                s[i+1][j+1]=1;
            }
        }
    }
    string ans = "Yes";
    rep(i,h){
        rep(j,w){
            if(s[i+1][j+1]==1){
                if(s[i][j+1]==0 && s[i+1][j]==0 && s[i+1][j+2]==0 && s[i+2][j+1]==0){
                    ans = "No";
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
  ll l,r; cin >> l >> r;
  int ans = 2018;
  for(ll i = l; i < r; i++){
    for(ll j = l + 1; j <= r; j++){
      int num = i * j % 2019;
      ans = min(ans, num);
      if(ans == 0) break;
    }
    if(ans == 0) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
c=input()
c=list(c)
a=sorted(c)
countw=0
countr=0

for i in range(n):
  if c[i]=='R' and a[i]=='W':
    countw+=1
  elif c[i]=='W' and a[i]=='R':
    countr+=1
    
ansmin=min(countw,countr)
ansmax=max(countw,countr)

print(ansmin+abs(ansmin-ansmax))

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

int main()
{
    ll N, M;

    cin >> N >> M;

    dsu d(N);

    rep(i, M)
    {
        int A;
        int B;
        cin >> A >> B;
        A--;
        B--;
        d.merge(A, B);
    }

    cout << d.groups().size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 8876
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
    int n,d;
    scanf("%d%d",&n,&d);
    if(n%(2*d+1)==0)
    printf("%d",n/(2*d+1));
    else
    {printf("%d",n/(2*d+1)+1);}
    return 0;
}

Measured memory_bytes: 128
palindrome :: String -> Bool
palindrome str = (str == reverse str)

main = do
  s <- getLine
  let n = length s
  if palindrome s
     && palindrome (take ((n-1) `div` 2) s)
     && palindrome (drop ((n+3) `div` 2 - 1) s)
  then putStrLn "Yes"
  else putStrLn "No"

Measured memory_bytes: 508
#include <stdio.h>
#define MAX (int)1e5

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

int main(){
  int n,b[MAX],i,sum=0;
  
  scanf("%d",&n);
  for(i=0;i<n-1;i++)
    scanf("%d",&b[i]);
  
  sum += b[0];
  for(i=0;i<n-2;i++)
    sum += min(b[i],b[i+1]);
  sum += b[n-2];
  
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int N;
	long ANS=0;
	vector<int> NN;
	cin >> N;
	for(int i=0;i<N;i++){
		int t;
		cin >> t;
		NN.push_back(t);
	}

	for(int i=0;i<NN.size();i++){
		for(int j=0;j<NN.size();j++){
			if(i<j){
				ANS=ANS+NN[i]*NN[j];
			}
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int N, B;
  cin >> N >> B;
  int R = N - B;
  COMinit();
  rep(i, 1, B+1) {
    ll BB = COM(B-1, i-1);
    ll RR = COM(R+1, i);
    cout << BB * RR % MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 12160