akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define H 10004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N],dp[N];
ll seg[4*N][2];
multiset < ll > values[N][2];

void update(ll low,ll high,ll pos,ll slow,ll id)
{
    if(low == high && low == slow)
    {
        if(!values[low][id].empty())
            seg[pos][id]= *(values[low][id].begin());
        else
            seg[pos][id] = INF;
        return;
    }
    if(low>slow||high<slow)
        return;

    ll mid = (low+high)/2;

    update(low,mid,pos*2+1,slow,id);
    update(mid+1,high,pos*2+2,slow,id);

    seg[pos][0]=min(seg[pos*2+1][0],seg[pos*2+2][0]);
    seg[pos][1]=min(seg[pos*2+1][1],seg[pos*2+2][1]);

    return;
}

ll query(ll low,ll high,ll pos,ll slow,ll shigh,ll id)
{
    if(low >= slow && high <= shigh)
    {
        return seg[pos][id];
    }
    if(high < slow || low > shigh)
        return INF;

    ll mid = (low+high)/2;

    return min(query(low,mid,pos*2+1,slow,shigh,id),query(mid+1,high,pos*2+2,slow,shigh,id));
}


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

    cin >> n >> k;

    rep(i,0,n)
    {
        cin >> ar[i];
    }

    memset(seg,INF,sizeof seg);

    dp[0] = 0;
    values[ar[0]][0].insert(-ar[0]);
    update(0,H,0,ar[0],0);
    values[ar[0]][1].insert(ar[0]);
    update(0,H,0,ar[0],1);

    rep(i,1,n)
    {
        ll v1 = query(0,H,0,0,ar[i],0)+ar[i];
        ll v2 = query(0,H,0,ar[i],H,1)-ar[i];

        dp[i] = min(v1,v2);

       // cout << i << ": " << v1 << " " << v2 << endl;

        values[ar[i]][0].insert(dp[i]-ar[i]);
        update(0,H,0,ar[i],0);
        values[ar[i]][1].insert(dp[i]+ar[i]);
        update(0,H,0,ar[i],1);


        if(i >= k)
        {
            multiset < ll >::iterator it = values[ar[i-k]][0].find(dp[i-k]-ar[i-k]);
            values[ar[i-k]][0].erase(it);
            update(0,H,0,ar[i-k],0);
            it = values[ar[i-k]][1].find(dp[i-k]+ar[i-k]);
            values[ar[i-k]][1].erase(it);
            update(0,H,0,ar[i-k],1);
        }

       // cout << seg[0][0] << " " << seg[0][1] << endl;
    }

    cout << dp[n-1];

    return 0;
}



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

