akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e6 + 9, M = 1e5 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

struct edge {
  int to, color, weight;
};
vector<edge> adj[N];

int first[N], height[N], tree[4*N], dist[N], ans[N];
vector<int> euler;
void dfs(int node, int par, int lvl) {
  first[node] = euler.size();
  height[node] = lvl;
  euler.push_back(node);
  for(auto it: adj[node]) {
    if(it.to == par) continue;
    dist[it.to] = dist[node] + it.weight;
    dfs(it.to, node, lvl + 1);
    euler.push_back(node);
  }
}

void build(int node, int start, int end) {
  if(start == end) {
    tree[node] = euler[start];
    return;
  }
  int mid = (start + end) / 2;
  build(node * 2, start, mid);
  build(node * 2 + 1, mid + 1, end);
  int left = tree[node * 2], right = tree[node * 2 + 1];
  if(height[left] <= height[right])
    tree[node] = left;
  else
    tree[node] = right;
}

int query(int node, int start, int end, int l, int r) {
  if(start > r || end < l)
    return -1;
  if(start >= l && end <= r)
    return tree[node];
  int mid = (start + end) / 2;
  int left = query(node * 2, start, mid, l , r);
  int right = query(node * 2 + 1, mid + 1, end, l, r);
  if(left == -1)
    return right;
  if(right == -1)
    return left;
  if(height[left] <= height[right])
    return left;
  return right;
}

int lca(int a, int b) {
  int l = first[a], r = first[b];
  if(l > r)
    swap(l, r);
  return query(1, 0, euler.size() - 1, l, r);
}

struct queryy {
  int id, color, val, factor;
};
vector<queryy> qq[N];
int cntColor[N], curSum[N];
void dfs2(int node, int par) {
  for(auto it: qq[node]) {
    ans[it.id] -= curSum[it.color] * it.factor;
    ans[it.id] += cntColor[it.color] * it.val * it.factor;
  }
  for(auto it: adj[node]) {
    if(it.to == par) continue;
    ++cntColor[it.color];
    curSum[it.color] += it.weight;
    dfs2(it.to, node);
    --cntColor[it.color];
    curSum[it.color] -= it.weight;
  }
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m, u, v, col, val;
  cin >> n >> m;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v >> col >> val;
    adj[u].push_back({v, col, val});
    adj[v].push_back({u, col, val});
  }
  dfs(1, -1, 0);
  build(1, 0, euler.size() - 1);
  for (int i = 0; i < m; ++i) {
    cin >> col >> val >> u >> v;
    int lcaUV = lca(u, v);
    ans[i] = dist[u] - dist[lcaUV] + dist[v] - dist[lcaUV];

    qq[lcaUV].push_back({i, col, val, -2});
    qq[u].push_back({i, col, val, 1});
    qq[v].push_back({i, col, val, 1});
  }
  dfs2(1, -1);
  for (int i = 0; i < m; ++i)
    cout << ans[i] << '\n';
  return 0;
}


Measured memory_bytes: 82420
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

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

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int h,w,k;
  cin>>h>>w>>k;

  char map[300][300]={};
  for(int r=0;r<h;r++){
    for(int c=0;c<w;c++){
      cin>>map[r][c];
    }
  }

  int result[300][300]={};

  int count=1;
  for(int i=0;i<300;i++){
    for(int j=0;j<300;j++){
      result[i][j]=0;
    }
  }

  for(int r=0;r<h;r++){
    bool found_in_r=false;
    for(int c=0;c<w;c++){

      if(map[r][c]=='#'){
        found_in_r=true;
        for(int di=c;di<w;di++){
          if(result[r][di]!=0||(di!=c&&map[r][di]=='#')){
            break;
          }
          result[r][di]=count;
        }
        for(int di=c-1;di>=0;di--){
          if(result[r][di]!=0||(di!=c&&map[r][di]=='#')){
            break;
          }
          result[r][di]=count;
        }
        count++;
      }
    }

  }
  for(int r=0;r<h;r++){
    bool found_in_r=false;
    for(int c=0;c<w;c++){
      if(map[r][c]=='#'){
        found_in_r=true;
        break;
      }
    }
    if(!found_in_r){
      int vec;
      if(r==0){
        vec=+1;
      }else{
        vec=-1;
      }
      for(int c=0;c<w;c++){
        result[r][c]=result[r+vec][c];
      }
    }
  }

  for(int r=h-1;r>=0;r--){
    bool found_in_r=false;
    for(int c=0;c<w;c++){
      if(map[r][c]=='#'){
        found_in_r=true;
        break;
      }
    }
    if(!found_in_r){
      int vec;
      if(r==h-1){
        vec=-1;
      }else{
        vec=+1;
      }
      for(int c=0;c<w;c++){
        result[r][c]=result[r+vec][c];
      }
    }
  }


  for(int r=0;r<h;r++){
    for(int c=0;c<w-1;c++){
      cout<<result[r][c]<<" ";
    }
    cout<<result[r][w-1]<<endl;
  }



  return 0;
}

