akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
using namespace std;
typedef long long LL;
int main()
{
	LL N,X,M;
	LL S=0;
	cin>>N>>X>>M;
	LL i;
	LL A=X;
	S+=A;
	set<LL> mySet;
	set<LL>::iterator sit;
	mySet.insert(A);
	bool bClear=false;
	LL firstA=0;
	for (i=2;i<=N;i++){
		A=(A*A)%M;
		sit=mySet.find(A);
		if (sit==mySet.end()){
			mySet.insert(A);
		}else{
			if (!bClear){
				mySet.clear();
				mySet.insert(A);
				firstA=A;
				bClear=true;
			}else{
				break;
			}
		}
		if (A==0){
			cout<<S<<endl;
			return 0;
		}	
		S+=A;
	}
	LL mySetNums=mySet.size();
	if (i<N && mySetNums>0){
		LL remain=N-i;
		LL nums=remain/mySetNums;
		i=N-remain%mySetNums;
		LL S1=0;
		for (sit=mySet.begin();sit!=mySet.end();sit++){
			S1+=(*sit);
		}
		S+=S1*nums;
		A=firstA;
		S+=A;
		i++;
	}
	for (;i<=N;i++){
		A=(A*A)%M;
		S+=A;
	}
	cout<<S<<endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; print(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	map<int, int> mp;
	vector<int> v;
	rep(i, 0, n) { int t; read(t); mp[t]++; }
	if (mp.size() == 1 && mp.begin()->first == 0) die("Yes");
	if (n % 3 != 0) die("No");
	for (auto p : mp) rep(i, 0, p.second / (n / 3)) v.push_back(p.first);
	if (v.size() != 3) die("No");

	if ((v[0] ^ v[1]) == v[2] && (v[0] ^ v[2]) == v[1] && (v[1] ^ v[2]) == v[0]) die("Yes");
	else die("No");
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a <= c && c <= b && b <= d) {
    cout << (b - c) << endl;
  } else if (c <= a && a <= d && d <= b) {
    cout << (d - a) << endl;
  } else if (a <= c && d <= b) {
    cout << (d - c) << endl;
  } else if (c <= a && b <= d) {
    cout << (b - a) << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

int memo[100]={2,1};

int f(int n){
    if(memo[n]!=0)return memo[n];
    return memo[n] = f(n-1)+f(n-2);
}

signed main(){
    int n;
    cin>>n;
    cout<<f(n)<<endl;
}


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

// macros
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INT_IN(a) int a; cin >> a
#define STR_IN(s) string s; cin >> s
#define PRINTLN(s) cout << s << endl
#define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl;

// util functions
template<class T> inline T sqr(T x) {return x*x;}

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T>inline T max(vector<T> v){T max=v[0]; FOR(i, 1, v.size())max=MAX(v[i], max); return max;}
template <typename T>inline T min(vector<T> v){T min=v[0]; FOR(i, 1, v.size())min=MIN(v[i], min); return min;}
template <typename T>inline vector<T> concat(vector<T> a, vector<T> b){vector<T> ab; ab.reserve(a.size()+b.size());ab.insert(ab.end(),a.begin(),a.end());ab.insert(ab.end(),b.begin(),b.end());return ab;}

// types
typedef long long LL;

// consts
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

int main(){
    int H, W;
    while(cin >> H >> W){
        if(!H and !W) break;
        if(!H or !W) continue;
        int ih = H - 2;
        int iw = W - 2;
        REP(i, W) cout << "#";
        cout << endl;
        REP(i, ih){
            cout << "#";
            REP(j, iw){
                cout << ".";
            }
            cout << "#" << endl;
        }
        REP(i, W) cout << "#";
        cout << endl << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>

using namespace std;

int main(){
    int a;
    int b;
    string op;
    while(1){
        cin >> a >> op >> b;
        if(op == "?") break;
        if(op == "+"){
            cout << a + b << endl;
        }
        if(op == "-"){
            cout << a - b << endl;
        }
        if(op == "*"){
            cout << a * b << endl;
        }
        if(op == "/"){
            cout << a / b << endl;
        }
    }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> p(n);
  rep(i, n) cin >> p[i].second >> p[i].first;

  sort(p.begin(), p.end(), greater<pair<ll, ll>>());
  ll ans = 0, res = 0, cnt = 0;
  map<ll, ll> m;
  rep(i, k) {
    res += p[i].first;
    if (m[p[i].second]++ == 0) {
      res += 2 * cnt + 1;
      cnt++;
    }
  }
  ans = res;
  ll left = k - 1, right = k;
  while (1) {
    while (right < n && m[p[right].second] != 0) right++;
    if (right == n) break;
    m[p[right].second]++;
    res += p[right++].first + 2 * cnt + 1;
    cnt++;
    while (left >= 0 && m[p[left].second] == 1) left--;
    if (left == -1) break;
    m[p[left].second]--;
    res -= p[left--].first;
    ans = max(ans, res);
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 5760
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N = II()
    A = LMIIS()
    A.sort()
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    
main()

Measured memory_bytes: 84280
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//最大公約数
int gcd(int n, int m) {
	if (m == 0)return n;
	return gcd(m, n%m);
}

int main() {
	int n, k; cin >> n >> k;
	VI a(n); rep(i, n)cin >> a[i];

	int g = a[0];
	FOR(i, 1, n)g = gcd(g, a[i]);
	int m = *max_element(all(a));

	puts((k%g == 0 && m >= k) ? "POSSIBLE" : "IMPOSSIBLE");
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n = in.nextInt();

            int[] a = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                a[i] = in.nextInt();
            }

            int ans = 0;
            for (int i = 1; i + 1 <= n; ++i) {
                if (a[i] == i) {
                    int tmp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = tmp;
                    ans++;
                }
            }

            if (a[n] == n)
                ans++;

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 35800
def combination_init_mod(n, mod):
    fact = [1] * (n + 1)
    inv_fact = [0] * (n + 1)

    for i in range(1, n + 1):
        fact[i] = fact[i - 1] * i
        fact[i] %= mod

    inv_fact[n] = 1 * pow(fact[n], mod - 2, mod)

    for i in range(n - 1, -1, -1):
        inv_fact[i] = inv_fact[i + 1] * (i + 1)
        inv_fact[i] %= mod

    return fact, inv_fact


def combination_mod(n, r, fact, inv_fact, mod):
    ans = 1
    ans *= fact[n]
    ans %= mod
    ans *= inv_fact[r]
    ans %= mod
    ans *= inv_fact[n - r]
    ans %= mod

    return ans


n, k = map(int, input().split())
mod = 10**9 + 7

fact, inv_fact = combination_init_mod(3000, mod)

for i in range(1, k + 1):
    if i == 1:
        print(n - k + 1)
    elif i - 1 <= n - k:
        ans = combination_mod(n - k + 1, i, fact, inv_fact, mod)
        ans %= mod
        ans *= combination_mod(k - 1, i - 1, fact, inv_fact, mod)
        ans %= mod
        print(ans)
    else:
        print(0)


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



int main(){
    int N,M,X,res=10000000;
    cin>>N>>M>>X;
    vector<int> C(N);
    vector<vector<int> > A(N,vector<int>(M));
    for(int i=0;i<N;i++){
        cin>>C.at(i);
        for(int j=0;j<M;j++){
            cin>>A.at(i).at(j);
        }
    }
    for(int tmp=0;tmp<(1<<N);tmp++){
        int mon=0;
        vector<int> sum(M,0);
        bitset<12> B=tmp;
        for(int i=0;i<N;i++){
            if(B.test(i)){
                for(int j=0;j<M;j++){
                    sum.at(j)+=A.at(i).at(j);
                }
                mon+=C.at(i);
            }
        }
        bool suc=true;
        for(int j=0;j<M;j++){
            if(sum.at(j)<X){
                suc=false;
            }
        }
        if(suc){
            res=min(res,mon);
        }
    }
    if(res==10000000){
        cout<<-1<<endl;
    }
    else{
        cout<<res<<endl;
    }
    
}

Measured memory_bytes: 3636
fun main() {
  val N = readInt()
  val LN = readInts().sorted()
  var cnt = 0
  for (i in 0 until N) {
    for (j in i + 1 until N) {
      for (k in j + 1 until N) {
        val a = LN[i]
        val b = LN[j]
        val c = LN[k]
        if (a == b || b == c || c == a) continue
        if (a + b > c && b + c > a && c + a > b) cnt++
      }
    }
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 40740
N,M=map(int,input().split())
H=list(map(int,input().split()))
G=[[] for _ in range(N)]

for i in range(M):
    A,B=map(int,input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)

cnt=0
for i in range(N):
    f=True
    for g in G[i]:
        if H[i]<=H[g]:
            f=False
            break
    if f:
        cnt+=1

print(cnt)

Measured memory_bytes: 29348
A, B, C = map(int, input().split())
i = 0
sum = 0
cnt = 0
while True:
    sum  += A
    i += 1
    cnt += 1
    if sum >= C:
        break
    if i%6 == 0:
        sum += A+B
        i = 0
        cnt += 1
        if sum >= C:
            break
print(cnt)


Measured memory_bytes: 5596
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, M;
  int ans = 0;
  cin >> N >> M;
  vector<vector<int> > v(N);
  vector<bool> seen(N, true);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    v[A].pb(B);
    v[B].pb(A);
  }

  rep(i, N) {
    if (seen[i]) {
      int p = i;
      int cnt = 0;
      queue<int> que;
      que.push(p);
      seen[p] = false;
      while (!que.empty()) {
        p = que.front();
        // cout << p << ' ' << cnt << endl;
        cnt++;
        que.pop();
        for (int i = 0; i < v[p].size(); i++) {
          int t = v[p][i];
          if (seen[t] == true) {
            que.push(t);
            seen[t] = false;
          }
        }
      }
      ans = max(cnt, ans);
      // cout << endl;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 14940
#include <cstdio>

int main()
{
  double t5, t10;
  while (~scanf("%lf %lf", &t5, &t10)) {
    if (t5 < 35.50 && t10 < 71.00)
      puts("AAA");
    else if (t5 < 37.50 && t10 < 77.00)
      puts("AA");
    else if (t5 < 40.00 && t10 < 83.00)
      puts("A");
    else if (t5 < 43.00 && t10 < 89.00)
      puts("B");
    else if (t5 < 50.00 && t10 < 105.00)
      puts("C");
    else if (t5 < 55.00 && t10 < 116.00)
      puts("D");
    else if (t5 < 70.00 && t10 < 148.00)
      puts("E");
    else
      puts("NA");
  }
  return 0;
}

Measured memory_bytes: 0
using System;

namespace ABC169D
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            int x = 0;
            long d = 2;
            long z = 0;
            while(d*d<=n)
            {
                if (n % d != 0)
                    d++;
                
                    z = d;
                    while(n%z ==0)
                    {
                        x += 1;
                        n /= z;
                        z *= d;

                    }
                    while (n % d == 0)
                        n /= d;
                    d++;
                

            }

            if (n != 1)
                x++;
            Console.WriteLine(x);


        }
    }
}


Measured memory_bytes: 17520
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int p = sc.nextInt();

		int c = a * 3;
		int pie = (c + p) / 2;

		System.out.println(pie);



	}

}


Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)

typedef long long i64;

const i64 MOD = 1e9 + 7;
template <i64 MOD> struct ModInt {
  i64 value;

  ModInt(i64 v = 0) { value = v % MOD; }

  operator i64() { return value; }
  ModInt<MOD> operator+(int v) { return (value + v) % MOD; }
  ModInt<MOD> operator+(i64 v) { return (value + v) % MOD; }

  ModInt<MOD> operator-(i64 v) {
    v %= MOD;
    return (MOD + value - v) % MOD;
  }

  ModInt<MOD> operator*(i64 v) { return (value * v) % MOD; }
};

// Eucli
i64 inv_mod(i64 a, i64 m = MOD) {
  i64 b, x, u, q, abs_m, tmp;

  abs_m = (m < 0) ? -m : m;
  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? abs_m + x : x;
}

i64 fact[404040];
i64 inv_fact[404040];
using mint = ModInt<MOD>;

mint nCr(int n, int r) {
  return (fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD) % MOD;
}

//重複組み合わせ
i64 nHr(int n, int r) { return (nCr(n + r - 1, r)) % MOD; }


int main(){
	fact[0] = 1;
	for(int i = 1;i < 404040;i++){
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	inv_fact[404040 - 1] = inv_mod(fact[404040 - 1]);
	for(int i = 404040 - 2;i >= 0;i--){
		inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD;
	}


	mint result = 0;

	int n,m,k;
	cin >> n >> m >> k;
	for(int i = 0;i <= k;i++){
		int j = k - i;
		mint l = 1,r = 1;
		if(i != 0)
			l = nCr(n + 2 * i , i) - nCr(n + 2 * i , i - 1);
		if(j != 0)
			r = nCr(m + 2 * j , j) - nCr(m + 2 * j,j - 1);
		result = result + l * r * nCr(n + m + 2 * k,n + 2 * i);
	}
	cout << result << endl;
}



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


namespace AtCoder
{
    class Pair
    {
        public Pair(long a,long b)
        {
            this.right = b;
            this.left = a;
        }
        public long right;
        public long left;
    }

    class Program
    {
        static void Main(string[] args)
        {
            new BG042().slove();
            #if DEBUG
                Console.WriteLine("続行するには何かキーを押してください．．．");
                Console.ReadLine();
            #endif

        }
    }

    class BG042
    {
        public void slove()
        {
            var o = getLineInts();
            var a = o[0];
            var b = o[1];
            var c = o[2];
            var temp = 0;
            temp = a;
            a = b;
            b = temp;
            temp = a;
            a = c;
            c = temp;

            Console.WriteLine("{0} {1} {2}", a, b, c);
        }

        public static int[] getCharInts()
        {
            //return getChar().Select(p => int.Parse(p.ToString())).ToArray();
            var a = new List<int>();
            var b = getChar();
            int i;
            for (i = 0; i < b.Count(); i++)
            {
                a.Add(int.Parse(b[i].ToString()));
            }
            return a.ToArray();
        }


        public static long[] getLineLongs()
        {
            return getLine().Select(p => long.Parse(p)).ToArray();
        }



        public static char[] getChar()
        {
            return getLine()[0].ToCharArray();
        }

        public static int[] getLineInts()
        {
            return getLine().Select(p => int.Parse(p)).ToArray();
        }

        public static String[] getLine()
        {
            String line = Console.ReadLine();
            String[] sp = line.Split(' ');
            if (sp.Length == 1)
            {
                //System.out.println(line);
                return new String[] { line };
            }
            else
            {
                return sp;
            }
        }
       

        void puts(Object mes)
        {
            Console.WriteLine(mes);
        }
    }


}


Measured memory_bytes: 13396
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_profit = lst[1] - lst[0]
min_value = min(lst[0], lst[1])

for i in range(2, N):
    price = lst[i]
    max_profit = max(max_profit, price - min_value)
    min_value = min(min_value, price)

print(max_profit)

Measured memory_bytes: 15640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N,M,X,Y; cin >> N >> M >> X >> Y;
    int x_max=-100,y_min=100;
    for (int i=0;i<N;i++) {
        int x_i; cin >> x_i;
        if (x_i>x_max) x_max = x_i;
    }
    for (int i=0;i<M;i++) {
        int y_i; cin >> y_i;
        if (y_i<y_min) y_min = y_i;
    }   
    bool ans = false; 
    for (int j=X+1;j<=Y;j++){
        if (x_max<j&&j<=y_min) {
            ans = true;
            break;
        }
        if (ans) break;
    }
    cout << ((ans)? "No War" : "War") << endl;
}

Measured memory_bytes: 256
def main():
    rdx = list(map(int, input().split()))
    r, d, x = rdx[0], rdx[1], rdx[2]
    ans = 0
    arr = []
    for i in range(10):
        if i == 0:
            ans = r * x - d
        else:
            ans = r * arr[i-1] - d
        print(ans)
        arr.append(ans)
main()

Measured memory_bytes: 2940
#!/usr/bin/env python

def f(x: int) -> int:
    """
    >>> f(0)
    1
    >>> f(1)
    0
    """
    if x == 1:
        return 0
    else:
        return 1


if __name__ == '__main__':
    x = int(input())
    print(f(x))

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
using namespace std;
int LOG = 40;
int main(){
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	vector<int> cnt(LOG, 0);
	for (int i = 0; i < N; i++){
		for (int j = 0; j < LOG; j++){
			if (A[i] >> j & 1){
				cnt[j]++;
			}
		}
	}
	long long X = 0;
	for (int i = LOG - 1; i >= 0; i--){
		long long next = X + ((long long) 1 << i);
		if (cnt[i] * 2 < N && next <= K){
			X = next;
		}
	}
	long long ans = 0;
	for (int i = 0; i < N; i++){
		ans += X ^ A[i];
	}
	cout << ans << endl;
}

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

// 全パターン拡張(二次元dp)
int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(3));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
        }
    }

    vector<vector<int> > dp(n, vector<int>(3));
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(k==j){
                    continue;
                }
                dp[i][k] = max(dp[i-1][j] + a[i][k], dp[i][k]);
            }
        }
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;

    return 0;
}

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

