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

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
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; }

using namespace std;

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

    cin >> a >> b >> c;

    if (a == b && a != c) {
        cout << "Yes" << endl;
        return 0;
    } else if (b == c && b != a) {
        cout << "Yes" << endl;
        return 0;
    } else if (a == c && a != b) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import math

def combination_count(n,k):
    if k > n or k < 0:
        return 0
    if n == 0 or k == 0:
        return 1
    
    s = math.factorial(n)
    t = math.factorial(k)
    u = math.factorial(n-k)
    
    return s//(t*u)
    
n,k = map(int,input().split())

mod = 10**9 + 7

for i in range(1,k+1):
    x = combination_count(n-k+1,i) * combination_count(k-1, i-1)
    print(x%mod)
    

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>
#include<math.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}
#define MAX(a,b) ( ((a)>(b)) ? (a):(b) )

int main(){
    char str[100];
    int i;

    my_gets(str,100,stdin);
    for(i=0; str[i]!='\0'; i++){
        if(str[i]==str[i+1]){
            puts("Bad");
            return 0;
        }
    }
    puts("Good");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct po{int y,x;};
int w,h,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
string mp[61];
queue <po> Q;
int xl,xr;
double sum,cnt;

void dfs(int y,int x,int used[62][11]){
  if(used[y][x]++)return;
  sum+=x+0.5,cnt++;
  int ch=mp[y][x];
  if(mp[y+1][x]!=ch&&mp[y+1][x]!='.')xl=min(xl,x),xr=max(xr,x);
  if(y-1>=0&&mp[y-1][x]!=ch&&mp[y-1][x]!='.') Q.push(po{y-1,x});
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(!(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]!=ch))dfs(ny,nx,used);
  }
}

bool check(int l,int r){
  int used[62][11]={};
  while(!Q.empty())dfs(Q.front().y,Q.front().x,used),Q.pop();
  double g=sum/cnt;
  return l<g&&g<r;
}

string solve(){
  int used[62][11]={};
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(mp[i][j]=='.'||used[i][j])continue;
      xl=100,xr=-1;
      sum=cnt=0;
      dfs(i,j,used);
      if(!check(xl,xr+1))return "UN";
    }
  return "";
}

int main(){
  while(1){
    cin>>w>>h;
    if(!h&&!w)break;
    for(int i=0;i<h;i++)cin>>mp[i];
    mp[h].clear();
    for(int i=0;i<w;i++)mp[h]+='#';
    cout <<solve()<<"STABLE"<<endl;
  }
  
  return 0;
}

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

