akhauriyash/Code-Regression huggingface dataset:
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
    #define ll long long int
    #define MOD 1000000007
    #define mod 998244353
    #define pi 3.1415926535
    #define fi first
    #define se second
    #define vll vector<ll>
    #define vpll vector<pair <ll,ll> >
    #define vvll vector< vll >
    #define str string
    #define umap unordered_map
    #define uset unordered_set
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define repA(i,s,n) for(ll i=s;i<=n;i++)
    #define repD(i,s,n) for(ll i=s;i>=n;i--)
    #define pb push_back
    #define mp make_pair
    #define lb lower_bound
    #define ub upper_bound
    #define elif else if
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ALL(v) v.begin(),v.end()
    #define sortA(v) sort(ALL(v))
    #define sortD(v) sort(ALL(v),greater <ll> ())
    #define print(v) for(auto itr:v) cout<<*itr<<" ";
    #define sz size()
    #define nl cout<<"\n";
    using namespace std;
    ll factorial(ll n){return (n==1||n==0)?1:n*factorial(n-1);}
    ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
    ll powerMod(ll x,ll y,ll m){if(y==0)return 1;ll p=powerMod(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
    ll modInverse(ll a,ll m){return powerMod(a,m-2,m);}

    int main(){
        fast
        ll x=0,n=0;
        cin>>x>>n;
        if(n==0){cout<<x;return 0;}
        vll v;
        ll temp=0;
        rep(i,n){
            cin>>temp;
            v.pb(temp);
        }
        ll i=0;
        while(true){
            if(find(ALL(v),x-i)==v.end()){
                cout<<x-i;
                break;
            }
            elif(find(ALL(v),x+i)==v.end()){
                cout<<x+i;
                break;
            }
            i++;
        }
        return 0;
    }

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
typedef pair<P,int> PP;

int dp[333][333];

int main(){
	int d,n;
	cin>>d>>n;
	int temp[333];
	PP wear[333];
	
	for(int i=0;i<300;i++)
	for(int j=0;j<300;j++)dp[i][j]=-1;
	
	for(int i=0;i<d;i++)cin>>temp[i];
	
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		wear[i]=make_pair(make_pair(a,b),c);
		}
		
		for(int i=0;i<n;i++){
			if(wear[i].first.first<=temp[0]&&temp[0]<=wear[i].first.second){
				dp[1][i]=0;
				}
			}
			
			for(int td=2;td<=d;td++){//today
				for(int i=0;i<n;i++){
					if(wear[i].first.first<=temp[td-1]&&temp[td-1]<=wear[i].first.second){
						dp[td][i]=0;
						}
					}
					
					for(int i=0;i<n;i++){
						for(int j=0;j<n;j++){
							if(dp[td-1][i]!=-1&&dp[td][j]!=-1){
								dp[td][j]=max(dp[td][j],dp[td-1][i]+abs(wear[i].second-wear[j].second));
								}
							}
						}
				}
				
		int ans=0;
		for(int i=0;i<300;i++){
			ans=max(ans,dp[d][i]);
			}	
		cout<<ans<<endl;
		return 0;		
	}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

struct prog {
    int s, t, c;
};

bool operator<(prog a, prog b) {
    return (a.c == b.c ? a.s < b.s : a.c < b.c);
}

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

    int H, W, N;
    cin >> H >> W >> N;

    vector<vector<int>> ans(H, vector<int>(W));
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        for (int j = cnt; j < cnt + a; ++j)
            ans[j / W][j % W] = i + 1;
        cnt += a;
    }

    for (int i = 0; i < H; ++i) {
        if (i % 2 == 0) {
            for (auto j = ans[i].begin(); j != ans[i].end(); ++j)
                cout << *j << ' ';
        }
        else {
            for (auto j = ans[i].rbegin(); j != ans[i].rend(); ++j)
                cout << *j << ' ';
        }
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
  int i,n;
  char str[256],rts[256];
  scanf ("%255s",&str);
  for (i=0;str[i]!='\0';i++)
    {}
  n=i-1;
  for (i=0;str[i]!='\0';i++)
    {
      rts[n-i]=str[i];
    }
  printf("%s\n",rts);
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const int INF = 1000000;

//階乗関数
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int x,n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  
  int i = 0;
  int ans_min=INF,ans_count;

  while(i < 102) {
    bool flag = true;
    rep(j,n){
      if(i == p.at(j)){
        flag = false;
      }
    }

    if(flag){
      int tmp = abs(x - i);
      if(ans_min > tmp){
        ans_min = min(tmp,ans_min);
        ans_count = i;
      }
      
    }
    i++; 
  }

  cout << ans_count << endl;
}



Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	
		int i;
		int a[1000];
		int sum = 0;
		int max = 0;

		for(i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
			if(a[i] > max)
				max = a[i];
			sum += a[i];
		}

		

		
		printf("%d\n", sum - max / 2);
	
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9+7;

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

    ll n,a,b; cin>>n>>a>>b;
    cout << min(n*a,b);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC155_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dic = new Dictionary<int, int>();
            foreach (var n in abc)
            {
                if (dic.ContainsKey(n))
                {
                    dic[n]++;
                }
                else
                {
                    dic.Add(n, 1);
                }
            }

            if (dic.Count == 2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13280
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
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")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let a = read::<String>().chars().collect::<Vec<_>>();
    if n % 2 != 0 {
        println!("No");
        return;
    }

    let m = n / 2;

    for i in 0..m {
        if a[i] != a[m + i] {
            println!("No");
            return;
        }
    }
    println!("Yes")
}


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

