akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc054/tasks/abc054_c

int main() {
    int N, M; cin >> N >> M;
    int path[8][8] = {};

    int a,b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--; b--;
        path[a][b] = 1;
        path[b][a] = 1;
    }

    int perm[N-1];
    for (int i = 1; i < N; i++) {
        perm[i - 1] = i;
    }

    int ans = 0;
    do {
        int now = 0;
        for (int i = 0; i < N - 1; i++) {
            if (path[now][perm[i]] == 0) break;
            now = perm[i];
            if (i == N-2) ans++;
        }
    } while(next_permutation(perm, perm + (N - 1)));

    cout << ans << "\n";

    return 0;
}


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


int main() {
int64_t N,W;
  cin >> N>>W;
  int64_t s = N*W;
  int64_t ans;
  if(N ==1 ||W ==1) ans =1;
 else  if(s%2==0) ans = s/2;
  else ans = s/2+1;
  printf("%lld\n",ans);
}
  


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s;

void out(int i,int j){
  cout << i << " " << j <<endl;
}

int main(){
  cin >> s;
  if(s.size()==2){
    if(s[0] == s[1]){
      out(1,2);
    }else{
      out(-1,-1);
    }
    return 0;
  }
  REP(i,s.size()-2){
    if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
      out(i+1,i+3);
      return 0;
    }
  }
  out(-1,-1);
}


Measured memory_bytes: 512
#include <stdio.h>
#include <limits.h>
typedef unsigned int uint;