#define int long long

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    vector<int> v(x);
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++) {
        if (x[i] <= v[N / 2 - 1]) cout << v[N / 2]<< endl;
        else cout << v[N / 2 - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 5376
n,m = map(int,input().split())

a = []
b = []

for i in range(n):
    s=list(input())
    a.append(s)
for i in range(m):
    s=list(input())
    b.append(s)

k = 0 # 1 nara ok
c = 0
d = 0

for i in range(n-m+1):
    for j in range(n-m+1):
        v = 0
        for w in range(m):
            for r in range(m):
                if b[w][r] == a[i+w][j+r]:
                    v += 1
        if v == m**2:
            k = 1

if k == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from bisect import bisect_right
from itertools import accumulate

N, M, K = [int(x) for x in input().split()]

a_book = [0] + list(accumulate([int(x) for x in input().split()]))
b_book = [0] + list(accumulate([int(x) for x in input().split()]))

check = {}

max_books = 0

for i, a in enumerate(a_book):
    if a > K:
        break

    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)


Measured memory_bytes: 44324
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	m := make(map[string]bool)
	for i := 0; i <= 999; i++ {
		v := fmt.Sprintf("%03d", i)
		k := 0
		for j := 0; j < n; j++ {
			if s[j] == v[k] {
				k++
				if k == 3 {
					m[v] = true
					break
				}
			}
		}
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main() {
    int n; cin>>n;
    vector<int> a;
    for(int i = 0; i < 2 * n; i++) {
        int l; cin>>l;
        a.push_back(l);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < 2*n; i+=2) {
        ans += min(a[i], a[i+1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
pTa :: String -> String
pTa [] = []
-- somewhat weird
pTa v = case splitAt 5 v of
            ("apple",s) -> "peach" ++ pTa s
            ("peach", s) -> "apple" ++ pTa s
            _ -> let (pr, po) = break (\c -> (c == 'a') || (c == 'p')) (tail v)
                     in head v : pr ++ pTa po

main = getLine >>= putStrLn . pTa

Measured memory_bytes: 3628
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, X);
    IN(ll, Y);
    REP(i, X + 1)
    {
        REP(j, X + 1)
        {
            if (i + j == X and 2 * i + 4 * j == Y)
            {
                OUT("Yes");
                return 0;
            }
        }
    }
    OUT("No");
}

Measured memory_bytes: 3580
a = input().split()
b = len(a)
c = int(a[0])
d = int(a[1])
e = int(a[2])
f = int(a[3])
g = int(a[4])

if g >= 60:
    h = g//60
    i = g%60
    if f>=i:
        A = e-h
        B = f-i
    else:
        A = e-h-1
        B = 60-(i-f)
else:
    if g<=f:
        A = e
        B = f-g
    else:
        A = e-1
        B = 60-(g-f)
if B>=d:
    C = A-c
    D = B-d
else:
    C = A-c-1
    D = 60-(d-B)
E = C*60
F = E+D
print(F)

Measured memory_bytes: 9228
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int ans = 0;
	if(x<4) {
	    System.out.println(1);
	    return;
	}
	for(int i = 2; i<40; i++) {
	    int tmp = i;
	    int cnt = 0;
	    while(tmp<=x) {
		tmp *= i;
		cnt++;
	    }
	    if(cnt>=2) ans = Math.max(ans, tmp/i);
	}
	System.out.println(ans);
    }
}

Measured memory_bytes: 22868
def is_ans(n:int) -> int:
    count = 0
    for i in range(1,n+1):
        if n%i == 0:
            count += 1
    return count

def main():
    tmp = 0
    ans = 0
    n = int(input())
    for i in range(1,n+1):
        if i%2 == 1:
            tmp = is_ans(i)
        if tmp == 8:
            ans += 1
        tmp = 0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os") 

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=5e2+10, lg=23, mod=1e9+7, inf=1e18;

ll h,w;
map<ll,bool> a[maxn],b[maxn];


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

	cin>>h>>w;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		char c; cin>>c;
		if(c=='#') a[i][j]=b[i][j]=1;
		if(i==0)        a[i][j]=1;
		else if(i==h-1) b[i][j]=1;
		else if(j%2)    a[i][j]=1;
		else            b[i][j]=1;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cout<<(a[i][j]?'#':'.');
		cout<<endl;
	}
	cout<<endl;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cout<<(b[i][j]?'#':'.');
		cout<<endl;
	}

	return 0;
}








 






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