using namespace std;


// Bismilahir Rahmanir Rahim


typedef unsigned int ui;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef short int si;
typedef unsigned short int usi;
typedef pair <int, int> pii;


#define CASE false
#define TEST false
#define BUFFER true
#define TIME false
#define DEBUG true
#define SET_GEN false
#define _ << " " <<
#define __ << "\n"
#define ff first
#define ss second
#define RANGE(a, b) (rand() % (b-a+1) + a)


const double pi = acos(-1.);
const double eps = 1e-7;
const int high = 2e9;
const int inf = 2147483647;
const int _inf = -2147483648;
const lli INF = 1e18;
const int mod = 1e9+7;


void delay(int sec); // DEBUG


void solution(void)
{	
	int n;
	
	cin >> n;
	vector <int> dp(3);
	
	int a, b, c;
	cin >> a >> b >> c;
	
	dp[0] = a;
	dp[1] = b;
	dp[2] = c;
	
	for(int i = 1; i < n; ++i) {
		vector <int> new_dp(3);
		
		cin >> a >> b >> c;
		new_dp[0] = max(dp[1], dp[2]) + a;
		new_dp[1] = max(dp[0], dp[2]) + b;
		new_dp[2] = max(dp[0], dp[1]) + c;
		
		dp = new_dp;
	}
	
	cout << max(max(dp[0], dp[1]), dp[2]);
	

    return ;
}

