akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return (0)
#define rep(i, n) for (int(i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for (int(i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for (auto &(elem) : (_list))
#define view(_list)      \
    foreach (e, _list)   \
    {                    \
        cout << e << sp; \
    }                    \
    cout << next
#define FAST                     \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define INF 1e+9
#define PI acos(-1)
#define TAU PI * 2
#define EPS 0.00000001
const ll MOD = 1000000007;

// 解説
int main()
{
    ll a, b, n;
    cin >> a >> b >> n;

    ll up = n + 1;
    ll low = 0;

    ll ans = 0;
    while (up - low > 1)
    {
        ll mid = (low + up) / 2;
        ll tmp = floor(a * mid / b) - a * floor(mid / b);
        if (tmp >= ans){
            low = mid;
            ans = tmp;
        }else{
            up = mid;
        }
    }

    println(ans);
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N, M; cin >> N >> M;
  vector<vector<pair<int, int>>> g(N);
  rep(i, M) {
    int a, b, c; cin >> a >> b >> c;
    g[a - 1].emplace_back(b - 1, c);
    g[b - 1].emplace_back(a - 1, c);
  }

  set<pair<int, int>> st;
  rep(i, N) {
    vector<int> dist(N, inf);
    dist[i] = i;

    PQ_G<tuple<int, int, int>> pq;
    pq.emplace(0, i, -1);

    while (!pq.empty()) {
      int cost, pos, prev; tie(cost, pos, prev) = pq.top();
      pq.pop();
      if (dist[pos] < cost) { continue; }
      if (prev >= 0) {
        int a = prev, b = pos;
        if (a > b) swap(a, b);
        st.emplace(a, b);
      }
      for (auto e: g[pos]) {
        int to, ecost; tie(to, ecost) = e;
        if (minimize(dist[to], cost + ecost)) {
          pq.emplace(dist[to], to, pos);
        }
      }
    }
  }
  cout << M - (int)st.size() << "\n";
}


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

int main() {
  
  int k;
  
  cin >> k;
  
  if(k<10){
    cout << k << endl;
    return 0;
  }
  
  queue<long long int> num;
  
  for(int i=0; i<9; i++){
    num.push(i+1);
  }
    
  for(int i=0; i<k ; i++){
    
    if(i==k-1){
      cout << num.front() << endl;
      return 0;
    }else{
      
      if(num.front()%10!=0)
        num.push(num.front()*10+num.front()%10-1);
      
    
      num.push(num.front()*10+num.front()%10);
      
      if(num.front()%10!=9)
        num.push(num.front()*10+num.front()%10+1);
      
    
      num.pop();
    }
  }
  
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
public class Main
{
    public static long solve(int[][] level, int[] bucket, int[] cost, int i, int x){
        if(i >= cost.length){
            for(int j = 0; j < bucket.length; j++){
                if(bucket[j] < x){
                    return Long.MAX_VALUE;
                }
            }
            return 0;
        }
        long ans = Long.MAX_VALUE;
        long op1 = solve(level, bucket, cost, i+1, x);
        if(op1 != Long.MAX_VALUE){
            ans = Math.min(ans, op1);
        }
        int[] copy = bucket.clone();
        for(int j = 0; j < bucket.length; j++){
            copy[j] += level[i][j];
        }
        op1 = solve(level, copy, cost, i+1, x);
        if(op1 != Long.MAX_VALUE){
            ans = Math.min(ans, cost[i] + op1);
        }
        return ans;
    }
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().trim().split(" ");
		int n = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		int x = Integer.parseInt(s[2]);
		int[] cost = new int[n];
		int[] bucket = new int[m];
		int[][] level = new int[n][m];
		for(int i = 0; i < n; i++){
		    String[] str = br.readLine().trim().split(" ");
		    cost[i] = Integer.parseInt(str[0]);
		    for(int j = 0; j < m; j++){
		        level[i][j] = Integer.parseInt(str[j+1]);
		    }
		}
		long ans = solve(level, bucket, cost, 0, x);
		if(ans != Long.MAX_VALUE){
		    System.out.println(ans);
		}
		else{
		    System.out.println(-1);
		}
	}
}



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