int main(){	
	int N;
	double R=0;
	cin >> N;
	vector<pair<int, int>> Town(N);
	for (int i=0; i<N; i++){
		int x,y;
		cin >> x >> y;
		Town.at(i) = make_pair(x,y);
	}
	
	for (int i=0; i<N; i++){
		for (int j=i+1; j<N; j++){
			R += sqrt(pow(Town.at(i).first-Town.at(j).first,2) + pow(Town.at(i).second-Town.at(j).second,2));
		}
	}

	R = R*2/N;
	
	cout << setprecision(10) << R << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cassert>
using namespace std;

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

int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
int n;

inline char atc(string s,int i,int j) { return s.at(i*n+j); }

bool iseliminated(string mp) {
    int i,j;
    rep(i,mp.length()) if(mp[i] == '#') return false;
    return true;
}

pair<int,int> getPos(string mp) {
    int i,j;
    rep(i,mp.length()) if(mp[i] == '@') return make_pair(i/n,i%n);
}


string update(string &mp) {
    int i,j,k;
    string tmp = mp;

    rep(i,n) rep(j,n) {
        int adj = 0;
        if(mp.at(i*n+j) == '@') continue;
        rep(k,8) {
            if(i+dy[k] < 0 || i+dy[k] >= n) continue;
            if(j+dx[k] < 0 || j+dx[k] >= n) continue;
            if(mp.at((i+dy[k])*n+(j+dx[k])) == '#'
               || mp.at((i+dy[k])*n+(j+dx[k])) == '@') adj++;
        }
        if(mp.at(i*n+j) == '#') {
            if(adj == 2 || adj == 3) continue;
            else tmp.at(i*n+j) = '.';
        }else{
            if(adj == 3) tmp.at(i*n+j) = '#';
        }
    }
    return tmp;
}

int bfs(string bmap) {
    int i,j;
    queue<pair<int,string > >Q;
    set<string> memo;
    memo.insert(bmap);
    Q.push(make_pair(0,bmap));
    while(!Q.empty()) {
        string nmap = Q.front().second;
        int ii = Q.front().first;
        Q.pop();

        if(nmap.find("#") == string::npos) return ii;
        // if(iseliminated(nmap)) return ii;

        pair<int,int> pos = getPos(nmap);
        for(int i=0; i<8; ++i) {
            if(pos.first+dy[i] < 0 || pos.first+dy[i] >= n) continue;
            if(pos.second+dx[i] < 0 || pos.second+dx[i] >= n) continue;
            if(nmap.at((pos.first+dy[i])*n+(pos.second+dx[i])) == '#') continue;
            string next = string(nmap);
            next.at((pos.first+dy[i])*n+pos.second+dx[i]) = '@';
            next.at((pos.first)*n+pos.second) = '.';
            next = update(next);
            if(memo.find(next) != memo.end()) continue;
            memo.insert(next);
            Q.push(make_pair(ii+1, next));
        }
    }
    return -1;
    assert(false);
}

int main() {
    while(cin>>n, n) {
        string imap = "",tmp;
        for(int i=0; i<n; ++i) {
            cin>>tmp;
            imap += tmp;
        }
        cout<<bfs(imap)<<endl;
    }
}

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

namespace ABC155
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int[] abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(abc);
            if (abc[0] == abc[1] && abc[1] == abc[2])
                Console.WriteLine("No");
            else if (abc[0] != abc[1] && abc[1] != abc[2])
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
      int n;
      cin>>n;
      int w[n];
      rep0(i,n) cin>>w[i];
      int s1=0;
      int s2=0;
      rep0(i,n) s2+=w[i];
      int ans=inf;
      rep0(i,n-1){
            s1+=w[i];
            s2-=w[i];
            ans=min(ans,abs(s2-s1));
      }
      cout<<ans<<endl;

      return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    k = int(input())
    s = input()

    l = len(s)

    if l <= k:
        print(s)
    else:
        print(s[:k]+"...")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

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

template<typename T1, typename T2>
T1 mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  T1 tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

/////////////////////////////////////////////////////////

void Main(){
  int N;
  string S;
  cin >> N >> S;
  int cnt1 = 0;
  int cnt2 = 0;
  int l = 0;
  int r = 0;
  rep(i, 0, N){
    if(S[i] == '('){
      l++;
    }else{
      r++;
      if(r > l + cnt1) cnt1++;
    }
  }
  cnt2 = (l + cnt1) - r;
  rep(i, 0, cnt1) cout << '(';
  cout << S;
  rep(i, 0, cnt2) cout << ')';
  cout << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[3];
    rep(i,3)cin>>a[i];
    vector<ll> l(12,inf);
    rep(i,n)cin>>l[i];
    int all=1<<(24);
    ll ans=inf;
    rep(i,all){
        vector<int> sum(3);
        ll ret=-30;
        rep(j,n){
            int u = (i>>(2*j))&3;
            if(u!=3){
                sum[u]+=l[j];
                ret+=10;
            }
        }
        rep(j,3){
            ret+=abs(a[j]-sum[j]);
            if(!sum[j])ret+=1e7;
        }
        ans=min(ans,ret);
    }
    cout<<ans<<endl;
    return 0;
}



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

int main( )
{
    map<string, int> mp;
    map<string, int>::iterator it;
    int n, i, j, k, mx = 0;
    string s;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    for (it = mp.begin(); it != mp.end(); it++) {
        if ((*it).second == mx) {
            cout << (*it).first << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 26240
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    progs = [[] for _ in range(C)]
    for si, ti, ci in zip(s, t, c):
        progs[ci - 1].append((si, ti))
    ds = []
    for prog in progs:
        if not prog:
            continue
        prog.sort()
        ds.append((prog[0][0] - 1, 1))
        ds.append((prog[-1][1], -1))
        for i in range(len(prog) - 1):
            if prog[i][1] != prog[i + 1][0]:
                ds.append((prog[i][1], -1))
                ds.append((prog[i + 1][0] - 1, 1))
    ds.sort()
    ans = 0
    m = 0
    for _, d in ds:
        m += d
        ans = max(ans, m)
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [int()] * (N)  # type: "List[int]"
    t = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, C, s, t, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37436
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    map<int, int> trades;
    map<int, bool> cont;
    
    string line;
    while(true) {
        getline(cin, line);
        if (line == "") break;

        istringstream is (line);
        int n, c;
        char comma;
        is >> n >> comma >> c;

        trades[n] += 1;
    }

    while(getline(cin, line)) {
        istringstream is (line);
        int n, c;
        char comma;
        is >> n >> comma >> c;
        
        if (trades[n] >= 1)  {
            trades[n] += 1;
            cont[n] = true;
        }
    }

    map<int, int>::iterator itr;
    for(itr = trades.begin(); itr != trades.end(); itr++) {
        if (cont[itr->first]) {
            cout << itr->first << " " << itr->second << endl;
        }
    }

    
    return 0;
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    cout << N*800 - (N/15)*200 << endl;
}


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

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 100003

struct Volume{
	double effectivePrice;
	int litre,price;

	bool operator<(const Volume& a) const {
		return tie(effectivePrice,litre,price) < tie(a.effectivePrice,a.litre,a.price);
	}
};

int main(void)
{
  vector< Volume > vp;
  vp.resize(4);

  lli currLitre = 25;

  for(int i=0;i<4;i++) {
  	scan(vp[i].price);
  	vp[i].litre = currLitre;
  	vp[i].effectivePrice = (double) vp[i].price * 100.0 / (double)vp[i].litre;
  	currLitre = currLitre * 2;
  }

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

  lli n;
  cin>>n;
  n = n * 100;

  lli res = 0;
  //25 50 100 200
  for(int i=0;i<4;i++) {
  	lli used = n / vp[i].litre;
  	res += used * (lli)vp[i].price;
  	//cerr<<vp[i].litre<<" "<<used<<endl;
  	int rem = n % vp[i].litre;
  	n = rem;
  }
  cout<<res;
  return 0;
}


void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 256
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const n = parseInt(readMany(1)[0])
    const a = []
    a.push(readMany(n).map(it => parseInt(it)))
    a.push(readMany(n).map(it => parseInt(it)))

    let max = 0

    for (let i = 0; i < n; i += 1) {
        let candies = 0
        for (let j = 0; j <= i; j += 1) candies += a[0][j]
        for (let j = i; j < n; j += 1) candies+= a[1][j]
        if (candies > max) max = candies
    }

    console.log(max)
})()


Measured memory_bytes: 7372
MODULE bSearchMod
! 二分探索
! 昇順の配列のみ対応。
      IMPLICIT NONE
      
      integer, parameter, private :: p = 8
      
      contains
! key以上の値が現れる最初のインデックスposを返す。
! O( log2(n) )
! 配列arrayはインデックスが1スタートで昇順の状態にしておいてほしい。
! key値がarrayの最大値より大きい場合、配列サイズ+1が返される。
! ex)
! [2, 2, 4, 4, 5]; key = -1
!  pos = 1
!
! [2, 2, 4, 4, 5]; key = 3
!        pos = 3
!
! [2, 2, 4, 4, 5]; key = 100
!                 pos = 6
      function lowerBound( array,key ) result( pos )
        implicit none
        integer(p),intent(in) :: array(1:),key
        integer(p) :: pos
        integer(p) :: left,right,mid
        logical :: isOK
        
        left = 0
        right = size( array )+1
        
        do while( abs(right-left)>1 )
          mid = (left+right)/2 !オーバーフローは考えないよ
          
          isOK = key<=array(mid)
          if( isOK )then
            right = mid
          else
            left = mid
          end if
        end do
        
        pos = right
      end function lowerBound
      
      END MODULE bSearchMod
      
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      PROGRAM tsundoku
      use bSearchMod
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 8
      integer(p) :: n,m,k,ans=0,time
      integer(p), allocatable :: a(:),b(:)
      integer(p) :: i,numB
      
      read*,n,m,k
      allocate( a(0:n),b(m) )
      read*,a(1:n)
      read*,b
      a(0) = 0
      
      do i = 1,n
          a(i) = a(i-1) + a(i)
      end do
      if( m>=2 )then
        do i = 2,m
          b(i) = b(i-1) + b(i)
        end do
      end if
      
      
      do i = 0,n
        time = k-a(i)
        if( time<0 ) cycle
        
        numB = lowerBound(b,time+1)
        if( b(numB)/=time ) numB = numB - 1
        ans = max( ans,i+numB )
      end do
      
      print*,ans
      
      stop
      !debugg
      
      
      
      END PROGRAM

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	string s;
	cin >> s;
	int l=0, r=s.size()-1;
	while((s[l] != 'A' || s[r] != 'Z') && l != r){
		if(s[l] != 'A') ++l;
		if(s[r] != 'Z') --r;
	}
	cout << (l==r? 0:r-l+1);
	

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define yu return
#define xian 0
using namespace std;
char a[105],flag;
int main()
{
	cin>>a;
	flag=0;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='C')
		flag=1;
		if(a[i]=='F'&&flag==1)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";

	yu xian;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char** argv) {
  int a, b;
  std::cin >> a;
  std::cin >> b;

  int s = (a + b);
  int r = s / 2;
  if ((r * 2) == s) {
    std::cout << r << std::endl;
  } else {
    std::cout << "IMPOSSIBLE";
  }
}


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

