akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------
int V, E ;
vector<int> color ;
vector<int> seen ;
vector<vector<int>> graph ;
queue<int> que ;

bool f = true ;
vector<int> color1 ;

void dfs_01(int v,int c){
    color1[v] = c ;
    for(int i=0;i<graph[v].size();i++){
        if(color1[graph[v][i]]==c){
            f = false ;
        }
        if(color1[graph[v][i]]==0){
            dfs_01(graph[v][i],-c) ;
        }
    }
    return ;
}



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

    cin >> V ;
    vector<int> zero(V,0) ;
    seen = zero ;
    color = zero ;
    color1 = zero ;


    for(int i=0;i<V;i++){
        graph.push_back(vector<int>()) ;
        string s ;
        cin >> s ;
        REP(j,V){
            if(s[j]=='1'){
                graph[i].PB(j) ;
            }
        }
    }

    dfs_01(0,1) ;

    if(!f){
        cout << -1 <<endl ;
        return 0 ;
    }
    
    int ans = 0 ;

    REP(i,V){
        seen = zero ;
        color = zero ;
        que.push(i) ;
        seen[i] = 1 ;
        color[i] = 1 ;

        while(!que.empty()){
            int k = que.front() ;
            que.pop() ;
            for(int i=0;i<graph[k].size();i++){
                if(seen[graph[k][i]]==0){
                    que.push(graph[k][i]) ;
                    seen[graph[k][i]] = 1 ;
                    color[graph[k][i]] = color[k] + 1  ;
                }
            }
        }
        sort(ALL(color)) ;

        ans = max(ans,color[V-1]) ;
    }

    cout << ans <<endl ;


    

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define MAX_CARD_NUMBER 13        //カードに表記される数字の最大数
#define MAX_MARK_NUMBER 4          //マークの種類数
#define S 0                                             //スペード(S)は0
#define H 1                                             //ハート(H)は1
#define C 2                                             //クローバー(C)は2
#define D 3                                             //ダイヤモンド(D)は3
#define NO_EXIST 0                              //カードなし
#define EXIST 1                                     //カードあり

