akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while(n != 0){
    if(n&1) ans = ans*x % M;
    x = x*x % M;
    n = n >> 1;
  }
  return ans;
}

// 組み合わせ
ll comb(ll a, ll b){ 
  if(a == 0 && b == 0)return 1;
  if(a < b || a < 0)return 0;
  ll tmp = ifac[a-b]* ifac[b] % M;
  return tmp * fac[a] % M;
}

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

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<300000; i++){
    fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
    ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }

  ll ans = 0;
  rrep(i, 3000) {
    if (3*i > s) break;
    int res = s - 3*i;
    ans += comb(res+i-1, i-1);
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) {if(a<b) {a=b;return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if(a>b) {a=b;return true;} return false;}
const ll INF = 1LL<<60;

class UnionFind {
public:
    std::vector<int> data;
    UnionFind( int n ) {
        data.resize( n, -1 );
    }
    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }
    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }
};

struct Edge {
    int to;
    ll dist;
};

ll solve() {
    ll N;
    cin >> N;
    vector<vector<ll>> A(N,vector<ll>(N));
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin >> A[i][j];
        }
    }
    auto cmp = [&](pii& i1, pii& i2) { 
        return A[i1.first][i1.second] > A[i2.first][i2.second];
    };
    priority_queue<pii, vector<pii>, decltype(cmp)> q(cmp);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            q.push(pii(i,j));
        }
    }

    vector<vector<Edge>> G(N);
    UnionFind uf(N);

    auto cmpD = [&](pair<ll,int>& i1, pair<ll,int>& i2) { 
        return i1.first > i2.first;
    };
    auto dijkstra = [&](int s, int f) -> ll {
        vector<ll> dist(N,INF);
        dist[s] = 0;
        priority_queue<pair<ll,int>, vector<pair<ll,int>>, decltype(cmpD)> qD(cmpD);
        qD.push(make_pair(dist[s], s));
        while ( !qD.empty() ) {
            ll d = qD.top().first;
            int v = qD.top().second;
            if ( v == f ) return d;
            qD.pop();
            if ( d > dist[v] ) continue;
            for ( auto e : G[v] ) {
                ll dn = dist[v] + e.dist;
                if ( chmin( dist[e.to], dn ) ) {
                    qD.push(make_pair(dn, e.to));
                }
            }
        }
        return INF;
    };

    while ( !q.empty() ) {
        auto p = q.top();
        q.pop();
        bool addEdge = false;
        if ( uf.find(p.first) != uf.find(p.second) ) {
            addEdge = true;
            uf.unite(p.first,p.second);
        } else {
            ll dd = dijkstra(p.first,p.second);
            if ( dd < A[p.first][p.second] ) {
                return -1;
            } else if ( dd > A[p.first][p.second] ) {
                addEdge = true;
            }
        }
        if ( addEdge ) {
            G[p.first].push_back(Edge{p.second,A[p.first][p.second]});
            G[p.second].push_back(Edge{p.first,A[p.first][p.second]});
        }
    }

    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( auto e : G[i] ) {
            ans += e.dist;
        }
    }
    ans /= 2;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';