Measured memory_bytes: 1280
//
//  main.cpp
//  C - 2D Plane 2N Points
//
//  Created by 谢威宇 on 2018/3/17.
//  Copyright © 2018年 Ervin's Studio. All rights reserved.
//

#include <iostream>
#include <cstring>
using namespace std;
struct _p{
    int x,y;
}red[200],blue[200];
int line[102][102]={0};
int girl[102]={0};
int used[102]={0};

bool found(int x,int n)
{
    for(int i=1; i<=n; i++)
    {
        if(line[x][i]&&!used[i])
        {
            used[i]=1;
            if(girl[i]==0||found(girl[i],n))
            {
                girl[i]=x;
                return 1;
            }
        }
    }
    return 0;
}

int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        red[i].x=x;
        red[i].y=y;
    }
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        blue[i].x=x;
        blue[i].y=y;
        for(int j=1;j<=n;j++)
        {
            if(red[j].x<x&&red[j].y<y)
            {line[j][i]=1;}
        }
    }
    
//    for(int i=1;i<=n;i++)
//    {
//        for(int j=1;j<=n;j++)
//            cout<<line[i][j]<<" ";
//        cout<<endl;
//    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        memset(used,0,sizeof(used));
        if(found(i,n))
            ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
bool judge(double *a) {
	if(a[1] < a[2]) return false;
	else if(a[0] > a[3]) return false;
	else return true;
}

