akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif


int32_t main(){    
	#ifdef XOX
		freopen("Input.txt", "r", stdin);
		freopen("Output.txt", "w", stdout);
	#endif
 
	ios::sync_with_stdio(!cin.tie(NULL));

	int h, w, k;
	cin >> h >> w >> k;
	char tmp;
	int arr[h][w];
	int cnt = 0;

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cin >> tmp;
			arr[i][j] = tmp == '#';
			cnt += arr[i][j];
		}
	}
	int ans = 0;

	for(int a = 0; a < (1 << h); a++) {
		for(int b = 0; b < (1 << w); b++) {
			int tmp = 0;
			for(int i = 0; i < h; i++) {
				if(!(a&(1 << i)))	continue;
				for(int j = 0; j < w; j++) {
					tmp += (arr[i][j] and !(a&(1 << i) and b&(1 << j)));
					//cerr << tmp << " ";
				}
			}

			for(int i = 0; i < w; i++) {
				if(!(b&(1 << i)))	continue;
				for(int j = 0; j < h; j++) {
					tmp += arr[j][i];
					//cerr << tmp << " ";
				}
			}

			if((cnt - tmp) == k)	ans++;//  cerr << a << " " << b << " " << tmp << " " << cnt << "\n";
		}
	}

	cout << ans;
}

Measured memory_bytes: 3600
/****************
 *		*
 * ALDS_1_5_C   *
 * KouchCurve	*
 *		*
 * 2019/08/19	*
 *		*
 ***************/

#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

const double a = M_PI * 60.0/ 180.0;

//x座標,y座標を格納する型
typedef struct{
  double x;
  double y;
}Point;

/*
コッホ曲線を生成する関数
*/
void kouch(int count,Point p1,Point p2){
  if(count < 1) return;

  Point s,t,u;

  s.x = (2.0 * p1.x+ 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y+ 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x+ 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y+ 2.0 * p2.y) / 3.0;
  u.x = (t.x - s.x) * cos(a) - (t.y - s.y) * sin(a) + s.x;
  u.y = (t.x - s.x) * sin(a) + (t.y - s.y) * cos(a) + s.y;

  kouch(count-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  kouch(count-1,s,u);
  printf("%.8f %.8f\n",u.x ,u.y);
  kouch(count-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  kouch(count-1,t,p2);
  
  return;
}

int main(void){
  Point p1 = {0,0};
  Point p2 = {100,0};
  int n=0;

  cin >> n;
  
  printf("%.8f %.8f\n",p1.x,p1.y);
  kouch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
  
  return 0;
}



Measured memory_bytes: 3152
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	int x;
	cin>>x;
	cout<<1-x<<endl;	
}

Measured memory_bytes: 3604
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        elif time % F[j]:
            time += F[j] - (time % F[j])
        time += C[j]

    print(time)


Measured memory_bytes: 3064
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main{
	static double eps = 0.0000000001;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if(n == 0) break;
			Point2D.Double[] p = new Point2D.Double[n];
			for(int i = 0; i < n; i++) {
				String[] s = sc.next().split(",");
				double x = Double.parseDouble(s[0]);
				double y = Double.parseDouble(s[1]);
				p[i] = new Point2D.Double(x, y);
			}
			int max = 0;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					Point2D.Double[] t = CircleCross.getCross(p[i], p[j]);
					if(t == null) continue;
					boolean flag = false;
					if(t.length == 2) flag = true;
					int cnt1 = 0;
					int cnt2 = 0;
					for(int k = 0; k < n; k++) {
						if (Point2D.Double.distance(t[0].getX(), t[0].getY(), p[k].getX(), p[k].getY()) -1.0 <= 10e-6) {
                            cnt1++;
                        }
						if (flag && Point2D.Double.distance(t[1].getX(), t[1].getY(), p[k].getX(), p[k].getY()) -1.0 <= 10e-6) {
                            cnt2++;
                        }
					}
					max = Math.max(max, cnt1);
					max = Math.max(max, cnt2);
				}
			}
			System.out.println(max);
		}
		sc.close();
	}
}