using namespace std;
using ll = long long;


int main()
{
    ll q;
    cin >> q;
    
    map<ll,ll> compress;
    map<ll,ll> sser;

    vector<tuple<ll,ll,ll>> ask;
    for(ll i = 0; i < q; i++) {
        ll f, a, b;
        cin >> f;
        if(f == 2)ask.push_back({2,-1,-1});
        else {
            cin >> a >> b;
            compress[a] = -1;
            ask.push_back({1,a,b});
        }
    }


    ll cot = 0; //定数項
    priority_queue<ll> front;
    priority_queue<ll,vector<ll>,greater<ll>> back;
    // front.push(-1e9),back.push(1e9);
    ll fsum = 0, bsum = 0;
    //front.top()が中央値

    for(ll i = 0; i < q; i++) {
        ll f, a, b;
        tie(f,a,b) = ask[i];


        //追加クエリ
        if(f == 1) {
            cot += b;
            front.push(a);
            fsum += a;
            
            while(front.size() - back.size() >= 2) {
                back.push(front.top());
                bsum += front.top();
                fsum -= front.top();
                front.pop();
            }
            
           while(front.size() && back.size() && front.top() > back.top()) {
               ll sf = front.top(), sb = back.top();
               front.pop(), back.pop();
               bsum += sf - sb, fsum += sb - sf;
               back.push(sf),front.push(sb);
           }
        }
        else 
        {//求値クエリ
            ll med = front.top();
            // print(med);
            // print(fsum);
            // print(bsum);
            // print(front.size());
            // print(back.size());
            ll ab = med * front.size() - fsum;//先頭
            ab += bsum - med * back.size();
            cout << med << " " << ab + cot << endl;
        }
/*
        auto df = front;
        auto db = back;
        cerr << "front : " << fsum << " : ";
        while(df.size()) {
            cerr << df.top()<<",";
            df.pop();
        }cerr<<endl;
        cerr << "back  : " << bsum << " : ";
        while(db.size()) {
            cerr << db.top()<<",";
            db.pop();
        }cerr<<endl;cerr<<endl;
*/

    }


}

Measured memory_bytes: 15404
#include <stdio.h>