int main(void){
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for(int i=0;i<n;++i) {
        cin >> a[i].second >> a[i].first;
    }
    sort(a.begin(), a.end());
    int next = a[n-1].first;
    for(int i=n-1;i>=0;--i){
        if(next > a[i].first){
            next = a[i].first;
        }
        if(next < a[i].second){
            cout << "No" << endl;
            return 0;
        }
        next -= a[i].second;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
	int x[4],y[4];

	scanf("%d%d%d%d",&x[0],&y[0],&x[1],&y[1]);

	int dx=x[1]-x[0],dy=y[1]-y[0];

	x[2] = x[1] - dy,y[2]=y[1]+dx;
	x[3] = x[0] - dy,y[3] = y[0] + dx;
	if(x[0]*y[1]+x[1]*y[2]+x[2]*y[0]>x[1]*y[0]+x[2]*y[1]+x[0]*y[2]){
		printf("%d %d %d %d",x[2],y[2],x[3],y[3]);
		return 0;
	}
	x[2] = x[1] + dy,y[2]=y[1]-dx;
	x[3] = x[0] + dy,y[3] = y[0] - dx;
	if(x[0]*y[1]+x[1]*y[2]+x[2]*y[0]>x[1]*y[0]+x[2]*y[1]+x[0]*y[2]){
		printf("%d %d %d %d",x[2],y[2],x[3],y[3]);
		return 0;
	}

}


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

using namespace std;
using ll = long long;

int main() {
  ll A , B;
  cin >> A >> B;
  if(A==B)
    cout << A+B << endl;
  else{
    ll m = max(A,B);
    cout << m+m-1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

vector<int> ans;


template <typename G>
vector<int> topological_sort(const G& g) {
  const int N = (int)g.size();
  vector<int> deg(N);
  for (int i = 0; i < N; i++) {
    for (auto& to : g[i])
      ++deg[to];
  }
  stack<int> st;
  for (int i = 0; i < N; i++) {
    if (deg[i] == 0)
      st.emplace(i);
  }
  vector<int> ord;
  while (!st.empty()) {
    auto p = st.top();
    st.pop();
    ord.emplace_back(p);
    for (auto& to : g[p]) {
      if (--deg[to] == 0) {
        st.emplace(to);
        ans[to] = p + 1;
      }
    }
  }
  return ord;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N - 1 + M), B(N - 1 + M);
  rep(i, N - 1 + M) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  vector<vector<int>> G(N);
  rep(i, N - 1 + M) {
    G[A[i]].pb(B[i]);
  }

  ans = vector<int>(N);

  auto sorted = topological_sort(G);

  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 8048
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner kbd = new Scanner(System.in);

    String n;
    boolean[] ans;
    int count;

    void run(){
	while(kbd.hasNext()){
	    n = kbd.next();
	    int[] num = new int[10]; // 何が何枚あるか、0は未使用
	    for(int i=0; i<n.length(); i++){
		int a = Integer.parseInt(n.substring(i, i+1));
		num[a]++;
	    }
	    ans = new boolean[10];
	    count = 0;
	    solve(num);

	    if(count!=0){
		for(int i=0; i<num.length; i++){
		    if(ans[i]) {
			System.out.print(i);
			count--;
			if(count!=0)
			    System.out.print(" ");
		    }
		}
	    }
	    else System.out.print("0");
	    System.out.println();
	}
    }

    void solve(int[] num){
	/*
	  牌の追加の仕方は9通りなので、全パターン試す
	*/
	for(int k=1; k<10; k++){
	    int[] ns = Arrays.copyOf(num, 10);
	    ns[k] += 1;
	    /*
	      もし追加したのが5枚目だったら、なかったことにして次へ
	      そうでなければ、成り立っているか確かめる
	    */
	    if(ns[k]<5){
	        /*
		System.out.println("--- k = "+k+" ---");
		for(int i=0; i<ns.length; i++){
		    System.out.println(i+" : "+ns[i]);
		}
	        */
		check(ns, 0, k, false);
		if(ans[k]) count++;
	    }
	    ns[k] -= 1;
	}
    }

    void check(int[] num, int level, int k, boolean f){
	/* 
	   枝刈りチェック
	   全部0だったら終わり
	*/
	boolean tf = true;
	for(int i=0; i<num.length; i++)
	    tf = tf && num[i]==0;
	if(tf){
	    ans[k] = true;
	    return;
	}
	else if(level == num.length) return;


	boolean flag = false;
	/* 確認用
	System.out.println("** l = "+level+" **");
	for(int i=0; i<num.length; i++){
	    System.out.println(i+" : "+num[i]);
	}
	*/

	// 1. 刻子ケース
	if(num[level]>=3){
	    flag = true;
	    num[level] -= 3;
	    if(num[level]==0)
		check(num, level+1, k, f);
	    else
		check(num, level, k, f);
	}
	if(flag){
	    num[level] += 3;
	    flag = false;
	}

	// 2. 雀頭ケース
	if(num[level]>=2 && !f){
	    flag = true;
	    f = true;
	    num[level] -= 2;
	    if(num[level]==0)
		check(num, level+1, k, f);
	    else
		check(num, level, k, f);
	}
	if(flag){
	    num[level] += 2;
	    flag = false;
	    f = false;
	}

	// 3. 順子ケース
	if(level+2<num.length && num[level]>=1 &&
	   num[level+1]>=1 && num[level+2]>=1){
	    flag = true;
	    num[level] -= 1;
	    num[level+1] -= 1;
	    num[level+2] -= 1;
	    if(num[level]==0)
		check(num, level+1, k, f);
	    else
		check(num, level, k, f);
	}
	if(flag){
	    num[level] += 1;
	    num[level+1] += 1;
	    num[level+2] += 1;
	    flag = false;
	}	

	if(num[level]==0) check(num, level+1, k, f);
	else return; // 1以上あるのに引けなかったパターン
    }
}

Measured memory_bytes: 18004
#include"iostream"
#include"string"
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	char a[110][110];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}
	int check = 0;

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (a[i][j] == '#')check++;
		}
		if (check == 0)
		{
			for (int i1 = i ; i1 < h; i1++)
			{
				for (int j = 0; j < w; j++)
				{
					a[i1][j] = a[i1+1][j];
				}
			}
			i--;
			h--;
		}
		check = 0;
	}


	for (int j = 0; j < w; j++)
	{
		for (int i = 0;i < h; i++)
		{
			if (a[i][j] == '#')check++;
		}
		if (check == 0)
		{
			for (int j1 = j; j1 < w; j1++)
			{
				for (int i = 0; i < h; i++)
				{
					a[i][j1] = a[i][j1 + 1];
				}
			}
			j--;
			w--;
		}
		check = 0;
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cout << a[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int dp[1001][1001] = {0};
int main() {
	int W, N;
	int t = 1;
	while ( cin >> W, W ) {
		cin >> N;
		vector<int> v(N), w(N);
		for (int i = 0; i < N; ++i) {
			scanf("%d,%d", &v[i], &w[i]);
		}
		fill(&dp[0][0], &dp[0][0]+1001*1001, 0);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= W; ++j) {
				if (w[i] + j <= W) {
					dp[i+1][w[i] + j] = max(dp[i+1][w[i] + j], dp[i][j] + v[i]);
				}
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			}
		}
		int aw = 0, av = 0;
		for (int i = 0; i <= W; ++i) {
			if (dp[N][i] > av) {
				av = dp[N][i], aw = i;
			}
		}
		cout << "Case " << t << ":" << endl;
		cout << av << endl;
		cout << aw << endl;
		++t;
	}
}