int main(int argc, char *arv[])
{
    #if BUFFER
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif

    #if SET_GEN
    srand((unsigned int) time(0));
    #endif

    int t = 1;

    #if CASE
    int cnt = 1;
    #endif

    #if TEST
    cin >> t;
    #endif

    #if TIME
    clock_t start_time, end_time;
    double time_elapsed;
    #endif


    while(t--) {

        #if TIME
        start_time = clock();
        #endif

        #if CASE
        cout << "Case " << cnt++ << ": ";
        #endif

        solution();

        #if TIME
        end_time = clock();

        time_elapsed = (double) (end_time - start_time) / CLOCKS_PER_SEC;

        cout << "\nRuntime: " << fixed << setprecision(7) << time_elapsed << "\n";
        #endif
    }


    return 0;
}

void delay(int sec)
{
    int mili_sec = 1000 * sec;

    clock_t start_time = clock();

    while (clock() < start_time + mili_sec);

    return ;
}


Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class BRuinedSquare {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
            for (int i = 0; i < 2; i++) {
                int x = x2 + (y1 - y2);
                int y = y2 + (x2 - x1);
                out.print(x);
                out.print(' ');
                out.print(y);
                out.print(' ');
                x1 = x2;
                y1 = y2;
                x2 = x;
                y2 = y;
            }
        }

    }
}