char cc[123 * 4567];
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   int n, m, ans = 0;
   cin >> n >> m;

   for (int i = 0; i < m; i++)
   {
      int x, y;
      cin >> x >> y;
      cc[x] = 1 ^ cc[x];
      cc[y] = 1 ^ cc[y];
   }
   
   for (int i = 1; i <= n; i++)
   {
      if (cc[i])
      {
         ans = 1;
         break;
      }
   }

   cout << (ans ? "NO" : "YES") << "\n";
   return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int  n; cin >> n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	vector<int> ans;
	ans.push_back(a[0]);
	for(int i=1;i<n;++i)
	{
		if(a[i]<=ans.back())
		{
			ans.push_back(a[i]);
			continue;
		}
		int left = -1,right=ans.size();
		while(1)
		{
			ll mid = ((1LL)*left + (1LL)*right)/2;
			if(a[i]<=ans[mid])left=mid;
			else right = mid;
			if(right-left==1)
			{
				ans[right]= a[i];
				break;
			}
		}
		//rep(i,ans.size())cout<<ans[i]<<" ";cout<<endl;
	}
	
	cout<<ans.size()<<endl;

	return 0;
}


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

typedef long long ll;
const ll N = 1005;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const char typ[5] = "RULD";

ll arm[45], m;
ll n, x[N], y[N];