int main(void) {
    int S;
    int h;
    int m;
    int s;

    scanf("%d", &S);
    s = S % 60;
    m = (S / 60) % 60;
    h = (S / 3600) % 24;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array
ll a_n(ll a, ll n); // a^n

int main() {
    char c;
    cin >> c;
    cout << char(c + 1) << endl;
    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}
ll a_n(ll a, ll n) { 
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return ret * a_n(a, n-count) ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-6
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 
int h,n;
int a[maxn];

int main() {
	cin>>h>>n;
	F(i,1,n) cin>>a[i];
	sort(a+1,a+1+n,greater<int>() );
	F(i,1,n){
		h-=a[i];
		if(h<=0) break;
	}
	if(h<=0){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int a,b;
	char c;
	while(1){
		scanf("%d %c %d",&a,&c,&b);
		if(c=='+'){
			printf("%d\n",a+b);
		}else if(c=='-'){
			printf("%d\n",a-b);
		}else if(c=='*'){
			printf("%d\n",a*b);
		}else if(c=='/'){
			printf("%d\n",a/b);
		}else if(c=='?'){
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2712
/**
	If you only do what you can do, 
	You will never be more than you are now!
	----------------------------------------
	We must all suffer from one of two pains: the pain of discipline or the pain of regret. 
	The difference is discipline weighs grams while regret weighs tons.
**/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2e5;
const int INF = 1e9;

int n, m, cnt[N];

int main () {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	fo(i, 1, m, 1) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		++cnt[b];
	}	
	fo(i, 1, n, 1) {
		if(cnt[i] & 1) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	ll a,b,x;
	ll ans;
	cin >> a >> b >> x;
	if(a==0){
		ans = b/x+1;
	}else{
		ans = b/x-(a-1)/x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int a[100001];
int parent[100001];
int col[100001], CN;
Vi v[100001];
int find(int a)
{
	if (parent[a] < 0)return a;
	return parent[a] = find(parent[a]);
}
void merge(int a, int b)
{
	a = find(a), b = find(b);
	if (a != b)
	{
		parent[a] += parent[b];
		parent[b] = a;
	}
}
int main() {
	MEM_1(parent);
	int n, m;
	scanf("%d%d", &n, &m);
	fup(i, 1, n, 1)scanf("%d", a + i);
	while (m--)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		merge(x, y);
	}
	fup(i, 1, n, 1)
		if (parent[i] < 0)col[i] = ++CN;
	fup(i, 1, n, 1)
	{
		if (parent[i] > 0)
			col[i] = col[find(i)];
		v[col[i]].push_back(i);
	}
	int ans = 0;
	fup(i, 1, CN, 1)
	{
		for (int x : v[i])
		{
			int t = a[x];
			int tt = lower_bound(ALL(v[i]), t) - v[i].begin();
			if (tt != (int)v[i].size() && v[i][tt] == t)ans++;
		}
	}
	printf("%d", ans);
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e1 + 5);

int n;
ll x;

ll size[MAX_N];
// ll putty[MAX_N];

map<pair<int, ll>, ll> memo;

ll ans;

ll calc(int l, ll b) {
  auto key = make_pair(l, b);
  if (memo.find(key) != memo.end()) {
    return memo[key];
  }

  if (l == 0) {
    return 1LL;
  }

  ll child = size[l - 1];

  ll ret;

  if (b <= 1) {
    ret = 0LL;
  } else if (1 < b && b <= 1 + child) {
    ret = calc(l - 1, b - 1);
  } else if (b == 1 + child + 1) {
    ret = calc(l - 1, child) + 1;
  } else if (1 + child + 1 < b && b <= 1 + child + 1 + child) {
    ret = calc(l - 1, child) + 1 + calc(l - 1, b - (1 + child + 1));
  } else if (b == 1 + child + 1 + child + 1) {
    ret = calc(l - 1, child) * 2 + 1;
  }

  return memo[key] = ret;
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &x);

  size[0] = 1LL;
  for (int i = 1; i <= n; ++i) {
    size[i] = size[i - 1] * 2 + 3; 
  }
  
  ans = calc(n, x);

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
package main
import (
        "bufio"
        "fmt"
        "os"
        "strings"
        "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func Atoi2(c string) int {
  tmp, _ := strconv.Atoi(c)
  return tmp
}

func main() {
	input := nextLine()
	rec := strings.Split(input, " ")
	var hoge []int

  var o string

	for _, c := range rec{
		hoge = append(hoge, Atoi2(c))
	}

  if hoge[0] > hoge[1]{
    o = ">"
  }else if hoge[0] < hoge[1]{
    o = "<"
  }else{
    o = "=="
  }

	fmt.Printf("a %s b\n",o)
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#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 DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  ll T=-1,A=-1;
  REP(i,n){
    ll t,a;
    cin >> t >> a;
    if(i==0){
      T = t;
      A = a;
      continue;
    }
    ll dt = T/t;
    if(T%t>0) dt++;
    ll da = A/a;
    if(A%a>0) da++;
    ll div = max(dt,da);
    T = div * t;
    A = div * a;
  }
  cout << T + A << endl;
  return 0;
}


Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

S = input()
T = input()
typeS = [0 for _ in range(1+len(S))]
typeT = [0 for _ in range(1+len(T))]
typeS[0] = typeT[0] = 0 
for i in range(len(S)):
    ctr = 2
    if S[i] == 'A':
        ctr = 1
    typeS[i+1] = (typeS[i] + ctr)%3
for i in range(len(T)):
    ctr = 2
    if T[i] == 'A':
        ctr = 1
    typeT[i+1] = (typeT[i] + ctr)%3
Q = int(input())
for _ in range(Q):
    a, b, c, d = inpl()
    if (typeS[b] - typeS[a-1])%3 == (typeT[d] -typeT[c-1])%3:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 55436
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
c=i2()
s="Yes"
b=[c[0]-c[1],c[1]-c[2]]
c=i2()
if not (b[0]==c[0]-c[1] and b[1]==c[1]-c[2]):s="No"
c=i2()
if not (b[0]==c[0]-c[1] and b[1]==c[1]-c[2]):s="No"
print(s)

Measured memory_bytes: 38384
//Name: Tree Construction
//Level: 3
//Category: 木,Tree,動的計画法,DP
//Note:

/**
 * 右か上にしか辺を伸ばせないので、これは二分木になる。
 * 座標の制約から、上に伸ばした辺に対応させる頂点と、右に伸ばした辺に対応させる頂点は、
 * 中間のどこかを境として分割することができる。
 * したがって、これを再帰的に繰り返していけばよい。
 * それぞれの部分木の根は、部分木に含まれる頂点群の(最小のx, 最小のy)である。
 *
 * これはコストが単調(S⊂Tのとき、Sのコスト < Tのコスト)であり、かつMonge性
 * (w(l,r) + w(l',r') ≦ w(l,r') + w(l',r) が l ≦ l' ≦ r ≦ r' について成立する)
 * を満たしているため、Knuth-Yao Speedupが適用できる。
 * (この問題では等号で成立している？)
 *
 * オーダーはO(N^2)。
 */
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int dp[1024][1024];
int yao[1024][1024];
bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<pair<int,int>> nodes(N);
    for(int i = 0; i < N; ++i) {
        cin >> nodes[i].first >> nodes[i].second;
    }
    for(int i = 0; i <= N+1; ++i) {
        for(int j = 0; j <= N+1; ++j) {
            dp[i][j] = 2 * 10000 * 10000;
            yao[i][j] = 0;
        }
    }
    for(int i = 0; i <= N+1; ++i) {
        dp[i][i+1] = 0;
        yao[i][i+1] = i;
    }
    for(int r = 1; r <= N; ++r) {
        for(int l = r-1; l >= 0; --l) {
            const pair<int,int> root(nodes[l].first, nodes[r-1].second);
            for(int m = yao[l][r-1]; m <= yao[l+1][r]; ++m) {
                const int d = nodes[m-1].second - root.second + nodes[m].first - root.first;
                const int cost = dp[l][m] + dp[m][r] + d;
                if(cost <= dp[l][r]) {
                    dp[l][r] = cost;
                    yao[l][r] = m;
                }
            }
        }
    }
    cout << dp[0][N] << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 9388
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static bool Calc(int rows, int cols, List<string> g) {
        int r = 0;
        int c = 0;

        var used = new bool[rows, cols];
        used[0, 0] = true;
        while (true) {
            if (g[r][c] == '#') used[r, c] = true;
            else break;

            if (r == rows-1 && c == cols-1) break;

            if (c < cols-1 && g[r][c+1] == '#') {
                c++;
            }
            else if (r < rows+1 && g[r+1][c] == '#') {
                r++;
            }
            else break;
        }

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (g[i][j] == '#' && !used[i, j]) {
                    return false;
                }
            }
        }
        return true;
    }

    static void Main() {
        var hw = ReadInts();
        int rows = hw[0], cols = hw[1];
        var g = new List<string>();
        for (int i = 0; i < rows; i++) {
            g.Add(Console.ReadLine());
        }

        if (Calc(rows, cols, g)) {
            Console.WriteLine("Possible");
        }
        else {
            Console.WriteLine("Impossible");
        }
    }
}


Measured memory_bytes: 2904
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	a := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	sum := 0
	for _, x := range a {
		sum += x
	}
	if sum > n {
		fmt.Println("-1")
	} else {
		fmt.Println(n - sum)
	}
}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){
            if(c[i]!=c[j]||((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}



int main(){
    while(input())solve();
    return 0;
}

Measured memory_bytes: 17544
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#ifdef LOCAL
    #include "trace.h"
#else
    #define trace(args...)
#endif
 
ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
	ll n; cin>>n;
	ll ans = 0;
	for(ll a = 1; a<=n; a++)
		for(ll b = 1; b<=n/a; b++){
			ll rem = n - a*b;
			ans += (rem>0);
		}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef LOCAL
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3648
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)


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

int main(){
  ll n,x,y,i;
  cin >> n;
  vector<ll> s(n),d(n);
  for(i=0;i<n;i++){
    cin >> x >> y;
    s.at(i)=x+y;
    d.at(i)=x-y;
  }
  sort(s.begin(),s.end());
  sort(d.begin(),d.end());
  
  cout << max(s.at(n-1)-s.at(0),d.at(n-1)-d.at(0)) << endl;
}

Measured memory_bytes: 6368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int n, m, hit, d;
string inp;
bool amida[30][9];
int top[11];

bool hantei()
{
	//debug
	/*
	rep(i, d)
	{
		rep(j, n-1)
		{
			cout << amida[i][j] ? "1" : "0";
		}
		cout << endl;
	}
	*/

	for (int i=1; i<=n; i++) top[i] = i;
	rep(i, d) rep(j, n-1)
	{
		if (amida[i][j])
		{
			int tmp = top[j+1];
			top[j+1] = top[j+2];
			top[j+2] = tmp;
		}
	}
	//for (int i=1; i<=n; i++) cout << top[i] << " ";
	if (top[hit] == m)
	{
		//cout << "true" << endl;
		return true;
	} else {
		//cout << "false" << endl;
		return false;
	}
}

int main()
{
	while (cin >> n, n)
	{
		cin >> m >> hit >> d;
		rep(i, d)
		{
			cin >> inp;
			rep(j, inp.length())
			{
				amida[i][j] = inp[j] == '1' ? true : false;
			}
		}

		bool tukeru = false;

		if (hantei())
		{
			cout << 0 << endl;
			continue;
		} else {
			//amida[][]を修正しながら全探索
			rep(i, d)
			{
				bool exit1 = false;
				rep(j, n - 1)
				{
					bool exit2 = false;
					int nx[] = {-1, 1};
					bool flag = true;	//その位置に横棒を追加できるか
					if (!amida[i][j])
					{
						rep(k, 2)
						{
							if (0 <= j + nx[k] && j + nx[k] < n - 1 && amida[i][j + nx[k]]) flag = false;
						}
						if (flag)
						{
							//printf("i = %d, j = %d\n", i, j);
							amida[i][j] = true;	
							if (hantei())
							{
								cout << i + 1 << " " << j + 1 << endl;
								exit1 = exit2 = true;
								tukeru = true;
							}
							amida[i][j] = false;
						}
					}
					if (exit2) break;
				}
				if (exit1) break;
			}
		}
		if (!tukeru) cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std; 
int odd_even(int s){
  if(s%2==0){
      s/=2;
    }else{
      s=3*s+1;
    }
  return s;
}
int main() {
  int s;
  cin >> s;
  int i=1,j,count=0,ans=1;
  vector<int> vec(1000001);
  vec.at(0)=s;
  while(count<1){
    vec.at(i)=odd_even(s);
    s=odd_even(s);
     i++;
    for(j=0;j<i-1;j++){
      if(vec.at(i-1)==vec.at(j)){
        count++;
      }
         }
         }
  out:     
  cout << i;
}


Measured memory_bytes: 4096
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
tmp=1000
for i in range(1,10):
    for j in range(3,5):
        num=int(str(i)*j)
        if num-N >= 0 and tmp > num-N:
            tmp = num-N
            ans=num
print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int d = a*4+b*2+c;
    if (d == 1 || d == 6) {
        cout << "Open" << endl;
    } else {
        cout << "Close" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>

int main(){
	int i,j;
	int n;
	char suit;
	int num;
	int card[4][14];

	for(i=0;i<14;i++){
		card[0][i]=0;
		card[1][i]=0;
		card[2][i]=0;
		card[3][i]=0;
	}
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf(" %c %d",&suit,&num);
		if(suit=='S') card[0][num]=num;
		if(suit=='H') card[1][num]=num;
		if(suit=='C') card[2][num]=num;
		if(suit=='D') card[3][num]=num;
	}
	for(i=0;i<4;i++){
		for(j=1;j<=13;j++){
			if(card[i][j]!=j){
				if(i==0) printf("S %d\n",j);
				if(i==1) printf("H %d\n",j);
				if(i==2) printf("C %d\n",j);
				if(i==3) printf("D %d\n",j);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#define N 10000
#define Q 500

int main(){
  int n, q, i, j, count = 0, S[N], T[Q];

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

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

  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(T[i] == S[j]){
	count++;
	break;
      }
    }
  }

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

  return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long[] a = new long[n], b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nl()*2;
            b[i] = in.nl()*2;
        }
        Arrays.sort(a);
        Arrays.sort(b);
        long l, r;
        if(n%2==0){
            l = (a[n/2-1]+a[n/2])/2;
            r = (b[n/2-1]+b[n/2])/2;

        }else{
            l = a[n/2]/2;
            r = b[n/2]/2;
        }
        out.println(r-l+1);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 60044
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a; string s; cin >> a >> s;
  if(a >= 3200)  cout << s<<endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main() {
	char t[1000005];
	size_t len;
	int b = 0;
	scanf("%s",&t);
	len = strlen(t);
	b = len;
	for (int i = 0; i < b; i++) {
		if (t[i] == '?') t[i] = 'D';
	}
	printf("%s", t);
	return 0;
}

Measured memory_bytes: 1932
#include<stdio.h>

int main()
{
	int a,b,c,keep;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		keep = a;
		a = b;
		b = keep;
	}
	if(a>c){
		keep = a;
		a = c;
		c = keep;
	}
	if(b>c){
		keep = b;
		b = c;
		c = keep;
	}
	
	printf("%d %d %d\n",a,b,c);
	return 0;
}
	
		


Measured memory_bytes: 2032
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		if(N % 2 == 0)N--;
		int res;
		if(N <= 1)res = 0;
		else res = N / 2;
		out.println(res);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 21972
from bisect import bisect_left
 
N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()
 
sum = 0

for i in range(N):
    for j in range(i + 1, N):
        sum += bisect_left(Lmat, Lmat[i]+Lmat[j]) - (j + 1)
        
print(sum)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int gcm(int, int,int);
int main() {
	int n,m;


	cin >> n>>m;
	vector<int>a(m);
	int sum=0;
	for(int i=0;i<m;i++){
		cin >> a[i];
		sum+=a[i];
	}
	if (sum > n){
		cout << -1 << endl;

	}
	else{
		cout << n-sum << endl;
	}
	return 0;
}


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

void solve() 
{
	int x,y;cin>>x>>y;
	cout<<abs(abs(x)-abs(y))+((x<0&&y<0)||(x>=0&&y>=0)?(x>=y)*2:1)+(y?0:-1)<<endl;
}

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

Measured memory_bytes: 3600
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

ll dp[3010][3010][2];

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

  ll n,t;
  std::cin>>n>>t;

  std::vector<ll> a(n),b(n);
  rep(i,0,n)std::cin>>a[i]>>b[i];

  rep(i,0,3010)rep(j,0,3010)rep(k,0,2)dp[i][j][k]=-MOD;
  dp[0][0][0]=0;

  rep(i,0,n){
    rep(j,0,t+1){
      dp[i+1][j][0]=dp[i][j][0];
      if(j>=a[i])chmax(dp[i+1][j][0],dp[i][j-a[i]][0]+b[i]);
    }

    rep(j,0,t+1){
      dp[i+1][j][1]=dp[i][j][1];
      if(j>=a[i])chmax(dp[i+1][j][1],dp[i][j-a[i]][1]+b[i]);
      if(j>=1)chmax(dp[i+1][j][1],dp[i][j-1][0]+b[i]);
    }
  }

  ll ans=0;
  rep(i,0,t+1){
    chmax(ans,std::max(dp[n][i][0],dp[n][i][1]));
  }

  std::cout<<ans;

  return 0;
}


Measured memory_bytes: 141824
#include<atcoder/all>
#include<bits/stdc++.h>
using namespace std;
using namespace atcoder;
const int MOD = 998244353;
void plusle(int &a, int b) {
    a += b;
    while (a >= MOD) a -= MOD;
}
void minun(int &a, int b) {
    a -= b;
    while (a < 0) a += MOD;
}
int add(int a, int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    return a;
}
int sub(int a, int b) {
    a -= b;
    while (a < 0) a += MOD;
    return a;
}
int mul(int a, int b) {
    return int64_t(a) * b % MOD;
}
int power(int a, int64_t b) {
    int res = 1;
    for (; b > 0 ; b >>= 1, a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res;
}

const int MX = 2e5 + 10;
int fac[MX], invf[MX] ;
void prefact() {
    fac[0] = 1 ;
    for (int i = 1 ; i < MX ; i ++) {
        fac[i] = mul(fac[i - 1], i);
    }
    invf[MX - 1] = power (fac[MX - 1], MOD - 2);
    for (int i = MX - 2 ; i >= 0 ; i --) {
        invf[i] = mul(invf[i + 1], i + 1);
    }
}
int ncr(int N, int R) {
    if (R > N) return 0;
    if (R == 0 || R == N) return 1;
    return mul(fac[N], mul(invf[N - R], invf[R]));
}
const int nax = 2e5 + 10;


int h[nax];
int n;
int cnt[nax];

multiset < pair <int, vector <int>>> setik;

int main() {
    prefact();
    scanf("%d", &n);
    for (int i = 1 ; i <= 2 * n ; ++ i) {
        scanf("%d", h + i);
        cnt[h[i]] += 1;
    }

    for (int i = 1 ; i <= 100000 ; ++ i) {
        if (cnt[i] <= 1) continue;
        vector <int> foo(cnt[i] / 2 + 1);

        int cur = cnt[i];
        int f = 1;

        for (int j = 0 ; j < foo.size() ; ++ j) {
            foo[j] = mul(f, invf[j]);
            f = mul(f, ncr(cur, 2));
            cur -= 2;
        }

        setik.emplace(foo.size(), foo);
    }

    while (setik.size() >= 2) {
        vector <int> p1 = setik.begin()->second;
        setik.erase(setik.begin());
        vector <int> p2 = setik.begin()->second;
        setik.erase(setik.begin());
        p1 = convolution(p1, p2);
        setik.emplace(p1.size(), p1);
    }

    vector <int> c = setik.empty() ? vector<int>(1, 1) : setik.begin()->second;

    if (c.size() <= n) c.resize(n + 2);


    const int INV2 = (MOD + 1) / 2;

    int ans = 0;

    for (int bar = 0 ; bar < c.size() ; ++ bar) {
        int v = c[bar];
        v = mul(v, fac[2 * (n - bar)]);
        v = mul(v, invf[n - bar]);
        v = mul(v, power(INV2, n - bar));
        if (bar % 2 == 0) {
            plusle(ans, v);
        } else minun(ans, v);
    }

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

    /**
    f(i) the number of ways to get
    i equal pairs from first v group
    */



}


Measured memory_bytes: 8848
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long m = long.Parse(input[1]);
    List<long> divisorList = new List<long>();

    for(long answer = (long)Math.Sqrt(m)+1; answer > 0; answer--)
    {
      if(m % answer == 0)
      {
        divisorList.Add(answer);
        divisorList.Add(m/answer);
      }
    }
    divisorList.Sort((a, b) => a.CompareTo(b));

    for(int i = divisorList.Count()-1; i >= 0; i--)
    {
      if(divisorList[i] * n <= m)
      {
        Console.WriteLine(divisorList[i]);
        break;
      }
    }
    
	}
}

Measured memory_bytes: 13652
package main

import (
        "fmt"
        "sort"
)

type Entry struct {
        sid int
        num int
}

type List []Entry

func (l List) Len() int {
        return len(l)
}

func (l List) Swap(i, j int) {
        l[i], l[j] = l[j], l[i]
}
func (l List) Less(i, j int) bool {
        if l[i].sid == l[j].sid {
                return (l[i].num < l[j].num)
        } else {
                return (l[i].num < l[j].num)
        }
}

func main() {
        N := 0
        fmt.Scan(&N)
        l := List{}
        for i := 0; i < N; i++ {
                A := 0
                fmt.Scan(&A)
                l = append(l, Entry{i + 1, A})
        }

        sort.Sort(l)
        for i := 0; i < N; i++ {
                fmt.Printf("%d ", l[i].sid)
        }

}

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

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

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

    int count = 0;

    for (int i =0; i < N; i++) {
        if ((i + 1) != p.at(i)) {
            count++;
        }
    }

    if (count == 0 || count == 2) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

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

int main(){
    string s;int q;cin>>s>>q;
    int t[q],f[q];
    char c[q];
    deque<char> d;
    rep(i,s.size()){
        d.push_back(s[i]);
    }
    rep(i,q){
        cin>>t[i];
        if(t[i]==2){
            cin>>f[i]>>c[i];
        }
    }
    bool a=true;
    rep(i,q){
        if(t[i]==1){
            if(a)a=false;
            else a=true;
        }
        else{
            if(f[i]==1){
                if(a){
                    d.push_front(c[i]);
                }
                else{
                    d.push_back(c[i]);
                }
            }
            if(f[i]==2){
                if(!a){
                    d.push_front(c[i]);
                }
                else{
                    d.push_back(c[i]);
                }
            }
        }
    }
    if(!a) reverse(all(d));
    rep(i,d.size())cout<<d[i];
}


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


bool is_prime(long long n){
	bool ans=true;
	for (int i=2; i<=sqrt(n); i++){
		if (n%i==0) ans=false;
	}
	
	return ans;
	
}


int main(){
	long long a,b;
	cin>>a>>b;
	
	vector<long long> divisores;
	
	long long k=__gcd(a,b);
	
	for (int i=1; i<=sqrt(k); i++){
		if (k%i==0){
			divisores.push_back(k/i);
			if (i!=k/i) divisores.push_back(i);
		}
	}
	
	int res=0;
	
	for (int i=0; i<divisores.size(); i++){
		if (is_prime(divisores[i])) res++;
	}

	
	cout<<res<<endl;

}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int s,n,m;
int a[300000];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> a[i];
    int mx=-1;
    int nm=0;
    for (int i=1;i<n;i++)
    if (a[i]+a[i+1]>mx) {
        mx=a[i]+a[i+1];
        nm=i;
    }
    if (mx<m) cout << "Impossible\n";
    else {
        cout << "Possible\n";
        for (int i=1;i<nm;i++) cout << i << "\n";
        for (int i=n-1;i>=nm+1;i--) cout << i << "\n";
        cout << nm << "\n";
    }
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int s[M];
    int c[M];
    rep(i, M) cin >> s[i] >> c[i];

    int num[N];
    rep(i, N) num[i] = -1;

    rep(i, M){
        if ( (num[s[i] - 1] == -1) || (num[s[i] - 1] == c[i]) ){
            num[s[i] - 1] = c[i];
            if ( (c[i] == 0) && (s[i] == 1) && (N != 1) ){
            cout << -1 << endl;
            return 0;
            }
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    rep(i, N){
        if (num[i] == -1){
            if ((i == 0) && (N != 1)){
                num[i] = 1;
            }else{
                num[i] = 0;
            }
        }
    }
    
    rep(i, N) cout << num[i];
    cout << endl;
    return 0;
}

 

Measured memory_bytes: 256
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
ans = 0
for i in range(n-2):
    if a[i] <= a[i+1] <= a[i+2] or a[i+2] <= a[i+1] <= a[i]:
        ans += 1
print(ans)


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

int X, A, B;
bool judge = false;

int main() {
cin >> X;
  A = X/100;
  B = X%100;
  for(int i; i < A; i++){
  if (B <= 5*A){
  judge = true;
  }
  }
  if(judge == true) cout << "1" << endl;
  else cout << "0" << endl;
  }

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i=0;i<n;i++) {
			p[i]= sc.nextInt();
		}
		int ans = 0;
		for(int i=1;i<n-1;i++) {
			if((p[i-1]-p[i])*(p[i]-p[i+1])>0){
				ans ++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <climits>

using namespace std;


int main(){

        long n,max=LONG_MIN,min=LONG_MAX,sum=0,a;

        scanf("%ld",&n);

        for(int i=0;i<n;i++){
                scanf("%ld ",&a);
                if(max<a)
                        max=a;
                if(min>=a)
                        min=a;
                sum+=a;
        }
        printf("%ld %ld %ld\n",min,max,sum);

        return 0;
}


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

int n,k,a[10];
string s,t;

int main() {
  cin >> s;
  if(s.size()==3) reverse(all(s));
  cout << s << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    sort(all(a));
    cout<<a[n/2]-a[n/2-1]<<endl;
    
}

Measured memory_bytes: 1024