akhauriyash/Code-Regression huggingface dataset:
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 

int a[maxs];
int tree[4*maxs];

void build(int node,int s,int e)
{
    if(s==e)
    {
        tree[node]=a[s];
    }
    else
    {
        int mid=(s+e)/2;
        build(node*2,s,mid);
        build(node*2+1,mid+1,e);
        tree[node]=tree[node*2]+tree[node*2+1];
    }
}
void update(int node,int s,int e,int idx,int val)
{
    if(s==e)
    {
        a[idx]=val;
        tree[node]=val;
    }
    else
    {
       int mid=(s+e)/2;
        if(idx>=s&&idx<=mid)
        update(node*2,s,mid,idx,val);
        else
        update(node*2+1,mid+1,e,idx,val);
         tree[node]=tree[node*2]+tree[node*2+1];
    }
}
int query(int node,int s,int e,int l,int r)
{
    if(l>e||s>r)
    return 100005;
    if(l<=s&&r>=e)
    return tree[node];
    else
    {
        int mid=(s+e)/2;
        int p1=query(2*node,s,mid,l,r);
        int p2=query(2*node+1,mid+1,e,l,r);
        return p1+p2;
    }
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   ll x,y; cin>>x>>y;
       int flag =0;
       for (int i = 0; i <= x; i++)
       {
          if(2*i+4*(x-i)==y){
            flag++;
       }
       }
         if(flag==0){cout<<"No";}
         else{cout<<"Yes";}
         return 0;  
}




Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
#define int long long
const int maxn = 1020;
int n, x[maxn], y[maxn], odd, even;
namespace sol{
    int a[59], k, ham;
    const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
    const char dr[] = "DULR";
    void dfs(int x, int y, int cur) {
        if(cur == 0) return;
        int chg = 1LL << (cur - 1);
        for(int dir = 0; dir < 4; ++dir) {
            int xf = x + dx[dir] * chg, yf = y + dy[dir] * chg;
            if(abs(xf) + abs(yf) < (1LL << (cur - 1)) ) {
                putchar(dr[dir]);
                dfs(xf, yf, cur - 1);
                break;
            }
        }
    }
    inline void solve() {
        rep(i, n) ham = max(ham, x[i] + y[i]) + 2;
        for(k = 0; (1LL << k) < ham; ++k) ;
        if(even) printf("%lld\n1 ", ++k + 1);
        else printf("%lld\n", ++k);
        for(int i = k; i ; --i) {
            a[i] = 1LL << (i - 1);
            printf("%lld%c", a[i], i == 1LL ? '\n' : ' ');
        }
        for(int i = 1; i <= n; ++i){
            if(even) putchar('L'), x[i]++;
            dfs(x[i], y[i], k);
            putchar('\n');
        }
    }
}
signed main(){
    scanf("%lld", &n);
    odd = even = true;
    rep(i, n) scanf("%lld%lld", &x[i], &y[i]);
    rep(i, n) {
        int sum = abs(x[i]) + abs(y[i]);
        if(sum & 1) even = false; else odd = false;
    }
    if((odd | even) == 0) {puts("-1"); return 0;}
    sol::solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  string s;
  cin>>s;
  if((s.size()%2==0)^(s[0]==s[s.size()-1])) cout<<"Second"<<endl;
  else cout<<"First"<<endl;

  return 0;
}


Measured memory_bytes: 512
N, M = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
dp = [1]*N

M.times do
  a, b = gets.split.map(&:to_i)
  if H[a-1] > H[b-1]
    dp[b-1] = 0
  elsif H[a-1] == H[b-1]
    dp[a-1] = 0
    dp[b-1] = 0
  else
    dp[a-1] = 0
  end
end

p dp.select{|v| v == 1}.size


Measured memory_bytes: 22640
#include<stdio.h>

int main() {
    int i;
    int n;
    int prices[] = {6000, 4000, 3000, 2000};

    for (i=0; i<4; i++) {
        int ind;
        unsigned long long int  times;

        scanf("%d %llu", &ind, &times);
        printf("%llu\n", prices[ind-1] * times);
    }
}

Measured memory_bytes: 1036
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
#define int long long int
#define double long double
using namespace std;
#define INT_MAX 1000000005
#define INF 1000000005
const int MAX_N = 1 << 17;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

