akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll

int dp[100001];

void solve() {
	int c, n, m;
	cin >> c >> n >> m;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		for (int q = c; q >= 0; --q) {
			dp[q + a] = max(dp[q + a], dp[q] + b);
		}
	}
	ll ans[10001] = {};
	for (int i = 1; i <= c; ++i) {
		for (int q = 1; q * i <= c&&q <= m; ++q) {
			ans[q] = max(ans[q], dp[i] * q);
		}
	}
	for (int i = 1; i <= m; ++i) {
		cout << ans[i] << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3412
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e5;

int n;
int t[(N << 1) + 1];
struct Node {
	int x, num;
} node[(N << 1) + 1];
ll ans;

inline bool compare(Node a, Node b)
{
	return a.x < b.x;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++) {
		int x = read();
		node[((i - 1) << 1) + 1] = Node{ x, ((i - 1) << 1) + 1 };
		x = read();
		node[i << 1] = Node{ x, i << 1 };
	}

	sort(node + 1, node + (n << 1) + 1, compare);
	for (int i = 1; i <= n; i++) {
		ans += (ll)node[i].x;
		t[node[i].num]++;
	}
	bool flag = true, flag2 = true, flag3 = true;
	for (int i = 1; i <= n; i++) {
		if (t[((i - 1) << 1) + 1])
			flag2 = false;
		if (t[i << 1])
			flag3 = false;
		if (t[((i - 1) << 1) + 1] && t[i << 1])
			flag = false;
	}
	if (flag && !flag2 && !flag3) {
		if ((node[n].num + 1) >> 1 != (node[n + 1].num + 1) >> 1)
			ans += (ll)node[n + 1].x - (ll)node[n].x;
		else
			ans += (ll)min(node[n + 2].x - node[n].x, node[n + 1].x - node[n - 1].x);
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6012
# C - Monsters Battle Royale

def gcd(x, y):
    if x == 0:
        return y
    else:
        return gcd(y%x, x)

N = int(input())
A = list(int(x) for x in input().split())

ans = gcd(A[0], A[1])
for i in range(2, N):
    ans = gcd(ans, A[i])

print(ans)

Measured memory_bytes: 15020
# coding: utf-8

list = input().rstrip().split(" ")
len = int(list[1]) - int(list[0])

count = 0

for i in range(len+1):
    num = int(list[0]) + i
    result = int(list[2]) % int(num)
    if int(result) == 0:
        count += 1

print(count)

Measured memory_bytes: 7672
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n =scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <=n; k++) {
                    sum+=gcd(k,gcd(i,j));
                }
            }
        }
        System.out.println(sum);
    }
    public static int gcd(int a, int b){
        if(b == 0) return a;
        return gcd(b, a%b);
    }
}


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

int A, B, C, X;

