akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 200005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],cnt[16],ans;
int b[16],cnt1,sz[maxn],sz2[maxn],dp[maxn];

inline int gs(int sta)
{
	for(int i=1;i<=cnt1;i++) if((sta&(1<<(i-1)))) sz[sta]^=b[i];
}

int main()
{
	int n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read(),w=read();
		a[u]^=w; a[v]^=w;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==0) continue;
		if(cnt[a[i]]) cnt[a[i]]=0,ans++;
		else cnt[a[i]]=1;
	}
	for(int i=1;i<=15;i++) if(cnt[i]) b[++cnt1]=i;
	int ed=(1<<cnt1)-1;
	//for(int i=1;i<=cnt1;i++) cout<<b[i]<<" "; cout<<endl;
	for(int i=1;i<=ed;i++) gs(i),sz2[i]=sz2[i>>1]+(i&1);
	for(int i=1;i<=ed;i++) dp[i]=sz2[i]-1;
	//for(int i=0;i<=ed;i++) cout<<i<<" "<<sz[i]<<" "<<sz2[i]<<endl;
	for(int i=1;i<=ed;i++)
	{
		if(sz[i]!=0) continue;
		for(int j=i;j;j=(j-1)&i)
		{
			if(sz[j]==0) dp[i]=min(dp[i],dp[j]+dp[i^j]);
			//else dp[i]=min(dp[i],sz2[j]+sz2[i^j]+1);
		}
	}
	cout<<dp[ed]+ans<<endl;
	//for(int i=0;i<=ed;i++) cout<<i<<" "<<dp[i]<<endl;
	return 0;
}

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

int main() {
	double A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	double i, j, k, l;

	double ans_water;
	double ans_sugar;

	double ans_p=0;
    
	for (i = 0; 100*i <= F; i++) {
		for (j = 0; 100*j <= F - j; j++) {
			for (k = 0; C*k <= F - 100*i - 100*j; k++) {
				for (l = 0; D*l <= F - 100*i - 100*j - C*k; l++) {

					double water = 100 * A * i + 100 * B * j;
					double sugar = C * k + D * l;
					double sum=water+sugar;
					double p = sugar / sum;

					if (sum <= F && p <= E/(100+E) && ans_p <= p) {
						ans_p = p;
						ans_water = water;
						ans_sugar = sugar;
					}
				}
			}
		}
	}

	cout << int(ans_water + ans_sugar) <<" "<< int(ans_sugar) << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int main() {
	ios::sync_with_stdio(false);
  char c;
  cin >> c;
  if ('a' <= c && c <= 'z') cout << 'a' << endl;
  else cout << 'A' << endl;
}

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

vector<long long int> temp;

void lunlun(long long int a, long long int n) {
    if(a>1e11) return;
    else temp.emplace_back(a);

    if(a%10==0) {
        lunlun(a*10+a%10, n);
        lunlun(a*10+a%10+1, n);
    }
    else if(a%10==9) {
        lunlun(a*10+a%10, n);
        lunlun(a*10+a%10-1, n);
    }
    else {
        lunlun(a*10+a%10-1, n);
        lunlun(a*10+a%10, n);
        lunlun(a*10+a%10+1, n);
    }

}

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

    long long int n; cin>>n;
    for(long long int i=1; i<=n && i<=9; i++) lunlun(i,n);

    sort(temp.begin(), temp.end());
    cout<<temp[n-1];
    //for(int i:temp) cout<<i<<" ";


}


Measured memory_bytes: 10476
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  k = sc.nextInt();
     int  a = sc.nextInt();
     int  b = sc.nextInt();
     int flag=0;
    for( int i=a;i<=b;i++){
      if(i%k==0){
        flag++;
      }
    }
    if(flag>0){
      System.out.println("OK");
    }else{
      System.out.println("NG");
    }
   }
}

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

