akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main()
{
    std::string str;
    std::cin >> str;

    char current = str[0];
    int count = 0;
    for (const char c : str)
    {
        if (c != current)
        {
            ++count;
            current = c;
        }
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 512
def main():
    words = int(input())
    first_b = [""]
    last_a = [""]
    others = []
    ab = []
    for _ in range(words):
        s = input()
        if s[0] == "B" and s[-1] == "A":
            ab.append(s)
        elif s[-1] == "A":
            last_a.append(s)
        elif s[0] == "B":
            first_b.append(s)
        else:
            others.append(s)
    connect = []
    for i in range(max(len(last_a), len(first_b))):
        if i < len(last_a) - 1:
            connect.append(last_a[i])
        if i < len(first_b) - 1:
            connect.append(first_b[i])
    word = last_a[-1] + "".join(ab) + first_b[-1] + "".join(connect) + "".join(others)
    print(word.count("AB"))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3828
#include<bits/stdc++.h>
#include <array>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;

struct Problem {
	void Solve() {
		ULL N, M, V, P; cin >> N >> M >> V >> P;

		UL ans = 0;
		ULL A[100000];
		for (UL i = 0; i < N; i++) cin >> A[i];
		sort(A, A + N);
		if (V >= P) {
			N -= P - 1;
			V -= P - 1;
			ans += P;
			reverse(A, A + N);
			LL S = M;
			for (UL i = 1; i < N; i++) {
				if (A[i] + M < A[0]) break;
				S -= (A[i - 1] - A[i]) * i;
				if (V * M <= S + (N - i) * M) ans++;
				S += M;
			}
		}
		else {
			N -= P - 1;
			V = 1;
			ans += P;
			reverse(A, A + N);
			for (UL i = 1; i < N; i++) {
				if (A[0] <= A[i] + M) ans++;
			}
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

using namespace std;

int main(void){
    string str;
    getline(cin,str);
    int len = str.length();
    long int sum =0;
    for(int bits = 0; bits < (1 << (len-1)); bits++) {
        string strsum = "";
        for(int i = 0; i < len; i++){
            strsum+=str[i];
            if((bits & ( 1 << i )) || i==len-1 ){
                sum += stol(strsum);
                strsum = "";
            }
        }
        
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// #include "ext/pb_ds/assoc_container.hpp"
// #include "ext/pb_ds/tree_policy.hpp"
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
vector<int> v;






int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a;i<b+1;i++){
        if(i%k==0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";

}


Measured memory_bytes: 3560
#include <stdio.h>

int main() {
  int n, i, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x = i;
    if (x%3 == 0) {
      printf(" %d", i);
    } else {
      do {
        if (x%10 == 3) {
          printf(" %d", i);
          break;
        }
      } while (x /= 10);
    }
  }
  putchar('\n');
  return 0;
}



Measured memory_bytes: 2040
a = input()
frm = int(a[:2])
lat = int(a[2:])


if frm > 12 and lat > 12:
    print('NA')
elif frm <= 12 and lat > 12:
    if 0<frm:
        print('MMYY')
    else:
        print('NA')    
elif frm > 12 and  lat <= 12:
    if lat > 0:
        print('YYMM')
    else:
        print('NA')
elif frm <= 12 and lat==0:
    if frm >0:
        print('MMYY')
    else:
        print('NA')
elif frm == 0 and  lat <= 12:
    if lat >0:
        print('YYMM')
    else:
        print('NA')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
long long q,h,s,d;
long long n;
cin >>q >>h >>s >>d;
cin >>n;
int z=0;
z=q*4;
int min=z;
z=q*2+h;
if(min >z){
min =z;
}
z=h*2;
if(min >z){
min =z;
}
if(min >s){
min =s;
}
int min2;
z=min*2;
if(d>z){
min2 =z;
}
else{
min2 =d;
}

if(n==1){
cout << min;
}
else{
long long k=n/2;
long long s =n%2;
long long ans =k*min2;
if(s==1){
ans=ans+min;
}
cout <<ans;
}
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)

int n, m, ans,a[5000],b[5000];

int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) scanf("%d",&a[i]);
	rep(i,m) scanf("%d",&b[i]);
	rep(i,m){
		int cnt = 0;
		rep(j,n){
			if(i+cnt>=m) break;
			if(a[j] == b[i+cnt]) cnt++;			
		}
		if(cnt>ans)ans=cnt;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


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

}


Measured memory_bytes: 3628
a=list(list(0 for i in range(3)) for i in range(3))
b=list(list(0 for i in range(3)) for i in range(3))
for i in range(3):
    a[i][0],a[i][1],a[i][2]=map(int,input().split())
n=int(input())
for i in range(n):
    s=int(input())
    for j in range(3):
        for k in range(3):
            if(a[j][k]==s):
                b[j][k]=1
if(b[0][0]+b[1][1]+b[2][2]==3 or b[2][0]+b[1][1]+b[0][2]==3):
    print("Yes")
elif(sum(b[0])==3 or sum(b[1])==3 or sum(b[2])==3):
    print("Yes")
else:
    x=0
    for i in range(3):
        if(b[0][i]+b[1][i]+b[2][i]==3):
            x=1
            break
        
    if(x==1):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int isidistin(int arr1[], int arr2[],int d)
{

   int dist=0;
   for(int i=0; i<d; i++)
   {
       dist+=pow((arr1[i]-arr2[i]), 2);
   }
   float pop = dist/1.0;
   float de = sqrt(pop);
   int d1 = sqrt(dist);
   //cout<<d1<<" "<<de<<endl;
   if(ceil(de) == d1)
   {
       return 1;
   }
   else
   {
       return 0;
   }
}
int main() {
    long long int n, d;
    int arr[11][11];
    cin>>n>>d;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<d; j++)
        {
            int p;
            cin>>p;
            arr[i][j]=p;
        }
    }
    int count=0;
    for(int i=0; i<n-1; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(isidistin(arr[i], arr[j], d) == 1)
            {
                count++;
            }
        }
    }
    /*
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<d; j++)
        {
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    cout<<count;
    return 0;
    
}

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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; ll X; cin >> X;
  ll n = 100;
  ll ans = 0;
  while(n < X){
    n += n/100;
    ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
import sys
import numpy as np

a_t=int(input())
b_t=int(input())
c_t=int(input())
d_t=int(input())
e_t=int(input())

a_d = a_t % 10
b_d = b_t % 10
c_d = c_t % 10 
d_d = d_t % 10
e_d = e_t % 10

dish_d = np.zeros(5)
dish_d[0] = a_d
dish_d[1] = b_d
dish_d[2] = c_d
dish_d[3] = d_d
dish_d[4] = e_d

if any(dish_d) == 0:
    time = (
        a_t // 10 + np.where(a_d==0, 0, 1) \
        + b_t  // 10 + np.where(b_d==0, 0, 1) \
        + c_t // 10 + np.where(c_d==0, 0, 1) \
        + d_t // 10 + np.where(d_d==0, 0, 1) \
        + e_t // 10 + + np.where(e_d==0, 0, 1)
       ) * 10
else:
    time = (
            a_t // 10 + np.where(a_d==0, 0, 1) \
            + b_t  // 10 + np.where(b_d==0, 0, 1) \
            + c_t // 10 + np.where(c_d==0, 0, 1) \
            + d_t // 10 + np.where(d_d==0, 0, 1) \
            + e_t // 10 + + np.where(e_d==0, 0, 1)
           ) * 10 - (10 - np.min(dish_d[np.nonzero(dish_d)]))
print(int(time))

Measured memory_bytes: 13280
import java.util.*;
public class Main {
    static String getCharString(String string, int index) {
        return String.valueOf(string.charAt(index));
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s0 = sc.next(), s1 = sc.next(), s2 = sc.next();
        String ans = getCharString(s0, 0) + getCharString(s1, 1) + getCharString(s2, 2);
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
 
const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const LL mod = 1e9 + 7;
 
LL a[N];
LL inv[N];
LL fa[N];
LL n;
 
void init()
{
    fa[0] = fa[1] = 1;
    inv[1] = 1;
    for(LL i = 2; i < N; i++)
    {
        fa[i] = fa[i-1] * i % mod;
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    }
    inv[0] = 1;
    for(int i = 1; i < N; i++)
        (inv[i] *= inv[i - 1]) %= mod;
}
 
LL C(LL n, LL k)
{
    LL ans = 0;
    if(k > n)
        return ans;
    ans = ((fa[n] * inv[k] % mod) * inv[n - k]) % mod;
    return ans;
}
int main()
{
    init();
    while(cin >> n)
    {
        map<LL, int>q;
        LL p = 0;
        for(int i = 1; i <= n + 1; i++)
        {
            scanf("%lld", a + i);
            if(!q[a[i]])
                q[a[i]] = i;
            else
                p = i;
        }
        for(int i = 0; i <= n; i++)
        {
            LL ans = 0;
            ans = (ans + C(n + 1, i + 1)) % mod;
            ans = (ans - C(n - p + q[a[p]], i)) % mod;
            while(ans < 0)
                ans += mod;
            printf("%lld\n", ans);
        }
    }
    return 0;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

int p[200001],r[200001],c[200001];
void init(){rep(i,200001)p[i]=i,r[i]=0,c[i]=1;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  int cx=c[x],cy=c[y];
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
  c[find(x)]=cx+cy;
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  ll n,m;
  cin >> n >> m;
  init();
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    unite(x,y);
  }
  int ans=0;
  rep(i,n) {
    if(find(i)==i) ans=max(ans,c[i]);
  }
  pr(ans);
}

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


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

template<int mod> struct modint {
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (i64) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
  #define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  #define op(o) bool operator o(modint that) const { return x o that.x; }
    op(==) op(!=) op(<) op(<=) op(>) op(>=)
  #undef op
};

using mint = modint<2>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n; cin >> n;
  vi32 a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  i32 ans = 0;
  rep(i, 30) {
    vi32 ma(n), mb(n);
    rep(j, n) ma[j] = a[j] % bit(i + 1);
    rep(j, n) mb[j] = b[j] % bit(i + 1);
    sort(all(mb));
    mint cnt = 0;
    rep(j, n) {
      mint c1 = lower_bound(all(mb), 2 * bit(i) - ma[j])
              - lower_bound(all(mb), 1 * bit(i) - ma[j]);
      mint c2 = lower_bound(all(mb), 4 * bit(i) - ma[j])
              - lower_bound(all(mb), 3 * bit(i) - ma[j]);
      cnt += c1 + c2;
    }
    if (cnt == 1) ans += bit(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
  int i,j,k,n,x,y;
  char str[1000];
  char rev[1000];
  char command[10];
  int length;

  i=0;
  while(1)
    {
      scanf("%c",&str[i]);
      if(str[i]=='\n') break;
      i++;
    }
  length=i;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      j=0;
      while(1)
	{
	  scanf("%c",&command[j]);
	  if((j==0)&&(command[j]=='\n')) j--;
	  if(command[j]==' ') break;
	  j++;
	}
      switch(command[2])
	{
	case 'p':
	  scanf("%d %d ",&x,&y);
	  for(j=x;j<=y;j++) scanf("%c",&str[j]);
	  break;
	case 'v':
	  scanf("%d %d",&x,&y);
	  for(j=x;j<=y;j++) rev[j]=str[j];
	  for(j=x;j<=y;j++) str[j]=rev[x+y-j];
	  break;
	case 'i':
	  scanf("%d %d",&x,&y);
	  for(j=x;j<=y;j++) printf("%c",str[j]);
	  printf("\n");
	}
    }
  return 0;
}

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

int main(){
	
	int N;
	int L;
	cin >> N;
	cin >> L;
	int A[210];
	int B[210];
	int sum;
	int ans;
	
	for(int i=0; i<N; i++){
		A[i]= L+i;
		sum += A[i];
		B[i]= abs(L+i);
	}
	sort(B,B+N);
	if(sum>0){
		ans = sum-B[0];
	} else {
		ans = sum+B[0];
	}
		cout << ans << endl;
		
		return 0;
}

Measured memory_bytes: 256
x=range(int(input()))
f=lambda a,b,c,d : a*d - b*c 
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:_+=f(P[j][0],P[j][1],P[j+1][0],P[j+1][1])
print(_*0.5)

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

int main(){
	int h;
	int m;
	int s;
	while(cin >> h >> m >> s){
		if(h == -1 && m == -1 && s == -1) break;
		int rest = 7200 - (3600 * h + m * 60 + s);
		int rh = rest / 3600;
		int rm = (rest % 3600) / 60;
		int rs = rest % 60;
		int rh2 = (rest * 3) / 3600;
		int rm2 = ((rest * 3) % 3600) / 60;
		int rs2 = (rest * 3) % 60;
		cout << 0 << rh << ":";
		if(rm >= 10){
			cout << rm << ":";
		}else{
			cout << 0 << rm << ":";
		}
		if(rs >= 10){
			cout << rs << endl;
		}else{
			cout << 0 << rs << endl;
		}
		cout << 0 << rh2 << ":";
		if(rm2 >= 10){
			cout << rm2 << ":";
		}else{
			cout << 0 << rm2 << ":";
		}
		if(rs2 >= 10){
			cout << rs2 <<endl;
		}else{
			cout << 0 << rs2 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,C,d[33][33],c;
int cnt[3][33]={};
int ans=inf;
int main(){
	cin>>n>>C;
	rep(i,C)rep(j,C)cin>>d[i][j];
	rep(i,n)rep(j,n)cin>>c,cnt[(i+j)%3][c-1]++;
	rep(i,C)rep(j,C)if(i!=j)rep(k,C)if(j!=k&&i!=k){
		int tmp=0;
		rep(l,C)tmp+=d[l][i]*cnt[0][l];
		rep(l,C)tmp+=d[l][j]*cnt[1][l];
		rep(l,C)tmp+=d[l][k]*cnt[2][l];
		ans=min(ans,tmp);
	}
	print(ans);
}

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

	int a,b,k;
	cin >> a>>b>>k;
	int n = min(a,b);

	for (int i = n; i>=0; i--) {
		if (a%i==0 && b%i==0) {
			k--;
			if (k==0) {
				cout << i << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <tuple>
using namespace std;

long long A, B, K;

int main() {
	vector<long long>L; cin >> A >> B >> K;
	for (int i = 1; i <= 1000000; i++) {
		if (B%i == 0 && A%i == 0) L.push_back(i);
	}
	reverse(L.begin(), L.end());
	cout << L[K - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<algorithm>
using namespace std;

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

	ans = (double(b) / double(a));

		if (ans > c) cout << c << endl;
		else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin>>N;
    if((N-90<10&&N-90>=0)||(N-9)%10==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;
const double eps = 1e-9;

int n;
vector<pair<double,double>> pts;


double get(double x1, double y1, double x2, double y2) {
    double dx = x1-x2;
    double dy = y1-y2;
    return sqrt(dx*dx + dy*dy);
}

double dist(double x, double y) {
    double hi = 0;
    for (auto p: pts) {
	hi = max(hi, get(p.first,p.second,x,y));
    }
    return hi;
}

double f(double x) {
    double lo = 0;
    double hi = 1050;

    while (hi-lo>eps) {
	double mid1 = lo + (hi-lo)/3;
	double mid2 = hi - (hi-lo)/3;
	if (dist(x,mid1) < dist(x,mid2)) {
	    hi = mid2;
	} else {
	    lo = mid1;
	}
    }
    return dist(x, lo);
}

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

    cin>>n;
    pts.resize(n);
    for (int i=0; i<n; i++) {
	cin>>pts[i].first>>pts[i].second;
    }


    double lo = 0;
    double hi = 1050;

    while (hi-lo > eps) {
	double mid1 = lo + (hi-lo)/3;
	double mid2 = hi - (hi-lo)/3;

	if (f(mid1) < f(mid2)) {
	    hi = mid2;
	} else {
	    lo = mid1;
	}
    }

    cout<<fixed<<setprecision(12)<<f(lo)<<endl;    
    return 0;
}


Measured memory_bytes: 3744
while True :
    try :
        x1, y1, x2, y2, xq, yq = map(float, input().split(','))
    except EOFError :
        break
    
    if x1 != x2 and y1 != y2:
        ## d_P1_P2 : P1-P2の傾き ##
        d_P1_P2 = (y2-y1)/(x2-x1)
        ## d_Q1_Q2 : Q1-Q2の傾き ##
        d_Q1_Q2 = -1/d_P1_P2
        
        ## 直線P1-P2 ##
        b_P1_P2 = y1 - d_P1_P2 * x1
        ## y = d_P1_P2 * x + b_P1_P2
        
        ## 直線Q1-Q2 ##
        b_Q1_Q2 = yq - d_Q1_Q2 * xq
        ## y = d_Q1_Q2 * x + b_Q1_Q2
        
        ## P1-P2 と Q1-Q2 の交点(xq3, yq3) ##
        ## d_P1_P2 * x + b_P1_P2 = d_Q1_Q2 * x + b_Q1_Q2
        ## (d_P1_P2 - d_Q1_Q2) * x = b_Q1_Q2 - b_P1_P2
        xq3 = (b_Q1_Q2 - b_P1_P2) / (d_P1_P2 - d_Q1_Q2)
        yq3 = d_P1_P2 * xq3 + b_P1_P2
        
        ## Q2の座標(xq2, yq2) ##
        xq2 = xq3 - (xq - xq3)
        yq2 = yq3 - (yq - yq3)
        
    elif x1 == x2 :
        xq2 = x1 + x1 - xq
        yq2 = yq
    
    else :
        xq2 = xq
        yq2 = y1 - (yq - y1)
    
    print('{0:.8f} {1:.8f}'.format(xq2, yq2))
    
    


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

using namespace std;
const int maxn = 2000001;
int c[maxn], mark[maxn];
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main(){
	int n; cin >> n;
	assert(n >= 2);
	int a[n];
	memset(c, 0, sizeof c);
	bool not_pairwise = false;
	vector<int> v;

	for(int i = 0; i < n; i++) {
		cin >> a[i];
		v.push_back(a[i]);
	}

	
	for(int i = 0; i < n; i++) {
		c[v[i]]++;
	}
	
	int g = v[0];
	for(int i = 1; i < n; i++) {
		g = __gcd(v[i], g);
		
	}
	
	if(!not_pairwise)
	{
		memset(mark, 0, sizeof mark);
		for(int i = 2; i < maxn; i++) {
			if(mark[i]) continue;
			int cnt = 0;
			for(int j = i; j < maxn; j+=i) {
				if(c[j]) cnt+=c[j];
				mark[j] = 1;
			}	
			if(cnt > 1) {
				not_pairwise = true;
			}
		}
	}
	string ans = "";
	if(!not_pairwise ) {
		ans =  "pairwise coprime\n";
	}else {
		if(g == 1 ) {
			ans =  "setwise coprime\n";
		}else ans = "not coprime\n";
	}
	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 26724
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] point = new int[n];
        int k = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int a;
        for(int i=0;i<q;i++){
            a = Integer.parseInt(sc.next())-1;
            point[a]++;
        }
        sc.close();
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<n;i++){
            if(k - (q-point[i])>0){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
    }
}

Measured memory_bytes: 48952
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=100,M=100;
int n,m;
char a[N+1][M+5];
int dp[N+1][M+1];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]+1;
	dp[1][1]=a[1][1]=='#';
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(i>1||j>1){
		dp[i][j]=inf;
		if(i-1>=1)dp[i][j]=min(dp[i][j],dp[i-1][j]+(a[i-1][j]=='.'&&a[i][j]=='#'));
		if(j-1>=1)dp[i][j]=min(dp[i][j],dp[i][j-1]+(a[i][j-1]=='.'&&a[i][j]=='#'));
	}
	cout<<dp[n][m];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int N, M;
vector<pair<int, int> > v;

int main(){
    int a, b, prev, cnt = 0;
    cin >> N >> M;
    Rep(i, 0, M){
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    } 
    sort(v.begin(), v.end(), [](pair<int, int> x, pair<int, int> y) -> bool{return (x.second < y.second);});
    prev = -1;
    for(auto i : v){
        a = i.first;
        b = i.second;
        if(prev < a){
            prev = b - 1;
            cnt++;
        }
    }
    Print(cnt);
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int num;
  cin >> num;
   int ans = int(num/500)*1000;
   num -= 500 * int(num/500);
   if(int(num/500)>1){
     ans += int(num / 5) * 5;
   }
   else{
     ans += int(num / 5) * 5;
   }
   cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            nums[i] = num;
            sum += num;
        }
        
        int sum2 = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            sum2 += nums[i];
            
            min = Math.min(min, Math.abs(sum - sum2 - sum2));
        }
        
        
        System.out.println(min);
        
    }
}

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


uint64_t func(uint64_t H) {
    if (H == 1) return 1;
    return 2 * func(H/2) + 1;
}

int main () {
    uint64_t H;
    cin >> H;
    cout << func(H) << endl;

    return 0;

}



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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

i32 n, k;
vector<i32> a;

bool validate(i32 d) {
    vector<i32> r(n+1);
    transform(begin(a), end(a), begin(r)+1, [&](i32 i) { return i % d; });
    sort(begin(r)+1, end(r));
    partial_sum(begin(r), end(r), begin(r));
    
    bool res = false;
    for (i32 i = 0; i < n+1; i++) {
        res |= r[i] == (n-i) * d - (r[n] - r[i]) && r[i] <= k;
    }
    return res;
}

int main() {
    cin >> n >> k;
    a.assign(n, 0);
    for (auto& e : a) cin >> e;
    i64 s = accumulate(begin(a), end(a), 0l);
    
    i32 ans = 0;
    for (i32 i = 1; i <= sqrt(s); i++) {
        if (s % i != 0) continue;
        if (validate(i)) ans = max(ans, i);
        if (validate(s / i)) ans = max(ans, s / i); 
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
int n,A[N];
int main(){
//	freopen("temp.txt","r",stdin);
	scanf("%d",&n);
	int ans=0;
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=2;i<n;i++){
		if((A[i-1]<A[i]&&A[i+1]>A[i])||(A[i-1]>A[i]&&A[i+1]<A[i]))ans++;
	}
	printf("%d",ans);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    long long a[100010];
    long long sum1 = 0;
    long long sum2 = 0;
    long long res1 = 0;
    long long res2 = 0;
    for (int i=1; i<=n; i++) {
        cin >> a[i]; 
        sum1 += a[i];
        if (i % 2 == 0){
            if (sum1 < 0) continue;
            else if (sum1 >= 0) {
                res1 += sum1 + 1;
                sum1 = -1;
            }
        }
        else if (i % 2 == 1){
            if (sum1 > 0) continue;
            else if (sum1 <= 0) {
                res1 += -sum1 + 1;
                sum1 = 1;
            }
        }
    }
    for (int i=1; i<=n; i++){
        sum2 += a[i];
        if (i % 2 == 0){
            if (sum2 > 0) continue;
            else if (sum2 <= 0) {
                res2 += -sum2 + 1;
                sum2 = 1;
            }
        }
        else if (i % 2 == 1){
            if (sum2 < 0) continue;
            else if (sum2 >= 0) {
                res2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }
    long long ans = min(res1, res2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

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

  map<ll, ll> mp;
  for (ll i = 1; i < N; i++)
  {
    int ai;
    cin >> ai;
    mp[ai]++;
  }
  for (ll i = 1; i <= N; i++)
  {
    cout << mp[i] << endl;
  }
  
  
}

Measured memory_bytes: 16024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long

class Task
{
public:
	string name;
	int time;
};

int main()
{
	ios::sync_with_stdio(false);
		int n, q;
	cin >> n >> q;
	
	queue<Task> que;
	for (int i = 0; i < n; i++) {
		Task t;
	    cin >> t.name >> t.time;
		que.push(t);
	}
	
	int elapsed = 0;
	while (!que.empty())
	{
		Task t = que.front();
		que.pop();
		
		elapsed += min(t.time, q);
		t.time -= q;

		if (t.time <= 0)
		{
			cout << t.name << " " << elapsed << endl;
		}
		else
		{
			que.push(t);
		}
	}
	
	return 0;
}

Measured memory_bytes: 6296
#include <stdio.h>

int c[100001] = {0}, s;

int main() {
    int n, m, h[100001], a, b;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &h[i]);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &a, &b);
        if (h[a] <= h[b]) c[a] = 1;
        if (h[b] <= h[a]) c[b] = 1;
    }
    for (int i = 1; i <= n; i++)
        if (!c[i])s++;
    printf("%d", s);
    return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 1000;
int N;
int a[MAX_N];


int main(){
  cin >> N;
  ll odd = 0, even = 0;
  int oddmax = -INFi, evenmax = -INFi;
  int oddmaxi, evenmaxi;

  REP(i, N) {
    cin >> a[i];
    if(a[i] > 0) {
      if (i % 2 == 0) even += a[i];
      else odd += a[i];
    } else {
      if(i % 2 == 0) {
        if(evenmax < a[i]) {
          evenmaxi = i;
          evenmax = a[i];
        }
      } else {
        if(oddmax < a[i]) {
          oddmaxi = i;
          oddmax = a[i];
        }
      }
    }
  }


  if(even == 0 && odd == 0) {
    if(oddmax > evenmax) {
      cout << oddmax << endl;
      cout << N - 1 << endl;
      for(int i = N; i > oddmaxi + 1; i--) {
        cout << i << endl;
      }
      REP(i, oddmaxi) {
        cout << 1 << endl;
      }
    } else {
      cout << evenmax << endl;
      cout << N - 1 << endl;
      for(int i = N; i > evenmaxi + 1; i--) {
        cout << i << endl;
      }
      REP(i, evenmaxi) {
        cout << 1 << endl;
      }
    }
  } else {
    int crt;
    int ct = 0;
    // count

    if(odd > even) {

      ct ++;
      crt = 1;
    } else {

      crt = 0;
    }
    while(a[crt] <= 0) {
      ct += 2;
      crt += 2;
    }
    crt += 2;
    while(crt < N) {
      if(a[crt] < 0){
        ct ++;
        if(crt == N - 1 || crt == N - 2) ct++;
      } else {
        ct ++;
        if(crt == N - 2) ct ++;
      }
      crt += 2;
    }

    // output

    if(odd > even) {
      cout << odd << endl;
      cout << ct << endl;
      cout << 1 << endl;  // +1
      crt = 1;
    } else {
      cout << even << endl;
      cout << ct << endl;
      crt = 0;
    }
    while(a[crt] <= 0) {
      cout << 1 << endl << 1 << endl;
      crt += 2;
    }
    crt += 2;
    while(crt < N) {
      if(a[crt] < 0){
        cout << 3 << endl;
        if(crt == N - 1 || crt == N - 2) cout << 2 << endl;
      } else {
        cout << 2 << endl;
        if(crt == N - 2) cout << 2 << endl;
      }
      crt += 2;
    }

  }


  return 0;
}


Measured memory_bytes: 256
S = input()
cdt = []
before_invalid = False


def is_acgt(char):
    if char == 'A':
        return True
    if char == 'C':
        return True
    if char == 'G':
        return True
    if char == 'T':
        return True
    return False


for i in S:
    if is_acgt(i):
        if not before_invalid:
            cdt.append(1)
        else:
            current = len(cdt) - 1
            cdt[current] = cdt[current] + 1
        before_invalid = True
    else:
        before_invalid = False

ans = 0
if len(cdt) > 0:
    ans = max(cdt)
print(ans)


Measured memory_bytes: 3064
from collections import defaultdict
MOD = 10**9 + 7

N = int(input())

dp = [defaultdict(int) for x in range(N+1)]
dp[0][''] = 1

def sol(s):
    if s.find('ABC') != -1: # 見つかった場合
        return False
    L = len(s)
    for i in range(L-1):
        li = list(s)
        li[i], li[i+1] = li[i+1], li[i]
        t = ''.join(li)
        if t.find('ABC') != -1:
            return False
    return True

for n in range(N):
    for s,cnt in dp[n].items():
        for c in 'ABCD':
            ns = s + c
            if sol(ns):
                dp[n+1][ns[-3:]] += cnt
                dp[n+1][ns[-3:]] %= MOD

ans = sum(dp[N].values())
ans %= MOD
print(ans)


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

using namespace std;

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i)
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i)

#define DEBUG(...) fprintf(stderr , __VA_ARGS__)

template<typename T>inline int chkmin(T &x , const T &y){ return x > y ? x = y , 1 : 0; }
template<typename T>inline int chkmax(T &x , const T &y){ return x < y ? x = y , 1 : 0; }

template<typename T>inline T read(T &f)
{
	f = 0 ; int x = 1 ; char c = getchar();
	while(!isdigit(c)) x = c == '-' ? -1 : 1 , c = getchar();
	while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
	return f *= x;
}

using int64 = long long;
using uint64 = unsigned long long;

const int N = 100000 + 5;

int n , A[N] , f[N] , Ans;

int main()
{
	read(n);
	rep(i , 1 , n) read(A[i]);
	per(i , n - 1 , 1)
	{
		if(A[i] >= A[i + 1]) f[i] = f[i + 1] + 1;
		else f[i] = 0;
		chkmax(Ans , f[i]);
	}
	cout << Ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    vector<pair<ll, ll>> v(n);
    for (int i = 0; i < n; ++i) {
        ll a, b; cin >> a >> b;
        v[i] = make_pair(b, a);
    }
    sort(v.begin(), v.end());

    ll time = 0;
    for (int i = 0; i < n; ++i) {
        pair<ll, ll> front = v[i];
        if (time + front.second > front.first) {
            cout << "No"<< endl;
            return 0;
        }
        time += front.second;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6432
function Main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10),
    a = args[1].split(' ').map(n => parseInt(n, 10));

  const aver = a.reduce((p, c) => p + c) / a.length;
  var diff = [];
  var index = 0;

  a.forEach((val, i) => {
    diff[i] = Math.abs(aver - val);
    index = diff[index] <= diff[i] ? index : i;
  });
  console.log(index);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

void vswap(int, int);
vector<int> a;

int main(){
	int w, n; cin >> w >> n;
	for(int i = 1; i <= w; i++) a.push_back(i);
	for(int i = 0; i < n; i++){
		int x, y;
		scanf("%d,%d", &x, &y);
		vswap(x - 1, y - 1);
	}
	for(int i = 0; i < a.size(); i++) cout << a[i] << endl;
	return 0;
}

void vswap(int x, int y){
	int tmp;
	tmp = a[y];
	a[y] = a[x];
	a[x] = tmp;
	return;	
}

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

int main()
{
	int N, a[100];
	cin >> N;
	for(int i = 0 ; i < N; ++i)
	{
		cin >> a[i];
	}
	
	int swap = 0;
	for(int i = 0; i < N - 1; ++i)
	{
		int m = i;
		for(int j = i + 1; j < N; ++j)
		{
			if(a[j] < a[m])
			{
				m = j;
			}
		}
		
		if(m != i)
		{
			int temp = a[m];
			a[m] = a[i];
			a[i] = temp;
			
			++swap;
		}
	}
	
	for(int i = 0 ; i < N; ++i)
	{
		if(i != 0)
		{
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl << swap << endl;

    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<int(n);i++)

const ll MOD=1000000007;

int n;
void input() {
	cin >> n;
}

void solve() {
	if (n % 2 == 0)cout << n / 2 << endl;
	else cout << n / 2 + 1 << endl;
}


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

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

typedef vector< int > vi;
typedef long long ll;
typedef vector< ll > vl;
typedef pair< int, int > pii;

int H, W, N;
vi A, B;

void init(){
    cin >> H >> W >> N;
    A = vi( N );
    B = vi( N );
    for( int i = 0; i < N; ++i )
        cin >> A[ i ] >> B[ i ],
        --A[ i ], --B[ i ];
}

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

bool in_range( int x, int y ){
    return 0 <= x and x < H and 0 <= y and y < W;
}

bool sqr_in_range( int x, int y ){ // left-top ( x, y ), size 3 * 3
    for( int di = 0; di < 9; ++di )
        if( not in_range( x + dx[ di ], y + dy[ di ] ) )
            return false;
    return true;
}

int count_black( int x, int y, const set< pii > &st ){
    if( not sqr_in_range( x, y ) )
        return 0; // !!! dump
    int cnt = 0;
    for( int di = 0; di < 9; ++di )
        cnt += st.count( pii( x + dx[ di ], y + dy[ di ] ) );
    return cnt;
}

void solve(){
    vl ans( 10 );
    set< pii > pnt;
    for( int i = 0; i < N; ++i )
        pnt.insert( pii( A[ i ], B[ i ] ) );

    for( int i = 0; i < N; ++i )
        for( int j = 0; j < 9; ++j )
            ++ans[ count_black( A[ i ] - dx[ j ], B[ i ] - dy[ j ], pnt ) ];

    ll psum = 0;
    for( int i = 1; i < 10; ++i )
        ans[ i ] /= i,
        psum += ans[ i ];

    ll tot = 1LL * ( H - 3 + 1 ) * ( W - 3 + 1 );
    ans[ 0 ] = tot - psum;

    for( int i = 0; i < 10; ++i )
        cout << ans[ i ] << "\n";
}

signed main(){
    ios::sync_with_stdio( 0 );
    init();
    solve();
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-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;}
 

 int main(){
 ll n ; cin>> n ;
 bitset<200005> x ; cin>> x ;
 ll sum=0 ;
 rep(i,n){
   if(x[i]==1) sum++ ;
 }
 vector<ll> A(200005),B(200005) ;
 rep(i,200005){
   if(i==0){
     A[i]= 1 ;
     B[i] = 1 ;
   }
   else{
     A[i]= (A[i-1]*2)%(sum+1) ;
     if((sum-1)!=0)B[i]= (B[i-1]*2)%(sum-1) ;
   }
 }
 ll p=0 ;
 ll q=0 ;
 rep(i,n){
   if(x[i]==1){
     p = (p+A[i])%(sum+1) ;
     if((sum-1)!=0)q= (q+B[i])%(sum-1) ;
   }
 }
 rep(i,n){
   ll ans=0 ;
   ans++ ;
   ll ke = n-1-i ;
   ll next=0 ;
   if(x[ke]==0){
     next= (p+ A[ke]) %(sum+1) ; 
   }
   if(x[ke]==1){
    if(sum-1==0){
      cout<<0<<endl ;
      continue ;
    }
    else next = (q-B[ke]+sum-1)%(sum-1) ;
   }
   
   if(next==0){
     cout<<ans<<endl ;
   }
   else{
     while(next!=0){
      ans++ ;
      bitset<20> s(next) ;
      ll cum = 0;
      rep(i,20){
        cum+= s[i] ;
      }
      next = next%cum ;
    }
     cout<<ans<<endl ;
   }
 }
   return 0 ;
 }



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

using namespace std;

int b[20], a[20];

int main() {
	int n, m, c;
	scanf("%d %d %d", &n, &m, &c);

	for (int i = 0;i < m;++i)
		scanf("%d", &b[i]);

	int cnt = 0;
	while (n--) {
		int tot = c;
		for (int i = 0;i < m;++i) {
			scanf("%d", &a[i]);

			tot += a[i] * b[i];
		}

		if (tot > 0)
			cnt++;
	}

	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    P = [int(input()) for _ in range(N)]

    #f1(N, P)
    editorial(N, P)


def editorial(N, P):
    """
    入力例3
        N=8
        P=63127485
         |6   7 8 |
         | 3   4 5|
         |  12    |
        上記の3つの列は要素ai+1=aiである部分列
            連続する列が長いほど、移動しなくて済む要素は多い
            連続するためには、最小未満は左・最大より大きいものは末尾に移動する
        部分列(wikipediaより)
            残った要素がもとの数列における相対的な序列を保つ
            与えられた列からいくつかの要素を取り去ることによって得られる列
    ksomemo様にお借りしました
    """
    if N == 1:
        print(0)
        return

    # WA(N, P)
    a = [0] * (N+1)
    for i, p in enumerate(P):
        a[p] = i

    tmp = 1
    max_len = 1
    for i in range(1, N):
        if a[i] < a[i+1]:
            tmp += 1
            max_len = max(max_len, tmp)
        else:
            tmp = 1
    ans = N - max_len
    print(ans)


def WA(N, P):
    tmp = 0
    ans = 0
    for i, p in enumerate(P):
        if i == 0 or P[i-1] + 1 == p:
            tmp += 1
        else:
            ans = max(ans, tmp)
            tmp = 1

    print(N - ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;
	for (;;)
	{
		c -= b;

		if (c <= 0)
		{
			cout << "Yes";
			break;
		}

		a -= d;

		if (a <= 0)
		{
			cout << "No";
			break;
		}
	}
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef unsigned long long ULL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N;

ULL gcd(ULL a, ULL b) {
    ULL r;
    while(b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main() {
    std::cin >> N;
    ULL ans = 0;
    REP(i, N) {
        ULL t;
        std::cin >> t;
        if(i == 0) {
            ans = t; 
        }else {
            ans *= t / gcd(ans, t);
        }
    }
    std::cout << ans << std::endl;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i=A; i<B+1; i++) {
		int a, b, d, e;
		a = i/10000%10, b = i/1000%10;
		d = i/10%10, e = i%10;
		if (a==e && b==d) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
A = raw_input()
B = raw_input()
C = raw_input()
dic = {"a": A, "b": B, "c": C}
turn = "a"
while True:
    try:
        nx = dic[turn][0]
    except:
        print turn.upper()
        exit()
    dic[turn] = dic[turn][1:]
    turn = nx


Measured memory_bytes: 2692
# AOJ 0601 Sugar Glider
# Python3 2018.7.4 bal4u

import sys
from sys import stdin
input = stdin.readline

import heapq
def dijkstra(V, to, start, goal, x):
	Q = []
	visited = [0]*V
	heapq.heappush(Q, (-x, start))
	while Q:
		t, s = heapq.heappop(Q)
		t = -t
		if s == goal: return x+h[goal]-t*2
		if visited[s]: continue
		visited[s] = 1
		for e, c in to[s]:
			if visited[e] or c > h[s]: continue
			d = min(h[e], t-c)
			heapq.heappush(Q, (-d, e))
	return -1
	
n, m, x = map(int, input().split())
h = [int(input()) for i in range(n)]
to = [[] for i in range(n)]
for i in range(m):
	a, b, t = map(int, input().split())
	a, b = a-1, b-1
	to[a].append((b, t))
	to[b].append((a, t))
print(dijkstra(n, to, 0, n-1, x))


Measured memory_bytes: 107440