akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

ll x, y, z;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> x >> y >> z;
	
	cout << ((x + y - 1) / y * z) << endl;
	
	return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		int max = 0;
		int maxI = 0;

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
			if (max < a[i]) {
				max = a[i];
				maxI = i;
			}
		}

		int ans = 0;

		for (int i = 0; i < n; i++) {
			if (i == maxI) {
				ans += a[i] / 2;
			} else {
				ans += a[i];
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21076
def solver():
    N = int(input())
    S = list(input())
    res = 0
    for xxx in range(0, 1000):
        xxx = str(xxx)
        xxx = xxx.zfill(3)
        xxx = list(xxx)
        
        c = 0
        for s in S:
            if xxx[c]==s:
                c += 1
                if c==3:
                    res += 1
                    break
    return res

ans = solver()
print(ans)

Measured memory_bytes: 3316
int main(void)
{
	int a,b,d,r,n;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	
	return 0;
}



Measured memory_bytes: 2036
N = int(input())
S = list(str(input()))

l = [chr(ord('A')+i) for i in range(26)]
p = []
for t in range(len(S)):
    for i in range(26):
        if S[t] == l[i]:
            k = (i+N)%26
            p.append(l[k])
print(''.join(map(str,p)))

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

using namespace std;

typedef long long int LL;
typedef unsigned long long int ULL;
typedef pair<int, int> PII;
typedef map<int, int> MII;

const int SZ = 212345;
const int MOD = 1e9 + 7;

int n, k, a[SZ];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int m = n - k;
  LL s = 0;
  for (int i = 0; i < m; i++) {
    s += a[i];
  }
  cout << s << endl;
  return 0;
}


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

 using namespace std;

 int main() {
   int N;
   string s, t;
   cin >> N >> s >> t;

   int ans;
   bool finished = false;

   for (int i = 0; i < N; i++) {
     if (s.substr(i, N - i) == t.substr(0, N - i)) {
       ans = i + N;
       finished = true;
       break;
     }
   }

   if (!finished) ans = 2 * N;

   cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,x,t; cin >> n >> x >> t;
    int k = (n+x-1)/x;
    int ans = k*t;
    cout << ans << endl;
}



Measured memory_bytes: 3588
#include <stdio.h>
#include <iostream>

int main() {
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			std::cout << i << "x" << j << "=" << (i * j) << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3064
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    V<int> v(3);
    for(int &e : v) cin >> e;
    sort(ALL(v));
    cout << v[0] + v[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;

  if(c-(a-b)>0) cout << c-(a-b) << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
n = int(input())
pre_t,pre_x,pre_y=0, 0, 0
for i in range(n):
    t, x, y = map(int, input().split())
    d_t = t-pre_t
    d_x = abs(x-pre_x)
    d_y = abs(y-pre_y)
    if d_x + d_y > d_t or (d_x + d_y + d_t) % 2:
        print("No")
        quit()
    pre_t,pre_x,pre_y=t, x, y
print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INTXT std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
#define INF 1e9

using namespace std;
typedef long long ll;
static const ll MOD = 1000000007LL;

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

  vector<int> vals(n);
  REP(i, n){
    cin >> vals.at(i);
  }

  vector<int> costs(n);
  REP(i, n){
    cin >> costs.at(i);
  }

  int ans = 0;
  REP(i, n){
    ans += max(vals.at(i) - costs.at(i), 0);
  }
  
  cout << ans << endl;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);                             
  int n;
  cin >> n;
  vector<int> foo(n), bar(n);
  for (int i = 0; i < n; i++) {
    cin >> foo[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> bar[i];
  }
  int x, y;
  x = y = 0;
  for (int i = 0; i < n; i++) {
    if (foo[i] > bar[i]) {
      x += foo[i], y += bar[i];
    }
  }
  cout << x - y << '\n';
  return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, K; cin >> N >> K;
    ll A[N]; rep(i, N) cin >> A[i];
    ll bitcnt[40] = {};
    rep(i, 40){
        rep(j, N){
            if((A[j] >> i) & 1) bitcnt[i]++;
        }
    }
    int top_bit = -1; //Kの立っている最上位ビット
    rep(i, 40) if((K >> i) & 1) top_bit = i;
    if(top_bit == -1){
        ll ans = 0; rep(i, N) ans += A[i]; cout << ans << endl;
    }
    else{
        int keta_of_K[40]; rep(i, 40) keta_of_K[i] = (K >> i) & 1;
        ll dp[40][2];
        rep(i, 40) rep(j, 2) dp[i][j] = 0;
        dp[top_bit][0] = (1ll << top_bit) * (N - bitcnt[top_bit]);
        dp[top_bit][1] = (1ll << top_bit) * bitcnt[top_bit];
        for(int i = top_bit; i > 0; i--){
            for(int smaller = 0; smaller <= 1; smaller++){
                for(int d = 0; d <= (smaller ? 1 : keta_of_K[i-1]); d++){
                    int to = smaller || d < keta_of_K[i-1];
                    int val;
                    if(d == 0) val = bitcnt[i-1];
                    else val = N - bitcnt[i-1];
                    dp[i-1][to] = max(dp[i-1][to], dp[i][smaller] + (1ll << (i-1)) * val);
                }
            }
        }
        //ここまででKの最上位ビット以下はわかった
        ll ans = max(dp[0][0], dp[0][1]);
        //Kの最上位ビットより上のビットを足しに行く
        for(int i = top_bit+1; i < 40; i++){
            ans += (1ll << i) * bitcnt[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);
    zip(A, B).sort();
    long ans;
    long i;
    while (0 < M)
    {
        long cnt = min(M, B[i]);
        ans += A[i] * cnt;
        M -= cnt;
        i++;
    }
    writeln(ans);
}


Measured memory_bytes: 4860
ABCK = [int(x) for x in input().split()]
A=ABCK[0]
B=ABCK[1]
C=ABCK[2]
K=ABCK[3]

n=0

if K<=A:
  n=K
elif K<=A+B:
  n=A
elif K<=A+B+C:
  n=A-(K-A-B)
  
print(n)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  vector<int> nums;
  cin >> n;
  for(int i=0; i<n; i++){
      int temp;
      cin >> temp;
      nums.push_back(temp);
  }

  int max = -1;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if( i != j && nums.at(i) - nums.at(j) > max ){
        max = nums.at(i) - nums.at(j);
      }
    }
  }

  cout << max;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    cin >> N;
}

int solve(){
    N %= 1000;
    if(N==0) cout << 0 << endl;
    else cout << (1000-N) << endl;
    return 0;
}   

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

Measured memory_bytes: 3664
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[1000][3],size;

void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		if(s<3 && x<8 && a[x+2][y]>0)return 0;
		if(check(x,y,s)>0){
			draw(x,y,s,-1);
			if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1);return 0;}
			if(nn>1){
				if(search(nn-1,i-1)>0){printf("%d %d %d\n",y,x,s);return 1;}
			}else{
				int p,q;
				for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
				printf("%d %d %d\n",y,x,s);return 1;miss:;
			}
			draw(x,y,s,+1);
		}
	}
	return 0;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; else for(;x>0;x--)push(i,j,1);
			x=check(i,j,2); if(x==0)continue; else for(;x>0;x--)push(i,j,2);
			x=check(i,j,3); if(x==0)continue; else for(;x>0;x--)push(i,j,3);
		}
	}
	//for(i=0;i<size;i++)printf("%d %d %d\n",list[i][0],list[i][1],list[i][2]);
	/*
	if(size>80){
	fprintf(stderr,"%3d\n",n);
	for(i=0;i<10;i++){for(j=0;j<10;j++){fprintf(stderr,"%3d",a[i][j]);}fprintf(stderr,"\n");}fprintf(stderr,"\n");
	assert(0);
	}*/
	search(n,size-1);
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, k, s;
    cin >> n >> k >> s;
    if (n == k) {
        rep(i, n) printf("%lld%s", s, (i == (n - 1)) ? "\n" : " ");
    }
    else if (s == 1) {
        rep(i, k) printf("%lld%s", 1, (i == (n - 1)) ? "\n" : " ");
        reps(i, k, n) printf("%lld%s", 10, (i == (n - 1)) ? "\n" : " ");
    }
    else {
        rep(i, k + 1) {
            ll val = 0;
            if (i % 2 == 0) val = ((s + 1) / 2);
            else val = (s / 2);
            printf("%lld%s", val, (i == (n - 1)) ? "\n" : " ");
        }
        reps(i, k + 1, n) {
            printf("%lld%s", s / 2 + 10, (i == (n - 1)) ? "\n" : " ");
        }
    }
    return 0;
}


