akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;


class Edge {
	public:
		int to, cost;
		Edge(int to, int cost) : to(to), cost(cost) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int prim(const Graph &g, int s = 0) {
	int n = g.size();
	int total = 0;

	vector<bool> visited(n);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
	//priority_queue<pair<int, int> > q;

	q.push(make_pair(0,s));

	vector<int> res;
	while (not q.empty()) {
		pair<int, int> u = q.top(); q.pop();
		if (visited[u.second]) continue;
		total += u.first;
		res.emplace_back(u.first);
		visited[u.second] = true;
		for(auto it : g[u.second]) {
			if (not visited[it.to]) q.push(make_pair(it.cost, it.to));
		}
	}
	sort(all(res));
	//for(auto i : res){ show(i) }
	return res[res.size() / 2];
}

int main(){
	int n, m;
	while(cin >> n >> m, n){
		Graph g(n);
		rep(i,m){
			int a, b, c;
			cin >> a >> b >> c;
			a--; b--;
			g[a].emplace_back(b,c);
			g[b].emplace_back(a,c);
		}
		cout << prim(g) << endl;
	}
}

Measured memory_bytes: 3388
a,b,c=input().split()
if a == b:
    if a != c:
        print('Yes')
    else:
        print("No")
elif a == c:
    if a != b:
        print('Yes')
    else:
        print("No")
elif b == c:
    if b != a:
        print('Yes')
    else:
        print("No")
else:
    print("No")


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

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

typedef long long ll;
using namespace std;

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

  int A, B;
  cin >> A >> B;

