akhauriyash/Code-Regression huggingface dataset:
while True:
    n=input()
    if n==0:break
    L=map(int,raw_input().split())
    temp=[]
    F=[]
    for i in range(n-1):
        if L[i]+1==L[i+1]:
            temp.append(L[i])
        else:
            temp.append(L[i])
            F.append(temp)
            temp=[]
    else:
        temp.append(L[n-1])
        F.append(temp)
    S=[]
    for ls in F:
        if len(ls)!=1:
            S.append(str(ls[0])+"-"+str(ls[-1]))
        else:
            S.append(str(ls[0]))
    print " ".join(S)

Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int G[100][100];
   
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      G[i][j]=(i==j?0:1000);
   
  int n,e;
  cin>>n>>e;
   
  for(int i=0;i<e;i++){
    int a,b;
    cin>>a>>b;
    G[a][b]=-1;
  }
   
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
   
  for(int i=0;i<n;i++){
    if(G[i][i]<0){
      cout<<1<<endl;
      return 0;
    }
  }
   
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split(' '))

c = [[0 for j in range(w)] for i in range(h)]

for i in range(h):
    line = input()
    for j in range(w):
        c[i][j] = line[j]

ans = 0

for il in range(1<<h):
    for jl in range(1<<w):
        count = 0
        for i in range(h):
            for j in range(w):
                if il>>i&1: continue
                if jl>>j&1: continue
                if c[i][j] == '#': count += 1
        if count == k: ans += 1

print(ans)


Measured memory_bytes: 9176
#include<iostream>
#include<stack>
#include<queue>

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  
  while(1){

    cin >> n >> r;
    if(r == 0 || n == 0)
      break;

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
      //cout << "done" << endl;
    }
  }

  return 0;
}

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

using P = pair<int, int>;

constexpr int MAX_Y = 10003;
constexpr int MAX_X = 10003;

int main() {
    int n, r;
    while(cin >> n >> r, n) {
        vector<vector<P>> v(MAX_Y);
        for(int i=0; i<n; ++i) {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            ++x1; ++y1; ++x2; ++y2;
            v[y1].emplace_back(x1, 1);
            v[y1].emplace_back(x2, -1);
            v[y2].emplace_back(x1, -1);
            v[y2].emplace_back(x2, 1);
        }
        vector<vector<int>> sum(2, vector<int>(MAX_X));
        int S = 0, len = 0;
        for(int i=0; i<MAX_Y; ++i) {
            int now = i % 2, pre = (i+1) % 2;
            fill(sum[now].begin(), sum[now].end(), 0);
            for(int j=0; j<v[i].size(); ++j) {
                sum[now][v[i][j].first] += v[i][j].second;
            }
            for(int j=0; j<MAX_X; ++j) {
                sum[now][j+1] += sum[now][j];
                sum[now][j] += sum[pre][j];
            }
            for(int j=0; j<MAX_X; ++j) {
                S += sum[now][j] > 0;
                len += ((sum[pre][j] > 0) != (sum[now][j] > 0));
                len += ((sum[now][j] > 0) != (sum[now][j+1] > 0));
            }
        }
        
        if(r == 1) {
            cout << S << endl;
        } else {
            cout << S << '\n' << len << endl;
        }
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

string s, t;
int ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//freopen("in.txt", "r", stdin);
	
	cin >> s >> t;
	int n = s.length(), m = t.length();
	ans = m;
	n = n - m + 1;
	REP(i, 0, n) {
		int k = 0;
		REP(j, i, i + m) {
			k += (s[j] != t[j-i]);
		}
		ans = min(ans, k);
	}
	cout << ans;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
const int mod = 1e9+7;

const double pi = acos(-1);

int main(){
    double r;
    cin>>r;
    double res = 2*r*pi;
    printf("%.10f\n",res);

	return 0;
}


Measured memory_bytes: 3808
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int main() {
	int N, K, dummy;
	dummy = scanf("%d %d", &N, &K);

	char ok[10];
	memset(ok, 1, sizeof(ok));

	int tmp1;
	for (int i = 0; i < K; i++) {
		dummy = scanf("%d", &tmp1);
		ok[tmp1] = 0;
	}
	
	for (int yen = N; yen < 100000; yen++) {
		char ss[6];
		bool NG = false;
		sprintf(ss, "%d", yen);
		for (int i = 0; ss[i] != 0; i++) {
			if (ok[ss[i] - '0'] == 0) {
				NG = true;
				break;
			}
		}
		if (!NG) {
			printf("%d", yen);
			return 0;
		}
	}

	return 0;
}


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

namespace ABC136_E
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var factorial = CalcFactorial(A.Sum());
            factorial.Sort();
            factorial.Reverse();

            int ans = 1;
            foreach (var f in factorial)
            {
                var facd = A.Select(x => x % f).ToArray();
                int numf = facd.Sum() / f;
                var big = facd.OrderByDescending(x => x).Take(numf).Select(x => f - x).Sum();

                if (big > K)
                {
                    continue;
                }

                ans = f;
                break;
            }

            Console.WriteLine(ans);
        }

        private static List<int> CalcFactorial(int v)
        {
            var ret = new List<int>();
            for (int i = 2; i * i < v; i++)
            {
                if (v % i == 0)
                {
                    ret.Add(i);
                    ret.Add(v / i);
                }
            }

            ret.Add(v);

            return ret;
        }
    }
}