int n, k;
vector<int> a;

bool f(ll c)
{
  vector<ll> m(n);
  ll msum = 0;
  rep(j, n)
  {
    m[j] = a[j] % c;
    msum += m[j];
  }
  sort(m.begin(), m.end());
  ll msum2 = 0;
  for (int j = m.size() - 1; j >= 0; j--)
  {
    msum -= m[j];
    msum2 += c - m[j];
    if (max(msum, msum2) <= k)
    {
      cout << c << endl;
      return true;
    }
  }
  return false;
}

int main()
{
  cin >> n >> k;
  a.resize(n);
  ll s = 0;
  rep(i, n)
  {
    cin >> a[i];
    s += a[i];
  }
  vector<ll> c;
  for (ll i = 1; i * i <= s; i++)
    if (s % i == 0)
    {
      if (f(s / i))
        return 0;
      c.push_back(i);
    }
  for (int i = c.size() - 1; i >= 0; i--)
    if (f(c[i]))
      return 0;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct edge {
	int to, id;
};
int main() {
	int N, Q;
	cin >> N >> Q;
	vector<int> A(N - 1), B(N - 1), C(N - 1), D(N - 1);
	vector<vector<edge> > G(N);
	vector<vector<int> > coledge(N - 1);
	for (int i = 0; i < N - 1; ++i) {
		cin >> A[i] >> B[i] >> C[i] >> D[i]; --A[i], --B[i], --C[i];
		G[A[i]].push_back(edge{ B[i], i });
		G[B[i]].push_back(edge{ A[i], i });
		coledge[C[i]].push_back(i);
	}
	int bits = 1;
	while ((1 << bits) <= N) ++bits;
	vector<vector<int> > par(bits, vector<int>(N));
	vector<int> depth(N), vord(N), eordl(N - 1), eordr(N - 1);
	int cnt = 0;
	function<void(int, int)> dfs = [&](int pos, int pre) {
		vord[pos] = cnt;
		for (edge e : G[pos]) {
			if (e.to == pre) continue;
			eordl[e.id] = cnt++;
			depth[e.to] = depth[pos] + 1;
			par[0][e.to] = pos;
			dfs(e.to, pos);
			eordr[e.id] = cnt++;
		}
	};
	dfs(0, -1);
	for (int i = 1; i < bits; ++i) {
		for (int j = 0; j < N; ++j) {
			par[i][j] = par[i - 1][par[i - 1][j]];
		}
	}
	function<int(int, int)> lca = [&](int va, int vb) {
		if (depth[va] < depth[vb]) swap(va, vb);
		for (int i = bits - 1; i >= 0; --i) {
			if (depth[va] - depth[vb] >= (1 << i)) {
				va = par[i][va];
			}
		}
		if (va == vb) return va;
		for (int i = bits - 1; i >= 0; --i) {
			if (par[i][va] != par[i][vb]) {
				va = par[i][va];
				vb = par[i][vb];
			}
		}
		return par[0][va];
	};
	vector<int> X(Q), Y(Q), U(Q), V(Q);
	vector<vector<int> > colquery(N - 1);
	for (int i = 0; i < Q; ++i) {
		cin >> X[i] >> Y[i] >> U[i] >> V[i]; --U[i], --V[i], --X[i];
		colquery[X[i]].push_back(i);
	}
	vector<vector<int> > bit(2, vector<int>(2 * N + 1));
	function<void(int, int, int)> add = [&](int id, int pos, int val) {
		for (int i = pos + 1; i <= 2 * N; i += i & (-i)) {
			bit[id][i] += val;
		}
	};
	function<int(int, int)> sum = [&](int id, int pos) {
		int ans = 0;
		for (int i = pos; i >= 1; i -= i & (-i)) {
			ans += bit[id][i];
		}
		return ans;
	};
	for (int i = 0; i < N - 1; ++i) {
		add(0, eordl[i], +D[i]);
		add(0, eordr[i], -D[i]);
	}
	vector<int> qans(Q);
	for (int i = 0; i < N - 1; ++i) {
		for (int j : coledge[i]) {
			add(0, eordl[j], -D[j]);
			add(0, eordr[j], +D[j]);
			add(1, eordl[j], +1);
			add(1, eordr[j], -1);
		}
		for (int j : colquery[i]) {
			int W = lca(U[j], V[j]);
			qans[j] += Y[j] * (sum(1, vord[U[j]]) - sum(1, vord[W]));
			qans[j] += Y[j] * (sum(1, vord[V[j]]) - sum(1, vord[W]));
			qans[j] += sum(0, vord[U[j]]) - sum(0, vord[W]);
			qans[j] += sum(0, vord[V[j]]) - sum(0, vord[W]);
		}
		for (int j : coledge[i]) {
			add(0, eordl[j], +D[j]);
			add(0, eordr[j], -D[j]);
			add(1, eordl[j], -1);
			add(1, eordr[j], +1);
		}
	}
	for (int i = 0; i < Q; ++i) {
		cout << qans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 33892
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.util.OptionalInt;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumDifference solver = new BMaximumDifference();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumDifference {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            int max = IntStream.of(a).max().getAsInt();
            int min = IntStream.of(a).min().getAsInt();

            out.println(max - min);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

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

    }
}



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

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
//---------------------------------------------------------------

using vi = vector<int>;
void dfs(int src, Matrix &M, vi &time_s, vi &time_t, int &time) {
    int n = M.size();
    time_s[src] = time++;
    for (int dst = 0; dst < n; dst++) {
        if (M[src][dst] && time_s[dst] < 0) {
            dfs(dst, M, time_s, time_t, time);
        }
    }
    time_t[src] = time++;
}

int main() {
    int n; cin >> n;
    Matrix M(n, Array(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int v; cin >> v; M[u - 1][v - 1]++;
        }
    }
    vector<int> time_s(n, -1), time_t(n, -1);
    int time = 0;
    for (int i = 0; i < n; i++) if (time_s[i] < 0) {
        dfs(i, M, time_s, time_t, time);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << time_s[i] + 1 << " " << time_t[i] + 1 << endl;
    }
    return 0;
}


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

const int N = (int) 1e5 + 5;

int n, m;
int a[N];

long long ans = 0;
multiset <int> myset;
multiset <int> :: iterator it;

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		myset.insert(a[i]);
	}
	while (m--) {
		it = myset.end();
		it--;
		int v = *it;
		myset.erase(it);
		myset.insert(v / 2);
	}
	for (it = myset.begin(); it != myset.end(); it++) {
		ans += *it;
	}
	cout << ans;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool judge = false;
  for (int i = 0; i < N; i++) {
    char tmp;
    cin >> tmp;
    if (tmp == 'Y') {
      judge = true;
      break;
    }
  }
  if (judge) cout << "Four" << endl;
  else cout << "Three" << endl;
}


