akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll  N,K;
    cin >> N >> K ;
    
    ll ans = 0;
    rep(i, N){
        ll inp; cin >> inp;
        if(inp >= K) ans ++;
    }

    cout << ans << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h = {0};
    for (auto i = 1, t=0; i != n + 1; ++i)
    {
        cin >> t;
        h.push_back(t);
    }
    vector<int> cost = {0, 0};

    for (auto i = 2; i != n + 1; ++i)
    {
        auto temp = 0x7fffffff;
        for (auto j = min(k, i-1); j > 0; --j)
            temp = min(temp, cost[i-j]+abs(h[i-j]-h[i]));
        cost.push_back(temp);
    }
    cout << *(cost.rbegin());
    return 0;
}


Measured memory_bytes: 1400
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringJoiner;

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) throws Exception {
		Main main = new Main();
		main.run();
	}

	void run() {
		int n = in.nextInt();
		int[] nums = in.nextIntArray(n);
		int count = 0;
		boolean swapped = true;
		while (swapped) {
			swapped = false;
			for (int i = 0; i < n - 1; i++) {
				if (nums[i] > nums[i + 1]) {
					swapped = true;
					count++;

					int temp = nums[i];
					nums[i] = nums[i + 1];
					nums[i + 1] = temp;
				}
			}
		}
		StringJoiner joiner = new StringJoiner(" ");
		Arrays.stream(nums).mapToObj(String::valueOf).forEach(joiner::add);
		System.out.println(joiner.toString());
		System.out.println(count);
	}
}

class FastReader {
	private InputStream in = System.in;
	private byte[] buf = new byte[1024];
	private int charNum;
	private int charLen;
	private StringBuilder sb = new StringBuilder();

	public int read() {
		if (charLen == -1)
			throw new InputMismatchException();
		if (charNum >= charLen) {
			charNum = 0;
			try {
				charLen = in.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (charLen <= 0)
				return -1;
		}
		return buf[charNum++];
	}

	public String next() {
		int c = read();
		while (isWhitespace(c)) {
			c = read();
		}
		sb.setLength(0);
		do {
			sb.appendCodePoint(c);
			c = read();
		} while (!isWhitespace(c));
		return sb.toString();
	}

	public char[] nextCharArray() {
		return next().toCharArray();
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public int[] nextIntArray(int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++)
			array[i] = nextInt();
		return array;
	}

	public List<Integer> nextIntList(int n) {
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; i++)
			array[i] = nextInt();
		return Arrays.asList(array);
	}

	public int[][] nextIntArray2D(int n, int m) {
		int[][] array = new int[n][m];
		for (int i = 0; i < n; i++)
			array[i] = nextIntArray(m);
		return array;
	}

	public List<int[]> nextIntsList(int n, int m) {
		List<int[]> list = new ArrayList<int[]>(n);
		for (int i = 0; i < n; i++)
			list.add(nextIntArray(m));
		return list;
	}

	public long nextLong() {
		int c = read();
		while (isWhitespace(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isWhitespace(c));
		return res * sgn;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public double[] nextDoubleArray(int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++)
			array[i] = nextDouble();
		return array;
	}

	public boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
}

Measured memory_bytes: 30776
def check(P,k,staffList):
    i = 0
    for _ in range(k):
        staffNum = 0
        while(staffNum + staffList[i]<= P):
            staffNum += staffList[i]
            i += 1
            if i == n:
                return n
    return i


def getMaxP(n,k,staffList):
    # Pが増えれば，入れられる個数は単純増加するので，二部探索によりPの最小値を求められる
    left = 0
    right = 100000*10000
    while right-left>1:
        mid = (left+right)//2
        staffNum = check(mid,k,staffList)
        if staffNum >= n :
            right = mid
        else:
            left = mid

    return right


if __name__ == "__main__":
    n,k = map(int,input().split())
    staffList = [int(input()) for _ in range(n)]

    # 特定の最大積載量でどれだけ積めるのかを計算する
    P = getMaxP(n,k,staffList)

    print(P)


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

int main()
{
	int n;
	double x1,y1,x2,y2,x3,y3,xp,xp1,xp2,yp1,yp2,yp,r;
	scanf("%d",&n);

	for(int x=0;x<n;x++)
	{
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		xp1=(y1-y3)*(y1*y1 -y2*y2 +x1*x1 -x2*x2) -(y1-y2)*(y1*y1 -y3*y3 +x1*x1 -x3*x3);
		xp2=2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3);
		xp=xp1/xp2;
		yp1=(x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2) -(x1-x2)*(x1*x1 -x3*x3 +y1*y1 -y3*y3);
		yp2=2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3);
		yp=yp1/yp2;

		r=(x3-xp)*(x3-xp)+(y3-yp)*(y3-yp);
		r=sqrt(r);
		printf("%.3f %.3f %.3f\n",xp,yp,r);
	}
	return 0;
}

Measured memory_bytes: 1080
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n;
int a[100005],b[100005],c[100005];
long long sum[100005];
int tmp;
long long ans;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
    	scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
    	scanf("%d",&c[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1); 
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(n-(upper_bound(c+1,c+n+1,b[i])-(c+1)));
	}
	b[n+1]=a[n]+3;
	for(int i=1;i<=n;i++){
		tmp=(upper_bound(b+1,b+n+2,a[i])-b);
		if(tmp>n)break;
		else ans+=(sum[n]-sum[tmp-1]);
	}
	cout<<ans;
    return 0;
}

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