Measured memory_bytes: 5168
N = int(input())
S = input()
DP = [[0]*5005 for _ in range(5005)]

for i in range(N):
    for j in range(N):
        if S[i] == S[j]:
            DP[N-i][N-j] = DP[N-i+1][N-j+1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(DP[i][j], j-i)
        ans = max(ans, now)

print(ans)


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

const int MAX = 300001;
bool data[MAX];
vector<int> MSPrime;


void make(){
  fill(data,data+MAX,false);
  for(int i = 0; i < MAX; i++){
    if(7*i+1 < MAX) data[7*i+1] = true;
    else break;
    if(7*i+6 < MAX) data[7*i+6] = true;
    else break;
  }

  for(int i = 5; i < sqrt(MAX); i++)
    if(data[i]) 
      for(int j = 2*i; j < MAX; j+=i) data[j] = false;

  for(int i = 2; i < MAX; i++)
    if(data[i])MSPrime.push_back(i);
}

void solve(int in){
  for(int i = 0; i < MSPrime.size(); i++){
    if(!(in%MSPrime[i])) cout << " " << MSPrime[i];
    if(MSPrime[i] > in) break;
  }
  
}
int main(){
  make();
  int in;
  while(cin >> in){
    if(in == 1) break;
    
    cout << in << ":";
    solve(in);
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1468
n=int(input())
a=list(map(int,input().split()))

a=sorted(a)


b=a.pop(-1)
mid=b/2
dist=10**9
for i in range(n-1):

    #できるだけ最大値から離れた値
    d=abs(mid-a[i])
    if d <dist:
        dist=d
        ans=a[i]

print(b,ans)



Measured memory_bytes: 20076
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
T,U=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  Y,Z=-1,-10**20
  V,W=Y,Z
  T,U=V,W
  for j in range(26):
    if Y==-1:
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      T,U=V,W
      V,W=Y,Z
      Y,Z=j,X[j]+S[i][j]
    elif W<X[j]+S[i][j]:
      T,U=V,W
      V,W=j,X[j]+S[i][j]
    elif T<X[j]+S[i][j]:
      T,U=j,X[j]+S[i][j]
  XX[Y]-=X[Y]
  X[Y]=0
  P.append([Y,V,T])
  if randrange(0,50)==0:
    P[i][1]=randrange(0,26)
  if randrange(0,3)==0:
    P[i][2]=randrange(0,26)
  P[i]=tuple(P[i])
SCORE=0
X=[0]*26
for i in range(D):
  SCORE+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
  for k in range(2):
    d,q=i,P[i][k+1]
    SCORE2=SCORE
    YY=XX[:]
    SCORE2-=S[d][P[d][0]]
    SCORE2+=S[d][q]
    for j in range(26):
      X[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      X[P[d][0]]+=C[P[d][0]]
      X[q]+=C[q]
      X[Z]=0
      YY[P[d][0]]+=X[P[d][0]]
      YY[q]+=X[q]
    if SCORE2-sum(YY)>SCORE-sum(XX):
      z=[P[i][k+1]]
      for l in range(3):
        if l!=k:
          z.append(P[i][l])
      P[i]=tuple(z)
      XX=YY[:]
      SCORE=SCORE2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 79668
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
const int mo=1e9+7;
typedef pair<int,int> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
signed main(){
	int k,a,b;read(k);read(a);read(b);
	int tmp=a/k*k;
	if(tmp<a)tmp+=k;
	if(tmp<=b)puts("OK");
	else puts("NG");
	return 0;
}

Measured memory_bytes: 3624
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BComparingStrings {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        REP(i, b) {
            cout << a;
        }
        cout << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BComparingStrings solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
 
int main()
{
    int i;
 
    int sum = 0;
    char W[11], T[1001];
 
    scanf("%s", W);
    for( i = 0; W[i]; ++i ) W[i] = tolower(W[i]);
    while( 1 ){
        scanf("%s", T);
        if( strcmp("END_OF_TEXT", T) == 0 ) break;
        for( i = 0; T[i]; ++i ) T[i] = tolower(T[i]);
        if( strcmp(W, T) == 0 ) ++sum;
    }
 
    printf("%d\n", sum);
 
  }

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

typedef long long LL;
const int N = 3005;

int n, mod, dp[N];

int pow(int x, int y, int ans = 1, int mod = ::mod) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> mod;
	int c = 1, ans = 0; dp[0] = 1;
	for (int i = 0; i <= n; ++i) {
		int x = pow(2, n - i), y = 1, sum = 0;
		for (int j = 0; j <= i; ++j, y = (LL) y * x % mod)
			sum = (sum + (LL) y * dp[j]) % mod;
		ans = (ans + (LL) c * pow(2, pow(2, n - i, 1, mod - 1), sum)) % mod;
		c = (LL) c * pow(i + 1, mod - 2, i - n + mod) % mod;
		for (int j = i + 1; j; --j)
			dp[j] = (dp[j - 1] + (LL) (j + 1) * dp[j]) % mod;
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sq(a) (a)*(a)
long double PI=3.14159265358979;
int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double p,q,r,s,tt,uu,vv,ww,angle,ans;
    p=h*1.00*30;
    q=(m/60.00)*30.00;
    r=p+q;
    s=m*6.00;
    if(r>=s)
    {
        tt=((r-s)*PI)/180.00;
        angle=cos(tt);
        uu=sq(a)*1.00+sq(b)*1.00-2.00*a*b*angle;
        vv=sqrtl(uu);
        cout<<setprecision(15)<<vv<<endl;
        return 0;
    }
    else
    {
        tt=((s-r)*PI)/180.00;
        angle=cos(tt);
        uu=sq(a)*1.00+sq(b)*1.00-2.00*a*b*angle;
        vv=sqrtl(uu);
        cout<<setprecision(15)<<vv<<endl;
        return 0;
    }
}

Measured memory_bytes: 4168
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	
	public void solve(InputReader in, PrintWriter out) {
		long n = in.nextLong(), m = n%11;
		long ans = n / 11 * 2;
		
		if (m > 0) {
			if (m <= 6)
				ans += 1;
			else
				ans += 2;
		}
		
		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 22612
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

con=min(listA[1])+min(listA[2])
listB=[listA[1][listA[i+3][0]-1]+listA[2][listA[i+3][1]-1]-listA[i+3][2] for i in range(listA[0][2])]
print(min(con,min(listB)))

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int t, x;
    cin >> t >> x;

    cout << (double(t) / double(x)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};



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

    string s;
    cin>>s;
    int n = s.size() - 1;
    if(s[n] == 's')cout << s << "es" << endl;
    else cout << s << "s" << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_SIZE 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 100

int N,E;
vector<int> G[SIZE];
bool can_visit[SIZE][SIZE];

void bfs(int start_node){

	queue<int> Q;

	for(int i = 0; i < G[start_node].size(); i++){
		can_visit[start_node][G[start_node][i]] = true;
		Q.push(G[start_node][i]);
	}

	while(!Q.empty()){

		for(int i = 0; i < G[Q.front()].size(); i++){
			if(can_visit[start_node][G[Q.front()][i]] == false){
				can_visit[start_node][G[Q.front()][i]] = true;
				Q.push(G[Q.front()][i]);
			}
		}
		Q.pop();
	}
}

int main(){

	scanf("%d %d",&N,&E);

	int from,to;
	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)can_visit[i][k] = false;
	}

	for(int i = 0; i < N; i++)bfs(i);

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			if(can_visit[i][k] == true && can_visit[k][i] == true){
				printf("1\n");
				return 0;
			}
		}
	}

	printf("0\n");

	return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int cnt=0;
	for(int i=a;i<=b;i++){
		if(c%i==0)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, v: "List[int]"):
    v.sort()
    tmp = (v[0] + v[1]) / 2
    for i in range(2, N):
        tmp = (tmp + v[i]) / 2
    ret = tmp
    print(ret)
    return


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
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, v)

if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    ll ans = 0;
    REP(i, K) {
        ll now = i;
        ll next = i + K;
        char pre = ' ';
        while(now < N) {
            if (T[now] == pre) {
                pre = ' ';
            } else {
                if (T[now] == 'r') {
                    ans += P;
                    pre = 'r';
                }
                else if (T[now] == 's') {
                    ans += R;
                    pre = 's';
                }
                else {
                    ans += S;
                    pre = 'p';
                }
            }
            now = next;
            next = next + K;
        }
    }
    PRINT(ans);
    return 0;
} 

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int g=0;
        if(n.substring(0,1).equals("1")) {
            g++;
        }
        if(n.substring(1,2).equals("1")) {
            g++;
        }
        if(n.substring(2,3).equals("1")) {
            g++;
        } 
        System.out.println(g);
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
int main() {
	int dataset,a,b,c;
	string triangle[1000];
	cin >> dataset;
	for (int i = 0; i < dataset; i++){
		cin >> a >> b >> c;
		if (a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b){
			triangle[i] = "YES";
		}
		else
		{
			triangle[i] = "NO";
		}
	}
	for (int i = 0; i < dataset; i++){
		cout << triangle[i]<<"\n";
	}
	cin >> a;
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    int H = in.nextInt();
    int W = in.nextInt();
    in.nextLine();
    boolean[][] obj = new boolean[H][W];
    int[][] left = new int[H][W];
    int[][] top = new int[H][W];
    int[][] right = new int[H][W];
    int[][] bottom = new int[H][W];
    
    for(int h=0; h<H; h++){
      char[] c = in.nextLine().toCharArray();
      for(int w=0; w<W; w++){
        if(c[w]=='#'){
          obj[h][w] = true;
          left[h][w] = 0;
          top[h][w] = 0;
        }else{
          obj[h][w] = false;
          if(w==0){
            left[h][w] = 1;
          }else{
            left[h][w] = left[h][w-1]+1;
          }
          if(h==0){
            top[h][w] = 1;
          }else{
            top[h][w] = top[h-1][w]+1;
          }
        }
      }
    }
    int max=0;
    for(int h=H-1; h>=0; h--){
      for(int w=W-1; w>=0; w--){
        if(obj[h][w]){
          right[h][w] = 0;
          bottom[h][w] = 0;
        }else{
          if(w==W-1){
            right[h][w] = 1;
          }else{
            right[h][w] = right[h][w+1]+1;
          }
          if(h==H-1){
            bottom[h][w] = 1;
          }else{
            bottom[h][w] = bottom[h+1][w]+1;
          }
        }
        int num = left[h][w]+top[h][w]+right[h][w]+bottom[h][w]-3;
        if(max < num){
          max = num;
        }
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 142424
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int tmp;
        int ans = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    tmp = gcd(a, b);
                    ans += gcd(tmp, c);
                }
            }
        }
        System.out.println(ans);
    }

    static int gcd(int i, int j) {
        int rem = j;
        while ((rem = i % j) != 0) {
            i = j;
            j = rem;
        }
        return j;
    }
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  map<ll, ll> m;
  rep(i, N + 1) {
    if (i == 0) continue;
    vector<P> fac = factorize(i);
    rep(j, fac.size()) {
      P p = fac[j];
      if (p.first == 1) continue;
      m[p.first] += p.second;
    }
  }

  ll ans = 0;
  qll q;
  q.push(1);

  for (auto mm : m) {
    if (mm.second <= 1) continue;
    qll next;
    while (!q.empty()) {
      ll f = q.front();
      q.pop();
      next.push(f);
      rep(i, mm.second / 2) {
        ll n = f * ((i + 1) * 2 + 1);
        if (n == 75) ans++;
        if (n > 75) continue;
        next.push(n);
      }
    }
    q = next;
  }

  ANS;
  return 0;
}