signed main()
{
int d,g;
std::cin >> d >> g;
std::vector<std::vector<int>> pc;
for(int i = 0; i < d; i++){
    int tempp,tempc;
    std::cin >> tempp >> tempc;
    std::vector<int> temp;
    temp.push_back(tempp);
    temp.push_back(tempc);
    pc.push_back(temp);
}
int sum = INF;
std::vector<int> checker(d,0);
for(int i = 0; i < d; i++){
    checker[i] = 100 * (i + 1) * pc[i][0] + pc[i][1];
}
int goal = 1 << d;
int flag = 0;
while(flag < goal){
    int temp = 0;
    int temps = 0;
    int last = 0;
    for(int i = 0; i < d; i++){
        if(flag & (1 << i)){
            temps += pc[i][0];
            temp += checker[i];
        } else {
            last = i;
        }
    }
    int ad = ((g - temp)+ (100 * (last + 1) - 1)) / (100 * (last + 1));
    if(temp >= g && sum > temps){
        sum = temps;
    } else if(temp < g && ad < pc[last][0] && sum > temps + ad){
        sum = temps + ad;
    }
    flag++;
}
std::cout << sum << std::endl;

return 0;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n;
    cin >> n;
    vll a(n);
    cin >> a;
    sort(all(a));
    double inv = 0;
    RREP(i,n) inv += 1/(double)a[i];
    cout << 1/inv << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

class Edge{
public:
	int from,to,cost;
	Edge(int f,int t,int c){
		from = f;
		to = t;
		cost = c;
	}
	void swap(){
		int a = from;
		from = to;
		to = a;
	}
};

vector<Edge> edge;

int n,m;
const int INF = 999999999;


int solve(int s){
	int* d = new int[n + 1];
	for(int i=0;i<=n;i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	while(1){
		bool f = true;
		vector<Edge>::iterator it;
		for(it = edge.begin();it<edge.end();it++){
			if(d[it->from] != INF){
				if(d[it->to] > d[it->from] + it->cost){
					d[it->to] = d[it->from] + it->cost;
					f = false;
				} 
			}
		}
		if(f){
			break;
		}
	}
	int ans = 0;
	for(int i=2;i<=n;i++){
		if(d[i] <= 2){
			ans += 1;
		}
	}
	delete[] d;
	return ans;
}

int main(){
	int a,b;
	while(scanf("%d %d",&n,&m) && (n || m)){
		edge.clear();
		for(int i=0;i<m;i++){
			scanf("%d %d",&a,&b);
			edge.push_back( Edge(a,b,1) );
			edge.push_back( Edge(b,a,1) );
		}
		printf("%d\n",solve(1));
	}
}

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

int main(){
	int n;
	scanf("%d", &n);
	int len[n];
	for(int i=0; i<n; i++){
		scanf("%d", &len[i]);
	}
	
	int swap;
	for(int i=n-1; i>0; i--){
		for(int j=0; j<i; j++){
			if(len[j]<len[j+1]){
				swap = len[j+1];
				len[j+1] = len[j];
				len[j] = swap;
			}
		}
	}
	
	
	int count=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				if(len[i]< len[j]+len[k]){
					count++;
				}
				else k=n;
			}
		}
	}
	
	
	
	/*
	for(int i=0; i<n; i++){
		printf("%d ", len[i]);
	}
	*/
	
	printf("%d\n", count);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
	int x,y,z;
	cin >> x >> y >> z;
	int mi = min(x, min(y, z));
	int ma = max(x, max(y, z));
	cout << mi << " " << x + y + z - mi - ma << " " << ma << endl;
	return 0;
}

Measured memory_bytes: 1168
import scala.collection.mutable.PriorityQueue
import scala.collection.mutable.Set
import scala.util.Sorting

object Main {
  val pq = PriorityQueue[(Long, (Int, Int, Int))]()(scala.math.Ordering.by(v => v._1))
  val lines = scala.io.Source.stdin.getLines.toStream
  val Array(num_x, num_y, num_z, num_k) = lines(0).split(" ").map(_.toLong)
  val xs = lines(1).split(" ").map(_.toLong)
  val ys = lines(2).split(" ").map(_.toLong)
  val zs = lines(3).split(" ").map(_.toLong)
  Sorting.quickSort[Long](xs)(Ordering[Long].reverse)
  Sorting.quickSort[Long](ys)(Ordering[Long].reverse)
  Sorting.quickSort[Long](zs)(Ordering[Long].reverse)
  val checked = Set[(Int, Int, Int)]()

  def main(args: Array[String]) = {
    pq.enqueue((xs(0) + ys(0) + zs(0)) -> (0, 0, 0))
    bfs(num_k)
  }

  def bfs(max: Long = 3000, count: Long = 1): Unit = {
    val (value, (lx, ly, lz))  = pq.dequeue
    println(value)
    if (xs.length > lx+1 && !checked.contains((lx + 1, ly, lz))) {
      checked += ((lx+1, ly, lz))
      pq.enqueue((value - xs(lx) + xs(lx + 1)) -> (lx + 1, ly, lz))
    }
    if (ys.length > ly+1 && !checked.contains((lx, ly+1, lz))) {
      checked += ((lx, ly+1, lz))
      pq.enqueue((value - ys(ly) + ys(ly+1)) -> (lx, ly+1, lz))
    }
    if (zs.length > lz+1 && !checked.contains((lx, ly, lz+1))) {
      checked += ((lx, ly, lz+1))
      pq.enqueue((value - zs(lz) + zs(lz+1)) -> (lx, ly, lz+1))
    }
    if (count < max && (zs.length > lz+1 || ys.length > ly+1 || xs.length > lx+1)) {
      bfs(max, count + 1)
    }
  }
}