int main(void)
{
    int aiMarksNumbers[MAX_MARK_NUMBER][MAX_CARD_NUMBER + 1];  //カード存在判定結果を格納する二次元配列
                                                                                                                            // カードなし：NO_EXIST、カードあり：EXISTを格納する
    int iInputNumber;                                //カードの数字
    int iCardsNumber;                              //所持カードの枚数
    int iMarkCount;                                   //カウントアップ変数
    int iNumberCount;                              //トランプの数字1-13のカウントアップ変数
    char chInputMark;                              //カードのマーク

    //所持カード枚数の初期化
    iCardsNumber = 0;
    //所持カードの枚数を標準入力
    scanf("%d", &iCardsNumber);

    //カードの数字を初期化
    iInputNumber = 0;
    //カード存在判定結果を格納する二次元配列を初期化
    for (iMarkCount = 0; iMarkCount < MAX_MARK_NUMBER; iMarkCount++)
    {
        for (iNumberCount = 1; iNumberCount <= MAX_CARD_NUMBER; iNumberCount++)
        {
            aiMarksNumbers[iMarkCount][iNumberCount] = 0;
        }
    }

    //カード存在判定結果をaiMarksNumbersに格納
    for (iNumberCount = 0; iNumberCount < iCardsNumber; iNumberCount++)
    {
        //szInputMark:マークの頭文字とiInputNumber:カードの数字の標準入力
        scanf(" %c %d", &chInputMark, &iInputNumber);

        //存在するならEXISTを代入する
        switch (chInputMark)
        {
        case 'S':
            aiMarksNumbers[S][iInputNumber] = EXIST;
            break;

        case 'H':
            aiMarksNumbers[H][iInputNumber] = EXIST;
            break;

        case 'C':
            aiMarksNumbers[C][iInputNumber] = EXIST;
            break;

        case 'D':
            aiMarksNumbers[D][iInputNumber] = EXIST;
            break;

        default:
            break;
        }
    }

    //足りないカードを出力
    for (iMarkCount = 0; iMarkCount < MAX_MARK_NUMBER; iMarkCount++)
    {
        for (iNumberCount = 1; iNumberCount <= MAX_CARD_NUMBER; iNumberCount++)
        {
            //あるマークである番号のカードがないなら出力
            if (aiMarksNumbers[iMarkCount][iNumberCount] == NO_EXIST)
            {
                switch (iMarkCount)
                {
                case S:
                    printf("S %d\n", iNumberCount);
                    break;

                case H:
                    printf("H %d\n", iNumberCount);
                    break;

                case C:
                    printf("C %d\n", iNumberCount);
                    break;

                case D:
                    printf("D %d\n", iNumberCount);
                    break;

                default:
                    break;
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#include <limits>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll n;
    cin >> n;
    string s;
    cin>>s;
    ll e1=0, w1 = 0;
    vector<ll> e(n, 0);
    vector<ll> w(n, 0);
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i] == 'W')
        {
            w1++;
        }
        else if (s[i] == 'E')
        {
            e1++;
        }
        e[i] = e1;
        w[i] = w1;
    }
    ll ans = LLONG_MAX;
    for (ll i = 0; i < n; i++)
    {
        if(i==0){
            ans = min(e[n - 1] - e[i], ans);
        }
        else if(i==n-1){
            ans = min(ans, w[i - 1]);
        }
        else{
            ans = min(ans, w[i - 1] + e[n - 1] - e[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5380
nmq = [int(x) for x in input().split()]

n = nmq[0]
m = nmq[1]
q = nmq[2]

lis = []

for i in range(0,q):
    lis.append([int(x) for x in input().split()])

def check(ar):
    total = 0
    for thing in lis:
        if ar[thing[1]] - ar[thing[0]] == thing[2]:
            total = total + thing[3]
    return total

def solve(pre,count):
    count = int(count)
    if count == n:
        return(check(pre))
    else:
        maxx = 0
        for i in range(pre[count],m+1):
            temp = solve(pre + [i], count+1)
            if temp > maxx:
                maxx = temp
        return(maxx)
    
print(solve([1],0))
    


Measured memory_bytes: 9232
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   int a,b;
   cin >> a >> b;
   if(a <= b){
      cout << a << endl;
      return 0;
   }
   else{
      cout << a-1 << endl;
      return 0;
   }
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int collatz_sub(int a)
{
	if ( a % 2 == 0 ) return a / 2;
	else return 3 * a + 1;
}

int main()
{
	int s,tmp,count = 1;
	scanf("%d",&s);
	int A[1000000];
	A[s] = 1;

	while ( 1 ) {
		count++;
		tmp = collatz_sub(s);
		if ( A[tmp] == 1 ) {
			printf("%d\n",count);
			break;
		} else {
			A[tmp] = 1;
			s = tmp;
		}
	}
  	return 0;
}

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

int main(){
    long a, b;
    cin >> a >> b;
    
    if(a > b){
        cout << "a > b" << endl;
    }else if(a < b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}


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

using namespace std;
int main()
{

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2-x1;
    int b = y2-y1;
    int x3, x4, y3, y4;
    x3 = x2 + b*-1;
    y3 =  y2 + a;
    x4 = x3 -a;
    y4 = y3 - b;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x0123456789) cerr<<#x0123456789<<':'<<x0123456789<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x0123456789:v)cerr<<x0123456789<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;
typedef long double ld;

ll sum[51];
ll len[51];

long long POW(long long x,long long n){long long ans = 1;while(n){if(n%2)ans *= x;x *= x;n >>= 1;}return ans;}
long long POW(long long x,long long n,long long mod){long long ans = 1;while(n){if(n%2)ans *= x;x *= x;x %= mod;ans %= mod;n >>= 1;}return ans;}

ll dfs(ll N,ll X){
    if(X==len[N])return sum[N];
    if(X==0)return 0;
    if(X < 2+len[N-1])return dfs(N-1,X-1);
    if(X == 2+len[N-1])return sum[N-1]+1;
    return sum[N-1]+1+dfs(N-1,X-len[N-1]-2);
}

signed main(){
    ll N,X;
    cin >> N >> X;
    FOR(i,0,51)sum[i] = POW(2,i+1)-1;
    FOR(i,0,51)len[i] = POW(2,i+2)-3;
    cout << dfs(N,X) << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long p = sc.nextLong();

		long ini = p;

		Map<Long, Long> map = new HashMap<>();

		double rt = Math.sqrt(p);

		for (long i = 2; i <= rt; i++) {

			while (p % i == 0) {
				long now = map.getOrDefault(i, (long) 0);
				map.put(i, now + 1);
				p = p / i;
			}
		}

		long now = map.getOrDefault(p, (long) 0);
		map.put(p, now + 1);

		List<Long> list = new ArrayList<>();

		for (Long i : map.keySet()) {
			while (map.get(i) >= n) {
				list.add(i);
				map.put(i, map.get(i) - n);
			}
		}

		long ans = list.stream().mapToLong(Long::valueOf).reduce(1, (a, b) -> a * b);

		if (n == 1) {
			ans = ini;
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 26836
# coding: utf-8
N,M=map(int,input().split())
L=[]
B=[]
A=[]
flg=0
cnt=0
for i in range(M):
    a,b=list(map(int,input().split()))
    L.append([a,b])
    if a==1:
        B.append(b)
        cnt+=1
    elif b==N:
        A.append(a)
        
#print(L)
ans=[]
if len(set(A)&set(B))==0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 101720
#include <iostream>
#include <cmath>
using namespace std;
bool judge(int X){
    bool flag = true;
    for(int i = 2; i <= sqrt(X); i++){
        if(X % i == 0){

            flag = false;
            break;
        }
    }
    if(flag) return true;
    else return false;

}

int main(){
    int X; cin >> X;
    while(1){
        bool flag = judge(X);
        if(flag){
            cout << X << endl;
            return 0;
        }
        X += 1;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		List<Double> height = new ArrayList<>();
		while (str!=null) {
			double h = Double.parseDouble(str);
			height.add(h);
			str = br.readLine();
		}
		int length = height.size();
		double[] heightarray = new double[length];
		for (int i = 0; i < length; i++) {
			heightarray[i] = height.get(i);
		}
		for (int i = 0; i < length - 1; i++) {
			for (int j = i + 1; j < length; j++) {
				double temporary;
				if (heightarray[i] < heightarray[j]) {
					temporary = heightarray[i];
					heightarray[i] = heightarray[j];
					heightarray[j] = temporary;
				}
			}
		}
		System.out.println(heightarray[0] - heightarray[length - 1]);
	}
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : 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 -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

bool sign(ll a, ll b) {
    return (0 <= a && 0 <= b) || (a < 0 && b < 0);
}

tuple<char, ll, ll> make_tuple(ll a, ll b) {
    char c = sign(a, b)? '+' : '-';
    if (a == 0 || b == 0) c = '+';
    a = abs(a), b = abs(b);
    ll x = a / __gcd(a, b), y = b / __gcd(a, b);
    return make_tuple(c, x, y);
}

tuple <char, ll, ll> reverse(tuple<char, ll, ll> &t) {
    char c = get<0>(t);
    ll x = get<1>(t), y = get<2>(t);
    if (x == 0 || y == 0) c = '-';
    return make_tuple(c == '-'? '+' : '-', y, x);
}

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

    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<mint> mul(N+1);
    mul[0] = 1;
    for (int i = 1; i <= N; ++i) mul[i] = mul[i-1] * 2;

    map<tuple<char, ll, ll>, int> mp;
    int count = 0;
    rep(i, N) {
        if (A[i] == 0 && B[i] == 0) {
            count++;
            continue;
        }
        auto t = make_tuple(A[i], B[i]);
        mp[t]++;
    }

    mint ans = 1;
    map<tuple<char, ll, ll>, bool> flg;
    for (auto p : mp) {
        auto t = p.first;
        int a = p.second;

        auto rt = reverse(t);
        int b = mp[rt];

        if (flg[t] || flg[rt]) continue;

        ans *= mul[a] + mul[b] - 1;
        flg[t] = flg[rt] = 1;
    }

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

Measured memory_bytes: 70372
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 c = sc.nextInt();
    System.out.println(method(a, b, c));
  }
  static int method(int a, int b, int c) {
    int divisor = 0;
    for(int i = a;i < b + 1;i++) {
      if(c % i == 0) {
        divisor++;
      }
    }
    return divisor;
  }
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b;
  cin >> a >> b;
  if(a<10 && b<10){
    cout << a*b << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long ans = 1;
        while(true) {
            x *= 2;
            if(x > y) break;
            ans++;
        }
        System.out.println(ans);
    }
}

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

#define ll long long
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define E_ACH2(x, a) for (auto& x: a)
#define E_ACH3(x, y, a) for (auto& [x, y]: a)
#define E_ACH4(x, y, z, a) for (auto& [x, y, z]: a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...) E_ACHC(__VA_ARGS__)(__VA_ARGS__)

const int mxN=2e5, M=1e9+7;
int n, k, c0;
vector<ll> ap, an;

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

	cin >> n >> k;
	FOR(n) {
		ll a;
		cin >> a;
		if(a>0)
			ap.push_back(a);
		else if(a<0)
			an.push_back(-a);
		else
			++c0;
	}
	sort(all(ap));
	sort(all(an));
	if(k+c0>n) {
		cout << 0;
		return 0;
	}
	if(k==n-c0?an.size()%2==0:ap.size()||k%2==0) {
		reverse(all(ap));
		reverse(all(an));
		ll ans=1;
		int i=0, j=0;
		for(; k; --k) {
			if(i<ap.size()&&(j>=an.size()||ap[i]>an[j])) {
				ans=ans*ap[i]%M;
				++i;
			} else {
				ans=ans*an[j]%M;
				++j;
			}
		}
		if(j&1) {
			//i j-2
			//i-2 j
			ans=1;
			if(i<ap.size()&&j-1>=0&&(j>=an.size()||i-1<0||ap[i]*ap[i-1]>an[j]*an[j-1])) {
				FOR(k, i+1)
					ans=ans*ap[k]%M;
				FOR(k, j-1)
					ans=ans*an[k]%M;
				//ans=ans*a[i]%M;
				//ans=ans*a[i+1]%M;
			} else {
				FOR(k, i-1)
					ans=ans*ap[k]%M;
				FOR(k, j+1)
					ans=ans*an[k]%M;
				//ans=ans*a[i]%M;
				//ans=ans*a[i+1]%M;
			}
		}
		cout << ans;
		return 0;
	}
	if(c0) {
		cout << 0;
		return 0;
	}
	ll ans=1;
	for(int i=0, j=0; k; --k) {
		if(i<ap.size()&&(j>=an.size()||ap[i]<an[j])) {
			ans=ans*ap[i]%M;
			++i;
		} else {
			ans=ans*an[j]%M;
			++j;
		}
	}
	cout << M-ans;
}

Measured memory_bytes: 5536
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int dp[10000];

int main(void)
{
    int N,M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<vector<int>> c(M);
    REP(i, M){
        cin >> a[i] >> b[i];
        c[i].assign(b[i], 0);
        REP(j, b[i]){
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    REP(i, 1<<N){
        dp[i] = INF;
    }
    dp[0] = 0;

    REP(i, 1<<N){
        REP(j, M){
            int next_st = i;
            REP(k, b[j]){
                next_st |= 1<<c[j][k];
            }
            chmin(dp[next_st], dp[i]+a[j]);
        }
    }

    if(dp[(1<<N)-1] == INF) pr(-1);
    else pr(dp[(1<<N)-1]);
}

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

int main(void){
    long long A,B,C,K;
    cin>>A>>B>>C>>K;
    
    int ans;
    if(K%2==0){
        ans=A-B;
    }else{
        ans=B-A;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
d,g=map(int,input().split())
P,C=[],[]
for i in range(d):
  p,c=map(int,input().split())
  P.append(p)
  C.append(c)
ans=float("inf")
for i in range(2**d):
  count,pt=0,0
  key=str(bin(i))[2:].zfill(d)
  for j in range(d):
    if key[j]=="1":
      count+=P[j]
      pt+=P[j]*(j+1)*100+C[j]
  if pt>=g:
    ans=min(ans,count)
  else:
    for k in range(d):
      ind=d-(k+1)
      if key[ind]=="0":
        if pt+P[ind]*(ind+1)*100>=g:
          count+=(g-pt-100)//((ind+1)*100)+1
          ans=min(ans,count)
          break
        else:
          count+=P[ind]
          pt+=P[ind]*(ind+1)*100+C[ind]
          if pt>=g:
            ans=min(ans,count)
            break
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
int h,w,d;
int main()
{
	scanf("%d%d%d",&h,&w,&d);
	for(int i=0;i<h;i++,puts(""))
		for(int j=0;j<w;j++)putchar("RGBY"[((i+j)%(d+d))/d*2+((i-j)%(d+d)<0?((i-j)%(d+d)+d+d)/d:(i-j)%(d+d)/d)]);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define SQ 320
typedef int ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,r,timer,mx,l;
ll a[100500];
int main() {
    //freopen("input.txt","r",stdin);
    cin >> n;
    ll ans = 1, k = 1;
    for (int i = 0; i < n; i++)
    {
        ans *= 3;
        cin >> x;
        if (x%2 == 0)
            k *= 2;
    }
    cout << ans-k << endl;
    return 0;
}


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

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


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] HN = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            List<int> A = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList();
            int H = HN[0];
            int N = HN[1];
            if(H <= A.Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 36016
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	ll N,M;
	cin>>N>>M;
	ll ans=0;
	if(N*2>=M)
		ans+=M/2;
	else{
		ans+=N;
		M-=2*N;
		ans+=M/4;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

val sc = Scanner(System.`in`)
val n = sc.nextInt()

fun main(args: Array<String>) {
    var tmp = 0
    var total = 0
    for (i in 0 until n) {
        val h = sc.nextInt()
        if (h >= tmp) {
            tmp = h
            total++
        }
    }
    print(total)
}

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

using namespace std;

const long long MAX_E = 101010;


struct edge{
    int u, v, cost;
};

edge es[MAX_E];

bool comp(const edge &e1, const edge &e2){
    return e1.cost < e2.cost;
}

class UnionFind{
public:

    //親の番号を格納する. Parentだった場合は−(the size)とする
    vector<int> Parent;
    
    //作るときはParentの値を全て-1にする
    //こうすると, すべての頂点が根となる
    UnionFind(int N){
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A){
        if (Parent[A] < 0) return A; //自分のグループにいる
        return Parent[A] = root(Parent[A]); //親をつなぎ替える
    }
    
    //size関数を作る
    //自分の所属するグループの頂点数を調べる
    long long size(int A){
        return -Parent[root(A)]; //親をとりたい
    }
    
    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接繋がない
        //root(A) に root(B)をくっつける　
        //リーダー同士をくっつける
        
        A = root(A);
        B = root(B);
        
        if (A == B){
            return false; //すでにくっついてる
        }
            
        //大きい方に小さい方をくっつけたい
        //大小が逆だったらひっくり返す
            
        if(size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        
        //BのParentをAに変更する
        Parent[B] = A;
        
        return true; //くっついた
    }
    
};



int kruskal(int V, int E){
    
    sort(es, es+E, comp);
    
    UnionFind uni(V);
    
    int res = 0;
    
    for (int i = 0; i < E; i++){
        edge e = es[i];
        
        if (uni.root(e.u) != uni.root(e.v)){
            uni.connect(e.u, e.v);
            res += e.cost;
        }
    }
    
    return res;
}




int main(){
    
    int V, E;
    cin >> V >> E;
    
    for (int i = 0; i < E; i++){
        int s, t, w;
        cin >> s >>t >> w;
        
        es[i] = (edge){s, t, w};
    }
    
    cout << kruskal(V, E) << endl;
    return 0;
}


Measured memory_bytes: 4416
N, M, X, Y = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
flg = False
for Z in range(-100,101):
    if X<Z<=Y and max(A)<Z and min(B) >= Z:
        flg = True
if flg:
    print("No War")
else:
    print("War")

Measured memory_bytes: 79812
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
score = 0
for _ in range(n):
    a = A.pop()
    aa = A.pop()
    b = B.pop()
    if (a+aa-b) >=0:
        A.append(min(aa,a+aa-b))
        score += b
    else:
        A.append(0)
        score += a+aa
print(score)

Measured memory_bytes: 24144
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc102_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();

            int min = input.ToList().Min();
            int max = input.ToList().Max();

            WriteLine(max-min);
        }
    }
}

Measured memory_bytes: 13396
from collections import Counter
from operator import itemgetter

N = int(input())
A = Counter(map(int,input().split()))
A1 = list(A.items())
A1 = sorted(A1,key=itemgetter(1),reverse = True)
#print(A1)

if A1[0][1] == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 44624
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(void){
	int n, k; cin>>n>>k;
	int D[20] = {};
	for(int i=0;i<k;i++) cin>>D[i];

	for(int i=n;i<100000;i++) {
		int tmp = i;
		set<int> st;
		while(tmp!=0) {
			st.insert(tmp % 10);
			tmp /= 10;
		}
		bool flag = true;

		for(int j=0;j<k;j++) {
			if(st.count(D[j])) flag = false;
		}

		if(flag) {
			cout<< i <<endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=10000000000000007;
const int MOD=1000000007;

class Edge{
public:
//int s;
int t;
long long len;
};
class Node{
    public:
    int num;//node番号
    long long dist;//startからの距離
    vector<Edge> edge;//自分から生えている辺
    bool comp;//dijkstra中で到達しているかどうか
    void in_edge(Edge &edge_in){
        edge.push_back(edge_in);
    }  
};
bool operator >(const Node& a,const Node &r){
        return a.dist > r.dist;
    }
void dijkstra(vector<Node> &node,int s,int t,int n){
    //n個のノードでできたグラフのsからtまでの最短距離を計算する
    //この時各要素のdistの値はsからの最短距離となる
    for(int i=1;i<=n;i++){
        //初期化
        node[i].dist=inf;
        node[i].num=i;
        node[i].comp=true;
    }
    node[s].dist=0;
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push(node[s]);
    while(!que.empty()){
        Node buf;
        buf=que.top();//
        que.pop();
        int k=buf.num;
        if(node[k].comp){
            node[k].comp=false;
            int edge_num=buf.edge.size();
            for(int i=0;i<edge_num;i++){
                int buf_t=node[k].edge[i].t;
                int buf_len=node[k].edge[i].len;
                if(node[buf_t].dist>node[k].dist+buf_len){
                node[buf_t].dist=node[k].dist+buf_len;
                que.push(node[buf_t]);
                }
            }
        }
    }
}
signed main(){
  int n,m,s,t;//n:node_num,s:start_node,t:goal_node,m:edge_num
    cin>>n>>m>>s>>t;
    vector<Node> yen(n+1);
    vector<Node> snuke(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        long long l,r;
        cin>>a>>b>>l>>r;
        Edge in;
//        in.s=a;
        in.t=b;
        in.len=l;
        yen[a].in_edge(in);//有向グラフの場合ここまで
        in.len=r;
        snuke[a].in_edge(in);
//        in.s=b;
        in.t=a;
        snuke[b].in_edge(in);
        in.len=l;
        yen[b].in_edge(in);//無向グラフの場合こっちも
    }
    dijkstra(yen,t,s,n);
    dijkstra(snuke,t,s,n);
    vector<Node> yenr=yen;
    vector<Node> snuker=snuke;
    dijkstra(yenr,s,t,n);
    dijkstra(snuker,s,t,n);
    vector<pair<int,int>> mins(n+1);
    mins[0]=make_pair(inf,inf);
    rep1(i,n){
      mins[i].first=yenr[i].dist+snuke[i].dist;
      mins[i].second=i;
    }
    sort(ALL(mins));
    int cur=0;
    rep(i,n){
      while(i>=mins[cur].second){
        cur++;
      }
      ll res=1e15;
      res-=mins[cur].first;
      cout<<res<<endl;
    }
  return 0;
}


Measured memory_bytes: 44020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>
#define push_back pb
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1e14;

ll ind(ll n,ll N){
	return n >= 0 ? n : n + N; 
}

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

	ll N,x;
	cin >> N >> x;

	ll a[N];
	rep(i,N){
		cin >> a[i];
	}

	// b[i][j] = min(a[i-j],a[i-j+1],...,a[i])
	// b[i][j] は下のように埋まる
	ll b[N][N];	
	rep(i,N){
		b[i][0] = a[i];
	}

	FOR(j,1,N){	
		rep(i,N){
			b[i][j] = min(b[i][j-1],a[ind((i-j),N)]);
		}
	}

	ll ans = INF;

	// 魔法を使う回数のループ
	rep(j,N+1){
		//魔法の時間	
		ll tm = j * x; 	

		// 各スライムの元スライム作成時間を足す
		rep(i,N) tm += b[i][j];	

		ans = min(ans,tm);
	}

	cout << ans << endl;
}

Measured memory_bytes: 31488
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

#define EPS (1e-8)
#define INF (1e8)
int H,W;
string t[100];
bool visited[100][10];
bool visited2[100][10];
bool ans;
int cx,cnt;
double l,r;

void rec(int y,int x){
  if(visited[y][x])return;
  visited[y][x]=true;
  cx+=x;cnt++;
  if(y>0&&(t[y][x]==t[y-1][x]||t[y-1][x]!='.'))rec(y-1,x);
  if(y+1<H&&t[y][x]==t[y+1][x])rec(y+1,x);
  if(x>0&&t[y][x]==t[y][x-1])rec(y,x-1);
  if(x+1<W&&t[y][x]==t[y][x+1])rec(y,x+1);
}

void rec2(int y,int x){
  if(visited2[y][x])return;
  visited2[y][x]=true;
  if(t[y][x]!=t[y+1][x]&&t[y+1][x]!='.'){
    l=min(l,x-0.5);
    r=max(r,x+0.5);
  }
  if(y>0&&t[y][x]==t[y-1][x])rec2(y-1,x);
  if(y+1<H&&t[y][x]==t[y+1][x])rec2(y+1,x);
  if(x>0&&t[y][x]==t[y][x-1])rec2(y,x-1);
  if(x+1<W&&t[y][x]==t[y][x+1])rec2(y,x+1);
}

void init(){
  ans=true;
  for(int i=0;i<100;i++)
    for(int j=0;j<10;j++)
      visited[i][j]=visited2[i][j]=false;
}

int main(){
  while(1){
    cin>>W>>H;
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++)cin>>t[i];
    t[H]="0000000000";
    init();
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(visited2[i][j]||t[i][j]=='.')continue;
	for(int k=0;k<H;k++)
	  for(int l=0;l<W;l++)
	    visited[k][l]=false;
	cx=cnt=0;
	rec(i,j);
	l=INF,r=-INF;
	rec2(i,j);
	double d=(double)cx/(double)cnt;
	if(d<l+EPS || r-EPS<d)ans=false;
      }
    }
    cout<<(ans?"STABLE":"UNSTABLE")<<endl;
  }
  return 0;
}

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

int main() {
	int n;
	int count = 0;
	int old_count = -1;
	cin >> n;
	vector<int>a;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		a.push_back(p);
	}
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			int k = a[i];
			a[i] = a[minj];
			a[minj] = k;
			count++;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1)cout << " ";
	}cout << endl;
	cout << count << endl;
}





Measured memory_bytes: 3176
#include<stdio.h>

int main(void) {

	int i;
	int n;
	char tmp;
	char s[101];
	char t[101];
	char res[202];

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

	//printf("%s\n", s);
	//printf("%s\n", t);

	for (i = 0; i < n; i++) {
		res[2 * i] = s[i];
		res[2 * i + 1] = t[i];
	}

	for (i = 0; i < 2 * n; i++) {
		printf("%c", res[i]);
	}


	return 0;
}

Measured memory_bytes: 128
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[] 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 = lread();
    auto S = sread();
    long ans;
    foreach (i; 0 .. N - 2)
        if (S[i .. i + 3] == "ABC")
        {
            ans++;
        }
    writeln(ans);
}


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;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;
const int SI = 100005;

const int MAX_N = (1<<18);

struct segtree{
    int n;
    ll dat[2*MAX_N-1]; //(1<<17) = 130000

    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        for(int i = 0; i < 2*n-1; i++) dat[i] = 0;
    }

    void update(int k, int a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = dat[k*2+1] + dat[k*2+2];
        }
    }

    ll query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        else{
            ll vl = query(a,b,k*2+1,l,(l+r)/2);
            ll vr = query(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }
} seg;

ll n;
int a[100000];
int b[100000];
int c[100000];

bool check(int mid) {
    seg.init(2*SI+1);
    int cnt = 0;
    rep(i,n) {
        if (a[i] >= mid) {
            cnt++;
        } else {
            cnt--;
        }
        seg.update(SI+cnt,seg.dat[seg.n-1+SI+cnt]+1);
    }
    ll sum = seg.query(SI,2*SI,0,0,seg.n);
    int now = 0;
    rep(i,n) {
        if (a[i] >= mid) {
            now++;
        } else {
            now--;
        }
        seg.update(SI+now, seg.dat[seg.n-1+SI+now]-1);
        sum += seg.query(SI+now,2*SI,0,0,seg.n);
    }
    if (sum >= ((n*(n+1)/2)+1)/2) return true;
    else return false;
}

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) b[i] = a[i];
    sort(b, b+n);
    int st = -1, en = n, mid;
    while (en-st > 1) {
        mid = (st + en) / 2;
        if (check(b[mid])) {
            st = mid;
        } else {
            en = mid;
        }
    }
    cout << b[st] << endl;
}




Measured memory_bytes: 5120
#include<iostream>
#include<map>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long int lli;

const int mod = 1000000007;

int main(){
  lli N;
  cin >> N;
  map<int, int> m;
  for (int i = 1; i <= N; i++) {
    int ii = i;
    for (int j = 2; j <= N; j++) {
      if (ii % j == 0) {
	while (ii % j  == 0) {
	  m[j]++;
	  ii /= j;
	}
      }
    }
  }
  lli ans = 1;
  for(auto it = m.begin(); it != m.end(); it++) {
    ans = (ans * (it -> second + 1)) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <deque>
using namespace std;
typedef pair<int, int> i_i;
const int dh[4] = {-1, 1, 0, 0};
const int dw[4] = {0, 0, -1, 1};
const int INF = 10000000;
int H, W, sh, sw, th, tw;
char field[1000][1000];
int dp[1000][1000];

void solve() {
  // 幅優先探索
  deque<i_i> deq;
  deq.emplace_back(sh, sw);
  dp[sh][sw] = 0;
  while (!deq.empty()) {
    i_i now = deq.front();
    deq.pop_front();
    int ch = now.first;
    int cw = now.second;
    int cd = dp[ch][cw];
    //歩いて移動する
    for (int i = 0; i < 4; i++) {
      int nh = ch + dh[i];
      int nw = cw + dw[i];
      if (0 > nh || nh >= H || 0 > nw || nw >= W || field[nh][nw] == '#') {
        continue;
      }
      if (dp[nh][nw] > cd) {
        dp[nh][nw] = cd;
        deq.emplace_front(nh, nw);
      }
    }
    //ワープして移動する
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int nh = ch + i;
        int nw = cw + j;
        if (0 > nh || nh >= H || 0 > nw || nw >= W || field[nh][nw] == '#') {
          continue;
        }
        if (dp[nh][nw] > cd + 1) {
          dp[nh][nw] = cd + 1;
          deq.emplace_back(nh, nw); //　後方にpushする
        } 
      }
    }
  }
  
  if (dp[th][tw] == INF) cout << "-1";
  else cout << dp[th][tw];
}

int main() {

  cin >> H >> W >> sh >> sw >> th >> tw;
  sh--;sw--;th--;tw--;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
      dp[i][j] = INF;
    } 
  }
  
  solve();
}

