akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    for(;;) {
        cin >> a >> b;
        if(a == 0 && b == 0) break;
        if(a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3100
// ConsoleApplication70.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include<cstring>
#include<string>
#include <iostream>
using namespace std;
int main()
{
	string a;
	cin >> a;
	for (int i = 0; i < a.length(); i++)
	{
		cout << "x" ;
	}
	cout << "\n";

   
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = STR()
ans = 0
for i in range(len(s)):
    if s[i] == '+':
        ans += 1
    else:
        ans -= 1
print(ans)

Measured memory_bytes: 59628
n = int(input())
s = input()
t = [input() for i in range(n)]
c = 0
for tt in t:
	f = False
	for i in range(len(tt)):
		for j in range(len(tt))[1:]:
			f |= s == tt[i::j][:len(s)]
	if f: c += 1
print(c)

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc103_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S, T;
  cin >> S >> T;
  int N = S.size();

  if (S == T) {
    cout << "Yes" << endl;
    return 0;
  }
  rep(i, N) {
    rotate(S.rbegin(), S.rbegin() + 1, S.rend());
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath>
#include<queue> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  
  int N,n1,n2,i,j;
  cin >> N;
  n1=N%10;
  n2=N/100;
  if(n1==n2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;


LL ruijo(int n){
    LL ans2=1;
    for(int i=0;i<n;++i){
        ans2*=2;
    }
    return ans2;
}


int main(){
    LL n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}



Measured memory_bytes: 256
import java.util.*;
/**
 *
 * @author kouki
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int toshi = sc.nextInt();
        if (toshi==3||toshi==5||toshi==7) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
    
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt)
    val list = IntArray(n)
    for ( i in 0 until n) {
        list[a[i]-1] = i + 1
    }
    println(list.joinToString(separator=" "))
}

Measured memory_bytes: 55904
#include <bits/stdc++.h>
using namespace std;
int main() {
	double n,m,s;
	while(cin>>n>>m>>s,n){
		int ans=0;
		for(int i=1;i<1000;i++){
			for(int j=1;j<1000;j++){
				int p1=i*(n+100)/100;
				int p2=j*(n+100)/100;
				if(p1+p2==s){
					int p1=i*(m+100)/100;
					int p2=j*(m+100)/100+p1;
					ans=max(ans,p2);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
import java.lang.reflect.GenericDeclaration;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		int m=scanner.nextInt();
		if(n<m){
			int tmp=n;
			n=m;
			m=tmp;
		}
		
		System.out.println(gcd(n,m));
	}

	private static int gcd(int n, int m) {
		// TODO Auto-generated method stub
		
		if(m==0) return n;
		else return gcd(m, n%m);
	}

}



Measured memory_bytes: 26324
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	void CalcDigitNum(ll a, std::vector<ll>& digit_num) {
		int cnt = 0;
		while (a != 0) {
			if (a % 2 == 1) ++digit_num[cnt];
			a /= 2;
			++cnt;
		}
	}
}

int main() {

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

	std::vector<std::vector<ll>> digit_num(n, std::vector<ll>(60, 0LL));

	// なるほど！

	rep(i, n) {
		CalcDigitNum(a[i], digit_num[i]);
	}

	ll ans = 0LL;
	rep(i, 60) {
		ll zero_num = 0LL;
		ll one_num = 0LL;
		rep(j, n) {
			zero_num += 1 - digit_num[j][i];
			one_num += digit_num[j][i];
		}

		ans += ((zero_num * one_num) % mod) *  ((1LL << i) % mod);
		ans %= mod;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 154880
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    if(k == 1)
        cout<<0;
    else cout<<n-k;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k, x, y, s = 0;
    cin >> n >> k >> x >> y;
    if (k <= n) s = s + k * x + (n - k) * y;
    else s = s + n * x;
    cout << s;
}

Measured memory_bytes: 3592
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int s = scanInt(), w = scanInt();
        out.print(w >= s ? "unsafe" : "safe");
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32780
A, B, C, D = map(int, input().split())


def gcd(x, y):
    while x % y > 0:
        x, y = y, x % y
    return y


def lcm(x, y):
    return (x * y) // gcd(x, y)


num1 = B // C - (A - 1) // C
num2 = B // D - (A - 1) // D
num3 = B // lcm(C, D) - (A - 1) // lcm(C, D)


print(B - A + 1 - (num1 + num2 - num3))

Measured memory_bytes: 3064
A,B,M = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
min_cost = min(a_list)+min(b_list)
for _ in range(M):
    x,y,c = map(int,input().split())
    cost = a_list[x-1] + b_list[y-1] -c
    if cost<min_cost:
        min_cost = cost
print(min_cost)

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

using ll = long long;
static const ll MOD = 1e9 + 7;

// A*B(行列の掛け算, 各項はmで割った余り)
vector<vector<ll>> mul(vector<vector<ll>> &A, vector<vector<ll>> &B, ll m) {
  vector<vector<ll>> C(A.size(), vector<ll>(B[0].size(), 0));
  for (int i = 0; i < A.size(); i++) {
    for (int k = 0; k < B.size(); k++) {
      for (int j = 0; j < B[0].size(); j++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m;
      }
    }
  }
  return C;
}

// A^n(行列累乗, 各項はmで割った余り)
vector<vector<ll>> power(vector<vector<ll>> A, ll n, ll m) {
  vector<vector<ll>> B(A.size(), vector<ll>(A.size(), 0));
  for (int i = 0; i < A.size(); i++) B[i][i] = 1;
  
  while (n > 0) {
    if (n & 1) B = mul(B, A, m);
    A = mul(A, A, m);
    n >>= 1;
  }
  return B;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  ll k;
  cin >> n >> k;
  
  vector<vector<ll>> a(n, vector<ll>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<vector<ll>> b = power(a, k, MOD);
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans += b.at(i).at(j);
    }
  }
  
  cout << ans % MOD << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  ll n; cin>>n;
  ll v[n+1]; fill(v,v+n+1,1);
  bool f[n+1]={}; f[0]=f[1]=true; // 素数でない
  for(ll i=2;i<=n;i++) {
    if(f[i]) continue;
    for(ll j=2*i;j<=n;j+=i) {
      f[j]=true;
    }
  }

  for(ll i=2;i<=n;i++) {
    if (f[i]) continue;
    for(ll j=i;j<=n;j+=i) {
      ll k=j, p=1;
      while(k%i==0) k/=i,p++;
      v[j]*=p;
    }
  }
  ll an=0;
  for(ll i=1;i<=n;i++) {
    an+=i*v[i];
  }
  cout<<an<<endl;
}

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

#define N 26
#define MAX_T 1.9

const int INF = 1 << 30;
const double mean = 0.0;
const double stddev = 1.0;

int c[N];
int s[365][N];
int last[N];
std::chrono::time_point<std::chrono::steady_clock> start, endt;
random_device rd;
mt19937 generator(rd());
uniform_real_distribution<> dist_real(0.0, 1.0);
uniform_int_distribution<> dist_int(0, RAND_MAX);

struct ContestInfo {
	int D;
	long score;
	long best_score;
	vector<int> t;
	vector<int> best_t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		held[qq].insert(dd);
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}

	void save() {
		best_t = t;
		best_score = score;
	}

	void output(bool show = false) {
		for (int i = 0; i < D; i++)
			cout << best_t[i] + 1 << endl;
		if (show) cout << best_score << endl;
	}
};

double dice() {
	return dist_real(generator);
}

double prob(double rem) {
	return 1.0 / pow(3, rem);
}

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	endt = std::chrono::steady_clock::now();
	std::chrono::duration<double> elapsed_seconds = endt - start;
	return elapsed_seconds.count();
}

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	tic();
	int t;
	ContestInfo ci(d);
	for (int i = 0; i < d; i++) {
		t = max_element(s[i], s[i] + N) - s[i];
		// t = dist_int(generator) % N;
		ci.add(i, t);
	}

	int current_score = ci.score;
	int best_score = current_score;
	ci.save();

	int dd, qq;
	while (toc() < MAX_T) {
		dd = dist_int(generator) % d;
		qq = dist_int(generator) % N;
		int old_q = ci.t[dd];
		ci.change(dd, qq);
		long new_score = ci.score;
		// if (new_score < current_score || prob(MAX_T - toc()) < dice()) {
		if (new_score < current_score) {
			ci.change(dd, old_q);
		} else {
			current_score = new_score;
		}
		if (best_score < current_score) {
			best_score = current_score;
			ci.save();
		}
	}
	ci.output();
}

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

int main() {
	
	while(true){
		string str;
		getline( cin, str);
		if( str == "." ) break;
		stack<char> s;
		
		bool yes = true;
		for(char c : str){
			if( c=='(' || c=='['){
				s.push(c);
			}
			else if( c==')'){
				if( s.empty() || s.top() != '(' ){
					yes=false;
					break;
				}
				s.pop();
			}
			else if( c==']'){
				if( s.empty() || s.top() != '[' ){
					yes=false;
					break;
				}
				s.pop();
			}
		}
		if(!s.empty()) yes=false;
		cout << (yes?"yes":"no") << endl;
	}
	return 0;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
int n, m, x;
int books[15][15];
int prices[15];
int dfs(int index, int current_price, vector<int> keiken, bool buy_this=false) {
  // 最初の呼出では本を買わない
  if(buy_this) {
    REP(i,m) {
      keiken[i] += books[index][i];
    }
    current_price += prices[index];
  }
  if(index == 0) {
    REP(i,m) {
      if(keiken[i] < x) {
        return -1;
      }
    }
    return current_price;
  }
  int a = dfs(index-1, current_price, keiken, true);
  int b = dfs(index-1, current_price, keiken);
  if(a == -1 || b == -1) {
    return max(a,b);  // 両方-1の時は-1、そうで無い時は大きい方
  }
  return min(a,b);
}
/***** MAIN *****/
signed main() {
  cin >> n >> m >> x;
  REP(i,n) {
    cin >> prices[i];
    REP(j,m) {
      cin >> books[i][j];
    }
  }
  cout << dfs(n, 0, vector<int>(m,0));
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.B
{
    public class Program
    {
        public static long H { get; private set; }
        public static long W { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            (H, W) = Read2Longs();
            var table = new List<string>();
            for (int i = 0; i < H; i++)
            {
                table.Add(ReadText());
            }

            var sb = new StringBuilder();
            for (int i = 0; i < H; i++)
            {
                var s = string.Empty;
                for (int j = 0; j < W; j++)
                {
                    if (table[i][j] == '#')
                    {
                        s += '#';
                        continue;
                    }
                    s += GetCount(table, i, j).ToString();
                }
                sb.AppendLine(s);
            }

            return sb.ToString().Trim();
        }

        private static int GetCount(List<string> table, int i, int j)
        {
            var count = 0;
            if (i - 1 >= 0 && j - 1 >= 0 &&
                table[i - 1][j - 1] == '#') count++;
            if (i - 1 >= 0 &&
                table[i - 1][j] == '#') count++;
            if (i - 1 >= 0 && j + 1 < W &&
                table[i - 1][j + 1] == '#') count++;
            if (j - 1 >= 0 &&
                table[i][j - 1] == '#') count++;
            //if (j - 1 >= 0 &&
            //    table[i][j - 1] == '#') count++;
            if (j + 1 < W &&
                table[i][j + 1] == '#') count++;
            if (i + 1 < H && j - 1 >= 0 &&
                table[i + 1][j - 1] == '#') count++;
            if (i + 1 < H && j >= 0 &&
                table[i + 1][j] == '#') count++;
            if (i + 1 < H && j + 1 < W &&
                table[i + 1][j + 1] == '#') count++;

            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28432
n = int(input())

sl = list(input())

sum_r = sl.count("R")
sum_g = sl.count("G")
sum_b = sl.count("B")

rl = []
gl = []
bl = []

for s in sl:
    if s == "R":
        sum_r -= 1
    if s == "G":
        sum_g -= 1
    if s == "B":
        sum_b -= 1
    rl.append(sum_r)
    gl.append(sum_g)
    bl.append(sum_b)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if sl[i] == sl[j]:
            continue
        if "R" not in [sl[i], sl[j]]:
            ans += rl[j]
            if k < n:
                if sl[k] == "R":
                    ans -= 1
        if "G" not in [sl[i], sl[j]]:
            ans += gl[j]
            if k < n:
                if sl[k] == "G":
                    ans -= 1
        if "B" not in [sl[i], sl[j]]:
            ans += bl[j]
            if k < n:
                if sl[k] == "B":
                    ans -= 1
print(ans)

Measured memory_bytes: 68988
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 3001;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n; double p[N], dp[N][N];

void solve()
{
    cin >> n; for (int i=1; i<=n; ++i) cin >> p[i];
    dp[0][0] = 1;
    for (int i=1; i<=n; ++i) {
        for (int j=0; j<=n; ++j) {
            dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
        }
    }
    double ans=0;
    for (int i=n/2 + 1; i<=n; ++i) ans += dp[n][i];
    cout << fixed << setprecision(10) << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 74100
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

int solve (string s)
{
    stack<int> stk;
    string n="";
    int n1, n2;
    bool o=true;
    for (int i=0; i<s.size(); i++)
    {
        if (s[i]=='+' || s[i]=='-' || s[i]=='*')
        {
            o=false;
            n2=stk.top();
            stk.pop();
            n1=stk.top();
            stk.pop();
            if (s[i]=='+') stk.push(n1+n2);
            if (s[i]=='-') stk.push(n1-n2);
            if (s[i]=='*') stk.push(n1*n2);
        }
        else if (s[i]==' ')
        {
            if (o) stk.push(stoi(n));
            o=true;
            n="";
        }
        else n+=s[i];
    }
    return stk.top();
}

int main()
{
    string s;
    getline(cin, s);
    cout<<solve(s)<<'\n';
    return 0;
}



Measured memory_bytes: 3228
X,K,D = map(int,input().split())
if X < 0:
    X *= -1
if D < 0:
    D *= -1
if abs(K*D) > X:
    if K % 2 == 0:
        mini = X//(2*D)
        bigger = X//(2*D)+1
        ans = min(abs(X-(2*D*mini)),abs(X-(2*D*bigger)))
    else:
        smaller_start = X-D
        bigger_start = X+D
        smaller_mini = smaller_start//(2*D)
        smaller_big = smaller_start//(2*D)+1
        bigger_mini = bigger_start//(2*D)
        bigger_big = bigger_start//(2*D)+1
        ans = min(abs(smaller_start-2*D*smaller_mini),abs(smaller_start-2*D*smaller_big),abs(bigger_start-2*D*bigger_mini),abs(bigger_start-2*D*bigger_mini))
else:
    ans = abs(X-K*D)
print(ans)

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

int main()
{
  int S, R, M = 0;
  cin >> S;
  R = S;
  for (long i = 0; i < 8; i++)
  {
    int A = 10;
    for (long j = 0; j < i; j++)
    {
      A *= 10;
    }
    M += S % A / (A / 10);
    S -= S % A;
  }
  if (R % M == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

int main(){
    long long X,K,D; cin >> X >> K >> D;
    long long S = abs(X)/D;
    if(S>=K){
        cout << abs(X+((X>0)?-1:1)*D*K) << endl;
    } else {
        if(X>0){
            X -= D*S;
            K -= S;    
            cout << abs(X-((K%2)?D:0)) << endl;
        } else {
            X += D*S;
            K -= S;
            cout << abs(X+((K%2)?D:0)) << endl;
        }
    }
}

Measured memory_bytes: 3612
#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>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

/*
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()
*/

template <class T> void chmin(T& a, T& b) { a = min(a, b);}
template <class T> void chmax(T& a, T& b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-9;

ll func(ll i) {
    return i*i*i*i*i;
}

void solve() {
    ll x;
    cin >> x;
    for(ll i = -1000; i < 1000; i++) {
        for(ll j = -1000; j < 1000; j++) {
            if(x == func(i) - func(j)) {
                cout << i << ' ' << j << endl;
                return;
            }
        }
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3632
#!/usr/bin/perl

use strict;
use warnings;

my ($n, $k);
{
    my $in = <STDIN>;
    ($n, $k) = split(" ", $in);
}
my @p;
{
    my $in = <STDIN>;
    @p = split(" ", $in);
}
my $sum = 0;
for (my $j=0; $j<$k; $j++)
{
    $sum += $p[$j];
}
my $max = $sum;
if ($n>$k)
{
    for (my $i=0; $i<$n-$k+1; $i++)
    {
        $sum = $sum - $p[$i] + $p[$i+$k];
        if ($max<$sum)
        {
            $max = $sum;
        }    
    }
}
$max = ($max+$k)/2;
print "$max\n";

Measured memory_bytes: 33060
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, x: "List[int]"):

    ans = 10000000000000000000


    al = []

    for i in range(N-K+1):
        if(x[i] <= 0 <= x[i+K-1]):
            w = abs(x[i+K-1]) + abs(x[i]) + min(abs(x[i+K-1]), abs(x[i]))
        else:
            w = max(abs(x[i+K-1]),abs(x[i]))
        
        al = [x[i], x[i+K-1]]
        ans = min(ans, w)
        
    if(not al):
        print(0)
    else:
        print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15148
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,T;
  cin >> n >> m >> T;
  ll a[n],b[m];
  rep(i,n) R a[i];
  rep(i,m) R b[i];
  sort(a,a+n);
  sort(b,b+m);
  while(T--) {
    ll x;
    R x;
    ll ans=MAXL;
    ll x1=-1,x2=-1,y1=-1,y2=-1;
    ll k=lower_bound(a,a+n,x)-a;
    if(k!=n) x2=a[k];
    if(k) x1=a[k-1];
    k=lower_bound(b,b+m,x)-b;
    if(k!=m) y2=b[k];
    if(k) y1=b[k-1];
    {
      ll M=MAXL,f=1;
      if(x1!=-1) M=min(M,x1);
      else f=0;
      if(y1!=-1) M=min(M,y1);
      else f=0;
      if(f&&M!=MAXL) ans=min(ans,abs(x-M));
    }
    {
      vector<ll> v;
      if(x1!=-1) v.pb(x1);
      if(y2!=-1) v.pb(y2);
      if(v.size()==2) {
        rep(i,2) {
          ll y=x,sum=0;
          rep(j,v.size()) {
            sum+=abs(y-v[j]);
            y=v[j];
          }
          ans=min(ans,sum);
          reverse(all(v));
        }
      }
    }
    {
      vector<ll> v;
      if(x2!=-1) v.pb(x2);
      if(y1!=-1) v.pb(y1);
      if(v.size()==2) {
        rep(i,2) {
          ll y=x,sum=0;
          rep(j,v.size()) {
            sum+=abs(y-v[j]);
            y=v[j];
          }
          ans=min(ans,sum);
          reverse(all(v));
        }
      }
    }
    {
      ll M=-MAXL,f=1;
      if(x2!=-1) M=max(M,x2);
      else f=0;
      if(y2!=-1) M=max(M,y2);
      else f=0;
      if(f&&M!=-MAXL) ans=min(ans,abs(M-x));
    }
    pr(ans);
  }
}

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


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    LL x, y; cin >> x >> y;
    int ans = 0;
    for (LL i = x; i <= y; i *= 2) ans++;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a[3],n,m;
int type[10009];
vector<int> G[10005];
int dist[4][10005];

int bfs(int s){
	for(int i=3;i<4;i++){
		queue<int> que;
		for(int j=0;j<n+3;j++){
			dist[i][j]=INF;
		}
		dist[i][s]=0;
		que.push(s);
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int k=0;k<G[v].size();k++){
				int nv=G[v][k];
				if(dist[i][nv]==INF){
					dist[i][nv]=dist[i][v]+1;
					que.push(nv);
				}
			}
		}
	}
	int bes=s;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			if((dist[3][i]+dist[j][i])==dist[j][s]){
				bes=min(bes,i);
			}
		}
	}
	return bes;
}

int main(void){
	scanf("%d%d%d%d",&n,&a[0],&a[1],&a[2]);
	memset(type,-1,sizeof(type));
	for(int i=0;i<3;i++){
		for(int j=0;j<a[i];j++){
			int b;
			scanf("%d",&b);
			b--;
			type[b]=i;
		}
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		if(type[u]>=0){
			u=n+type[u];
		}
		if(type[v]>=0){
			v=n+type[v];
		}
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=0;i<3;i++){
		type[n+i]=i;
	}
	for(int i=0;i<3;i++){
		queue<int> que;
		for(int j=0;j<n+3;j++){
			dist[i][j]=INF;
			if(type[j]==i){
				dist[i][j]=0;
				que.push(j);
			}
		}
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int k=0;k<G[v].size();k++){
				int nv=G[v][k];
				if(dist[i][nv]==INF){
					dist[i][nv]=dist[i][v]+1;
					que.push(nv);
				}
			}
		}
	}
	int ans=INF;
	for(int i=0;i<n+3;i++){
		int aa=dist[0][i]+dist[1][i]+dist[2][i];
		ans=min(aa,ans);
	}
	int bes=114514;
	for(int i=0;i<n+3;i++){
		if(type[i]>=0){
			bes=min(bes,i);
		}
		int aa=dist[0][i]+dist[1][i]+dist[2][i];
		if(aa==ans){
			bes=min(bfs(i),bes);
		}
	}
	printf("%d %d\n",ans,bes+1);
	return 0;
}


Measured memory_bytes: 9248
N = int(input())
H = list(input().split())
H = [int(H[i]) for i in range(N)]
count = 0
MAX = 0
Now = H[0]
for i in range(1, N):
    if Now >= H[i]:
        count += 1
        Now = H[i]
    else:
        MAX = max(MAX, count)
        count = 0
        Now = H[i]
        
print(max(MAX, count))

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    string s;
    cin >> s;
    for(int i=1;i<=2;i++){
        if(s[0]!=s[i]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 3584
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int x[n], y[n]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    for (int i = 0; i < n; i++) {
        double lb = -100, ub;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            double a = atan2(x[j] - x[i], -y[j] + y[i]),
                b = a + M_PI;
            if (lb == -100) { lb = a; ub = b; }
            else {
                if (b < lb) { a += 2 * M_PI; b += 2 * M_PI; }
                else if (ub < a) { a -= 2 * M_PI; b -= 2 * M_PI; }
                lb = max(a, lb);
                ub = min(b, ub);
            }
            if (lb > ub) break;
        }
        cout << setprecision(12) << max(0.0, (ub - lb) / 2 / M_PI) << endl;
    }
}


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

int main(){
  	int a,b,c;
  	string s;
  	cin >> s;
  	string ans;
  	if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]){
      	ans = "Yes";
    }else if(s[0] == s[2] && s[0] != s[1] && s[1] == s[3]){
    	ans = "Yes";
    }else if(s[0] == s[3] && s[0] != s[1] && s[1] == s[2]){
    	ans = "Yes";
    }else{
    	ans = "No";
    }
  	cout << ans << endl;
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {  
            string n = Console.ReadLine();   
            string s = Console.ReadLine();  
            int k = Int32.Parse(Console.ReadLine()); 
            string ret = "";

            for(int i=0;i < s.Length;i++)
            {
                if(s[i] != s[k - 1])
                {
                    ret += '*';
                }
                else
                {
                    ret += s[i];
                }
            }

            Console.WriteLine(ret);
        } 
    }
}


Measured memory_bytes: 13140
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        double r,men,shu;
        r=scan.nextDouble();
         
        men=r*r*Math.PI;
        shu=r*2*Math.PI;
        System.out.println(BigDecimal.valueOf(men).toPlainString()+" "+BigDecimal.valueOf(shu).toPlainString());
    }
}


Measured memory_bytes: 28164
def main():
    n,x = map(int, input().split())
    l = list(map(int, input().split()))
    ans = 1
    max = 0

    #while True:
        #i = 0
        #max += l[i]
        #if max < x:
            #ans += 1
        #i += 1

    for i in range(len(l)):
        max += l[i]
        if max <= x:
            ans += 1
    print(ans)

main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    int N = S.size() + 1;

    ll ans = 0;
    int pre = 0;
    for (int i = 0; i < N - 1; ) {
        int j = 0;
        for (j = i; j < N - 1; ++j) {
            if (S[j] == '<') break;
        }
        int k = 0;
        for (k = j; k < N - 1; ++k) {
            if (S[k] == '>') break;
        }

        ans += max(pre, j - i);
        if (j != i) ans += (ll)(j - i) * (j - i - 1) / 2;
        if (k != j) ans += (ll)(k - j) * (k - j - 1) / 2;
        pre = k - j;

        i = k;
    }
    ans += pre;

    write(ans);
}

Measured memory_bytes: 1172
n = int(input())
dict = {}


for _ in range(n):
    s = input()
    if s in dict:
        dict[s] +=1
    else:
        dict[s] = 1

s = sorted(dict.items(),key=lambda x:x[1],reverse=True)

l = []

for k in dict:
    if dict[k] == s[0][1]:
        l.append(k)

ss = sorted(l)
for v in ss:
    print(v)

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

using namespace std;
#define int long long
const int maxn=105;
bool u[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int x,n;
    cin>>x>>n;
    int a[n];
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=0;i<n;++i) u[a[i]]=true;
    for(int j=0;j<maxn;++j)
    {
        if(!u[x-j])
        {
            cout<<(x-j);
            return 0;
        }
        if(!u[x+j])
        {
            cout<<(x+j);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))
def solve():
    d = {}
    r = max(a)
    mi = (r+1)//2
    for i in a:
        if i < mi:
            return False
        d[i] = d.get(i, 0) + 1

    if not(mi in d and d[mi] == 1+r%2):
        return False
    for i in range(mi+1, r+1):
        if i not in d or d[i] < 2:
            return False
    return True

if solve():
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3064
import fractions as fr
import itertools as it
import collections as col
import heapq as hq
import sys
sys.setrecursionlimit(10**9)

"""
N=int(input())
W=list(map(int, input().split()))
ans=10**100
for T in range(1,N):
        S1=sum(W[:T])
        S2=sum(W[T:])
        ans = min(ans, abs(S1-S2))
print(ans)
"""
P,Q,R=map(int, input().split())
print(min([P+Q, P+R, Q+R]))

Measured memory_bytes: 5436
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <utility>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

using namespace std;

#define init() ios::sync_with_stdio(false); cin.tie();
#define for0(i, n) for (int i=0; i<n; i++)
#define for1(i, n) for (int i=1; i<=n; i++)
#define for2(i, a, b) for (int i=a; i<=b; i++)
#define bac0(i, n) for (int i=n-1; i>=0; i--)
#define bac1(i, n) for (int i=n; i>0; i--)
#define bac2(i, a, b) for (int i=a; i>=b; i--)
#define PB push_back
#define MOD 1000000009
#define S second
#define F first
#define B 99997LL

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, char> ic;

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

int n, m;
char grid[305][305];

int main() {
    init()

    cin >> n;
    for0 (i, n) cin >> grid[i];

    for0 (a, n) {
        bool ok = true;
        for0 (i, n) {
            for0 (j, i) {
                if (grid[i][(j + a) % n] != grid[j][(i + a) % n]) {
                    ok = false;
                    break;
                }
                if (!ok) break;
            }
        }
        if (ok) m += n;
    }

    cout << m << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
int A[112345];

ll solve(int flg) {
	ll l = 0, r = longINF;
	
	while (r - l > 1) {
		ll m = (l + r) / 2;
		ll cur = m;
		REP(i, N) cur = cur - cur % A[i];
		
		if (!flg) (cur >= 2 ? r : l) = m;
		else (cur <= 2 ? l : r) = m;
	}
	
	return !flg ? r : l;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	
	ll l = solve(0), r = solve(1);
	if (l <= r) cout << l << " " << r << endl;
	else puts("-1");
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n;
int a[N], cache[N][4];
bool vis[N][4];

int dp(int idx, int have)
{
	if(idx > n)
	{
		if(have <= 1)
			return 0;
		return -1e18;
	}
	int &ans = cache[idx][have];
	if(vis[idx][have])
		return ans;
	vis[idx][have] = 1;
	if(!have)
		ans = a[idx] + dp(idx + 2, have);
	else
		ans = max(a[idx] + dp(idx + 2, have), dp(idx + 1, have - 1));
	return ans;
}

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	int ans;
	if(n % 2)
		ans = max(dp(1, 2), dp(2, 1));
	else
		ans = max(dp(1, 1), dp(2, 0));
	cout << ans;
	return 0;
}


Measured memory_bytes: 16932
n = int(input())
li = []
for i in range(n):
    a, b = input().split()
    b = int(b)
    li.append([a, b, i+1])

li.sort(key=lambda x: x[1], reverse=True)
li.sort(key=lambda x: x[0])
for i in range(n):
    print(li[i][2])


Measured memory_bytes: 3060
// seabreeeze //
 
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli unsigned long long
lli MOD=1e9+7;
 
#define MAXN 2000006 
 
// Template function //
lli powermod(lli x, lli y)  
{  
    lli res = 1;  
    x = x % MOD;
    if (x == 0) return 0;  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % MOD;  
        y = y>>1;   
        x = (x*x) % MOD;  
    }  
    return res;  
}
lli modinv(lli x)
{
    return powermod(x,MOD-2);
}
// Template functions end //
 
// Custom funtions //
void preprocess()
{

}

int mex(int a[],int n)
{
    vector<int> c(n+1,0);
    for(int i=0;i<n;i++)
    {
        c[a[i]]=1;
    }
    for(int i=0;i<n+1;i++)
    {
        if(c[i]==0)
        return i;
    }
    return 0;
}
 
// Custom functions end //
 
int main()
{
    lli q=1;
    // cin>>q;
    time_t start, end;
    time(&start);
    preprocess();
    for(lli tc=1;tc<=q;tc++)
    {
        // Start solution //
        lli n;
        cin>>n;
        cout<<(1000-n%1000)%1000<<endl;
        // End Solution //
        end:;
    }
    
    time(&end);
    // cout<<fixed<<double(end - start)<<setprecision(10)<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

#define NUM 2147483647

using namespace std;

struct Info{
	int left,right,minimum;
};

Info* info;
int* index_table;
int N;

void func(int index){
	int div = info[index].right - info[index].left;

	if(div != 0){
		if(div%2 == 1){ //????????????2?????????????????´???
			info[index*2+1].left = info[index].left;
			info[index*2+1].right = (info[index].left + info[index].right)/2;
			func(index*2+1);
			info[index*2+2].left = (info[index].left + info[index].right)/2 + 1;
			info[index*2+2].right = info[index].right;
			func(index*2+2);
		}else{
			info[index*2+1].left = info[index].left;
			info[index*2+1].right = (info[index].left + info[index].right)/2;
			func(index*2+1);
			info[index*2+2].left = (info[index].left + info[index].right)/2 + 1;
			info[index*2+2].right = info[index].right;
			func(index*2+2);
		}
	}else{
		index_table[info[index].left] = index;
	}
}

void update(int index, int new_value){
	info[index_table[index]].minimum = new_value;

	if(index_table[index] == 0)return;
	int t = index_table[index];

	/*while(true){
		info[t].minimum = min(info[2*t+1].minimum,info[2*t+2].minimum);
		if(t == 0)break;
		t = (t-1)/2;
	}*/
	do{
		t = (t-1)/2;
		info[t].minimum = min(info[2*t+1].minimum,info[2*t+2].minimum);
	}while(t != 0);
}

int getMinimum(int index,int left,int right){
	if(info[index].left > right || info[index].right < left){
		return NUM;
	}else if(info[index].left >= left && info[index].right <= right){
		return info[index].minimum;
	}else{
		return min(getMinimum(index*2+1,left,right),getMinimum(index*2+2,left,right));
	}
}

int main(){

	int Q,type,a,b;
	scanf("%d %d",&N,&Q);

	info = (Info*)malloc(sizeof(Info)*(4*N));
	for(int i = 0; i < 4*N; i++){
		info[i].minimum = NUM;
		info[i].left = info[i].right = -1;
	}
	index_table = new int[N];

	info[0].left = 0,info[0].right = N-1;

	func(0);

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d",&type,&a,&b);
		if(type == 0){
			update(a,b);
		}else{
			printf("%d\n",getMinimum(0,a,b));
		}
	}
	return 0;
}

Measured memory_bytes: 7764