int main(){
    cin >> A >> B >> C >> X;
    int res = 0;

    for(int a=0; a<=A; a++){
        for(int b=0; b<=B; b++){
            for(int c=0; c<=C; c++){
                if(500*a + 100*b + 50*c == X) res++;
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
/*
*  Author: windystreet
*  Date  : 2019-04-13 11:07:49
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

bool ok(char c){
	if(c=='A' || c == 'C' || c =='G' || c == 'T')return true;
	return false;
}
int ans[maxn];
void solve(){
	int n,Q;
	cin>>n>>Q;
	string s;
	cin>>s;
	int len = n;
	for(int i=0;i<len-1;i++){
		if(s[i]=='A' && s[i+1]=='C'){
			ans[i+1] = ans[i]+1;
		}else{
			ans[i+1] = ans[i];
		}
	}
	// for(int i=0;i<len;i++){
	// 	printf("%d%c",ans[i]," \n"[i==len-1]);
	// }
	int l,r;
	while(Q--){
		cin>>l>>r;
		printf("%d\n",ans[r-1]-ans[l-1]);
	}
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("F:/in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <bitset>
#include <cstring>
#include <string>


using namespace std;
typedef long long int ll;
typedef vector<int>  VI;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))

int takakuwa[1000009] = {1};


void solve(int& n,int& a, int& b){
	//takakuwa[0] =1;
	CLR(takakuwa);
	takakuwa[0] = 1;
	REP(i,1000001){
		if(i+a > 1000000) break;
		takakuwa[i+a] = max(takakuwa[i],takakuwa[i+a]);
	}
	REP(i,1000001){
		if(i+b > 1000000) break;
		takakuwa[i+b] = max(takakuwa[i],takakuwa[i+b]);
	}
	int ans =0;
	REP(i,n+1){
		if(takakuwa[i] ==0) ans +=1;
	}
	cout << ans << endl;
}

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

	/*
	int n;
	cin >>n;
	for(int i;i<n;i++){
		cin >>;
	}
	*/
	int n,a,b;
	while(cin >>n >>a >>b){
		if(n==0 && a==0 && b==0)return 0;
		solve(n,a,b);
		}	
	return 0;
}

Measured memory_bytes: 5104
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	char[] s;
	public void solve() {
		N = nextInt();
		s = next().toCharArray();
		int ans = 0,x = 0;
		for(int i = 0;i < N;i++){
			if(s[i] == 'I'){
				x++;
			}else{
				x--;
			}
			ans = Math.max(ans, x);
		}

		out.println(ans);
	}
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21204
const main = arg => {  
  const input = arg.trim().split('\n')
  const [n, m] = input[0].split(' ').map(t => parseInt(t))

  const ln = new Array(n)
  for (let i = 0; i < n; i++) ln[i] = new Array(0)

  input.slice(1, m + 1).forEach(t => {
    const l = t.split(' ')
    ln[parseInt(l[0]) - 1].push(l[1])
  })

  let cc = 0
  let pc = 0

  ln.filter(l => l.length > 0).forEach(l => {
    const i = l.indexOf('AC')
    if (i < 0) return
    pc += i
    cc++
  })

  console.log(cc, pc)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 53812
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<pair<int,int> > v;
    for(int i = 0;i < m;i++)
    {
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(b,a));
    }
    sort(v.begin(),v.end());
    int ans = 0;
    int pos = 0;
    for(int i = 0;i < m;i++)
    {
        if(v[i].second >= pos)
        {
            pos = v[i].first;
            ans++;
        }
    }
    cout << ans << "\n";

    return 0;
}

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

int main(){
  int N,A,B,C1=0,C2=0,C3=0;
  cin >> N >> A >> B;
  for(int i=0;i<N;i++){
    int P;
    cin >> P;
    if(P<=A){
      C1++;
    }
    else if(P<=B){
      C2++;
    }
    else{
      C3++;
    }
  }
  cout << min({C1,C2,C3}) << endl;
}

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

using namespace std;

const int N = 8010;

char s[N];
int b[2];
vector <int> a[2];
bool f[2 * N];
bool nf[2 * N];

int main() {
  scanf("%s %d %d", s, b + 0, b + 1);
  a[0].clear();
  a[1].clear();
  int dir = 0, cnt = 0;
  for (int i = 0; s[i]; ++i) {
    if (s[i] == 'F') {
      ++cnt;
    } else {
      a[dir].push_back(cnt);
      dir = 1 - dir;
      cnt = 0;
    }
  }
  a[dir].push_back(cnt);
  {
    for (int i = 0; i < 2 * N; ++i) {
      f[i] = false;
    }
    f[8000] = true;
    for (int i = 1; i < (int)a[0].size(); ++i) {
      for (int j = 0; j < 2 * N; ++j) {
        nf[j] = false;
      }
      for (int j = 0; j < 2 * N; ++j) {
        if (!f[j]) {
          continue;
        }
        if (j - a[0][i] >= 0) {
          nf[j - a[0][i]] = true;
        }
        if (j + a[0][i] < 2 * N) {
          nf[j + a[0][i]] = true;
        }
      }
      for (int j = 0; j < 2 * N; ++j) {
        f[j] = nf[j];
      }
    }
    int t = 8000 + b[0] - a[0][0];
    if (t < 0 || t >= 2 * N || !f[t]) {
      puts("No");
      return 0;
    }
  }
  {
    for (int i = 0; i < 2 * N; ++i) {
      f[i] = false;
    }
    f[8000] = true;
    for (int i = 0; i < (int)a[1].size(); ++i) {
      for (int j = 0; j < 2 * N; ++j) {
        nf[j] = false;
      }
      for (int j = 0; j < 2 * N; ++j) {
        if (!f[j]) {
          continue;
        }
        if (j - a[1][i] >= 0) {
          nf[j - a[1][i]] = true;
        }
        if (j + a[1][i] < 2 * N) {
          nf[j + a[1][i]] = true;
        }
      }
      for (int j = 0; j < 2 * N; ++j) {
        f[j] = nf[j];
      }
    }
    int t = 8000 + b[1];
    if (t < 0 || t >= 2 * N || !f[t]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 384
/**
 * Question Link: https://atcoder.jp/contests/dp/tasks/dp_t
 * Video solution: https://www.youtube.com/watch?v=FAQxdm0bTaw
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void printMatrix (const vector < vector < int > > & mat) {
	for (const vector < int > vec : mat) {
		for (const int x : vec) {
			cout << x << " ";
		}
		cout << endl;
	}
}

void add_self (int & a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

void sub_self (int & a, int b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}

const int mx = 3005;
char s[mx];
int dp[mx][mx];

int main() {
	// dp (i, j) = total permutations of numbers in the range
	// [1, i] such that last number is j

	int n;
	scanf ("%d %s", &n, s);

	// O (N ^ 3) solution
	// From here
	// dp[1][1] = 1;
	// for (int len = 2; len <= n; len++) {
	// 	for (int b = 1; b <= len; b++) {
	// 		for (int a = 1; a <= len; a++) {
	// 			int new_a = a;
	// 			if (new_a >= b) {
	// 				new_a++;
	// 			}
	// 			assert (new_a != b);
	// 			if ((new_a < b) != (s[len - 2] == '<')) continue;
	// 			add_self (dp[len][b], dp[len - 1][a]);
	// 		}
	// 	}
	// }
	// int answer = 0;
	// for (int i = 1; i <= n; i++) {
	// 	add_self (answer, dp[n][i]);
	// }
	// to here

	dp[1][1] = 1;
	for (int len = 2; len <= n; len++) {
		vector < int > pref_sum (len + 1, 0);
		for (int i = 1; i <= len; i++)  {
			pref_sum[i] = (pref_sum[i - 1] + dp[len - 1][i]) % MOD;
		}
		for (int b = 1; b <= len; b++) {
			int L, R;
			if (s[len - 2] == '<') {
				// a := 1 -> (b - 1)
				L = 1, R = b - 1;
			} else {
				L = b, R = len;
			}
			add_self (dp[len][b], (pref_sum[R] - pref_sum[L - 1] + MOD) % MOD);
			// for (int i = L; i <= R; i++) {
			// 	add_self (dp[len][b], dp[len - 1][i]);
			// }
			// for (int a = 1; a <= len; a++) {
			// 	int new_a = a;
			// 	if (new_a >= b) {
			// 		new_a++;
			// 	}
			// 	assert (new_a != b);
			// 	if ((new_a < b) != (s[len - 2] == '<')) continue;
			// 	add_self (dp[len][b], dp[len - 1][a]);
			// }
		}
	}
	int answer = 0;
	for (int i = 1; i <= n; i++) {
		add_self (answer, dp[n][i]);
	}
	printf ("%d\n", answer);
	return 0;
}

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


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n,l;
	cin >> n>>l;
	vector<int> a(n);
	rep(i, n) {
		a[i] = l + i;
	}
	int s = 0;
	rep(i, n) s += a[i];
	int ans = 1e9;
	rep(i, n) {
		int t = s - a[i];
		if (abs(t - s) < abs(ans - s)) ans = t;
	}
	cout << ans;
	return 0; 
}









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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 0

for i in range(1,n+1,2):
    fact = factorization(i)
    sum = 1
    for j in fact:
        sum *= j[1]+1
    if sum == 8:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    set<pair<int,int>> visited;
    vector<vector<int>> wiz(h,vector<int> (w,0));
    int sy,sx,gy,gx;
    cin>>sy>>sx>>gy>>gx;
    sy--,sx--,gy--,gx--;
    bool goal = false;
    rep(i,h){
        cin>>s[i];
    }
    int maho=0;
    visited.insert({sy,sx});
    queue <pair<int,int>> q;
    queue <pair<int,int>> allq;
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    wiz[sy][sx]=0;

    //cout << dis[sy][sx]<<endl;
    q.push({sy,sx});
    allq.push({sy,sx});
    while(!goal){
        while(!q.empty()){//q.empty=true -> 全部終わったか、壁がある（ワープ?)か
            pair<int ,int> p = q.front();
            allq.push(p);
            q.pop();
            //先頭の今決まってる座標を取り出す
            if(p == make_pair(gy,gx)){//ゴール到達
                goal = true;
                break;
            }
            for(int i=0;i<4;i++){
                int ny = p.first + dy[i];
                int nx = p.second + dx[i];
                if(nx<0||ny<0||nx>=w||ny>=h){
                    continue;
                }
                else if(s[ny][nx]=='#'){
                    continue;
                    //探索しようと思ったら壁
                }
                else if(visited.count({ny,nx})){//探索済み
                    continue;
                }
                else{
                    //dis[ny][nx]= dis[p.first][p.second]+1;
                    //cout <<"dis["<<ny<<"]["<<nx<<"]="<<dis[ny][nx]<<endl;
                    visited.insert({ny,nx});
                    q.push(make_pair(ny,nx));
                    allq.push({ny,nx});
                    wiz[ny][nx]=maho;
                    //新しく確定マスをキューに入れる    
                }
            }
        }
        //ここに来た=>終わりか、周りを壁に囲まれたか
        if(goal)break;
        maho++;
        while(!allq.empty()){
            pair<int,int> cand = allq.front();
            allq.pop();
            for(int dy=-2;dy<=2;dy++){
                for(int dx=-2;dx<=2;dx++){
                    int ny = cand.first + dy;
                    int nx = cand.second + dx;
                    if(ny>=h || ny<0 || nx >=w || nx <0){continue;}
                    if(s[ny][nx]=='#'){continue;}
                    if(!visited.count({ny,nx})){//訪問できなかった
                        visited.insert({ny,nx});
                        wiz[ny][nx]=maho;
                        q.push({ny,nx});
                    }
                }
            }
        }
        if(q.empty()){
            cout<<-1<<endl;
            return 0;}
    }
    cout << wiz[gy][gx]<<endl;

}

Measured memory_bytes: 29016
n = int(input())
s = input()

R_cnt = s.count("R")
G_cnt = s.count("G")
B_cnt = s.count("B")

ans = R_cnt * G_cnt * B_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

print(ans) 

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define pb push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
#define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 2e18;
const int upper = (int) 3e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

int arr[upper];
signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n, l; cin >> n >> l;
	for (int i = 1; i <= n; i += 1) {
		cin >> arr[i];
	}
	bool ok = false;
	int idx;
	for (int i = 2; i <= n; i += 1) {
		if (arr[i] + arr[i - 1] >= l) {
			ok = true;
			idx = i;
			break;
		}
	}
	if (!ok) {
		cout << "Impossible";
		return 0;
	}
	cout << "Possible\n";
	for (int i = 1; i <= idx - 2; i += 1) {
		cout << i << endl;
	}
	for (int i = n - 1; i >= idx; i -= 1) {
		cout << i << endl;
	}
	cout << (idx - 1) << endl;
 	end_routine();		
}


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

int gcd(int a, int b) {
	if (!b) return a;
	if (!a) return b;
	return a > b ? gcd(b, a % b) : gcd(a, b % a);
}

int main() {
	int N, K, Ai;
	int m = 0;
	int d = 0;

	cin >> N >> K;
	for (int i=0; i<N; i++) {
		cin >> Ai;
		if (!d) d = Ai; else d = gcd(d, Ai);
		m = max(Ai, m);
	}

	if (K > m || gcd(d, K) != d) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << "POSSIBLE" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int nextInt(void){
	int res=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')
		ch=getchar();
	while(ch<='9'&&ch>='0'){
		res=res*10+ch-'0';
		ch=getchar();
	}
	return res;
}
signed main(void){
	int n=nextInt(),m=nextInt();
	int ans[n+1];
	for(int i=1;i<=n;i++)
		ans[i]=i;
	for(int i=1;i<=m;i++)
		swap(ans[nextInt()],ans[nextInt()]);
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
}

Measured memory_bytes: 1116
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int H, max_;

	while (true)
	{
		max_ = 0;

		cin >> H;

		if (H == 0) { break; }

		vector<vector<char> > c(H, vector<char>(H));

		vector<vector<int> > dp(H, vector<int>(H, 0));

		for (int i = 0; i < H; i++)
		{
			dp[0][i] = 1; dp[i][0] = 1;
		}

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < H; j++)
			{
				cin >> c[i][j];

				if (c[i][j] == '*')
				{
					dp[i][j] = 0;
				}
				else
				{
					max_ = 1;
				}
			}
		}

		for (int i = 1; i < H; i++)
		{
			for (int j = 1; j < H; j++)
			{
				if (c[i][j] == '.')
				{
					dp[i][j] = min({ dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1] }) + 1;

					max_ = max(dp[i][j], max_);
				}
			}
		}

		cout << max_ << endl;
	}

	return 0;
}

Measured memory_bytes: 7804
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); ++i) {
		s = s.back() + s.substr(0, s.size() - 1);
		if (s == t) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

using namespace std;

typedef long long llint;

/* nの約数を列挙 */
vector<long long> divisors(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i != 0) continue;
    res.push_back(i);
    if (n / i == i) continue;  // 上の行で追加済み。
    res.push_back(n / i);
  }
  return res;
}

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

  auto v = divisors(n);
  sort(v.begin(), v.end());
  llint ans = 1e18;
  for (int i = 0; i < v.size(); i++) {
    llint x = v[i];
    llint y = n / x;
    ans = min(ans, x + y - 2);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main()
{
	int n,m;
	cin>>n>>m;
	int l=-1,h=M;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		l=max(l,x);
		h=min(h,y);
	}
	int x=h-l+1;
	if(x>=0)
	cout<<x;
	else
	cout<<0;
}

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


int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i,k){
        cin >> d.at(i);
    }
    for(int x=n;;x++){
        ostringstream ss;
        ss << x;
        string t = ss.str();
        bool ok=true;
        rep(i,(int)t.length()){
            rep(j,k){
                char c=t[i]-'0';
                if(c==d.at(j)){
                    ok=false;
                    break;
                }
            }
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF = 1 << 30;
const int maxx = 10010;

int dp[maxx], s[maxx];
int w[maxx], v[maxx];
int main() {
	int n, W;
	int A[100];
	int T[50000 + 10];
	scanf("%d %d", &n, &W);
	memset(dp, 0, sizeof(dp));
	memset(s, 0, sizeof(s));
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &v[i], &w[i]);
		s[i] = s[i - 1] + w[i];
	}
	for (int i = 1; i <= n; i++)
	{
		int b = max(w[i], W - s[n] + s[i - 1]);
		for (int j = W; j >= b; j--)
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
	}
	printf("%d\n", dp[W]);
	return 0;
}


Measured memory_bytes: 3304
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	int n;
	cin >> n;
	ll a[n + 1], b[n + 1], c[n];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i < n; i++) {
		cin >> c[i];
	}
	int prev = -1;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += b[a[i]];
		if (prev == a[i] - 1) {
			sum += c[prev];

		}
		prev = a[i];
	}
	cout << sum << nl;

}