int main() {
	double d;
	while(scanf("%lf", &d) != EOF) {
		double x[4], y[4];
		x[0] = d;
		rep(i,7) {
			if(i % 2) cin >> x[i/2+1];
			else cin >> y[i/2];
		}
		if(judge(x) && judge(y)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector< list<int> > v;
vector<bool> used;
int p[100000];
int r[100000];

int find(int x){
  if(p[x] == x) return x;
  else return p[x] = find(p[x]);
}
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(r[x] < r[y])
    p[x] = y;
  else{
    p[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

void dfs(int pos, int bgn){
  if(used[pos]) return;
  used[pos] = true;
  unite(pos, bgn);
  for(list<int>::iterator it = v[pos].begin(); it != v[pos].end(); it++){
    dfs(*it, bgn);
  }
}

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

  cin >> n >> m;
  v = vector< list<int> >(n, list<int>(0));
  used = vector<bool>(n, false);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  for(int i = 0; i < n; i++){
    p[i] = i;
    r[i] = 0;
  }

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

  int q; cin >> q;
  for(int i = 0; i < q; i++){
    int a, b;
    cin >> a >> b;
    if(same(a, b)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}

// end of Template

bool calc[200000];
int n;
ll memo[200000],h[200000],k;
ll dp(ll x){
    if(x==n)return 0;
    else if(calc[x])return memo[x];
    else{
        ll res = INT_MAX;
        for(int i=1;i<=k;i++){
            if(x+i<=n){
                res = min(res,abs(h[x]-h[x+i]) + dp(x+i));
            }
            else break;
        }
        memo[x] = res;
        calc[x] = true;
        return res;
    }
}
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>h[i];
    cout<<dp(1)<<newl;

}




Measured memory_bytes: 6656
'''
頂点1から全頂点通る一筆書きが何個あるか
頂点数(N)は最大で8なので道順を全列挙して調べてもいける
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007


    N,M = map(int, input().split())
    g = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int, input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)

    res = []
    visited = [0]*N

    def dfs(node):
        visited[node]=1
        if sum(visited)==N:
            res.append(1)
            return
        for n_node in g[node]:
                if not visited[n_node]:
                    dfs(n_node)
                    visited[n_node] = 0
    dfs(0)
    print(len(res))


    # My
    # n,m = map(int, input().split())
    # edge = [list(map(int, input().split())) for _ in range(m)]
    # res = []
    # visited = [0]*n

    # def dfs(node):
    #     visited[node-1]=1
    #     if sum(visited)==n:
    #         res.append(1)
    #         return
    #     for x,y in edge:
    #         if x == node:
    #             if not visited[y-1]:
    #                 dfs(y)
    #                 visited[y-1] = 0
    #         if y == node:
    #             if not visited[x-1]:
    #                 dfs(x)
    #                 visited[x-1] = 0

    # for a,b in edge:
    #     if a==1:
    #         dfs(a)
    #         print(len(res))
    #         exit()
    #     if b==1:
    #         dfs(b)
    #         print(len(res))
    #         exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		if (Math.abs(a-c) <= d) {
			System.out.println("Yes");
		} else if (Math.abs(a-b) <= d && Math.abs(b-c) <= d) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#S= str(input())
#T= str(input())
N = int(input())
D,X = map(int,input().split())

#A = list(map(int,input().split()))
c=0
for i in range(N):
    a=int(input())
    t=0
    while 1+t*a<=D:
        c+=1
        t+=1
print(c+X)


Measured memory_bytes: 2940
r = 2**15+1
sqrt = int(r**0.5)
p = [1]*(r+1)
p[:2] = [0,0]
for i in range(2,sqrt+1):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r+1,i)]
while 1:
	n = input()
	if n == 0: break
	count = 0
	for i in range(2,n/2+1):
		if p[i] and p[n-i]:
			count += 1
	print count

Measured memory_bytes: 5004
S=input()
N=0
if S[0]=="R":
    N+=1
    if S[1]=="R":
        N+=1
        if S[2]=="R":
            N+=1
elif S[1]=="R":
    N+=1
    if S[2]=="R":
        N+=1
elif S[2]=="R":
    N+=1
print(N)

Measured memory_bytes: 9100
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		int n  = Integer.parseInt(line);

		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		long total = 0L;

		String[] numline  = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(numline[i]);

			if (min > input) min = input;
			if (max < input) max = input;
			total += input;
		}

		System.out.println(min + " " + max + " " + total);
	}
}

Measured memory_bytes: 28536
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
#define SIZE 2010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int h, w, k, a[15][SIZE], pre[15][SIZE], ans = 1e9;

int query(int xa, int ya, int xb, int yb) {
	return pre[xb][yb] - pre[xa][yb] - pre[xb][ya] + pre[xa][ya];
}

void gao(int top) {
	vector<int> vec(1, 0);
	int cnt = 1, tmp = 0, pre = 0;
	while (top) {
		if (top & 1) ++tmp, vec.emplace_back(cnt);
		top >>= 1;
		++cnt;
	}
	vec.emplace_back(h);
	
	rep(i, 1, w) {
		bool f = false;
		rep(j, 1, (vec.size() - 1)) {
			if (query(vec[j - 1], pre, vec[j], i) > k) {
				if (query(vec[j - 1], i - 1, vec[j], i) > k) return;
				f = true;
			}
		}
		if (f) { ++tmp; pre = i - 1; }
	}
	ans = min(ans, tmp);
}

int main() {
	io(); cin >> h >> w >> k;
	int top = (1 << (h - 1)) - 1;
	rep(i, 1, h) {
		string s; cin >> s;
		rep(j, 1, w) a[i][j] = s[j - 1] - '0';
	}
	rep(i, 1, h)
		rep(j, 1, w)
			pre[i][j] = a[i][j] + pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
	for (int i = top; i >= 0; --i) gao(i);
	cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct LCA {
  int N, logN; // logN-1 == floor(lg(N-1))
  vector<vector<int>> G;
  vector<int> depth;
  // vから根の方向に2^k回登ったときのノード parent[k][v]
  vector<vector<int>> parent;

  LCA(int size) : N(size), G(size), depth(size) {
    logN = 0;
    for(int x = 1; x < N; x *= 2) logN++;
    parent.assign(max(logN, 1), vector<int>(N));
  }

  // どちらが根であってもOK
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void dfs(int v, int par, int dep) {
    depth[v] = dep;
    parent[0][v] = par;
    for(int next : G[v]) {
      if(next != par) dfs(next, v, dep + 1);
    }
  }

  void init(int root) {
    dfs(root, -1, 0);
    for(int k = 1; k < logN; k++) {
      for(int v = 0; v < N; v++) {
        if(parent[k - 1][v] == -1) parent[k][v] = -1;
        else parent[k][v] = parent[k - 1][parent[k - 1][v]];
      }
    }
  }

  int lca(int u, int v) {
    if(depth[u] > depth[v]) swap(u, v); // vのほうが深くなる
    // uとvの深さが同じになるまでvを根の方向に移動する
    for(int k = 0; k < logN; k++) {
      if(((depth[v] - depth[u]) >> k) & 1) {
        v = parent[k][v];
      }
    }
    if(u == v) return u;
    for(int k = logN - 1; k >= 0; k--) {
      if(parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

int main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  LCA lca(N);
  for(int u = 0; u < N; u++) {
    int k; cin >> k;
    while(k--) {
      int v; cin >> v;
      lca.add_edge(u, v);
    }
  }
  lca.init(0);
  int Q; cin >> Q;
  while(Q--) {
    int u, v; cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}

Measured memory_bytes: 16100
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;cin>>s;
	int len = s.length();
	unordered_map <char,int> count(0);
	for(int i=0;i<len;i++){
			//~ if(count.find(s[i])==count.end())count[s[i]]++;
			//~ else count[s[i]]++;
			count[s[i]]++;
		}
	for(auto it=count.begin();it!=count.end();it++){
			if(it->second % 2 != 0){
					cout<<"No";
					return 0;
				}
		}	
	cout<<"Yes";	
	return 0;
	}


Measured memory_bytes: 3620
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#define ll long long

using namespace std;

signed main() {
	string s; cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (i & 1) {
			if (s[i] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s[i] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    l=[input() for i in range(5)]
    sum=0
    for j in range(5):
        sum+=(int(l[j])//10)*10
    num=10
    for n in range(5):
        if int(l[n][-1])!=0 and int(l[n][-1]) < num:
            num=int(l[n][-1])
    sum-=10-num
    for s in range(5):
        if int(l[s])%10!=0:
            sum+=10
    print(sum)
resolve()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b;
	cin >> a >> b;
	print((a + b) % 24);





	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;

#define MAX_N (105)

int n;
bool G[MAX_N][MAX_N];
int dist[MAX_N];
int main()
{
    queue<int> q;
    scanf("%d", &n);
    for ( int i = 1; i <= n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	for ( int j = 0; j < k; j++ ) {
	    int d;
	    scanf("%d", &d);
	    G[u][d] = true;
	}
    }

    memset(dist, -1, (n+1) * sizeof(int));

    dist[1] = 0;
    q.push(1);
    
    while ( !q.empty() ) {
	int cur = q.front(); q.pop();
	for ( int i = 1; i <= n; i++ ) {
	    if ( G[cur][i] && (dist[i] == -1) ) {
		dist[i] = dist[cur] + 1;
		q.push(i);
	    }
	}
    }

    for ( int i = 1; i <= n; i++ ) {
	printf("%d %d\n", i, dist[i]);
    }

    return 0;
}

Measured memory_bytes: 1048
/*
#include<rabbit>;
using blueHulkStress;
using AceOfSpades;
*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
const int dx[] = {1,-1,0,0,1,-1,1,-1};
const int dy[] = {0,0,1,-1,1,-1,-1,1};
const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{
	
	int n, k;cin>>n>>k;
	vi v(k);
	rep(i,k)cin>>v[i];

	while(1)
	{
		bool f = 0;
		for(auto i:to_string(n))
		{
			f|=count(all(v),i-'0');
		}
		if(!f)return cout<<n,0;
		n++;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;

if(c == 'a' ||c == 'i' ||c == 'u' ||c == 'e' ||c == 'o') 
{ 
cout << "vowel" << endl; 
} else {
           cout << "consonant" << endl;
          }
}

Measured memory_bytes: 256
def is_palindromic(x):
    s = str(x)
    left = 0
    right = len(s) - 1
    while (left < right):
        if (s[left] != s[right]):
            return False
        left += 1
        right -= 1
    return True
    
if __name__ == "__main__":
    A,B = map(int, input().split())
    result = 0
    for x in range(A, B + 1):
        if is_palindromic(x):
            result += 1
    print (result)

Measured memory_bytes: 3064
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

// Author:: Subash Singha Roy
// Institution:: Jalpaiguri Government Engineering College

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (int)(1e9+7)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=a-1;i>=b;i--)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
#define mp make_pair
#define pr  pair <ll,ll> 
#define ff first
#define ss second
#define inf 999999999999999999
ll mult(ll a,ll b, ll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=mod){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = mod) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = mod) {return fpow(a, p - 2, p);}
bool sa(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);}
bool fd(const pair<int,int> &a,const pair<int,int> &b){return (a.first>b.first);}
bool sd(const pair<int,int> &a,const pair<int,int> &b){return (a.second>b.second);}

int main(){
fio
ll n,m;
string s,s1;
cin>>s>>s1;
n=s.length();
m=s1.length();
ll dp[n+2][m+2];
fr(i,0,n+1){
    fr(j,0,m+1){
        if(i==0 || j==0){
            dp[i][j]=0;
        }
        else if(s[i-1]==s1[j-1]){
            dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}
ll ind=dp[n][m];

char ans[ind+1];
ans[ind]='\0';
ll i=n,j=m;
while(i>0 && j>0){
    if(s[i-1]==s1[j-1]){
        ans[ind-1]=s[i-1];
        i--;j--;ind--;
    }
    else{
        if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
}
cout<<ans;
rr;}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int A,B;
	cin >> A;
	cin >> B;
	if (A>=13)
	{
		cout << B << endl;
	}
	else if (A>=6)
	{
		cout << B / 2 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// 2017-03-13
#include <iostream>
#include <string>
using namespace std;

int gcd(int m, int n) {
	while (n != 0) {
		int t = n;
		n = m % n;
		m = t;
	}
	return m;
}

int main() {
	string s;
	while (cin >> s, s != "#") {
		int n = 0;
		bool d[20];
		for (int i = 0; i < s.length(); ) {
			if (s[i] == 'n') {
				d[n] = false; // north
				i += 5;
			} else {
				d[n] = true; // west
				i += 4;
			}
			n++;
		}
		int a = d[n - 1] ? 90 : 0;
		int b = 1;
		for (int i = n - 2; i >= 0; i--) {
			a = 2 * a + (d[i] ? 90 : -90);
			b *= 2;
		}
		int c = gcd(a, b);
		if (b == c) {
			cout << a / c << endl;
		} else {
			cout << a / c << "/" << b / c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>

int main(){
	int n,m;
	int i;
	int al,ar,l,r;
	scanf("%d %d",&n,&m);
	al=1;
	ar=n;
	for(i=0;i<m;i++){
		scanf("%d %d",&l,&r);
		if(l>al){
			al=l;
		}
		if(r<ar){
			ar=r;
		}
	}
	if(ar>=al){
		printf("%d\n",ar-al+1);
	}else{
		printf("0\n");
	}
	return 0;
}


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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

const int N = 100;
char s[N];

int main() {
    int n = read(), k = read();
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
        if (i == k) putchar(s[i] + 'a' - 'A');
        else putchar(s[i]);
    }  
    puts("");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long A = inputLongArray[0];
            long B = inputLongArray[1];
            long C = inputLongArray[2];
            long K = inputLongArray[3];
            if (K<=A)
            {
                //1 * K枚
                Console.WriteLine(K);
            }
            else if (K<=A+B)
            {
                Console.WriteLine(A);
            }
            else 
            {
                Console.WriteLine(A*1 -1*(K-A-B));
            }
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


Measured memory_bytes: 28240
from functools import reduce

N = int(input())
A_list = list(map(int, input().split()))

sums = [A_list[0]]

for i in range(1, N):
    sums.append(sums[i-1] + A_list[i])

result = 0
for i in range(1, N):
    result += sums[i-1] * A_list[i]

result %= 10**9 + 7

print(result)


Measured memory_bytes: 112176
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int 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 Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
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;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c;
    if(a==b&&b==c)Cout("Yes");
    else Cout("No");
    return 0;
}


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

#define rep(i,n) for(ll i=0;(i)<(ll)n;(i)++)
const long long INF = 100000000000;

int main(){
  int n,m; cin >> n >> m;
  scc_graph g(n);
  rep(i,m){
    int u,v; cin >> u >> v;
    g.add_edge(u,v);
  }
  auto scc = g.scc();
  cout << scc.size() << endl;
  for(auto es : scc){
    cout << es.size() << " ";
    for(auto e : es){
      cout << e << " ";
    }
    cout << endl;
  }
    
}


Measured memory_bytes: 40604
/**
 *    author        : Saurav Paul 
 *    created       : August 14, 2020 5:26 PM
 *    Problem Name  : G - Longest Path
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_g
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

using ll = long long int ;
int N , M ;
vector<vector<int>> graph ;
vector<int> dp ;
vector<int> indegree ;

int dfs(int node){

    if(~dp[node]) return dp[node] ;

    int cnt = 0 ;

    for(auto nxt : graph[node]){
        cnt = max(cnt,dfs(nxt)) ;
    }

    return dp[node] = cnt + 1;
}

void solve(){
    cin >> N >> M  ;

    graph = vector<vector<int>> (N+1,vector<int>()) ;
    dp = vector<int> (N+1, -1) ;
    indegree = vector<int> (N+1) ;
    
    for(int i = 1; i <= M ; i++){
        int u , v ;
        cin >> u >> v;
        graph[u].emplace_back(v) ;
        indegree[v] ++ ;
    }

    int answer = 0 ;
    for(int i = 1; i <= N ; i++){
        if(indegree[i] == 0){
            answer = max( answer , dfs(i) - 1 ) ;
        }
    }

    cout << answer << endl ;
}

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

    int testcase = 1;
    for(int i = 1 ; i <= testcase ; i ++){
        solve();
    }

    return 0 ;
}


Measured memory_bytes: 14172
#include<stdio.h>
#define NUM 100

int main(){
  int i,j,N,minj,temp;
  int change=0;
  int A[NUM];

  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&A[i]);
  }

  for(i=0; i<N-1; i++){
    minj = i;
    for(j=i; j<=N-1; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    temp = A[minj];
    A[minj] = A[i];
    A[i] = temp;
    if(minj != i){
      change++;
    }
  }

  for(i=0; i<N; i++){
    printf("%d",A[i]);
    if(i < N-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",change);
  
  return 0;
}



Measured memory_bytes: 2140
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

S = str(input())

ans_S = [str(0) for i in range(len(S))]
ans_1 = 0
for i in range(len(S)):
    if i%2==0:
        ans_S[i] = str(1)

    if ans_S[i]!=S[i]:
        ans_1 += 1

ans_2 = 0
ans_S = [str(0) for i in range(len(S))]
for i in range(len(S)):
    if i%2==1:
        ans_S[i] = str(1)

    if ans_S[i]!=S[i]:
        ans_2 += 1

ans = min(ans_1,ans_2)
print(ans)


Measured memory_bytes: 26196
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

A_m = np.array(sorted([abs(int(x)) for x in A if x < 0]), np.int64)
N_m = len(A_m)

A_p = np.array(sorted([int(x) for x in A if x > 0]), np.int64)
N_p = len(A_p)

M = N_m * N_p
P = (1 / 2) * (N_m) * (N_m - 1) + (1 / 2) * (N_p) * (N_p - 1)
Z = (1 / 2) * N * (N - 1) - (M + P)

if M < K <= M + Z:
    print(0)
    sys.exit()

def cnt_M(x):
    cnt = np.searchsorted(A_m, x // A_p, side="right").sum()
    return cnt >= M - K + 1

if K <= M:
    left = -1 -10 ** 18
    right = 1 + 10 ** 18
    while right - left> 1:
        mid = (left + right) // 2
        if cnt_M(mid):
            right = mid
        else:
            left = mid
 
    print(-right)
    sys.exit()

K -= (M + Z)
def cnt_P(x):
    cnt = 0
    ng = 0
    cnt += np.searchsorted(A_m, x // A_m, side="right").sum()
    cnt += np.searchsorted(A_p, x // A_p, side="right").sum()
    ng = np.count_nonzero(A_m * A_m <= x) + np.count_nonzero(A_p * A_p <= x)
    cnt = (cnt - ng) // 2
    return cnt >= K

left = -1 - 10 ** 18
right = 1 + 10 ** 18

while right - left > 1:
    mid = (left + right) // 2
    if cnt_P(mid):
        right = mid
    else:
        left = mid
print(right)

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

int main(){
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	
	double ma=m*6;
	double ha=h*30+m*0.5;
	double ang=max(ha,ma)-min(ha,ma);
  	ang=360-ang;
  ang=ang*(M_PI/180);
	ang=cos(ang);
	
//  cout <<ang<< endl;
	double c=sqrt(a*a+b*b-2*a*b*ang);
	
	cout.precision(10);
	cout << c << endl;

}



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

int main()
{
	
	ll t;
	cin>>t;

	ll ans = 0;
	ll first = (t/500)*1000;
	t -= (t/500)*500;
	ll second = (t/5)*5;

	cout<<first + second<<endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(Math.min(a,b)+" "+Math.max(0, a+b-x));




	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int cnt = 0;
void merge(vector<int> &a, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	vector<int> l(n1+1), r(n2+1);
	rep(i,n1) {
		l[i] = a[left+i];
	}
	rep(i,n2) {
		r[i] = a[mid+i];
	}
	l[n1] = INT_MAX, r[n2] = INT_MAX;
	int i = 0, j = 0;
	rep2(k,left,right) {
		if(l[i] <= r[j]) {
			a[k] = l[i];
			i++;
		} else {
			a[k] = r[j];
			j++;
		}
		cnt++;
	}
}
void merge_sort(vector<int> &a, int left, int right) {
	if(left+1<right) {
		int mid = (left+right) / 2;
		merge_sort(a, left, mid);
		merge_sort(a, mid, right);
		merge(a, left, mid, right);
	}
}
int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) {
		cin >> v[i];
	}
	merge_sort(v,0,n);
	cout << v[0];
	rep2(i,1,n) {
		cout << " " << v[i];
	}
	cout << endl << cnt << endl;
	return 0;
}

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

int const MAX = 200005;
long long a[MAX];

long long function(long long k, long long l) {
	return k * l + l * (l + 1) / 2;
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[n + 1] = 0;
	long long ans = 0;
	for (int i = n; i >= 1; i--) {
		if (a[i] > i - 1 || a[i] < a[i + 1] - 1) {
			cout << -1 <<  endl;
			return 0;
		}
		if (a[i] >= a[i+1]) {
			ans += a[i];
		}
	}
	cout << ans << endl;
}


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

#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<(a); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pow2(x) (1ll<<(x))

using namespace std;

const int Mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	char c[n][n];
	if(n==2){
		cout << "-1\n";
		return 0;
	}
	if(n%3==0&&n<=9){
		loop(n){
			loopi(j,n){
				if(i%3==0){
					if(j==i||j==i+1) cout << 'a';
					else cout << '.';
				}
				else if(i%3==1){
					if(j==i+1) cout << 'a';
					else cout << '.';
				}
				else{
					if(j==i) cout << 'a';
					else cout << '.';
				}
			}
			cout << "\n";
		}
		return 0;
	}
	if(n==7){
		cout << "ab..aa.\n";
		cout << "ab....a\n";
		cout << "b.aa..a\n";
		cout << "bcc.a..\n";
		cout << "aa.ba..\n";
		cout << "..ab.aa\n";
		cout << "..accbb\n";
		return 0;
	}
	if(n==11){
		cout << "ab..aa.....\n";
		cout << "ab....a....\n";
		cout << "b.aa..a....\n";
		cout << "bcc.a......\n";
		cout << "aa.ba......\n";
		cout << "..ab.aa....\n";
		cout << "..accbb....\n";
		cout << ".......abcc\n";
		cout << ".......abdd\n";
		cout << ".......ccab\n";
		cout << ".......ddab\n";
		return 0;
	}
	loop(n) loopi(j,n) c[i][j]='.';
	c[0][0]=c[1][0]=c[2][2]=c[3][2]='a';
	c[0][1]=c[1][1]=c[2][3]=c[3][3]='b';
	c[0][2]=c[0][3]=c[2][0]=c[2][1]='c';
	c[1][2]=c[1][3]=c[3][0]=c[3][1]='d';
	loop(n){
		loopi(j,n){
			if(i<=3||j<=3) continue;
			c[i][j]=c[i-4][j-4];
		}
	}
	if(n%4==0){
		loop(n){
			loopi(j,n) cout << c[i][j];
			cout << "\n";
		}
		return 0;
	}
	char ans[n][n];
	loop(n) loopi(j,n) ans[i][j]='.';
	/*
	abaa.
	ab..a
	baa.a
	b.bcc
	aabaa
	*/
	ans[0][0]=ans[0][2]=ans[0][3]=ans[1][0]=ans[1][4]=ans[2][1]=ans[2][2]=ans[2][4]=ans[4][0]=ans[4][1]=ans[4][3]=ans[4][4]='a';
	ans[0][1]=ans[1][1]=ans[2][0]=ans[3][0]=ans[3][2]=ans[4][2]='b';
	ans[3][3]=ans[3][4]='c';
	ans[0][4]=ans[1][2]=ans[1][3]=ans[2][3]=ans[3][1]='.';
	if(n%4==1){
		loop(n){
			loopi(j,n){
				if(i<=4||j<=4) continue;
				ans[i][j]=c[i-5][j-5];
			}
		}
	}
	if(n%4==2){
		loop(5){
			loopi(j,5) ans[i+5][j+5]=ans[i][j];
		}
		loop(n){
			loopi(j,n){
				if(i<=9||j<=9) continue;
				ans[i][j]=c[i-10][j-10];
			}
		}
	}
	if(n%4==3){
		loop(5){
			loopi(j,5) ans[i+5][j+5]=ans[i][j];
		}
		loop(5){
			loopi(j,5) ans[i+10][j+10]=ans[i+5][j+5];
		}
		loop(n){
			loopi(j,n){
				if(i<=14||j<=14) continue;
				ans[i][j]=c[i-15][j-15];
			}
		}
	}
	loop(n){
		loopi(j,n) cout << ans[i][j];
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);
int asc(const void *a, const void *b);
int desc(const void *a, const void *b);
double to_deg(double rad);

//main function
int main() {
    int a = iin(), b = iin();
    iout((a > 9 || b > 9) ? -1 : a*b);
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

/*
    int型の最大公約数
*/

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    int型の最小公倍数
*/

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    long long型の最大公約数
*/

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    long long型の最小公倍数
*/

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    int型の昇順用比較関数
*/

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

/*
    int型の降順用比較関数
*/

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

/*
    弧度法を度数法に
*/

double to_deg(double rad) {
    return rad * 180.0 / (atan(1.0) * 4.0);
}


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

int main(void) {
    int N; cin >> N;
    int AC=0,WA=0,TLE=0,RE=0;
    for(int i=0; i<N; i++) {
        string S; cin >> S;
        if(S == "AC") AC++;
        else if(S == "WA") WA++;
        else if(S == "TLE") TLE++;
        else if(S == "RE") RE++;
    }

    cout << "AC" << " " << 'x' << " " << AC << endl;
    cout << "WA" << " " << 'x' << " " << WA << endl;
    cout << "TLE" << " " << 'x' << " " << TLE << endl;
    cout << "RE" << " " << 'x' << " " << RE << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a * b/ gcd(a, b);
}
int main() {
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long all = B - A + 1;
    long long ableC = (B / C) - (A-1) / C;
    long long ableD = B / D - (A-1) / D;
    long long CD = lcm(C, D);
    long long ableCD = B / CD - (A-1) / CD;
    long long ans = all - ableC - ableD + ableCD;
    cout << ans << endl;
    return 0;
}



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

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; }

using ll = long long;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

void dfs(const graph &g,vector<int> &v, int s,int parent,vector<int> &P,vector<int> &d){
  for(auto nx:g[s]){
    if(nx==parent)continue;
    P[nx]=s;
    d[nx]=d[s]+1;
    dfs(g,v,nx,s,P,d);
    v[s]+=v[nx];
  }
  v[s]++;
}

int main() {
  int N;
  cin>>N;
  graph g(N);
  for(int i = 0; i < N-1; i++) {
    int x,y;
    cin>>x>>y;
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
  }
  vector<int> A(N,0),B(N,0);
  vector<int> Aparent(N,-1),Bparent(N,-1),Adis(N,0),Bdis(N,0);
  dfs(g,A,0,-1,Aparent,Adis);
  dfs(g,B,N-1,-1,Bparent,Bdis);
  int d = Adis[N-1]-1;
  int a=0,b=0;
  a+=B[0];
  b+=A[N-1];
  int S = 0,T=Bparent[0];
  for(int i = 0; i < d; i++){
    if(i<(d+1)/2) a+= B[T]-B[S];
    else b+=B[T]-B[S];
    S=T;
    T=Bparent[S];
  }
  if(a>b) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fi first
#define se second
#define endl '\n'

const int N = 1e5;

struct Cake{
    ll x, y, z;
};

pll v[N+5];
Cake arr[N+5];

ll value(Cake a, bool p1, bool p2, bool p3){
    ll ret = 0;

    if(p1 == 1) ret += a.x;
    else ret += (a.x < 0? abs(a.x) : -a.x);

    if(p2 == 1) ret += a.y;
    else ret += (a.y < 0? abs(a.y) : -a.y);

    if(p3 == 1) ret += a.z;
    else ret += (a.z < 0? abs(a.z) : -a.z);

    return ret;
}

int main(){

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

    ll n, m; cin >>n >>m;
    for(int i = 0; i<n; i++) cin >>arr[i].x >>arr[i].y >>arr[i].z;

    ll ans = 0;
    ll t1, t2, t3;
    for(int i = 0; i<=1; i++){
        for(int j = 0; j<=1; j++){
            for(int k = 0; k<=1; k++){

                ll aux = 0;
                t1 = t2 = t3 = 0;

                for(int a = 0; a<n; a++){
                    //if(!p1 && !p2 && !p3) cout <<value(arr[a]) <<endl;
                    v[a] = {-value(arr[a], i, j, k), a};
                }

                sort(v, v+n);

                for(int a = 0; a<m; a++){
                    t1 += arr[v[a].se].x;
                    t2 += arr[v[a].se].y;
                    t3 += arr[v[a].se].z;
                }

                aux = abs(t1) + abs(t2) + abs(t3);

                if(aux > ans) ans = aux;

            }
        }
    }


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


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

int main(){
	int N , M;
	scanf("%d%d",&N,&M);
	int ans = 1 , x;
	for( int i = 1 ; i < sqrt(M) + 1 ; i++ ){
		if( M % i  == 0 ) {
			x = M / i ;
			if( i < x && i >= N ) {
				if( ans < x )ans = x;
			}
			if( i < x && x >= N ) {
				if( ans < i )ans = i;
			}



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

	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;

int main()
{
    int N;
    double T,A;
    cin >> N;
    cin >> T >> A;
    pair<double,double> H[N];

    for (int i = 0; i < N; i++) {
        cin >> H[i].first;
        H[i].second = i+1;
    }

    for (int i = 0; i < N; i++) {
        H[i].first = abs(T - H[i].first * 0.006 - A);
    }

    sort(H,H+N);
    cout << H[0].second << endl;
}


Measured memory_bytes: 256
a = int(input())
b = list(map(int, input().split()))
ans1 = 0
ans2 = 0
c = sorted(b, reverse=True)
for i in range(a):
    if i % 2 ==1:
        ans1 += c[i]
    else:
        ans2 += c[i]
print((ans1-ans2)*-1)

Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#define mp make_pair
#define ii pair < ll, ll >
#define F first
#define S second
#define i_ii pair < ll, ii >
#define mpp(AA, BB, CC) mp( AA, mp(BB, CC) )
#define ll long long int

using namespace std;

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int v[3];
    cin >> v[0] >> v[1] >> v[2];
    sort(v, v + 3);
    int a = v[2] - v[1];
    v[1] += a;
    v[0] += a;
    int res = a;
    a = v[2] - v[0];
    //cout << res << ' ';
    res += (a + 1)/2;
    v[0] += a + a%2;
    //cout << res << ' ';
    if(v[0] != v[2]) res++;
    //cout << res << endl;
    cout << res;
    return 0;
}














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

int main(){
        int N;
        cin >> N;
        vector<int> a(N);
        for(int i=0;i<N;i++){
               cin >>  a.at(i);
        }

        vector<int> b(N);
        for(int i=0;i<N;i++){
               cin >>  b.at(i);
        }
        vector<int> c(N-1);
        for(int i=0;i<N-1;i++){
               cin >>  c.at(i);
        }
        int sum=0;
        for(int i=0;i<N-1;i++){
                if(a.at(i+1)==a.at(i)+1){
                sum+=b.at(a.at(i)-1)+c.at(a.at(i)-1);
                }else{
                sum+=b.at(a.at(i)-1);
                }
        }
        sum+=b.at(a.at(N-1)-1);
        cout << sum << endl;
        return 0;
}


Measured memory_bytes: 256
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  C = [a-b for a,b in zip(A,B)]
  if sum(C)<0:
    return -1
  c = sum([-a for a in C if a<0])
  C.sort(reverse=True)
  ans = 0
  for i in range(N):
    if C[i]<0:
      ans += 1
      continue
    if C[i]==0 or c==0:
      continue
    c = max(c-C[i],0)
    ans += 1
  return ans
print(solve())

Measured memory_bytes: 24372
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto nm = readints();
    int n = nm[0], m = nm[1];

    auto xs = new bool[](n + 1); // 1 から i へ定期便があるか
    auto ys = new bool[](n + 1); // n から i へ定期便があるか
    for (int i = 0; i < m; i++) {
        auto ab = readints();
        int a = ab[0], b = ab[1];
        if (a > b)
            swap(a, b);

        if (a == 1)
            xs[b] = true;
        if (b == n)
            ys[a] = true;
    }

    bool found = false;
    for (int i = 2; i < n; i++) {
        if (xs[i] && ys[i]) {
            found = true;
            break;
        }
    }
    writeln(found ? "POSSIBLE" : "IMPOSSIBLE");
}


Measured memory_bytes: 3580