Measured memory_bytes: 41576
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, MA, MB;
    cin >> N >> MA >> MB;
    vector<vector<ll> >dp(500, vector<ll>(500, 114514));
    dp[0][0] = 0;
    for(ll i = 0; i < N; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        for(ll ta = 444; ta >= 0; ta--){
            for(ll tb = 444; tb >= 0; tb--){
                ll fa = ta - a;
                ll fb = tb - b;
                if(fa < 0 || fb < 0)continue;
                dp[ta][tb] = min(dp[ta][tb], dp[fa][fb] + c);
            }
        }
    }
    ll ans = 114514;
    for(ll a = MA, b = MB;;a += MA, b+= MB){
        if(a > 444 || b > 444)break;
        ans = min(ans, dp[a][b]);
    }
    if(ans == 114514)cout << "-1" << endl;
    else cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<math.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	string s;
	cin >> s;
	s [ 3 ] = '8';
	cout << s << endl; 
	return 0;	
}

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

int main() {
    int A, B, ans;

    cin >> A >> B;

    if (A >= 13) {
        ans = B;
    } else if (A >= 6) {
        ans = B / 2;
    } else {
        ans = 0;
    }

    cout << ans << endl;
}

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

int main() {
  int a,c=0;
  cin>>a;
  vector<char> b(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  for(int i=0;i<a-1;i++){
    if(b.at(i)==b.at(i+1)){
      c++;
    }
  }
  cout<<a-c<<endl;
}

Measured memory_bytes: 3672
#! python3
# maximum_profit.py

n = int(input())
R = [int(input()) for i in range(n)]

min_i = 0
max_val = R[1]-R[0]
max_j = -1
for i in range(n-1):
    if R[min_i] < R[i]:
        continue
    elif R[min_i] > R[i]:
        min_i = i

    if max_j <= i:
        max_j = i+1
        for j in range(i+1, n):
            if R[max_j] < R[j]:
                max_j = j

    if max_val < R[max_j] - R[min_i]:
        max_val = R[max_j] - R[min_i]

print(max_val)


Measured memory_bytes: 13620
#include <stdio.h> 
 
int main(){ 
  int a, b, r, tmp; 

  scanf("%d", &a);  
  scanf("%d", &b); 

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

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

  printf("%d\n", b); 

  return 0;
 
} 

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

int main()
{
    int x, y;
    for (;;)
    {
        cin >> x >> y;
        if (x == 0 && y == 0)
            break;
        else if (x <= y)
            cout << x << " " << y << endl;
        else if (x > y)
            cout << y << " " << x << endl;
    }

    return 0;
}



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

using namespace std;

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> data(n);
	for (int i = 0; i < n; i++) {
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	for (int i = 0; i < n; i++) {
		cout << data[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = list(map(int,input().split(" ")))

if N[0] > N[1]:
  if N[0] > 9:
    print(-1)
  else:
    print(N[0]*N[1])
else:
  if N[1] > 9:
    print(-1)
  else:
    print(N[0]*N[1])


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

typedef vector<ll> vec;
typedef vector<vec> mat;
/*
 行列累乗
 X = A^M*B
 A ( N*N行列)
 
 O(N^3 logM)
 */
mat mul(mat&A,mat&B,const ll M){
    mat C(A.size(),vec(B[0].size()));
    for(int i = 0; i < (int)A.size();i++){
        for(int k = 0; k < (int)B.size();k++){
            if(A[i][k] == 0) continue;
            for(int j = 0; j < B[0].size();j++){
                C[i][j] = (C[i][j] + A[i][k]*B[k][j])%M;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n,const ll M){
    mat B(A.size(),vec(A.size()));
    for(int i = 0; i < A.size();i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n&1) B= mul(B,A,M);
        A = mul(A,A,M);
        n>>=1;
    }
    return B;
}

ll N,M,A,B,C,T;
mat S;
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N >> M >> A >> B >> C >> T,N){
        S = mat(N,vec(1));
        for(int i = 0; i < N;i++) cin >> S[i][0];
        
        mat D(N,vec(N));
        for(int i = 0; i < N;i++){
            if(i-1>=0) D[i][i-1] = A;
            D[i][i] = B;
            if(i+1<=N-1) D[i][i+1] = C;
        }
        
        mat DT = pow(D,T,M);
        
        mat R = mul(DT,S,M);
        for(int i = 0; i < N;i++){
            cout << R[i][0];
            if(i!=N-1) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3204
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		try (Scanner cin = new Scanner(System.in)) {

			int N = cin.nextInt();
			int[] d = new int[N];

			for (int i = 0; i < N; i++) {
				d[i] = cin.nextInt();
			}

			int M = cin.nextInt();
			int[] t = new int[M];

			for (int i = 0; i < M; i++) {
				t[i] = cin.nextInt();
			}

			Arrays.sort(d);
			Arrays.sort(t);

			int index = 0;

			for (int ti : t) {
				int tmp = -1;
				for (int i = index; i < N; i++) {
					if (d[i] == ti) {
						tmp = i;
						break;
					}
				}
				if (tmp == -1) {
					System.out.println("NO");
					return;
				}
				index = tmp + 1;
			}
			System.out.println("YES");
		} finally {
		}
	}

}

Measured memory_bytes: 107012
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  int sx,sy,tx,ty;cin >>sx>>sy>>tx>>ty;
  string s="";
  for(int i=0;i<ty-sy;++i) s+="U";
  for(int i=0;i<tx-sx;++i) s+="R";
  for(int i=0;i<ty-sy;++i) s+="D";
  for(int i=0;i<tx-sx+1;++i) s+="L";
  //s+="L";
  for(int i=0;i<ty-sy+1;++i) s+="U";
  for(int i=0;i<tx-sx+1;++i) s+="R";
  s+="DR";
  for(int i=0;i<ty-sy+1;++i) s+="D";
  for(int i=0;i<tx-sx+1;++i) s+="L";
  s+="U";
  cout << s << endl;
  return 0;
}

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

vector<bool>digit(10);

bool ok(int num){
	int x=num;
	while(x>0){
	int y=x%10;
		if(!digit[y])return false;
		x=x/10;
	}
	return true;
}

int main(){
	int n,k;cin>>n>>k;
	int x;
	digit.assign(10,true);
	for(int i=0;i<k;i++){
		cin>>x;digit[x]=false;
	}
		int z=n;	
	while(true){

		if(ok(z)){
          cout<<z<<endl;
          return 0;
        }
		z++;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pqq priority_queue
#define itt ::iterator
void setIO(string y)
{
    if(y=="")
        return ;
#ifndef ybw
    freopen((y+".in").c_str(),"r",stdin);
    freopen((y+".out").c_str(),"w",stdout);
#endif
}
int n,a,b;
int main()
{
    setIO("");
	cin>>n>>a>>b;
	if(abs(a-b)&1)puts("Borys");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int d[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, 0, n) d[i] = INF;
    vector<int> a(m), b(m);
    rep(i, 0, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        chmin(d[a[i]], b[i]);
    }
    int ans = 0;
    int limit = INF;
    rep(i, 0, n - 1){
        chmin(limit, d[i]);
        if(limit == i + 1){
            limit = INF;
        }else{
            ans++;
        }
    }
    cout << n - 1 - ans << endl;
}

Measured memory_bytes: 2560
n=int(input())
a=list(map(int,input().split()))
data=[0]*9
for i in a:
  if 1<=i<=399:
    data[0]+=1
  elif 400<=i<=799:
    data[1]+=1
  elif 800<=i<=1199:
    data[2]+=1
  elif 1200<=i<=1599:
    data[3]+=1
  elif 1600<=i<=1999:
    data[4]+=1
  elif 2000<=i<=2399:
    data[5]+=1
  elif 2400<=i<=2799:
    data[6]+=1
  elif 2800<=i<=3199:
    data[7]+=1
  elif 3200<=i:
    data[8]+=1
min=0
for i in range(8):
  if data[i]!=0:
    min+=1
if min!=0:
  print(min,min+data[8])
else:
  print(1,data[8])

Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <string>
using namespace std;

int main(){
  int n, k;
  string s;
  cin >> n;
  cin >> s;
  cin >> k;
  for(int i=0; i<n; i++){
    if(s[i] != s[k-1]) s[i] = '*';
  }
  cout << s << endl;
  return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var ST = Console.ReadLine().Split();
            var AB = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var U = Console.ReadLine();
            if (ST[0] == U) AB[0]--;
            else AB[1]--;
            Console.WriteLine($"{AB[0]} {AB[1]}");
        }
    }
}

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

using namespace std;

#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<string> vs;

typedef vector<vector<int>> vvi;
typedef vector<vector<ld>> vvd;
typedef vector<vector<ll>> vvl;

typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<ld>>> vvvd;
typedef vector<vector<vector<ll>>> vvvl;

constexpr int MOD = 1000000007;
constexpr char nl = '\n';

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

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

  for (int i = 0; 1; i++) {
    if (i % 2 == 0) {
      C -= B;
    } else {
      A -= D;
    }
    if (A <= 0 || C <= 0) {
      break;
    }
  }
  cerr << A << "!" << C << nl;
  if (A <= 0) {
    cout << "No" << nl;
  } else {
    cout << "Yes" << nl;
  }
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
using namespace std;
enum{I,P,Q,R,C};
int main()
{
  int n;
  int limit[5];
  while(cin>>n,n){
    vector< vector<int> >food(n,vector<int>(5,0));
    for(int i=0;i<n;i++){
      for(int j=0;j<4;j++)cin>>food[i][j];
      food[i][C] = 4*food[i][P] + 9*food[i][Q] + 4*food[i][R];
    }

    for(int j=1;j<=4;j++)cin>>limit[j];

    int count=0;
    for(int i=0;i<n;i++){
      bool ok=true;
      for(int j=1;j<=4;j++)if(food[i][j]>limit[j])ok=false;
      if(!ok)continue;
      cout<<food[i][I]<<endl;
      count++;
    }
    if(!count)puts("NA");
  }
}

Measured memory_bytes: 944
n = gets.to_i;
s = gets.chomp.to_s;

i = 0
count = 0

while i < n
   if s[i] == 'A' && s[i + 1] == 'B' && s[i+2] == 'C'
      count += 1;
      i += 2
   end

   i += 1
end

puts count; 


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 200010;
int N,M;
bool x[MC] , y[MC];

bool judge(){
	repp(i,2,N){
		if(x[i] && y[i]) return 1;
	}
	return 0;
}

int main(){
	scanf("%d%d" , &N , &M);
	repp(i,0,M){
		int a,b;
		scanf("%d%d" , &a , &b);
		if(a>b) swap(a,b);
		if(a==1) x[b] = 1;
		if(b==N) y[a] = 1;
	}
	printf("%s\n" , judge() ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
long long gcd(long long a, long long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {

    int n, m, l;
    cn n;


   int a[n+1];
   int b[n+1];
   int c[n+1];

    _ninp(n,a);
    _ninp(n,b);
    _ninp(n-1,c);
int res=0;

for (int i = 0; i < n; ++i)
{
     res+=b[a[i]-1];
     if(i){
        if(a[i-1]+1==a[i])res+=c[a[i]-2];
     }
     

}

ct res,nl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cassert>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#define el endl
int main(){
	int a,b,c;
	scanf("%d",&a);
	printf("%.6lf",(double)a*3.141592*2);
}

Measured memory_bytes: 3816
#整数の入力
N = int(input())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))
#スペース区切りの整数の入力リスト
B_list = list(map(int, input().split()))

count = 0
for i in range(N):
  # もしBよりAの方が大きい場合
  # A[i]しか倒せない
  if(A_list[i] >= B_list[i]):
    count = count + B_list[i]
    #print("1 : ",B_list[i])
    
  # A[i+1]も倒せるけど
  # A[i+1]に残る場合
  elif((B_list[i] - A_list[i]) < A_list[i+1]):
    count = count + A_list[i] + (B_list[i] - A_list[i])
    A_list[i+1] = A_list[i+1] - (B_list[i] - A_list[i])
    #print("2 : ",(B_list[i] - A_list[i])+A_list[i])
    
  # A[i+1]も全部倒せる場合
  else:
    count = count + A_list[i+1]+A_list[i]
    #print("3 : ",A_list[i+1]+A_list[i])
    A_list[i+1] = 0
    
  
    
print(count)



Measured memory_bytes: 18624
/*
***************************************************************************
 name  : ITP1_02_D.cpp
 title : Circle in a Rectangle
 make  : 2018/08/01 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

// Prototype
void Judge(int a,int b,bool *j); // Judgement whether it is inside

main(void){
  int w,h;     // rectangle
  int x,y,r;   // circle
  bool judge=0; // parameters to determine

  std::cin >> w >> h >> x >> y >> r; // input "w h x y r"

  Judge(x+r,w,&judge); // judgment on the right
  Judge(x-r,0,&judge); // judgment on the left
  Judge(y+r,h,&judge); // judgment on the top
  Judge(y-r,0,&judge); // judgment on the bottom

  if(judge){
    std::cout << "No" << std::endl; // output "No"
  }
  else{
    std::cout << "Yes" << std::endl; // output "Yes"
  }

}

// +-----------------------------------------+
// | name       : Judge                      |
// | obtain     : int a,int b,bool *j        |
// | return     : none                       |
// | processing : Judge whether it is inside |
// +-----------------------------------------+
void Judge(int a,int b,bool *j){

  if(b == 0){
    if(a < b){
      (*j)++; // increment *j
    }
  }
  else{
    if(a > b){
      (*j)++; // increment *j
    }
  }

}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  const int s = accumulate(a.begin(), a.end(), 0);
  vector<int> dp(s + 1);
  vector<int> dp2(s + 1);
  dp[0] = 1;
  dp2[0] = 1;
  constexpr int kMod = 998244353;
  for (int i = 0; i < n; ++i) {
    vector<int> nxt(s + 1, 0);
    vector<int> nxt2(s + 1, 0);
    for (int j = 0; j <= s; ++j) {
      nxt[j] = (dp[j] + dp[j]) % kMod;
      nxt2[j] = dp2[j];
      if (j >= a[i]) {
        (nxt[j] += dp[j - a[i]]) >= kMod ? nxt[j] -= kMod : 0;
        (nxt2[j] += dp2[j - a[i]]) >= kMod ? nxt2[j] -= kMod : 0;
      }
    }
    dp = nxt;
    dp2 = nxt2;
  }
  int res = 1;
  for (int i = 0; i < n; ++i) res = 3LL * res % kMod;
  for (int i = 0; i <= s; ++i) {
    if (s - i <= i) {
      (res += kMod - 3LL * dp[i] % kMod) >= kMod ? res -= kMod : 0;
    }
  }
  if (s % 2 == 0) {
    res += 3LL * dp2[s / 2] % kMod;
    res %= kMod;
  }
  cout << res << "\n";
}


Measured memory_bytes: 1704
while True:
   m, f, r = map(int, input().split())
   if m == -1 and f == -1 and r == -1:
      break
   S = m + f
   if m == -1 or f == -1:
      print("F")
   elif S >= 80:
      print("A")
   elif S >= 65 and S < 80:
      print("B")
   elif S >= 50 and S < 65:
      print("C")
   elif S >= 30 and S < 50:
      if r >= 50:
         print("C")
      else:
         print("D")
   else:
      print("F")


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

int main()
{
	int n,m,i;
	scanf("%d",&n);
	for(i=1;i<=9;i++)
	{
		m=i*100+i*10+i;
		if(m>=n) {printf("%d",m);break;}
	}
}


Measured memory_bytes: 256
string = list(input())
n = int(input())

for repeat in range(n):
    ope = input().split()

    if ope[0] == "replace":
        rep_str = list(ope[3])
        rep_ind = 0
        #print(rep_str)
        for i in range(int(ope[1]), int(ope[2])+1):
            #print(string[i],rep_str[rep_ind])
            string[i] = rep_str[rep_ind]
            rep_ind += 1
        #print(string)
        
    elif ope[0] == "reverse":
        rev_str = []
        rev_ind = int(ope[2])
        times = 0
        for i in range(len(string)):
            rev_str.append(string[i])
        for i in range(int(ope[1]),int(ope[2])+1):
            string[i] = rev_str[rev_ind]
            rev_ind -= 1
        
    elif ope[0] == "print":
        for i in range(int(ope[1]),int(ope[2])+1):
            print(string[i],end="")
        print("")



Measured memory_bytes: 5760
n = int(input())
l = list(map(int, input().split()))
check = True
for i in range(n):
    if l[i] % 2 == 1:
        next
    else:
        if l[i] % 3 == 0 or l[i] % 5 == 0:
            next
        else:
            check = False
if check:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)


using namespace std;

struct SizeAwareUnionFind
{
    vector<int> par, cou;
    SizeAwareUnionFind(int N) : par(N), cou(N) { rep(i, N) {par[i] = i, cou[i] = 1;} }
    int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); }
    void unite(int x, int y) {
        x = find(x), y = find(y); if (x == y) return;
        if (cou[x] < cou[y]) swap(x, y); 
        par[y] = x, cou[x] += cou[y];
    }
    int count(int x) { return cou[find(x)]; }
    bool same(int x, int y) { return find(x) == find(y); }
};
 
int main() {

	int n, m;

	cin >> n >> m;
	SizeAwareUnionFind uf(n + 1);


	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		 uf.unite(x, y);
	}


	set<int> s;
	for(int i = 1; i <= n; i++) {

		s.insert( uf.find(i));
	}
	cout << s.size() << endl;
	return 0;

}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
int main() {
    int n; std::cin >> n;
    std::vector<int> dp(1+n, (int)1e9+7), h(1+n);
    for (int i = 1; i <= n; ++i) { std::cin >> h[i]; }
    dp[1] = 0;
    for (int i = 2; i <= n; ++i) {
        dp[i] = std::min(dp[i-2] + std::abs(h[i]-h[i-2]), dp[i-1] + std::abs(h[i] - h[i-1]));
    }
    std::cout << dp[n] << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){int n,i,ans=0,k,a;
      map<int,int>mp;
      cin>>n;
               int c[n+1];
      for(i=1;i<=n;i++){
          cin>>c[i];
          //k=i-c;
          //ans+=mp[k];
          a=i+c[i];
          mp[a]++;
      }
               for(i=1;i<=n;i++){
         
          k=i-c[i];
          ans+=mp[k];
          //a=i+c;
          //mp[a]++;
      }
               cout<<ans;
    return 0;}

Measured memory_bytes: 27948
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	int a,b;
	cin>>a>>b;
	if(a*b%2)
		cout<<"Odd"<<endl;
	else
		cout<<"Even"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    string str;
    cin >> str;
    for(int i=0; i<str.length(); ++i){
        if(str[i] == '1') str[i] = '9';
        else str[i] = '1';
    }
    cout << str << endl;
    return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N=1e5+10, mod=998244353;
ll n,m,v,p,a[N];

bool can(ll x){
	int temp=v;
	ll b[n],tt=0;
	for(int i=0;i<n;i++)b[i]=a[i];
	
	for(int i=x;i<n && temp ;i++,temp--) b[i]+=m;
	for(int i=0;i<min(x,p-1) &&temp;i++,temp--) b[i]+=m;

	for(int i=x-1;i>=p-1;i--){
		if( b[i]>b[x] )return 0;
		tt+=b[x]-b[i];
	}
	
	return tt>=m*1ll*temp;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	cin>>n>>m>>v>>p;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n,greater<int>());
	int res=p,l=p+1,r=n;
	
	while(l<=r){
		int m=(l+r)/2;
		if(can(m-1)){
			l=m+1; res=m;
		}else r=m-1;
	}
	cout<<res<<"\n";
	
    yogeshk972();
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
vector<int> eratosu(1000010,1);

int solve(int A, int D, int N){
    int cnt = 0;
    int i = 0;
    while(1){
        if(eratosu[A+D*i] == 1)cnt++;
        if(cnt == N)break;
        i++;
    }
    return A+D*i;
}

int main(){
    eratosu[0] = 0;
    eratosu[1] = 0;
    for(int i =0;i < eratosu.size();i++){
        if(eratosu[i] == 1){
            for(int j = 2; i * j < eratosu.size(); j++){
                eratosu[i*j] = 0;
            }
        }
    }
    // for(int i = 0; i < 20;i++)cout<<eratosu[i] << " ";
    int A,D,N;
    vector<int>ans;
    while(cin>>A>>D>>N){
        if(!A && !D && !N)break;
        ans.push_back(solve(A,D,N));
    }
    for(int a:ans)cout<<a<<endl;
}


Measured memory_bytes: 6604
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  vector<int> x(5);
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i = 0; i < 5; i++){
    if (x[i] == 0){
      cout << i + 1 << '\n';
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 3620
// abc160_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]){
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))

if 0 in lis:
    ans = 0
    for i in lis:
        if i < 0:
            ans += -1 * i
        else:
            ans += i
    print(ans)
    exit()

minus = [0]*n
for i in range(n):
    if lis[i] < 0:
        minus[i] = 1

if sum(minus) % 2 == 0:
    ans = 0
    for i in lis:
        if i < 0:
            ans += -1 * i
        else:
            ans += i
    print(ans)
else:
    ans = 0
    m = 10**9+1
    for i in lis:
        if i < 0:
            ans += -1*i
        else:
            ans += i
        m = min(m, abs(i))
    print(ans - 2*m)


Measured memory_bytes: 20124
#include <stdio.h>
int main(void)
{
    int n;
    scanf("%d",&n);
    int a,b,c,d;
    d=n%10;
    c=((n-d)/10)%10;
    b=(n/100)%10;
    a=(n/1000);
    //printf("%d%d%d%d",a,b,c,d);
    if(a+b+c+d==7)printf("%d+%d+%d+%d=7",a,b,c,d);
    else if(a-b+c+d==7)printf("%d-%d+%d+%d=7",a,b,c,d);
    else if(a+b-c+d==7)printf("%d+%d-%d+%d=7",a,b,c,d);
    else if(a+b+c-d==7)printf("%d+%d+%d-%d=7",a,b,c,d);
    else if(a-b-c+d==7)printf("%d-%d-%d+%d=7",a,b,c,d);
    else if(a+b-c-d==7)printf("%d+%d-%d-%d=7",a,b,c,d);
    else if(a-b+c-d==7)printf("%d-%d+%d-%d=7",a,b,c,d);
    else if(a-b-c-d==7)printf("%d-%d-%d-%d=7",a,b,c,d);
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,s,t;
vpll G[200100];
ll dist[200100];


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m>>s>>t; s--,t--;
  rep(i,m){
    ll u,v,a,b; cin>>u>>v>>a>>b; u--,v--;
    G[u].emplace_back(v,a);
    G[v].emplace_back(u,a);
    ll nu=u+n, nv=v+n;
    G[nu].emplace_back(nv,b);
    G[nv].emplace_back(nu,b);
  }
  
  fill(dist,dist+2*n+5,LINF);
  dist[s]=dist[t+n]=0;
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,s);
  q.emplace(0,t+n);
  while(!q.empty()){
    auto p=q.top(); q.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        q.emplace(dist[nv],nv);
      }
    }
  }
  
  ll base=1e15;
  ll prev=0;
  vll ans(n);
  rrep(i,n){
    chmax(prev,base-(dist[i]+dist[n+i]));
    ans[i]=prev;
  }
  
  rep(i,n){
    cout<<ans[i]<<endl;
  }
  
}

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

int main() {

    int a, b;
    scanf("%d%d", &a, &b);
    if(a == b) printf("0");
    else if(!((a+b)%2)) printf("%d", (a+b)/2);
    else printf("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
char S[4];

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

void solve(){
  bool first_year = false;
  bool second_year = false;
  bool first_month = false;
  bool second_month = false;
  if(10*ctoi(S[0])+ctoi(S[1])>=1&&10*ctoi(S[0])+ctoi(S[1])<=12) first_month = true;
  if(10*ctoi(S[2])+ctoi(S[3])>=0&&10*ctoi(S[2])+ctoi(S[3])<=99) second_year = true; 
  if(10*ctoi(S[0])+ctoi(S[1])>=0&&10*ctoi(S[0])+ctoi(S[1])<=99) first_year = true;
  if(10*ctoi(S[2])+ctoi(S[3])>=1&&10*ctoi(S[2])+ctoi(S[3])<=12) second_month = true;

  if(first_year&&second_month){
    if(first_month&&second_year) cout << "AMBIGUOUS" << endl;
    else cout <<"YYMM"<<endl;
  }else if(first_month&&second_year) cout <<"MMYY" << endl;
  else cout << "NA" << endl;
    
}

int main(){
  cin >> S;
  solve();
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
struct SegmentTree {

    T id;
    function<T(T, T)> op;
    vector<T> dat;
    int size;

    SegmentTree(int n, T id, function <T(T, T)> op) : id(id), op(op) {
        size = 1;
        while (size < n) size <<= 1;
        dat.assign(size * 2 + 10, id);
    }

    void update(int k, T x) {
        k += size, dat[k] = x;
        while (k > 1) k >>= 1, dat[k] = op(dat[k << 1], dat[(k << 1) | 1]);
    }

    void merge(int k, T x) { update(k, op(x, dat[k + size])); }
    //[a, b)
    T query(int a, int b) {
        T tl = id, tr = id;
        for (int l = a + size, r = b + size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) tl = op(tl, dat[l++]);
            if (r & 1) tr = op(tr, dat[--r]);
        }
        return (op(tl, tr));
    }
};

int main() {
    ll N, Q, A, B;
    ll X[200005];
    cin >> N >> Q >> A >> B;
    SegmentTree<ll> segl(N + 3, LLINF, [](ll a, ll b) { return (min(a, b)); });
    SegmentTree<ll> segr(N + 3, LLINF, [](ll a, ll b) { return (min(a, b)); });

    ll sum = 0;

    X[0] = A;
    segl.update(B, -B);
    segr.update(B, B);
    for (int i = 1; i <= Q; i++) {
        cin >> X[i];
        ll diff = llabs(X[i] - X[i - 1]);
        sum += diff;
        ll val = min(segl.query(1, X[i] + 1) + X[i], segr.query(X[i] + 1, N + 1) - X[i]);
        segl.update(X[i - 1], val - X[i - 1] - diff);
        segr.update(X[i - 1], val + X[i - 1] - diff);
    }
    ll minv = 0;
    for (int i = 1; i <= N; i++) {
        minv = min(minv, segl.query(i, i + 1) + i);
    }
    cout << minv + sum << endl;

    return (0);
}

Measured memory_bytes: 9984
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>


using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))

const ll MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  ll n,k;
  cin>>n>>k;
  ll ret=0;
  for(int i=k+1;i<=n;i++){
    ret += max(0,((n+1)%i)-k);
    ret += (i-k)*((n+1)/i);
    if(k==0) ret-=1;
  }
  cout<<ret<<"\n";
}


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

int T;
int n;
int ti[101];
int d[101];
int dp[101][31];
int finD;

const int INF=1000000000;
int dfs(int pos,int tm){
	if(pos==finD+1)return 0;
	if(dp[pos][tm]!=-1)return dp[pos][tm];
	int res=INF;
	// JtFCðùÞ
	res=min(res,dfs(pos+1,1%T)+1);
	// ÔÉ¤êÍAùÜÈ¢Æ¢¤Iðà è
	if(d[pos]==-1||d[pos]>=ti[tm])res=min(res,dfs(pos+1,(tm+1)%T));
	return dp[pos][tm]=res;
}

int main(){
	while(cin>>T&&T){
		for(int i=0;i<T;i++)cin>>ti[i];
		cin>>n;
		memset(dp,-1,sizeof(dp));
		memset(d,-1,sizeof(d));
		finD=0;
		for(int i=0;i<n;i++){
			int da,m;
			cin>>da>>m;
			finD=max(finD,da);
			if(d[da]==-1)d[da]=m;
			else d[da]=min(d[da],m);
		}
		for(int i=0;i<31;i++)dp[finD+1][i]=0;
		for(int i=finD;i>=0;i--){
			for(int j=0;j<T;j++){
				dp[i][j]=INF;
				dp[i][j]=min(dp[i][j],dp[i+1][1%T]+1);
				if(d[i]==-1||d[i]>=ti[j])dp[i][j]=min(dp[i][j],dp[i+1][(j+1)%T]);
			}
		}
		int res=dp[1][0];
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=2100;
struct edge{int to,nxt;}e[N<<1];
int head[N],tot=1;
void adde(int x,int y){e[tot]=(edge){y,head[x]};head[x]=tot++;}
int fo[N],to[N],dep[N];
void dfs(int u,int f)
{
    for(int i=head[u];i;i=e[i].nxt)
    {
        int v=e[i].to;if(v==f)continue;
        dep[v]=dep[u]+1;dfs(v,u);
    }
}
int main()
{
    int n,k;scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&fo[i],&to[i]);
        adde(fo[i],to[i]),adde(to[i],fo[i]);
    }
    if(k%2==0)
    {
        int ans=1e9;
        for(int i=1;i<=n;i++)
        {
            int sum=0;dep[i]=0;dfs(i,i);
            for(int j=1;j<=n;j++)sum+=(dep[j]>k/2);
            ans=min(ans,sum);
        }
        printf("%d\n",ans);
    }
    else
    {
        int ans=1e9;
        for(int i=1;i<n;i++)
        {
            int x=fo[i],y=to[i],sum=0;
            for(int j=1;j<=n;j++)dep[j]=-1;
            dep[x]=0;dfs(x,y);
            for(int j=1;j<=n;j++)sum+=(dep[j]>k/2);
            for(int j=1;j<=n;j++)dep[j]=-1;
            dep[y]=0;dfs(y,x);
            for(int j=1;j<=n;j++)sum+=(dep[j]>k/2);
            ans=min(ans,sum);
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 384