using namespace std;

int n;
int arr[200100];

int tmp[200100];
bool ok(int t) {
    int i;
    for (i=0;i<2*n-1;i++) tmp[i] = (arr[i]>=t);
    for (i=0;i<n-1;i++) {
        if (tmp[n-1+i]==tmp[n-1+i+1]) return tmp[n-1+i];
        if (tmp[n-1-i]==tmp[n-1-i-1]) return tmp[n-1-i];
    }
    return tmp[0];
}

int main() {
    int s, e, i;
    scanf("%d",&n);
    for (i=0;i<2*n-1;i++) scanf("%d",&arr[i]);
    s = 1; e = 2*n+1;
    while(s<=e) {
        int m = (s+e)>>1;
        if (ok(m)) s= m+1;
        else e = m-1;
    }
    printf("%d\n",e);
    return 0;
}


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

using namespace std;

int main (){

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif


	cin.tie(0);
	ios::sync_with_stdio(false);

	int a,b;
	cin>>a>>b;

	cout<<a*b<<endl;
		
}

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

#define IN inline
#define CO const
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int N=2e5+10;
int K[N],L[N],R[N];

void real_main(){
	int n=read<int>();
	vector<int> F,G;
	int64 ans=0;
	for(int i=1;i<=n;++i){
		read(K[i]),read(L[i]),read(R[i]);
		ans+=min(L[i],R[i]);
		if(L[i]>R[i]) F.push_back(i);
		else if(L[i]<R[i]) G.push_back(i);
	}
	sort(F.begin(),F.end(),[&](int a,int b)->bool{
		return K[a]<K[b];
	});
	priority_queue<int,vector<int>,greater<int> > heap;
	for(int i:F){
		if((int)heap.size()<K[i]){
			ans+=L[i]-R[i];
			heap.push(L[i]-R[i]);
		}
		else if(heap.size() and heap.top()<L[i]-R[i]){
			ans+=L[i]-R[i]-heap.top();
			heap.pop(),heap.push(L[i]-R[i]);
		}
	}
	sort(G.begin(),G.end(),[&](int a,int b)->bool{
		return n-K[a]<n-K[b];
	});
	while(heap.size()) heap.pop();
	for(int i:G){
		if((int)heap.size()<n-K[i]){
			ans+=R[i]-L[i];
			heap.push(R[i]-L[i]);
		}
		else if(heap.size() and heap.top()<R[i]-L[i]){
			ans+=R[i]-L[i]-heap.top();
			heap.pop(),heap.push(R[i]-L[i]);
		}
	}
	printf("%lld\n",ans);
}
int main(){
	for(int T=read<int>();T--;) real_main();
	return 0;
}


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

int N;


typedef struct{
  int num;
  char s;
}card;



void stable_judge(char **ans,card *A){
  int i;
  int a;
  int number[10]={};
  for(i=0;i<N;i++){
    a=A[i].num;
    if(ans[a][number[a]]!=A[i].s){
      printf("\nNot stable\n");
      break;
    }
    number[a]+=1;
  }
  if(i==N) printf("\nStable\n");
} 
  

int main(){

  int i,j;
  card *bub,*sel;
  char **ans;//正解の並び
  ans=malloc(10*sizeof(char *));
  for(i=0;i<=9;i++) ans[i]=malloc(4*sizeof(char));
  int  number[10]={};//ansのi行に何個数字が入っているかを表す配列
  
  scanf("%d",&N);
  bub=malloc(N*sizeof(card));
  sel=malloc(N*sizeof(card));
  for(i=0;i<N;i++) scanf("%*[^HCDS]%c%d",&bub[i].s,&bub[i].num);//読み飛ばしを行う。
  for(i=0;i<N;i++){
    sel[i].num=bub[i].num;
    sel[i].s=bub[i].s;
  }//入力完了

  
  int a;
  for(i=0;i<N;i++){
    a=bub[i].num;
    ans[a][number[a]]=bub[i].s;
    number[a]+=1;
  }//正解（安定性）を判断するためのans完成

  int b;
  int check;
  char ss;
  for(i=0;i<N-1;i++){
    check=0;
    for(j=N-1;j>=i+1;j--){
      if(bub[j].num < bub[j-1].num){
        b=bub[j].num;
        ss=bub[j].s;
        bub[j].num=bub[j-1].num;
        bub[j].s=bub[j-1].s;
        bub[j-1].num=b;
        bub[j-1].s=ss;
        check=1;
      }//スワップ
    }
    if(check==0) break;//交換無しなら終了
  }//バブルソート
  

  int mini;
  for(i=0;i<N-1;i++){
    mini=i;
    for(j=i+1;j<N;j++){
      if(sel[j].num < sel[mini].num) mini=j;
    }
    if(i!=mini){
        b=sel[mini].num;
        ss=sel[mini].s;
        sel[mini].num=sel[i].num;
        sel[mini].s=sel[i].s;
        sel[i].num=b;
        sel[i].s=ss;
    }//スワップ
  }//バブルソート

  printf("%c%d",bub[0].s,bub[0].num);
  for(i=1;i<N;i++) printf(" %c%d",bub[i].s,bub[i].num);
  stable_judge(ans,bub);//バブルソートに関する出力

  printf("%c%d",sel[0].s,sel[0].num);
  for(i=1;i<N;i++) printf(" %c%d",sel[i].s,sel[i].num);
  stable_judge(ans,sel);//選択ソートに関する出力
  
  return 0;
}