void solve (ll X, ll Y, ll I) {
	ll CX = 0, CY = 0, CI = -1;
	for(ll i=0;i<4;i++) {
		ll NX = dx[i]*arm[I], NY = dy[i]*arm[I];
		if(CI == -1 || abs(NX-X)+abs(NY-Y) < abs(CX-X)+abs(CY-Y)) {
			CX = NX;
			CY = NY;
			CI = i;
		}
	}
	printf("%c",typ[CI]);
	if(I) solve(X-CX, Y-CY, I-1);
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&x[i],&y[i]);
		if(abs(x[i]+y[i])%2 != abs(x[1]+y[1])%2) {
			puts("-1");
			return 0;
		}
	}
	if(abs(x[1]+y[1])%2) {
		m = 39;
		arm[0] = 1;
		arm[1] = 2;
		for(ll i=1;i<=19;i++) {
			arm[2*i] = arm[2*i-1];
			arm[2*i+1] = arm[2*i]*3;
		}
	}
	else {
		m = 40;
		arm[0] = 1;
		arm[1] = 1;
		for(ll i=1;i<=20;i++) {
			arm[2*i] = arm[2*i-1]*3;
			arm[2*i+1] = arm[2*i];
		}
	}
	printf("%lld\n",m);
	for(ll i=m;i--;) {
		printf("%lld ",arm[i]);
	}
	puts("");
	for(ll i=1;i<=n;i++) {
		solve(x[i], y[i], m-1);
		puts("");
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef char String[1024];

int main(void)
{
    String str;
    scanf("%s", str);
    int strnum = atoi(str);
    int h = strnum / 3600;
    int m = (strnum % 3600) / 60;
    int s = (strnum % 3600) % 60;
    printf("%d:%d:%d\n", h, m, s);
    return (0);
}


Measured memory_bytes: 2000
#include <cstdio>

int main()
{
	int n,k,s,p; scanf("%d%d%d",&n,&k,&s);
	for(int i=1; i<=k; i++) printf("%d ",s);
	if(s==1000000000) p=1; else p=s+1;
	for(int i=k+1; i<=n; i++) printf("%d ",p);
	return 0;
}

Measured memory_bytes: 1280
while 1:
    a,op,b = input().split()
    a=int(a)
    b = int(b)
    op  = str(op)
    if op == "?":
        break
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)


Measured memory_bytes: 5596
m = []
d = []
for _ in range(2):
    temp = list(map(int, input().split()))
    m.append(temp[0])
    d.append(temp[1])
if m[0] == 12 and d[0] == 31:
    print(1)
elif m[1] == m[0] + 1:
    print(1)
else:
    print(0)

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

namespace ABC141A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            s = Console.ReadLine();
            if (s == "Sunny")
                Console.WriteLine("Cloudy");
            else if (s == "Cloudy")
                Console.WriteLine("Rainy");
            else
                Console.WriteLine("Sunny");

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> a = new ArrayList<>();
		for(int i = 0;i < N;i++){
			a.add(sc.nextInt());
		}
		sc.close();
		long cnt = 0;
		int flg = 1;
		if(a.indexOf(1) == -1){
			System.out.println(-1);
			return;
		}else{
			cnt += a.indexOf(1);
			for(int i = a.indexOf(1);i < N-1;i++){
				if(a.get(i+1)==flg+1){
					flg++;
				}else{
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 93364
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type Int64Heap []int64

func (h Int64Heap) Len() int           { return len(h) }
func (h Int64Heap) Less(i, j int) bool { return h[i] < h[j] }
func (h Int64Heap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *Int64Heap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int64))
}

func (h *Int64Heap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

type InverseInt64Heap []int64

func (h InverseInt64Heap) Len() int           { return len(h) }
func (h InverseInt64Heap) Less(i, j int) bool { return h[j] < h[i] }
func (h InverseInt64Heap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *InverseInt64Heap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int64))
}