signed main() {
	judge();
	boost;
	solve();
}


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

int main(){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if((a==b)+(b==c)+(c==a)==1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define imp() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define endl "\n"
#define lli long long int 
#define ll long long 
#define f(i,a,b) for(i=(int)a;i<(int)b;i++)

int main() {
	// your code goes here
	//imp();
	int n,x,t;cin>>n>>x>>t;int c=0;
	//cout<<(n*t)/x<<"\n";
while(n>0)
{
    c++;
    n=n-x;
}
	cout<<c*t<<"\n";
	
	return 0;
}


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

int N, K, A;

int main() {
    cin >> N >> K;
    A = 1;
    for(int i=1; i<=N; i++) {
        if (2*A < A+K) {
            A = 2*A;
        } else {
            A = A+K;
        }
    }
    cout << A << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    long long int n ;
    cin >> n ;
    long long int h[n] , mincost[n+1] = {0}  , x = 0 ;
    for(int i = 0 ; i < n ; i++)
        cin >> h[i] ;
    mincost[1] = abs(h[1] - h[0]) ;
    mincost[2] = abs(h[2] - h[0]) > (mincost[1] + abs(h[2] - h[1])) ? mincost[1] + abs(h[2] - h[1]) : abs(h[2] - h[0]) ;
    for(int i = 3 ; i < n ; i++)
    {
        mincost[i] = mincost[i-1] + abs(h[i] - h[i-1]) > mincost[i-2] + abs(h[i] - h[i-2]) ? mincost[i-2] + abs(h[i] - h[i-2]) : mincost[i-1] + abs(h[i] - h[i-1]) ; 
    }
    cout << mincost[n-1] << endl ;
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> box(n,vector<int>(3,0));
  for(int i=0;i<n;i++) {
    cin >> box.at(i).at(0) >> box.at(i).at(1) >> box.at(i).at(2);
  }
  vector<vector<int>> dp(n+1,vector<int>(3,0));
  for(int i=0;i<n;i++) {
    for(int j=0;j<3;j++) {
      for(int k=0;k<3;k++) {
        if(j==k) {
          continue;
        }
        dp.at(i+1).at(j)=max(dp.at(i+1).at(j),dp.at(i).at(k)+box.at(i).at(j));
      }
    }
  }
  /*for(int i=0;i<n+1;i++) {
    cout << dp.at(i).at(0) << " " << dp.at(i).at(1) << " " << dp.at(i).at(2) << endl;
  }*/
  int ans=max(dp.at(n).at(0),max(dp.at(n).at(1),dp.at(n).at(2)));
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>

int main() {
    int a[11];
    int n, i, cnt = 0;
    
    while ( scanf("%d",&n) != EOF ) {
        if ( n == 0 ) {
            cnt--;
            printf("%d\n", a[cnt]);
        } else {
            a[cnt] = n;
            cnt++;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2100
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,l[N],k[N],r[N],ans;vpii f,b;
void F(vpii a){
	priority_queue<int>q;
	for(auto i:a){
		q.push(-i.S);
		ans+=i.S;
		//we assume its left is best
		while(q.size()>i.F)ans+=q.top(),q.pop();
	}
}
void solve(){
	cin>>n;ans=0;f.clear(),b.clear();
	rep(i,1,n)cin>>k[i]>>l[i]>>r[i];
	rep(i,1,n){
		if(l[i]>r[i]){
			ans+=r[i];
			f.pb({k[i],l[i]-r[i]});
		}
		else{
			ans+=l[i];
			b.pb({n-k[i],r[i]-l[i]});
		}
	}
	sort(all(f)),sort(all(b));
	F(f),F(b);cout<<ans;
}
int32_t main()
{
  ibs;cti;
  // solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}


Measured memory_bytes: 15924
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int n,v[110000],a[110000],b[110000],ans,mx1,mx2,my1,my2;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&v[i]);
	for(int i=1;i<=n;i+=2) a[v[i]]++;
	fo(i,1,100000)
		if (a[i]>a[mx1]){//!!!
			mx2=mx1;
			mx1=i;
		}else if (a[i]>a[mx2]) mx2=i;
	for(int i=2;i<=n;i+=2) b[v[i]]++;
	fo(i,1,100000)
		if (b[i]>b[my1]){//!!!
			my2=my1;
			my1=i;
		}else if (b[i]>b[my2]) my2=i;
	//printf("%d %d %d %d\n",mx1,mx2,my1,my2);
	if (mx1!=my1){
		ans=n-a[mx1]-b[my1];
	}else{
		ans=n-a[mx1]-b[my2];
		if (n-a[mx2]-b[my1]<ans) ans=n-a[mx2]-b[my1];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	
	public static long naive(long n, long m, long d, long comb, int deep, long prev) {
		if(deep >= m) { return comb; }
		
		long ret = 0;
		for(long curr = 1; curr <= n; curr++) {
			if(prev >= 1 && Math.abs(prev - curr) == d) {
				ret += naive(n, m, d, comb + 1, deep + 1, curr);
			}else {
				ret += naive(n, m, d, comb + 0, deep + 1, curr);
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final long n = sc.nextLong();
			final long m = sc.nextLong();
			final long d = sc.nextLong();
			
			if(d != 0) {
				long all = 1;
				for(int i = 0; i < m; i++) { all *= n; }
				//System.out.printf("%.10f\n", naive(n, m, d, 0, 0, 0) / (double)(all));

				final double lower1 = Math.max(0, n - 2 * d);
				final double lower2 = Math.min(n, 2 * d);
				//System.out.println(n + " " + d + " " + lower1 + " " + lower2);
				
				final double all_1 = lower1 == 0 ? 0 : ((lower1 / n) * (2 * (m - 1)));
				final double all_2 = lower2 == 0 ? 0 : ((lower2 / n) * ((m - 1)));
				//System.out.println(all_1 + " " + all_2);
				
				System.out.printf("%.10f\n", (all_1 + all_2) / n);
				//System.out.printf("%.10f\n", (m - 1) / (double)(n));
			}else {
				System.out.printf("%.10f\n", (m - 1) / (double)(n));
			}
			
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

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

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        while(x%2 == 0) {
            ans++;
            x /= 2;
        }
    }
    cout << ans;

}

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


Measured memory_bytes: 3668
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<2*a;i++)scanf("%d",p+i);
	double ret=0;
	std::sort(p,p+2*a);
	for(int i=0;i<2*a;i++){
		ret+=(double)p[i]*i/(2*a-1);
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 896
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<vector<ll>> dp(n+1, vector<ll>(13, 0));
    dp[0][0] = 1LL;

    int mod = 13;
    for(int i=0; i<n; i++){
        for(int j=0; j<13; j++){
            if(s[i] == '?'){
                for(int k=0; k<=9; k++){
                    int j2 = (j * 10 + k) % mod;
                    (dp[i+1][j2] += dp[i][j]) %= MOD;
                }
            }
            else{
                int num = s[i] - '0';
                int j2 = (j * 10 + num) % mod;
                (dp[i+1][j2] += dp[i][j]) %= MOD;
            }
        }
    }

    cout << dp[n][5] << endl;
}

Measured memory_bytes: 13648
a=input().strip()
b=input().strip()
aa=[]
for i in a:
  aa.append(i)
aa.sort()
aaa="".join(aa)

bb=[]
for i in b:
  bb.append(i)
bb.sort(reverse=True)
bbb="".join(bb)
ccc=[aaa,bbb]
ccc.sort()

if bbb==ccc[0]:
  print('No')
else:
  print('Yes')


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

int main(){
    int d;
    int g;
    cin>>d>>g;
    vector<vector<int>> vec(d, vector<int>(2));
    for(int i=0; i<d; i++){
        cin>>vec.at(i).at(0)>>vec.at(i).at(1);
    }
    vector<int> res(d);
    for(int i=0; i<d; i++){
        res.at(i)=vec.at(i).at(0)*100*(i+1)+vec.at(i).at(1);
    }
    vector<int> num(pow(2, d));
    for(int tmp=0; tmp<(1<<(d)); tmp++){
        bitset<10> b(tmp);
        int ref=0;
        for(int i=0; i<d; i++){
            if(b.test(i)){
                ref+=res.at(i);
                num.at(tmp)+=vec.at(i).at(0);
            }
        }
        if(ref<g){
            b.flip();
            int s=0;
            for(int i=d-1; i>-1; i--){
                if(b.test(i)){
                    s=i;
                    break;
                }
            }
            for(int i=0; i<vec.at(s).at(0); i++){
                if(ref+100*(s+1)*i>=g){
                    num.at(tmp)=num.at(tmp)+i;
                    break;
                }if(i==vec.at(s).at(0)-1&&ref+100*(s+1)*i<g){
                    num.at(tmp)=0;
                }
            }
        }
    }
    int ans=1000000;
    for(int i : num){
        if(i!=0&&ans>i){ans=i;}
    }
    cout<<ans<<endl;
}


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

int main(){
  int a, b;
  cin >> a >> b;

  int x;

  if(b < 10){
    x = a * 10 + b;
  }else if(b < 100){
    x = a * 100 + b;
  }else{
    x = a * 1000 + b;
  }

  if(sqrt(x) - (int)sqrt(x) == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

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

int M;
int a[7];
int s, g;
int N[301];

bool isChecked[301];
set<int> milestone[301];  //そのマスで出せばゴールにたどり着ける目を格納する

int iabs(int x){ return x >= 0 ? x : -x; }

bool search(int now){
	if (isChecked[now]) return false;
	else if (now == g)  return true;

	isChecked[now] = true;
	for (int dice = 1; dice <= 6; dice++){
		if (now + a[dice] <= M && search(now + a[dice] + N[now + a[dice]])){
			milestone[now].insert(a[dice]);
		}
		if (now - a[dice] >= 1 && search(now - a[dice] + N[now - a[dice]])){
			milestone[now].insert(-a[dice]);
		}
	}

	return milestone[now].size() > 0 ? true : false;
}

int main(){
	cin >> M;
	for (int i = 1; i <= 6; i++){
		cin >> a[i];
	}
	cin >> s >> g;
	for (int i = 1; i <= M; i++){
		cin >> N[i];
	}
	bool canGoal = search(s);

	/*うわわああああああああああああああああああああああああああああああああああああ
	あああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ
	あああああああああああああああああああああああああああああああああああああああああああああああああああああああああ
	ああああああああ*/

	int now = s; //自分が今いるマスの番号
	for (;;){
		int dice;
		cin >> dice;

		if (milestone[now].count(a[dice]) > 0){
			now = now + a[dice] + N[now + a[dice]];
			cout << 1 << endl;
		}
		else if (milestone[now].count(-a[dice]) > 0){
			now = now - a[dice] + N[now - a[dice]];
			cout << -1 << endl;
		}
		else cout << 0 << endl;
		cout.flush();

		if (now == g) return 0;
	}
	
	return 0;
}

Measured memory_bytes: 1304
import math

X = int(input())


def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    # nの平方根まで計算する
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True

while True:
    if isPrime(X):
        break
    X += 1

print(X)


Measured memory_bytes: 3060
import sys

S=input()
N=len(S)
ans=0
for i in range(1<<N-1):
    start=0
    for j in range(N-1):
        if 1&(i>>j):
            ans += int(S[start:(j+1)])
            start = j + 1
    ans += int(S[start:])

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
  int A,B;
  char op;
  int S;
  scanf("%d %c %d",&A,&op,&B);
  if(op=='+'){
    S=A+B;
  }
  else if(op=='-'){
    S=A-B;
  }
  else{
  }
  printf("%d\n",S);
  return 0;
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    set<int> st;
    rep(i, min(k, b - a + 1)) st.insert(a + i);
    rep(i, min(k, b - a + 1)) st.insert(b - i);
    for(int t : st) cout << t << endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python
import collections
N, M = map(int, input().split())
A = [int(i)%M for i in input().split()]
B = [0]
sum_ = 0
for a in A:
    sum_ = (sum_ + a) % M
    B.append(sum_)
b = collections.Counter(B)
ans = 0
for c in b.values():
    ans += int(c * (c - 1) / 2)
print(ans)

Measured memory_bytes: 17368
n = int(input())
a = list(map(int,input().split()))

sleft = []
sright = [0]*n
left = 0
right = 0
for i in range(n):
    left += a[i]
    sleft.append(left)
for i in range(n-1,-1,-1):
    right += a[i]
    sright[i] = right
ans = float('inf')
for i in range(1,n):
    ans = min(ans, abs(sright[i] - sleft[i-1]))
print(ans)

Measured memory_bytes: 88144
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  string s;
  cin>>s;
  ll count1=0,count2=0;
  REP(i,SIZE(s)){
    if(s[i]=='1'){count1++;}
    else{count2++;}
  }
  cout<<min(count1,count2)*2<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,i,j;
  cin>>n;
  vector<int64_t> d(n);
  for(i=0;i<n;i++) cin>>d.at(i);
  int64_t ans=0;
  for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) ans+=d.at(i)*d.at(j);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
#define M 1000000007
#define ll long long
#define ldb long double
#define pi acos(-1)
using namespace std;
ll n,k,l,r,a[N],ans=1e18,sum,ans1;
char s[N],t[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>s>>t;
	l=strlen(s);
	r=strlen(t);
	for(int i=0;i<=l-r;i++)
	{
		sum=0;
		for(int j=0;j<r;j++)
		if(s[i+j]!=t[j])
		sum++;
		ans=min(ans,sum);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3640