Measured memory_bytes: 23252
N = int(input())
F = []
for i in range(N):
  a,b = map(int,input().split())
  F.append([a+b,a,b])
F.sort(key=lambda x:x[0],reverse=True)
ans = 0
for i in range(N):
  if i%2==0:
    ans += F[i][1]
  else:
    ans -= F[i][2]
print(ans)


Measured memory_bytes: 63960
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<int> v[n];
	for(int i = 0,j,k; i<m; i++)
	{
		cin>>j>>k;
		--j,--k;
		v[j].push_back(k);
		v[k].push_back(j);
	}
	int flag = 0;
	for(int i = 1; i<n; i++)
	{
		int y = 0;
		for(int j :v[i])
			if(j==0 || j== n-1)
				y++;
		if(y==2)
			flag = 1;
	}
	if(flag)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	int q;
	cin >> q;
	int cnt_q1 = 0;
	string pre = "", post = "";
	rep(i, q) {
		int type;
		cin >> type;
		if(type == 1) {
			cnt_q1++;
		}
		else if(type == 2) {
			int f;
			char c;
			cin >> f >> c;
			if((cnt_q1 % 2 == 0 && f == 1) || (cnt_q1 % 2 == 1 && f == 2)) {
				pre = c + pre;
			}
			else {
				post += c;
			}
		}
	}
	s = pre + s + post;
	if(cnt_q1 % 2 == 1) {
		reverse(s.begin(), s.end());
	}
	cout << s << endl;
}


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