func (h *InverseInt64Heap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	var q int
	fmt.Scan(&q)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	la := &InverseInt64Heap{}
	ra := &Int64Heap{}
	var laSum int64
	var raSum int64
	heap.Init(la)
	heap.Init(ra)
	var bSum int64
	for i := 0; i < q; i++ {
		scanner.Scan()
		o, _ := strconv.Atoi(scanner.Text())

		if o == 1 {
			scanner.Scan()
			a, _ := strconv.Atoi(scanner.Text())
			aa := int64(a)
			if len(*la) == 0 {
				heap.Push(la, aa)
				laSum += aa
			} else if (*la)[0] < aa {
				heap.Push(ra, aa)
				raSum += aa
				if la.Len() < ra.Len() {
					v := heap.Pop(ra).(int64)
					raSum -= v
					heap.Push(la, v)
					laSum += v
				}
			} else {
				heap.Push(la, aa)
				laSum += aa
				if la.Len()-ra.Len() > 1 {
					v := heap.Pop(la).(int64)
					laSum -= v
					heap.Push(ra, v)
					raSum += v
				}
			}
			// fmt.Printf("la: %v\nlaSum: %d\nra: %v\nraSum: %d\n", *la, laSum, *ra, raSum)
			scanner.Scan()
			b, _ := strconv.Atoi(scanner.Text())
			bSum += int64(b)
		} else {
			x := (*la)[0]
			fx := bSum + (x * int64(la.Len())) - laSum + (-x * int64(ra.Len())) + raSum
			fmt.Printf("%d %d\n", x, fx)
		}
	}
}


Measured memory_bytes: 9088
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

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

  cin >> a >> b >> c >> d;
  area1 = a*b;
  area2 = c*d;

  if(area1>area2)
    cout << area1 << endl;
  else
    cout << area2 << endl;
  
  
  return 0;
}


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

struct Proc { 
	char name[200];
	int t;
};

int head, tail, n;
Proc Q[MAX];

void enq(Proc y) {
	Q[tail] = y;
	tail = (tail + 1) % MAX;
}

Proc deq(void) {
	Proc x = Q[head];
	head = (head + 1) % MAX;
	return x;
}

int main(void) {
	int n, q;
	head = 0;
	tail = 0;
	int sumtime = 0;
	Proc aaa;

	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> Q[i].name >> Q[i].t;
	}

	head = 1;
	tail = (n + 1) % MAX;

	while (head != tail) {
		aaa = deq();
		if (aaa.t - q <= 0) {
			sumtime += aaa.t;
			cout << aaa.name << " " << sumtime << endl;
		}
		else {
			sumtime += q;
			aaa.t -= q;
			enq(aaa);
		}
	}

	return 0;
}

