akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N = 110000;

char s[N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> s + 1;
	int n = strlen(s + 1);
	bool ok = true;
	if (s[1] == '0') ok = false;
	if (s[n] == '1') ok = false;
	for (int i = 1; i < n; i++) {
		if (s[i] != s[n - i]) ok = false;
	}
	vector<int> p(n + 1, -1);
	vector<int> q(n + 1, -1);
	for (int i = 1; i < (n + 1) / 2; i++) {
		p[i] = i + 1;
		p[n - i + 1] = n - i;
	}
	if (n % 2 == 0) p[n / 2] = n / 2 + 1;
	for (int i = 2; i <= n / 2; i++) {
		if (s[i] == '1') continue;
		q[i] = i + 1;
		if (n % 2 != 0 || i != n / 2) q[n - i + 1] = n - i;
	}
	function<int(int)> find = [&](int x) {
		if (q[x] == -1) return x;
		return q[x] = find(q[x]);
	};
	if (ok) {
		for (int i = 1; i <= n; i++) if (p[i] != -1) cout << i << ' ' << find(p[i]) << "\n";
	}
	else cout << "-1";
	return 0;
}


Measured memory_bytes: 6372
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<P> vec[1000]; // F -> pos , S -> cost
int MD[1000][13];
const int INF = 1<<27;

//C++だとなぜかRuntimeErrorになったので仕様変更
//vecにはコストいらないからvector<PP> vec -> vector<P> vec へ


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n+1)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      P po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F][p.S] > p.F.F + po.S){
	MD[po.F][p.S] = p.F.F+po.S;
	que.push(PP(P(MD[po.F][p.S],po.F),p.S));
      }
      if(p.S > 0 && MD[po.F][p.S-1] > p.F.F + po.S/2 ){
	MD[po.F][p.S-1] = p.F.F+po.S/2;
	que.push(PP(P(MD[po.F][p.S-1],po.F),p.S-1));
   
      }
    }
  }
}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(P(y,co));
      vec[y].push_back(P(x,co));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

//Version.1

Measured memory_bytes: 1268
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