class CircleCross {
static double DIF = 10e-6;
    public static Point2D.Double[] getCross(Point2D.Double p1, Point2D.Double p2) {
        Point2D.Double[]  cRet = null;
        if (p1 != null && p2 != null) {
            double  length = p1.distance(p2);
            if (length <= DIF) {
                cRet    = new Point2D.Double[1];
                cRet[0] = new Point2D.Double(p1.x, p1.y);
            } else if (length <= 2.0 + DIF) {
                double  theta = Math.atan2(p2.y - p1.y, p2.x - p1.x);
                double  alpha = Math.acos(length / 2.0);

                cRet    = new Point2D.Double[2];
                cRet[0] = new Point2D.Double(p1.x + Math.cos(theta + alpha), p1.y + Math.sin(theta + alpha));
                cRet[1] = new Point2D.Double(p1.x + Math.cos(theta - alpha), p1.y + Math.sin(theta - alpha));
            }
        }

        return cRet;
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> c(n - 1), s(n - 1), f(n - 1);
  rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

  vector<int> t(n);
  rep(i, n - 1) {
    for (int j = i; j < n - 1; j++) {
      if (t[i] < s[j]) {
        t[i] = s[j];
      } else if (t[i] % f[j] != 0) {
        t[i] += f[j] - t[i] % f[j];
      }
      t[i] += c[j];
    }
  }

  rep(i, n) cout << t[i] << endl;
  return 0;
}


Measured memory_bytes: 3552
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()

if A > B:
    ans = 0
elif N == 1 and A < B:
    ans = 0
else:
    ans = (N - 2) * (B - A) + 1

print(ans)


Measured memory_bytes: 10564
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    ans=min(A[x-1]+B[y-1]-c,ans)
print(ans)

Measured memory_bytes: 70892
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){
	int N;
	cin >> N;
	if (N%2 == 0)
		cout << 1/2.0 << endl;
	else cout << (N+1)/2.0/N << endl;

	return 0;
}

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

int main(){
    int X, Y;
    cin >> X >> Y;
    bool can = false;

    if((Y % 2) == 1){
        cout << "No" << endl;
    }else{
        for (int a = 0; a <= X; a++){
            if((4 * X - 2 * a) == Y){
                can = true;
            }
        }
        if (can) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3560
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI2(N,M);
    vector<unordered_set<int>> neighbors(N);
    FOR(i,M){
        GI2(a,b);
        neighbors[a-1].insert(b-1);
        neighbors[b-1].insert(a-1);
    }
    FOR(i,N){
        if(neighbors[i].count(0)){
            if(neighbors[i].count(N-1)){
                print("POSSIBLE");
                return 0;
            }
        }
    }
    print("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 31944
N = int(input())
h = list(map(int, input().split(" ")))

dp = [float("inf")]*(N)
dp[0] = 0

for i in range(N-1):
    dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i])
    if i + 2 < N:
        dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i])

print(dp[-1])

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,a,b,ans;
  cin >> n >> m;
  ans = m;
  bool f = true;
  rep(i,n){
    cin >> a >> b;
    m += a - b;
    ans = max(ans,m);
    if(m < 0){
      f = 0;
    }
  }
  if(f) cout << ans << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