Measured memory_bytes: 3708
import sys

a,b,c,k = input().split()
A = int(a)
B = int(b)
C = int(c)
K = int(k)

ans = 0

if (K - A >= 0):
  ans += A
else:
  ans += K

K = K - A - B

if (K > 0):
  ans = ans - K

print (ans)

    

Measured memory_bytes: 9148
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;


int main()
{
	int N;
	vector<vector<int> > Aij(3, vector<int>(3, 0));
	set<int> s_list;
	rep(i, 3) {
		rep(j, 3) {
			cin >> Aij[i][j];
			s_list.insert(Aij[i][j]);
		}
	}
	
	cin >> N;
	vector<int> Bi(N, 0);
	rep(i, N) {
		cin >> Bi[i];
		auto it = s_list.find(Bi[i]);
		if (it != s_list.end()){ 
			rep(j, 3) {
				rep(k, 3) {
					if (Aij[j][k] == Bi[i]) Aij[j][k] = -1;
				}
 			}
		}
	}

	bool judge = false;
	bool judges[8] = {true,true,true,true,true,true,true,true};
	rep(i, 3){
		if (Aij[i][0] != -1) judges[0] = false;
		if (Aij[i][1] != -1) judges[1] = false;
		if (Aij[i][2] != -1) judges[2] = false;
		if (Aij[0][i] != -1) judges[3] = false;
		if (Aij[1][i] != -1) judges[4] = false;
		if (Aij[2][i] != -1) judges[5] = false;
		if (Aij[i][i] != -1) judges[6] = false;
		if (Aij[2-i][i] != -1) judges[7] = false;
	}

	rep(i, 8) {
		if (judges[i] == true) {
			judge = true;
		}
	}

	if (judge) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
} 

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>