inline static uint gl(void){
    uint x = 0;
    for(;;){
        const uint c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

uint v[200000];
int main(void){
    const uint h = gl();
    const uint w = gl();
    const uint n = gl();
    for(uint i=0; i<h; i++){ v[i] = w+1; }
    for(uint i=0; i<n; i++){
        const uint x = gl()-1;
        const uint y = gl()-1;
        v[x] = y<v[x] ? y : v[x];
    }
    uint right = 0;
    for(uint x=1; x<h; x++){
        if(v[x]<right+1){
            printf("%d\n", x);
            return 0;
        }else if(v[x]>right+1){
            right++;
        }
    }
    printf("%d\n", h);
    return 0;
}


Measured memory_bytes: 896
n = input()
l = len(n)
n_r = n[::-1]
n_1 = n[:(l-1)//2]
n_2 = n[(l+3)//2 - 1:]

if n == n_r and n_1 == n_1[::-1] and n_2 == n_2[::-1]:
    print("Yes")
else:
    print("No")


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

using namespace std;

int nc2(int k){
  return k*(k-1)/2;
}

int kai(int k){
  if(k>0){
    return k*kai(k-1);
  }
  else{
    return 1;
  }
}

double kyo(int a1, int b1, int a2, int b2){
  return pow( pow(a1-a2,2)+pow(b1-b2,2) , 0.5);
}

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<double> kyori(nc2(n));
  int a=0;
  double total=0;


  for(int i=0;i<n;i++){
    cin >> x.at(i);
    cin >> y.at(i);
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      kyori.at(a) = kyo(x.at(i),y.at(i) , x.at(j),y.at(j));
      a++;
    }
  }
  for(int i=0;i<nc2(n);i++){
    total=total+kyori.at(i);
  }

  total=total*(n-1);
  total=total/nc2(n);


  printf("%.9f\n",total);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
int A[MAX], n;

int partition(int p, int r){
	int tmp,x = A[r];
	int j,i = p - 1;
	for (j = p; j < r; j++){
		if (A[j] <= x){
			i = i + 1;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i + 1;
}

int main(){
	int i,j;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	j = partition(0, n-1);
	for (i = 0; i < n; i++){
		if (i){
			printf(" ");
		}
		if (i == j){
			printf("[%d]", A[i]);
		}
		else{
			printf("%d", A[i]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2948
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int k, n;
vector<int> a;
vector<int> dist;
int biggest;

int main()
{
	cin >> k >> n;
	for (int in = 0; in < n; in++)
	{
		int x;
		cin >> x;
		a.push_back(x);

		if (in != 0)
		{
			int diff = a[in] - a[in - 1];
			biggest = max(biggest, diff);
		}
	}
	biggest = max(biggest, k - a[a.size() - 1] + a[0]);

	cout << k - biggest << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	ll n;
	cin >> n;
	ll p1 = 0, p2 = 0;
	for (ll i = 0; i < n; i++) {
		string s, t;
		cin >> s >> t;
		if (s < t) {
			p2 += 3;
		}
		else if (s == t) {
			p1++;
			p2++;
		}
		else {
			p1 += 3;
		}
	}
	cout << p1 << " " << p2 << endl;
}




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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  int cnt = 0;
  for (int i = 100; i >= 1; i--){
    if (A % i == 0 && B % i == 0){
      cnt++;
      if (cnt == K){
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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 {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

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

	
	vector<ll> A(N + 1), B(N + 1);
	repn(i, N) cin >> A[i] >> B[i];

	ll zero = 0;
	ll xzero = 0;
	ll yzero = 0;

	map<pair<ll, ll>,ll> pos, neg;

	repn(i, N) {
		ll x = A[i];
		ll y = B[i];

		if (x == 0 && y == 0) { zero++; }
		else if (x == 0) { xzero++; }
		else if (y == 0) { yzero++; }
		else {
			ll g = gcd(abs(x), abs(y));
			x = abs(x) / g;
			y = abs(y) / g;

			if (A[i]>0&&B[i]>0) { pos[{x, y}]++; }
			else if (A[i] < 0 && B[i] < 0) { pos[{x, y}]++; }
			else { neg[{x, y}]++; }
		}
	}

	mint ans = 1;
	ans *= ((mint)2 ^ xzero) + ((mint)2 ^ yzero) - 1;
	for (auto p : pos) {
		ll x = p.first.first;
		ll y = p.first.second;

		if (neg.count({ y,x }))ans *= ((mint)2 ^ pos[{x, y}]) + ((mint)2 ^ neg[{y, x}]) - 1;
		else { ans *= (mint)2 ^ pos[{x, y}]; }
	}

	for (auto p : neg) {
		ll x = p.first.first;
		ll y = p.first.second;

		if (!pos.count({ y,x }))ans *= (mint)2 ^ neg[{x, y}];
	}

	ans += zero - 1;
	cout << ans << endl;
}


Measured memory_bytes: 18820
import java.util.Scanner;
//AGC030A
//Main
public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt(); //解毒NOTおいC
		int B = sc.nextInt(); //解毒おいC
		int C = sc.nextInt(); //毒入りおいC
		int ans = 0;
		int cure =  A + B;

		if(C <= cure) {
			ans = B + C;
		}else {
			ans = cure + B +1;
		}
		System.out.println(ans);

	}
}



Measured memory_bytes: 21844
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        decimal[] key = new decimal[] { 0.25m, 0.5m, 1, 2 };
        for (int i = 0; i < key.Length; i++) {
            Price.Add(key[i], inpt[i]);
            Value.Add(key[i], inpt[i]/key[i]);
        }

        long ans = 0;
        long val = long.Parse(Reader.ReadLine());
        if (val > 2 && val % 2 > 0 && Value.OrderBy(a => a.Value).First().Key == 2m)
        {
            ans = val / 2 * Price[2];
            val = val % 2;
        }
    	decimal p = Value.Where(a => val % a.Key == 0m).OrderBy(a => a.Value).First().Key;
		ans += (long)(val / p * Price[p]);
		Console.WriteLine(ans);
	}



    private Dictionary<decimal, int> Price = new Dictionary<decimal, int>();
    private Dictionary<decimal, decimal> Value = new Dictionary<decimal, decimal>();




    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"

100 100 100 100
3


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


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

int main(){
int n;
  cin>>n;
vector<int> w(n);
  for(int i=0;i<n;i++){
  cin>>w[i];
  }
  int s1=0,s2=0;
  int m=1e9;
  for(int t=0;t<n;t++){
    for(int k=0;k<=t;k++)s1+=w[k];
      for(int k=n-1;k>t;k--)s2+=w[k];
    m=min(abs(s1-s2),m);
    s1=0;s2=0;
  }
  cout<<m;
return 0;
}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define MOD1 1000000007
#define MOD2 998244353


int main()
{

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

	IOS

	ll n;
	cin >> n;
	ll map[100005] = {0};
	ll sum = 0;
	for(ll i=0; i<n; i++){
		ll temp;
		cin >>temp;
		sum += temp;
		map[temp]++;
	}


	ll q;
	cin >> q;

	while(q--){
		long long a,b;
		cin >> a >> b;
		sum = sum + map[a]*(b-a);
		map[b] += map[a]; 
		map[a] = 0;
		cout << sum << endl;
	}
}

Measured memory_bytes: 4356
N = input()
A = map(str, raw_input().split())
B = A[:]
for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            A[j], A[j-1] = A[j-1], A[j]
bubble = " ".join(A)
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[minj][1]):
            minj = j
    B[i], B[minj] = B[minj], B[i]
select = " ".join(B)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable"

Measured memory_bytes: 6472
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <bitset>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

// a と b の最大公約数を返す関数
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

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

    
  cout << abs(N-1) << endl;

}

Measured memory_bytes: 3556
import sys
input = lambda: sys.stdin.readline().rstrip()

def calc(a, b):
    if b == 0: return a
    if a == R: return b + R
    if b == C: return R + C + (R - a)
    if a == 0: return R + C + R + (C - b)

R, C, N = map(int, input().split())
A = []
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    if (x1 == 0 or x1 == R or y1 == 0 or y1 == C) and (x2 == 0 or x2 == R or y2 == 0 or y2 == C):
        A.append((calc(x1, y1), i))
        A.append((calc(x2, y2), i))

A = [l[1] for l in sorted(A, key = lambda x: x[0])]
B = []

while A:
    while len(B) and A[-1] == B[-1]:
        A.pop()
        B.pop()
    if A:
        B.append(A.pop())

print("NO" if len(B) else "YES")

Measured memory_bytes: 31884
#include <iostream>
#include <cmath>

using namespace std;

int l[10];
int N;
int A, B, C;

#define INF 100000000

int search(int a, int b, int c, int mp, int i)
{
  if (i >= N) {
    if (a == 0 || b == 0 || c == 0) {
      return INF;
    }
    return mp + abs(A - a) + abs(B - b) + abs(C - c);
  }

  int x = search(a + l[i], b, c, mp + 10, i + 1);
  int y = search(a, b + l[i], c, mp + 10, i + 1);
  int z = search(a, b, c + l[i], mp + 10, i + 1);
  int w = search(a, b, c, mp, i + 1);

  return min({x, y, z, w});
}


int main()
{
  cin >> N >> A >> B >> C;

  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }

  int result = search(0, 0, 0, -30, 0);
  cout << result << endl;
  return 0;
}

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


int main() {
  string S;
  cin >> S;
  if(S.at(0)=='R'){
    if(S.at(1)=='R'){
      if(S.at(2)=='R'){
        cout << 3 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
    else{
     cout << 1 << endl;
    }
  }
  else{
    if(S.at(1)=='R'){
      if(S.at(2)=='R'){
        cout << 2 << endl;
      }
      else{
        cout << 1 << endl;
      }
    }
    else{
      if(S.at(2)=='R'){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }
    }
  }
}

Measured memory_bytes: 3596
local n = io.read("*n")
n = n * 100
f = false
for i = 1, 50000 do
  local cand = i * 108
  cand = cand - (cand % 100)
  if cand == n then
    print(i)
    f = true
    break
  end
end
if not f then
  print(":(")
end


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>


using namespace std;


int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cout<<"Case "<<i+1<<":"<<endl;
        int s;
        cin>>s;
        for(int j=0; j<10; j++){
            s=s*s;
            s/=100;
            s=s%10000;
            cout<<s<<endl;
        }

    }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int H,A; cin>>H>>A;
  cout<<H/A+min(1,H%A)<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int D = scanner.nextInt();
		    int X = scanner.nextInt();
		    int[] A = new int[N];
		    for(int i = 0; i < N; i++) 
		    {
		    	A[i] = scanner.nextInt();
		    }
		    
		    for(int i = 0; i < N; i++) 
		    {
		    	X = X + (D-1)/A[i] + 1;
		    }
		    System.out.println(X);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i,n)rep(j,n)rep(k,n) ans += gcd(i,gcd(j,k));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int a;
    int b;
  int c;
  int d;
 
   cin >> a >> b >> c >> d;
  
   int e = a - b;
  
  if (e < 0){
     int f = a*c;

    cout << f << endl;
  }else {
  
    int f = b*c+e*d;

    cout << f << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x,i;
 
	i=1;
	 
	scanf("%d", &x);
	
	while(x != 0){
	printf("Case %d: %d\n",i, x);
	i++;
    scanf("%d", &x);
	}

	return 0;
}

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

li range_sum(li init, li delta, li count) {
    return (init + init + delta * (count - 1)) * count / 2;
}

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

    li n, x, d;
    cin >> n >> x >> d;

    if (d == 0) {
        if (x == 0) {
            cout << 1 << endl;
            return 0;
        } else {
            cout << n + 1 << endl;
            return 0;
        }
    }

    if (d < 0) {
        x *= -1;
        d *= -1;
    }

    li _g = abs(__gcd(x, d));
    x /= _g;
    d /= _g;

    map<li, vector<pair<li, li>>> mod_ranges;
    for (int count = 0; count <= n; ++count) {
        li lower_bound = range_sum(x, d, count);
        li upper_bound = range_sum(x + d * (n - 1), -d, count) + d;
        if (lower_bound > upper_bound) {
            swap(lower_bound, upper_bound);
        }
        li mod = (lower_bound % d + d) % d;
        mod_ranges[mod].emplace_back(lower_bound, upper_bound);
    }

    li ans = 0;
    for (auto it : mod_ranges) {
        vector<pair<li, li>> ranges = it.second;
        sort(ranges.begin(), ranges.end());
        li begin = -(1LL << 60);
        li end = begin;
        for (auto range : ranges) {
            li fr = range.first;
            li to = range.second;
            if (fr > end) {
                ans += (end - begin) / d;
                begin = fr;
                end = to;
            } else {
                begin = min(fr, begin);
                end = max(to, end);
            }
        }
        ans += (end - begin) / d;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 22144
n = int(input())
p_ = input().split(" ")


def compare(p, i):
    if p[i-1] < p[i] & p[i] < p[i+1]:
        return True
    if p[i-1] > p[i] & p[i] > p[i + 1]:
        return True
    return False
dic = {}
p = []

for i in range(n):
    p.append( int(p_[i]))

count=0
for i in range(1,n-1):
  res = compare(p,i)
  if res:
    count+=1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,x,y,t;
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>t>>x>>y;
		if(x+y>t||(t-x-y)%2) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  ll n,m;
  cin>>n>>m;
  if(n>=m/2){cout<<m/2<<endl;}
  else cout<<n+(m/2-n)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
#define M 1000000007
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    int k,a,b,flag=0;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0){flag=1;break;}
    }  
    if(flag)
    {
        cout<<"OK";
    }else
    {
         cout<<"NG";
    }cout<<"\n";
    

}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=s.size()-1;i>=0;i--){
		cout<<s[i];
	}
	cout<<endl;
    return 0;
}

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

using namespace std;

int n;
int a[10010],b[10010];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	for(int i=1;i<=n;i++){
		scanf("%d",b+i);
		a[i]-=b[i];
	}

	sort(a+1,a+n+1);

	int lst=n;
	for(int i=1;i<=n;i++){
		if(a[i]>=0||a[lst]<=0)break;

		int temp=abs(a[i])/2;
		a[i]+=temp*2;

		while(a[lst]>0&&a[lst]<=temp){
			temp-=a[lst];
			a[lst]=0;
			lst--;
		}
		if(temp&&a[lst]>0)
			a[lst]-=temp;
	}

	for(int i=1;i<=n;i++)
		if(a[i]>0){
			puts("No");
			return 0;
		}
	puts("Yes");

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c;
    char d,e;
  	cin>>a>>b;
  //if(a==||a==5||a==3)
    cout<<a+b/2<<endl;
 // else 
  //  cout<<"NO"<<endl;
 /* else if(a==23)
    cout<<"Christmas Eve Eve"<<endl;
  else
    cout<<"Christmas Eve Eve Eve"<<endl;
  */
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll H, W, K;
    ll mod = 1e9 + 7;
    cin >> H >> W >> K;
    vector<int> dummy_dp(8, 0);
    dummy_dp[0] = dummy_dp[1] = 1;
    for(int i = 2; i < 8; i++)
        dummy_dp[i] = dummy_dp[i-1] + dummy_dp[i-2];
    vector<ll> dp(W+1, 0);
    dp[1] = 1;
    for(int h = 0; h < H; h++) {
        vector<ll> new_dp(W+1, 0);
        for(int i = 1; i <= W; i++) {
            new_dp[i] += dp[i] * (dummy_dp[i-1]) * (dummy_dp[W-i]);
            new_dp[i] %= mod;
            if (i-1 > 0) { // from left
                new_dp[i] += dp[i-1] * (dummy_dp[i-1-1]) * (dummy_dp[W-i]);
                new_dp[i] %= mod;
            }
            if (i+1 <= W) { // from right
                new_dp[i] += dp[i+1] * (dummy_dp[i-1]) * (dummy_dp[W-i-1]);
                new_dp[i] %= mod;
            }
        }
        dp.swap(new_dp);
    }
    cout << dp[K] << endl;
    return 0;
}




Measured memory_bytes: 256
symbols = []
done = false
flg = true
while line=gets
  line.chomp!
  if line == "." then break end
  line.each_char do |c|
    case c
    when '(', '['
      symbols << c
    when ')'
      flg = false if symbols.pop != '('
    when ']'
      flg = false if symbols.pop != '['
    when '.'
      done = true
      break
    end
  end
  flg = false unless symbols.empty?
  if done
    puts flg ? 'yes' : 'no'
    flg = true
    done = false
    symbols = []
  end
end

Measured memory_bytes: 8832
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>
#include <set>

using namespace std;

int N, M, X;
vector<vector<int>> book_info;

int min_result = 1e9;

void process(int depth, int last, vector<int> score, int price)
{
	bool check = true;
	for (auto e : score)
	{
		if (e < X)
		{
			check = false;
			break;
		}
	}

	if (check)
	{
		min_result = min(min_result, price);
		return;
	}

	if (depth == N)
	{
		return;
	}

	for (int i = last + 1; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			score[j] += book_info[i][j + 1];
		}
		process(depth + 1, i, score, price + book_info[i][0]);
		for (int j = 0; j < M; j++)
		{
			score[j] -= book_info[i][j + 1];
		}
	}
}

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

	cin >> N >> M >> X;

	book_info.assign(N, vector<int>(M + 1, 0));

	for (int i = 0; i < N; i++)
	{
		cin >> book_info[i][0];
		for (int j = 0; j < M; j++)
		{
			cin >> book_info[i][j + 1];
		}
	}

	process(0, -1, vector<int>(M, 0), 0);

	if (min_result == 1e9)
	{
		cout << -1;
	}
	else
	{
		cout << min_result;
	}

	return 0;
}

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