Measured memory_bytes: 8492
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
    int n,k;
    cin >> n >> k;
    double ans = 0.0;
    // if(n > k)
    // {
    //     vector<int> count;
    //     for(int i = k-1;i >= 0;i--){
    //       count.push_back(i);
    //     }
    //     int num = 1;
    //     int cn_z = 0;
    //     while(true){
    //       for(int i = 0;i < count.size();i++){
    //         if(count[i]*2 >= k){
    //           ans += pow(0.5,num);
    //           cout << num << endl;
    //           count[i] = 0;
    //           cn_z++;
    //         }
    //         else if(count[i] == 0) cn_z++;
    //         else count[i] *= 2;
    //       }
    //       num++;
    //       if(cn_z == count.size()) break;
    //       cn_z = 0;
    //     }
    //     ans = n-ans;
    //     ans /= n;
    //     // cout << ans << endl;
    //     cout << ans << endl;
    //     printf("%.12f\n",ans);
    // }
    // else{
      vector<int> count;
      for(int i = 1;i <= n;i++){
        count.push_back(i);
      }
      int num = 0;
      int cn_z = 0;
      while(true){
        for(int i = 0;i < count.size();i++){
          if(count[i] >= k){
            ans += pow(0.5,num);
            // cout << num << endl;
            count[i] = 0;
            cn_z++;
          }
          else if(count[i] == 0) cn_z++;
          else count[i] *= 2;
        }
        num++;
        if(cn_z == count.size()) break;
        cn_z = 0;
      }
      ans /= n;
      // cout << ans << endl;
      printf("%.12f\n",ans);
    // }
}