int main() {
	int N;
	string S;
	cin >> N >> S;
	int c = 0;
	for (int i = 0; i < N - 2; i++) {
		if (S[i] == 'A'&&S[i + 1] == 'B'&&S[i + 2] == 'C')c++;
	}
	cout << c << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    vector<ll> n(3, 0);
    for(char c : s){ n.at(c - 'a')++; }
    ll max = *max_element(n.begin(), n.end());
    ll min = *min_element(n.begin(), n.end());
    if(max - min <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

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

#include <string>
#include <vector>
#include <algorithm>
int main(){
    int n; cin >> n;
    if(n%2==0){
        cout << 0.5 << endl;
    } else {
        printf("%f\n",(double)(n/2+1)/n);
    }
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 2000000000;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
	ll len;
	if(a > b) len = a-b;
	else len = b-a;
	if(len==0){
		cout << "YES" << endl;
		return 0;
	}
	if(v <= w){
		cout << "NO" << endl;
		return 0;
	}
	if(len <= (v-w)*t){
		cout << "YES" << endl;
	}else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		arr[i] = a-(i+1);
	}
	sort(arr,arr+n);
	ll sum=0;
	for(int i=0;i<n;i++){
		sum += abs(arr[n/2]-arr[i]);
	}
	cout<<sum<<endl;
}


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

tuple<int, int> input_int2() {
	int a, b;
	cin >> a >> b;	
	return forward_as_tuple(a, b);
}

void input_int_array(int n, int* array) {
	for (int i=0,tmp=0; i<n && cin >> tmp; i++) array[i] = tmp;
}

int H, W, h, w;
void input() {
	tie(H,W) = input_int2();
	tie(h,w) = input_int2();
}

int solve() {
	return (H-h)*(W-w);
}

int main() {
	input();
	cout << solve() << endl;
}


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

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  if (n >= 10000)
  {
    ans += min(90000, n - 10000 + 1);
  }
  if (n >= 100)
  {
    ans += min(900, n - 100 + 1);
  }
  if (n >= 1)
  {
    ans += min(9, n - 1 + 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
s = input()
t = input()

def check(s, t):
    for i in range(len(s)):
        for j in range(min(len(t), len(s[i:]))):
            if s[i:][j] != '?' and s[i:][j] != t[j]:
                break
            if j == len(t)-1:
                return True, i
    return False, 0


s = s[::-1]
t = t[::-1]
c, i = check(s, t)
ans = ''
if c:
    ans = s[:i] + t + s[(i+len(t)):]
    ans = ans.replace('?', 'a')
    print(ans[::-1])
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

import java.util.*;

public class Main{
  static int n;
  static long h;
  static int[] a, b;

  public static void main(String[] args){
    FastScanner sc = new FastScanner();
    n = sc.nextInt();
    h = sc.nextInt();
    a = new int[n]; b = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();  b[i] = sc.nextInt();
    }

    Arrays.sort(a);
    Arrays.sort(b);

    int maxA = a[n - 1];

    int countB = 0;
    long sumB = 0;
    for(int i = n - 1; i >= 0; i--){
      if(maxA < b[i]){
        sumB += (long)b[i];
        ++countB;
        if(sumB >= h){
          System.out.println(countB);
          return;
        }
      }
    }

    long ans;
    if((h - sumB) % (long)maxA == 0){
      ans = (h - sumB) / (long)maxA + countB;
    }
    else{
      ans = (h - sumB) / (long)maxA + countB + 1;
    }

    System.out.println(ans);
  }
}

class FastScanner {
  private static final InputStream in = System.in;
  private static final PrintWriter out = new PrintWriter(System.out);
  private final byte[] buffer = new byte[2048];
  private int p = 0;
  private int buflen = 0;

  public FastScanner(){
  }

  private boolean hasNextByte() {
    if(p < buflen){
      return true;
    }
    p = 0;
    try{
      buflen = in.read(buffer);
    }catch (IOException e) {
      e.printStackTrace();
    }
    if(buflen <= 0){
      return false;
    }
    return true;
  }

  public boolean hasNext() {
    while(hasNextByte() && !isPrint(buffer[p])){
      p++;
    }
    return hasNextByte();
  }

  private boolean isPrint(int ch) {
    if(ch >= '!' && ch <= '~'){
      return true;
    }
    return false;
  }

  private int nextByte() {
    if(!hasNextByte()){
      return -1;
    }
    return buffer[p++];
  }

  public String next() {
    if(!hasNext()){
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = -1;
    while(isPrint((b = nextByte()))){
      sb.appendCodePoint(b);
    }
    return sb.toString();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public long nextLong() {
    return Long.parseLong(next());
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}


Measured memory_bytes: 43012
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;

	vector<int> inputs;
	for (int i = 0; i < n; ++i)
	{
		int input;
		cin >> input;
		inputs.push_back(input);
	}

	sort(inputs.begin(), inputs.end());

	int min = INT_MAX;
	for (int i = 0; i <= n - k; ++i)
	{
		int diff = inputs[i+k-1] - inputs[i];
		if (min > diff) min = diff;
	}

	cout << min << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;

signed main()
{
    fast;
    int n,k;
    cin>>n>>k;

    if ( n >= 10 )
    {
        cout<<k<<endl;
    }
    else
    {
        cout<<k + 100*(10-n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int, input().split()))
a = [list(map(int,input().split())) for i in range(n)]
d = -1000
x = 0
for i in range(n):
    d = 0
    for j in range(m):
        d += a[i][j]*b[j]
    if d+c>0:
        x+=1
print(x)

Measured memory_bytes: 62288
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

vector<pair<int, int> > G[10001];

int main()
{
	int N, M;
	
	scanf("%d %d", &N, &M);
	
	int x, y, z;
	while (scanf("%d %d %d", &x, &y, &z) && z){
		G[--x].push_back(make_pair(--y, z));
	}
	
	int L;
	scanf("%d", &L);
	for (int i = 0; i < L; i++){
		int coef[10001], sum[10001] = {0};
		for (int j = 0; j < M; j++){
			scanf("%d", coef + j);
		}
		
		for (int j = 0; j < N; j++){
			for (int k = 0; k < G[j].size(); k++){
				sum[j] += coef[G[j][k].first] * G[j][k].second;
			}
		}
		
		for (int j = 0; j < N; j++){
			printf("%d%c", sum[j], j == N - 1 ? '\n' : ' ');
		}
	}
	
	return (0);
}

Measured memory_bytes: 2088
#include<stdio.h>
#include<stdlib.h>
int n,a;
int* t[100];
int  u[100];
int  begin[100];
int  end[100];
int visited[100];

int v[100];
int w=0,cnt=1;

void push(int x){
  v[w]=x;
  w++;
}

void pop(){
  w--;
}

int main(){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    a--;
    scanf("%d",&u[a]);
    t[a]=malloc( sizeof(int) * u[a] );
    for(j=0;j<u[a];j++){
      scanf("%d",&t[a][j]);
      t[a][j]--;
    }
  }
  for(j=0;j<n;j++){
    if(visited[j]==1)continue;
    push(j);
    while(w!=0){
      a=v[w-1];
      if(visited[a]==0)begin[a]=cnt++;
      visited[a]=1;
      for(i=0;i<u[a];i++){
	if(visited[t[a][i]]==0){
	  push(t[a][i]);
	  break;
	}
      }
      if(i==u[a]){
	end[a]=cnt++;
	pop();
      }
    }
  }
    
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,begin[i],end[i]);
  }
  return 0;
}

Measured memory_bytes: 600
from collections import deque

N = int(input())
m = N*(N-1) // 2

hash_table = [[0]*N for i in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    hash_table[i][j] = hash_table[j][i] = count
    count += 1


graph = [[] for i in range(m)]
before_this = [0] * m
for i in range(1, N+1):
  A = deque(list(map(int, input().split())))
  pre_a = A.popleft()
  pre_pair = hash_table[i-1][pre_a-1]
  for a in A:
    pair = hash_table[i-1][a-1]
    graph[pre_pair].append(pair)
    before_this[pair] += 1
    pre_pair = pair


games = deque([])
for i in range(m):
  if not before_this[i]:
    games.append(i)


if not games:
  ans = -1
else:
  ans = 0
  num_finished = 0
  while games:
    ans += 1
    num_games = len(games)
    num_finished += num_games
    for i in range(num_games):
      pair = games.popleft()
      subseq = graph[pair]
      for ss in subseq:
        before_this[ss] -= 1
        if not before_this[ss]:
          games.append(ss)
    
  if num_finished != m:
    ans = -1

print(ans)

Measured memory_bytes: 121684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
//static const int MAX = 10000;


int main(){
  int N = in(), x, y;
  vector<int> l(N);
  long long count = 0;
  rep(i, N) l[i] = in();
  sort(l.begin(), l.end());

  rep(i, N){
    for(int j = i+1; j < N; j++){
      x = l.end() - lower_bound(l.begin(), l.end(), l[i]+l[j]);
      y = j+1;

      count += l.size()-x-y;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
ans = 0
for i in range(len(li)-2):
  for j in range(i+1,len(li)-1):
    for k in range(j+1,len(li)):
      a = li[i]
      b = li[j]
      c = li[k]
      if a==b or b==c or c==a:
        continue
      if a+b>c and b+c>a and c+a>b:
        ans += 1
print(ans)

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

int main()
{
    int i,j,n,cnt=1;
    cin>>n;
    string s[n];
    for(i=0;i<n;i++)
        cin>>s[i];
    sort(s,s+n);
    for(i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            cnt++;
    }
    cout<<cnt<<endl;


return 0;
}


Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    string s;
    int n;
	scanf("%d",&n);
    cin >> s;
    int lc=0,resl = 0;
	rep(i,n){
        if(s[i] == '('){
            lc++;
        }else{
            if(lc > 0){
                lc--;
            }else{
                resl++;
            }
        }
	}
    int rc=0,resr = 0;
    for(int i = n-1;i>=0;i--){
		if(s[i] == '('){
            if(rc > 0){
                rc--;
            }else{
                resr++;
            }
        }else{
            rc++;
        }
	}
    rep(i,resl){
        cout << "(";
    }
    cout << s;
    rep(i,resr){
        cout << ")";
    }
    cout << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int answer[101];

int main(int argc, char const* argv[])
{
	int input;

	for( int i = 0;i < 101;i++ ) answer[i] = 0;

	while( std::cin >> input ){
		answer[input]++;
	}

	int max = 0;

	for( int i = 1;i < 101;i++ ){
		max = std::max( answer[i], max );
	}


	for( int i = 1;i < 101;i++ ){
		if( answer[i] == max ) std::cout << i << std::endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  ll n;
  cin >> n;
  if (n % 2) {
    cout << 0 << endl;
    return;
  }
  // n は偶数で, n 以下の数のちょうど半分が奇数
  n /= 2;
  ll ans = 0;
  rep3(i, 1, inf) {
    ll add = n / pow(5LL, i);
    if (add == 0) break;
    ans += add;
  }
  cout << ans << endl;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  cout << 6-A-B << endl;
    
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

Measured memory_bytes: 256
until (n=gets.to_i)==0
  l1=gets.split.map(&:to_i)
  l2=Array.new(n)
  count=0
  loop do
    l1.each.with_index do |num,id|
      l2[id]=l1.count{|item| item==num}
    end
    break if l1==l2
    count+=1
    l1=l2.dup
  end
  puts "#{count}\n#{l1.join(" ")}"
end

Measured memory_bytes: 8804
class Solver
  def initialize
    while data = gets
      @data = data.chomp.split(' ').map(&:to_i)
      @length = @data.shift
      @data.unshift(0)
      @graph = Array.new(@data.size).map{Array.new(@data.size, 0)}
      @dp = Array.new(1 << @data.size).map{Array.new(@data.size, -1)}
      create_graph
      answer = 9999

      answer = solver( 0, 0 )

      @graph.each do |graph|
        #p graph
      end
      puts (answer <= @length)? "OK" : "NA"
    end
  end

  def create_graph
    0.upto(@data.size-1) do |id|
      0.upto(@data.size-1) do |id2|
        if id == 0
          @graph[id][id2] = @data[id2]
        elsif id != id2
          if id2 == 0
            @graph[id][0] = @data[id]
          else
            @graph[id][id2] = calc_dist(id, id2)
          end
        end
      end
    end
  end

  def calc_dist(id1, id2)
    r1 = @data[id1]
    r2 = @data[id2]
    a = r1 + r2
    b = r1 - r2
    dist = Math.sqrt(a**2 - b**2)
  end

  def solver( s, v )
    return @dp[s][v] if @dp[s][v] >= 0

    return @dp[s][v] = 0 if s == (1 << @data.size) - 1 && v == 0

    res = 9999
    0.upto(@data.size-1) do |id|
      if !((s >> id) & 1 == 1)
        res = [ res, solver( s | (1 << id), id) + @graph[v][id]].min
      end
    end
    @dp[s][v] = res
  end
end

s = Solver.new

Measured memory_bytes: 8436
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  cin >> n;
  int i = 1;
  while (i*2<=n) {
    i*=2;
  }
  cout << i << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    long long int N;
    cin >> N;
    REP(i,100000){
        if(i*i<=N&&N<(i+1)*(i+1)){
            cout << i*i;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= flag;
}
#if __cplusplus >= 201103l
template<typename T, typename... V>
void read(T &x, V&... v) { read(x), read(v...); }
#endif

const int _ = 2e5 + 10, Inf = 2e9 + 10;
int n, rmx, rmn = Inf, bmx, bmn = Inf; ll ret;
std::multiset<int> r, b;

struct node {
	int v1, v2;
	node() {}
	node(int _v1, int _v2) { v1 = _v1, v2 = _v2; }
	bool operator < (const node &a) const { return v1 < a.v1; }
} p[_];

ll calc() { return 1ll * (*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()); }

int main () {
	read(n);
	for(int i = 1, x, y; i <= n; ++i) {
		read(x, y); if(x > y) swap(x, y);
		p[i] = node(x, y), r.insert(x), b.insert(y);
	}
	ret = calc(), sort(p + 1, p + n + 1);
	for(int i = 1; i <= n; ++i) {
		int x = p[i].v1, y = p[i].v2;
		r.erase(r.find(x)), b.erase(b.find(y));
		r.insert(y), b.insert(x);
		ret = min(ret, calc());
	}
	printf("%lld\n", ret);
	return 0;
} 
//

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

const string S[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
  string s;
  int i;
  cin >> s;
  rep(j, 3) {
    if(S[j] == s) {
      i = j;
    }
  }
  cout << S[(i+1)%3] << endl;
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,max;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            max = a + b;
            if (max < a - b) max = a - b;
            if (max < a * b) max = a * b;

           
            Console.WriteLine(max);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11220
L, N = gets.split.map(&:to_i)
S = gets.chomp
R = Array.new(N) { gets.split.map(&:to_i) }

ANS = [0]
L.times {|i|
  isAC = S[i] == 'A' && S[i + 1] == 'C'
  ANS[i + 1] = ANS[i] + (isAC ? 1 : 0)
}

R.each {|f, t|
  p ANS[t - 1] - ANS[f - 1]
}

Measured memory_bytes: 15816
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    sum=m+f
    if m==-1 or f==-1 :
        print("F")
    elif sum>=80:
        print("A")
    elif sum>=65:
        print("B")
    elif sum>=50:
        print("C")
    elif sum>=30:
        if r>=50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000 
const long long  MOD =1e9+7;
#define MAXR 100000 
int main(){
    string S;
    cin >> S;
    if(S=="Sunny")cout << "Cloudy"<<endl;
    else if(S=="Cloudy")cout << "Rainy"<<endl;
    else cout << "Sunny"<< endl;
}

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

int main() {
    long double L;
    cin>>L;
    long double a = L/3;
    cout << setprecision(18) << a * a * a  << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  string s;
  cin>>s;
  if(s[0]==s[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

string replace(string str, int a, int b){
    string repl;
    cin >> repl;
    for(int i = 0; i <= b - a; i++){
        str[a + i] = repl[i];
    }
    return str;
}

string reverse(string str, int a, int b){
    string rev = str;
    for(int i = a, j = 0; i <= b; i++, j++){
        str[i] = rev[b - j];
    }
    return str;
}

void print(string s, int a, int b){
    for(int i = a; i <= b; i++){
        cout << s[i];
    }
    cout << endl;
}

int main(){
    string str;
    while(cin >> str){
        int q;
        cin >> q;
        rep(i,q){
            string order;
            int a, b;
            cin >> order >> a >> b;
            if(order == "replace") str = replace(str, a, b);
            else if(order == "reverse") str = reverse(str, a, b);
            else if(order == "print") print(str, a, b);
        }
    }
}

Measured memory_bytes: 1220
#include<stdio.h>
int main()
{
  int a,b,r,d;
  double f;
  scanf("%d%d",&a,&b);
  d = a / b;
  r = a % b;
  f = (double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 632
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  string S;
  int N, K;

  cin >> N >> K >> S;

  S[K - 1] = S[K - 1] - ('Z' - 'z');

  cout << S << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

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

        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == 0 && b == 0) break;

            for(int i=0; i<a; i++){
                for(int j=0; j<b; j++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
vector<lint> c;
vector<lint> a[15];

int main(){
    lint n,m,x; cin>>n>>m>>x;
    rep(i, n){
        lint _c; cin>>_c;
        c.push_back(_c);
        rep(j, m){
            lint _a; cin>>_a;
            a[i].push_back(_a);
        }
    }

    int M = (1<<n);
    lint ans = INF;
    rep(s, M){
        vector<lint> check(m);
        lint cost = 0;
        rep(i,n){
            if(s&(1<<i)){
                cost += c[i];
                rep(j, m){
                    check[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(j, m){
            if(check[j]<x) ok = false;
        }
        if(ok){
            ans = min(ans, cost);
        }
    }
    if(ans == INF) ans = -1;
    out(ans);
}

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    
    if(a.size()<b.size()){
        string pre=b;
        b=a;
        a=pre;
    }
    
    string hoge="";
    
    for(int i=b.size();i<a.size();i++) hoge+="0";
    
    string ans="EQUAL";
    
    for(int i=0;i<a.size();i++){
        if(a.at(i)>b.at(i)){
            ans="GREATER";
            break;
        }else if(a.at(i)<b.at(i)){
            ans="LESS";
            break;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using pii = pair<int, int>;

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

    int N, M;
    cin >> N >> M;
    vector<pii> AB(N);
    vector<int> A(N), B_diff(N + 1), L(M), R(M);
    REP(i, N) {
        cin >> AB[i].first >> AB[i].second;
    }
    REP(i, M) {
        cin >> L[i] >> R[i];
        ++R[i];
    }

    sort(all(AB));

    REP(i, N) {
        A[i] = AB[i].first;
    }

    REP(i, N - 1) {
        B_diff[i + 1] = AB[i + 1].second ^ AB[i].second;
    }
    B_diff[0] = AB[0].second;
    B_diff[N] = AB[N - 1].second;

    vector<vector<pii>> g(N + 1);
    REP(i, M) {
        auto l = distance(A.begin(), lower_bound(all(A), L[i]));
        auto r = distance(A.begin(), lower_bound(all(A), R[i]));
        if (l != r) {
            g[l].emplace_back(r, i);
            g[r].emplace_back(l, i);
        }
    }

    vector<bool> used(N, false);
    vector<int> c;

    function<int(int)> dfs = [&](int u) {
        used[u] = true;
        int result = B_diff[u];
        for (pii e: g[u]) {
            int v, edge_id;
            tie(v, edge_id) = e;
            if (used[v]) {
                continue;
            }
            if (dfs(v) == 1) {
                c.push_back(edge_id);
                result ^= 1;
            }
        }
        return result;
    };


    REP(i, g.size()) {
        if (!used[i]) {
            int root = dfs(i);
            if (root == 1) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    sort(all(c));

    cout << c.size() << '\n';
    REP(i, c.size()) cout << (c[i] + 1) << ' '; // 1-based indexing
    cout << endl;

    return 0;
}


Measured memory_bytes: 17148
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  std::string S;
  std::cin >> S;
  if ((S[0]==S[1] && S[2]==S[3] && S[0]!=S[2]) ||
      (S[0]==S[2] && S[1]==S[3] && S[0]!=S[1]) ||
      (S[0]==S[3] && S[1]==S[2] && S[0]!=S[1])){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 15 09:40:47 2019

@author: 17664
"""

s = input()

alphaList = list(set(s))

cnt = 0
ans = 'Yes'

for i in alphaList:
    cnt = s.count(i)
    if cnt % 2 != 0:
        ans = 'No'
        break
    else:
        cnt = 0
        
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100+5;

int n;
int m;
int a[N];

int main(){
	ri(n);
	int S = 0;
	for(int i=1; i<=n; i++){
		ri(a[i]);
		S += a[i];
	}
	ri(m);
	int p, x;
	for(int i=1; i<=m; i++){
		ri2(p,x);
		printf("%d\n",S + x - a[p]);
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
from collections import defaultdict
N,M=map(int,input().split())
A=list(map(int,input().split()))
acc = [0]+list(accumulate(A,lambda x,y:x+y))
d = defaultdict(list)
for i in range(len(acc)):
    d[acc[i] % M].append(i)
ans = 0
for l in map(len,d.values()):
    ans += l*(l-1)//2
print(ans)

Measured memory_bytes: 31956
#include <stdio.h>
#include <string.h>

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

    char s[10010];
    scanf("%s", s);

    int len;
    len = strlen(s);

    for(int i=0; i<len; i++){
        char c = s[i] + n;
        if(c <= 90){
            s[i] = c;
        }else{
            s[i] = c % 91 + 65;
        }
    }

    printf("%s", s);

    return 0;
}

Measured memory_bytes: 128
N = int(input())
h_list = list(map(int, input().split()))

hh = [h_list[0]]
ans = 1
for index, i in enumerate(h_list):
  if index == 0:
    continue;
  else:
    if i >= max(hh):
      ans+=1
  hh.append(i)
  
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
using namespace std;
struct P{
  double x,y;
  P(){}
  P(double x,double y):x(x),y(y){}
};
bool isIntersecter(P a,P b,P p,P q ){
  return ((a.x - b.x)*(p.y - a.y) - (a.y - b.y)*(p.x - a.x))*((a.x - b.x)*(q.y - a.y) - (a.y - b.y)*(q.x - a.x)) > 0;
}
int main(){
  P a[4];
  char c;
  while(cin >> a[0].x){
    cin >> c >> a[0].y; 
    for(int i = 1 ; i < 4 ; i++ ) {
      cin >> c >> a[i].x >> c >> a[i].y;  
    }
    if(isIntersecter(a[0],a[2],a[1],a[3]) ||
       isIntersecter(a[1],a[3],a[0],a[2])){
      cout << "NO" << endl;
    } else cout << "YES" << endl;

  }
}

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

const int N = 200010;
int n, m;
char s[N];
multiset<int> g[N];
int count_a[N], count_b[N];
queue<int> q;
bool vis[N];

int main()
{
	//freopen("in.txt", "r", stdin);
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	for(int i = 1; i <= m; i ++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].insert(v);
		g[v].insert(u);
	}
	for(int i = 1; i <= n; i ++)
	{
		for(multiset<int>::iterator j = g[i].begin(); j != g[i].end(); j ++)
		{
			int v = *j;
			if(s[v] == 'A') count_a[i] ++;
			else count_b[i] ++;
		}
		// if(i == 11 || i == 12) printf("%d: %d %d\n", i, 
		// 	count_a[i], count_b[i]);
		if(count_a[i] == 0 || count_b[i] == 0) 
			vis[i] = 1, q.push(i);
	}
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(multiset<int>::iterator j = g[u].begin(); j != g[u].end(); j ++)
		{
			int v = *j;
			if(vis[v]) continue;
			int sz = g[v].count(u);
			g[v].erase(u);
			if(s[u] == 'A') count_a[v] -= sz;
			else count_b[v] -=sz;
			// if(u == 13 && v == 11) printf("%d %d\n", count_a[v], 
			// 						count_b[v]);
			if(count_a[v] == 0 || count_b[v] == 0)
				vis[v] = 1, q.push(v);
		}
		g[u].clear();
	}
	bool flag = 0;
	for(int i = 1; i <= n; i ++)
		if(!vis[i]) flag = 1;
	printf("%s\n", flag ? "Yes" : "No");
	return 0;
}

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

using namespace std;

int main(){
	int a;
	bool f1, f2,f3;
	int count;
	string x;
	while (1){
		cin >> a;
		if (!a){
			break;
		}
		count = 0;
		f1 = 0;
		f2 = 0;
		f3 = 0;
		for (size_t i = 0; i < a; i++)
		{
			cin >> x;
			if (x == "lu"){
				if (f2 == 1&&f3==0){
					count++;
					f3 = 1;
				}
				f1 = 1;
			}
			else if (x == "ru"){
				if (f1 == 1&&f3==0){
					count++;
					f3 = 1;
				}
				f2 = 1;
			}
			else if(x=="ld"){
				if (f2 == 0&&f3==1){
					count++;
					f3 = 0;
				}
				f1 = 0;
			}
			else if (x == "rd"){
				if (f1 == 0&&f3==1){
					count++;
					f3 = 0;
				}
				f2 = 0;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
eval"N,*A="+`dd`.split*?,
x=[h=(Hash.new 0),h.dup]
N.times{|i|x[i%2][A[i]]+=1}
((a,b),(c,d)),((e,f),(g,h))=x.map{|a|a.sort_by{|_,s|-s}}
p N.-a!=e ?b+f:[b+=h||0,f+=d||0].max

Measured memory_bytes: 32452
#include <cstdio>
#include <cmath>
int main()
{
	int x, h;
	while (scanf("%d%d", &x, &h), x && h)
		printf("%.6f\n", (4.0*(sqrt(double(h*h)+double(x*x)/4.0)*x))/2.0+x*x);
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    double m = scan.nextDouble();
    int a[] = new int[n];
    double summation = 0;
    for (int i = 0; i < n; i++){
      int c = scan.nextInt(); 
      a[i] = c;
      summation = summation + (double)c;
    }
    double border = Math.ceil(summation/(4*m));
    int judge = 0;
    for (int i =0; i < n; i++){
      if (a[i] >= border){
        judge++;
      }
    }
    if (judge >= m){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main(){
    string s;
    cin >> s;
    int sta, fin;
    bool onetime = true;
    for(int i = 0; i < s.size(); i ++){
        if(onetime){
            if(s.at(i) == 'A'){
                sta = i;
                onetime = false;
            }
        }
        if(s.at(i) == 'Z'){
            fin = i;
        }
    }
        cout << fin -sta + 1 << endl;
}
           

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;

ll N;
ll p[20002];
ll d[20002];
ll a[20002];
ll b[20002];


int main(){
    cin>>N;
    rep(i,N) cin>>p[i];
    a[p[1]]=500000000;
    b[p[1]]=500000000;
    rep(i,N-1) d[i]=p[i+1]-p[i];
    rep(i,N-1){
        a[p[i+1]]=a[p[i]]+(N+2)*d[i];
        b[p[i+1]]=b[p[i]]-(N+2)*d[i];
    }
    rep(i,N){
        a[p[i]]+=i;
        b[p[i]]+=i;
    }
    rep(i,N){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    rep(i,N){
        cout<<b[i]<<" ";
    }
    cout<<endl;


    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long sum,a,n,ans,L;
char op;
vector<long>A;
main()
{
	cin>>n;
	cin>>a;
	A.push_back(a);
	sum+=a;
	for(int i=1;i<n;i++)
	{
		cin>>op>>a;
		if(op=='-')
		{
			A.push_back(-a);
			A.push_back(0);
			sum-=a;
		}
		else
		{
			A.back()+=a;
			sum+=a;
		}
	}
	ans=sum;
	for(int i=A.size()-2;i>0;i-=2)
	{
		ans=max(ans,sum-A[i+1]*2+L);
		sum=sum-A[i]-A[i+1];
		L+=-A[i]+A[i+1];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2420
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BOARD_SIZE 600
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

typedef enum {
  BLACK,
  WHITE,
} Cell;

Cell board[BOARD_SIZE][BOARD_SIZE];

#define QUEUE_SIZE 0x10000
typedef int Item;
Item queue[QUEUE_SIZE];
size_t queue_in = 0;
size_t queue_out = 0;
int queue_is_full = 0;

size_t inc_queue_index(size_t index)
{
  return (index + 1) % QUEUE_SIZE;
}

void queue_push(const Item* item)
{
  if(queue_is_full) {
    fputs("Queue is full.\n", stderr);
    exit(1);
  }
  memcpy(&queue[queue_in], item, sizeof(Item));
  queue_in = inc_queue_index(queue_in);
  queue_is_full = queue_in == queue_out;
}

void queue_pop(Item* result)
{
  if(queue_in == queue_out && !queue_is_full) {
    fputs("Queue is empty.\n", stderr);
    exit(1);
  }
  memcpy(result, &queue[queue_out], sizeof(Item));
  queue_out = inc_queue_index(queue_out);
  queue_is_full = 0;
}

void clear_queue()
{
  queue_in = 0;
  queue_out = 0;
  queue_is_full = 0;
}

void init_board()
{
  for(int x = 0; x < 100; x++) {
    for(int y = 0; y < 50; y++) {
      board[x][y] = BLACK;
    }
    for(int y = 50; y < 100; y++) {
      board[x][y] = WHITE;
    }
  }
}

void fill_white(int num_black)
{
  if(num_black == 0) {
    return;
  }
  for(int x = 0; x < 100; x += 2) {
    for(int y = 0; y < 49; y += 2) {
      board[x][y] = WHITE;
      num_black--;
      if(num_black == 0) {
        return;
      }
    }
  }
}

void fill_black(int num_white)
{
  if(num_white == 0) {
    return;
  }
  for(int x = 0; x < 100; x += 2) {
    for(int y = 51; y < 100; y += 2) {
      board[x][y] = BLACK;
      num_white--;
      if(num_white == 0) {
        return;
      }
    }
  }
}

void make_board(int num_black, int num_white)
{
  fill_black(num_black-1);
  fill_white(num_white-1);
}

void print_board()
{
  for(int x = 0; x < 100; x++) {
    for(int y = 0; y < 100; y++) {
      if(board[x][y] == BLACK) {
        putchar('#');
      } else if(board[x][y] == WHITE) {
        putchar('.');
      } else {
        fprintf(stderr, "Unknown Cell found: %d\n", board[x][y]);
        exit(1);
      }
    }
    putchar('\n');
  }
}

int main()
{
  int num_white, num_black;
  scanf("%d%d", &num_white, &num_black);
  init_board();
  make_board(num_black, num_white);
  printf("%d %d\n", 100, 100);
  print_board();

  return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		int sum = 0;
		Scanner scan = new Scanner(System.in);
		HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
		int N = scan.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
			if(hashMap.get(a[i]) == null) {
				hashMap.put(a[i], 1);
			} else {
				hashMap.put(a[i], (hashMap.get(a[i]) + 1));
			}
		}
		for(Integer i : hashMap.keySet()) {
			if(hashMap.get(i) == i) {
				
			} else {
				if(hashMap.get(i) < i) {
					sum += hashMap.get(i);
				} else {
					sum += hashMap.get(i) - i;
				}
			}
		}
		System.out.println(sum);
		scan.close();

	}

}


Measured memory_bytes: 63376
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;

#define pii pair<int,int>
#define valid(nx,ny,r,c) nx>=0 && nx<r && ny>=0 && ny<c
int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1};

char cell[50][50];
int main() {
    int i,j,k,r,c;
    cin>>r>>c;
     for(i=0; i<r; i++)
        for(j=0; j<c; j++)
           cin>>cell[i][j];


    for(i=0; i<r; i++) {
        for(j=0; j<c; j++) {
            int cnt=0;
            if(cell[i][j]=='.') {
                for(k=0; k<8; k++) {
                    int nx=i+fx[k];
                    int ny=j+fy[k];
                    if(valid(nx,ny,r,c))
                    {
                        if(cell[nx][ny]=='#')
                        cnt++;
                    }

                }
                cell[i][j]=cnt+'0';
            }
        }
    }

    for(i=0; i<r; i++) {
        for(j=0; j<c; j++)
            cout<<cell[i][j];
        cout<<endl;
    }



    return 0;

}





Measured memory_bytes: 256