const int maxn = 1e6+6, M = 1e9+7;
int fac[maxn], ifac[maxn];
int mult(int a, int b) {
    return (1LL*a*b) % M;
}
int modexp(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b&1) res = mult(res,a);
        a = mult(a,a);
        b >>= 1;
    }
    return res;
}

int comb(int n, int r) {
    return mult(fac[n],mult(ifac[r],ifac[n-r]));
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x, y; cin >> x >> y;
    fac[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fac[i] = mult(fac[i-1],i);
    }
    for (int i = 0; i < maxn; i++) {
        ifac[i] = modexp(fac[i],M-2);
    }
    if ((2*x-y) < 0 || (2*x-y) % 3 != 0) {
        cout << 0 << '\n';
    }
    else {
        int b = (2*x-y)/3;
        int a = x-2*b;
        if (a >= 0 && b >= 0) {
            cout << comb(a+b,a) << '\n';
        }
        else {
            cout << 0 << '\n';
        }
    }
}



Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m, x;
	cin >> n >> m >> x;
	
	vector<int> c(n);
	vector< vector<int> > a(n);
	
	for(int i = 0; i < n; ++i) {
		cin >> c[i];
		a[i].resize(m);
		
		for(int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}
	
	ll ans = 1e18;
	for(int bits = 0; bits < (1 << n); ++bits) {
		bool yes = true;
		vector<ll> choice;
		
		for(int i = 0; i < n; ++i) {
			if( bits & (1 << i) ) {
				choice.push_back(i);
			}
		}
		
		vector<ll> sum(m, 0LL);
		ll cost = 0LL;
			
		for(int j : choice) {
			for(int k = 0; k < m; ++k) {
				sum[k] += a[j][k];
			}
				
			cost += c[j];
		}
			
		for(int k = 0; k < m; ++k) {
			if( sum[k] < x ) yes = false;
		}
		
		if( yes ) ans = min(ans, cost);
	}
	
	if( ans >= 1e10 ) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
 

string s;
int ans;

main () {
	cin >> s;
	forn (i, 0, sz(s) / 2 - 1)
		if (s[i] != s[sz(s) - 1 - i])
			++ans;
	cout << ans << endl;
} 

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

int main() {
  char C;
  cin >> C;
  
  if (C == 'a' || C == 'i' || C == 'u' || C == 'e' || C == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    double N, K; cin >> N >> K;
    double ans = 0;
    for(int i = 1; i < N + 1; i++) {
        int cnt = 0;
        int tmp = i;
        while(tmp < K) {
            cnt++;
            tmp *= 2;
        }
        ans += 1/N * pow(0.5, cnt);
    }
     cout << fixed << setprecision(10) << ans << endl;
}

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

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  if (n % 2 == 1) {
    cout << "No" << endl;
  } else {
    string s1 = s.substr(0, n / 2);
    string s2 = s.substr(n / 2);
    if (s1 == s2) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int total1 = N * A;
        int total2 = B;
        if(total1 < total2){
            System.out.println(total1);
        }else{
            System.out.println(total2);
        }
    }
}


Measured memory_bytes: 35700
#include <iostream>

int main() {
    int n = 0;
    std::cin >> n;
    if (n % 4 == 0 || n % 7 == 0) {
        std::cout << "Yes" << std::endl;
        return 0;
    }
    for (int i = 0; i < n / 7; i++) {
        n = n - 7;
        if (n % 4 == 0) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int a[110];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",a+i);
	int ans=0;
	rep(i,0,n)rep(j,i+1,n)rep(k,j+1,n){
		if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]
		   &&a[i]+a[j]>a[k]
		   &&a[j]+a[k]>a[i]
		   &&a[k]+a[i]>a[j])ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1728
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a <= k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <bitset>
#include <random>


bool match_left(int shift, const std::string& left, const std::string& right) {
	for (auto i = 0; i + shift < left.size() && i < right.size(); ++i) {
		if (left[i + shift] != '?' && right[i] != '?' && left[i + shift] != right[i]) {
			return false;
		}
	}
	return true;
}
bool match_str(int shift, const std::string& a, const std::string& b) {
	if (shift < 0) return match_left(-shift, a, b);
	else return match_left(shift, b, a);
}

int main() {
	std::vector<std::string> str(3);
	for (auto& s : str) std::cin >> s;
	std::vector<std::vector<std::unordered_set<int>>> diff(3, std::vector<std::unordered_set<int>>(3));
	for (auto i = 0; i < 3; ++i) {
		for (auto j = i + 1; j < 3; ++j) {
			diff[i][j].insert(-(int)str[i].size()); 
			diff[i][j].insert(str[j].size());
			diff[j][i].insert(-(int)str[j].size());
			diff[j][i].insert(str[i].size());
			for (int k = 1 - (int)str[i].size(); k < (int)str[j].size(); ++k) {
				//std::cout << k << std::endl;
				if (match_str(k, str[i], str[j])) {
					diff[i][j].insert(k);
					diff[j][i].insert(-k);
				}
			}
		}
	}
	int min = INT_MAX;
	std::vector<int> perm(3); std::iota(perm.begin(), perm.end(), 0);
	for (auto i = 0; i < 6; ++i) {
		const auto a = perm[0];
		const auto b = perm[1];
		const auto c = perm[2];
		for (const auto d : diff[a][b]) {
			for (const auto e : diff[b][c]) {
				if (d + e <= -(int)str[a].size()) {
					int left = std::min({ 0, d + e, e });
					int right = std::max<int>({ (int)str[c].size(), d + e + (int)str[a].size(), e + (int)str[b].size() });
					if (min > right - left) {
						min = right - left;
					}
				}
				else if ((int)str[c].size() <= d + e) {
					int left = std::min({ 0, d + e, e });
					int right = std::max<int>({ (int)str[c].size(), d + e + (int)str[a].size(), e + (int)str[b].size() });
					if (min > right - left) {
						min = right - left;
					}
				}
				else if (diff[a][c].find(d + e) != diff[a][c].end()) {
					int left = std::min({ 0, d + e, e });
					int right = std::max<int>({ (int)str[c].size(), d + e + (int)str[a].size(), e + (int)str[b].size() });
					if (min > right - left) {
						min = right - left;
					}
				}
			}
		}
		std::next_permutation(perm.begin(), perm.end());
	}
	std::cout << min << std::endl;
}

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


void solve(long long X){
    long long fiveHundredCount = X/500;
    long long fiveCount = (X-500*fiveHundredCount)/5;
    cout << 1000*fiveHundredCount+5*fiveCount << endl;

}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cnt = 0;
		for(int i = a; i <= b; i++) {
			int fi = i / 10000;
			int on = i % 10;
			int fo = i / 1000 % 10;
			int tw = i % 100 / 10 ;  
			if(fi == on && fo == tw) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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

int result(int a[], int n) 
{ 
    int sum = 0; 
    for (int i = 0; i < n; i++) 
        sum = sum + a[i]; 

    int array_sq_sum = sum * sum; 
  
    int sq_sum = 0; 
    for (int i = 0; i < n; i++) 
        sq_sum += a[i]*a[i]; 

    return (array_sq_sum - sq_sum)/2; 
}

int main(){
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int res = result(a,n);
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static public void main(String args[]){
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a>b){
			System.out.println("a > b");
		} else if(a<b){
			System.out.println("a < b");
		} else {
			System.out.println("a == b");
		}
	}
}

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

int main(){
  long long a,b,x;
  long long count=0;
  cin >> a >> b >> x;
  
  long long tmp1,tmp2;
  tmp1 = (b/x)+1;
  tmp2 = ((a-1)/x)+1;
  if(a==0) tmp2 = 0;
  count = tmp1 - tmp2;
  
  cout << count << endl;
}

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

map<string, ll> dp[105];
ll MOD = pow(10,9)+7;

bool ok(string s){
  for(int i=0;i<s.size();i++){
    string t="";
    for(int j=0;j<s.size();j++){
      if(i!=j)t+=s[j];
    }
    if(t=="AGC")return false;
  }
  if(s.substr(0,3)=="AGC" || s.substr(0,3)=="GAC" || s.substr(0,3)=="ACG")return false;
  if(s.substr(1,3)=="AGC" || s.substr(1,3)=="GAC" || s.substr(1,3)=="ACG")return false;
  return true;
}

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n;cin>>n;
  string dna="AGCT";
  dp[0][""]=1;
  for(int i=0;i<3;i++){
    for(int j=0;j<4;j++){
      for(auto &kv : dp[i]) {
        string nx = kv.first + dna[j];
        if(nx!="AGC" && nx!="GAC" && nx!="ACG") dp[i+1][nx]+=dp[i][kv.first];
      }
    }
  }
  for(int i=3;i<n;i++){
    for(int j=0;j<4;j++){
      for(auto &kv : dp[i]){
        string nx = kv.first + dna[j];
        if(ok(nx)){
          dp[i+1][nx.substr(1, 3)] += dp[i][kv.first];
          dp[i+1][nx.substr(1, 3)] %= MOD;
        }
      }
    }
  }
  ll ans=0;
  for(auto &kv : dp[n]){
    if(kv.first!="AGC" && kv.first!="GAC" && kv.first!="ACG") ans+=kv.second;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4024
import collections

n = int(input())
A = list(map(int, input().split()))
B = collections.deque(maxlen=n)
for i in range(n):
    if i % 2 == 0:
        B.append(A[i])
    else:
        B.appendleft(A[i])

B = list(B) if n % 2 == 0 else list(B)[::-1]
print(' '.join(map(str, B)))


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

g = []
if n%2==1:
    g.append([n])
    for i in range(1,n//2+1):
        g.append([i,n-i])
else:
    for i in range(1,n//2+1):
        g.append([i,n-i+1])

res = set()
for i in range(len(g)):
    for j in range(len(g)):
        if i==j:
            continue
        for v in g[i]:
            for u in g[j]:
                res.add((min(v,u),max(v,u)))
print(len(res))
for v,u in res:
    print(v,u)

Measured memory_bytes: 4028
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	int sum = accumulate(all(a), 0LL);
	int t = 0;
	int ans = INF;
	rep(i, 0, N) {
		int x = t, y = sum - x;
		if (i != 0) {
			chmin(ans, abs(x - y));
			dump(x, y, abs(x - y));
		}
		t += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
/*
さいころ

mapを使っているところは普通のサイコロとかなら配列で大丈夫
まぁ、せいぜいO(log24)なのでOKか

参考:
http://www.prefield.com/algorithm/misc/dice.html
*/
#include <bits/stdc++.h>
using namespace std;

//up(上),down(下),front(前),back(後ろ),right(右),left(左)
enum FACE{UP,DOWN,FRONT,BACK,RIGHT,LEFT};
template<typename T>
struct Dice{
    T var[6];
    map<pair<T,T>,int> M;
    vector<Dice> V;
    T& operator[](FACE f){return var[f];}
    Dice operator[](int idx){return V[idx];};
    Dice find(T up,T front){return V[ M[{up,front}] ];}
    int id(){return M[{var[FRONT],var[UP]}];}

    void rollR(){roll(UP,LEFT,DOWN,RIGHT);}
    void rollL(){roll(UP,RIGHT,DOWN,LEFT);}
    void rollU(){roll(UP,FRONT,DOWN,BACK);}
    void rollD(){roll(UP,BACK,DOWN,FRONT);}
    void rollT(){roll(FRONT,RIGHT,BACK,LEFT);}
    void rollH(){roll(FRONT,LEFT,BACK,RIGHT);}
    void roll(FACE a,FACE b,FACE c,FACE d){
        int tmp=var[a];
        var[a]=var[b];
        var[b]=var[c];
        var[c]=var[d];
        var[d]=tmp;
    }

    void allDice(){
        int cnt=0;
        V.resize(24);
        Dice d=*this;
        for(int k=0;k<6;(k&1?d.rollR():d.rollD()),k++){
            for(int i=0;i<4;d.rollT(),i++,cnt++){
                V[cnt]=d;
                M[{d[UP],d[FRONT]}]=cnt;
            }
        }
    }
    bool operator==(const Dice &d)const noexcept{
        for(int i=0;i<6;i++){
            if(var[i]!=d.var[i]) return false;
        }
        return true;
    }

};

signed main(){
    int N;
    cin>>N;
    vector<Dice<int>> V(N);
    for(int i=0;i<N;i++){
        cin>>V[i][UP]>>V[i][FRONT]>>V[i][RIGHT]>>V[i][LEFT]>>V[i][BACK]>>V[i][DOWN];
        V[i].allDice();
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=0;k<24;k++){
                if(V[i]==V[j].V[k]){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 8936
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int count=0;
  while(b<a || b==a){
    b*=2;
  count++;
  }
  while(c<b || c==b){
    c*=2;
    count++;
  }
  if(count<=k){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3620
import java.io.IOException;
import java.util.Scanner;

class Main {
	static final int INF = 1000000001;

	static long changecount = 0;
   public static void main(String args[]) throws IOException{

      Scanner sc = new Scanner(System.in);

	   int n = Integer.parseInt( sc.next()  );

	   int[] A = new int[n];

	   for(int i = 0;i < n; i++){

		   A[i] = Integer.parseInt(sc.next());
	   }

	    bubleSort(A, 0, n);


	   //System.out.println();
	   System.out.println(changecount);
	   sc.close();
   }



   public static void buble( int[] A, int left, int mid ,int right){

	   int n1 = mid - left;
	   int n2 = right - mid;
       int[] L = new int[n1+1];
       int[] R = new int[n2+1];


	   for(int i = 0; i < n1;i++ ){
		   L[i] = A[left + i];

	   }

	   for(int i = 0; i < n2;i++ ){
		   R[i] = A[mid + i];

	   }

	   L[n1] =  INF;
	   R[n2] =  INF;

	   int i = 0;
	   int j = 0;

	   for(int k = left; k < right; k++ ){

		   if(L[i] <= R[j]){
			   A[k] = L[i];
			      i = i + 1;
			      changecount+=j;
		   }else{
			   A[k] = R[j];
			      j = j + 1;

		   }

	   }


   }


   public static void bubleSort(int[] A, int left, int right){


	   if(left+1 < right){
		    int mid = (left + right)/2;
		    bubleSort(A, left, mid);
		    bubleSort(A, mid, right);
		   buble(A, left, mid, right);

	   }



   }
}

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

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    total_money = int(input())
    one_yen_count = int(input())

    balance = total_money % 500

    if one_yen_count - balance >= 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    ll N;cin >> N;
    vector<ll> A(N);
    ll ans=0;
    rep(i,N){
        cin >> A[i];
        while(A[i]%2 == 0){
            A[i] /= 2;
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int n;
  cin>>n;
  int d[55];
  rep(i,n) cin>>d[i];
  int ans=0;
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      ans+=d[i]*d[j];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

x = [0,0,0,0,0,0,0,0,0,0,0]
y = [0,0,0,0,0,0,0,0,0,0,0]
f = [0,0,0,0,0,0,0,0,0,0,0]

def distance(x1, y1, x2, y2):
	ff = float((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
	return math.sqrt(ff)

total = 0
num = 0

def dfs(now, pre, dis):
	global total 
	global num

	if (now == n+1):
		total += dis
		num += 1
		return 
	if (now == 1):
		for i in range(1, n+1):
			f[i] = 1
			dfs(now+1, i, dis)
			f[i] = 0
	else:		
		for i in range(1, n+1):
			if f[i] == 0:
				f[i] = 1
				dfs(now+1, i, dis+distance(x[pre], y[pre], x[i], y[i]))
				f[i] = 0




for i in range(1, n+1):
	x[i], y[i] = map(int, input().split())

# print(x)
# print(y)

dfs(1, 0, 0)
# print(total)
# print(num)
print(round(total/num, 10))

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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 3007
#define DIMM 100007
#define INF 1000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll ns,nt;
ll i,j,rc;
str s,t;
cr res[DIM];
ll dp[DIM][DIM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>s>>t;
    ns=s.length();
    nt=t.length();
    for(int i=1;i<=ns;i++){
     for(int j=1;j<=nt;j++){
      if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
     }
    }
    i=ns;j=nt;
    while(i!=0 && j!=0){
     if(s[i-1]==t[j-1]){
      rc++;
      res[rc]=s[i-1];
      i--;j--;
     }
     else{
      if(dp[i-1][j]>=dp[i][j-1])i--;
      else j--;
     }
    }
    for(int i=rc;i>=1;i--)cout<<res[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 70784