Measured memory_bytes: 892
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
arys = []
for i in range(N):
    tmp = input()
    ary = [int(a) - 1 for a in tmp.split()]
    arys.append(ary)


s = set([i for i in range(M)])
i_s = [0 for i in range(len(arys))]
min_num = None
while len(s) > 0:
    select_num = [0 for i in range(M)]
    max_v = None
    max_k = None
    for j, ary in enumerate(arys):
        while ary[i_s[j]] not in s:
            i_s[j] += 1
        select_num[ary[i_s[j]]] += 1
        tmp = select_num[ary[i_s[j]]]
        if max_v is None or max_v < tmp:
            max_v = tmp
            max_k = ary[i_s[j]]
    if min_num is None or min_num > max_v:
        min_num = max_v
    s.remove(max_k)
print(min_num)


Measured memory_bytes: 4212
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

x,y=map(int,input().split())
if x in a:
    if y in a:
        print("Yes")
    else:
        print("No")
elif x in b:
    if y in b:
        print("Yes")
    else:
        print("No")
else:
    if x in c and y in c:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define N 2001
int n, k;
ll fac[N * N], inv[N * N], dp[N][N] = {1};
ll Qpow(ll x, ll n) {
    ll s = 1;
    while (n) {
        if (n & 1) s = s * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return s;
}
ll C(int n, int m) {
    if (m < 0 || m > n) return 0;
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
    scanf("%d%d", &n, &k);
    if (k == 1) {
        puts("1");
        return 0;
    }
    for (int i = fac[0] = 1; i <= n * k; i++) fac[i] = fac[i - 1] * i % mod;
    inv[n * k] = Qpow(fac[n * k], mod - 2);
    for (int i = n * k; i; i--) inv[i - 1] = inv[i] * i % mod;
    for (int i = 0; i <= n; i++)
        for (int j = i; j <= n; j++) {
            dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod;
            ll s = C(k * (n - i) - (j - i) - 1, k - 2) + dp[i + 1][j];
            dp[i + 1][j] = dp[i][j] * s % mod;
        }
    printf("%lld", dp[n][n] * fac[n] % mod);
    return 0;
}

Measured memory_bytes: 85376
#include <stdio.h>

int main() {
  int X, A, B;
  scanf("%d %d %d", &X, &A, &B);
  int distA = (X > A) ? X - A : A - X;
  int distB = (X > B) ? X - B : B - X;
  (distA < distB) ? puts("A") : puts("B");
  return 0;
}

Measured memory_bytes: 2080
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int sum=0,N,L,absmin=INT32_MAX,in=0;
    cin>>N>>L;
    REP(i,N){
        int a = L+(i+1)-1;
        if(absmin>abs(a)){
            in=i;
            absmin=abs(a);
        }
        sum+=a;
    }
    cout<<sum-(L+(in+1)-1)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
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; }