  if (A < B) {
    cout << B + max(B - 1, A) << endl;
  } else {
    cout << A + max(A - 1, B) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  const int N=100000;
  int count[N]={0};    //1~100000 ga ikutsu haitteruka
  int i=0,n,a;
  int res=0;
  cin>>n;
  while(i<n && cin>>a){
    count[a]++;
    count[a-1]++;
    count[a+1]++;
    i++;
  }
  for(int i=0; i<N; i++)
    if(res<count[i]) res=count[i];

  cout<<res<<endl;
  return 0;
}
    


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    string s; cin>>s;
    int n=s.size();
    bool flg=1;
    int flgc=0,cnt=0;
    for(int i=0;i<n;i++){
        if('a'<=s[i]&&s[i]<='z') cnt++;
        if(i==0&&s[i]!='A') flg=0;
        if(2<=i&&i<=n-2){
            if(s[i]=='C') flgc++;
        }
    }
    if(cnt==n-2&&flgc==1&&flg) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    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;
using P = pair<int,int>;

int main(){
    int k;
    cin>>k;
    ll cnt=0;
    rep(i,k){
        cnt*=10;
        cnt+=7;
        if(cnt%k==0){
            cout<<i+1<<endl;
            return 0;
        }
        cnt%=k;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pi acos(-1.0)
#define is_palindrome(str) equal(str.begin(),str.begin() + str.size()/2, str.rbegin())

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     string s,t;
     cin>>s>>t;
     cout<<t<<s<<endl;
    
    return  0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[200];
int main(){
	int k,l;scanf("%d%s",&k,s),l=strlen(s);
	if(l>k)s[k]=s[k+1]=s[k+2]='.',s[k+3]=0;
	puts(s);
	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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


bool check(char c){
  string left = "qazwsxedcrfvtgb";
  string right = "yhnujmiklop";
  for(int i = 0; i < left.size(); i++){
    if(left[i] == c)return true;
  }
  return false;
}

int main(){
  string s;
  while(cin >> s, s != "#"){
    int cnt = 0;
    bool flag = check(s[0]);
    for(int i = 1; i < s.size(); i++){
      bool f = check(s[i]);
      if(flag != f)cnt++;
      flag = f;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 3024
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

const ll INF = 100000000000000000;
int main() {
  int n,m,r; in(n),in(m),in(r);
  vector<int> R(r);
  loop(i,0,r) in(R[i]),R[i]--;
  ll G[n][n];
  loop(i,0,n) loop(j,0,n) {
    if (i==j) G[i][j] = 0;
    else G[i][j] = INF;
  }
  loop(i,0,m) {
    int u, v; ll d; in(u),in(v),in(d);
    u--;v--;
    G[u][v] = G[v][u] = d;
  }
  
  loop(k,0,n) {
    loop(i,0,n) {
      loop(j,0,n) {
        if (i==k or k==j) continue;
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  
  sort(R.begin(), R.end());
  ll ans = INF;
  do {
    ll sum = 0;
    loop(i,0,r-1) {
      int a = R[i];
      int b = R[i+1];
      sum += G[a][b];
    }
    ans = min(ans, sum);
  } while (next_permutation(R.begin(), R.end()));
  print(ans);
  return 0;
}


Measured memory_bytes: 3904
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

namespace Nanshou
{
	typedef long long ll;
	const int N=105;
	const double eps=1e-9;
	const double pi=acos(-1.0);

	struct point
	{
		ll x,y;
		int id;

		point (ll a=0,ll b=0,int c=0)
		{
			x=a,y=b;
			id=c;
		}
	};

	bool operator < (point A,point B){return A.x<B.x;}
	point operator - (point A,point B){return point(A.x-B.x,A.y-B.y);}

	ll cross(point A,point B)
	{
		return A.x*B.y-A.y*B.x;
	}

	point s[N];
	double ans[N];

	int n,m;

	point t[N*2];
	point T[N*2];

	int M;

	void insert(point A)
	{
		while(m>1)
		{
			point B=t[m],C=t[m-1];

			if(cross(A-C,B-C)>=0)m--;
			else break;
		}
		t[++m]=A;
	}
	void Insert(point A)
	{
		while(M>1)
		{
			point B=T[M],C=T[M-1];

			if(cross(A-C,B-C)>=0)M--;
			else break;
		}
		T[++M]=A;
	}

	void calc_hull()
	{
		M=m=0;
		for(int i=1;i<=n;i++)
			insert(s[i]);

		for(int i=n;i;i--)
			Insert(s[i]);

		for(int i=2;i<=M;i++)
			t[++m]=T[i];
	}

	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%lld%lld",&s[i].x,&s[i].y),s[i].id=i;
		std::sort(s+1,s+n+1);
	}

	double fuck(point A)
	{
		return atan2(A.y,A.x);
	}

	void getans()
	{
		t[m+1]=t[2];

		for(int i=2;i<=m;i++)
		{
			double x=fuck(t[i]-t[i-1]),y=fuck(t[i+1]-t[i]);
	
			y-=x;
			while(y<0)y+=pi;

			ans[t[i].id]=y/pi/2;
		}
	}

	void solve()
	{
		initialize();

//		if(n==2)
//		{
//			printf("0.5\n0.5\n");
//			return;
//		}

		calc_hull();

		if(m==3)
		{
			ans[t[1].id]=0.5;
			ans[t[2].id]=0.5;
		}
		else getans();

		for(int i=1;i<=n;i++)
			printf("%.15lf\n",ans[i]);
	}
	
}

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


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		boolean flag = (n % 2 == 0);
		if(flag){
			flag = s.equals(s.substring(n / 2) + s.substring(n / 2));
		}
		System.out.println(flag ? "Yes" : "No");
	}
}


Measured memory_bytes: 23508
#include <iostream>
//#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL a;
    LL b;
    LL c;
    LL d;
    cin >> a >> b >> c >> d;
    LL ans=min(a,b)+min(c,d);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main()
{
    int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;
    if (N < K || N == K)
    {
        cout << N * X << endl;
    }
    else if (N > K)
    {
        cout << K * X + (N - K) * Y << endl;
    }
}

Measured memory_bytes: 256
N, K = map(int, input().split())

P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(len(P)):
    P[i] -= 1

ans = float("-inf")
for i in range(N):
    cycle = []
    pos = i
    total = 0
    while True:
        pos = P[pos]
        cycle.append(C[pos])
        total += C[pos]
        if pos == i: break

    l = len(cycle)
    t = 0
    for j in range(l):
        t += cycle[j]
        if j + 1 > K: break
        now = t

        if total > 0:
            cnt = (K-j-1) // l
            now += total * cnt
        ans = max(ans, now)
print(ans)             

Measured memory_bytes: 81188
ls = list(map(int,input().split()))
q = int(input())
a = [[ls[1],ls[2]],[ls[2],ls[4]],[ls[4],ls[3]],[ls[3],ls[1]]]
b = [[ls[5],ls[2]],[ls[3],ls[5]],[ls[0],ls[3]],[ls[2],ls[0]]]
c = [[ls[5],ls[4]],[ls[1],ls[5]],[ls[0],ls[1]],[ls[4],ls[0]]]
d = [[ls[5],ls[1]],[ls[4],ls[5]],[ls[0],ls[4]],[ls[1],ls[0]]]
e = [[ls[2],ls[5]],[ls[0],ls[2]],[ls[3],ls[0]],[ls[5],ls[3]]]
f = [[ls[2],ls[1]],[ls[4],ls[2]],[ls[3],ls[4]],[ls[1],ls[3]]]
for i in range(q):
    K = list(map(int,input().split()))
    if K in  a:
        print(ls[0])
    elif K in b:
        print(ls[1])
    elif K in c:
        print(ls[2])
    elif K in d:
        print(ls[3])
    elif K in e:
        print(ls[4])
    elif K in f:
        print(ls[5])


Measured memory_bytes: 5612
import java.text.CollationElementIterator;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;
	static int[][] puyo;
	static int H;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {

			H = sc.nextInt();

			if (H == 0) {
				break;
			}

			puyo = new int[H][5];

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < 5; j++) {
					puyo[i][j] = sc.nextInt();
				}
			}
			ans = 0;
			int tmpAns = -1;
			while (ans != tmpAns) {
				tmpAns = ans;
				// 各行を見る
				for (int i = 0; i < H; i++) {

					// それぞれの開始列
					for (int j = 0; j <= 2; j++) {
						if (puyo[i][j] == 0) {
							continue;
						}
						int samePuyos = 1;
						// 後の数字と比べる
						for (int k = j + 1; k < 5; k++) {
							if (puyo[i][j] == puyo[i][k]) {
								samePuyos++;
							}
							if (puyo[i][j] != puyo[i][k] || k == 4) {
								if (samePuyos > 2) {
									ans += puyo[i][j] * samePuyos;
									for (int l = j; l < j + samePuyos; l++) {
										// 消えたぷよを0にする
										puyo[i][l] = 0;
									}
								}
								break;
							}
						}
					}
				}
				puyoFall();
			}

			System.out.println(ans);
		}

	}

	static void puyoFall() {
		for (int k = 0; k < H; k++) {
			for (int i = H - 1; i > 0; i--) {
				for (int j = 0; j < 5; j++) {
					if (puyo[i][j] == 0) {
						puyo[i][j] = puyo[i - 1][j];
						puyo[i - 1][j] = 0;
					}
				}
			}
		}
	}

	static int getNum(List<Integer> column, int idx, int count) {
		if (column.get(count) != 0) {
			idx--;
		}

		if (idx == -1 || column.get(count) == -1) {
			return column.get(count);
		}
		count++;
		return getNum(column, idx, count);
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}



Measured memory_bytes: 56956
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanear := bufio.NewScanner(os.Stdin)

	var x1, x2, x3, x4, x5 int
	var err error

	scanear.Split(bufio.ScanWords)

	//標準入力を取得
	scanear.Scan()
	x1, err = strconv.Atoi(scanear.Text())
	if err != nil {
		panic(err)
	}

	scanear.Scan()
	x2, err = strconv.Atoi(scanear.Text())
	if err != nil {
		panic(err)
	}

	scanear.Scan()
	x3, err = strconv.Atoi(scanear.Text())
	if err != nil {
		panic(err)
	}

	scanear.Scan()
	x4, err = strconv.Atoi(scanear.Text())
	if err != nil {
		panic(err)
	}

	scanear.Scan()
	x5, err = strconv.Atoi(scanear.Text())
	if err != nil {
		panic(err)
	}

	if x1 == 0 {
		fmt.Println(1)
	} else if x2 == 0 {
		fmt.Println(2)
	} else if x3 == 0 {
		fmt.Println(3)
	} else if x4 == 0 {
		fmt.Println(4)
	} else if x5 == 0 {
		fmt.Println(5)
	}

	os.Exit(0)
}


Measured memory_bytes: 1772
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
#include<unordered_map>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(int i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding Space*/
map<char,int> m;
int main(){
  string s; cin >> s;
  ll ans = 0;
  int ss = s.size();
  rep(i,ss){
    char c = s[i];
    ans += i - m[c];
    m[c]++;
  }
  cout << ans + 1<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
int ans;
void Main(){
    int N = read();
    vector<int> X(N), Y(N);
    for (int i = 0; i<N; i++) {
        X[i] = read();
        Y[i] = read();
    }
    map<pair<int, int>, int> M;
    for (int i = 0; i<N-1; i++) {
        for (int j = i+1; j<N; j++) {
            M[make_pair(X[i]-X[j], Y[i]-Y[j])]++;
        }
    }
    M[make_pair(0, 0)] = 0;
    for (auto& m:M) {
        ans = max(ans, m.second+M[make_pair(-m.first.first, -m.first.second)]);
    }
    ans = N-ans;
    ans = max(1, ans);
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 384
<?php
$x = explode(" ",trim(fgets(STDIN)));
$t=0;
 for($i=1;$t<$x[0];$i++){
   $t+=$i;
 }
while(true){

if( $t-$x[0] == $t+$i-$x[1]){
 $ans = $t-$x[0];
  echo $ans;
  exit;
}else{
$t+=$i;
$i++;
}
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string alp = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> ll gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(ll H, ll W, ll h, ll w){return 0 <= h && h < H && 0 <= w && w < W;}

map<long long, long long> p_fact(long long n){
    map<long long, long long> h;
    long long div = 2;
    while(div * div <= n){
        if (n % div == 0){
            h[div]++;
            n /= div;
            div = 1;
        }
        div++;
    }
    if (n != 1) h[n]++;
    return h;
}

int main(){
    ll N; cin >> N;
    ll ans = 0;
    map<ll, ll> p = p_fact(N);
    for(auto e : p){
        for(ll i = 1; i < 100; i++){
            if (e.second < (i + 2) * (i + 1) / 2){
                ans += i;
                break;
            }
        }
    }
    pt(ans);
}

Measured memory_bytes: 3636
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  static String result = "";
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String s1 = sc.next();
    lcs(s1, s);
    StringBuilder sb = new StringBuilder(result);
      System.out.println(sb.reverse());
  }

  public static void lcs(String s1, String s) {
    int lcs[][] = new int[s.length() + 1][s1.length() + 1];
    for (int i = 0; i < s.length() + 1; i++)
      for (int j = 0; j < s1.length() + 1; j++) {
        if (i == 0 || j == 0)
          lcs[i][j] = 0;
        else if (s.charAt(i - 1) == s1.charAt(j - 1)) {
          lcs[i][j] = lcs[i - 1][j - 1] + 1;
        } else
          lcs[i][j] = Math.max(lcs[i - 1][j], lcs[i][j - 1]);

      }
    int i = s.length() , j = s1.length() ;
//      System.out.println(s.length() + " " + s1.length());
        while (i > 0 && j > 0){
        
            if (s.charAt(i - 1) == s1.charAt(j - 1)){
                i--;
                j--;
                result += s.charAt(i);
            } else if (lcs[i - 1][j] > lcs[i][j - 1]){
                i--;
            } else
                j--;
        }
//    System.out.println(lcs[s.length()][s1.length()]);
  }
}



Measured memory_bytes: 103632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] price = { 1, 5, 10, 50, 100, 500 };
	static int ans;
	static int[] N = new int[6];

	public static void main(String[] args) throws Exception {
		while (true) {
			int P = sc.nextInt();
			if (P == 0) break;
			ans = Integer.MAX_VALUE;
			int sum = 0;
			for (int i = 0; i < 6; ++i) {
				N[i] = sc.nextInt();
				sum += N[i] * price[i];
			}
			for (int i = P; i <= sum; ++i) {
				int give = give(i);
				if (give == -1) continue;
				ans = Math.min(ans, give + take(i - P));
			}
			System.out.println(ans);
		}
	}

	static int give(int p) {
		int c = 0;
		for (int i = 5; i >= 0; --i) {
			int max = p / price[i];
			if (max > N[i]) {
				p -= N[i] * price[i];
				c += N[i];
			} else {
				p -= max * price[i];
				c += max;
			}
		}
		return p != 0 ? -1 : c;
	}

	static int take(int p) {
		int c = 0;
		for (int i = 5; i >= 0; --i) {
			int coin = p / price[i];
			p -= coin * price[i];
			c += coin;
		}
		return c;
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int P[N];
  for (int i = 0; i < N; i++)
    cin >> P[i];
  int ans1 = 0;
  int ans2 = 0;
  int ans3 = 0;
  for (int i = 0; i < N; i++)
  {
    if (P[i] <= A)
      ans1++;
    else if (P[i] <= B)
      ans2++;
    else
      ans3++;
  }
  cout << min(min(ans1, ans2), ans3) << endl;
  return 0;
}

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

int main() {
  char a,b;
  cin >> a >> b;
  if (a==b) cout << '=' << endl;
  else if (a=='A') cout << '<' << endl;
  else if (b=='A') cout << '>' << endl;
  else if (a=='B') cout << '<' << endl;
  else if (b=='B') cout << '>' << endl;
  else if (a=='C') cout << '<' << endl;
  else if (b=='C') cout << '>' << endl;
  else if (a=='D') cout << '<' << endl;
  else if (b=='D') cout << '>' << endl;
  else if (a=='E') cout << '<' << endl;
  else if (b=='E') cout << '>' << endl;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

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

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
  int n;
  cin >> n;
  int b = 380000;
  double ans = 0;
  rep (i, n) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") {
      ans += x;
    } else {
      ans += x * b;
    }
  }

  // cout << ans << endl;
  printf("%.10f\n", ans);

  return 0;
}

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


int main() {
    string s;
    cin>>s;
    int c=0;
    for(int i=65;i<=90;i++){
        for(int j=0;j<4;j++){
            if(s[j]==i){
                c++;
                break;
            }
        }
        if(c>2)
            break;
    }
    if(c==2)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <bits/stdc++.h>
#define PI acos(-1)
#define fs first
#define sc second
#define debug freopen("1.in","r",stdin),freopen("1.out","w",stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll maxn = 1e6 + 10;
const ll mod = 998244353;

int n, arr[maxn];
ll ans = 1;
ll mul(ll x,ll y,ll z)
{
    ll sm = x / z * y;
    return ( x * y - sm * z + z ) % z;
}
ll qpow(ll m, ll k, ll p){
    ll res = 1 % p;
    while (k){
        if (k&1) res = res * m % p;
        m = m * m % p;
        k >>= 1;
    }
    return res;
}

int main(){
    ios;
    cin >> n;
    cin >> arr[1];
    if (arr[1] != 0){
        cout << 0;
        return 0;
    }
    for (int i = 2; i <= n; i ++){
        cin >> arr[i];
        if (arr[i] == 0){
            cout << 0;
            return 0;
        }
    }
    sort(arr + 1, arr + 1 + n);
    ll tmp = 1, tmpp = 1;
    for (int i = 2 ; i <= n; i ++){
        if (arr[i] - arr[i - 1] != 1 && arr[i] - arr[i - 1] != 0){
            cout << 0;
            return 0;
        }
        if (arr[i] == arr[i + 1])
            tmpp ++;
        else{
            ans = mul(ans, qpow(tmp, tmpp, mod), mod);
            tmp = tmpp;
            tmpp = 1;
        }
    }
    cout << ans;

    return 0;
}

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> h(n + 1, 0);
    vector<int> dp(n+1,0);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    dp[2] = abs(h[1]-h[2]);
    for (int i = 3; i <= n; i++) {
        int ans = INT_MAX;
        for (int j = max(1, i-k); j < i; j++) {
            ans = min(ans, dp[j] + abs(h[j]-h[i]));
        }
        dp[i] = ans;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 100010;
int n, a[maxn], b[maxn], c[maxn], dp[maxn][4];
int main()
{
    read(n);
    rep(i, 1, n) read(a[i]), read(b[i]), read(c[i]);
    dp[1][1] = a[1], dp[1][2] = b[1], dp[1][3] = c[1];
    rep(i, 1, n - 1) {
        dp[i + 1][1] = max(dp[i][2], dp[i][3]) + a[i + 1];
        dp[i + 1][2] = max(dp[i][1], dp[i][3]) + b[i + 1];
        dp[i + 1][3] = max(dp[i][1], dp[i][2]) + c[i + 1];
    }
    printf("%d\n", max(dp[n][1], max(dp[n][2], dp[n][3])));
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int32_t;
using Uint = uint32_t;
constexpr long long int mod = 1e9 + 7;


int main() {

	Int N; cin >> N;
	vector<Int> P(N), Q(N);
	rep(i, N)cin >> P[i];
	rep(i, N)cin >> Q[i];
	
	Int a = 0, b = 0;
	Int cnt = 0;
	vector<Int> v(N);
	rep(i, N)v[i] = i + 1;

	do {

		cnt++;

		bool flag_p = true;
		rep(i, N) {
			if (v[i] != P[i]) {
				flag_p = false;
				break;
			}
		}

		bool flag_q = true;

		rep(i, N) {
			if (v[i] != Q[i]) {
				flag_q = false;
				break;
			}
		}

		if (flag_p) {
			a = cnt;
		}

		if (flag_q) {
			b = cnt;
		}

	} while (next_permutation(v.begin(), v.end()));

	cout << abs(a - b) << endl;

}

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


int main() {
	string s, t, u;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	cin >> u;
	if (u == s) {
		a--;
	}
	if (u == t) {
		b--;
	}
	cout << a << " " << b;
	
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
//#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll x;
  cin >> x;
  
  rep2(a, 0, 120) rep2(b, -120, a) if(a*a*a*a*a - b*b*b*b*b == x) {
    cout << a << " " << b << newl;
    return 0;
  }
  return 0;
}

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

typedef long long ll;

int main(void){
    int n;
    cin>>n;
    ll sum = 0, rem = INF;
    bool all_same = true;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        sum += a;
        if(a!=b) all_same = false;
        if(a>b) rem = min(rem,b);
    }
    if(all_same){
        cout<<0<<endl;
    }else{
        cout<<sum-rem<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#include <cassert>
using namespace std;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
  vector.erase(vector.begin() + index);
}

int main() {
  int N, M, tmpA, tmpB, tmpC;
  cin >> N >> M;
  
  vector<int> A;
  for (int i=0; i<N; i++) {
    cin >> tmpA;
    A.push_back(tmpA);
  }
  
  vector<int> B, C, E;
  std::sort(A.begin(), A.end()); // 1, 2, 3...
  
  for (int j=0; j<M;  j++) {
    cin >> tmpB >> tmpC;
    B.push_back(tmpB);
    E.push_back(tmpC);
    C.push_back(tmpC);
  }
  
  // 配列のインデックス indiecs = {0, 1, 2, 3, 4} を作成する。
  std::vector<size_t> indices(C.size());
  std::iota(indices.begin(), indices.end(), 0);
  
  // ソートする。
  std::sort(indices.begin(), indices.end(), [&E](size_t i1, size_t i2) {
    return E[i1] < E[i2];
  });
  
  vector<int> D;
  
  for (int j=0; j<M;  j++) {
    //std::vector<int>::iterator iter = std::max_element(C.begin(), C.end());
    //size_t id = std::distance(C.begin(), iter);
    int id = indices[M-1-j];
    
    for (int i=0; i<B[id]; i++) {
      D.push_back(C[id]); // 最大のものを
    }
    if(D.size()>=N) break;

//    remove(C, id);
//    remove(B, id);
  }
  
  long long ans = 0;
  int i=0;
  for (; i<N; i++) {
    if(A[i]<D[i]) ans += D[i];
    else {
      ans += A[i];
      i++;
      break;
    }
  }
  for (; i<N; i++) {
    ans += A[i];
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
 
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()

using ll = long long int;
using i64 = long long int;
template <typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template <typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl;
  err(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1, T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline ostream &operator << (ostream & os,const vector<T>& v) {
  bool first = true;
  os << "[";
  for(unsigned int i = 0; i < v.size(); i++) {
    if(!first) os << ", ";
    os << v[i];
    first = false;
  }
  return os << "]";
}
template<typename T>
inline ostream &operator << (ostream & os,const set<T>& v) {
  bool first = true;
  os << "{";
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
inline ostream &operator << (ostream & os,const multiset<int>& v) {
  bool first = true;
  os << "{";
  for (auto x: v) {
    if(!first) os << ", ";
    os << x;
    first = false;
  }
  return os << "}";
}
template<typename T1, typename T2>
inline ostream &operator << (ostream & os,const map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii ;
    first = false;
  }
  return os << "}";
}
template<typename T>
ostream &operator << (ostream & os,const vector<vector<T>>& v) {
  for (auto &u: v) os << '\n' << u;
  return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/

i64 f(i64 x) {
  if (x <= 0LL) return 0LL;
  i64 ans = 0;
  for (int i = 0; i < 60; ++i) {
    i64 ones = (x / (1LL << (i + 1)) * (1LL << i));
    ones = ones + max(0LL, x % (1LL << (i + 1)) - (1LL << i) + 1);
    if (ones & 1) ans += (1LL << i);
  }
  return ans;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  i64 a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

signed main() {
  int a,b,k;
  cin >> a >> b >> k;
  if (a > k) a -= k;
  else {
    k -= a;
    a = 0;
    b = max(b-k, 0LL);
  }
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<(n);(i)++)


void Main()
{
	int X,Y;
  	cin >> X >> Y;
  	int ans = 0;
  	
  
  	switch(X){
    case 1: 
      ans += 300000; 
      break; 
    case 2: 
      ans += 200000; 
      break;
    case 3:	
      ans += 100000; 
      break;
    default: ;
  	}
  
	switch(Y){
    case 1: 
        ans += 300000; 
        break;
    case 2: 
        ans += 200000; 
        break;
    case 3:	
        ans += 100000; 
        break;
    default: ;
    }
  
  	if ( (X == 1) && (Y == 1) ){
    	ans += 400000;	
    }
  cout << ans << endl;
  return;
}

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

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


int main() {

    int64_t h,w,k;
    cin>>h>>w>>k;

    vector<vector<char>> c(h, vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c.at(i).at(j);
        }
    }

    int64_t result=0;
    for (int i = 0; i < (1 << h); i++) {
        bitset<6> s_h(i);
        for (int j = 0; j < (1 << w); j++){
            bitset<6> s_w(j);

            int64_t cnt=0;
            for(int k=0;k<h;k++){
                for(int l=0;l<w;l++){
                    if(s_h.test(k)==false&&s_w.test(l)==false){
                        if(c.at(k).at(l)=='#')
                            cnt++;
                    }
                }
            }
            if(cnt==k)
                result++;
        }
  }

    cout<<result<<endl;

	return 0;
}

Measured memory_bytes: 3632
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-29(Wed)
   note   
**********************************************************************/

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(a*n, b);
  cout << ans << endl;
}


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

void dfs(int node, vector<int> adj[], int dp[], int vis[]) 
{ 
	// Mark as visited 
	vis[node] = 1; 

	// Traverse for all its children 
	for (int i = 0; i < adj[node].size(); i++) { 

		// If not visited 
		if (!vis[adj[node][i]]) 
			dfs(adj[node][i], adj, dp, vis); 

		// Store the max of the paths 
		dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
	} 
} 

int main()
{
    int n;
    cin>>n;
    
    vector<int> adj[n];
    
    int e;
    cin>>e;
    
    int a,b;
    for(int i=0;i<e;i++)
    {
        cin>>a>>b;
        adj[a-1].push_back(b-1);
    }
    
    int dp[n]={0};
    int v[n]={0};
    
    for(int i=0;i<n;i++)
    {
        if(v[i]==0)
        {
            dfs(i,adj,dp,v);
        }
    }
   
    int m=0;
    for(int i=0;i<n;i++){
        m=max(m,dp[i]);}//cout<<dp[i]<<" ";
cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 9856
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a: usize = sc.read();
    println!("{}", a + a * a + a * a * a);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2080
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
int h,w,n,a,g[105][105],d[4][2]={-1,0,0,1,1,0,0,-1};
queue<int> q;
void dfs(int i,int j,int di){
	g[i][j]=q.front(),q.pop();
	int ti=i+d[di][0],tj=j+d[di][1];
	if(ti>=h||ti<0||tj>=w||tj<0||g[ti][tj]) di=(di+1)%4,ti=i+d[di][0],tj=j+d[di][1];
	if(!g[ti][tj]) dfs(ti,tj,di);
}
int main(){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		while(a--) q.emplace(i);
	}
	dfs(0,0,1);
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) printf("%d%c",g[i][j],j==w-1?'\n':' ');
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int m = 0;
  int s = 0;
  for (int i = 0; i < N; ++i) {
    int p;
    cin >> p;
    s += p;
    m = max(m, p);
  }
  s -= m / 2;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define ll long long 
#define pb push_back
int main(){	
	fast;
		string s; cin>>s;
		ll ca=0,cb=0;
		for(ll i=0;i<3;i++){
			if(s[i]=='A') ca++;
			else cb++;
			}
		if(ca>0 && cb>0) cout<<"Yes";
		else cout<<"No";
		}
		
		
	
	

	
	
	
		

Measured memory_bytes: 256
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


n = gi

puts 1000 - (n%1000==0 ? 1000: n%1000)


Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

ll f(ll n) {
    ll ans = 0;
    reps(x, 1, n + 1) {
        reps(y, 1, n + 1) {
            if ((x * x + y * y + 1 + x * y + y + x) > n) {
                break;
            }
            reps(z, 1, n + 1) {
                ll v = x * x + y * y + z * z + x * y + y * z + z * x;
                if (v == n) {
                    ans++;
                    break;
                }
                else if (v > n) {
                    break;
                }
            }
        }
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    reps(i, 1, n + 1) {
        cout << f(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 4;

void solve() {
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < m; ++i){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = n-sum;
    if(sum > n) ans = -1;
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 11100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    res = accumulate(a.begin(),a.end(),0LL) - N;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))

a = list(itertools.accumulate(a))
b = reversed(list(itertools.accumulate(reversed(b))))
c = map(sum, zip(a, b))
print(max(c))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int cnt=0;
    int a,b;
    rep(i,n){
        if(cnt==0&&s[i]=='A'){
            a=i; cnt++;
        }
        if(s[i]=='Z'){
            b=i;
        }
    }
    cout<<b-a+1<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, P[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> P[i];

    int ans = 0;
    rep(a, 1, N + 1) {
        int cnt = 0;
        rep(i, 0, N) if (a <= P[i]) cnt++;
        if (a <= cnt) ans = a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3212