int main(void){
    int N; cin >> N;
    string s; cin >> s;
    int one=0, two=0, three=0;
    int cnt=0;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                one=two=three=0;
                for(int x=0;x<N;x++){
                    
                    if(one==0){
                        if(i==(s[x]-'0')){
                            one=1; continue;
                        }else{
                            continue;
                        }
                    }else if(two==0){
                        if(j==(s[x]-'0')){
                            two=1; continue;
                        }else{
                            continue;
                        }
                    }else if(three==0){
                        if(k==(s[x]-'0')){
                            cnt++;
                            one=two=three=0;
                            break;
                        }else{
                            continue;
                        }
                    }
                    
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int dist[105][105];
int main(){
    int n,m;cin >> n >> m;
    vector<int> a(m),b(m),c(m);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dist[i][j]=INF;
            if(i==j) dist[i][j]=0;
        }
    }
    for(int i=0;i<m;i++){
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    int ans=0;
    for (int i = 0; i < m; i++)
    {
        if(dist[a[i]][b[i]]<c[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

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

ll mod = 1e9+7;

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

  int n;
  cin >> n;
  string ret = "No";
  for(int i = 1;i <= 9;i++){
    if(n%i == 0 && n / i <= 9)ret = "Yes";
  }
  cout << ret << endl;
}


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

/**
 * C - Fennec vs Monster
 * フェネックは N 体のモンスターと戦っています。
 * i 番目のモンスターの体力は Hi です。
 * フェネックは次の2 種類の行動を行うことができます。
 * 攻撃：モンスターを1体選んで攻撃することで、そのモンスターの体力を 1 減らす
 * 必殺技：モンスターを1 体選んで必殺技を使うことで、そのモンスターの体力を 0 にする
 * 攻撃と必殺技以外の方法でモンスターの体力を減らすことはできません。
 * 全てのモンスターの体力を0 以下にすればフェネックの勝ちです。
 * フェネックが K 回まで必殺技を使えるとき、モンスターに勝つまでに行う攻撃の回数 (必殺技は数えません) の最小値を求めてください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // モンスターの数
        int n = sc.nextInt();
        // フェネックが必殺技を使える回数
        int k = sc.nextInt();

        // 必殺技を全てのモンスターに使用できる場合
        if( n <= k ) {
            System.out.println( 0 );
        }
        else {
            // 各モンスターの体力
            List<Integer> h = new ArrayList<Integer>();

            for( int i = 0; i < n; i++ ) {
                h.add( sc.nextInt() );
           }
            // リストをソート
            Collections.sort( h , Collections.reverseOrder() );
//            System.out.println( h);

            long sum = 0;
            for( int i = 0; i < n; i++ ) {
                if( k <= 0 ) {
                    sum += h.get( i );
                }
                else {
                    --k;
                }
            }
            System.out.println( sum );
        }

        sc.close();
    }
}

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

int n;
char s[110];
int a[30], b[30], ans;


int main(){
    while(cin>>n){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0; i<n; i++){
            cin>>s[i];
            b[s[i]-'a']++;
        }

        ans = 0;
        for(int i=0; i<n; i++) {
            a[s[i]-'a']++;
            b[s[i]-'a']--;

            int t = 0;
            for(int j=0; j<27; j++){
                if(a[j]&&b[j])
                    t++;
            }

            ans = max(ans,t);
        }

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

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    arr, arr2, arr3, arr4, arr5 = [], [], [], [], []
    n.times{
        arr << gets.chomp
        arr2 << arr.last.split("")
        arr4 << arr.last.reverse
    }
    max = 0
    arr.each{|str| str.split('0').each{|item| max = item.length if max < item.length}}
    arr2.transpose.each{|ar| ar.join.split('0').each{|item| max = item.length if max < item.length}}
    0.upto(n-1){|y|
        temp = []
        (y+1).times{|i| temp << arr[y-i][i]}
        arr3 << temp
    }
    1.upto(n-1){|j|
        temp = []
        (n - j).times{|i| temp << arr[n-1-i][i+j]}
        arr3 << temp
    }
    arr3.each{|ar| ar.join.split('0').each{|item| max = item.length if max < item.length}}
    0.upto(n-1){|y|
        temp = []
        (y+1).times{|i| temp << arr4[y-i][i]}
        arr5 << temp
    }
    1.upto(n-1){|j|
        temp = []
        (n - j).times{|i| temp << arr4[n-1-i][i+j]}
        arr5 << temp
    }
    arr5.each{|ar| ar.join.split('0').each{|item| max = item.length if max < item.length}}
    puts max
end



Measured memory_bytes: 28500
import itertools
import numpy as np
n, d = map(int, input().split())

points = [list(map(int, input().split())) for x in range(n)]

cnt = 0
for p1, p2 in itertools.combinations(points, r=2):
    d = np.linalg.norm(np.array(p1) - p2)
    if d == int(d):
        cnt += 1
print(cnt)


Measured memory_bytes: 12424
#include <bits/stdc++.h>
#define rip(a,b) for(int (a)=0;(a)<(b);(a)++)
using namespace std;

int main(){
    long long K,N;
    cin >> K >> N;
    vector<long long>A(N);
    for(long long i=0;i<N;i++){
        cin >> A[i];
    }

    long long sum=0;
    long long ban=0;
    vector<long long>cost(N);
    for(long long i=0;i<N;i++){
        if(i==N-1){
            cost[i]=K-A[i]+A[0];
            continue;
        }

        cost[i]=A[i+1]-A[i];
    }
    // for(int i=0;i<N;i++){
    //     cout << cost[i] << endl;
    // }
    for(long long i=0;i<N;i++){
        ban=max(ban,cost[i]);
        sum+=cost[i];
    }

    cout << sum-ban << endl;

}



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

int main() {
	int x, y;
	cin >> x >> y;

	int a[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };

	if (a[x] == a[y]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int n;
string s;
vector<int> ans;
int f = -1;

int main(){
	cin >> n >> s;
	vector<int> si(n);
	rep(i, n){
		if(s.at(i) == 'o'){
			si.at(i) = 1;
		}else{
			si.at(i) = -1;
		}
	}
	vector<vector<int>> a(4, vector<int>(n));
	vector<int> b(4);
	ans = vector<int>(n);
	rep(i, 4) rep(j, n) a.at(i).at(j) = 22;
	if(s.at(0) == 'o'){
		a.at(0).at(0) = 1; a.at(0).at(1) = 1; b.at(0) = 1;
		a.at(1).at(0) = 1; a.at(1).at(1) =-1; b.at(1) =-1;
		a.at(2).at(0) =-1; a.at(2).at(1) = 1; b.at(2) =-1;
		a.at(3).at(0) =-1; a.at(3).at(1) =-1; b.at(3) = 1;
	}else{
		a.at(0).at(0) = 1; a.at(0).at(1) = 1; b.at(0) =-1;
		a.at(1).at(0) = 1; a.at(1).at(1) =-1; b.at(1) = 1;
		a.at(2).at(0) =-1; a.at(2).at(1) = 1; b.at(2) = 1;
		a.at(3).at(0) =-1; a.at(3).at(1) =-1; b.at(3) =-1;
	}
	rep(i, 4){
		for(int j=2; j<n; j++){
			a.at(i).at(j) = a.at(i).at(j-2) * a.at(i).at(j-1) * si.at(j-1); 
		}
		if(a.at(i).at(n-1) == b.at(i)){
			if(si.at(n-1) * a.at(i).at(n-2) * a.at(i).at(n-1) == a.at(i).at(0)){
				f = i;
				break;
			}
		}
	}
	if(f != -1){
		rep(i, n){
			if(a.at(f).at(i) == -1){
				cout << 'W';
			}else{
				cout << 'S';
			}
		}
		cout << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 2936
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n = read::<usize>();
    let mut hs = read_vec::<usize>();

    let mut prev_h = 1_000_000_000;
    for h in hs.iter_mut().rev() {

        if *h > prev_h {
            *h -= 1;
        }
        if *h > prev_h {
            println!("No");
            return;
        }
        prev_h = *h;
    }
    println!("Yes");
}

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

using namespace std;

using ll = long long;
using dd = double;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<dd>;
using vb = vector<bool>;

template <class T, class V>
istream& operator>>(istream& in, pair<T, V>& pair) {
    return in >> pair.first >> pair.second;
}

template <class T>
istream& operator>>(istream& in, vector<T>& elements) {
    for (size_t i = 0; i < elements.size(); ++i) {
        in >> elements[i];
    }
    return in;
}

template <class Container, class Element>
bool Contains(const Container& container, const Element& element) {
    return container.find(element) != container.end();
}

template <class T>
ostream& operator<<(ostream& out, const vector<T>& elements) {
    for (const T& element : elements) {
        out << element << ' ';
    }
    return out;
}

template <class T, class V>
ostream& operator<<(ostream& out, const pair<T, V>& pair) {
    out << pair.first << ' ' << pair.second;
}

#define FOR(i,n) for(size_t i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(c) sort((c).begin(), (c).end())

int main() {
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vi d(n);
    cin >> d;
    
    SORT(d);
    
    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        cout << d[n / 2] - d[n / 2 - 1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000


int main(){
	int N;cin>>N;
	vector<long long> A(N+1);
	vector<long long> B(N);
	for(int i=0;i<N+1;i++){
		cin>>A[i];
	}
	for(int i=0;i<N;i++){
		cin>>B[i];
	}
	
	long long ans = 0;
	for(int i=0;i<B.size();i++){
		if(B[i]>=A[i]){
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
			
		}
		else{
			ans += B[i];
			A[i]-=B[i];
			B[i] = 0;
			
		}
		if(B[i]>=A[i+1]){
			ans += A[i+1];
			B[i]-=A[i+1];
			A[i+1] = 0;
			
		}
		else{
			ans += B[i];
			A[i+1] -= B[i];
			B[i] = 0;
		}
	}
	
	cout<<ans<<endl;
	

	
	return 0;
}




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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[64][2][2][2];

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

	dp[63][0][0][0] = 1;
	int L, R;
	cin >> L >> R;

	rrep(d, 0, 63)
	{
		int ld = (L >> d) & 1;
		int rd = (R >> d) & 1;
		rep(lf, 0, 2)rep(rf, 0, 2)rep(msbf, 0, 2)
		{
			rep(x, 0, 2)rep(y, 0, 2)
			{
				if (x == 1 && y == 0)continue;
				if (x == 0 && y == 1 && msbf == 0)continue;
				if (lf == 0 && ld==1&&x == 0)continue;
				if (rf == 0 && rd == 0 && y == 1)continue;
				int nlf = lf, nrf = rf, nmsbf = msbf;
				if (x == 1 && ld == 0)nlf = 1;
				if (y == 0 && rd == 1)nrf = 1;
				if (x == 1 && y == 1)nmsbf = 1;
				dp[d][nlf][nrf][nmsbf] += dp[d + 1][lf][rf][msbf];
				dp[d][nlf][nrf][nmsbf] %= MOD;
			}
		}
	}

	int ans = 0;
	rep(lf, 0, 2)rep(rf, 0, 2)
	{
		ans = (ans + dp[0][lf][rf][1]) % MOD;
	}
	cout << ans << endl;

	return 0;
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int INF = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  char p[s.size()];
  for (int i = 0; i < s.size(); i++) {
    p[i] = s[s.size() - 1 - i];
    if (p[i] == 'b')
      p[i] = 'd';
    else if (p[i] == 'd')
      p[i] = 'b';
    else if (p[i] == 'q')
      p[i] = 'p';
    else if (p[i] == 'p')
      p[i] = 'q';
    if (p[i] != s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

void a()
{
	int n;
	cin >> n;
	double res = (double)((n+1)/2) / n;
	cout << res << endl;
}

int main()
{
	a();
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 200010
string s;
ll n,k;
int main(){
    cin>>n>>k>>s;
    lol(i,n){
	if((s[i]=='A')xor (i&1)){
	    k--;
	    if(!k){
		cout<<'B';
		for(int j=i+1;j<n;j++){
		    if(i&1){
			if(s[j]=='A')cout<<'B';
			if(s[j]=='B')cout<<'A';
		    }
		    else cout<<s[j];
		}
		for(int j=0;j<i;j++){
		    if((i&1) xor (j&1))cout<<'A';
		    else cout<<'B';
		}
		cout<<endl;
		return 0;
	    }
	}
	k--;
	if(!k){
	    for(int j=i+1;j<n;j++){
		if((i&1)==0){
		    if(s[j]=='A')cout<<'B';
		    if(s[j]=='B')cout<<'A';
		}
		else cout<<s[j];
	    }
	    for(int j=0;j<=i;j++){
		if((i&1) xor (j&1))cout<<'B';
		else cout<<'A';
	    }
	    cout<<endl;
	    return 0;
	}
    }
    if(n%2==0){
	lol(i,n){
	    if(i&1)cout<<'A';
	    else cout<<'B';
	}cout<<endl;
	return 0;
    }
    if(k&1)cout<<'B';
    else cout<<'A';
    lol(i,n-1){
	if(i&1)cout<<'A';
	else cout<<'B';
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n; 
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n){
        if(i%2==0 && a[i]%2==1)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;

    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if(y + r <= H && x + r <= W && y - r >= 0 && x - r >= 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;    
}

Measured memory_bytes: 584
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    H,W = map(int,input().split())
    C = [ input().rstrip() for i in range(H) ]

    for i in range(H):
        temp = C[i]
        print(temp)
        print(temp)



main()


Measured memory_bytes: 3060
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

left = [0 for i in range(N+1)]
right = [0 for i in range(N+1)]

for i in range(N):
    left[i] = gcd(left[i-1], A[i])

for i in reversed(range(N)):
    right[i] = gcd(right[i+1], A[i])

ans = 1

for i in range(N):
    l = left[i-1]
    r = right[i+1]
    if gcd(l, r) > ans:
        ans = gcd(l, r)

print(ans)



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      cnt++;
    } else {
      cnt--;
    }
    ans = max(ans, cnt);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import heapq
import copy
import bisect
from collections import deque

n = int(input())
a = []
b = []
tmp_a = []
tmp_b = []
flag = True

for _ in range(n):
	a_dash,b_dash = map(int,input().split())
	tmp_a.append(a_dash)
	tmp_b.append(b_dash)

k = zip(tmp_b,tmp_a)
sorted_k = sorted(k)
for b_dash,a_dash in sorted_k:
	a.append(a_dash)
	b.append(b_dash)

t = 0
qa = deque(a)
qb = deque(b)

for i in range(n):
	minimum_a = qa.popleft()
	minimum_b = qb.popleft()
	t += minimum_a
	if t > minimum_b:
		flag = False
		break

if flag:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 112932
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

using namespace std;

int n;
int k;

vector<pair<long long int,long long int> > v;
int main() {
	cin >> n>>k;
	for (int i = 0; i < n; i++) {
		long long int a,b;
		scanf("%lld%lld", &a,&b);
		v.push_back(make_pair(a,b) );
	}
	vector<bool> vv;
	for (long long int i = 0; i < 30; i++) {
		vv.push_back(((k >> i) & 1LL));
	}
	reverse(vv.begin(), vv.end());
	long long int ava = (1 << 30);
	int cnt = 30;
	long long int can = (1 << 30);
	long long int ans = 0;
	while(1){
		cnt--;
		if (cnt == -2)break;
		if (cnt >= 0)ava |= (1 << cnt);
		can|=(((k >> (cnt+1)) & 1) << (cnt+1) );
		if (cnt == -1 || (k >> cnt) & 1) {

		}
		else {
			continue;
		}
		long long int sum = 0;
		for (int j = 0; j < v.size(); j++) {
			long long int g = (v[j].first & ava);
			if ((g&can) == g) {
				sum += v[j].second;
			}
		}
		ans = max(ans, sum);
	}
	printf("%lld\n", ans);
return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int x,y,z,e;
  while( cin >> e,e ){
    int ret = 999999999;
    for(int y = 0 ; y*y <= e ; y++ ){
      for(int z = 0 ; z*z*z <= e ; z++ ){
	if(e - (y*y + z*z*z) >= 0)x = e - (y*y + z*z*z);
	  ret = min(ret,x+y+z);
      }
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();

		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < N; i++) {
			map.put(i, 0);
		}
		for (int i = 0; i < Q; i++) {
			int in = sc.nextInt() - 1;
			map.put(in, map.get(in) + 1);
		}
		for (int i = 0; i < N; i++) {
			int score = K;
			score = score - (Q - map.get(i));
			if (score <= 0) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 71424
import java.util.Arrays;
import java.util.Scanner;

class Main{
	
	public static void main (String[] args){
		Scanner sn = new Scanner( System.in );
		int x = sn.nextInt();
		int[] a = new int[3];
		while(sn.hasNext()){
            for(int i=0;i<3;i++)
                a[i] = sn.nextInt();                
            Arrays.sort(a);
            if(a[2]*a[2] == a[0]*a[0] + a[1]*a[1])
                System.out.println("YES");
            else
                System.out.println("NO");
        }
		
		
	}
	
} 

Measured memory_bytes: 13000
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem176c(n, a))
}

fun problem176c(n: Int, a: List<Long>): Long {
    val dp = LongArray(n) { 0L }
    var sum = 0L
    dp[0] = a[0]
    for (i in 0 until a.size - 1) {
        var diff = dp[i] - a[i + 1]
        if (diff < 0) diff = 0
        dp[i + 1] = a[i + 1] + diff
        sum += diff
    }
    return sum
}

Measured memory_bytes: 66352
#include <iostream>
#include <math.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main (){

        const int nmax=40,abmax=10,inf = 1000000;
        int a[nmax],b[nmax],c[nmax];
        int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

        int ma,mb,n;
        cin >> n >> ma >> mb;

        rep(i,n){
                cin >> a[i] >> b[i] >> c[i];
        }

        for(int i = 0; i <= n; ++i) {
                for(int ca = 0; ca <= nmax*abmax; ++ca) {
                        for(int cb=0; cb<=nmax*abmax; cb++) {
                                dp[i][ca][cb]=inf;
                        }
                }
        }

        dp[0][0][0]=0;

        for(int i = 0; i < n; ++i) {
                for(int ca = 0; ca <= nmax*abmax; ++ca) {
                        for(int cb = 0; cb <= nmax*abmax; ++cb) {
                                if(dp[i][ca][cb]==inf) continue;
                                dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
                                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
                        }
                }
        }


        int ans=inf;
        for(int ca = 1; ca <= nmax*abmax; ++ca) {
                for(int cb = 1; cb <= nmax*abmax; ++cb) {
                        if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
                }
        }

        if(ans==inf) ans=-1;
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 25984
import numpy as np
A,B,H,M=map(int,input().split())

M_angle=M*6
h_=0
if M_angle>0: 
    h_=30/(360/M_angle)
H_angle=H*5*6+h_
Angle=abs(H_angle-M_angle)
Cos=np.cos(np.deg2rad(Angle))

ans_=(A**2)+(B**2)-(2*A*B*Cos)
ans=ans_**0.5
print(ans)

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

int main(void) {
    string S;
    int count_W = 0;
    long long ans = 0;
    int i, N = 0;

    cin >> S;
    for (N = 0; S[N] != '\0'; N++);

    for (i = 0; i < N; i++) {
        if (S[i] == 'W') {
            int plus = i-count_W;
            ans += plus;
            count_W++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum, ans, dp[110000],a[200000][10], b[2000000];
string str, ss, dd;
bool f,ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	rep(i, 3) {
		rep(j, 3) {
			cin >> a[i][j];
		}
	}
	rep(j, 2) {
		LL num = a[j][0] - a[j + 1][0];
		rep(i, 2) {
			if (num != a[j][i + 1] - a[j + 1][i + 1])
				f = 1;
		}
	}
	rep(j, 2) {
		LL num = a[0][j] - a[0][j + 1];
		rep(i, 2) {
			if (num != a[i + 1][j] - a[i + 1][j + 1])
				f = 1;
		}
	}
	yn(!f);
	return 0;
}

Measured memory_bytes: 2560
#ABC126-B
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=input()
s1=int(S[:2])
s2=int(S[2:])
if (s1>=13 or s1==0) and 1<=s2 and s2<=12:
    print("YYMM")
elif (s2>=13 or s2==0) and 1<=s1 and s1<=12:
    print("MMYY")
elif (s1>=13 or s1==0) and (s2>=13 or s2==0):
    print("NA")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 38256
from itertools import chain
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

def count_bit(x):
    res = 0
    while x:
        res += x % 2
        x >>= 1
    return res

def int2bin(x,N): 
    res = [0]*N
    for i in range(N):
        res[N-1-i] = x % 2
        x >>= 1
    return res

inf = 10**10
M = N//2 # the n of odd index
ans = inf
for b in range(2**N):
    valid = True 
    if count_bit(b) == M:
        odd_index = int2bin(b,N) # 1 : odd
        evens = []
        odds = []
        for i in range(N):
            if odd_index[i]:
                if i % 2:
                    odds.append((A[i],i))
                else:
                    odds.append((B[i],i))
            else:
                if i % 2:
                    evens.append((B[i],i))
                else:
                    evens.append((A[i],i))
        SE = sorted(evens)
        SO = sorted(odds)
        L = [None]*N
        L[::2] = SE
        L[1::2] = SO
        for (a,_),(b,_) in zip(L,L[1:]):
            if a > b:
                valid = False
                break
        if valid:
            L = list(zip(L,range(N)))
            L = sorted(L,key=lambda x : x[0][1])
            L = [(a,c) for (a,b),c in L]
            temp = 0
            for i in range(N):
                for j in range(i):
                    if L[j] > L[i]:
                        temp += 1
            ans = min(temp,ans)

if ans == inf:
    ans = -1
print(ans)





Measured memory_bytes: 75868
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  bool f=0;
  rep(i,3){
    if(n%10==7) f=1;
    n/=10;
  }
  if(f) puts("Yes");
  else puts("No");

  return 0;
}


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

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B, C;
    cin >> A >> B >> C;
    swap(A,B);
    swap(A,C);
    cout << A << " " << B << " " << C << "\n";
}

Measured memory_bytes: 256
def main():

    N = int(input())
    S = {}
    cnt = 0
    for _ in range(N):
        s = list(input())
        s.sort()
        s = "".join(s)
        if s not in S:
            S[s] = 0
        else:
            S[s] += 1
            cnt += S[s]
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 17932
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
int N, K;
int A[200010];
std::vector<int> S;
int main() {
	std::cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		A[tmp]++;
	}
	S.emplace_back(0);
	for (int i = 1; i <= N; i++) {
		S.emplace_back(A[i]);
	}
	std::sort(S.rbegin(), S.rend());
	for (int i = 0; i < K; i++) {
		N -= S[i];
	}
	std::cout << N << std::endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,M;
	cin >> N >> M;
	vector< vector<int> > G(N);
	long long ans =1, mod =1000000007;
	for(int i =0; i < M; i++) {
		ans =(ans*2)%mod;
		int x,y;
		cin >> x >> y;
		if(x == 1 && y == 2) continue;
		G[N-x].push_back(N-y);}

	vector< vector<int> > deg(N,vector<int>(1<<N,0));
	for(int i =0; i < N; i++) for(int j =0; j < (1<<N); j++)
		ALL_THE(G[i],it) deg[i][j] +=(j>>*it)&1;

	vector<long long> cnt(1<<N,0);
	cnt[0] =1;
	for(int i =0; i < (1<<(N-2)); i++) if(cnt[i] != 0) {
		vector<int> v;
		int w,w2;
		for(int j =0; j < N; j++) if(((i>>j)&1) == 0) v.push_back(j);
		int sz =v.size();
		for(int j =0; j < (1<<(sz-2)); j++) for(int k =0; k < 2; k++) {
			w =0;
			for(int a =0; a < sz-2; a++) if((j>>a)&1) w +=1<<v[a];
			if(k) w +=(1<<(N-2))*3;
			if(w == 0) continue;
			w2 =(1<<N)-1-i-w;
			long long c =1;
			for(int a =0; a < N; a++) if((w2>>a)&1) c =(c*((1LL<<deg[a][w])-1))%mod;
			for(int a =0; a < N; a++) if((w>>a)&1) c =(c*(1LL<<deg[a][w2]))%mod;
			c =(c*cnt[i])%mod;
			cnt[i+w] =(cnt[i+w]+c)%mod;}
		}

	for(int i =0; i < (1<<N); i++) if((i>>(N-1))&1) if((i>>(N-2))&1) {
		long long e =1;
		for(int j =0; j < N; j++) if(((i>>j)&1) == 0)
			ALL_THE(G[j],it) if(((i>>*it)&1) == 0) e =(e*2)%mod;
		ans =(ans-e*cnt[i])%mod;}
	if(ans < 0) ans +=mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 2556
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PA;
const int MOD = 1000000007;
const ll INF=2e18;

ll N;
ll A,B,C;
string S,T;
int main(){
    cin>>S>>T;
    ll cnt=0;
    for(ll i=0;i<3;i++){
            if(S[i]==T[i]){
                cnt++;
            }
    }   
    cout<<cnt;
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


vector<vector<int>> s(11);
int p[11];
int k[11];

int main(){
  int N,M;
  cin >> N >> M;
  rep(i,M) {
	cin >> k[i];
	rep(j,k[i]) {
	  int a;
	  cin >> a;
	  a--;
	  s[i].push_back(a); 
	}
  }  
  rep(i,M) cin >> p[i];


  // rep(i,M) {
  // 	for(auto itr : s[i]) cout << itr;
  // 	cout << endl;
  // }
  
  int ans = 0;	  
  vector<int> v;
  for(int bit=0; bit < (1 << N); bit++) { //点灯電球は決め打たれる
	vector<bool> isturn(11,0);
	for(int i = 0; i < N; i++) {
	  if(bit & (1 << i)) {
		isturn[i] = true;
	  }
	}

	// for (auto itr : isturn) cout << itr;
	// cout << endl;

	
	bool f = true;
	rep(i,M) {
	  int mo = 0;
	  rep(j,k[i]) {
		if(isturn[s[i][j]]) {
		  mo++;
		}
	  }
	  if(mo%2 != p[i]) {
		f = false;
		break;
	  }
	}
	if(f) ans++;
  }
  cout << ans << endl;
  

  
  
  
  

  return 0;
}



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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((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 debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	int d;
	cin >> d;
	vector<int> c(26);
	rep(i,26) cin >> c[i]; 
	vector<vector<int>> s(d,vector<int>(26));
	rep(i,d) rep(j,26) cin >> s[i][j];
	rep(i,d){
		cout << 5 << endl;
	}
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

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

    bool flag = false;
    for(int i = 1; i < 340; ++i){
        if(i*i == sum){
            flag = true;
            break;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	double mind, maxd, d;
	cin >> d;
	mind = d;
	maxd = d;
	while (cin >> d){
		mind = min(mind, d);
		maxd = max(maxd, d);
	}
	cout << maxd - mind << endl;
}

Measured memory_bytes: 3144