signed main(){
    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

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

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

int main(){
  int H, W, N;
  cin >> H >> W;
  cin >> N;

  int a[N];
  REP(i, N) cin >> a[i];
  int ans[H][W] ={};

  int colorvec[H*W];
  int work=0;
  //iは色,a[i]は色のマス数
  REP(i, N){
    REP(j, a[i]){
      colorvec[work + j] = i+1;
    }
    work += a[i];
  }

  REP(i, H){
      REP(j, W){
        if(i%2 != 0) ans[i][j] = colorvec[i*W + j];
        else ans[i][j] = colorvec[i*W + W - j -1];
      }
  }

  REP(i, H){
      REP(j, W){
        cout << ans[i][j] << " ";
      }
      cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 384
terrain = list(input())

down_slopes = []
puddles = []
total_cross_section = 0

for (position, slope) in enumerate(terrain):
    if slope == '\\' :
        down_slopes.append(position)
    elif slope == '/' and down_slopes:
        last_position = down_slopes.pop()
        total_cross_section += position - last_position
        
        puddle_cross_section = 0
        while puddles:
            puddle = puddles.pop()
            if puddle[0] <= last_position:
                puddles.append(puddle)
                break
            puddle_cross_section += puddle[1]
        puddle_cross_section += position - last_position
        puddles.append([last_position,puddle_cross_section])
        
print(total_cross_section)
ans = [str(len(puddles))]
ans.extend( [str(puddle[1]) for puddle in puddles ] )
print(' '.join(ans ) )


Measured memory_bytes: 6388