Measured memory_bytes: 1280
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String a = saori.nextHayami();
		String b = saori.nextHayami();
		if(a.equals("H") && b.equals("H")){
			System.out.println("H");
		}
		if(a.equals("H") && b.equals("D")){
			System.out.println("D");
		}
		if(a.equals("D") && b.equals("H")){
			System.out.println("D");
		}
		if(a.equals("D") && b.equals("D")){
			System.out.println("H");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <iomanip>
#include <queue>
#include <deque>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

ll modpow (ll a, ll b) {
	ll ans = 1;
	for(int i = 0; i < b; i++) {
		ans*= a;
		ans = ans%MOD;
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<char> row1 (n);
	vector<char> row2 (n);
	vector<bool> exists(500,false);
	for(int i = 0; i < n; i++) {
		cin >> row1[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> row2[i];
	}

	//RG    RB 	  RB
	//BR	BG	  BR

	//3
	ll ways = 1;
	for(int i = 0; i < n; i++) {
		if(row1[i] == row2[i]) {
			if(i == 0) {
				ways*= 3;
			} else if(row1[i-1] == row2[i-1]) {
				ways*= 2;
			}
		} else {
			if(i == 0) {
				ways*= 3*2;
			} else if (row1[i-1] == row2[i-1]) {
				ways*= 2;
			} else {
				ways*= 3;
			}
			i++;
		}
		ways = ways%MOD;
	}
	cout << ways;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,X,Y,x[100],y[100],i;
  scanf("%d%d%d%d",&n,&m,&X,&Y);
  int max=X,min=Y;
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    if(max<x[i]) max=x[i];
  }
  for(i=0;i<m;i++){
    scanf("%d",&y[i]);
    if(min>y[i]) min=y[i];
  }
  puts(max<min?"No War":"War");
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int a1 = 0, a2 = 0, a3 = 0;
	int x;
	for(int i = 0; i < 10; i++){
		scanf("%d", &x);
		if(x > a1){
			a3 = a2;
			a2 = a1;
			a1 = x;
		}else if(x > a2){
			a3 = a2;
			a2 = x;
		}else if(x > a3){
			a3 = x;
		}
	}

	printf("%d\n%d\n%d\n", a1, a2, a3);

	return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto V=vecin(N);
	
	int Q=in();
	REP(i,Q){
		int u=in(),v=in(),k=in();
		out(count(V.begin()+u,V.begin()+v,k));
	}

	return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

bool dp[5005][5005];
int N, K, a[5005], cnt, l, r, mid;

inline bool check(int base)
{
	memset(dp, false, sizeof(dp));
	dp[0][0]=true;
	Forn(i, N)
	{
		forn(j, K+1)
		{
			dp[i][j]=dp[i-1][j];
			if(i!=base&&j>=a[i])
				dp[i][j] |=dp[i-1][j-a[i]];
		}
	}
	for(int sum=max(K-a[base], 0); sum<K; sum++)
		if(dp[N][sum])
			return true;
	return false;
}

int main()
{
	N=in(), K=in();
	Forn(i, N)
		a[i]=in();
	sort(a+1, a+1+N);
	l=0, r=N+1;
	while(l+1<r)
	{
		mid=(l+r>>1);
		if(check(mid))
			r=mid;
		else
			l=mid;		
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 24704
N,M=list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
seen = [-1 for i in range(N)]
count = 0
def dfs(x):
    global count
    if sum(seen) == N:
        count += 1
        return
    
    for i in range(M):
        if a[i][0] == x and seen[a[i][1]-1] == -1:
            seen[a[i][1]-1] = 1
            dfs(a[i][1])
            seen[a[i][1]-1] = -1
        if a[i][1] == x and seen[a[i][0]-1] == -1:
            seen[a[i][0]-1] = 1
            dfs(a[i][0])
            seen[a[i][0]-1] = -1
seen[0] = 1
dfs(1)
print(count)


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	S, T := sc.Next(), sc.Next()
	A, B := sc.NextInt(), sc.NextInt()
	U := sc.Next()

	if S == U {
		A--
	}
	if T == U {
		B--
	}
	fmt.Println(A, B)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>x(N);
  for(int i=0;i<N;i++){
    cin>>x.at(i);}
  int disA,disB,ans=0;
  for(int i=0;i<N;i++){
   disA=abs(2*(x.at(i))); //i番目のA(i)とボール(i)の最短距離
 
   disB=abs(2*(K-x.at(i)));//i番目のB(i)とボール(i)の最短距離

   ans+=min(disA,disB);//i番目のボールを取るロボットの最短距離
  }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#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 k;
  cin >> k;

  int x = 7;
  for (int i = 1; i <= k; ++i) {
    if (x % k == 0) {
      cout << i << endl;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3600
//知らない考え方だあ

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int IMAX = 1000000;

ll mod = 998244353;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

ll fac[IMAX + 1], ifac[IMAX + 1];

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


	int N;
	cin >> N;
	int A[1000001] = {};
	rep(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}

	fac[0] = 1;
	rep1(i, IMAX) fac[i] = fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = ifac[i] * i % mod;

	ll C[IMAX + 1];
	rep1(i, IMAX) C[i] = ifac[i] * fac[i - 1] % mod;

	rep1(i, IMAX) {
		C[i] = (C[i] % mod + mod) % mod;
		for (int j = i + i; j <= IMAX; j += i) {
			C[j] = C[j] - C[i];
		}
	}

	ll kotae = 0;
	rep1(i, IMAX) {
		ll goukei = 0, goukei2 = 0;
		for (int j = i; j <= IMAX; j += i) {
			goukei += (ll)A[j] * j;
			goukei2 += (ll)j * j * A[j];
		}

		ll kei = goukei % mod;
		ll kari = (kei * kei - goukei2) % mod;
		kari = (kari + mod) * ifac[2] % mod;

		kotae = (kotae + kari * C[i]) % mod;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 27648
import sys

# フェルマーの小定理
# ・aはpの倍数ではない
# ・pは素数
# の場合に以下が成り立つ。
# a**(p-1) mod p = 1
def nCr(n, r, mod):
  p = 1
  q = 1
  for i in range(r):
    p = (p * (n - i)) % mod
    q = (q * (r - i)) % mod
  return p * pow(q, mod-2, mod)

n, a, b = map(int, sys.stdin.readline().split())
MOD = 10 ** 9 + 7
ans = pow(2, n, MOD) - 1
ans = (ans - nCr(n, a, MOD) - nCr(n, b, MOD)) % MOD
print(ans)

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

int main(){
	string s;cin>>s;
	int Min=s.size();
	rep(i,s.size()-1){
		if(s[i]!=s[i+1]){
			Min=min(Min,max(i+1,(int)s.size()-i-1));
		}
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 512
def wf(N, cost):
    for k in range(N):
        for i in range(N):
            c_ik = cost[i][k]
            for j, (c_kj, c_ij) in enumerate(zip(cost[k], cost[i])):
                temp = c_ik + c_kj
                if temp < c_ij:
                    cost[i][j] = temp

import sys
import itertools
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
cost = [[float("inf")] * N for _ in range(N)]

for i in range(N):
    cost[i][i] = 0

for _ in range(M):
    A, B, C = map(int, sys.stdin.readline().split())
    cost[A - 1][B - 1] = C
    cost[B - 1][A - 1] = C

wf(N, cost)

ans = float('inf')
for place in itertools.permutations(r):
    temp_cost = 0
    current_place = place[0]
    for next_place in place[1:]:
        temp_cost += cost[current_place - 1][next_place - 1]
        current_place = next_place

    if temp_cost < ans:
        ans = temp_cost

print(ans)



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

int main() {
    std::string s;
    std::cin >> s;
    auto count = 0, j = 0;
    bool ret = (s[0] == 'A');
    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C') count++, j = i;
    }
    ret = (ret && (count == 1));
    for (auto i = 1; i < s.size(); i++) {
        if (i == j) continue;
        ret = (ret && (s[i] >= 'a') && (s[i] <= 'z'));
    }

    std::cout << (ret ? "AC" : "WA") << std::endl;

    return 0;
}

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

int n, a[101010];

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n, greater<int>());
    cout << a[0] << " ";

    if(a[0] % 2 == 0)
    {
        int m = 1e9, pos = 0;
        for(int i = 1; i < n; i++)
        {
            int x = abs(a[0] / 2 - a[i]);
            if(x < m)
            {
                pos = i;
                m = x;
            }
        }
        cout << a[pos] << endl;
    }
    else
    {
        int m = 1e9, pos = 0;
        for(int i = 1; i < n; i++)
        {
            int x = abs(a[0] / 2 - a[i]);
            int y = abs(a[0] / 2 - a[i] + 1);
            if(x < m || y < m)
            {
                pos = i;
                m = min(x, y);
            }
        }
        cout << a[pos] << endl;
    }

    return 0;
}

Measured memory_bytes: 640
import math

A, B, C, D = [int(x) for x in input().split(" ")]
lcm_c_d = (C * D) // math.gcd(C, D)
num_c = (B // C) - (A - 1) // C
num_d = (B // D) - (A - 1) // D
num_cd = (B // lcm_c_d) - (A - 1) // lcm_c_d
print(B - A - num_c - num_d + num_cd + 1)


Measured memory_bytes: 61968
Color = input().split()
ColNum = list(map(int,input().split()))
Ball=input()

if(Ball == Color[0]):
  ColNum[0] -= 1
elif(Ball == Color[1]):
  ColNum[1] -= 1
else:
  print('error!')

print(str(ColNum[0]) + ' ' + str(ColNum[1]))

Measured memory_bytes: 38612
#include <iostream>

using namespace std;

int main() {
    int n, m, a, b, *ans;
    cin >> n >> m;
    ans = new int[n];
    for (int i = 0; i < m; i++) {
        ans[i] = 0;
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        ans[a-1]++;
        ans[b-1]++; 
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

#define N 100010
#define rep(i, j, n) for(int i=j; i<n; ++i)

using ll = long long;

int main() {
    int n, m;
    ll  ans = 0LL;
    std::vector< std::vector< int > > vec(N);
    std::priority_queue< int > que;

    std::cin >> n >> m;
    rep(i, 0, n) {
        int a, b;
        std::cin >> a >> b;
        --a;
        vec[a].push_back( b );
    }

    rep(i, 0, m) {
        for (auto v : vec[i]) que.push( v );
        if (que.empty()) continue;
        ans += que.top();
        que.pop();
    }

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

    return 0;
}



Measured memory_bytes: 5632
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

ll n;
vector<ll>list(10000, 0);

bool IsPrime(ll num)
{

	if (num < 2) return true;
	else if (num == 2) {
		n /= 2;
		list[2]++;
		return true;
	}
	else if (num % 2 == 0) {
		n /= 2;
		list[2]++;
		return false; // 偶数はあらかじめ除く
	}

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

	// 素数である
	return true;
}

signed main() {

	cin >> n;
	ll n2 = n - 1;

	while (true)
	{
		bool flag = false;

		if (n < 1000000000) {
			if (n2 > 1) {
				n *= n2;
				n2--;
			}
		}

		if (IsPrime(n) == true) {
			list[n]++;
			break;
		}

	}

	ll sum = 1;

	for (int i = 2; i < list.size(); i++) {
		if (list[i] > 0) {
			sum = sum * (list[i] + 1);
			sum %= MOD;
		}
	}

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn char_index(c: char) -> usize {
    c.to_digit(36).unwrap() as usize - 10
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();
    let mut chars = vec![vec![]; 26];
    for i in 0..s.len() {
        chars[char_index(s[i])].push(i);
    }

    let mut indices = vec![0; t.len()];
    let mut offset = 0;
    for i in 0..t.len() {
        let cs = &chars[char_index(t[i])];
        if cs.len() == 0 {
            println!("-1");
            return;
        }
        let j = match cs.binary_search(&offset) {
            Ok(j) => j,
            Err(j) => j,
        };
        let j = if j >= cs.len() {
            0
        } else {
            j
        };
        indices[i] = cs[j];
        offset = if indices[i] == s.len() - 1 {
            0
        } else {
            indices[i] + 1
        };
    }

    let mut count = 0;
    for i in 1..t.len() {
        if indices[i] <= indices[i - 1] {
            count += 1;
        }
    }
    count *= s.len();
    count += indices[t.len() - 1] + 1;
    println!("{}", count);
}


Measured memory_bytes: 8444
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i=0; i<n; ++i)
typedef pair<int,char> card;

card a[9];
int perm[9];

int main() {
    int tc,k;
    string s;
    cin>>tc;
    while(tc--) {
        rep(i,9) {
            cin>>k;
            a[i].first = k;
        }

        rep(i,9) {
            cin>>s;
            a[i].second = s[0];
        }

        rep(i,9) perm[i] = i;

        int k = 0;
        do {
            // cout<<k<<endl;

            if(a[perm[0]].second == a[perm[1]].second
               && a[perm[1]].second == a[perm[2]].second
               && a[perm[3]].second == a[perm[4]].second
               && a[perm[4]].second == a[perm[5]].second
               && a[perm[6]].second == a[perm[7]].second
               && a[perm[7]].second == a[perm[8]].second) {

                if(((a[perm[0]].first == a[perm[1]].first
                    && a[perm[1]].first == a[perm[2]].first)
                   || (a[perm[0]].first+1 == a[perm[1]].first
                       && a[perm[1]].first == a[perm[2]].first-1))
                   &&((a[perm[3]].first == a[perm[4]].first
                    && a[perm[4]].first == a[perm[5]].first)
                   || (a[perm[3]].first+1 == a[perm[4]].first
                       && a[perm[4]].first == a[perm[5]].first-1))
                   && ((a[perm[6]].first == a[perm[7]].first
                    && a[perm[7]].first == a[perm[8]].first)
                   || (a[perm[6]].first+1 == a[perm[7]].first
                       && a[perm[7]].first == a[perm[8]].first-1))) {
                    cout<<1<<endl;
                    goto END;
                }

            }
        NEXT:;
            k++;
        } while( next_permutation(perm, perm+9) );
        cout<<0<<endl;
    END:;
    }
}

Measured memory_bytes: 928
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DLunlunNumber {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k; cin >> k;
      vector<vector<ll>> dp(10, vector<ll>(10));
      for(int i=0; i<=9; i++) {
        dp[0][i] = 1;
      }
      for(int i=1; i<=9; i++) {
        for(int j=0; j<10; j++) {
          if (j+1<10) dp[i][j+1] += dp[i-1][j];
          dp[i][j] += dp[i-1][j];
          if (j>0) dp[i][j-1] += dp[i-1][j];
        }
      }

      int now = 0;
      int x, y;
      bool fin = false;
      for(int i=0; i<10; i++) {
        if (fin) break;
        for(int j=1; j<10; j++) {
          now += dp[i][j];
          if (now >= k) {
            now -= dp[i][j];
            x = i; y = j;
            cout << y;
            fin = true;
            break;
          }
        }
      }

      for(int i=x-1; i>=0; i--) {
        for(int j=max(0, y-1); j<=min(9, y+1); j++) {
          now += dp[i][j];
          if (now >= k) {
            now -= dp[i][j];
            y = j;
            cout << y;
            break;
          }
        }
      }
      cout << endl;

    }
};

signed main() {
  DLunlunNumber solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define nl "\n" 


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans;
    ans = (n/500)*1000;
    n=n%500;
    ans+=(n/5)*5;
    cout << ans;
	return 0;
}


Measured memory_bytes: 256
S, T = input(), input()
d = dict()
count = 0
S_list = []
for c in S:
    try:
        n = d[c]
    except:
        d[c] = n = count
        count += 1
    S_list.append(n)
d = dict()
count = 0
for m, c in zip(S_list, T):
    try:
        n = d[c]
    except:
        d[c] = n = count
        count += 1
    if n != m:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 5296
// let coding = begin

#include<bits/stdc++.h>

#define ll long long
#define pb       push_back
#define all(a)   a.begin(), a.end()

using namespace std;
const int MAX = 1e9+9;
const int MIN = -1e9;
const int N= 1e5+9;
const double PI = 3.14159265;
int n,k;
int tab[N];
vector<int> g;
int ans;
int main(){
  clock_t start;
  cin >> n >> k;
  for(int i=0; i<n; i++){
    cin >> tab[i];
  }
  sort(tab, tab+n);
  vector<int> dist;
  for(int i=0; i<n; i++){
    dist.pb(abs(tab[i]-k));
  }
  for(int i=1; i<n; i++){
    g.pb( tab[i] - tab[i-1] );
  }
  int ans = ((n == 1 )?0:g[0]);
  for(int i=0; i<g.size(); i++){
    ans = __gcd(ans, g[i]);
  }
  for(int val : dist){
    ans =  __gcd(val, ans) ;
  }
  cout << ans <<  endl;
  cerr << "Time: " << (clock() - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << endl;
  return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
template <class T> struct FenwickTree {
 
   vector<T> node;
   FenwickTree (int n) : node(n,0) {}
 
   void add(int idx, T val) {
      for (int i = idx; i < node.size(); i |= i + 1) {
         node[i] += val;
      }
   }
 
   T sum(int idx) {
      T ret = 0;
      for (int i = idx - 1; i >= 0; i = (i & (i + 1)) - 1) {
         ret += node[i];
      }
      return ret;
   }
 
};
 
int N,M;
vector< pair<int,int> > add;
vector<int> l,r;
FenwickTree<int> inst(100010);
 
int main() {
 
  cin >> N >> M;
  l.resize(N);
  r.resize(N);
 
  REP(i,N) {
    int lt,rt; cin >> lt >> rt;
    l[i] = lt;
    r[i] = rt;
    add.push_back(make_pair(rt - lt + 1, i));
  }
  
  sort(add.begin(),add.end());
 
  int j = 0;
  for(int i=1; i<=M; i++) {
    while(j < add.size()) {
      if(add[j].first >= i) break;
      int idx = add[j].second;
      inst.add(l[idx],1);
      inst.add(r[idx]+1,-1);
      j++;
    }
 
    int ans = N - j;
    for(int k=i; k<=M; k+=i) ans += inst.sum(k+1);
    cout << ans << endl;
  }
 
  return 0;
}

Measured memory_bytes: 9200
N = int(input())
H = list(map(int, input().split()))

mx = 0
t = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        t += 1
        mx = max(mx, t)
    else:
        t = 0
    # print(i, H[i], t, mx)

print(mx)


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

q = input()

for loop in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    # ax + by = c
    a1, b1, c1 = [y1 - y0, x0 - x1, x0 * (y1 - y0) - y0 * (x1 - x0)]
    a2, b2, c2 = [y3 - y2, x2 - x3, x2 * (y3 - y2) - y2 * (x3 - x2)]
    det = a1 * b2 - b1 * a2
    # parallel
    if det == 0:
        if x0 * a1 + y0 * b1 != x2 * a1 + y2 * b1: # not collinear
            print 0
        elif max(x0, x1) < min(x2, x3) or max(x2, x3) < min(x0, x1) \
            or max(y0, y1) < min(y2, y3) or max(y2, y3) < min(y0, y1): # not overlap
            print 0
        else: # overlap
            print 1
        continue

    if (a1 * x2 + b1 * y2 - c1) * (a1 * x3 + b1 * y3 - c1) <= 0 and \
        (a2 * x0 + b2 * y0 - c2) * (a2 * x1 + b2 * y1 - c2) <= 0:
        print 1
    else:
        print 0



Measured memory_bytes: 4716
N = int(input())
l = list(map(int,input().split()))

ans = 0
for i in range(len(l)-1):
    if l[i] <= l[i+1]:
        pass
    else:
        ans += l[i] - l[i+1] 
        l[i+1] += l[i] - l[i+1] 
print(ans)

Measured memory_bytes: 32300
/* 
 * Project: AtCoder Beginners Contest 167 C - Skill Up
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/04
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <algorithm>
#include <vector>
#include <cstdio>
#include <climits>
using namespace std;

int n, m, x;
int c_price[12];
int a[12][12];

void solve() {

    int bit_max = 1<<n;
    int sum_price = INT_MAX;

    for (int i=0;i<bit_max;i++) {
        vector<int> skill(m);
        int cost = 0;
        for (int j=0;j<n;j++) {
            if ((i>>j)&1) {
                cost += c_price[j];
                for (int k=0;k<m;k++) {
                    skill[k] += a[j][k];
                }
            }
        }
        bool achieve = true;
        for (int k=0;k<m;k++) {
            if (skill[k] < x)
                achieve = false;
        }
        if (achieve)
            sum_price = min(sum_price, cost);
    }
    if (sum_price == INT_MAX) {
        printf("%d\n", -1);
        return;
    } else {
        printf("%d\n", sum_price);
        return;
    }
}

int main() {

    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &x);
    for (int i=0;i<n;i++) {
        scanf("%d", &c_price[i]);
        for (int j=0;j<m;j++) {
            scanf("%d", &a[i][j]);
        }
    }

    solve();
}

Measured memory_bytes: 3192