akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
int n;
vector<int>G;
void insertionSort(int A[],int n,int g)
{
	for(int i=g;i<n;i++)
	{
		int v=A[i];
		int j=i-g;
		while(j>=0&&A[j]>v)
		{
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}
void shellSort(int A[],int n)
{
	for(int h=1; ;)
	{
		if(h>n) break;
		G.push_back(h);
		h=3*h+1;
	}
for(int i=G.size()-1;i>=0;i--)
{

	insertionSort(A,n,G[i]);
}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	scanf("%d",&A[i]);
	cnt=0;
	shellSort(A,n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--)
	{
		printf("%d",G[i]);
		if(i) printf(" ");
		
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  long double x[4], y[4];
  while(cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3]) {
    long double xa = x[0], ya = y[1], wa = x[1] - x[0], ha = y[1] - y[0],
                xb = x[2], yb = y[3], wb = x[3] - x[2], hb = y[3] - y[2];
    if((x[2] <= x[1]) &&
    (x[3] >= x[0]) &&
    (y[2] <= y[1]) &&
    (y[3] >= y[0])) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>

int main(){

int i,j,k;
int N;
int sum=0;
int count=0;

while(1){
i=0;
j=0;
k=0;
N=0;
sum=0;
count=0;
scanf("%d",&N);
if(N ==0){break;}
for(i=1;i<=N; i++){
  //printf("%d ",i);
  sum=i;
  for(j=1;j<=N;j++){
     sum+=(i+j);
     //printf("%d ",i+j);
     if(sum == N){
	//printf("N\n"); 
	count++;
	break;
     }
  }
//printf("\n");
sum=0;
}
printf("%d\n",count);
}
return 0;


}

Measured memory_bytes: 1028
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): # sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    n=inp()
    x=[]
    y=[]
    for _ in range(n):
        a,b=inpm()
        x.append(a)
        y.append(b)
    cnt=0
    for i in range(n-1):
        for j in range(i+1,n):
            cnt+=( (x[i]-x[j])**2 + (y[i]-y[j])**2 )**(1/2)
    com=1
    for i in range(1,n+1):
        com*=i
    s=(n*(n-1))//2
    print( (cnt*(n-1))/(s) )


if __name__ == "__main__":
    main()




Measured memory_bytes: 39260
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    
    if(n%2!=0) {
        cout <<"No" << endl;
        return 0;
    }
    string S1;
    for(int i=0; i<n/2; i++){
        S1 = S1+s[i];
    }
    string S2;
    for(int i=n/2; i<n; i++){
        S2 = S2+s[i];
    }
    if(S1 == S2){
        cout <<"Yes" << endl;
        return 0;
    }
    else{
        cout <<"No" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
n = int(input())
a = [str(input()) for i in range(n)]
for i in range(1,14):
    if "S " + str(i) not in a:
        print("S " + str(i))
for i in range(1,14):
    if "H " + str(i) not in a:
        print("H " + str(i))
for i in range(1,14):
    if "C " + str(i) not in a:
        print("C " + str(i))
for i in range(1,14):
    if "D " + str(i) not in a:
        print("D " + str(i))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int s; cin>>s;
	if(s%10==1) cout<<"pon";
	else if(s%10==2) cout<<"hon";
	else if(s%10==3) cout<<"bon";
	else if(s%10==4) cout<<"hon";
	else if(s%10==5) cout<<"hon";
	else if(s%10==6) cout<<"pon";
	else if(s%10==7) cout<<"hon";
	else if(s%10==8) cout<<"pon";
	else if(s%10==9) cout<<"hon";
	else cout<<"pon";
	
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = scan.nextInt();
		if(arr[0]!=0) calc_end();
		long ans = 0L;
		int pre = 0;
		for(int index = n-1; index >= 0; index--) {
			int num = arr[index];
			if(num>index) calc_end();
			if(num>=pre) ans += (long)num;
			else if(num+1!=pre) calc_end();
			pre = num;
		}

		System.out.println(ans);
	}

	public static void calc_end() {
		System.out.println(-1);
		System.exit(0);
	}
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int N;
ll A[100000];
ll kMax = 1000000000000000000;

int main() {
  cin >> N;
  REP(i, N) cin >> A[i];
  if (find(A, A + N, 0) != A + N) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = 1;
  REP(i, N) {
    if (__builtin_mul_overflow(ans, A[i], &ans) || ans > kMax) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


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

int main()
{
    int sx,sy,tx,ty;
    while(cin >> sx >> sy >> tx >> ty)
    {
        for(int i = 0;i < ty - sy;i++)
        cout << "U";
        for(int i = 0;i < tx - sx;i++)
        cout << "R";
        for(int i = 0;i < ty - sy;i++)
        cout << "D";
        for(int i = 0;i < tx - sx;i++)
        cout << "L";
        cout << "L";
        for(int i = 0;i < ty - sy + 1;i++)
        cout << "U";
        for(int i = 0;i < tx - sx + 1;i++)
        cout << "R";
        cout << "DR";
        for(int i = 0;i < ty - sy + 1;i++)
        cout << "D";
        for(int i = 0;i < tx - sx + 1;i++)
        cout << "L";
        cout << "U" << endl;
    }
    return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int n;	cin >> n;
	ll sum = 0;
	map<int, int> m;
	for (int i = 0; i < n; i += 1) {
		int a;	cin >> a;
		sum += a;
		m[a]++;
	}
	int q;	cin >> q;
	for (int i = 0; i < q; i += 1) {
		int b, c;	cin >> b >> c;
		sum += (m[b]*c - m[b]*b);
		if (m[c] == 0)
			m[c] = m[b];
		else
			m[c] += m[b];
		m.erase(b);
		cout << sum << '\n';
	}
	return 0;
}

Measured memory_bytes: 6560
#include <bits/stdc++.h>
using namespace std;
#define N 200005
#define ll long long
int n,m,pw[N],dp[N],bc[N];ll ans;char a[N];
int main()
{
	scanf("%d %d %s",&n,&m,a+1);
	pw[0]=1;for(int i=1;i<=n;++i) pw[i]=pw[i-1]*10%m;
	if(m==2)
	{
		for(int i=1;i<=n;++i) if(!((a[i]&15)%2)) ans+=i;
		printf("%lld\n",ans);return 0;
	}
	if(m==5)
	{
		for(int i=1;i<=n;++i) if(!((a[i]&15)%5)) ans+=i;
		printf("%lld\n",ans);return 0;
	}bc[0]=1;
	for(int i=1;i<=n;++i)
	{
		dp[i]=(dp[i-1]*10+(a[i]&15))%m;
		ans+=bc[dp[i]*pw[n-i]%m];++bc[dp[i]*pw[n-i]%m];
	}printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;


int main(){
  int a, b, c; cin >> a >> b >> c;
  cout << a + b + c - max({a, b, c}) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, x;
    int a[100010];
    cin >> n >> x;
    imfor(i, n) {
        cin >> a[i];
    }
    ll ans = 0;
    imfor(i, n) {
        if (i == 0) {
            continue;
        }
        if (a[i - 1] + a[i] > x) {
            if (x - a[i - 1] >= 0) {
                ans += a[i] - (x - a[i - 1]);
                a[i] = x - a[i - 1];
            }
            else {
                ans += a[i];
                a[i] = 0;
                ans += a[i - 1] - x;
                a[i - 1] = x;    
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def main():
    N, K = list(map(int,input().split()))
    for k in range(K):
        # print(N-K+1,k+1,K-1,k)
        if (N-K+1<k+1):
            print("0")
            continue
        tmp= cmb(N-K+1,k+1)
        tmp2=cmb(K-1,k)
        print(tmp*tmp2%mod)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 14256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int flag = 1;
  if(S.at(0) != 'A')flag = 0;
  int count = 0, sub = 0;
  for(int i = 2; i < S.size() - 1; i++){
    if(S.at(i) == 'C')count++;
  }
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) >= 'a' && S.at(i) <= 'z')sub++;
  }
  if(count != 1)flag = 0;
  if(sub != S.size() - 2)flag = 0;
  if(flag == 0)cout << "WA" << endl;
  else cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

inline void Main() {
  // code
  string s;
  cin >> s;

  long long int result = 0;
  string n;n.push_back(s.at(0));
  rep(bit, 1<<(s.size()-1)) {
    rep(i, s.size()-1) {
      if(bit & (1<<i)) {
        result += stoll(n);
        n.clear();
      }
      n.push_back(s.at(i+1));
    }
    result += stoll(n);
    n.clear();n.push_back(s.at(0));
  }

  cout << result << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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

int main(void) {
    ll a,b,c,k; cin >> a >> b >> c >> k;
    ll sum = 0;
    ll x = k - a; //bの数
    ll y = x - b; //cの数
    if(x<=0) {
        sum += k;
        cout << sum << endl; 
        return 0;
    }
    else {
        sum += a;
        if(y<=0) {
            cout << sum << endl;
            return 0;
        }
        else {
            sum -= y;
            cout << sum << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3600
#include <numeric>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; for (auto& e : a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; for (auto& e : a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; for (auto& r : a) { for (auto& e : r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; for (auto& e : a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

#define forn(a, e) for (int a = 0; a < (int)e; a++)
#define forr(a, s, e) for (int a = s; a < (int)e; a++)

using i64 = long long;

template<typename T>
using Pair = array<T, 2>;

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

    int n;
    while (cin >> n) {
        vector<int> h(n);
        forn(i, n) {
            cin >> h[i];
        }

        int i = 0;
        int ans = 0;
        while (i < n) {
            int cur = 0;
            while (i + 1 < n && h[i + 1] <= h[i]) {
                cur++;
                i++;
            }
            ans = max(ans, cur);
            i++;
        }
        cout << ans << endl;
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int s,w; cin>>s>>w;
	cout<<(s<=w?"unsafe"s:"safe"s)<<"\n"s;
}*/

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c,d; cin>>a>>b>>c>>d;
	for(int i=0;a>0&&c>0;++i){
		if(i&1)a-=d;
		else c-=b;
	}
	cout<<(a>0?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    char tmp[1000][1000];
    string cp;
    cin>>cp;
    int stop,ans=0,st[1000]={};
    for(int i=0;;i++){
        cin>>s;
        if(s=="END_OF_TEXT"){
            stop=i;
            break;
        }
        for(int j=0;j<s.size();j++){
            if('A'<=s[j] && s[j]<='Z'){
                s[j]+=32;
            }
            tmp[i][j]=s[j];
            st[i]++;
        }
    }
    bool judge;
    for(int i=0;i<stop;i++){
        if(tmp[i][0]==cp[0]){
            if(st[i]!=cp.size()){
                continue;
            }
            judge=true;
            for(int j=0;j<st[i];j++){
                if(tmp[i][j]!=cp[j]){
                    judge=false;
                }
            }
            if(judge){
                /*for(int j=0;j<st[i];j++){
                    cout<<tmp[i][j];
                }*/
                //cout<<endl;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    //cout<<stop<<endl;
    return 0;
}



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

int main() {
  
  string X, Y;
  
  cin >> X >> Y;
  
  if(X<Y) {
    
    cout << "<" << endl;
    
  } else if(Y<X) {
    
    cout << ">" << endl;
    
  } else if(X==Y) {
    
    cout << "=" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int n,m,f=0;;
  cin>>n>>m;
  int a[n+1];
  memset(a,0,sizeof(a));
  map<int,int>ma;
  for(int i=0;i<m;i++)
  {
    ll x,y;
    cin>>x>>y;
    if(x==1&&y==0)
    {
      f=1;
    }
    if((ma[x]&&ma[x]!=y))
    {
          f=1;
    }
    ma[x]=y;
  }
  
  for(int i=2;i<=n;i++)
  {
    if(!ma[i])
    {
      ma[i]=0;
    }
  }
  

if(f==0)
{
for(auto it=ma.begin();it!=ma.end();it++)
{
     a[it->first]=it->second;
}
}
if(n==1&&m==0)
{
  cout<<0<<endl;
}
else if(n==1&&m==1)
{
   cout<<ma[1]<<endl;
}

else if(f)
{
  
  
  {
  cout<<-1<<endl;
  }
}
else
{
  if(ma[1]==0)
  {
    a[1]=1;
    ma[1]=1;
  }
for(int i=1;i<=n;i++)
{
  cout<<a[i];
}
cout<<endl;
}
}
return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    plus2_cnt = 0
    neg_cnt = 0
    for i in range(N):
        diff = b[i] - a[i]
        if diff >= 0:
            plus2_cnt += diff // 2
        else:
            neg_cnt += abs(diff)
    
    if plus2_cnt >= neg_cnt:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    solve()


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()


#define MOD 1000000007

li n, w;
li ww[111];
li v[111];

vector<vector<li>> ws__;

li cumuls[4][111];

int main(void)
{
	cin >> n >> w;
	ws__.resize(4);

	rep(i, n) {
		cin >> ww[i] >> v[i];
	}
	li base = ww[0];

	rep(i, n) {
		ws__[ww[i] - base].push_back(v[i]);
	}

	rep(i, 4) {
		sort(ws__[i].begin(), ws__[i].end());
		reverse(ws__[i].begin(), ws__[i].end());
		cumuls[i][0] = 0;
		rep(j, ws__[i].size()) {
			cumuls[i][j + 1] = cumuls[i][j] + ws__[i][j];
		}
	}

	li res = 0;
	rep(i1, ws__[0].size() + 1) {
		if (base * i1 > w) {
			break;
		}
		rep(i2, ws__[1].size() + 1) {
			if (base * i1 + (base + 1) * i2 > w) {
				break;
			}
			rep(i3, ws__[2].size() + 1) {
				if (base * i1 + (base + 1) * i2 + (base + 2) * i3 > w) {
					break;
				}
				rep(i4, ws__[3].size() + 1) {
					if (base * i1 + (base + 1) * i2 + (base + 2) * i3 + (base + 3) * i4 > w) {
						break;
					}
					res = max(res, cumuls[0][i1] + cumuls[1][i2] + cumuls[2][i3] + cumuls[3][i4]);
				}
			}
		}
	}
	cout << res << endl;




	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    
    long n;
    cin >> n;
    long long x = 0;
    long long y = 0;
    long long ar[n];
    for(long i = 0; i<n; i++){
        cin >> ar[i];
        y+=ar[i];
    }
    long long ans = 0;
    for(long i = 0; i+1<n; i++){
        x += ar[i];
        y-= ar[i];
        if(i==0){
            ans = abs(x-y);
        }
        ans = min(ans,abs(x-y));
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>    
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 2019     
using namespace std;

main()
{    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    s = '@' + s;
    map<int, int> m;
    m[0] = 1;
    int var = 0;
    int mul = 1;
    for(int i = 1; i <= n; i++){
        var = var + (s[i] - '0') * mul;
        var %= mod;
        mul *= 10;
        mul %= mod;
        m[var]++;
    }
    int ans = 0;
    for(auto to: m){
        ans += ((to.S) * (to.S - 1)) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,c;
  while(1){
  cin >> k;
  if(k==0) break;
  int a=0;
  //k=2の時、1通り
  //  3      3
  //  4      6
    for(int i=0; i<((k-1)*k)/2; i++){
        cin >> c;
        a += c;
    }
  a = a / (k-1);
  cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int a,b;
  cin >> a >> b;
  cout << a*b << ' ' << 2*(a+b) << endl; 
  return 0;
}



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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int a , b ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>a>>b ;
	return cout<<a*b<<"\n" , 0 ;
}		

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    double n, x, t;
    cin>>n>>x>>t;
    double t1 = ceil(double(n/x));
    //cout<<n/x<<endl;
    //cout<<t1<<endl;
    ll t11 = ll(t1)*ll(t);
    cout<<t11<<endl;

}


Measured memory_bytes: 3648
fun list() = readLine()!!.split(" ").map {it.toInt()}

val dx = arrayOf(0,1,0,-1)
val dy = arrayOf(1,0,-1,0)

fun main() {
	val (h,w) = list()
	val (ch,cw) = list()
	val (dh,dw) = list()

	val a = Array(h) {readLine()!!}
	val r = Array(h) {IntArray(w) {Int.MAX_VALUE/2}}

	val q = java.util.ArrayDeque<Triple<Int,Int,Int>>()
	r[ch-1][cw-1] = 0
	q.add(Triple(ch-1,cw-1,0))

	fun isRoad(y:Int,x:Int) = y in 0 until h&&x in 0 until w&&a[y][x]=='.'

	fun f(y:Int,x:Int,v:Int) {
		for(d in 0..3) {
			val nx = x+dx[d]
			val ny = y+dy[d]
			if(isRoad(ny,nx)&&r[ny][nx]>v) {
				r[ny][nx] = v
				q.addFirst(Triple(ny,nx,v))
			}
		}

		for(dy in -2..2) {
			for(dx in -2..2) {
				val nx = x+dx
				val ny = y+dy
				if(isRoad(ny,nx)&&r[ny][nx]>v+1) {
					r[ny][nx] = v+1
					q.addLast(Triple(ny,nx,v+1))
				}
			}
		}
	}

	while(!q.isEmpty()) {
		val (y,x,v) = q.poll()
		f(y,x,v)
	}

	println(r[dh-1][dw-1].let {if(it==Int.MAX_VALUE/2) -1 else it})
}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A<C){
    if(B<D){
      cout << max(B-C, 0) << endl;
    }
    else{
      cout << D-C << endl;
    }
  }
  else{
    if(B<D){
      cout << B-A << endl;
    }
    else{
      cout << max(D-A, 0) << endl;
    }
  }
}


Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]
if n == 1:
  print("Yes")
  exit()
s = 0
for i in range(n-1):
  if h[i] > h[i+1] + 1:
    print("No")
    exit()
  elif h[i] > h[i+1]:
    if s == 1:
      print("No")
      exit()
    else:
      s = 1
  elif h[i] < h[i+1]:
    s = 0
print("Yes")

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
int x;
int main(){
    cin >> x;
    int t = x / 100;
    int y = t * 100 + t * 10 + t;
    if(x > y)  cout << (t + 1) * 100 + (t + 1) * 10 + (t + 1) << endl;
    else cout << y << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    int c[5];
    int count=0;

    for(int i=a;i<=b;i++){
        c[0]=i/10000 % 10;
        c[1]=i/1000 % 10;
        c[2]=i/100 % 10;
        c[3]=i/10 % 10;
        c[4]=i % 10;

        if(c[0]==c[4] && c[1]==c[3]) count++;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

x = sum(list(map(int, input().split())))

if x%9==0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9568
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> connect(M, vector<int>(N, 0));
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int s;
            cin >> s;
            connect[i][s - 1] = 1;
        }
    }
    int p[M];
    cins(p, p + M);
    int ans = 0;
    for(int i = 0; i < (1 << N); i++){
        for(int j = 0; j < M; j++){
            int on = 0;
            for(int k = 0; k < N; k++){
                if((i >> k) & 1){
                    on += connect[j][k];
                }
            }
            if(on % 2 != p[j]){
                goto pass;
            }
        }
        ans++;
    pass:;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = (1e5)+1;

int n;
vector<pair<ll, ll> > a;
multiset<ll> r, b;
long long ans = LLONG_MAX;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	a.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		if(a[i].first > a[i].second) swap(a[i].first, a[i].second);
	}
	sort(a.begin(), a.end());
	for(auto p: a) {
		r.insert(p.first);
		b.insert(p.second);
	}
	ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);
	for(auto p: a) {
		r.erase(r.find(p.first));
		b.erase(b.find(p.second));
		r.insert(p.second);
		b.insert(p.first);
		ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);
	}
	cout << ans;
}


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

int main() {
  int n;
  cin >> n;
  
  int m = n % 10;
  
  if(m == 2 || m == 4 || m == 5 || m == 7 || m == 9){
    cout << "hon" << endl;
  }else if(m == 3){
    cout << "bon" << endl;
  }else{
    cout << "pon" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  stack<int> s1;
  stack< pair<int, int> > s2;
  string s;
  int sum=0;
  cin >> s;
  rep(i, s.size()) {
    if(s[i]=='\\') {
      s1.push(i);
    }
    else if(s[i] == '/' && s1.size() > 0) {
      int j = s1.top();
      int a = i-j;
      sum+=i-j;
      s1.pop();
      while(s2.size()>0&&s2.top().first>j) {
        a+=s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j,a));
    }
  }

  cout<<sum<<endl;
  cout<<s2.size();
  vector<int> ans;
  for (int i=0, s2_size=s2.size();i<s2_size;++i) {
    ans.push_back(s2.top().second);
    s2.pop();
  }
  reverse(ans.begin(), ans.end());
  for (int i=0, ans_size=ans.size();i<ans_size;++i) {
    cout<<" ";
    cout<<ans.at(i);
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3304
import itertools
from collections import defaultdict, deque
from copy import deepcopy
ml = [[0,1],[0,-1],[-1,0],[1,0]]
def main(n):
    def move(fi,mli,y,x):
        f = deepcopy(fi)
        for mi in mli:
            mx,my = ml[mi]
            mx += x
            my += y
            if 0 <= mx <= 4 and 0 <= my <= 4:
                f[y][x], f[my][mx] = f[my][mx], f[y][x]
                x, y = mx, my
            else:
                return False
        return f

    def d(b):
        a = 0
        de = []
        for y in range(5):
            for x in range(5):
                if c[y][x]:
                    val = c[y][x]
                    if y == 4 or y == 0:
                        if x == 4 or x == 0:
                            continue
                        if c[y][x+1] == c[y][x-1] == c[y][x]:
                            de.append((y,x, 0))
                    else:
                        if x == 4 or x == 0:
                            if c[y+1][x] == c[y-1][x] == c[y][x]:
                                de.append((y,x, 1))
                            continue
                        else:
                            if c[y][x+1] == c[y][x-1] == c[y][x]:
                                de.append((y,x, 0))
                            if c[y+1][x] == c[y-1][x] == c[y][x]:
                                de.append((y,x, 1))
        for y,x,di in de:
            for i in range(3):
                if di:
                    if c[y+i-1][x]:
                        a += score[c[y+i-1][x]-1] * b
                        c[y+i-1][x] = 0
                else:
                    if c[y][x-1+i]:
                        a += score[c[y][x-1+i]-1] * b
                        c[y][x-1+i] = 0
        if fall():
            a += d(b+1)
        return a

    def fall():
        f = False
        for x in range(5):
            for y in range(3,-1,-1):
                if c[y][x] and c[y+1][x] == 0:
                    for yi in range(y+1,5):
                        if c[yi][x] == 0:
                             continue
                        yi -= 1
                        break
                    c[yi][x],c[y][x] = c[y][x],c[yi][x]
                    f = True
        return f

    ans = 0
    field = [list(map(int, input().split())) for i in range(5)]
    score = list(map(int, input().split()))
    for i in range(n+1):
        mlis = list(itertools.product(range(4),repeat = i))
        for mli in mlis:
            for y in range(5):
                for x in range(5):
                    c = move(field, mli, y, x)
                    if c:
                        ans = max(ans,d(1))
    print(ans)

while 1:
    n = int(input())
    if n == -1:
        break
    main(n)



Measured memory_bytes: 6360
#include <vector>

using namespace std;

typedef vector<int> vi;

// ?????£?????????????§£ (Strongly Connected Component)
// ????????°???????????°????????????????????£??¬??????????????? ???????????§
struct SCCGraph: public vector<vi> {

	vector<int> order;    // ?±????????????£??????????????????(????????????????????????????????£?????????)
	vector<int> vs;   // ??°????????????
	vector<bool> used;    // ?????§???????????????

	using vector::vector;	// ?¶?????????????????????????
	SCCGraph(const vector<vi> &v): vector::vector(v) {}	// ??????????????????????????????????????¨???????????????

	// a -> b ????????????????????????push_back()??§?????????
	void add_edge(int a, int b){
		(*this)[a].push_back(b);
	}

	// scc()??§??????
	void dfs(int n, int k, vector<vi> &v, vector<vi> &rv){
		used[n] = true;
		order[n] = k;
		for(auto t: v[n]){
			if( !rv.empty() ) rv[t].push_back(n);	// ???????????°???????????????
			if( !used[t] ) dfs(t, k, v, rv);
		}
		vs.push_back(n);
	}

	// ?????£?????????????§£?????????
	int scc(){
		int N = size();
		used.assign(N, false);
		order.resize(N);
		vs.clear();
		vector<vi> rG(N), tmp;   // ????????????????????°????????¨
		for(int n=0; n < N; n++){
			if( !used[n] ) dfs(n, n, (*this), rG);
		}
		used.assign(N, false);
		int k = 0;		// ?????£??????????????????
		for(int i = vs.size()-1; i >= 0; i--){
			if( !used[ vs[i] ] ) dfs(vs[i], k++, rG, tmp);
		}
		return k;
	}

	// ?±????????????£????????????????????????????????????
	bool find(int x, int y){
		return order[x] == order[y];
	}

};
// ??¢??°??¨??????scc??????????????????????????????????????????????±????????????£??????????????????
vector<int> scc(const vector<vi> &v){
	SCCGraph g(v);
	g.scc();
	return g.order;
}



// test
// AOJ GRL_3_C (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp)
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
	int V, E;
	SCCGraph graph(10005);

	cin >> V >> E;
	rep(i,E){
		int s, t;
		cin >> s >> t;
		graph.add_edge( s, t );
	}

	graph.scc();
	//rep(i,V) cout << "graph: " << i << " " << graph.order[i] << endl;

	int Q;
	cin >> Q;
	rep(i,Q){
		int u, v;
		cin >> u >> v;
		cout << (int)graph.find(u, v) << endl;
	}

	return 0;
}

// scc()??¢??°????????¨????????????
/*
int main(){
	int V, E;
	vector<vi> edge(10005);

	cin >> V >> E;
	rep(i,E){
		int s, t;
		cin >> s >> t;
		edge[s].push_back( t );
	}

	auto g = scc(edge);

	int Q;
	cin >> Q;
	rep(i,Q){
		int u, v;
		cin >> u >> v;
		cout << (int)(g[u] == g[v]) << endl;
	}

	return 0;
}
*/

Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define name "main"
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fto(i,a,b) for(int i=a; i<=b;++i)
#define maxn 100009
#define ll long long

using namespace std;
bool gone[maxn][3],ck[maxn][3];
int cl[maxn];
int xd[maxn][3],a[maxn][3],w,h,n;
pii b[maxn];
bool check(int i, int x,int j){
    if(ck[i][x])return false;
    ck[i][x]=true;
    if(xd[i][x]==0){
        xd[i][x]=j;
        ck[i][x]=false;
        return true;
    }
    /// xd[i][x]!=0;
    /// i,x la cot hoac hang, j la chi so can dien
    /// t la so can dien
    int t=xd[i][x];
    if(check(a[t][1-x],1-x,t)){
        xd[i][x]=j;
        ck[i][x]=false;
        return true;
    }
    return false;
}
int main()
{
    cin >> n >> h >> w;
    fto(i,1,n){
        cin >> a[i][0]>> a[i][1] >> b[i].fi;
        b[i].se=i;
    }
    sort(b+1,b+n+1,greater<pii> ());
    ll res=0;
    fto(i,1,n){
        int j=b[i].se;
        if(check(a[j][0],0,j)){
            //xd[a[j][0]][0]=j;
            res+=b[i].fi;
        }
        else if(check(a[j][1],1,j)){
            //xd[a[j][1]][1]=j;
            res+=b[i].fi;
        }
    }
    cout << res ;
    return 0;
}


Measured memory_bytes: 6400
inp = input()
H = int(inp.split()[0])
W = int(inp.split()[1])
l = []
for i in range(H):
    l.append(list(input()))

for i in range(H*2):
    line = ""
    for j in range(W):
        line = line + l[int((i)/2)][j]
    print(line)


Measured memory_bytes: 3188
defmodule Main do
  def main do
    [x, y] =
      IO.read(:line)
      |> String.trim |> String.split
	if x == y do
    	IO.puts("=")
    else
    	if x > y do
        	IO.puts(">")
            else
            IO.puts("<")
        end
    end
    
  end
end


Measured memory_bytes: 30892
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll l;
    cin >> l;
    
    ll r = 1;
    while(pow(2, r) <= l){
        r++;
    }
    // cout << r << endl;
    
    vector<tuple<ll, ll, ll>> ans;
    ll c = 0;
    REP(i, r - 1){
        ll res = 1 << i;
        ans.push_back(make_tuple(i + 1, i + 2, 0));
        ans.push_back(make_tuple(i + 1, i + 2, res));
        c += res;
    }
    
    
    for(ll i = r - 1; i >= 1; i--){
        ll res = 1 << (i - 1);
        if(l - c > res){
            ans.push_back(make_tuple(i, r, c + 1));
            c += res;
        }
    }
    
    cout << r << ' ' << ans.size() << '\n';
    REP(i, ans.size()){
        cout << get<0>(ans[i]) << ' ' << get<1>(ans[i]) << ' ' << get<2>(ans[i]) << '\n';
    }
}

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

int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    for(int i=0; i<x; i++)cin>>a[i];
    for(int i=0; i<y; i++)cin>>b[i];
    for(int i=0; i<z; i++)cin>>c[i];
    vector<ll> xy;
    for(int i=0; i<x; i++){
        for(int j=0; j<y; j++){
            xy.push_back(a[i]+b[j]);
        }
    }
    sort(xy.rbegin(),xy.rend());
    if(xy.size()>3000)xy.resize(3000);

    vector<ll> xyz;
    for(int i=0; i<xy.size(); i++){
        for(int j=0; j<z; j++){
            xyz.push_back(xy[i]+c[j]);
        }
    }
    sort(xyz.rbegin(),xyz.rend());
    for(int i=0; i<k; i++){
        cout<<xyz[i]<<endl;
    }
    return 0;
}

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

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

	int64_t steps=0;
	int maximum=0;
	for (int i=0;i<n;++i)
	{
		if (a[i]<maximum)
		{
			steps+=maximum-a[i];
		}
		else
		{
			maximum=a[i];
		}
	}
	cout << steps << endl;
}







Measured memory_bytes: 4044
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

void solve() {
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t) cout<<"Yes\n";
    else cout<<"No\n";
}

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

Measured memory_bytes: 256
import sys
from operator import itemgetter
input = sys.stdin.readline


class BIT():
    """一点加算、区間取得クエリをそれぞれO(logN)で答える
    add: i番目にvalを加える
    get_sum: 区間[l, r)の和を求める
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目にvalを加える"""
        i += 1
        while i <= self.n:
            self.bit[i] += val
            i += i & -i

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        return self._sum(r) - self._sum(l)
      

n = int(input())
info = [tuple([i] + list(map(int, input().split()))) for i in range(n)]
MOD = 998244353

ans = [[0] * n for i in range(4)]

info = sorted(info, key = itemgetter(1))
to_ind = {x[2]: ind for ind, x in enumerate(sorted(info, key = itemgetter(2)))}

bit = BIT(n)
for j in range(n):
    i, x, y = info[j]
    tmp = bit.get_sum(0, to_ind[y])
    ans[2][i]= tmp
    ans[3][i] = j - tmp
    bit.add(to_ind[y], 1)
    
bit = BIT(n)
for j in range(n)[::-1]:
    i, x, y = info[j]
    tmp = bit.get_sum(0, to_ind[y])
    ans[1][i] = tmp
    ans[0][i] = n - j - 1 - tmp
    bit.add(to_ind[y], 1)

res = 0
pow2 = [1] * (n + 10)
for i in range(n):
    pow2[i + 1] = pow2[i] * 2
    pow2[i + 1] %= MOD

ans = list(zip(*ans))
for a1, a2, b1, b2 in ans:
    res += (pow2[a1] - 1) * (pow2[b1] - 1) * (pow2[a2 + b2])
    res %= MOD
    res += (pow2[a2] - 1) * (pow2[b2] - 1) * (pow2[a1 + b1])
    res %= MOD
    res += pow2[n - 1]
    res -= (pow2[a1] - 1) * (pow2[a2] - 1) * (pow2[b1] - 1) * (pow2[b2] - 1)
    res %= MOD
print(res % MOD)

Measured memory_bytes: 126036
def check_string(s):
  if(a_exist(s)):
    c_index = c_find(s)
    if(c_index != False):
      if(is_lower(s,c_index)):
        return 'AC'
  return 'WA'

def a_exist(s):
  if(s[0] == 'A'):
    return True
  else:
    return False

def c_find(s):
  c_cnt = 0
  for i in range(len(s)):
    if(i < 2):
      continue
    if(i == len(s)-1):
      continue
    if(s[i] == 'C'):
      c_cnt += 1
      index = i
  if(c_cnt == 1):
    return index
  else:
    return False

def is_lower(s,index):
  for i in range(len(s)):
    if(i == 0):
      continue
    if(i == index):
      continue
    if(s[i].islower() == False):
      return False
  return True

if __name__ == '__main__':
  s = input()
  print(check_string(s))

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

int main(void){
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];
    
    sort(abc.begin(), abc.end());
    
    cout << abc[0] << " " << abc[1] << " " << abc[2] << endl;
    return 0;
}

Measured memory_bytes: 3044
#!/usr/bin/env python3
import sys
import numpy as np

MOD = 1000000007  # type: int

# 4c2 = 4*3/1*2     = 6 (0,1)[1],(0,2)[2],(0,3)[3],(1,2)[3],(1,3)[4],(2,3)[5]
# 4c3 = 4*3*2/1*2*3 = 4 ()
# 4c4 = 1           = 1

    
def solve(N: int, K: int):
    #print(N,K)
    ans=0
    for i in range(K, N+2):
        ans+=i*(N+1-i)+1
    print(ans%MOD)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27096