Measured memory_bytes: 256
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))

sorted_A = sorted(A)

left_med = sorted_A[(N-1)//2]
right_med = sorted_A[(N+1)//2]

for i in range(N):
  if A[i] <= left_med:
    print(right_med)
  else:
    print(left_med)


Measured memory_bytes: 92508
A['   '];
M;
B, X, Y;
W, J, I;
main() {
  scanf("%d%d", &I, &M);
  for (; ~scanf("%d%d", &X, &Y);) {
    for (B = Y + 1, J = 1; J * J <= M; J++)
      I = (X + J - 1) / J, W = Y / J + 1, A[I]++, A[W < B ? W : B]--, B = I;
    for (I = 1; I < B; I++)
      (X - 1) / I < Y / I ? A[I]++, A[I + 1]-- : 0;
  }
  for (I = 1; I <= M; I++) {
    A[I] += A[I - 1];
    printf("%d\n", A[I]);
  }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    if(s[len-1]!='s'){
        cout<<s<<"s"<<endl;
    }
    else
    {
        cout<<s<<"es"<<endl;
    }
    return 0;
}


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

const int _ = 1e5 + 6;
vector < int > nxt[_]; int N , cnt;

int dfs(int x , int p){
	int lft = 1;
	for(auto t : nxt[x])
		if(t != p && dfs(t , x) && lft){++cnt; lft = 0;}
	return lft;
}

int main(){
	cin >> N; for(int i = 1 ; i < N ; ++i){int p , q; cin >> p >> q; nxt[p].push_back(q); nxt[q].push_back(p);}
	dfs(1 , 0); cout << (cnt * 2 == N ? "Second" : "First");
	
	return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
 
 
int N;
long long A[200002];
 
bool Check(long long val)
{
  for(int i = 1; i <= N; i++) {
    long long *Begin = &A[i], *End = &A[i + N + 1]; // ???????????????
    bool Flag = true;
    for(int j = 0; j < 3; j++) {
      long long Need = *Begin + val;
      long long *It = lower_bound(Begin, End, Need);
      if(It == End) {
        Flag = false;
        break;
      }
      Begin = It;
    }
    if(Flag) return(true);
  }
  return(false);
}
 
int main()
{
  cin >> N;
  for(int i = 1; i <= N + N; i++) {
    if(1 <= i && i <= N) {
      cin >> A[i];
      A[i + N] = A[i];
    }
    A[i] += A[i - 1];
  }
  long long low = 0, high = 1LL << 60;
  while(high - low > 0) {
    long long mid = (low + high + 1) >> 1;
    if(Check(mid)) low = mid;
    else high = mid - 1;
  }
  cout << low << endl;
}

Measured memory_bytes: 2724
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,d  =lr()
d = d*d
ans = 0
for i in range(n):
    x,y = lr()
    if x*x + y*y <= d:
        ans+=1
print(ans)

Measured memory_bytes: 75856
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> h(n+1);
    REP(i,n)cin>>h[i+1];
    vector<vector<ll>> heights(n+1);
    REP(i,m){
        ll a,b;
        cin>>a>>b;
        heights[a].push_back(h[b]);
        heights[b].push_back(h[a]);
    }
    ll cnt=0;
    FOR(i,1,n+1){
        if(SIZE(heights[i])!=0){
            ll highest=MAX(heights[i]);
            if(highest<h[i])cnt++;
        }else{
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main() {
  string s,t,u;
  cin >> s>>t;
  int a,b;
  cin >> a>>b;
  cin >> u;
  if (u==s){
    cout << a-1 << " "<< b<< endl;
  } else {
    cout << a << " "<< b-1<< endl;
  }
  return 0;
}


Measured memory_bytes: 256
use std::io::BufRead;
use std::collections::HashSet;

fn main() {
	print!("{}", result());
}

fn result() -> usize {
	let stdin = std::io::stdin();
	let num = stdin
		.lock()
		.lines()
		.skip(1)
		.flat_map(|l| l)
		.flat_map(|l| l.parse::<i64>())
		.fold(HashSet::new(), |mut v, e|
			if v.contains(&e) {
				v.remove(&e);
				v
			} else {
				v.insert(e);
				v
			})
		.len();
	num
}


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

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

#include<algorithm>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll X[N];
  ll ave = 0;
  REP(i,N){
    cin >> X[i];
    ave += X[i];
  }
  ave = ave/N;

  ll ret1 = 0;
  REP(i,N){
    ret1 += (X[i] - ave) * (X[i] -ave);
  }

  ll ret2 = 0;
  REP(i,N){
    ret2 += (X[i] - ave - 1) * (X[i] - ave - 1);
  }


  cout << min(ret1,ret2) << endl;
  return 0;
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	dsu d(N);

	for (int i=0; i<M; i++) {
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		d.merge(A, B);
	}

	int ans = d.groups().size() - 1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;

ll solve(ll l, ll r) {
    ll n = r - l + 1;
    return n * (2*l + (n-1)) / 2;
}

ll add(ll a, ll b) {
    return (a+b)%mod;
}

ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}
int main() {
    fastIO;
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int i = k; i <= n+1; i++) {
        ll x = solve(0, i-1);
        ll y = solve(n - i + 1, n);
        //cout << x << ' ' << y << endl;
        ans = add(ans, sub(y, x));
        ans = add(ans, 1);
    }
    cout << ans;
}

Measured memory_bytes: 3588
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

template<typename Type> class RangeTree {
private:
	int size_; std::vector<std::vector<Type> > dat;
	inline int query_(int a, int b, Type x, int k, int l, int r) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r)
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return lower_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin();
		int lc = query_(a, b, x, (k << 1), l, (l + r) >> 1);
		int rc = query_(a, b, x, (k << 1) + 1, (l + r) >> 1, r);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::vector<Type>());
		for (int i = 0; i < n; i++) dat[i + size_] = std::vector<Type>({ *(begin_ + i) });
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[(i << 1) + 1].size());
			std::merge(dat[i << 1].begin(), dat[i << 1].end(), dat[(i << 1) + 1].begin(), dat[(i << 1) + 1].end(), dat[i].begin());
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		return query_(l, r, x, 1, 0, size_);
	}
};