Measured memory_bytes: 22900
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,ans=0;
int main(){
    ll n;
  cin>>n;
    while(n>1){
        n=(n+2)/3;
        ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3112
from heapq import heappush, heappop
INF = 10 ** 20

def search(item_lst, d):
  visited = {}
  visited[(0, 0)] = True
  que = []
  heappush(que, (0, 0, 0))
  while que:
    score, a, e = heappop(que)
    for da, de in item_lst[e]:
      na = a + da
      if na >= d:
        print(score + 1)
        return True
      ne = e + de
      if ne > 100:
        ne = 100
      
      if (na, ne) not in visited:
        visited[(na, ne)] = True
        heappush(que, (score + 1, na, ne))
  
  print("NA")
  return False

def main():
  while True:
    d, n = map(int, input().split())
    if d == 0:
      break
    item_lst = [[] for _ in range(101)]
    for _ in range(n):
      a, e, r = map(int, input().split())
      for i in range(r, 101):
        item_lst[i].append((a, e))
    search(item_lst, d)
main()


Measured memory_bytes: 7268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    ll answer = 0;
    for (int z=0;z<n;z++){
    	if (a[z] != b[z] && a[z] != c[z] && b[z] != c[z]) answer+=2;
    	else if (a[z] == b[z] && b[z] == c[z]) answer+=0;
    	else answer+=1;
    }
    cout << answer << endl;
	cin >> a;
}

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

using namespace std;

int main() {
	set<int> st;
	for (int i = 0; i < 3; ++i) {
		int a;
		cin >> a;
		st.insert(a);
	}

	cout << (st.size() == 2 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
h,w,k = gets.chomp.split.map(&:to_i)
c = []
h.times do
  c.push gets.chomp
end

# countmap = Array.new(h+1){Array.new(w+1, 0)}
# 1.upto(h) do |i|
#   1.upto(w) do |j|
#     count = 0
#     count += 1 if c[i-1][j-1] == '#'
#     count += countmap[i-1][j]
#     count += countmap[i][j-1]
#     count -= countmap[i-1][j-1]
#     countmap[i][j] = count
#   end
# end

ans = 0
(1<<h).times do |bity|
  (1<<w).times do |bitx|
    count = 0
    h.times do |i|
      w.times do |j|
        next if bity[i] == 1 || bitx[j] == 1
        count += 1 if c[i][j] == '#'
      end
      break if count > k
    end
    if count == k
      ans += 1
    end
  end
end

puts ans


Measured memory_bytes: 14736
D, N = gets.strip.split(' ').map(&:to_i)

if D == 0
  puts N == 100 ? 101 : N
elsif D == 1
  puts N == 100 ? 100 * N + 100 : 100 * N
else
  puts N == 100 ? 10000 * N + 10000 : 10000 * N
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;


int main(){
    int N; cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    rep(i,N){
        ll tmp = 0;
        ll ng =  N;
        ll ok = -1;
        
        while(abs(ok-ng)>1){
            ll mid = (ok+ng) / 2;
        
            if(A[mid] < B[i]) ok = mid;
            else ng = mid;
        }
        tmp += ok+1;

        ng = -1;
        ok = N;
        
        while(abs(ok-ng)>1){
            ll mid = (ok+ng) / 2;
        
            if(C[mid] > B[i]) ok = mid;
            else ng = mid;
        }

        tmp *= (N-ok);
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4500
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	if (b % a == 0) cout << a + b << endl;
	else cout << b - a << endl;
 	return 0;
 }

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

using namespace std;

const int N = 100000;
const int M = 200000;

int f[N + 1];
int dnf[N + 1];
int low[N + 1];
int col[N + 1];
bool book[N + 1];
int fi[N + 1];
int ne[M + 1];
int to[M + 1];
int S[N + 1];
int in[N + 1];
int top;
int n;
int m;
int tot;
int jsq;
int scc;
int A[N + 1];

void add(int u, int v) {
	tot++;
	ne[tot] = fi[u];
	fi[u] = tot;
	to[tot] = v;
}

void Tarjan(int x) {
	book[x] = 1;
	S[++top] = x;
	dnf[x] = low[x] = ++jsq;
	for(int i = fi[x]; i; i = ne[i]) {
		if(!dnf[to[i]]) {
			Tarjan(to[i]);
			low[x] = min(low[x], low[to[i]]);
		}
		else if(book[to[i]]) {
			low[x] = min(low[x], dnf[to[i]]);
		}
	}
	if(dnf[x] == low[x]) {
		int t = 0;
		scc++;
		while(t != x && top) {
			t = S[top--];
			book[t] = 0;
			col[t] = scc;
		}
	}
}

int main() {
	scanf("%d%d", &n, &m); scc = n;
	for(int i = 1; i <= n; i++) scanf("%d", &f[i]);
	for(int i = 1; i <= m; i++) {
		int a;
		int b;
		scanf("%d%d", &a, &b);
		add(a, b);
		add(b, a);
	}
	for(int i = 1; i <= n; i++)
		if(!dnf[i])
			Tarjan(i);
	for(int i = 1; i <= n; i++) A[i] = col[i];
	int res = 0;
	for(int i = 1; i <= n; i++) res += A[f[i]] == col[i];
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 6656
#include <stdio.h>
#define MAX 100000

int A[MAX];

int partition(int p, int r)
{
	int x = A[r];
	int i = p-1;
	int j, tmp;
	
	for(j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	
	return i+1;
}

int main(void)
{
	int n, i, p;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++)scanf("%d", &A[i]);
	
	p = partition(0, n-1);
	
	for(i = 0; i < n; i++){
		if(i != 0)printf(" ");
		if(i == p)printf("[%d]", A[i]);
		else printf("%d", A[i]);
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2172
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main()
{
    int H, W;
    vector<string> fi;
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; i++)
    {
        cin >> fi[i];
        // cout << fi[i] << endl;
    }

    // Left accumulation.
    for (int i = 0; i < H; i++)
    {
        int cur = 0;
        for (int j = 0; j < W; j++)
        {
            if (fi[i][j] == '#')
            {
                cur = 0;
            }
            else
            {
                cur++;
            }
            Left[i][j] = cur;
        }
    }

    // Right accumulation.
    for (int i = 0; i < H; i++)
    {
        int cur = 0;
        for (int j = W - 1; j >= 0; j--)
        {
            if (fi[i][j] == '#')
            {
                cur = 0;
            }
            else
            {
                cur++;
            }
            Right[i][j] = cur;
        }
    }

    // Up accumulation.
    for (int j = 0; j < W; j++)
    {
        int cur = 0;
        for (int i = 0; i < H; i++)
        {
            if (fi[i][j] == '#')
            {
                cur = 0;
            }
            else
            {
                cur++;
            }
            Up[i][j] = cur;
        }
    }

    // Down accumulation.
    for (int j = 0; j < W; j++)
    {
        int cur = 0;
        for (int i = H - 1; i >= 0; i--)
        {
            if (fi[i][j] == '#')
            {
                cur = 0;
            }
            else
            {
                cur++;
            }
            Down[i][j] = cur;
        }
    }

    int res = 0;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            if (fi[i][j] == '#')
                continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 72448
from itertools import product
from collections import deque

S = list(input())
P = ['', '+']

sumN = 0
for pp in product(P, repeat=len(S) -1):
    eq = ''
    SQ = deque(S)
    PQ = deque(list(pp))
    while SQ:
        eq += SQ.popleft()
        if PQ:
            eq += PQ.popleft()
    sumN += eval(eq)

print(sumN)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int x,a , b;
    cin >> x >> a >> b;
    int ans = x - a;
    ans -= ans / b * b;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  long long A = 0, N;
  cin >> N;
  if (N == 2) {
    A = 1;
  } else if (N == 1) {
    A = 0;
  } else {
   for (N--;N > 0;N--) {
    A += N; 
   }
  }
  cout << A;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    city = []
    city_num = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [P, Y] = [long(input_raw[0]), long(input_raw[1])]
        city.append((Y, P, i))
        city_num[P] = 0

    city.sort()
    numbers = []
    for i in range(M):
        C_number = city_num[city[i][1]] + 1
        city_num[city[i][1]] += 1
        P_number = city[i][1]
        numbers.append((city[i][2], "%06d%06d" %(P_number, C_number)))

    numbers.sort()

    for num in numbers:
        print num[1]

if __name__ == '__main__':
    main()

Measured memory_bytes: 44432
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <memory.h>
#include<iomanip>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;

string a, b;
int A[MAX];
int B[MAX];
vector<PII> P;
int L[MAX];
int R[MAX];
int n;

void ADD(int& key, int val)
{
	key += val;
	if (key < 0) key += n;
	if (key >= n) key -= n;
}

int solve(vector<PII>& P, int sh)
{
	sort(ALL(P));
	int ans = INF;
	int mx = 0;
	RFOR(i, SZ(P), 0)
	{
		int val = P[i].first + 2 * mx + abs(P[i].first - sh);
		ans = min(ans, val);
		mx = max(mx, P[i].second);
	}

	ans = min(ans, mx * 2 + sh);
	// cout << "sh=" << sh << endl;
	// FOR(i,0, SZ(P))
	// {
	//     cout << P[i].first << " " << P[i].second << endl;
	// }
	// cout<< "ans=" << ans << endl;
	if (ans == INF) ans = 0;
	return ans;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> a >> b;
	n = SZ(a);
	int cntA = 0, cntB = 0;
	FOR(i, 0, n)
	{
		A[i] = a[i] - '0';
		B[i] = b[i] - '0';

		cntA += A[i];
		cntB += B[i];
	}

	if (cntB == 0 && cntA)
	{
		cout << -1 << endl;
		return 0;
	}

	FOR(i, 0, n)
	{
		FOR(d, 0, n)
		{
			int x = 0;
			ADD(x, i - d);
			if (B[x] == 1)
			{
				L[i] = d;
				break;
			}
		}

		FOR(d, 0, n)
		{
			int x = 0;
			ADD(x, i + d);
			if (B[x] == 1)
			{
				R[i] = d;
				break;
			}
		}
	}

	// FOR(i,0,n)
	// {
	//     cout << L[i] << " " << R[i] << endl;
	// }
	int ans = INF;
	FOR(i, 0, n)
	{
		P.clear();
		int cnt = 0;
		FOR(j, 0, n)
		{
			int x = 0;
			ADD(x, j - i);

			cnt += B[x] != A[j];
			if (B[x] == 0 && A[j] == 1)
			{
				P.PB(MP(L[j], R[j]));
			}
		}

		ans = min(ans, solve(P, i) + cnt);
		FOR(j, 0, SZ(P))
		{
			swap(P[j].first, P[j].second);
		}

		ans = min(ans, solve(P, n - i) + cnt);
	}

	cout << ans << endl;
}

Measured memory_bytes: 384