//配列の初期化は={}
//文字列は初期化しなくてもokかも？


Measured memory_bytes: 2080
#include <cstdio>
#include <cstring>
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
using namespace std;
int main(){
  bool l, n, b, s;
  char str[512];
  scanf("%s", str);
  l = n = b = s = false;
  if(strlen(str) >= 6) l = true;
  rep(i, strlen(str)){
    if(str[i] >= '0' && str[i] <= '9') n = true;
    else if(str[i] >= 'A' && str[i] <= 'Z') b = true;
    else if(str[i] >= 'a' && str[i] <= 'z') s = true;
  }
  puts(l&&n&&b&&s?"VALID":"INVALID");
  return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int a,b,m,p[N],q[N];
int main() {
	scanf("%d%d%d",&a,&b,&m);
	rep(i,0,a) scanf("%d",p+i);
	rep(i,0,b) scanf("%d",q+i);
	int ans=*min_element(p,p+a)+*min_element(q,q+b);
	rep(i,0,m) {
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		ans=min(ans,p[x-1]+q[y-1]-c);
	}
	printf("%d\n",ans);
}


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

int solve(vector<int >& arr , int N) {
	if (N < 2)return 0;	
	vector<int> DP(N);
	DP[N-1] = 0;
	DP[N - 2] = abs(arr[N - 1] - arr[N - 2]);

	for (int i = N-3; i >=0; i--) {
		int a = DP[i + 1] + abs(arr[i] - arr[i + 1]);
		int b = DP[i + 2] + abs(arr[i] - arr[i + 2]);
		DP[i] = (a>b)?b:a;
	}
	return DP[0];
}

int main()
{
	int N;
	cin >> N;
	vector<int> arr(N);
	for (int i = 0 ; i< N ; i++) {
		cin >> arr[i];
	}
    
	cout << solve(arr , N) << endl;
	return 0 ;
}



Measured memory_bytes: 1024
import math
def main():
    N = int(input())
    d = {}
    zb = 0
    za = 0
    zab = 0
    r = 0
    mod = 10**9 + 7
    for i in range(N):
        a, b = map(int, input().split())
        if a== 0 and b == 0:
            zab += 1
        elif b == 0:
            zb += 1
        elif a == 0:
            za += 1
        else:
            if a < 0:
                a = -a
                b = -b
            x = math.gcd(abs(a), abs(b))
            if (a//x, b//x) in d:
                d[(a//x, b//x)] += 1
            else:
                d[(a//x, b//x)] = 1
    used = set()
    l = []
    for x in d:
        if x in used:
            continue
        a, b = x[0], x[1]
        used.add(x)
        if a * b > 0:
            t = (abs(b), -abs(a))
            if t in d:
                used.add(t)
                l.append((d[x], d[t]))
            else:
                l.append((d[x], 0))
        else:
            t = (abs(b), abs(a))
            if t in d:
                used.add(t)
                l.append((d[x], d[t]))
            else:
                l.append((d[x], 0))
    r = pow(2, za) + pow(2, zb) - 1
    for i in l:
        r *= (pow(2, i[0]) + pow(2, i[1]) - 1)
        r %= mod
    return (r - 1 + zab) % mod
print(main())


Measured memory_bytes: 71980
#include<stdio.h>
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	int angka=1;
	
	for(int i=1;i<=n;i++){
		if(angka+k>angka*2){
			angka=angka*2;
		}
		else{
			angka=angka+k;
		}
	}
	printf("%d\n",angka);
	
	
	return 0;
}

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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    string a, b;
    cin >> a >> b;
    string aS, bS;
    REP(i, stoi(b)) { aS += a; }
    REP(i, stoi(a)) { bS += b; }
    cout << min(aS, bS) << endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
// constexpr ll mod = 1e9+7;
constexpr int mod = 2019;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  // cout << "N:" << N << endl;
  vector<int> cnt(2020, 0);
  int sum = 0;
  int beki = 1;
  ll ans = 0;
  REPR(i, N-1){
    sum = sum +(S[i]-'0')*beki;
    sum %= mod;
    beki *=10;
    beki %=mod;
    ans += cnt[sum];
    cnt[sum]++;
    // cout << S.substr(i, N-i) << " " << sum << endl;
    if(sum == 0){
      ans++;
    }
  }
  cout << ans << endl;
  // cout << 18171 % mod << endl;
  // cout << 81712114LL % mod << endl;
  // cout << 1817181712114LL % mod << endl;
  // cout << 1817100000000LL % mod << endl;
  return 0;
}


Measured memory_bytes: 3748
#include <stdio.h>

int keta(int a){
  int i;
  for(i=0;;i++){
    a=a/10;
    if(a==0)break;
  }
  return i+1;
}

int main(){
  int n,i,sum=0;
  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    if(keta(i)%2==1)sum++;
  }
  printf("%d\n",sum);
}

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

int main() {
  int a , b , c , d  ;
  cin >> a >> b >> c ;
  
  d = a * b ;
  
  if(d < c) {
    cout << d << endl;
  }
  
  if(d == c) {
    cout << d << endl;
  }
  
  if(d > c) {
    cout << c << endl;
  }
  
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
cap=a**2*b
y=((cap-x)*2)/a**2

if y<=b:
      y=((cap-x)*2)/a**2
      theta=math.degrees(math.atan(y/a))
      print(theta)
else:
      y=(2*x)/(a*b)
      theta=math.degrees(math.atan(y/b))
      print(90-theta)

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long				ll;
typedef pair <int, int> ii;
 
/*
struct point{
	ll x;
	ll y;
	point(){x = 0;y = 0;}
	point(ll x, ll y):x(x), y(y){}
};
*/

int dw[] = {0, 1, 0 ,-1};
int dh[] = {1, 0 ,-1, 0};
//テ、ツクツ凝・ツ渉ウテ、ツクツ甘・ツキツヲ

int main() {

	int w, h;
	while(cin >> w >> h, w, h){
		vector<vector<int>> yoko(h ,vector<int>(w+1, 1));
		vector<vector<int>> tate(h+1 ,vector<int>(w, 1));
		
		rep(i, 2*h-1){
			if(i%2==0){
				rep(j, w-1) cin >> yoko[(int)(i/2)][j+1];
			}
			else{
				rep(j, w) cin >> tate[(int)(i/2)+1][j];
			}
		}
		
		/*
		rep(i, yoko.size()){
			rep(j, yoko[i].size()) cout << yoko[i][j]<<"\t";
			cout << endl;
		}
		cout << endl;
		rep(i, tate.size()){
			rep(j, tate[i].size()) cout << tate[i][j]<<"\t";
			cout << endl;
		}
		*/
		
		queue<pair<ii, int>> qu;
		qu.push(make_pair(make_pair(0, 0), 0)); // h, w
		
		vector<vector<bool>> used(h, vector<bool>(w));
		
		int ans = 0;
		
		while(!qu.empty()){
			pair<ii, int> tmp = qu.front();
			qu.pop();
			
			int hh = tmp.first.first;
			int ww = tmp.first.second;
			
			if(used[hh][ww]) continue;
			used[hh][ww] = true;
			if(hh == h-1 && ww == w-1){
				ans = tmp.second + 1;
				break;
			}
			
			if(yoko[hh][ww] == 0) qu.push(make_pair(make_pair(hh, ww-1), tmp.second + 1));
			if(yoko[hh][ww+1] == 0) qu.push(make_pair(make_pair(hh, ww+1), tmp.second + 1));
			if(tate[hh][ww] == 0) qu.push(make_pair(make_pair(hh-1, ww), tmp.second + 1));
			if(tate[hh+1][ww] == 0) qu.push(make_pair(make_pair(hh+1, ww), tmp.second + 1));
		}
		
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i=1,x;
    while (1) {
        scanf("%d",&x);
        if (x == 0) {
            break;
        }else{
            printf("Case %d: %d\n",i,x);
        }i++;
    }
    return 0;
}



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

using namespace std;


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

    int n;
    cin >> n;

    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(n-1);

    for(int &i : A)
        cin >> i;

    for(int &i : B)
        cin >> i;

    for(int &i : C)
        cin >> i;

    int sum = 0;
    for(int i = 0 ; i < A.size(); ++i)
    {
        sum += B[A[i]-1];
        if(i !=0 && A[i] - A[i-1] == 1)
        {
            sum += C[A[i-1]-1];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)
using LL = long long;

const LL LINF = 1e18;

struct Edge {
	int to; LL cost;
	Edge(int t, LL c = 0) : to(t), cost(c) {}

	bool operator>(const Edge& rhs) const {
		return cost > rhs.cost;
	}
	bool operator<(const Edge& rhs) const {
		return cost < rhs.cost;
	}

};
using Graph = vector< vector<Edge> >;
void BellmanFord(const Graph& G, vector<LL>& d, vector<bool>&negative, int s) {
	const int V = G.size();
	d = vector<LL>(V, LINF);

	d[s] = 0;

	for (int lp = 0; lp < V; ++lp) {
		for (int i = 0; i < V; ++i) {
			for (const auto& e : G[i]) {
				if (d[i] == LINF)continue;
				if (d[e.to] > d[i] + e.cost) {
					d[e.to] = d[i] + e.cost;
				}
			}
		}
	}
	negative = vector<bool>(V, false);
	for (int lp = 0; lp < V; ++lp) {
		for (int i = 0; i < V; ++i) {
			for (const auto& e : G[i]) {
				if (d[i] == LINF)continue;
				if (d[e.to] > d[i] + e.cost) {
					d[e.to] = d[i] + e.cost;
					negative[e.to] = true;
				}
				if (negative[i] == true) {
					negative[e.to] = true;
				}
			}
		}
	}
}

int main() {
	LL N, M, P;
	cin >> N >> M >> P;
	Graph G(N);
	vector<vector<LL>>lis(N, vector<LL>(N, 0));

	FOR(i, 0, M) {
		LL a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].emplace_back(b, -c + P);
	}
	vector<LL>d(N);
	vector<bool>negative(N);
	BellmanFord(G, d, negative, 0);

	if (negative.back()) {
		cout << -1 << endl;
	}
	else {
		cout << max(0LL, -d.back()) << endl; // こっち～
	}


}






Measured memory_bytes: 49408
#include<cstdio>
#include<cstring>
int main()
{
	char s[103];
	scanf("%s",s+1);
	int len=strlen(s+1);
	int pd=0;
	for(int i=1;i<=len;i++){
		if(s[i]=='C'){
			for(int j=i+1;j<=len;j++){
				if(s[j]=='F'){
					pd=1;
					break;
				}
			}
			break;
		}
	}
	printf("%s\n",pd?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    ll x = max({a, b, c});
    ll d = a+b+c;

    if(x%2 == d%2) {
        out((3*x - d)/2);
    }
    else {
        out((3*(x+1) - d)/2);
    }
    
    re0;
}

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

int main(void){

  int input;
  int hour;
  int minute;
  int second;

  cin >> input;

  hour = input / 3600;
  minute = (input % 3600) / 60;
  second = (input % 3600) % 60;

  cout << hour << ":" << minute <<":" << second << endl;

  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll N,P;
int main(){
    cin >> N >> P;
    map<ll,int> mp;
    ll num = P;
    for(ll i = 2; i*i <= P; i++){
        while(num % i == 0){
            mp[i]++;
            num /= i;
            // cout << i << " ";
        }
    }
    //cout << endl;
    ll ans = 1;
    if(N == 1){
        cout << P << endl;
        return 0;
    }
    for(ll i = 2; i*i <= P; i++){
        if(mp[i] >= N){
            ans *= pow(i,(mp[i]/N));
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 62720
//Problem:
//Date:
//Skill:

#define CLR(a) memset((a),0,sizeof(a))
#define MAX 2140000000;
#define RE(i,n)  for(i=0;i<n;i++)
#define RE2(i,n) for(i=1;i<=n;i++)
#include<algorithm>
#include<iostream>
#include<time.h>
#include<string.h>

using namespace std;
bool map[11][10010];
int m, n;
int add(int y)
{
	int ans(0);
	for (int i = 1; i <= m; i++)
	{
		ans += map[i][y];
	}
	//cout << max(ans, m - ans) << endl;
	return max(ans, m - ans);

}
void change(int num)
{
	int i,j;
	RE2(i, m)//第1到m位
	{
		if(num&(1<<(i-1)))
			RE2(j, n)
		{
			map[i][j] = !map[i][j];
		}
	}
}
int search()
{
	int ans(0);
	int i, j, k;
	for (i = 0; i < (1 << m); i++)//遍历每一种情况
	{
		int maxnum(0);
		change(i);

		RE2(j, n)
		{
			maxnum+= add(j);
		}
		ans = max(ans, maxnum);

		change(i);
	}
	return ans;
}

//#define LOCAL
int main()
{
#ifdef LOCAL

	freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
	//	freopen("C:\\Users\\VULCAN\\Desktop\\data.out", "w", stdout);
#endif
	//这是一条帅气的分界线，写程序从这里开始吧
	int i, j, k;
	
	while (cin >> m >> n,m)
	{
		RE2(i, m)RE2(j, n)
		{
			cin >> map[i][j];//输入
//			cout << map[i][j];
		}
		int ans=search();
		cout << ans << endl;
	}








	//这是一条可爱的分界线
#ifdef LOCAL
	printf("用时%.3f秒\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}







Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long n,cnt=1000;
    cin >> n;
    long a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n-1;i++){
        long stock=0;
        if(a[i+1]>a[i]) stock = cnt/a[i];
        cnt += (a[i+1]-a[i])*stock;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3496
N, M = map(int, input().split())
bigp = 10**9+7
L = []
p, power = 2, 0
K = M
while p*p <= K:
    while K%p == 0:
        K = K//p
        power += 1
    if power > 0:
        L.append([p, power])
    if p == 2:
        p += 1
    else:
        p += 2
    power = 0
if K > 1:
    L.append([K, 1])


ans = 1
def ModComb(n, r, p):
    N = n%p
    R = r%p
    if N<R:
        return 0
    if N < 2*R:
        R = N-R
    if R == 0:
        return 1
    else:
        return (n*pow(r, p-2, p))%p*ModComb(n-1, r-1, p)


for i in range(len(L)):
    power = L[i][1]
    ans *= ModComb(N+power-1, power, bigp)
    ans %= bigp

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MEMBER 8
#define CLASS 3
#define COLUMN 2
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;

typedef struct {
    int bnum;
    double time;
}member;

void quick_sort(member *p, int left, int right);
int main(void) {
    member x[CLASS][MEMBER];
    member temp[MEMBER];
    member under[6];
    int i, j;
    
    for(i = 0; i < CLASS; i++) {
        for(j = 0; j < MEMBER; j++) {
            scanf("%d %lf", &temp[j].bnum, &temp[j].time);
        }
        quick_sort(temp, 0, MEMBER - 1);

        for(j = 0; j < MEMBER; j++)
            x[i][j] = temp[j];
    }
    
    int count = 0;
    for(i = 0; i < CLASS; i++) {
        for(j = 2; j < 4; j++) {
            under[count++] = x[i][j];
        }
    }
    
    quick_sort(under, 0, 5);
    
    for(i = 0; i < CLASS; i++)
        for(j = 0; j < COLUMN; j++)
            printf("%d %.2f\n", x[i][j].bnum, x[i][j].time);
    for(i = 0; i < 2; i++)
        printf("%d %.2f\n", under[i].bnum, under[i].time);
    
    return(0);
}

void quick_sort(member *p, int left, int right) {
    int i, j;
    double pivot;
    
    i = left;
    j = right;
    pivot = p[(left + right) / 2].time;
    
    while(1) {
        while(p[i].time < pivot) i++;
        while(p[j].time > pivot) j--;
        
        if(i >= j) break;
        
        swap(int, p[i].bnum, p[j].bnum);
        swap(double, p[i].time, p[j].time);
        i++;
        j--;
    }
    if(i - 1 > left) quick_sort(p, left, i - 1);
    if(j + 1 < right) quick_sort(p, j + 1, right);
}

Measured memory_bytes: 1236
N = int(input())
text = input()
result = []
for i in range(N-1):
      counter = 0
      text1 = text[0:i+1]
      text2 = text[i+1:]
      if  "a" in text1:
            if "a" in text2:
                  counter = counter + 1
      if  "b" in text1:
            if "b" in text2:
                  counter = counter + 1
      if  "c" in text1:
            if "c" in text2:
                  counter = counter + 1
      if  "d" in text1:
            if "d" in text2:
                  counter = counter + 1
      if  "e" in text1:
            if "e" in text2:
                  counter = counter + 1
      if  "f" in text1:
            if "f" in text2:
                  counter = counter + 1
      if  "g" in text1:
            if "g" in text2:
                  counter = counter + 1
      if  "h" in text1:
            if "h" in text2:
                  counter = counter + 1
      if  "i" in text1:
            if "i" in text2:
                  counter = counter + 1
      if  "j" in text1:
            if "j" in text2:
                  counter = counter + 1
      if  "k" in text1:
            if "k" in text2:
                  counter = counter + 1
      if  "l" in text1:
            if "l" in text2:
                  counter = counter + 1
      if  "m" in text1:
            if "m" in text2:
                  counter = counter + 1
      if  "n" in text1:
            if "n" in text2:
                  counter = counter + 1
      if  "o" in text1:
            if "o" in text2:
                  counter = counter + 1
      if  "p" in text1:
            if "p" in text2:
                  counter = counter + 1
      if  "q" in text1:
            if "q" in text2:
                  counter = counter + 1
      if  "r" in text1:
            if "r" in text2:
                  counter = counter + 1
      if  "s" in text1:
            if "s" in text2:
                  counter = counter + 1
      if  "t" in text1:
            if "t" in text2:
                  counter = counter + 1
      if  "u" in text1:
            if "u" in text2:
                  counter = counter + 1
      if  "v" in text1:
            if "v" in text2:
                  counter = counter + 1
      if  "w" in text1:
            if "w" in text2:
                  counter = counter + 1
      if  "x" in text1:
            if "x" in text2:
                  counter = counter + 1
      if  "y" in text1:
            if "y" in text2:
                  counter = counter + 1
      if  "z" in text1:
            if "z" in text2:
                      counter = counter + 1
      result = result + [counter]

print(max(result))

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

int main() {
  int n;
  cin >> n;
  
  vector<int> P(n);
  
  for (int i=0;i<n;i++){
    cin >>P.at(i);
  }
  
 int count=0;
  
  for (int i=1;i<n-1;i++){
    vector<int> veci={P.at(i-1),P.at(i),P.at(i+1)};
    sort(veci.begin(), veci.end());
    
    if (veci.at(1)==P.at(i)){
      count++;
    }
  }
  cout << count <<endl;
}

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

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

    int ans=1e9;
    for(int i=-100;i<=100;i++){
        int tmp=i;
        int cost=0;
        for(int j=0;j<N;j++){
            cost+=(tmp-a[j])*(tmp-a[j]);
        }
        ans=min(ans,cost);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace std;
int main(){
	int n;cin>>n;
	int ans=0;
	map<pair<int,pair<int,int> >,int> mp;
	for(int i=0;i<n;i++){
		int p1,p2,p3;cin>>p1>>p2>>p3;
		vector<int> v;
		v.push_back(p1);
		v.push_back(p2);
		v.push_back(p3);
		sort(all(v));
		if(mp.count(make_pair(v[0],make_pair(v[1],v[2])))){
			ans++;
		}else{
			mp[make_pair(v[0],make_pair(v[1],v[2]))]++;
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3212
import java.util.*;
public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
       	int cnt = 0;
        if(a % 10 == 1) cnt++;
      	a /= 10;
      	if(a % 10 == 1) cnt++;
      	a /= 10;
      	if(a % 10 == 1) cnt++;
      	System.out.println(cnt);
	}
}
        
        

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    string s;
    cin>>s;
    string str[4]={"dream","dreamer","erase","eraser"};
    for(int i=s.size()-1;i>=4;i--)
    {
        if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='s'&&s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'&&i>4)
        {
            s.erase(i-5,6);
            i=s.size();
        }
        else if(s[i]=='e'&&s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e')
        {
            s.erase(i-4,5);
            i=s.size();
        }
        else if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='m'&&s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'&&i>5)
        {
            s.erase(i-6,7);
            i=s.size();
        }
        else if(s[i]=='m'&&s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d')
        {
            s.erase(i-4,5);
            i=s.size();
        }
    }
    if(s.size()==0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

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

using namespace std;

typedef long long	ll;
const int N = int(1e5 + 10), M = 13;
ll dp[N][M];
const ll mod = int(1e9) + 7;
string s;
int n;

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

	cin >> s;

	n = s.length();
	reverse(s.begin(), s.end());

	dp[n][0] = 1LL;

	for(int i = n - 1 ; i >= 0 ; i--){
		for(int k = 0 ; k < M ; k++){
			if(s[i] == '?'){
				for(int j = 0 ; j < 10 ; j++){
					dp[i][(k * 10 + j) % 13] += dp[i + 1][k];

					if(dp[i][(k * 10 + j) % 13] >= mod){
						dp[i][(k * 10 + j) % 13] -= mod;
					}
				}
			}else{
				dp[i][(k * 10 + s[i] - '0') % 13] += dp[i + 1][k];

				if(dp[i][(k * 10 + s[i] - '0') % 13] >= mod){
					dp[i][(k * 10 + s[i] - '0') % 13] -= mod;
				}
			}
		}
	}
	
	// memset(dp, -1LL, sizeof dp);
	// printf("%lld\n", solve(n - 1, 0));
	printf("%lld\n", dp[0][5]);

	return 0;
}

Measured memory_bytes: 10704
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 1e5 + 10, M = 1e3 + 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

int main()
{
    string s;
    cin >> s;
    int f1 =0, f2 = 0;
    for(int i = 0; s[i]; i++)
    {
        if(s[i] == 'A')
            f1++;
        else
        {
            f2++;
        }
        
    }
    if(f1 && f2)
        puts("Yes");
    else
    {
        puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 256
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;

ll N, K;
ll p[MAX][70];

int main()
{
    optimiza_io
    cin >> N >> K;
    for( ll i = 1; i <= N; i ++ )
        cin >> p[i][0];
    
    for( ll j = 1; j <= 60LL; j ++ )
        for( ll i = 1; i <= N; i ++ )
            p[i][j] = p[ p[i][j - 1] ][j - 1];
    
    ll ans = 1;
    for( ll j = 60LL; j >= 0; j -- )
        if( ( 1LL << j ) <= K ) {
            K -= ( 1LL << j );
            ans = p[ans][j];
        }
    cout << ans << "\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 113016
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
	heappush(q, -x)
for _ in range(m):
	l = heappop(q)
	heappush(q, -((-l)//2))
print(-sum(q))

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数　
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define INTINF 1000000000
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000  //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

#define N_MAX 100
#define W_MAX 1000000000
#define v_MAX 1000

int main()
{
    int N;
    int A1_sum[N_MAX] = {};
    int A2_sum[N_MAX] = {};
    int rev_A2_sum[N_MAX] = {};
    int sum[N_MAX] = {};
    int tmp;
    int ans = 0;
    int tmpans = 0;

    cin >> N;
    cin >> A1_sum[0];
    for (int i = 1; i < N; i++)
    {
        cin >> tmp;
        A1_sum[i] = A1_sum[i - 1] + tmp;
    }
    cin >> A2_sum[0];

    for (int i = 1; i < N; i++)
    {
        cin >> tmp;
        A2_sum[i] = A2_sum[i - 1] + tmp;
    }

    rev_A2_sum[0] = A2_sum[N - 1];
    for (int i = 1; i < N; i++)
    {
        rev_A2_sum[i] = A2_sum[N - 1] - A2_sum[i - 1];
    }

    for (int i = 0; i < N; i++)
    {
        tmpans = A1_sum[i] + rev_A2_sum[i];
        if (tmpans > ans)
        {
            ans = tmpans;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  string tmp1 = S;
  string tmp2 = S.substr(0, (N-1)/2);
  string tmp3 = S.substr((N+3)/2-1);
  string T = S.substr(0, (N-1)/2);
  string U = S.substr((N+3)/2-1);
  reverse(ALL(S));
  reverse(ALL(T));
  reverse(ALL(U));
  if (S != tmp1) {
    cout << "No" << endl;
    return 0;
  }
  if (T != tmp2) {
    cout << "No" << endl;
    return 0;
  }
  if (U != tmp3) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  string s;
  cin >> s;
  map<char,char> mp;
  mp['A'] = 'T';
  mp['T'] = 'A';
  mp['C'] = 'G';
  mp['G'] = 'C';
  for(auto c : s) {
    cout << mp[c];
  }
  cout << endl;
}


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

using namespace std;
typedef complex<double> P;

bool eq(double d,double e){return abs(d-e)<1e-10;};
bool eqv(P p,P q){return eq(p.real(),q.real()) && eq(p.imag(),q.imag());}

const P nowhere(200,200);
double cross_product(P a, P b) { 
  return (conj(a)*b).imag();
}

P crosspoint(const P& l0, const P& l1,
	     const P& r0, const P& r1) {
    double n = cross_product(r1-r0, r0-l0);
    double d = cross_product(r1-r0, l1-l0);
    return l0 + (l1-l0)*n/d;
}

P ok(P p){
  if(abs(p.real()) > 100-1e-10 || abs(p.imag()) > 100-1e-10)
    return nowhere;
  else
    return p;
}

int n,nl;


int main(){
  while(scanf("%d",&n),n){
    vector<P> ps,qs;
    int ans=1;

    for(int i=0; i<n; i++){
      double x1,y1,x2,y2;
      scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
      ps.push_back(P(x1,y1)); qs.push_back(P(x2,y2));
    }

    for(int i=0; i<n; i++){
      int count=1;
      vector<P> cs;
      for(int j=0; j<i; j++){
	if(eq(cross_product(ps[i]-qs[i],ps[j]-qs[j]),0)) continue;
	P c = crosspoint(ps[i],qs[i],ps[j],qs[j]);
	if(ok(c)==nowhere) continue;

	bool duplicate=false;
	for(int k=0; k<cs.size(); k++)
	  if(eqv(cs[k],c))
	    duplicate=true;
	if(!duplicate){
	  count++;
	  cs.push_back(c);
	}
      }
      ans += count;
    }

    printf("%d\n",ans);
  }
}

Measured memory_bytes: 860
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repr(i,a,b) for(int i=a,i > b;--i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)

#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (ll)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <double, double> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<int> vii;

int main(){
	int n;
	string s1,s2;
	cin>>n>>s1>>s2;
	ll ans=1;
	bool prev=false; // false meaans vertical true means the two on top configuration
	int idx=0;
	if(s1[idx]==s2[idx]){
		ans=3;
		idx+=1;
		prev=false;
	}
	else {
		ans=6;
		idx+=2;
		prev=true;
	}
	while(idx < n){
		if(s1[idx] == s2[idx]){
			if(!prev) {ans*=2;ans%=mod;}
			else {
				prev=false;
			}
			idx++;
		}
		else{
			if(prev){
				ans*=3;ans%=mod;
			}
			else{
				ans*=2;ans%=mod;
			}
			idx+=2;
			prev=true;
		}
	}
	cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    ans = A*B;
    
    if(A-B == 0){
      /* 真の場合の処理 */
      printf("Yes");
    }else{
      /* 偽の場合の処理 */
      printf("No");
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    
    
    /* 出力する部分*/
    
    
    
    return 0;
}






Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int A,a,B,b,C,c,D,d,E,e,ta,tb,tc,td,te;

  while(1){
    scanf("%d %d",&A,&a);
    if(A==0&&a==0) break;
    scanf("%d %d %d %d %d %d %d %d",&B,&b,&C,&c,&D,&d,&E,&e);
  ta=A+a;
  tb=B+b;
  tc=C+c;
  td=D+d;
  te=E+e;
  if(ta>tb&&ta>tc&&ta>td&&ta>te) printf("A %d\n",ta);
  else if(tb>ta&&tb>tc&&tb>td&&tb>te) printf("B %d\n",tb);
  else if(tc>ta&&tc>tb&&tc>td&&tc>te) printf("C %d\n",tc);
  else if(td>ta&&td>tb&&td>tc&&td>te) printf("D %d\n",td);
  else if(te>ta&&te>tb&&te>tc&&te>td) printf("E %d\n",te);
               }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

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

	if(a==1||a==3||a==5||a==7||a==8||a==10||a==12){
		a=1;
	}else if(a==4||a==6||a==9||a==11){
		a=2;
	}else if(a==2){
		a=3;
	}

	if(b==1||b==3||b==5||b==7||b==8||b==10||b==12){
		b=1;
	}else if(b==4||b==6||b==9||b==11){
		b=2;
	}else if(b==2){
		b=3;
	}

	if(a==b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])
A.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
    money = A[i][0] * A[i][1]
    if M <= A[i][1]:
        ans += A[i][0]*M
        break
    ans += money
    M -= A[i][1]
    # print(ans)
print(ans)


Measured memory_bytes: 21224
import java.util.Scanner;

public class Main {

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

        String s = sc.nextLine();

        String[] str = s.split("");
        int top = Integer.parseInt(str[0]);
        int ans = 0;

        for (int i = 0; i < str.length; i++) {
            ans += Integer.parseInt(str[i]);
        }

        if (ans < top - 1 + 9 * (str.length - 1)) {
            ans = top - 1 + 9 * (str.length - 1);
        }

        System.out.println(ans);

    }


}


Measured memory_bytes: 23764
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] l=new int[n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    int sum=0;
    int max=0;
    for(int i=0;i<n;i++){
      sum+=l[i];
      max=Math.max(max,l[i]);
    }
    if(sum>max*2){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
n,k = map(int,input().split())
W = []
for _ in range(n):      W.append(int(input()))

right = sum(W)
left = max(W)-1

while left + 1 < right:
        mid = (left + right) // 2
        cnt = 1
        cur = 0
        for w in W:
                if mid < cur + w:
                        cur = w
                        cnt += 1
                else:
                        cur += w
        if cnt <= k:
                right = mid
        else:
                left = mid
print(right)



Measured memory_bytes: 9556
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();
    if(a >= 3200){
      System.out.print(s);
    }else{
      System.out.print("red");
    }
  }
}


Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b) {
		if (b < c) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void solve(int N, vector<int> A) {
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (A[i] - 1);
  }
  printf("%d\n", ans);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve(N, A);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int F[45];

int fibonacchi(int n){
  int v,u;
    
    if(F[n]!=0){
        return F[n];
    
    }else{
        
    if(n<=1)F[n]=1;
    else{
        
    u=fibonacchi(n-1);
    v=fibonacchi(n-2);
    F[n]=u+v;
        
    }
        
    return F[n];
    }
}

int main(void){
  int n,i;
    
    for(i=0;i<44;i++){
        F[i]=0;
    }
 
  scanf("%d",&n);
  printf("%d\n",fibonacchi(n));
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 0x1fffffffffffffff;
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto& i : a) cin >> i;
    const ll skip = 1 + n % 2; // 取る 取らない 取る 取らない ... を貪欲にやっていくと 1 + n % 2 個余って、 1 + n % 2 回飛ばせることがわかる
    vector<vector<ll>> dp(n + 2, vector<ll>(skip + 1, -INF)); // dp[i][j] := A[0, i) を j 要素無視して1つ飛びに取ったときの最大値
    dp[0][0] = 0;
    for(ll i = 0; i <= n; i++) for(ll j = 0; j <= skip; j++){
        if(j < skip) chmax(dp[i + 1][j + 1], dp[i][j]);
        if(i < n) chmax(dp[i + 2][j], dp[i][j] + a[i]); // 1個選んだら1個選ばないのもセット
    }
    cout << dp[n + 1][skip] << endl; // なので floor(n / 2) * 2 + skip == n + 1 に答えが入る
}

Measured memory_bytes: 15624