void solve(int N, vector<int> x, vector<int> y)
{
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        p.at(i) = i;
    }
    double len = 0;
    int cnt = 0;
    do
    {
        cnt++;
        for (int i = 1; i < N; i++)
        {
            int xi = x.at(p.at(i)), xj = x.at(p.at(i - 1));
            int yi = y.at(p.at(i)), yj = y.at(p.at(i - 1));
            len += sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj));
        }
    } while (next_permutation(p.begin(), p.end()));
    cout << fixed << setprecision(10);
    cout << len / cnt << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x.at(i);
        cin >> y.at(i);
    }
    solve(N, move(x), move(y));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = -100000;
    ans = max(a*c, b*d);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    cout << ans << "\n";

    return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr ll MOD =  998244353;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
COMinit();
int n,m,k;
cin>>n>>m>>k;
ll ans=0;
rep(i,k+1){
    ans+=((m*COM(n-1,i)%MOD)*modpow(m-1,n-i-1,MOD))%MOD;
    ans%=MOD;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 123184
from collections import deque

def main():
  N, M = list(map(int, input().split(' ')))

  root = [[] for i in range(N+1)]
  for i in range(M):
    A, B = list(map(int, input().split(' ')))
    root[A].append(B)
    root[B].append(A)

  mitisurube = [-1 for i in range(N+1)]
  next_ = deque()
  next_.append(1)

  while next_:
    now_pos = next_.popleft()
    for next_pos in root[now_pos]:
      if mitisurube[next_pos] == -1:
        mitisurube[next_pos] = now_pos
        next_.append(next_pos)
  #print('root')
  #print(*root)
  #print('mitisirube')
  print('Yes')
  print(*mitisurube[2:], sep='\n')

if __name__ == '__main__':
  main()

Measured memory_bytes: 96532
H,W=map(int,input().split())
C=[input() for i in range(H)]
F=[[0 for i in range(W)] for j in range(H)]
cc=0
for i in range(H):
    cc+=list(C[i]).count('#')
C[0]='s'+C[0][1:]
C[-1]=C[-1][:-1]+'g'
for i in range(H):
	if('s' in C[i]):
		home_y=i
		home_x=C[i].index('s')
	if('g' in C[i]):
		store_y=i
		store_x=C[i].index('g')

stack=[[home_x,home_y]]

def check(x,y):
	if(x<0 or x>=W or y<0 or y>=H):
		return 0
	if(C[y][x]=='.'):
		return 0
	if(F[y][x]==1):
		return 0
	return 1

while(len(stack)!=0):
    x,y=stack.pop()
    F[y][x]=1
    if(check(x+1,y)):
        stack.append([x+1,y])
    #if(check(x-1,y)):
        #stack.append([x-1,y])
    if(check(x,y+1)):
        stack.append([x,y+1])
    #if(check(x,y-1)):
        #stack.append([x,y-1])
    #print(stack)

if(F[store_y][store_x]==1) and cc==H+W-1:
	print('Possible')
else:
	print('Impossible')
#print(F)



Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 2010

bitset<SIZE> S1[SIZE], S2[SIZE];
int hist_size[SIZE][SIZE], b1[SIZE], b2[SIZE];
char str[SIZE][SIZE];

int find_maxArea(int idx, int h) {
   vector<int> stack;
   hist_size[1][idx] = -1;
   stack.push_back(1);
   for (int i = 2 ; i <= h ; ++i) {
      while (hist_size[stack.back()][idx] >= hist_size[i][idx]) {
         stack.pop_back();
      }
      b1[i] = stack.back();
      stack.push_back(i);
   } 

   stack.clear();
   hist_size[h + 1][idx] = -1;
   stack.push_back(h + 1);
   for (int i = h ; i > 1 ; --i) {
      while (hist_size[stack.back()][idx] >= hist_size[i][idx]) {
         stack.pop_back();
      }
      b2[i] = stack.back();
      stack.push_back(i);
   } 

   int ret = 0;
   for (int i = 2 ; i <= h ; ++i) {
      ret = max(ret, (b2[i] - b1[i]) * (hist_size[i][idx] + 1));
   }
   return ret;
}

int find_maxRect (int h, int w) {
   for (int i = h ; i > 1 ; --i) {
      hist_size[i][w] = !S1[i][w];
      for (int j = w - 1 ; j > 1 ; --j) {
         hist_size[i][j] = (!S1[i][j] ? hist_size[i][j + 1] + 1 : 0);
      }
   }
   int ret = 0;
   for (int j = 2 ; j <= w ; ++j) {
      ret = max(ret, find_maxArea(j, h));
   }
   ret = max(max(ret, h), w);
   return ret;
}

enum color {black = '#', white = '.'};

int main() {
   int h, w;
   scanf("%d %d", &h, &w);
   for (int i = 1 ; i <= h ; ++i) {
      scanf("%s", str[i] + 1);
   }
   for (int i = 1 ; i <= h ; ++i) {
      for (int j = 1 ; j <= w ; ++j) S1[i][j] = (str[i][j] == black);
   } 

   for (int i = 2 ; i <= h ; ++i) {
      S2[i] = S1[i - 1] ^ S1[i]; 
   }
   for (int j = 2 ; j <= w ; ++j) {
      for (int i = 2 ; i <= h ; ++i) {
         S1[i][j] = S2[i][j - 1] ^ S2[i][j];
      }
   }

   printf("%d\n", find_maxRect(h, w));

   return 0;
}

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

int main(){
  int n, q; string s;
  cin>>n; cin>>q; cin>>s;
  int memo[n] = {};
  for(int i=1;i<n;i++){
    memo[i] = memo[i-1]+(s[i-1]=='A' && s[i] =='C');
  }
  for(int j=0;j<q;j++){
    int l, r;
    cin>>l; cin>>r;
    cout<<memo[r-1]-memo[l-1]<<endl;
  }
}

Measured memory_bytes: 1408
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long A = input.nextInt();
        long B = input.nextInt();

        System.out.println(lcm(A,B));
    }

    public static long gcd(long A, long B) {
        while (B > 0) {
            long tmp = B;
            B = A % B;
            A = tmp;
        }
        return A;
    }

    public static long lcm(long A, long B) {
        return (A * B) / gcd(A,B);
    }
}


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