using namespace std;

int main(){

    int x,y;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0){
            break;
        }
        if(x>y){
            int tmp;
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x <<" "<< y << endl;
    }

    return 0;
}



Measured memory_bytes: 3084
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int INF = 1001001001;
const ll LINF = 1e18;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}

ll twoMod(ll in){
    ll count = 0;
    while(in % 2 == 0){
        count++;
        in /= 2;
    }
    return count;
}

int main() {
    ll N; string S; cin >> N >> S;
    
    ll e_count = 0;
    for (ll i = 0; i < N; i++) {
        if(S[i] == 'E') e_count++;
    }
    
    ll ret = e_count;
    ll re = e_count;
    ll lw = 0;
    for (ll i = 0; i < N; i++) {
        if(S[i] == 'E') re--;
        if(i >= 1 && S[i - 1] == 'W') lw++;
        ret = min(ret, re + lw);
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

string S;

int solve() {
	int res = S.size();
	int p = 0, st = -1;
	
	while (p < S.size()) {
		while (p < S.size() && !S[p]) p++;
		if (p == S.size()) break;
		
		st = p - 1;
		while (p < S.size() && S[p]) p++;
		chmin(res, max(st + 1, (int)S.size() - p));
	}
	
	return res;
}

int main() {
	cin >> S; REP(i, S.size()) S[i] -= '0';
	
	int ans = solve();
	REP(i, S.size()) S[i] ^= 1;
	chmax(ans, solve());
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

vector <ll> par(10000);
vector <ll> d(10000);

void init(ll n) {
  rep(i, n) {
    par.at(i) = i;
    d.at(i) = 0;
  }
}

ll find(ll n) {
  if (n == par.at(n)) {
    return n;
  } else {
    return par.at(n) = find(par.at(n));
  }
}

void unite(ll n, ll m) {
  n = find(n);
  m = find(m);
  if (n == m) return;
  if (d.at(n) < d.at(m)) {
    par.at(n) = m;
  } else {
    par.at(m) = n;
    if (d.at(n) == d.at(m)) d.at(n)++;
  }
}

bool same(ll n, ll m) {
  return find(n) == find(m);
}

int main() {
  ll n, m;
  cin >> n >> m;
  init(n);
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == 0) {
      unite(b, c);
    } else {
      if (same(b, c)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
}


Measured memory_bytes: 3236
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

const int MAXT=10000;
const long double LI =1e-10;

int main(){
  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  rep(i,N) cin>>X[i]>>Y[i];

  long double cx=0.0,cy=0.0;
  long double xsv=0.0,ysv=0.0;
  long double rate=0.5;
  long double madist=0.0;
  int tim=0;
  while(1){
      bool ch=false;
      rep(t,MAXT){
          madist=0.0;
          int n=0;
          for(int i=0;i<N;i++){
            long double dis=(X[i]-cx)*(X[i]-cx)+(Y[i]-cy)*(Y[i]-cy);
            dis=sqrt(dis);
            if(dis>madist){
                madist=dis;
                n=i;
            }
          }

          cx+=(X[n]-xsv)*rate;
          cy+=(Y[n]-ysv)*rate;

          long double dis=(cx-xsv)*(cx-xsv)+(cy-ysv)*(cy-ysv);
          dis=sqrt(dis);
          if(dis<=LI){
              cx=xsv;
              cy=ysv;
              ch=true;
              break;
          }

          xsv=cx;
          ysv=cy;
      }

      if(ch) break;
      rate/=2.0;
  }

  long double ans=madist;

  //ans/=2.0;
  cout<<fixed<<setprecision(15)<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  scanf("%d", &N);
  
  vector<long long> v(N);
  for(int i=0;i<N;i++){
      scanf("%d", &v[i]);
  }

  long long S = 0;  
  long long MOD = pow(10,9)+7;
  
  vector<long long> CUMSUM(N);
  CUMSUM[N-1] = v[N-1];
  for (int i=N-2;i>=0;i--){
    CUMSUM[i] = (v[i] + CUMSUM[i+1])%MOD;
  }

  for (int i=0;i<N-1;i++){
    S+=v[i]*CUMSUM[i+1]%MOD;
  }
  
  S%=MOD;

  printf("%d\n", S);  
  
  return 0;
}


Measured memory_bytes: 6436
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  ll L, R; cin >> L >> R;

  ll ans = 1<<30;
  for (ll i = L; i <= R; ++i) {
    for (ll j = i+1; j <= R; ++j) {
      ll tmp = i*j%2019;
      ans = min(ans, tmp);
      if (tmp == 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n, W = tuple(map(int, input().split()))
vw = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0 for _ in range(W + 1)] for _ in range(n + 1)]

for i in range(n):
    for w in range(W + 1):
        if w >= vw[i][1]:
            dp[i + 1][w] = max(dp[i][w - vw[i][1]] + vw[i][0], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]

print(max([max(e) for e in dp]))



Measured memory_bytes: 42472
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var n = ReadLine();
        for (int i = 0; i < n.Length; i++) {
            if (n[i] == '1') {
                Write('9');
            } else {
                Write('1');
            }
        }
        WriteLine();
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

int main(){
  int N, v, j, A[1000];

  cin >> N;

  for (int i=0; i<N; i++){
    cin >> A[i];
  }

  
      for (int i=0; i<N; i++){
    cout << A[i];
    if(i==N-1)
      printf("\n");
      else printf(" ");
  }

  for (int 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;

      for (int i=0; i<N; i++){
    cout << A[i];
    if(i==N-1)
      printf("\n");
      else printf(" ");
  }
  }



  return 0;
}

Measured memory_bytes: 3096
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))
c = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        c += 1

print(' '.join((str(x) for x in A)))
print(c)

Measured memory_bytes: 6724
local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]   
            c[4]=false
        end
        b=meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=meld(a,e)
    end
    return a
end


local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
    if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------
 
local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end
 
for i=1,m do
    local x=a:top()
    x=math.floor(x/2)
    a:pop()
    a:push(-x,x)
end
 
local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(string.format("%d",total))

Measured memory_bytes: 18232
n = int(input())
last_a = 0
first_b = 0
both = 0
ans = 0
for i in range(n):
  s = input()
  a, b = s[-1], s[0]
  if a == "A" and b == "B":
    both += 1
  elif a == "A":
    last_a += 1
  elif b == "B":
    first_b += 1
  for j in range(len(s)-1):
    if s[j] == "A" and s[j+1] == "B":
      ans += 1
if last_a == 0 and first_b == 0:
  ans += max(both - 1,0)
else:
  ans += min(last_a,first_b) + both
print(ans)


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

using namespace std;

const int N = 4234567;

int f[N];
const int bits = 30;
// 😂 😂
int main() {
  int n; cin >> n;
  f[0] = 0;
  for(int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + 1;
    for(int j = 6; j <= i; j *= 6) {
      f[i] = min(f[i - j] + 1, f[i]);
    }
    for(int j = 9; j <= i; j *= 9) {
      f[i] = min(f[i - j] + 1, f[i]);
    }
  }
  cout << f[n] << endl;
}

Measured memory_bytes: 640
/* 
* ID: juryc
* PROG: HandStand2
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int dig[10][10]; 
memset(dig,0,sizeof(dig));
auto fd=[&](int b){ while((b/10)) b/=10; return b;}  ;
auto ld=[&](int b){ return b%10; };
long long ans=0;
for(int i=1;i<=n;i++) { 
int v1=fd(i),v2=ld(i); 
ans+=2*dig[v2][v1]; 
if(v1==v2) ans++;
dig[v1][v2]++;
}
cout<<ans<<"\n"; 
return 0;
} 


Measured memory_bytes: 3636
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;

int main(){
	int n;
	cin >> n;
	int a[n+2], b[n+2], c[n+2];
	int da[n+2], db[n+2], dc[n+2];
	int i;
	rep(i, n){
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
	}
	rep(i, n){
		if(i==0){
			da[0] = a[0];
			db[0] = b[0];
			dc[0] = c[0];
		}
		if(i!=0){
			da[i] = max(db[i-1], dc[i-1]) + a[i];
			db[i] = max(da[i-1], dc[i-1]) + b[i];
			dc[i] = max(da[i-1], db[i-1]) + c[i];
		}
	}
	cout << max(da[n-1],max(db[n-1], dc[n-1])) << endl;
}


Measured memory_bytes: 2560
using System;

public class Program
{
    public static void Main()
    {
        string input = Console.ReadLine();
        string[] split = input.Split(' ');
        int length = Int32.Parse(split[0]);
        int breadth = Int32.Parse(split[1]);
        int area = length * breadth;
        int perimeter = (length + breadth) * 2;
        Console.WriteLine("{0} {1}", area, perimeter);
    }
    
}


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>

typedef long long int llint;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
	*this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

int main(void){
  int x, y;
  std::cin >> x >> y;

  llint a_three = -x + 2*y;
  llint b_three = 2*x - y;
  if(a_three%3!=0 or b_three%3!=0 or a_three < 0 or b_three < 0){
    std::cout << 0 << std::endl;
    return 0;
  }
  
  llint a = a_three / 3;
  llint b = b_three / 3;

  modint<1000000007> result = 1;
  for(int i=1; i<=a+b; i++){
    result *= i;
  }
  for(int i=1; i<=a; i++){
    result /= i;
  }
  for(int i=1; i<=b; i++){
    result /= i;
  }
  std::cout << result.value() << std::endl;
  return 0;
}


Measured memory_bytes: 384
n = int(input())
str = input()
a = str.split()
flag = 1

for i in range(n):
    if int(a[i]) % 2 == 0:
        if (int(a[i]) % 3 != 0 and int(a[i]) % 5 != 0):
            flag = 0
            break
if flag == 1:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+')
    cout<<a+b;
    else
    cout<<a-b;}

Measured memory_bytes: 3572