Measured memory_bytes: 17572
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(3);
    string s,s1,s2;
    cin >> n >> x;  
    cout << n-x+1 << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main() {
    int n, m; cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(3, 0));
    rep(i, n) cin >> a[i][0] >> a[i][1] >> a[i][2];

    ll res = 0;
    for (int bit = 0; bit < (1<<3); ++bit) {
        vector<ll> b;
        rep(i, n) {
            ll tmp = 0;
            rep(j, 3) {
                if (bit & (1<<j)) tmp += a[i][j];
                else tmp -= a[i][j];
            }
            b.push_back(tmp);
        }
        sort(all(b), greater<ll>());
        ll sum = 0;
        rep(i, m) sum += b[i];
        res = max(res, sum);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
src = [input() for i in range(H)]
MOD = 10**9+7

dp = [[0]*W for i in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if j+1 < W and src[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
            dp[i][j+1] %= MOD
        if i+1 < H and src[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= MOD
print(dp[-1][-1])

Measured memory_bytes: 54000
#include<stdio.h>
#include<stdlib.h>
#define N 1000

int top=0,S[N];

void push(int x){
  if(top==N){
    printf("Stack overflow!\n");
    exit(2);
    }
   S[++top]=x;
}
int pop(void){
   if(top==0){
    printf("Stack is empty!\n");
    exit(3);
    }
   top--;
   return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];

  //%sは空白も一緒に読み取ってくれる
  while( scanf("%s", s) != EOF){
    if(s[0]=='+'){
      push(pop()+pop());
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      push(pop()*pop());
    }
    else{
      push(atoi(s));    //atoi関数は文字数字を変換して数字にする
    }
  }

  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	cout<<max(a*b,c*d)<<"\n";

	return 0;
}

Measured memory_bytes: 256
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,M = na()
MOD=1000000007
#壊れいている段の数
a=[]
dp = [0]*(N+1)
dp[0]=1
a = [ni() for i in range(M)]
isbro = [1]*(N+1)
for i in range(M):
    isbro[a[i]]=0
#print(isbro)
for i in range(N):
    if(i-1>=0):
        dp[i+1] = dp[i]*isbro[i] + dp[i-1]*isbro[i-1]
    else:
        dp[i+1] = dp[i]*isbro[i]
    dp[i+1]%=MOD
#print(dp)
print(dp[N])

Measured memory_bytes: 9600
#include<iostream>
#include<set>
using namespace std;
int main() {
    int q;
    cin >> q;

    long A = 0, B = 0;
    
    multiset<int> ls, rs;

    while (q--) {
        int flag;
        cin >> flag;
        flag--;
        if (flag) {
            cout << *ls.rbegin() << ' ' << A + B << endl;
        } else {
            int a, b;
            cin >> a >> b;

            int precenter = a;
            if(ls.size() != 0) precenter = *ls.rbegin();

            B += b;

            if (ls.size() == 0) ls.insert(a);
            else if (a <= *ls.rbegin()) {
                ls.insert(a);
                if (ls.size() - 1 > rs.size()) {
                    rs.insert(*ls.rbegin());
                    auto itr = ls.end();
                    itr--;
                    ls.erase(itr);
                }
            } else {
                rs.insert(a);
                if (ls.size() < rs.size()) {
                    ls.insert(*rs.begin());
                    rs.erase(rs.begin());
                }
            }

            A += abs(a - *ls.rbegin());
            A += ((long)(*ls.rbegin() - precenter)) * (ls.size() - 1 - rs.size());

        }
    }
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

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

    ll N;
    string S;
    cin >> N >> S;
    vec R(N + 1), G(N + 1), B(N + 1);

    rep(i, N){
        if(S[i] == 'R') R[i + 1] = 1;
        if(S[i] == 'G') G[i + 1] = 1;
        if(S[i] == 'B') B[i + 1] = 1;
    }
    rep(i, N) R[i + 1] += R[i], G[i + 1] += G[i], B[i + 1] += B[i];

    ll ans = 0;
    rep(i, N) rep(j, N) if(i < j){
        if((S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R')){
            ans += B[N] - B[j];
            if(2 * j - i < N) if(S[2 * j - i] == 'B') --ans;
        }
        if((S[i] == 'R' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'R')){
            ans += G[N] - G[j];
            if(2 * j - i < N) if(S[2 * j - i] == 'G') --ans;
        }
        if((S[i] == 'G' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'G')){
            ans += R[N] - R[j];
            if(2 * j - i < N) if(S[2 * j - i] == 'R') --ans;
        }
    }

    print(ans);

    return 0;
}

Measured memory_bytes: 3704
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
  
 int main()
 {
   int a[4],b[4];
   int sum1,sum2;
   while(cin>>a[0])
   {
     sum1=sum2=0;
     for(int i=1;i<4;i++) cin>>a[i];
     for(int i=0;i<4;i++) cin>>b[i];
     for(int i=0;i<4;i++) sum1+=a[i];
     for(int i=0;i<4;i++) sum2+=b[i];
     if(sum1>sum2) cout<<sum1<<endl;
     else cout<<sum2<<endl;                
   }
   //while(1);      
   return 0;    
 }

 

Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (C > A + B + 1) {
		cout << 2 * B + A + 1 << endl;
	}
	else {
		cout << B + C << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	int ans = 0;
	for(int A = 0; A <= 100; A++) {
		int count = 0;
		for(auto v: a) count += (v >= A);
		if(count >= A) ans = A;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 3196
# 3個のパックにそれぞれ、a,b,c個のキャンディーが入っている
# キャンディーを2人に分ける際、個数が等しくなるか判定

# 入力
a, b, c = map(int, input().split())

# 処理
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9096
/*#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int  n;
    cin >> n;

    cout << 3*n*n << endl;
    return 0;

}

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


int main() {
	string input;
//	cin >> input;
	getline(cin, input);
	for (char& c : input) {
		if (c >= 'a' && c <= 'z') c = toupper(c);
		else if (c >= 'A' && c <= 'Z') c = tolower(c);
	}
	cout << input << endl;
	return 0;
}

Measured memory_bytes: 3096
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

min_cost = []
for k in range(2 ** n):
    cost = 0
    und = [0 for _ in range(m)]
    for i in range(n):
        if (k >> i) & 1 == 1:
            cost += a[i][0]
            for j in range(m):
                und[j] += a[i][j + 1]
    for j in range(m):
        if und[j] < x:
            break
    else:
        min_cost.append(cost)

if len(min_cost) == 0:
    print('-1')
else:
    print(min(min_cost))

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

int main(){
  int N;cin>>N;
  map<int,int>M;
  for(int i=0;i<N;i++){
    int a;cin>>a;
    if(M.count(a))
      M.at(a)++;
    else
      M[a]=1;
  }
  
  int res=M.size();
  int count=0;
  
  for(auto p : M){
    auto number=p.second;
    if(number%2==0)
      count++;
  }
  
  if(count%2!=0)
    res--;
  
  cout<<res;
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        _r: usize,
        g: usize,
        b: usize
    }
    println!("{}", if (10 * g + b) % 4 == 0 {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
/* created   : 2019-09-04 00:15:28
 * accepted  : 2019-09-04 00:16:04
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  string s, t; cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) {
      ans++;
    }
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mo 1000000007
#define N 5010
using namespace std;
int fa[N],a[N],n,sum,s2,si[N],b[N],nb;
ll ans,dp[N][N],jie[N];
int que(int x){if (fa[x]!=x)fa[x]=que(fa[x]);return fa[x];}
ll po(ll x,ll y){ll z=1;while (y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
void jb(int x,int y){
	int nx=que(x),ny=que(y);
	if (nx!=ny)fa[nx]=ny,si[ny]+=si[nx];else sum++;
}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++)fa[i]=i,si[i]=1;
	jie[0]=1;
	for (int i=1;i<=n;i++)jie[i]=jie[i-1]*i%mo;
	for (int i=1;i<=n;i++){
		cin>>a[i];
		if (a[i]!=-1)jb(i,a[i]);
	}
	for (int i=1;i<=n;i++)if (a[i]==-1){s2++;b[++nb]=si[que(i)];}
	ans=(n-sum)*po(n-1,s2)%mo;
	for (int i=1;i<=nb;i++){
		if (b[i]>1)ans=(ans+(b[i]-1)*(mo-po(n-1,s2-1)))%mo;
	}
	dp[0][0]=1;
	for (int i=1;i<=nb;i++){
		for (int j=0;j<i;j++){
			dp[i][j]=(dp[i][j]+dp[i-1][j])%mo;
			dp[i][j+1]=(dp[i][j+1]+dp[i-1][j]*b[i])%mo;
		}
	}
	for (int i=2;i<=nb;i++)ans=(ans+(dp[nb][i]*(mo-po(n-1,s2-i))%mo)*jie[i-1])%mo;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 120272
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a, n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a  ,min(b, c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a, n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main()
{
    int n, k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<n+1;i++)
    {
        cin>>arr[i];
    }
    int dp[n+1];
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    for(int i=3;i<n+1;i++)
    {
        int minm = INT_MAX;
        for(int j=1;j<k+1;j++)
        {
            if(i-j>0)
            {
                int diff = dp[i-j] + abs(arr[i] - arr[i-j]);
                if(diff < minm)
                {
                    minm = diff;
                }
            }
        }
        dp[i] = minm;
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int n,m,ans;
int a[111111];
signed main(){
    cin>>n>>m;
    int sum=0;
    rep(i,m){
    	cin>>a[i];
    	sum+=a[i];
    }
    if(sum>=n)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          long N = getLong();
          long K = getLong();
          
          N %= K;
          if(N > K / 2){
            N = K % N;
          }
          myout(N);
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 22728
use std::cmp::max;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn gcd(a: i64, b: i64) -> i64 {
    if a == 0 {
        b
    } else if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(i64;;);
    let mut lefts = vec![0];
    let mut left = 0;
    for &v in vs.iter() {
        left = gcd(v, left);
        lefts.push(left)
    }

    let mut rights = vec![0];
    let mut right = 0;
    for &v in vs.iter().rev() {
        right = gcd(v, right);
        rights.push(right)
    }
    rights.reverse();

    let mut ans = 0;
    for i in 0..lefts.len() {
        if i + 1 < rights.len() {
            ans = max(ans, gcd(lefts[i], rights[i + 1]))
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
n = gets.to_i
g = Array.new(n){ [] }
(n-1).times do
  a,b = gets.split.map(&:to_i)
  a -= 1; b -= 1
  g[a] << b
  g[b] << a
end
c = gets.split.map(&:to_i).sort.reverse.each
seen = Array.new(n, -1)
ans = 0
que = [[0,0]]
while que.size > 0
  v, pre = que.pop
  next if seen[v] != -1
  now = c.next
  seen[v] = now
  ans += pre < now ? pre : now
  g[v].each do |nv|
    que << [nv, now]
  end
end
 
puts ans
puts seen.join(" ")

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)
#define MOD 1000000007

int main(void) {
  int n;
  cin >> n;
  int d[n][2];
  rep(i,n) cin >> d[i][0] >> d[i][1];
  bool key = false;
  rep(i,n-2) {
    if(d[i][0]==d[i][1] && d[i+1][0] == d[i+1][1] && d[i+2][0]==d[i+2][1]) {
      key = true;
      //cout << "Yes" << endl;
    }
  }
  if(key==false)
  cout << "No" << endl;
  else 
  cout << "Yes" << endl;
}

Measured memory_bytes: 3620
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    s = IS()
    cnt = len(s)
    for c in set(s):
        dist = 0
        max_d = 0
        for si in s:
            if c != si:
                dist += 1
            else:
                max_d = max(max_d, dist)
                dist = 0
        cnt = min(cnt, max(max_d, dist))
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		int max = 0;
		int maxindex = 0;
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
			if(a[i] > max){
				max = a[i];
				maxindex= i;
			}
		}
		Arrays.sort(a);
		int anotherNum = a[n-2];
		for(int i = 0;i < n;i++){
			if(i == maxindex){
				System.out.println(anotherNum);
			} else {
				System.out.println(max);
			}
		}
		saori.close();
    }
}

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

Measured memory_bytes: 68808
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) {
	int ans = 1;
	while (n) {
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a,b; cin >> a >> b;
	int sockets = 1, ans = 0, allowed = 1, ptr = 0;
	while (sockets < b) {
		sockets = sockets-1+a;
		++ans; ++ptr;
		if (ptr == allowed) {
			allowed *= a;
			ptr = 0;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    count = 0
    if not(n or x):
        break
    for i in range(1, n-1, 1):
        for j in range(i+1, n, 1):
            for k in range(j+1, n+1, 1):
                if i + j + k == x:
                    count += 1
    print(count)

Measured memory_bytes: 7640
#include<stdio.h>
#include<string.h>
int main()
{
    char S[100];
    char S1[100]="Cloudy";
    char S2[100]="Rainy";
    char S3[100]="Sunny";
  

    gets(S);


    if(strcmp(S,S3)==0)
    {
        printf("%s\n",S1);
    }
    else if(strcmp(S,S1)==0)
    {
        printf("%s\n",S2);
    }
    else if(strcmp(S,S2)==0)
    {
        printf("%s\n",S3);
    }

    return 0;
}



Measured memory_bytes: 128
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    int k = sc.nextInt();
    
    if ((e - a) <= k) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    while(1){
    int x,y,z,dp[50][50]={0};
    cin>>x>>y;
    if(x==0 && y==0)break;
    cin>>z;
    for(int i=0;i<z;++i){
        int xx,yy;
        cin>>xx>>yy;
        dp[xx][yy]=-1;
        }
    for(int i=1;i<=x;i++){
        for(int j=1;j<=y;j++){
            if(dp[i][j]!=-1){
                int xxx,yyy;
                xxx=dp[i][j-1];
                yyy=dp[i-1][j];
                if(xxx==-1)dp[i][j]=yyy;
                else if(yyy==-1)dp[i][j]=xxx;
                else dp[i][j]=xxx+yyy;
                }
                if(i==1 && j==1)dp[i][j]=1;
            }
        }
    cout<<dp[x][y]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1176
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,r,x,y,z;
	long ans;
	int[] Ai;
	int[] rank = new int[31];
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		m = sc.nextInt();

		Ai = new int[n];

		for(int i=0;i<n;i++){
			Ai[i] = sc.nextInt();
		}

		Arrays.sort(Ai);
		int val = 0;

		for(int i=0;i<n;i++){
			while(Math.pow(2,val)<Ai[i]){
				val++;
			}
			rank[val]++;
		}

		while(m>0){
			int Aidx = n-1;
			for(int t=rank[val];t>0;t--){
				Ai[Aidx] /= 2;
				m--;	Aidx--;
				if(m<=0||Aidx<0)break; 
			}
			if(val>0)rank[val-1] += rank[val];
			else break;
			val--;
			Arrays.sort(Ai);
		}

		for(long l:Ai){
			ans += l;
		}

		// 出力
		System.out.println(ans);
	}

	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 49512
from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.extend([0])
s=0
for i in range(1,N+2):
    s+=abs(A[i]-A[i-1])
for i in range(1,N+1):
    print(s-((abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))-abs(A[i-1]-A[i+1])))

Measured memory_bytes: 14296
def even_line(w):
    s=''
    for i in range(0,w):
        if i%2 == 0:
            s=s+'#'
        else:
            s=s+'.'
    print(s)

def odd_line(w):
    s=''
    for i in range(0,w):
        if i%2 == 0:
            s=s+'.'
        else:
            s=s+'#'

    print(s)

if __name__ == '__main__':

    h, w = map(int, input().split())

    while (h != 0) and (w != 0):
        for i in range(0,h):
            if i%2==0:
                even_line(w)
            else:
                odd_line(w)
        h, w = map(int, input().split())
        print()


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define maxn 1005
#define dbg(n) cout << n << endl
using namespace std;

inline void read(int &x){
	int f = 1; x = 0; char s = getchar();
    while(s > '9' || s < '0'){
		if(s == '-') f = -1;
		s = getchar();
	}
    while(s <= '9' && s >= '0'){
		x = x * 10 + s - '0';
		s = getchar();
	}
    x = x * f;
}

int main(){
	string s;
	cin >> s;
	s[5] = s[13] = ' ';
	cout << s << endl;
	return 0;
}


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

int n,m;
vector <pair<int,int> > a[200002];
bool vis[100001];
int d[100001];

bool dfs(int x,int y) {
	if (vis[x]) return d[x]!=y;
	vis[x]=true;
	d[x]=y;
	for (int i=0;i<a[x].size();i++) {
		if (dfs(a[x][i].first,d[x]+a[x][i].second)) return true;
	}
	return false;
}

int main(){
	memset(vis,false,sizeof(vis));
	scanf("%d %d",&n,&m);
	for (int i=0;i<m;i++) {
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		x--;y--; 
		a[x].push_back(make_pair(y,z));
		a[y].push_back(make_pair(x,-z));
	}
	for (int i=0;i<n;i++) {
		if (!vis[i]&&dfs(i,0)) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 14464
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  let
    detectCycle :: Eq a => (a -> a) -> a -> ((Int, a), Int)
    detectCycle f = start 0 <$> id <*> (knot <$> id <*> id)
      where
        -- knot = a -> a -> a
        knot x y | x' == y'  = x'
                 | otherwise = knot x' y'
          where
            x' = f x
            y' = f (f y)
        -- start :: Int -> a -> a -> ((Int, a), Int)
        start k x y | x == y    = ((k, x), period x)
                    | otherwise = start (succ k) (f x) (f y)
        -- period :: a -> Int
        period x = period' 1 (f x)
          where
            period' k y | x == y    = k
                        | otherwise = period' (succ k) (f y)
  [n, x, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    next :: Int -> Int
    next y = y * y `mod` m
    as = iterate next x :: [Int]
    ((h, k), l) = detectCycle next x
    (stem, cycle) = splitAt h . take (h + l) $ as
    h' = min h n :: Int
    n' = n - h' :: Int
    (q, r) = n' `divMod` l :: (Int, Int)
  print $ sum (take h' stem) + q * sum cycle + sum (take r cycle)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 6880
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count=0;
    rep(i,N) if(S[i]=='R') count++;
    if(count*2>N) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> A(N, K - Q);
  REP(i, Q){
    int j; cin >> j; j--;
    A[j]++;
  }
  REP(i, N){
    if(A[i] > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int r,g,b,n;
  cin>>r>>g>>b>>n;
  
  int cnt=0;
  
  for(int i=0;i<=3000/r;i++){
    for(int j=0;j<=3000/g;j++){
      int cs=n-(i*r+j*g);
      if(cs%b==0&&cs>=0){
        cnt++;}
    }
  }
  
  cout<<cnt<<endl;
 
}

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

int main(){
  int N; cin >> N;
  string W[N+1];
  bool flag = true;
  for (int i=0; i<N; i++) {
    cin >> W[i];
  }
  //condition 1
  for (int i=0; i<N-1; i++) {
    if (W[i].back() != W[i+1].front()) {
      flag = false;
    }
  }
  //condition 2
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      if (W[i] == W[j]) {
        flag = false;
      }
    }
  }
  // result
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

const int INF = 1e9;

struct edge{
  int from,to,cap,rev;
  edge(int a,int b,int c,int d)
    :from(a),to(b),cap(c),rev(d){}
};

struct dinic{
  int n;
  vector< vector<edge> > graph;
  vi level,iter;

  dinic(int a=0):n(a){graph.resize(a);}

  void AddEdge(int s,int g,int c){
    graph[s].pb( edge(s,g,c,graph[g].sz) );
    graph[g].pb( edge(g,s,0,graph[s].sz-1) );
  }

  void DeleteEdge(int s, int g){
    int id = -1, rev = -1;
    rep(e,graph[s].sz){
      if(graph[s][e].to == g){
	id = e; rev = graph[s][e].rev;
      }
    }
    if(id<0)return;

    swap(graph[s][id],graph[s].back());
    swap(graph[g][rev],graph[g].back());
    graph[s][id].rev = rev;
    graph[g][rev].rev = id;
    graph[s].pop_back(); graph[g].pop_back();
  }

  void bfs(int s){
    level = vi(n,-1);
    level[s] = 0;
    queue<int> q; q.push(s);
    while(q.sz){
      int v = q.front(); q.pop();
      for(edge e: graph[v]){
	if(e.cap > 0 && level[e.to] < 0){
	  level[e.to] = level[v] + 1;
	  q.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v, int t, int f){
    if(v==t)return f;
    for(int &i = iter[v];i<(int)graph[v].sz;i++){
      edge &e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d > 0){
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t){
    int res = 0;
    for(;;){
      bfs(s);
      if(level[t]<0)return res;
      iter = vi(n,0);
      int f;
      while((f=dfs(s,t,INF))>0)res += f;
    }
  }
};

int main(){
  int n,m,l;
  cin.tie(); ios::sync_with_stdio(0);
  while(cin >> n >> m >> l){
    vector< vector<int> > d(n, vector<int>(n,INF));
    rep(i,n)d[i][i] = 0;

    rep(i,m){
      int a,b,c;
      cin >> a >> b >> c; a--; b--;
      d[a][b] = d[b][a] = c;
    }

    rep(k,n)rep(i,n)rep(j,n)d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    int V = 2*n+2, S = V-2, T = V-1;
    dinic mf(V);
    rep(i,n){
      int p; cin >> p;
      mf.AddEdge(S,i,p);
    }
    rep(i,n){
      int k; cin >> k;
      mf.AddEdge(i+n,T,k);
    }

    rep(i,n)rep(j,n){
      if(d[i][j]<l)mf.AddEdge(i,j+n,INF);
    }

    cout << mf.max_flow(S,T) << endl;
  }
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	map<int, int> even, odd;
	rep(i,n) {
		if (i % 2 == 0) even[v[i]]++;
		else odd[v[i]]++;
	}
	vector<pii> u, w;
	for (auto p: even) {
		u.push_back(pii(p.second, p.first));
	}
	for (auto p: odd) {
		w.push_back(pii(p.second, p.first));
	}
	sort(ALL(u), greater<>());
	sort(ALL(w), greater<>());

	if (u[0].second != w[0].second) {
		cout << n - u[0].first - w[0].first << endl;
	} else {
		int x = n - u[0].first - w[1].first;
		int y = n - u[1].first - w[0].first;
		cout << min(x, y) << endl;
	}
}

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

Measured memory_bytes: 9308
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll prime[111111];
ll a[111111];
ll sum[111111];

signed main()
{
	vector<ll> ans;
	int prime_count = 2;
	prime[0] = 2;
	a[2] = 1;
	prime[1] = 3;
	a[3] = 1;
	for(ll i=4; i<=100000; i++){
		bool flag = true;
		for(int k=0; k<prime_count; k++){
			if(i%prime[k]==0){
				flag = false;
				break;
			}
		}
		if(flag){
			prime[prime_count] = i;
			a[i] = 1;
			prime_count++;
		}
	}
	sum[0] = 0;
	sum[1] = 0;
	for(int i=2; i<=50000; i++){
		if(a[2*i-1]==1 and a[i]==1){
			sum[i] = sum[i-1]+1;
		}else{
			sum[i] = sum[i-1];
		}
	}
	ll Q;
	cin >> Q;
	REP(i, Q){
		ll l, r;
		cin >> l >> r;
		ans.PB(sum[(r+1)/2]-sum[(l-1)/2]);
	}
	for(auto v : ans){
		cout << v << endl;
	}
}


Measured memory_bytes: 5428