akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,s) for(int i=1;i<s;i++)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int main() {
	ll n = 0, m, ans = 0, A[10101];
	string s, str;
	cin >> n;
	rep(i, n) cin >> A[i];
	m = A[0];
	FOR(i, n) {
		if (m == A[i]) {
			ans++;
			m = A[i + 1];
			i++;
		}
		else
			m = A[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
inp = input()
n = int(inp)
inp = input()
split_inp = inp.split()
total_count = 0
ppre = int(split_inp[0])
pre = int(split_inp[1])
for st in split_inp[2:]:
    p = int(st)
    if pre != max(ppre, pre, p) and pre != min(ppre, pre, p):
        total_count += 1
    ppre = pre
    pre = p
print(total_count)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int main(){

  int N,i,v,j,k;
  int *A;

  scanf("%d",&N);

  A = (int *)malloc(sizeof(int)*N);
  if(A == NULL)exit(0);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(k=0;k<N-1;k++)printf("%d ",A[k]);
  printf("%d\n",A[N-1]);

  for(i=1;i<=N-1;i++){   
    v=A[i];
    j=i-1;
    while((j>=0)&&(A[j]>v)){      
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(k=0;k<N-1;k++)printf("%d ",A[k]);
    printf("%d\n",A[N-1]);

  }


  free(A);

  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
int main(){
  int i,j,n1,n2,S[10000],T[500],count=0,a;
  scanf("%d",&n1);
  for(i = 0; i < n1; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&n2);
  for(i = 0; i < n2; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0; i < n2; i++){
    a=0;
    for(j = 0; j < n1; j++){
      if(a == 0){
        if(T[i] == S[j]){
        count++; 
        a++;
        break;
    }
      }
    }
  }
  printf("%d\n",count);
   
  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> adj[100000];
int D[100000];

int dfs(int c)
{
	if(D[c]!=-1) return D[c];
	D[c]=0;
	for(auto n: adj[c]) {
		D[c]=max(D[c],dfs(n)+1);
	}
	return D[c];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, M, ans=0;
	memset(D,-1,sizeof(D));
	for(cin>>N>>M;M;M--) {
		int a, b;
		cin>>a>>b;
		adj[--a].push_back(--b);
	}
	for(int i=0;i<N;i++) {
		ans=max(ans,dfs(i));
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 7552
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string s;
	cin >> s;
	list<char>l(all(s));
	int a(0), b(0);
	rep(i, 0, N) {
		if (s[i] == '(') {
			a++;

		}
		else {
			b++;
			if (a < b) {
				a++;
				l.push_front('(');
			}
			
		}


	}
	if (a > b) {
		rep(i, 0, a - b)l.push_back(')');
	}
	cout << string(all(l)) << endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    int n;
    cin >> n;
    vl a(n,0);
    rep(i,n) cin >> a[i];
    for(int i = 1; i < n; i++) a[i] += a[i-1];
    ll ans = LINF;
    rep(i, n-1){
        ll temp = abs(a[i] - (a[n-1] - a[i]));
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;
vector<vector<int>> to(200005);
vector<int> ans(200005);

void dfs(int v, int p=-1) {
  for (int c : to[v]) {
    if (c == p)
      continue;
    ans[c] += ans[v];
    dfs(c, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  int a, b;
  for (int i=1; i<n; i++) {
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  int p, x;
  for (int i=1; i<=q; i++) {
    cin >> p >> x;
    p--;
    ans[p] += x;
  }

  dfs(0);

  for (int i=0; i<n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << ans[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 23552
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int l[100005] = {};
vector<vector<int>> g(100005);

int main() {
  int n;
  cin >> n;
  ll a[n+1] = {};
  ll tmp = 0;
  for(int i =1;i<n;i++){
    if(i*i > n){break;}
    for(int j =1;j <n;j++){
        if(j*j > n){
          break;
        }
      for(int k =1;k<n;k++){
        if(k*k > n){
          break;
        }
        tmp = i*i+j*j+k*k+i*j+j*k+k*i;
        if(tmp <= n){
          a[tmp] +=1;
        }
        
      }
    }
  }
  
  for(int i =1;i<n+1;i++){
    cout << a[i] <<endl;  
  }
  
}


Measured memory_bytes: 5392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll h, w;
	cin >> h >> w;
	if(h == 1 || w == 1){
		print(1)
	}
	else{
		if(h%2 == 0 || w%2 == 0){
			print((h*w)/2)
		}
		else{
			print((((h+1)*w)/2)-(w/2))
		}
	}
	return 0;
}

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

int main (void){
    int n, r;
    cin >> n >> r;
    if (n < 10) {
        cout << 100 * (10 - n) + r << endl;
    } else {
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main() {
    int n;cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }

    ll ans= 0;
    for(auto& p: mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }

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

Measured memory_bytes: 11136
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);
  
  for ( i = 1; i <= n;i++ ) scanf("%d", &A[i]);  
  
  for(i = 1; i <=n  ; i++) {
      v = A[i];
      j = i - 1;
      while( j >= 0 && A[j] > v ) {
	A[j+1] = A[j];
	j--;
      }
      A[j+1] =v;
      trace(A,n);            
  }
  
  return 0;
}

Measured memory_bytes: 608
#include <iostream>

int main() {
    int n, m = 0;
    for (int i = 0; i < 5; i++) {
        std::cin >> n;
        if (n == 0) {
            m = i + 1;
        }
    }
    std::cout << m << std::endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i, 0, n){
        cin >> a[i];
        sum += a[i];
    }
    bool f = true;
    if(sum % (n * (n + 1) / 2) != 0) f = false; 
    int x = sum / (n * (n + 1) / 2);
    rep(i, 0, n - 1){
        int diff = a[i + 1] - a[i];
        if((x - diff) % n != 0 || x - diff < 0) f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, r;
    cin >> n >> r;
    if(n <= 10)
    {
        int sum = 100 * (10 - n);
        cout << sum + r << endl;
    }
    else
    {
        cout << r << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;

int main()
{
    int n,x;cin>>n>>x;
    int l[n];
    rep(i,0,n)cin>>l[i];

    int now=1;ll sum=0;
    rep(i,0,n)
    {
        if((sum+l[i])<=x)
            sum+=l[i],now++;
        else
            break;
    }
    cout<<now;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int main(){
	int n,k;cin>>n>>k;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		if(x>=k)ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
import math
import itertools

n = int(input())
x = []
y = []
for _ in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)

path_len = 0
path = []

s = [i for i in range(n)]
paths = list(itertools.permutations(s))
path_lens = []

for path in paths:
    path_len = 0
    for i in range(len(path)-1):
        path_len += float(math.sqrt((x[path[i]]-x[path[i+1]])**2 +
                                    (y[path[i]]-y[path[i+1]])**2))
    path_lens.append(path_len)

print(sum(path_lens) / len(paths))

Measured memory_bytes: 15552
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	foreach (line; stdin.byLine) {
		auto str = line.chomp;
		if (str == "#") break;

		int s, cnt;
		foreach (e; str) {
			if ((e >= 'a' && e <= 'g') || (e >= 'q' && e <= 't') || 
				(e >= 'v' && e <= 'x') || (e == 'z')) {
				if (s == -1) cnt++;
				s = 1;
			} else {
				if (s == 1) cnt++;
				s = -1;
			}
		}
		cnt.writeln;
	}
}

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

using namespace std;



int main()
{
	int n;
	cin >> n;
	string s;
	
	set<string> ss;
	for(int i = 0; i < n; i++) 
	{
		cin >> s;
		ss.insert(s);
		
	}
	cout << ss.size() << "\n";	
    
    return 0;
}

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

int main(){
    int a=0,b=0,n;
    string A,B;
    
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> A >> B;
        if (A>B) a+=3;
        else if (A<B) b+=3;
        else {a++; b++;
        };
    };
    cout << a << " "<< b << endl;
    
    return 0;
}


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

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

   int a1,b1,c1;
   a1=a+b;
   b1=a+c;
   c1=(b+c);

   if(a1<c1&&a1<b1){
    cout<<a1<<endl;
   }
   else if(b1<a1&&b1<c1){
    cout<<b1<<endl;
   }
   else {
    cout<<c1<<endl;
   }



    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	int ret=0;
	for(i=1;i<=9;i++) {
		for(j=0;j<=9;j++) {
			for(k=0;k<=9;k++) {
				x=i*10001+j*1010+k*100;
				if(A<=x && x<=B) ret++;
			}
		}
		
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
n = int(input())
T = [[] for i in range(n)] #making the list
D = [-1] * n #making the undis pos
D[0] = 0 #first pos

#this mean Que
Q = [0] #insert fist pos to Que

for i in range(n - 1):
    u, v, w = map(int, input().split())
    T[u - 1].append([v - 1, w])
    T[v - 1].append([u - 1, w])
while Q:
    q = Q.pop()
    for adj, w in T[q]: ##BFS
        if D[adj] < 0: #uncertain is = -1
            D[adj] = (D[q] + w)%2
            Q.append(adj)
for d in D:
    print(d)




Measured memory_bytes: 45004
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, K: int):
    return int(math.log(N, K))+1


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(f'{solve(N, K)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75452
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
h = {}
a = inl()
for i in range(n):
    if a[i] in h:
        print('NO')
        exit()
    h[a[i]] = 1
print('YES')


Measured memory_bytes: 109012
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if b[i] > a[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        if a[i+1] - b[i] >=0:
            a[i+1] -= b[i]
            ans += b[i]
        elif a[i+1] - b[i] < 0:
            ans += a[i+1]
            a[i+1] = 0
    else:
        ans += b[i]
        a[i] -= b[i]
print(ans)

Measured memory_bytes: 23948
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
for i in range(n):
    a.append(list(map(int,input().split())))

s=[0]*n
for i in range(n):
    for j in range(m):
        s[i] += a[i][j]*b[j]
    s[i] += c
ans = 0
for i in range(n):
    if s[i] > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3064
def main21():
    buf = input("");
    bufs = buf.split();
    hai = [];
    for i in range(len(bufs)):
        hai.append(int(bufs[i]));
    mamono = [];
    for i in range(hai[0]):
        mamono.append(int(input("")));
    su = sum(mamono);
    hai[1] = hai[1] - su;
    mi = min(mamono);
    su2 = int(hai[1] / mi);
    print((hai[0]+ su2));


if __name__ == '__main__':
    main21()

Measured memory_bytes: 3064
N,M=map(int,input().split())#M道の数，N展望台数
H=list(map(int,input().split()))
lists=[]
for i in range(M):
  A,B=map(int,input().split())
  list=[A,B]
  lists.append([A,B])
list=[1]*N
for i in range(M):
  if H[lists[i][0]-1]<H[lists[i][1]-1]:
    list[lists[i][0]-1]=0
  elif H[lists[i][0]-1]>H[lists[i][1]-1]:
    list[lists[i][1]-1]=0
  else:
    list[lists[i][0]-1]=0
    list[lists[i][1]-1]=0
sum=0
for i in range(N):
  sum+=list[i]
  
print (sum)

Measured memory_bytes: 28952
class Union:
  def __init__(self, num):
    self.T = [-1 for i in range(num)]

  def root(self, x):
    if self.T[x] < 0: return x
    return self.root(self.T[x])

  def size(self, x):
    return -self.T[self.root(x)]

  def merge(self, x, y):
    a = self.root(x)
    b = self.root(y)
    if a == b: return False
    if self.size(a) < self.size(b): a, b = b, a
    self.T[a] += self.T[b]
    self.T[b] = a
    return True


N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

R = {}
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if a not in R: R[a] = [[b, i]]
  else: R[a].append([b, i])
  if b not in R: R[b] = [[a, i]]
  else: R[b].append([a, i])

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M
for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    for n, m in R[x]:
      if D[n] == D[x] or L[n] != 0:
        H[m] = h
        if L[n] == 1:
          L[n] = 1
          L[x] = 2
        else:
          L[n] = 2
          L[x] = 1
        break
    else:
      print(-1)
      exit()

for i in range(N):
  if L[i] == 1:
    L[i] = "B"
  else:
    L[i] = "W"
print("".join(list(map(str, L))))
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])


Measured memory_bytes: 136836
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<int> m(10);

    for(int i=0; i<10; i++){
        cin >> m[i];
    }
    sort(m.begin(), m.end());

    cout << m[9] << endl;
    cout << m[8] << endl;
    cout << m[7] << endl;

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=998244353;
int p[100000],q[100000],r[100000],ans[200000];
signed main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++)
        cin>>p[i];
    for(int i=0;i<b;i++)
        cin>>q[i];
    for(int i=0;i<c;i++)
        cin>>r[i];
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    for(int i=0;i<x;i++)
        ans[i]=p[a-x+i];
    for(int i=0;i<y;i++)
        ans[x+i]=q[b-y+i];
    sort(ans,ans+x+y);
    for(int i=0;i<min(c,x+y);i++){
        if(ans[i]>=r[c-1-i])
            break;
        ans[i]=r[c-1-i];
    }
    int sum=0;
    for(int i=0;i<x+y;i++)
        sum+=ans[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 3968
n = int(input())
a = [0 for i in range(120)]

for i in range(n):
  b,f,r,v = map(int,input().split())
  a[(b-1)*30 + (f-1)*10 + (r-1)] += v
_ = ''
for i in range(4):
  print(_,*a[i*30:i*30+10])
  print(_,*a[i*30+10:i*30+20])
  print(_,*a[i*30+20:i*30+30])
  if i != 3:
    print('####################')


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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, 10000000) {
        int cnt = 0;
        rep(j, n) {
            if(a[j] % 2 == 0) {
                a[j] = a[j] / 2;
                cnt++;
            }
        }
        if(cnt == n)
            ans++;
        else
            break;
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a+n);

    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += a[(n-1) - i/2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5180
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	vector<int> A(N,-1);
	vector<int> L(N,-1), R(N,1);
	FOR(i,0,N)cin>>A[i];
	L[0]=A[0];
	R[N-1]=A[N-1];
	FOR(i,1,N){L[i]=gcd(L[i-1], A[i]);R[N-i-1]=gcd(R[N-i],A[N-i-1]);}
	int ans=-1;
	FOR(i,1,N-1){
		ans=max(ans, gcd(L[i-1], R[i+1]));
	}
	ans=max(ans, R[1]);
	ans=max(ans, L[N-2]);

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1408
from collections import deque #pypyでも使える
n,q=map(int,input().split())

edges=[[] for i in range(n)] #枝がどことどこをつなぐかの情報を入れておく二次元配列
for i in range(n-1):
	a,b=map(lambda x:int(x)-1,input().split()) #ラムダ式は必見
	#もっといい感じの書き方ないかな?
	edges[a].append(b) #edges[a]には、ノードaの相方を格納
	edges[b].append(a) #edges[b]には、ノードbの相方を格納する決まり

#nodesの重さを格納
nodes=[0]*n
for i in range(q):
	p,x=map(int,input().split())
	nodes[p-1]+=x

#oyakoを、親についての単調増加にしたい->デフォで先頭要素でのソートになるので安心
#oyako.sort()
#と思ったけどソートじゃ無理っぽい
#根から順に処理->bfs幅優先探索
que=deque([0])
color=[0]*n #全てのノードに対して、未探索の0を入れる
color[0]=0 #colorは親としての処理を終えたかどうかを入れる。終えたら1にする
#TLEなった。二重ループはだめねえ。
# ->oyako(edges)を、二次元配列にしてインデックスの数字を持つものをedges[i]に格納すれば
while que: #qが空でないのはこう表現できる
	i=que.popleft()
	if color[i]==0:
		for edge in edges[i]:
			if color[edge]==0: #相方が親じゃなければ(親ならすでに探索済みのはず)
				nodes[edge]+=nodes[i]
				que.append(edge)
		color[i]=1

#綺麗にかけそうでこの書き方をしたけど大丈夫かな?
for node in nodes:
	print(node,end=' ')

Measured memory_bytes: 106572
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int q;
  cin>>q;
  priority_queue<long long> left;
  priority_queue<long long, vector<long long>, greater<long long>> right;
  int type_;
  long long a,b;
  long long x;
  long long ans = 0;
  
  REP(i,q){
    cin>>type_;
    if(type_==1){
      cin>>a>>b;
      ans += b;
      left.push(a);
      right.push(a);
      if(left.top()<=right.top())continue;
      long long templ,tempr;
      ans += left.top()-right.top();
      templ = left.top();
      tempr = right.top();
      left.pop();
      left.push(tempr);
      right.pop();
      right.push(templ);
    }else{
      x = left.top();
      cout<<x<<' '<<ans<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 4588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<int> A(N*3);
  for(auto&&e:A)cin >> e;
  sort(A.begin(), A.end());
  long long sum = 0;
  int idx = N;
  for(int i = N*3 - 2; i >=0; i-=2){
    if(idx == 0)break;
    sum += A[i];
    idx--;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define ran 101111

int n, m;
int a[ran];
vector<int> e[ran];
bool vis[ran];

vector<int> v, rem;

void dfs(int cur) {
	vis[cur] = true;
	v.push_back(a[cur]);
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if (!vis[nxt]) dfs(nxt);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	for(int i=0;i<m;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y); e[y].push_back(x);
	}
	
	int todo = -2;
	long long ans = 0LL;
	rem.clear();
	for(int i=0;i<n;i++) {
		if (vis[i]) continue;
		v.clear();
		dfs(i);
		sort(v.begin(), v.end());
		ans += v[0];
		for(int j=1;j<(int)v.size();j++)
			rem.push_back(v[j]);
		todo++;
	}
	
	if (todo > (int)rem.size()) puts("Impossible");
	else if (todo<0) puts("0");
	else {
		sort(rem.begin(), rem.end());
		for(int i=0; i<todo; i++) ans += rem[i];
		cout<<ans<<endl;
	}

	return 0;
}

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

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


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

using namespace std;

int main() {
    while (true) {
        int a, b;
        char op;
        cin >> a >> op >> b;
        int ans;
        if (op == '+') {
            ans = a + b;
        } else if (op == '-') {
            ans = a - b;
        } else if (op == '*') {
            ans = a * b;
        } else if (op == '/') {
            ans = a / b;
        } else {
            break;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>
int N, K, Q;
int A[100010];
int add[100010];
int ans[100010];
int main(void){
   scanf("%d", &N);
   scanf("%d", &K);
   scanf("%d", &Q);
   for(int i = 0; i < Q; i++){
       scanf("%d", &A[i]);
       A[i]--;
   }
   for(int i = 0; i < N; i++){
       ans[i] = 1;
   }
  
   for(int i = 0; i < Q; i++){
       if(K + add[A[i]] - i <= 0) ans[A[i]] = 0;
       add[A[i]]++;
   }
   
   for(int i = 0; i < N; i++){
       if(K - Q + add[i] <= 0) ans[i] = 0;
   }
   
   for(int i = 0; i < N; i++){
       if(ans[i]) printf("Yes\n");
       else printf("No\n");
   }
   
}


Measured memory_bytes: 1792
import java.util.*;

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

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

		LinkedList<Integer> list = new LinkedList<>();
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				list.addFirst(array[i]);
			} else {
				list.addLast(array[i]);
			}
		}

		if (n % 2 == 1) {
			Iterator iter = list.iterator();
			while(iter.hasNext()) {
				System.out.print(iter.next() + " ");
			}
		} else {
			ListIterator iter = list.listIterator(list.size());
			while(iter.hasPrevious()) {
				System.out.print(iter.previous() + " ");
			}
		}
	}
}

Measured memory_bytes: 104868
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int n;cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        ans+=a-1;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def solvM(e):
  p = [ 0 ]

  def term():
    res = 0
    while p[ 0 ] < len ( e ) and "0" <= e[ p[ 0 ] ] <= "9":
      res = res * 10 + ( ord ( e[ p[ 0 ] ] ) - ord ( "0" ) )
      p[ 0 ] = p[ 0 ] + 1
    return ( res )

  def fact():
    lv = term ( )
    while p[ 0 ] < len ( e ):
      if ( e[ p[ 0 ] ] == "*" ):
        p[ 0 ] = p[ 0 ] + 1
        lv = lv * term ( )
      else:
        break
    return ( lv )

  def expr():
    lv = fact ( )
    while p[ 0 ] < len ( e ):
      if ( e[ p[ 0 ] ] == "+" ):
        p[ 0 ] = p[ 0 ] + 1
        lv = lv + fact ( )
      else:
        break
    return ( lv )

  return expr ( )

def solvL(e):
  p = 0

  lv = 0
  while p < len ( e ) and "0" <= e[ p ] <= "9":
    lv = lv * 10 + ord ( e[ p ] ) - ord ( "0" )
    p = p + 1

  while p < len ( e ):
    op = e[ p ]
    p = p + 1

    rv = 0
    while p < len ( e ) and "0" <= e[ p ] <= "9":
      rv = rv * 10 + ord ( e[ p ] ) - ord ( "0" )
      p = p + 1

    if op == "+": 
      lv = lv + rv
    else:
      lv = lv * rv

  return ( lv )

e = input ( )
r = int ( input ( ) )
m = solvM ( e )
l = solvL ( e )

if ( m == r and l == r ):
  print ( "U" )
elif ( m == r ):
  print ( "M" )
elif ( l == r ):
  print ( "L" )
else:
  print ( "I" )

Measured memory_bytes: 6800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll a,b,k; 
int main(){
	cin >> a >> b >> k;
	if(a>=k)a-=k;
	else if(a+b>=k)k-=a,a=0,b-=k;
	else a=b=0;
	cout << a << " " << b;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	ll n, q;
	cin >> n >> q;

	vector<ll> s(n), t(n), x(n), d(q);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld %lld %lld", &s[i], &t[i], &x[i]);
	}
	for (int i = 0; i < q; i++)
	{
		scanf("%lld", &d[i]);
	}

	vector<pair<pll, ll> > events;//(時刻，座標，フラグ)
	set<ll> cannot_use;

	for (int i = 0; i < n; i++)
	{
		events.push_back(make_pair(make_pair(s[i] - x[i], x[i]), 1));
		events.push_back(make_pair(make_pair(t[i] - x[i], x[i]), 0));
	}

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

	int idx = 0;
	int siz = events.size();

	for (int i = 0; i < q; i++)
	{
		while (idx < siz && events[idx].first.first <= d[i]) {

			if (events[idx].second == 1) {
				//工事の開始
				cannot_use.insert(events[idx].first.second);
			}
			else
			{
				//工事の終了
				cannot_use.erase(events[idx].first.second);
			}
			idx++;
		}
		if (cannot_use.empty()) {
			cout << "-1" << endl;
		}
		else
		{
			cout << *cannot_use.begin() << endl;
		}
	}
	

	return 0;
}


Measured memory_bytes: 26728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

void solve() {
    int n, m;
    cin >> n >> m;
    int s = 0;
    rep(i, m) {
        int a;
        cin >> a;
        s += a;
    }
    cout << (s > n ? -1 : n - s) << endl;
    return;
}

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


Measured memory_bytes: 3700
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>> n;
  int s =0;
  for(int a=0;a<26;a++)
  {
    for(int b=0;b<15;b++)
    {if(n==a*4+b*7)
    {
      s++;
    }
    }
  }
  if(s>0)
  cout << "Yes" <<endl;
  else
    cout << "No" << endl;
}

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

int main()
{
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<(x2-(y2-y1))<<" "<<(y2+(x2-x1))<<" "<<(x1-(y2-y1))<<" "<<(y1+(x2-x1)); 
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 60
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

int main() {
	optimizar_io
	string s; cin >> s;
	if(s[0] >= 'a' && s[0] <= 'z') {
		cout << "a" << endl;
	} else cout << "A" << endl;
}

Measured memory_bytes: 3644
import java.io.*;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb;
        do {
            sb = new StringBuilder();
             
            String[] strs = br.readLine().split("\\s+");
            int height  = Integer.parseInt(strs[0]);
            int width   = Integer.parseInt(strs[1]);
             
            if (height == 0 && width == 0) break;
             
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    sb.append( (i + j) % 2 == 0 ? "#" : ".");
                }
                sb.append("\n");
            }
             
            System.out.println(sb);
        } while (true);
    }
}

Measured memory_bytes: 25736
#include <stdio.h>
#include <math.h>

int main(void)
{
  long long int i, a, b, n, max = 0, fa, fb;
  
  scanf("%lld %lld %lld", &a, &b, &n);
  
  if( n > b ){
      n = b-1;
  }
  
  for( i = n-1; i <= n; i++ ){
      fa = a*i/b;
      fb = i/b;
      if( max < fa - (a*fb) ){
          max = fa - (a*fb);
      }
  }
  

  printf("%lld\n", max);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;

map<char, int> sz;
map<char, map<int, int> > arr;
int c;

int f(string& s) {
	if(isdigit(s[c])) {
		string t;
		while(c < s.size() && isdigit(s[c])) t += s[c++];
		return atoi(t.c_str());
	}
	char a = s[c];
	if(arr.count(a) == 0) return -1;
	c += 2;// a[
	int idx = f(s);
	if(idx == -1) return -1;
	if(sz[a] <= idx) return -1;
	if(arr[a].count(idx) == 0) return -1;
	assert(s[c] == ']');
	c++; // ]
	return arr[a][idx];
}

bool ass(string& s) {
	char a = s[c];
	if(arr.count(a) == 0) return false;
	c += 2; // a[
	int idx = f(s);
	if(idx == -1) return false;
	if(sz[a] <= idx) return false;
	assert(s[c] == ']');
	c += 2; // ]=
	int num = f(s);
	if(num == -1) return false;
	arr[a][idx] = num;
	return true;
}

bool dec(string& s) {
	char a = s[c];
	//if(arr.count(a)) return false;
	c += 2;
	int size = f(s);
	if(size == -1) return false;
	sz[a] = size;
	arr[a] = map<int, int>();
	return true;
}

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

	while(1) {
		string s;
		vector<string> v;
		while(cin >> s, s != ".") {
			v.push_back(s);
		}
		if(v.size() == 0) break;
		arr.clear();
		sz.clear();
		int cnt = 0;
		for(int i = 0; i < v.size(); i++) {
			s = v[i];
			c = 0;
			// assign
			if(s.find('=') != -1) {
				if(!ass(s)) {
					cnt = i + 1;
					break;
				}
			}
			// declaration
			else {
				if(!dec(s)) {
					cnt = i + 1;
					break;
				}
			}
		}
		cout << cnt << endl;
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  
  int now = 0;
  string nows = s.at(0);
  long long ans = 0;
  for(int i = 0; i < n; i++){
    if(s.at(i) == nows) continue;
    int k = i - now;
    if(k == 2) ans++;
    else if(k > 2) ans += k * (k - 1) / 2;
    now = i;
    nows = s.at(i);
  }
  long long k = n - now;
  if(k == 2) ans++;
  else if(k > 1) ans += k * (k - 1) / 2;
  
  cout << ans << endl;
}

Measured memory_bytes: 7296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            int h = Integer.parseInt(strArr[0]);
            int w = Integer.parseInt(strArr[1]);
            String outputArr[] = new String[h];
            for (int i = 0; i < h; i++) {
                outputArr[i] = br.readLine();
            }
            for (int i = 0; i < h; i++) {
                System.out.println(outputArr[i]);
                System.out.println(outputArr[i]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,k,s=0;
   cin>>n>>k;
   int x[n];
   for(int i=0;i<n;i++)
    cin>>x[i];
    sort(x,x+n,greater<int>());
    for(int i=0;i<k;i++)
    s+=x[i];
    cout<<s;
   return 0;
   }

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

int main() {
  int n,d;
  cin >> n >> d;
  d = 2*d + 1;
  if(n%d == 0) {
    cout << n /d << endl;
  }
  else {
    cout << n/d +1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);

  if(a > b)
    {
      printf("a > b\n");
    }
  else if(a < b)
    {
      printf("a < b\n");
    }
  else
    {
      printf("a == b\n");
    }
  return 0;
}



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

using namespace std;


int main(){
	int n1 = 0, n2 = 0, n3 = 0;
	char c1, c2;
	int tyouhou = 0, hishi = 0, count = 0;
		
	while(cin >> n1 >> c1 >> n2 >> c2 >> n3){
		if(n1*n1 + n2*n2 == n3*n3) tyouhou++;
		if(n1 == n2) hishi++;
		count++;
		/*cout << "tyouhou = " << tyouhou << endl;
		cout << "hishi = " << hishi << endl;
		cout << "count = " << count << endl;*/
	}

	cout << tyouhou << endl << hishi << endl;

	return 0;
}

Measured memory_bytes: 1160
lis = input().split()
N = int(lis[0])
K = int(lis[1])
lis = list(range(N+1))

for i in range(K):
    d = int(input())
    A = input().split()
    #print("d=",d,"A=",A)
    for j in range(d):
        if int(A[j]) in lis:
            lis.remove(int(A[j]))

print(len(lis) - 1)

Measured memory_bytes: 9212
i = list(map(int, input().split()))
a=[]
c=[]
for j in range(i[0]):
    a.append(0)
for j in range(i[1]):
    b=int(input())
    c=list(map(int, input().split()))
    for k in range(b):
        a[c[k]-1]=1
print(a.count(0))

Measured memory_bytes: 9196
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      cnt += (r - l) + 1;
    }

    System.out.println(cnt);

  }
}

Measured memory_bytes: 39612
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


map<char, int>chmp;

int main() {
	chmp['r'] = 0;
	chmp['g'] = 1;
	chmp['b'] = 2;
	while (1) {

		string st; cin >> st;
		if (st == "0")break;
		vector<int>nums;
		for (auto c : st) {
			nums.emplace_back(chmp[c]);
		}

		map<vector<int>, int>mp;
		queue<pair<int,vector<int>>>que;
		que.push(make_pair(0,nums));
		int ans = 1e8;
		while (!que.empty()) {
			auto p(que.front());
			que.pop();
			if (mp.find(p.second) != mp.end())continue;
			mp[p.second];
			if (all_of(p.second.begin(), p.second.end(), [=](const int n) {return n == p.second[0]; })) {
				ans = p.first;
				break;
			}
			vector<int>st(p.second);
			for (int i = 0; i < st.size() - 1; ++i) {
				if (st[i] != st[i + 1]) {
					vector<int>nowst(st);
					nowst[i] = 3 - st[i] - st[i + 1];
					nowst[i + 1] = 3 - st[i] - st[i + 1];
					que.push(make_pair(p.first + 1, nowst));
				}
			}
		}
		if (ans > 1e7) {
			cout << "NA" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5496
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

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

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	ll a, b;
	cin >> a;
	char c;
	cin >> c;
	b = c - '0';
	cin >> c;
	rep(i,0,2)
	{
		cin >> c;
		b *= 10;
		b += c - '0';
	}
	cout << a * b / 100;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std; 

string list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main()
{
 int n, l, p;
 string s, ans;

 while(cin >> n){
	if(n==0){return 0;} ans = "";
	int* key = new int[n];
	for(int i=0; i<n; i++){cin >> key[i];}
	cin >> s; l=s.length();
	for(int i=0; i<l; i++){
		p = list.find(s.substr(i,1))-key[i%n];
		if(p<1){p+=104;p=p%52;}
		ans += list.substr(p,1);
	}
	cout << ans << endl; delete[] key;
 }
}

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

int main(){
  int n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;++i){
    cin>>a.at(i);
  }

  int64_t S1=0,S2=0,count1=0,count2=0;
  //odd>0,even<0
  for(int i=0;i<n;++i){
    S1 += a.at(i);
    if(i%2!=0 && S1<=0){
        count1 += (1-S1);
        S1=1;
    }
    else if(i%2==0 && S1>=0){
        count1 += (1+S1);
        S1=-1;
    }
  }
  //odd<0,even>0
  for(int i=0;i<n;++i){
    S2 += a.at(i);
    if(i%2!=0 && S2>=0){
        count2 += (1+S2);
        S2=-1;
    }
    else if(i%2==0 && S2<=0){
        count2 += (1-S2);
        S2=1;
    }
  }

  cout<<min(count1,count2)<<endl;
}



Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

n = input()
S = list(set(input().split()))
q = input()
T = list(set(input().split()))

ctr = 0
for i in T:
    try:
        x = S.index(i)
        ctr += 1
    except:
        pass
        
print(ctr)


Measured memory_bytes: 6212
#!/usr/bin/env python3
import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(A: int, B: int, K: int):
    d = gcd(A, B)
    return [i for i in range(1, d + 1) if (d % i) == 0][-K]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(A, B, K)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076