int main() {
  int N,M;
  cin>>N>>M;
  int64_t L,Q=10000000000;
  cin>>L;
  vector<vector<pair<int,int64_t>>> G(N);
  for(int i=0;i<M;i++){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    if(c<=L){
      G.at(a).push_back(make_pair(b,c));
      G.at(b).push_back(make_pair(a,c));
    }
  }
  vector<vector<int64_t>> r(N,vector<int64_t>(N,Q*300));
  for(int i=0;i<N;i++){
    priority_queue<pair<int64_t,int>,vector<pair<int64_t,int>>,greater<pair<int64_t,int>>> pq;
    pq.push(make_pair(0,i));
    r.at(i).at(i)=0;
    while(!pq.empty()){
      int64_t a;
      int b;
      tie(a,b)=pq.top();
      pq.pop();
      if(r.at(i).at(b)<a){
        continue;
      }
      int64_t k,l;
      k=a/Q,l=a%Q;
      for(auto x:G.at(b)){
        int s;
        int64_t n,Y;
        tie(s,n)=x;
        if(n+l<=L){
          Y=a+n;
        }
        else{
          Y=(k+1)*Q+n; 
        }
        if(Y<r.at(i).at(s)){
            r.at(i).at(s)=Y;
            pq.push(make_pair(Y,s));
          }
      }
    }
  }
  int Z;
  cin>>Z;
  for(int i=0;i<Z;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    if(r.at(a).at(b)/Q==300){
      cout<<"-1"<<endl;
    }
    else{
      cout<<r.at(a).at(b)/Q<<endl;
    }
  }
}

Measured memory_bytes: 7312
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  else if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else if(A+B<C+D){
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            decimal a = Convert.ToDecimal(input[0]);
            decimal b = Convert.ToDecimal(input[1]);

            Console.WriteLine(Math.Ceiling((a + b) / 2));
        }
    }
}


Measured memory_bytes: 11220
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y, x % y);
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}


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