int main() {
  int K, X;
  cin >> K >> X;

  if (K * 500 >= X)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


int power(ll x, unsigned int y)  
{  
	ll p=mod;
    ll res = 1;      
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  
ll gcdExtended(ll a, ll b, ll *x, ll *y)  
{  
    // Base Case  
    if (a == 0)  
    {  
        *x = 0;  
        *y = 1;  
        return b;  
    }  
  
    ll x1, y1; // Tor store results of recursive call  
    ll gcd = gcdExtended(b%a, a, &x1, &y1);  
  
    // Update x and y using results of  
    // recursive call  
    *x = y1 - (b/a) * x1;  
    *y = x1;  
  
    return gcd;  
}  

int main()
{
	vector<ll>v[200006];
	ll n,q;
	cin>>n>>q;
	ll s[n+1];

	rep(i,0,n+1)
	s[i]=0;

	rep(i,0,n-1)
	{
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
		

	}
	
	rep(i,0,q)
	{
		ll t,u;
		cin>>t>>u;
		s[t]+=u;
	}
	
	ll vis[n+1];
	for(int i=0;i<=n;i++)
	vis[i]=0;
	queue<ll> qw;

	qw.push(1);
	vis[1]=1;
	while(!qw.empty())
	{
		ll u=qw.front();
		qw.pop();
		rep(i,0,v[u].size())
		{
			ll c=v[u][i];
			

			if(vis[c]==1)
			{
				
				continue;
			}
			
			
			vis[c]=1;
			s[c]+=s[u];
		
			qw.push(c);
		}
	}
	rep(i,1,n+1)
	{
		cout<<s[i];
		if(i==n)
			cout<<endl;
		else
			cout<<" ";
	}

	
}


Measured memory_bytes: 19440
S = str(input())

targets = ['A', 'C', 'G', 'T']

ans = 0
for i in range(len(S)):
    cnt = 0
    if S[i] in targets:
        for j in range(i, len(S)):
            if S[j] in targets:
                cnt += 1
            else:
                break
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int a,b,c;
    cin >>a>>b>>c;
    if(b-a==c-b) cout << "YES"<< endl;
    else cout << "NO" <<endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

static const int MAX_N = 100010;

int memo[MAX_N];

int f(int n)
{

    if(n == 0) {
        return 0;
    }

    if(memo[n] != -1) {
        return memo[n];
    }

    int res = f(n-1) + 1;

    for(int i = 6; i <= n; i *= 6) {
        res = min(res, f(n-i) + 1);
    }

    for(int i = 9; i <= n; i *= 9) {
        res = min(res, f(n-i) + 1);
    }

    memo[n] = res;

    return res;
}

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

    for(int i = 0; i < MAX_N; ++i) {
        memo[i] = -1;
    }

    int ans = f(n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3712
x,n=list(map(int,input().split()))
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
P.append(x)
PP=sorted(P)
if PP.count(x) == 1:
  print(x)
else:
  i=PP.index(x)
  k=1
  high=x
  low=x
  while k>0:
    if PP.count(x+k)==0:
      high=x+k
    if PP.count(x-k)==0:
      low=x-k
    k+=1
    if low!=x:
      print(low)
      exit()
    elif high!=x:
      print(high)
      exit()


Measured memory_bytes: 62096
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    string s;
    cin >> s;

    int n = s.length();
    VI x(n);
    REP(i, n) {
        x[i] = s[i] - '0';
    }

    int ans = stol(s);

    FOR(i, 1, n) {
        stack<VI> q;
        FOR(j, 1, n) {
            q.push(VI(1, j));
        }

        while (!q.empty()) {
            VI t = q.top();
            q.pop();
            if (t.size() == i) {
                t.PB(n);
                int a = 0, p = 0;
                REP(j, n) {
                    if (j == t[p]) {
                        ans += a;
                        a = 0;
                        p++;
                    }
                    a = a * 10 + x[j];
                }
                ans += a;
            } else {
                int s=t.back()+1;
                if(n-t.size())
                t.PB(0);
                FOR(j,s,n){
                    t.back()=j;
                    q.push(t);
                }
            }
        }
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
def chk(s):
  if int(s) > N:
    return 0
  else:
    flag=True
    for c in '753':
      if not c in s:
        flag=False
        break
    count=0
    if flag:
      count=1
    for c in '753':
      count += chk(s+c)
    return count
print(chk('0'))

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

int main(){
	int high[3] = {0}, height;
	while(cin >> height){
		if(high[0] < height){
			high[2] = high[1];
			high[1] = high[0];
			high[0] = height;
		}
		else if(high[1] < height){
			high[2] = high[1];
			high[1] = height;
		}
		else if(high[2] < height)
			high[2] = height;
	}
	for(int i = 0; i < 3; i++)
		cout << high[i] << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
ll gcd(ll p,ll q){for(ll t;q;)t=p%q,p=q,q=t;return p;}

int d[50],cnt;
void f(ll x){
	for(ll p=2;p*p<=x;p++)if(x%p==0){
		d[cnt++]=p;
		while(x%p==0)x/=p;
	}
	if(x!=1)d[cnt++]=x;
}

int ord(ll x,int MOD){
	int e=MOD-1;
	rep(i,0,cnt)while(e%d[i]==0&&pom(x,e/d[i],MOD)==1)e/=d[i];
	return e;
}

int main(){
	int MOD,t;
	scanf("%d%d",&MOD,&t);
	f(MOD-1);
	while(t--){
		int n;
		scanf("%d",&n);
		ll ddd=MOD-1;
		rep(i,0,n){
			int x;
			scanf("%d",&x);
			if(x!=1)ddd=gcd(ddd,(MOD-1)/ord(x,MOD));
		}
		int target;
		scanf("%d",&target);
		int e=(MOD-1)/ord(target,MOD);
		puts(e%ddd?"0":"1");
	}
}


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

typedef long long ll;
const ll mod = 1e9+7;
const int N = 2e5;
ll fact[N+100],inv[N+100];

ll bigmod(ll a,ll b)
{
	if(b==0){
		return 1;
	}
	ll x = bigmod(a,b/2);
	x = (x*x)%mod;
	if(b%2){
		x = (x*a)%mod;
	}
	return x;
}
int main()
{
	fact[0] = inv[0] = 1;
	for(int i=1;i<=N;i++){
		fact[i] = (fact[i-1]*i)%mod;
		inv[i] = bigmod(fact[i],mod-2);
	}
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	ll ans = bigmod(2,n);
	ans = (ans-1+mod)%mod;
	ll mina = 1,minb = 1;
	for(int i=n;i>n-a;i--){
		mina = (mina*i)%mod;
	}
	for(int i=n;i>n-b;i--){
		minb = (minb*i)%mod;
	}
	mina = (mina*inv[a])%mod;
	minb = (minb*inv[b])%mod;
	ans = (ans-mina+mod)%mod;
	ans = (ans-minb+mod)%mod;
	printf("%lld\n",ans);
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  string s;
  cin >> s;
  ll n = s.size();

  ll ans = 100;
  for(char c = 'a'; c <= 'z'; c++){
    ll cnt = 0, ma = 0;
    for(ll i = 0; i < n; i++){
      if(s[i] != c) cnt++;
      else{
        ma = max(ma, cnt);
        cnt = 0;
      }

    }
    ma = max(ma, cnt);
    ans = min(ans, ma);
  }
  cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi v(n), c(n);

		for(int i=0;i<n;i++) scanf("%d", &v[i]);
		for(int i=0;i<n;i++) scanf("%d", &c[i]);

		int ans=0;
		for(int i=0;i<n;i++)
		{
			int t=v[i]-c[i];

			if(t>0) ans+=t;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256