#endif

vector<int>vec;
int n, q, a, b, c;
int main() {
	cin >> n; for (int i = 0; i < n; i++) { cin >> a; vec.push_back(a); }
	RangeTree<int>p(vec.begin(), vec.end());
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b >> c; a--; b--;
		int d = min(vec[a], vec[b]) - c, e = max(vec[a], vec[b]) + c;
		int V = p.query(a, b + 1, e + 1);
		int W = p.query(a, b + 1, d);
		cout << (b - a + 1) - (V - W) << endl;
	}
	return 0;
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, a, b, max_val;
ll l, r = 1000000000, mid, ans;
vector<int> h;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> a >> b;
    rep(i, 0, n) {
        int x; cin >> x;
        max_val = max(max_val, x);
        h.pb(x);
    }
    while (l <= r) {
        mid = (l+r) / 2;
        ll sum = 0;
        rep(i, 0, n) {
            if (h[i] > mid * b) {
                sum += (h[i] - mid * b + a - b - 1)/(a-b);
            }
        }
        if (sum <= mid) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	scanf("%d", &n);
	int ans = 2e9;
	for(int i=1;i<=n-1;i++){
		int a = i, b = n-a;
		int res = 0;
		while(a){
			res += a%10;
			a/=10;
		}
		while(b){
			res += b%10;
			b/=10;
		}
		ans = min(ans, res);
	}
	printf("%d\n", ans);
}

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

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

	int n, x, score = 0;
	cin >> n;
	vector<int> sn;
	for (int i = 0; i < n; ++i){
		cin >> x;
		score += x;
		if (x % 10 != 0){
			sn.push_back(x);
		}
	}
	if (sn.empty()){
		cout << "0" << "\n";
		return 0;
	}
	if (score % 10 == 0){
		sort(sn.begin(), sn.end());
		score -= sn[0];
	}
	cout << score << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[101101],ans;
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[i]==a[i-1])ans++;
    }
    if(ans&1)ans++;
    cout<<n-ans<<"\n";
    exit(0);
  
}