using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(auto &i : s) {
        if(i == '?')continue;
        i -= '0';
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(13));
    dp[0][0] = 1;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= 9; j++) {
            if(!(s[i] == j || s[i] == '?'))continue;
            for(int k = 0; k < 13; k++) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                dp[i + 1][(k * 10 + j) % 13] %= mod;
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 13696
N = gets.to_i
AA = 2.times.map { gets.split.map(&:to_i) }
ans = Array.new(N, 0)
N.times do |i|
  column = 0
  ans[i] = AA[column][i]
  N.times do |j|
    column = 1 if j >= i
    ans[i] += AA[column][j]
  end
end

puts ans.max


Measured memory_bytes: 14280
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int N, ans;
int mp[maxn];

int main(){
    cin >> N;
    ans = 0;
    memset(mp, 0, sizeof(mp));
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        if(tmp > N) ans++;
        else{
            mp[tmp]++;
        }
    }
    for(int i = 0; i <= N; i++){
        if(mp[i] != 0){
            if(mp[i] != i){
                if(mp[i] < i) ans += mp[i];
                else ans += mp[i]-i;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using pii=pair<int, int>;

using Weight =int;
struct Edge {
	int s, d;
	Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) :s(s), d(d), w(w) {};
};
using Array=vector<Weight>;
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void addArc(Graph& g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph& g, int s, int d, Weight w = 1) {
	addArc(g, s, d, w);
	addArc(g, s, d, w);
}
const int INF = 1e7;
//vector<int>dijkstra(const Graph& g, int s, Array& dist) {
//	int n = g.size();
//	enum {WHITE,GRAY,BLACK};
//	assert(s < n);
//	vector<int>color(n, WHITE); color[s] = GRAY;
//	vector<int>prev(n, -1);
//	dist.assign(n, INF); dist[s] = 0;
//	using State=tuple<Weight, int, int>;
//	priority_queue<State, vector<State>, greater<State>>pq; pq.emplace(0, s, -1);
//
//}

void solve(int N, int M) {
	vector<string>c(N);
	rep(i, 0, N) {
		cin >> c[i];
	}
	auto inrange = [&](int x, int y) {return 0 <= x and x < N and 0 <= y and y < M; };
	vector<int>dx = { 0,-1,0,1 }, dy = { 1,0,-1,0 };

	auto check = [&](int x, int y, int dir) {
		int xx = x + dx[dir];
		int yy = y + dy[dir];
		if (not inrange(xx, yy))return false;
		return c[xx][yy] == '.';
	};

	int x = 0, y = 0, dir = 0;
	auto idx = [&](int x, int y) {return x * M + y;
	};
	vector<int>visited;
	while (1) {
		int left = (dir + 1) % 4;
		if (check(x, y, left)) {
			dir = left;
			x += dx[dir];
			y += dy[dir];

		}
		else if (check(x, y, dir)) {
			x += dx[dir];
			y += dy[dir];
		}
		else {
			(dir += 3) %= 4;
		}
		visited.emplace_back(idx(x, y));
		if (x == 0 && y == 0)break;
	}
	if (visited.back() == 0)visited.pop_back();
	int cnt = 0;
	rep(i, 0, visited.size()) {
		int xx = visited[i] / M;
		int yy = visited[i] % M;
		if ((xx == 0 && yy == M - 1) || (xx == N - 1 && yy == 0) || (xx == N - 1 && yy == M - 1)) cnt++;
		for (int j = visited.size() - 1; j > i; j--) {
			if (visited[i] == visited[j]) {
				i = j;
				break;
			}
		}
	}
	if (cnt == 3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

signed main(void) {
	int N, M;
	while (cin >> N >> M, N && M) {
		solve(N, M);
	}
}


Measured memory_bytes: 3220
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  multiset<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    s.insert(a);
  }
  int ans = 0;
  while (!s.empty()) {
    auto x = s.end();
    x--;
    int t = *x;
    s.erase(x);
    int u = 1;
    while (u <= t) u *= 2;
    u -= t;
    auto y = s.find(u);
    if (y == s.end()) continue;
    ans++;
    s.erase(y);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<pair<string,int>>len(n);
	for (int i = 0; i < n; i++)cin >> len.at(i).first >> len.at(i).second;
	string s;
	cin >> s;
	int ans = 0;
	bool x = false;
	for (int i = 0; i < n; i++) {
		if (x == false) {
			if (len.at(i).first == s) x = true;
		}
		else ans += len.at(i).second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3644
from collections import deque
N, K = map(int, input().split())
S = list(input())
d = deque()
p = 0
q = 0
num = 0
i = 0
while i < N:
    if S[i] == '0':
        tmp = 0
        while i < N and S[i] == '0':
            tmp += 1
            i += 1
        d.append(p + tmp)
        q += d[-1]
        last = 0
        if len(d) > K:
            q -= d.popleft()
        num = max(num, q)
    else:
        j = i
        while j < N and S[j] == '1':
            j += 1
        p = j - i
        i = j
        num = max(num, p + q)
print(num)





Measured memory_bytes: 4340
N,X = map(int,input().split())
x = list(map(int,input().split()))

def gcd(n,m):
	if n%m==0:
		return m;
	else:
		return gcd(m,n%m);

ans = abs(x[0]-X)
for i in range(N):
	ans = gcd(ans,abs(x[i]-X))

print(ans)


Measured memory_bytes: 14224
#include <cstdio>
#include <algorithm>

using namespace std;

#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)

const int inf = 1e9;

int d[10][10];
bool found[10];
int N;

void wf()
{
	rep(k, 10) rep(i, 10) rep(j, 10) {
		chmin(d[i][j], d[i][k] + d[j][k]);
	}
}

int main()
{
	while (scanf("%d", &N), N) {
		fill_n(found, 10, false);
		fill(d[0], d[10], inf);
		rep(i, 10) d[i][i] = 0;

		rep(i, N) {
			int a, b, c; scanf("%d %d %d", &a, &b, &c);
			d[a][b] = d[b][a] = c;
			found[a] = found[b] = true;
		}

		wf();

		int mi = inf, a;

		rep(i, 10) if (found[i]) {
			int sum = 0;
			rep(j, 10) if (found[j]) {
				sum += d[i][j];
			}
			if (mi > sum) {
				mi = sum;
				a = i;
			}
		}

		printf("%d %d\n", a, mi);
	}
}

Measured memory_bytes: 1028
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
    int left = 0;
    int right = n;
    int mid;
    while(left < right) {
        mid = (left + right) / 2;
        if( key == A[mid]) return 1;
        if(key > A[mid]) left = mid + 1;
        else if(key < A[mid]) right = mid;
    }
    return 0;
}

int main() {
    int i, q, k, sum = 0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
}


Measured memory_bytes: 2104
import java.util.*;
 
class Main{
    Scanner sc = new Scanner(System.in);
 
    Main(){
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println( (a*b) + " " + (a*2+b*2) );
    }
 
    public static void main(String[] args){
    new Main();
    }
}


Measured memory_bytes: 26108
#include <stdio.h>

int main() {
	int a[100][100] = { 0 };
	int b[100] = { 0 };
	int c[100] = { 0 };
	int n, m;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			c[i] += a[i][j] * b[j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 2708
from collections import deque
N,M = map(int,input().split())
side = [[]for _ in range(N)]
counts = [0]*N
ans = [0]*N

for i in range(N+M-1):
    a,b = map(int,input().split())
    side[a-1].append(b-1)
    counts[b-1]+=1

queue = deque([counts.index(0)])
while queue:
    q = queue.popleft()
    for i in side[q]:
        counts[i] -= 1
        if counts[i] == 0:
            ans[i] = q+1
            queue.append(i)

for i in ans:
    print(i)

Measured memory_bytes: 23840
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;
double dp[3002][3002],p[3010];

int N;
int main(){
  cin >>N;
  REP(i,N){
    cin >>p[i];
  }
  dp[0][0]=1.0;
  FOR(i,0,N){
    FOR(j,0,N){
      dp[i+1][j+1]+=dp[i][j]*p[i];
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
    }
  }
  double ans=0;
  FOR(i,N/2+1,N+1){
    ans+=dp[N][i];
  }
  printf("%.10f\n",ans);
}


Measured memory_bytes: 70656
#include<stdio.h>

int main(){
    int a, b, i, x, y;
    scanf("%d %d",&a,&b);    
    //printf("%d %d\n",x,y);
    for(i=1;i<1001;i++){
        //printf("%d, %d\n", i*8/100, i/10);
        if(i*8/100==a&&i/10==b){ printf("%d",i); return 0; }
    }
    printf("-1"); return 0;
}

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

int main(){
  
  using namespace std;
  
  int X;
  cin >> X;
  string ans;
  
  if(X >= 30){
    ans = "Yes";
  } else{
    ans = "No";
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    int N;
    cin >>N;
    int H[N];
    for(int i = 0;i < N;i++) cin >> H[i];
    int ans = 0;
    int memo = -1;
    for(int i = 0;i < N;i++){
        if(H[i] >= memo){
            memo = H[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A = list(map(lambda x: x*(-1), A)) 
    heapq.heapify(A)
    ans = 0
    while M > 0:
        heapq.heappush(A, (heapq.heappop(A)*-1) // 2 * -1)
        M -= 1
    for i in range(N):
        ans += -A[i]
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

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

ll part[100010];
ll tmp[100010];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    vector<ll> a,b,c;
    ll x;
    cin>>n;
    f(n){
        cin>>x;
        a.pb(x);
    }
    f(n){
        cin>>x;
        b.pb(x);
    }
    f(n){
        cin>>x;
        c.pb(x);
    }
    sort(all(a));
    sort(all(b));
    sort(all(c));
    int i=1;
    for(auto val:b){
        ll l=lower_bound(all(a),val)-a.begin();
        tmp[i]=l;
       ++i;
    }
    fi(i,1,n+1){
        part[i]=tmp[i]+part[i-1];
    }
    ll ans=0;
    for(auto val:c){
        int l=lower_bound(all(b),val)-b.begin();
        ans+=part[l];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4340
n=int(input())
s=list(input())
w=s.count('.')
if s[0]=='.':
    sm=1
else:
    sm=0

def change(y):
    total=(y+1-sm)+(w-sm)
    return total
mn=change(0)
for i in range(1,n):
    if s[i]=='.':
        sm += 1
    mn=min(mn,change(i))
mn=min(mn,w)
print(mn)

Measured memory_bytes: 4840
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret += s[i] == t[i];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

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

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

  int n, k;
  cin >> n >> k;
  int a[200050];
  int memo[200050];
  REP(i, n) { cin >> a[i]; }
  MEMSET(memo, -1);

  int initial = 0;
  int shuuki = 0;
  vector<int> port;
  bool flag = true;
  int now = 0;
  port.pb(0);
  memo[0] = 0;
  int count = 0;

  while (flag) {
    now = a[now] - 1;
    // debug(now + 1);
    port.pb(now);
    count += 1;
    if (memo[now] != -1) {
      shuuki = count - memo[now];
      initial = count - shuuki;
      flag = false;
    } else {
      memo[now] = count;
    }
  }
  // debug(shuuki);
  // debug(initial);

  if (k <= initial) {
    cout << port[k] + 1 << endl;
  } else {
    cout << port[initial + (k - initial) % shuuki] + 1 << endl;
  }
  return 0;
};


Measured memory_bytes: 8456
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
//	ios::sync_with_stdio(false);
//	cin.tie(0);
const int maxx = 2e5+7;
const int maxn = 1e9+7;
typedef long long ll;
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll t,a,b,n;
ll max(ll a,ll b){
	if(a>b)return a;
	else return b;
}
int main(){
//	rept(i,1,40){
//		cout<<i*20/18-20*(i/18)<<endl;
//	}
	cin>>a>>b>>n;
	if(b>=n)cout<<max(((a*n)/b)-a*(n/b),(a*(n-1))/b-a*((n-1)/b))<<endl;
	else {
		cout<<((a*(b-1))/b)-a*((b-1)/b)<<endl;
	}
	return 0;
}

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

int main()
{
    double A,B,N;
    cin >> A >> B >> N;
    double x;

    if(N < B)
    {
        x = N;
    }
    else
    {
        x = B - 1;
    }
    
    ll ans = A * x / B;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int k;
int dp[15][15];

void solve(int i, int j, int c) {
	string res = to_string(j);
	int a = i - 1, b = j;
	c -= dp[i][j];
	while (a > 0) {
		for (int l = -1; l < 2; l++) {
			if (l < 0 && !a)continue;
			c += dp[a][b + l];
			if (k <= c) {
				b = b + l;
				res += to_string(b);
				c -= dp[a][b];
				a--;
				break;
			}
		}
	}
	cout << res << endl;
}

signed main() {
	cin >> k;
	for (int i = 0; i <= 9; i++)dp[1][i] = 1;
	for (int i = 2; i <= 10; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][j] += dp[i - 1][j];
			if (j)dp[i][j] += dp[i - 1][j - 1];
			if (j < 9)dp[i][j] += dp[i - 1][j + 1];
		}
	}
	int cnt = 0;
	for (int i = 1; i <= 10; i++) {
		for (int j = 1; j < 10; j++) {
			cnt += dp[i][j];
			if (k <= cnt) {
				solve(i, j, cnt);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=b && c>=a){
		cout << "Yes"<<endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
mod = 10**9 +7
ans = 1
k = 1
i = 2
N = math.factorial(n)

while N != 1:
    if N%i == 0:
        N = N//i
        k += 1
    else:
        ans *= k
        k = 1
        i += 1
ans *= k
print(ans%mod)


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

int ar[10];

int main()
{
  for(int i=0; i<3; i++)
  {
    int a ;
    cin >> a;
    
    ar[a]++;
  }
  
  if(ar[5]==2 && ar[7]==1)
  cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
  
}

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

int main() {
	int n,res=0;
	cin >> n;
	vector<unsigned long long> arr;

	for (int i = 0; i < n; i++) {
		unsigned long long x;
		cin >> x;
		arr.push_back(x);
	}

	while (1) {
		bool j = true;
		for (int i = 0; i < arr.size(); i++) {
			if (arr[i] % 2 == 1) {
				j = false;
				break;
			}
		}

		if (!j) break;

		res++;
		for (int i = 0; i < arr.size(); i++) arr[i] /= 2;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

hat_num = gets.to_i

hats = gets.split(' ').map(&:to_i)

puts 0 == hats.each_slice(2).reduce(0) { |result, slice| a, b = slice; b == nil ? result ^ a : result ^ (a^b) } ? 'Yes' : 'No'

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(ull i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ull j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/



int main(int argc, char const* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ull N;
    cin >> N;

    ull ans = 0;
    ull y;
    REPinit(i, 1, N + 1) {
        y = int(N / i);
        ans += ((y * (y + 1) * i) / 2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3676
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    int n;
    cin>>n;
    bool ok=false;
    rep(i,3){
        int num;
        num=n%10;
        n/=10;
        if(num==7){
            ok=true;
            break;
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
        
    return 0;
}

Measured memory_bytes: 3596
#import itertools #import *

def factorization(input):
    arr = []
    temp = input
    for i in range(2, int(-(-input**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([input, 1])

    return arr

n = int(input())
if(n == 1):
    print(0)
    exit()
lst = factorization(n)

element = []

for i in lst:
    for j in range(i[1]):
        element.append(i[0]**(j+1))

element = set(element)
element = sorted(list(element))
#element = list(itertools.permutations(element))
#print(element)

cnt = 0
for k in element:
    if (n % k !=0):
        #print(cnt)
        #exit()
        continue
    n = n/k
    cnt += 1

print(cnt)


Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

struct edge
{
  ll to;
  ll cost;
  edge() {}
  edge(ll to, ll cost) : to(to), cost(cost){};
};

vector<ll> dijkstra(ll s, vector<vector<edge>> &g)
{
  //pair.first=距離,pair.second=点
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
  vector<ll> dist(g.size(), INF);
  dist[s] = 0;
  q.push({0, s});

  while (!q.empty())
  {
    pair<ll, ll> p = q.top();
    q.pop();
    ll v = p.second;
    if (dist[v] < p.first)
      continue;
    rep(i, g[v].size())
    {
      edge e = g[v][i];
      if (dist[e.to] > dist[v] + e.cost)
      {
        dist[e.to] = dist[v] + e.cost;
        q.push({dist[e.to], e.to});
      }
    }
  }
  return dist;
}
int main()
{
ll n, m,s,t;
cin >> n >> m >> s >> t ;
vector<vector<edge>> g(n);
vector<vector<edge>> gg(n);
rep(i, m)
{
  ll a, b, c , d;
  cin >> a >> b >> c >> d;
  g[a - 1].emplace_back(b - 1, c);
  g[b - 1].emplace_back(a - 1, c);
  gg[a - 1].emplace_back(b - 1, d);
  gg[b - 1].emplace_back(a - 1, d);
}
auto v=dijkstra(s-1,g);
auto vv=dijkstra(t-1,gg);
vector<pair<ll,ll>> p;
rep(i,n){
  p.emplace_back(v[i]+vv[i],i);
}
sort(p.begin(),p.end());
ll itr=0;
rep(i,n){
  while(p[itr].second<i)itr++;
  cout << 1000000000000000-p[itr].first << endl;
  
}
return 0;
}

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

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

		int[] numbers = new int[5];
		
		for (int i = 0; i < numbers.length; i++) {
			numbers[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(numbers);
		

		StringBuilder sb = new StringBuilder();
		sb.append(numbers[0]);
		for (int i = 1; i < numbers.length; i++) {
			sb.insert(0, numbers[i] + " ");
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 25964
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  int N, X; cin >> N >> X;

  int cnt = N+1, pos = 0;
  for (int i = 0; i < N; i++) {
    int L; cin >> L;

    pos += L;
    if (pos > X) {
      cnt = i+1;
      break;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i,j,v,s[5000],m;
	while(scanf("%d",&n),n){
		memset(s,0,sizeof(s));
		m=-100000;
		for(i=0;i<n;i++){
			scanf("%d",&v);
			for(j=0;j<=i;j++){
				s[j]+=v;
				if(s[j]>m)
					m=s[j];
			}
		}
		printf("%d\n",m);
	}
	return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int main(void) {
    int n;
    cin >> n;

    string u;
    double x, ans=0.0;
    for(int i=0;i<n;i++) {
        cin >> x >> u;
        if(u=="JPY") ans += x;
        else ans += 380000.0*x;
    }

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


Measured memory_bytes: 256
#include<stdio.h>

int n=0,m=0;
//int a[],b[],c[51],d[51],point[];
int i=0,i2=0;
int disx=0,disy=0;
long long dis=0,mindis=0,mindisp=0;

int main(){
	scanf("%d %d",&n,&m);
int a[n+1],b[n+1],c[51],d[51],point[n+1];


	for(i=1;i<=n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=1;i<=m;i++){
		scanf("%d %d",&c[i],&d[i]);
	}




	for(i=1;i<=n;i++){//人ループ
		mindis=1000000000;
		
		for(i2=1;i2<=m;i2++){//ポイントループ
			disx=a[i]-c[i2];
			if(disx<0)
				disx=disx*-1;
			disy=b[i]-d[i2];
			if(disy<0)
				disy=disy*-1;
			dis=disx+disy;
			if(dis<mindis){
				mindis=dis;
				point[i]=i2;
			}
		}
	
	
	}

	for(i=1;i<=n;i++){
		printf("%d\n",point[i]);
	}
		

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}



int main(){
    string s;
    cin >> s;

    int ans=0;
    int len = s.length();

    for(int i=0;i<len;i++){
        for(int j=i;j<len;j++){
            bool ok =true;
            int count =0;
                for(int k=i;k<=j;k++){
                if(s[k]== 'A' or s[k]== 'C' or s[k]== 'G' or s[k]== 'T'){
                    count++;
                }
                else{
                    ok =false;
                }
                }

            if(ok){
                ans = max(count,ans);
            }

        }
    }

    cout << ans <<endl;

     return 0;

}



Measured memory_bytes: 3608
//Code-->**RAJESH_KUMAR**//

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

typedef long long int ll;
#define endl "\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define fe first
#define se second
const int M = 1e9 + 7;


signed  main() {

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

    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);

    //*************************************//
    
    int t ;  cin >> t;
    
    int temp=t%10;
    if(temp==2||temp==4||temp==5||temp==7||temp==9)
      cout<<"hon"<<endl;
    else if(temp==0||temp==1||temp==6||temp==8)
      cout<<"pon"<<endl;
    else
      cout<<"bon"<<endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
long long f[N][3];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n;
    char c='+';
    cin>>n;
    f[0][0]=0,f[0][1]=f[0][2]=-1LL<<60;
    for(int i=1;i<=n;i++) {
	int x=gi();
	if(c=='+') {
	    f[i][0]=f[i-1][0]+x;
	    f[i][1]=f[i-1][1]-x;
	    f[i][2]=f[i-1][2]+x;
	}
	else {
	    f[i][0]=f[i-1][0]-x;
	    f[i][1]=max(f[i-1][1]+x,f[i-1][0]-x);
	    f[i][2]=max(f[i-1][2]-x,f[i-1][1]+x);
	}
	if(i<n) c=getchar();
	f[i][1]=max(f[i][1],f[i][2]);
	f[i][0]=max(f[i][0],f[i][1]);
    }
    cout<<f[n][0];
    return 0;
}

Measured memory_bytes: 2560
#include        "iostream"
#include        "algorithm"
#include		"numeric"
#include        "cstring"
#include        "math.h"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        <ext/pb_ds/assoc_container.hpp> // Common file
#include        <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include        <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          db(x) cout<<#x <<" : "<< x <<endl;
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);   
	    freopen("ou.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
int ai[N],dp[N][4],bi[N],ci[N];

int Ans(int i , int pre )
{
	if( i >= n ) return dp[i][pre] = 0;

	int& ans = dp[i][pre];

	if( ~ans ) return ans;

	int aa = 0 , bb = 0, cc = 0;

	if( pre == 0 )
	{
		aa = ai[i] + Ans( i+1 , 1);
		bb = bi[i] + Ans( i+1 , 2);
		cc = ci[i] + Ans( i+1 , 3);
	}
	else if( pre == 1 )
	{
		bb = bi[i] + Ans(i+1 , 2);
		cc = ci[i] + Ans( i+1 , 3 );
	}
	else if( pre == 2)
	{
		aa = ai[i] + Ans( i+1 , 1);
		cc = ci[i] + Ans( i+1 , 3);
	}
	else if( pre == 3)
	{
		aa = ai[i] + Ans( i+1 , 1);
		bb = bi[i] + Ans( i+1 , 2);
	}

	return ans = max({ aa, bb , cc });
}

void go()
{
	cin >> n;
	
	fo(i,0,n)
	{
		cin >> ai[i] >> bi[i] >> ci[i];
	}

	memset( dp , -1 , sizeof dp);

	int ans = Ans(0,0);

	cout << ans << endl;
	
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}


Measured memory_bytes: 19072
#include<stdio.h>
int main(void)
{
    int a,b; /* 数の箱*/
    char c; /* 文字の箱*/
    do{
        scanf("%d ",&a);
        scanf("%c",&c);/*文字は %c */
        scanf(" %d",&b);
        switch(c){ /* switchの値で判断して実行 */
        case '+':
            printf("%d\n",a+b);
            break;
        case '-':
            printf("%d\n",a-b);
            break;
        case '*':
            printf("%d\n",a*b);
            break;
        case '/':
            printf("%d\n",a/b);
            break;
        case '%':
            printf("%d\n",a%b);
            break;
        default: /*どれにも当てはまらない場合*/
            break;
        }
    }while(c!='?'); /*doからwhileまででcが'？'になるまで繰り返す*/
    return 0;
}


Measured memory_bytes: 2672
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

template<class T>
struct RMQ {
	T INF;
	int n;
	vector<T> dat, laz;
	RMQ(int n_) {
		INF = 0;
		n = 1;
		while(n < n_) n <<= 1;
		dat.assign(2*n-1, 0);
		laz.assign(2*n-1, 0);
	}
	inline int chld(int k) {return k*2+1;}
	inline int chrd(int k) {return k*2+2;}
	void eval(int k) {
		if(laz[k] == INF) return;
		if(k < n-1) {
			laz[chld(k)] += laz[k];
			laz[chrd(k)] += laz[k];
		}
		dat[k] += laz[k];
		laz[k] = INF;
	}
	void update(int a, int b, T x, int k, int l, int r) {
		eval(k);
		if(a <= l and r <= b) {
			laz[k] += x;
			eval(k);
		} else if(a < r and l < b) {
			update(a, b, x, chld(k), l, (l+r)>>1);
			update(a, b, x, chrd(k), (l+r)>>1, r);
			dat[k] = max(dat[chld(k)], dat[chrd(k)]);
		}
	}
	inline void update(int a, int b, T x) {update(a, b, x, 0, 0, n);}
	T query(int a, int b, int k, int l, int r) {
		eval(k);
		if(r <= a or b <= l) return INF;
		if(a <= l and r <= b) return dat[k];
		return max(query(a, b, chld(k), l, (l+r)>>1), query(a, b, chrd(k), (l+r)>>1, r));
	}
	inline T query(int a, int b) {return query(a, b, 0, 0, n);}
};

struct info {
	int l, r, a;
	bool operator<(const info &X) const {return r < X.r;}
};
const int N = 2e5+10;

//head

int n, m;
info lra[N];
RMQ<ll> rng(N);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	rep(i, m) {
		int l, r, a;
		cin >> l >> r >> a;
		l--; r--;
		lra[i] = (info){l, r, a};
	}
	sort(lra, lra+m);

	int j = 0;
	rep(i, n) {
		rng.update(i, i+1, rng.query(0, i));
		while(j != m and lra[j].r == i) {
			rng.update(lra[j].l, i+1, lra[j].a);
			j++;
		}
	}

	cout << rng.query(0, n) << endl;
}

Measured memory_bytes: 13776
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
vector<int> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) {
        int a;
        cin>>a;
        v.push_back(a);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=v[i];
        ans--;
    }

    cout << ans<< "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int n;
    cin >> n;

    int ans = 180*(n-2);

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


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

short = H*30 + 30*(M/60)
long = M*6

diff = abs(short -long)

radian = math.radians(diff)
cosC = math.cos(radian)

C = A*A + B*B - 2*A*B*cosC

print(math.sqrt(C)) 



Measured memory_bytes: 9504
#include <stdio.h>

int main()
{
    int a, b, c, d;

    scanf("%d %d %d", &a, &b, &c);

    if(a>b) {
        d=a;
        a=b;
        b=d;
    }
    if(a>c) {
        d=a;
        a=c;
        c=d;
    }
    if(b>c) {
        d=b;
        b=c;
        c=d;
    }

    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=	(a*a)%mod;b>>=1;}return (res%mod);}
const int N=2e5+5;

ld pi= 3.14159265358979323846264338327950288419716939937510;
ld eps=1e-11;
bool f( ld c){
	if ( c<eps&&c>-eps)
		return true;
	return false;
}


void solve(int n){
	//int n;
	//cin>>n;
	ld cc=0;
	ld cd=0;
	ld c=0;
	for ( int i=0;i<500;i++){
		c+=n;
		cc+=sinl( c/180*pi);
		cd+=cosl( c/180*pi);
		//cout<<cc<<' '<<cd<<'\n';
		if ( f(cc)&&f(cd)){
			cout<<i+1<<'\n';
			return;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	/*
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
// */
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		int n;
		cin>>n;
		//cout<<"Case #"<<i<<": ";
    	solve(n);
    }
}

Measured memory_bytes: 3944
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int main(){
string s;
string down,up;
cin>>s;
int n=s.size();
down=s.substr(0,(n-1)/2);
up=s.substr((n+3)/2-1,(n-1)/2);
string down1=down;
string up1=up;
string s1=s;
reverse(all(s));
reverse(all(down));
reverse(all(up));
if(s==s1&&down==down1&&up==up1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<numeric>
using namespace std;

int main()
{
	long long a[10];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
	{
		cout<<0<<endl;
	}
	else{
		sort(a,a+3);
		cout<<a[0]*a[1]<<endl;
	}	
} 

Measured memory_bytes: 256