const double PI = acos(-1);

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
string Psb[2] = {"Impossible", "Possible"};
string psb[2] = {"impossible", "possible"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    string t = s;
    t[0]--;
    for (int i = 1; i < t.size(); i++) t[i] = '9';
    cout << max(accumulate(all(s), -s.size() * '0'), accumulate(all(t), -t.size() * '0'));
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

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

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

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

bool solve(void){
    int n;
    cin >> n;

    vector<int> a(n);
    int mini = n;
    int maxi = 0;
    rep(i, n){
        cin >> a[i];
        chmin(mini, a[i]);
        chmax(maxi, a[i]);
    }

    if(maxi - mini > 1){
        return false;
    }

    if(maxi == mini){
        return a[0] * 2 <= n || a[0] == n - 1;
    }

    int k = maxi;
    int uni = 0;
    rep(i, n){
        uni += a[i] == k - 1;
    }

    return uni < k && uni + (n - uni) / 2 >= k;
}

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

    if(solve()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    ll n,m;
    cin >> n >> m;
    vector <ll> l,r;
    for (ll i=0;i<m;i++){
        ll p,q;
        cin >> p >> q;
        l.push_back(p);
        r.push_back(q);
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    cout << max(ll(0), r[0] - l[m-1] + 1) << endl;


}

Measured memory_bytes: 2036
a, b, c, x, y = map(int, input().split(' '))

min_price = 100000 * 3 * 5000
for pizza_c in range(max(x, y) * 2 + 1):
        pizza_a = max(x - int(pizza_c / 2), 0)
        pizza_b = max(y - int(pizza_c / 2), 0)
        min_price = min(pizza_a * a + pizza_b * b + pizza_c * c, min_price)
print(min_price)


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

long long int dp[102][100002];int c, n, k, cisim[100][2];

long long int recursive(int konum, int agirlik){
	if(konum>=n)return 0;
	if(agirlik>=c)return 0;
	if(dp[konum][agirlik])return dp[konum][agirlik];

	if(cisim[konum][0]>c-agirlik){
	dp[konum][agirlik]=recursive(konum+1,agirlik);}
	else {
	dp[konum][agirlik]=max(cisim[konum][1]+recursive(konum+1, agirlik+cisim[konum][0]), recursive(konum+1, agirlik));}
	
	return dp[konum][agirlik];
}

int main(void){
	cin>>n>>c;
	for(int i=0;i<n;i++)cin>>cisim[i][0]>> cisim[i][1];
	memset(dp, 0, sizeof(long long int)*(n+1)*100002);
	cout<<recursive(0,0);
	return 0;
}

Measured memory_bytes: 79104
function f(dp,d)
	N=length(dp)
	[i-d>=1&&dp[i-d]||i+d<=N&&dp[i+d] for i=1:N]
end
function main()
	w=false
	x=[false for _=1:16001]
	x[8001]=true
	y=x[:]
	c=0
	F=true
	for s=chomp(readline())
		if s=='F'
			c+=1
		else
			if w
				y=f(y,c)
			else
				if F
					x[8001]=false
					x[8001+c]=true
					F=false
				else
					x=f(x,c)
				end
			end
			w=!w
			c=0
		end
	end
	if w
		y=f(y,c)
	else
		if F
			x[8001]=false
			x[8001+c]=true
			F=false
		else
			x=f(x,c)
		end
	end
	X,Y=map(t->parse(Int,t),split(readline()))
	if x[X+8001]&&y[Y+8001]
		println("Yes")
	else
		println("No")
	end
end
main()


Measured memory_bytes: 155180
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort(reverse=True)
F.sort()


def judge(x):
    val = 0
    for i in range(N):
        val += max(A[i] - x // F[i], 0)
        if val > K:
            return False
    if val <= K:
        return True


ub = 10**12
lb = -1

while lb + 1 < ub:
    x = (ub+lb)/2
    if judge(x):
        ub = x
    else:
        lb = x

print(int(ub))


Measured memory_bytes: 119628
import java.io.*;
import java.util.*;

public class Main {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        long a = in.nextLong();
        long b = in.nextLong();
        long c = in.nextLong();
        long d = in.nextLong();
        if(a > b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long lower = a;
        long upper = a;
        for (int i = 0; i < n; i++) {
            int rest = n - 1 - i;
            if(rest % 2 != 0) {
                lower += c;
                upper += d;
                continue;
            }
            int step = rest / 2;
            long lb = lower - step * (d - c);
            long ub = upper + step * (d - c);
            if(lb <= b && b <= ub) {
                System.out.println("YES");
                return;
            }
            lower += c;
            upper += d;
        }
        System.out.println("NO");
        return;
    }
}


class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 23636
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


using namespace std;



int main() {
	int A, B, T;
	cin >> A >> B >> T;
	cout << T / A * B << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define MAX_DIST 999999999

class Dijkstra{
public:
    struct edge{
        int to;
        int cost;
    };
    int vertex;
    vector<vector<edge>> graph;
    vector<int> dist;

    Dijkstra(int n){
        vertex = n;
        graph = vector<vector<edge>>(n);
        dist = vector<int>(n);
    };

    void dijkstra(int s){
        priority_queue<pii, vector<pii>, greater<pii>> que;
        fill(dist.begin(), dist.end(), MAX_DIST);
        dist[s] = 0;
        que.push(pii(0, s));

        while (!que.empty()){
            pii p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < graph[v].size(); i++) {
                edge e = graph[v][i];
                if (dist[e.to] > dist[v] + e.cost && !(dist[e.to] == MAX_DIST && dist[v] == MAX_DIST)){
                    dist[e.to] = dist[v] + e.cost;
                    que.push(pii(dist[e.to], e.to));
                }
            }
        }

    }

    void addEdge(int from, int to, int cost) {
        edge e;
        e.to = to;
        e.cost = cost;
        graph[from].push_back(e);
    }
};

int main() {
    int v, e;
    cin >> v >> e;
    Dijkstra d(v*3);
    for(int i = 0; i < e; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        d.addEdge(a,b+v,1);
        d.addEdge(a+v,b+2*v,1);
        d.addEdge(a+2*v,b,1);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;

    d.dijkstra(s);
    if(d.dist[t] == MAX_DIST){
        cout << -1 << endl;
    }else{
        cout << d.dist[t]/3 << endl;
    }

    return 0;

}


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

int a[15];

int main(){
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a, a+10);
	cout<<a[9]<<endl
		<<a[8]<<endl
		<<a[7]<<endl;
}

Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n, x;
    cin >> n >> x;
    if(x == 1 || x == 2*n-1){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";

    vector<ll> ans;
    if(x < n){
        rep(i, n-x)cout << 2*n-1-i << endl;
        rep(i, 2*n-1-(n-x))cout << i+1 << endl;
    }
    else if(x > n){
        for(ll i = x-n+1; i<=2*n-1; ++i)cout << i << endl;
        rep(i, x-n)cout << i+1 << endl;
    }
    else rep(i, 2*n-1)cout << i+1 << endl;
}

Measured memory_bytes: 1536
let bin_search x (a : int array) =
  let rec doit l r =
    if l >= r then false
    else begin
      let m = (l + r) / 2 in
      if x = a.(m) then true
      else if x < a.(m) then doit l m
      else doit (m + 1) r
    end
  in
  doit 0 (Array.length a)

let () =
  let read_seq () = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
  let _ = read_int () in
  let s = Array.of_list (read_seq ()) in
  let _ = read_int () in
  let t = read_seq () in
  Printf.printf "%d\n" (List.fold_left (fun acc e -> acc + (if bin_search e s then 1 else 0)) 0 t)

Measured memory_bytes: 16180
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int 
#define vi vector<int> 
#define vl vector<ll> 
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pair<ll,ll>>
#define umap unordered_map
#define uset unordered_set
#define all(c) c.begin(), c.end()
#define maxarr(A) *max_element(A, A+n) 
#define maxvec(v) *max_element(all(v)) 
#define minarr(A) *min_element(A, A+n);
#define minvec(v) *min_element(all(v));
#define lb(v,elem) lower_bound(all(v),elem)
#define ub(v,elem) upper_bound(all(v),elem)
#define pb push_back 
#define ff first 
#define ss second
#define sz(z) (int)z.size()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rev(i,a,b) for(int i=a; i>=b; i--)
#define debug(v) for(ll i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define debugn(v,n) for(ll i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
#define deb(sum) cout<<"sum = "<<sum<<endl;
#define mod 1000000007
#define INF (ll)1e18
#define endl "\n"
#define pi 3.142857142857143

  
ll binpow(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binpow(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

ll modexpo(ll x, ll y, ll p){  
	ll res = 1;  
	x = x % p; 
	if (x == 0) return 0;
	while (y > 0){   
		if (y & 1)  
			res = (res*x) % p;  
		y = y>>1;
		x = (x*x) % p;  
	}  
	return res;  
}

vector<int> getPrimes(int M){
	
	vi p(M,1);
	vector<int>prime;
	for(int i=2; i*i <= M; ++i){
		if(p[i]){
			for(int j = i*i; j<=M; j+=i) 
				p[j] = 0;
		}
	}
	rep(i,2,M) if(p[i]) prime.push_back(i);
	return prime;
}  


int main() { 
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL); 
  //freopen("1.in","r",stdin);
  
  int t=1;
  //cin>>t;
  while(t--){
  	 int n;
  	 cin>>n;
  	 vi a(n);
  	 rep(i,0,n) cin>>a[i]; 
  	 vi dp(1000006,0);
  	 int mx = maxvec(a);
  	 rep(i,0,n){
  	 	if(dp[a[i]]>0){
  	 		dp[a[i]]++;
  	 		continue;
  	 	}
  	 	for(int j=a[i]; j<=mx; j+=a[i]){
  	 		dp[j]++;
  	 	}
  	 }
  	 int ans=0;
  	 rep(i,0,n) if(dp[a[i]]==1) ans++;
  	 cout<<ans;
  } 
  return 0;
} 


Measured memory_bytes: 7956
A, B = map(int, input().split())

import math

def is_prime(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x % i == 0:
            return False

    return True


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1

    return lower_divisors + upper_divisors[::-1]


def gcd(a, b):

    if a == 0:
        return b
    else:
        return gcd(b%a, a)


da = make_divisors(A)
common_divisors = []

for d in da:
    if B % d == 0:
        common_divisors.append(d)

ans = [1 if is_prime(x) else 0 for x in common_divisors]
print(sum(ans))


Measured memory_bytes: 3416
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;

int n;
vector<int> G[N];
int a[N];
bool flag=true;
int dfs(int x,int p){
    int m=0,sum=0;
    rep(i,G[x].size()){
        if(G[x][i]==p)continue;
        int s=dfs(G[x][i],x);
        sum+=s;
        m=max(m,s);
    }
    if(p==0){
        if(G[1].size()==1){
            cout<<(sum==a[1]?"YES":"NO");
            return 0;
        }
        if(flag==false)cout<<"NO";
        else if(sum %2)cout<<"NO";
        else if(m*2>sum)cout<<"NO";
        else if(sum/2!=a[1])cout<<"NO";
        else cout<<"YES";
    }
    if(G[x].size()==1){
        return a[x];
    }
    if(sum<a[x]){
        flag=false;return 0;
    }
    else if(m>a[x]){
        flag=false;return 0;
    }
    else if(sum>a[x]*2){
        flag=false;return 0;
    }
    return a[x]*2-sum;
}
main(){
    cin>>n;
    rep2(i,1,n)cin>>a[i];
    rep(i,n-1){
        int c,d;cin>>c>>d;
        G[c].pb(d);G[d].pb(c);
    }
    dfs(1,0);
    return 0;
}

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

int main() {
    long T1, T2;
    long A1, A2, B1, B2;
    cin>>T1>>T2;
    cin>>A1>>A2;
    cin>>B1>>B2;
    if((A1-B1)*T1+(A2-B2)*T2==0) cout<<"infinity"<<endl;
    else if(((A1-B1)*T1>0 & (A1-B1)*T1+(A2-B2)*T2>0) | ((A1-B1)*T1<0 & (A1-B1)*T1+(A2-B2)*T2<0))cout<<0<<endl;
    else {
        long a = (A1-B1)*T1+(A2-B2)*T2;
        if(abs(A1-B1)*T1%abs(a)==0) cout<<2*(abs(A1-B1)*T1/abs(a))<<endl;
        else cout<<2*(abs(A1-B1)*T1/abs(a))+1<<endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
double dp[3000+1][3000+1];
double arr[3001];
double greaterhead(int n,int i,int j,int nooftail,int k)
{ if(n==0)
   return 1;
   if( dp[n][nooftail]>-0.9)
    return dp[n][nooftail];
   	double ans=arr[i]*greaterhead(n-1,i-1,j-1,nooftail,k);
	double p=0;
    if(k/2>nooftail)
    p=(1-arr[j])*greaterhead(n-1,i-1,j-1,nooftail+1,k);
     dp[n][nooftail]=(ans+p);
    return  dp[n][nooftail];
}
/*
greaterhead(int n,int *arr,int i,int j)
{  dp[1][1]=arr[1]*(1-arr[2])+(1-arr[1])*arr[2];
for(int i=1;i<=n;i++)
   for(int j=1;j<=n;j++)
{   if(i==1&&j==1)
   continue;
    if(i==1)
     dp[i][j]=(1-arr[j])*dp[i][j-1];
     else if(j==1)
      dp[i][j]=(arr[i])*dp[i-1][j];
      else
       dp[i][j]=arr[j-1]*dp[i]

}
	
}*/
int main()
{ memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	  cin>>arr[i];
	 printf("%0.10lf\n",greaterhead(n,n,n,0,n));

	  
}

Measured memory_bytes: 70912
<?php
list($h,$w) = explode(" ",trim(fgets(STDIN)));
while($h > 0){
    while($h > 0){
        echo str_repeat("#",$w) . PHP_EOL;
        --$h;
    }
    echo PHP_EOL;
    list($h,$w) = explode(" ",trim(fgets(STDIN)));
}

Measured memory_bytes: 15268
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  long long money = 1000;
  long long stock = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] < A[i + 1]) {
      long long tmp = money / A[i];
      stock += tmp;
      money -= tmp * A[i];
    } else if (A[i] > A[i + 1]) {
      money += stock * A[i];
      stock = 0;
    }
  }
  money += stock * A[N - 1];
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 3648
N, K = map(int, input().split())
l = [0 for i in range(100001)]
num_count = 0
n = 0
for j in range(N):
    a, b = map(int, input().split())
    l[a] += b
for k in l:
    num_count += k
    if num_count >= K:
        print(n)
        break
    else:
        n += 1

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector<vector<char>> data1(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> data1.at(i).at(j);
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << data1.at(i).at(j);
		}
		cout << endl;
		for (int j = 0; j < w; j++) {
			cout << data1.at(i).at(j);
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
function main(s) {
	n = s.split("\n")[0];
	k = s.split("\n")[1];
	x = s.split("\n")[2].split(" ");
	z = 0;
	for (var i = 0; i < n; i++) {
		z += Math.min(k-x[i], x[i]) * 2;
	}
	console.log(z);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 9420
N,M,K = map(int,input().split())
MOD = 998244353
if M==1:
    print(1 if K==N-1 else 0)
    exit()

MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

cs = []
ms = [(M * pow(M-1, N-1-K, MOD)) % MOD]
for i in range(K+1):
    cs.append(comb(N-1, i))
    if i:
        ms.append((ms[-1] * (M-1)) % MOD)

ans = 0
for c,m in zip(cs, ms[::-1]):
    ans += c*m
print(ans%MOD)


Measured memory_bytes: 52308
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
int a[4];
int main()
{
    ft
    int t,i,j,n,m,l,r,x,y,c=0;
    for(i=0; i<3; i++)
    {
        cin>>a[i];
    }
    cin>>x>>y;
    m=min(x,y);
    if((2*a[2])<=(a[0]+a[1]))
    {
        c+=2*m*a[2];
        l=abs(x-y);
        if(x>y)
        {
            if(a[0]>(2*a[2]))
            {
                c+=l*2*a[2];
            }
            else
            {
                c+=l*a[0];
            }
        }
        else
        {
            if(a[1]>(2*a[2]))
            {
                c+=l*2*a[2];
            }
            else
            {
                c+=l*a[1];
            }
        }
        cout<<c<<"\n";
    }
    else
    {
        c=(a[0]*x)+(a[1]*y);
        cout<<c<<"\n";
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#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 llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;

    REP(i, N){
        int sum = 0;
        int j = i + 1;
        sum += j % 10;
        j = j/10;
        sum += j % 10;
        j = j/10;
        sum += j % 10;
        j = j/10;
        sum += j % 10;
        j = j/10;
        sum += j % 10;

        if(sum >= A && sum <= B) ans += i + 1;
    }

    cout << ans << endl;

    return 0;
}

/*****************************************************************************/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
int a[100005];
int main()
{
	cin >> n >> m;
	set<int>S;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		S.insert(a[i]);
	}
	int M = 0,ans = 0;
	for(int i=1;i<n;i++){
		S.erase(S.find(a[i]));
		set<int>::iterator it = S.end(); it--;
		if(M < (*it)-a[i]){
			M = (*it)-a[i]; ans = 1;
		}
		else if(M == (*it)-a[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a>=13){
        ans = b;
    } else if (a<=12 && a>=6){
        ans = b/2;
    } else {
        ans = 0;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, k: usize, p: [u1; n], c: [i64; n]);
    let mut points: Vec<i64> = vec![];
    let mut ret = std::i64::MIN;
    for i in 0..n {
        points.clear();
        assert_eq!(points.len(), 0);
        let mut cur = i;
        loop {
            cur = p[cur];
            points.push(*points.last().unwrap_or(&0) + c[cur]);
            if cur == i {
                break;
            }
        }
        let pret = if k <= points.len() {
            *points[..k].iter().max().unwrap()
        } else {
            let s: i64 = *points.last().unwrap();
            if s <= 0 {
                *points.iter().max().unwrap()
            } else {
                let l = k % points.len();
                let a = k / points.len();
                let x = s * ((a - 1) as i64);
                let res = *points.iter().max().unwrap();
                let res = max(res, s + *points[..l].iter().max().unwrap_or(&0));
                x + res
            }
        };
        ret = max(ret, pret);
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2352
a, b = [int(n) for n in input().split()]

count = 0
for i in range(1, 10):
    for j in range(10):
        for k in range(10):
            n = int(''.join(list(map(str, [i, j, k, j, i]))))
            if n >= a:
                if n <= b:
                    #print(n)
                    count += 1
                else:
                    continue
            else:
                continue
print(count)

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

struct point{
	double x;
	double y;
};

int ccw(point p0, point p1, point p2){
	double dx1 = p1.x - p0.x, dy1 = p1.y - p0.y;
	double dx2 = p2.x - p0.x, dy2 = p2.y - p0.y;
	if(dy2 * dx1 > dy1 * dx2) return 1;
	else return -1;
}

int main(){
	point a, b, c, d;
	char ch;
	while(cin >> a.x >> ch >> a.y >> ch >> b.x >> ch >> b.y
		>> ch >> c.x >> ch >> c.y >> ch >> d.x >> ch >> d.y)
	{
		if((ccw(a,c,b) != ccw(a,c,d)) && (ccw(b,d,a) != ccw(b,d,c))){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

bool le(pair<int, int> x, pair<int, int> y) {
  int xx=min(x.first, x.second);
  int yy=min(y.first, y.second);
  return xx<yy;
}

bool re(pair<int, int> x, pair<int, int> y) {
  int xx=max(x.first, x.second);
  int yy=max(y.first, y.second);
  return xx>yy;
}

int main(void) {
  int n;
  pair<int, int> a[100], b[100];
  int ac[100]={0};
  int bc[100]={0};
  cin>>n;
  for(int i=0; i<n; i++) {
    int x, y;
    cin>>x>>y;
    a[i]=make_pair(x, y);
  }
  for(int i=0; i<n; i++) {
    int x, y;
    cin>>x>>y;
    b[i]=make_pair(x, y);
  }
  sort(a, a+n, re);
  sort(b, b+n, le);

  int ans=0;
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      if(ac[i]==1 or bc[j]==1) continue;
      if(a[i].first<b[j].first && a[i].second<b[j].second) {
	ans++;
	ac[i]=1;
	bc[j]=1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int l[n+1];
    l[0]=0;
    int r[n+2];
    r[n+1]=0;
    for(int i=1;i<=n;i++){
        l[i]=__gcd(a[i],l[i-1]);
    }
    for(int i=n;i>=1;i--){
        r[i]=__gcd(a[i],r[i+1]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,__gcd(l[i-1],r[i+1]));
    }
    cout<<ans;
}

Measured memory_bytes: 1408
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    vector <ll> input;
    bool is_even =false;
    cin >> n;
    REP(i, n){
        ll tmp;
        cin >> tmp;
        if(tmp < 0){is_even = !is_even; tmp *=-1;}
        input.push_back(tmp);
    }
    sort(ALL(input));
    ll ans =0;
    if(is_even){
        ans -= input[0];
    }else{
        ans += input[0];
    }
    REP(i, input.size()){
        if(i==0){continue;}
        ans += input[i];
        }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4240
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
vvl G(200005);
vl sum(200005,0);
bool visit[200005];
vl v(200005,0);

void bfs(ll s, ll n){
    queue<ll> q;
    q.push(s);
    sum[s] += v[s];
    while(!q.empty()){
        ll t = q.front(); q.pop();
        for(auto i : G[t]){
            sum[i] = sum[t] + v[i]; 
            q.push(i);
        }
    }
}
 
int main(){
    ll n,q; cin >> n >> q;
    rep(i,n-1){
        ll a,b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
    }
    ll p,x;
    rep(i,q){
        cin >> p >> x;
        p--;
        v[p] += x;
    }
    bfs(0,n);
    rep(i,n) cout << sum[i] << endl;
    //rep(i,q) cout << v[i] << endl;
}

Measured memory_bytes: 16512
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e6+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

LL f[MAXN];

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	cin>>n>>m;
	if(m==1||m+1==n*2)return 0*puts("No");
	for(i=n,j=m;i<2*n;i++,j++)f[i]=j%(2*n-1);
	for(i=1;i<n;i++,j++)f[i]=j%(2*n-1);
	puts("Yes");
	for(i=1;i<2*n;i++)printf("%I64d\n",f[i]?f[i]:n+n-1);
	return 0;
}

Measured memory_bytes: 14464
L,R,d = map(int,input().split())
count = 0
tmp = 0
while(True):
    if tmp < L:
        tmp = tmp + d
    elif L <= tmp and tmp<= R:
        count += 1
        tmp = tmp + d
    else:
        break
if d == 1:
    print(R- L + 1)
else:
    print(count)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};

// aとbの最大公約数
ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}

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

int main(){

	ll N, M;
	string S, T;
	cin >> N >> M;
	cin >> S >> T;

	ll L = N * M / gcd(N, M);
	ll p = lcm(L / N, L / M);

	for (ll i = 0; i < L; i+=p){
		if (S[i / (L / N)] != T[i / (L / M)]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << L << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n, m; CI n >> m;
	vector<pair<int, int>> a;
	REP(i, m) {
		int tm1, tm2; CI tm1 >> tm2; auto b = make_pair(tm1, tm2); a.push_back(b);
	}

	sort(a.begin(), a.end(), [](auto& x, auto& y) {return x.second < y.second; });

	int ans = 0;
	int tmp = 0;
	REP(i, m) {
		if (a[i].first >=tmp) {
			tmp = a[i].second;
			ans++;
		}
	}
	CO ans EN;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

vector< bool > get_prime(int n){
  vector< bool > prime( n + 1, true);
  
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  
  for(int i = 2; i * i <= n; i++){
    if(prime[i]){
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }
  
  return(prime);
}

int main(){
    int n;
    cin >> n;
    int i = 2;
	vector<bool> p = get_prime(55555);
    while(n != 0){
        if(i % 5 == 2 && p[i]){
            cout << i << endl;
            n--;
        }
        i++;
    }
}

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

int main(){
  int n;
  cin >> n;
  
  map<int,int> mp;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    mp[a]++;
    if(a!=1) mp[a-1]++;
    if(a!=100000) mp[a+1]++;    
  }
  int ans = 0;
  for(auto p:mp){
    ans = max(ans,p.second);
  }
  cout << ans << endl;  
}

Measured memory_bytes: 4736
s = input()
n = len(s)
r = (n-1)//2
l = (n+3)//2
for i in range(r):
  if (s[i] != s[r-i-1] or s[l-1+i] != s[n-1-i]):
    print("No")
    exit()
  elif s[i] != s[n-1-i]:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		String text;;
		char x;
		int [] az = new int[26];
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			text=sc.nextLine();
			for(int i =0; i<text.length(); i++) {
				x=text.charAt(i);
				if ('a'<=x && x<='z') {
					az[x-97]++;
				}
				else if ('A'<=x && x<='Z') {
					az[x-65]++;
				}
			}
		}
		for (int i=0; i<26; i++) {
			System.out.println((char)(i+97)+" : "+az[i]);
		}
	}
}



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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  map<int, int> cnt;

  for (int i = 0; i < 3; ++i) {
    int u, v;
    cin >> u >> v;
    cnt[u]++;
    cnt[v]++;
  }

  for (auto e : cnt)
    if (e.second == 3) {
      cout << "NO\n";
      return 0;
    }

  cout << "YES\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n,T; cin >> n >> T;
  vector<int> c(n),t(n);
  rep(i,n){
    cin >> c[i] >> t[i];
  }
  int ans = 1<<29;
  rep(i,n){
    if(t[i] > T) continue;
    ans = min(ans, c[i]);
  }
  if(ans == 1<<29){
    cout << "TLE" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 int *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}

Measured memory_bytes: 4764
NM = [int(_) for _ in input().split()]
N = NM[0]
M = NM[1]

A = [int(_) for _ in input().split()]

def solve(N, M, A):
    
    d = sum(A) / (4 * M)
    
    a = [i for i in A if i>=d ]
    
    if  len(a) >= M:
        return "Yes"
    else:
        return "No"

print(solve(N, M, A))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int INF = 0x3f3f3f3f, MAXN = 3005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
int N, ar[MAXN];
ll dp[MAXN][MAXN][2];
bool done[MAXN][MAXN][2];
ll f (int l, int r, int p){ //1 = maximize, 0 = minimize
	if (done[l][r][p]) return dp[l][r][p];
	done[l][r][p] = 1;
	if (l==r) return dp[l][r][p] = p?ar[l]:-ar[l];
	if (p) return dp[l][r][p] = max (f(l+1, r, 0)+ar[l], f(l, r-1, 0)+ar[r]);
	else return dp[l][r][p] = min (f(l+1, r, 1)-ar[l], f(l, r-1, 1)-ar[r]);
}
int main(){
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d", &N);
	for (int i = 1; i<=N; i++) scanf("%d", &ar[i]);
	printf("%lld\n", f(1, N, 1));
}	

Measured memory_bytes: 158208