Measured memory_bytes: 640
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll n;
    cin >> n;
    cout <<(n*(n +1)) /2;

  return 0;
}


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

int main() {
  long long int k, a, b;
  cin >> k >> a >> b;
  
  k -= (a - 1);
  long long int ans = a;

  if((b - a) > 2) {
    if(k % 2 == 0) ans += (b - a) * (k / 2);
    else ans += (b - a) * (k / 2) + 1;
  } else {
    ans += k;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  string s;
  cin >> s;
  rep0(i,(1<<3)){
    bitset<10>t(i);
    int temp = 0;
    temp += (s[0] - '0');
    rep0(j,3){
      if(t.test(j))temp += (s[j+1] - '0');
      else temp -= (s[j+1] - '0');
    }
    if(temp == 7){
      cout << s[0];
      if(t.test(0))cout<<'+';
      else cout<<'-';
      cout << s[1];
      if(t.test(1))cout<<'+';
      else cout<<'-';
      cout << s[2];
      if(t.test(2))cout<<'+';
      else cout<<'-';
      cout << s[3];
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	double x=0,y=0;
	double l,a=0,b;
	for(;~scanf("%lf,%lf",&l,&b);)
	{
		x+=l*sin(a);
		y+=l*cos(a);
		a+=b/180*M_PI;
	}
	cout<<(int)x<<"\n"<<(int)y<<endl;
}



Measured memory_bytes: 3536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> ipair;


int N, a[MAX_N + 1], b[MAX_N + 1], c[MAX_N + 1];
vector<int> adj[MAX_N + 1];
int res[MAX_N + 1];
int max_rank = -INF;

vector<int> ranks[MAX_N];
void set_rank(int node, int before, int rank) {
    max_rank = max(max_rank, rank);
    ranks[rank].push_back(node);
    for(int i = 0; i < adj[node].size(); ++i)
        if(adj[node][i] != before) {
            set_rank(adj[node][i], node, rank + 1);
        }
}

void print() {
    int rank = max_rank;
    for(int i = 1; i <= N; ++i) {
        int cur = ranks[rank][ranks[rank].size() - 1];
        ranks[rank].pop_back();
        res[cur] = c[i];

        if(ranks[rank].empty())
            rank--;
    }
}

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 1; i <= N - 1; ++i) {
        cin >> a[i] >> b[i];
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }

    for(int i = 1; i <= N; ++i) {
        cin >> c[i];
    }
    sort(c + 1, c + N + 1);

    int c_sum = 0;
    for(int i = 1; i <= N; ++i) {
        if(i < N)
            c_sum += c[i];
    }
    
    cout << c_sum << endl;

    set_rank(1, -INF, 0);
    print();
    
    for(int i = 1; i <= N; ++i) {
        cout << res[i];
        if(i != N)
            cout << " ";
    }
    cout << endl;
}

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

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
using ll = long long;

int main(){
	fastIO;
	int k,a,b;
	bool ok = false;
	cin >> k >> a >> b;
	for(int i=a;i<=b;++i){
		if(i%k==0){
			ok = true;
		}
	}
	cout << (ok ? "OK" : "NG") << '\n';
	return 0;
}

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

#define endl '\n'
#define endt '\t'
#define ends ' '
#define die(x) return cout << x << endl, 0;
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 924844033; 

////////////////////////

const int MAXN = 64;

int BigPower(ll a) {
	int b = -1;
	while (a) b++, a >>= 1;
	return b;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef LOCAL
	ifstream cin("sample.in");
	#endif

	ll a, b; cin >> a >> b;
	int p = MAXN - 1;
	while (p >= 0 && (a >> p) == (b >> p)) p--;
	if (p == -1) die(1);
	ll c = 1LL << p;
	a &= (c << 1) - 1, b &= (c << 1) - 1;
	b = (1LL << (BigPower(b - c) + 1)) - 1;
	if (b < a) cout << (c + b - a + 1) + (c - a) << endl;
	else cout << ((c << 1) - 1) - a + 1 << endl;

	return 0;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {
  // constant
  static final int INF = 1 << 30;

  // subroutines
  static int gcd(int a, int b) {
    if (a < b) {
      int tmp = a; a = b; b = tmp;
    }

    while (b > 0) {
      int r = a % b;
      a = b;
      b = r;
    }
    return a;
  }

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

    for (;;) {
      int m = sc.nextInt();
      int n = sc.nextInt();
      if ((m | n) == 0) break;

      int[] cbs = new int[m];
      for (int i = 0; i < m; i++) cbs[i] = sc.nextInt();

      int[] crs = new int[n];
      for (int i = 0; i < n; i++) crs[i] = sc.nextInt();

      int vn = m + n + 2;
      int st = m + n;
      int gl = m + n + 1;

      int[][] edges = new int[vn][vn];
      int[][] fs = new int[vn][vn];
      for (int i = 0; i < vn; i++)
	for (int j = 0; j < vn; j++)
	  edges[i][j] = fs[i][j] = 0;

      ArrayList<ArrayList<Integer>> nbrs = new ArrayList<ArrayList<Integer>>();
      for (int i = 0; i < vn; i++)
	nbrs.add(new ArrayList<Integer>());
  
      for (int i = 0; i < m; i++)
	for (int j = 0; j < n; j++)
	  if (gcd(cbs[i], crs[j]) > 1) {
	    edges[i][m + j] = 1;
	    nbrs.get(i).add(m + j);
	    nbrs.get(m + j).add(i);
	  }

      for (int i = 0; i < m; i++) {
	edges[st][i] = 1;
	nbrs.get(st).add(i);
      }

      for (int j = 0; j < n; j++) {
	edges[m + j][gl] = 1;
	nbrs.get(m + j).add(gl);
      }

      int[] prevs = new int[vn];
      int[] dists = new int[vn];
      
      for (;;) {
	for (int i = 0; i < vn; i++) {
	  prevs[i] = -1;
	  dists[i] = INF;
	}
	dists[st] = 0;

	ArrayList<Integer> q = new ArrayList<Integer>();
	q.add(st);

	while (! q.isEmpty()) {
	  int u = q.remove(0);
	  if (u == gl) break;

	  for (int v: nbrs.get(u)) {
	    if (fs[u][v] == edges[u][v]) continue;
	    int vd = dists[u] + 1;
	    if (dists[v] > vd) {
	      dists[v] = vd;
	      prevs[v] = u;
	      q.add(v);
	    }
	  }
	}
	if (dists[gl] >= INF) break;
    
	ArrayList<Integer> path = new ArrayList<Integer>();
	int u = gl;
	while (prevs[u] >= 0) {
	  path.add(0, u);
	  u = prevs[u];
	}
    
	int min_c = INF;
	u = st;
	for (int v: path) {
	  int cf = edges[u][v] - fs[u][v];
	  if (min_c > cf) min_c = cf;
	  u = v;
	}

	u = st;
	for (int v: path) {
	  fs[u][v] += min_c;
	  fs[v][u] -= min_c;
	  u = v;
	}
      }

      int sum = 0;
      for (int i = 0; i < m; i++) sum += fs[st][i];
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 216564
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        Console.WriteLine(getAns(n, k));
    }
    static int getAns(int n, int k)
    {
        var w = 1;
        var t = 1;
        while (true)
        {
            w *= k;
            if (w == n) return t + 1;
            else if (w > n) return t;
            t++;
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

ll f(ll n, ll k) {
    while (n >= k) {
        if (n % k == 0) {
            n /= k;
        }
        else {
            n -= k;
        }
    }
    return n;
}

int solve(ll n) {
    if (n == 2) {
        return 1;
    }
    int ans = 2;
    for (int d = 2; 1ll * d * d <= n - 1; d++) {
        if ((n - 1) % d == 0) {
            if (1ll * d * d == n - 1) ans++;
            else ans += 2;
        }
    }
    for (int d = 2; 1ll * d * d <= n; d++) {
        if (n % d == 0) {
            ll N = n;
            while (N % d == 0) {
                N /= d;
            }
            if (N % d == 1) ans++;
            N = n;
            int dd = N / d;
            while (N % dd == 0) {
                N /= dd;
            }
            if (N % dd == 1 && dd != d) ans++;
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ll n;
    cin >> n;
    cout << solve(n) << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize 03
#pragma GCC optimize ("unroll-loops")
#define int long long
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
const int N = 3e5 + 2e5;
const int inf = 2e9;
const int MOD = 1e9 + 7;
const int LogN = 30;

int mod(int a) {
    a %= MOD;
    return a;
}

void solve() {
    int D, T, S;
    string s, t;
    int n;
    int ans = 0, sum = 0;
    cin >> n;
    while (n--) {
        int x;
        cin >> x;
        ans = mod(ans + x * sum);
        sum = mod(sum + x);
    }
    cout << ans;
}

signed main() {
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0);
    solve();
}


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

int i,j,n;
string str;
int gcd(int x,int y){
    return (y == 0)?x:gcd(y,x%y);
}
int main(){
    cin >> n;
    int k;
    cin >> k;
    vector<int> a(n);
    for(i = 0;i < n;i++){
        cin >> a[i];
    }
    int maximum = a[0],maximums = a[0];
    for(i = 1;i < n;i++){
        if(a[i] > maximum) maximum = a[i];
        maximums = gcd(maximums,a[i]);
    }
    if(k <= maximum && k % maximums == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


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

int main(){
    int m, n;
    cin >> m >> n;
    for(int i = 0; i <= m; i++)
    for(int j = 0; j <= m; j++)
    for(int k = 0; k <= m, i + j + k <= m; k++){
        if(i + j + k == m && i*1000 + j*5000 + k*10000 == n){
            cout << k << " " << j << " " << i;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;

return 0;
}

Measured memory_bytes: 3648
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;
 
#pragma endregion
 
 
 
int main(){
  
  ll a;
  string s;
  cin >> a >> s;
  ll c = 100*(s[0] - '0') + 10*(s[2] - '0') + 1*(s[3] - '0');
  //cout << c << endl;
  cout << a*c / 100 << endl;
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int[] e1 = new int[n];
    int[] w1 = new int[n];
    int[] e2 = new int[n];
    int[] w2 = new int[n];
    for(int i = 0; i < n; i++) {
      if(i == 0) {
        if(s.charAt(i) == 'E') {
          e1[0] = 1;
        } else { 
          w1[0] = 1;
        }
      } else {
        if(s.charAt(i) == 'E') {
          e1[i] = e1[i - 1] + 1;
          w1[i] = w1[i - 1];
        } else {
          e1[i] = e1[i - 1];
          w1[i] = w1[i - 1] + 1;
        }
      }
    }
    for(int i = n - 1; i >= 0; i--) {
      if(i == (n - 1)) {
        if(s.charAt(i) == 'E') {
          e2[n - 1] = 1;
        } else { 
          w2[n - 1] = 1;
        }
      } else {
        if(s.charAt(i) == 'E') {
          e2[i] = e2[i + 1] + 1;
          w2[i] = w2[i + 1];
        } else {
          e2[i] = e2[i + 1];
          w2[i] = w2[i + 1] + 1;
        }
      }
    }
    int ans = n;
    for(int k = 0; k < n; k++) {
      if(k == 0) {
        ans = Math.min(ans, e2[1]);
      } else if(k == (n - 1)) {
        ans = Math.min(ans, w1[n - 2]);
      } else {
        ans = Math.min(ans, w1[k - 1] + e2[k + 1]);
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 33880
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9+7;


int main() {
	string S;
  	cin >> S;
  	if(S == "ABC") cout << "ARC" << endl;
  	else cout << "ABC" << endl;
}

Measured memory_bytes: 3624
(X,N) = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)

p.sort!

if N == 0
  puts X
else
  k = p[0]-1
  p.each_index { |i|
    k2 = p[i]-1
    if (k2 - X).abs < (k - X).abs and k2 != p[i-1]
      k = k2
    end
    k2 = p[i]+1
    if (k2 - X).abs < (k - X).abs and k2 != p[i+1]
      k = k2
    end
  }
  
  puts k
end


Measured memory_bytes: 14312
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
const ll inf = 1e10 + 2 ;
const int nmax = 1e5 + 1 ;
void solve(){
   // 1 2 3 4 5 6 . . . . .
   // 2 4 6 8 10 12 . . . .
   // 3 6 
    ll n ;
    cin >> n ;
    ll dis = 1e18 ; 
    for( ll i = 1 ; i*i <= n ; i++){
        if(n%i==0){
            ll x = n / i ; 
            ll ans = i + x - 2 ;
            dis = min(ans,dis);
        }
    }
    cout << dis ;

}
int main(){
//      #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
    int t = 1  ;
    //cin >> t ;
    while(t--)
        solve();
}
// logc (ai*aj) = k logc (x)
// logc ( ai*aj - x ) =  k  

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

using namespace std;

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

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

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

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

struct edge { ll to, cap, rev; };

vector<edge> G[1000];
ll level[1000];	//sからの距離
ll iter[1000];	//どこまで調べ終わったか

void add_edge(ll from, ll to, ll cap) {
	G[from].push_back({ to,cap,(ll)G[to].size() });
	G[to].push_back({ from,0,(ll)G[from].size() - 1 });
}

//sからの最短距離をBFSで計算する
void bfs(ll s) {
	fill(level, level + 1000, -1);
	queue<ll> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		ll v = que.front();
		que.pop();
		for (ll i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

//増加パスをDFSで探す
ll dfs(ll v, ll t, ll f) {
	if (v == t)return f;
	for (ll &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			ll d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

//sからtへの最大流を求める
ll max_flow(ll s, ll t) {
	ll flow = 0;
	for (;;) {
		bfs(s);
		if (level[t] < 0)return flow;
		fill(iter, iter + 1000, 0);
		ll f;
		while ((f = dfs(s, t, INF)) > 0) {//fに流せるパスが存在する間ループ
			flow += f;
		}
	}
}

ll n;
ll x[1000], y[1000];

int main() {
	cin >> n;
	rep(i, 2 * n) {
		cin >> x[i + 1] >> y[i + 1];
	}
	rep(i, n) {
		add_edge(0, i + 1, 1);
	}
	rep(i, n) {
		add_edge(n + 1 + i, 2 * n + 1, 1);
	}
	FOR(i, 1, n + 1) {
		FOR(j, n + 1, 2 * n + 1) {
			if (x[i] < x[j] && y[i] < y[j]) {
				add_edge(i, j, 1);
			}
		}
	}
	cout << max_flow(0, 2 * n + 1) << endl;
}

Measured memory_bytes: 512
main :: IO ()
main = do
  getLine
  hs <- map read . words <$> getLine
  print $ solve hs

solve :: [Int] -> Int
solve hs = head $ tail $ foldl f [0, 0, maxBound, head hs] hs
  where
    f [c_prev, c, h_prev, h] h_next 
      = [c, (c + dist h h_next) `min` (c_prev + dist h_prev h_next), h, h_next]

dist :: Int -> Int -> Int
dist h1 h2 = abs (h1 - h2)


Measured memory_bytes: 48508
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N;
	cin>>N;
	vector<int> A(N);
	rep(i,0,N) cin>>A[i];

	ll res=0;
	map<int,int> cnt;
	rep(i,0,N) {
		if (cnt.count(i-A[i])) res+=cnt[i-A[i]];
		cnt[i+A[i]]++;
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 13388