akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll h,w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i,h) {
    cin >> s[i];
  }
  ll res = 0;
  vector<vector<ll>> v(h, vector<ll>(w,0));
  REP(i,h) {
    ll tmp = 0;
    int start = 0;
    REP(j, w) {
      if (s[i][j] == '.' && j != w-1)  {
        tmp++;
      }
      else {
        if (s[i][j] == '.') tmp++;
        ll tmpj = s[i][j] == '.' ? j : j-1;
        for (int k = start; k <= tmpj; k++) {
         v[i][k] = tmp;
        }
        start = j+1;
        tmp = 0;
      }
    }
  }
  REP(i,w) {
    ll tmp = 0;
    int start = 0;
    REP(j, h) {
      if (s[j][i] == '.' && j != h-1)  {
        tmp++;
      }
      else{
        if (s[j][i] == '.') tmp++;
        ll tmpj = s[j][i] == '.' ? j : j-1;
        for (int k = start; k <= tmpj; k++) {
         v[k][i] += tmp;
        }
        start = j+1;
        tmp = 0;
      }
    }
  }
  REP(i,h) {
    REP(j,w) {
      res = max(v[i][j],res);
    }
  }
  cout << res-1 << endl;


  return 0;
}


Measured memory_bytes: 35712
S = list(input())
T = list(input())
ans = len(T)
cnt = 0

for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            cnt+=1
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9132
#include <stdio.h>

int main(void)
{
	int a, b;
	int cnt = 0;
	int sum;
	
	while (scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		cnt = 0;
		
		do {
			sum /= 10;
			cnt++;
		} while (sum > 0);
		
		printf("%d\n", cnt);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
	int a,b,c,r,n,x;
	n=0;
	scanf("%d %d %d",&a,&b,&c);
	
	for(x=a;x<=b;x++){
		r=c%x;
		if(r==0){
			n++;
		}
	}
	
	
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
long long n,m,tim,a[200003],b[200003],ans;
int main(){cin>>n>>m>>tim;
	for(int i=1;i<=n;i++)scanf("%lld",a+i),a[i]+=a[i-1];
	for(int i=1;i<=m;i++)scanf("%lld",b+i),b[i]+=b[i-1];
	for(long long i=0,j=m;i<=n;i++){
		long long T=tim-a[i];
		if(T<0)break;
		for(j;j>=0&&b[j]>T;j--);
		ans=max(ans,i+j);
	}cout<<ans;
}

Measured memory_bytes: 6720
from functools import reduce

def gcd(x, y):
    y, x = sorted([x, y])
    while True:
        r = x % y
        if r == 0:
            # print(x, y, r)
            return y
        else:
            # print(x, y, r)
            x, y = y, r

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
l = list(map(int, input().split(" ")))

p = lcm_list(l)
c = 0
z = 10 ** 9 + 7
for i in l:
  c += p // i
print(c % z)

Measured memory_bytes: 4708
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const int N = 555;
char s[N][N];

int main () {
   wez(n)
   FOR(i,n) scanf("%s", s[i]);
   bool allwhite = 1;
   FOR(i,n) FOR(j,n) if (s[i][j] == '#') allwhite = 0;
   if (allwhite) {
      pisz(-1);
      return 0;
   }
   int mini = INF;
   FOR(a,n) {
      int whites = 0;
      FOR(j,n) if (s[a][j] == '.') ++whites;
      int score = 0;
      if (whites == 0) {
         // ok
      } else {
         bool colhasblack = 0;
         FOR(i,n) if (s[i][a] == '#') colhasblack = 1;
         if (!colhasblack) score++;
         //if (a == 1) DBG(colhasblack);
         score += whites;
      }
      //if (a == 1) DBG(score);
      FOR(j,n) {
         bool haswhite = 0;
         FOR(i,n) if (s[i][j] == '.') haswhite = 1;
         score += haswhite;
      }
      REMIN(mini, score);
      //if (score == 4) DBG(a);
   }
   pisz(mini);
}

Measured memory_bytes: 512
A,B = map(int,input().split())


def a(num):
    list_a = []
    while num > 0:
        list_a.append(num % 10)
        num = num // 10
    return list_a

count = 0
for i in range(A,B+1):
    k = a(i)
    if k[0] == k[4] and k[1] == k[3]:
        count += 1
    
print(str(count))

Measured memory_bytes: 9152
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static long[] s;
	static int[] a,f;
	static void Main(){
		Sc sc=new Sc();
		s=sc.La;
		a=sc.Ia;
		f=sc.Ia;
		Array.Sort(a,(u,v)=>v-u);
		Array.Sort(f);
		Fu(10);
		long lb=-1,ub=long.MaxValue-1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(Fu(mid)){ub=mid;}
			else{lb=mid;}
		}
		Console.WriteLine("{0}",ub);
	}
	static bool Fu(long n){
		//Console.WriteLine("{0}.",n);
		long p=0;
		for(int i = 0;i<s[0];i++) {
			//Console.WriteLine("{0} {1}",f[i],n/f[i]);
			if(a[i]>n/f[i]){
				p+=a[i]-n/f[i];
			}
			if(p>s[1]){break;}
		}
		return p<=s[1];
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 47456
a, b, c, x, y = map(int, input().split())
l = []
kari = [x, y]
kari = max(kari)*2

for i in range(kari+1):
    if i%2!=0:
        continue

    a_p = a*(x-(i//2))
    b_p = b*(y-(i//2))
    if (i//2)>=x:
        a_p = 0
    if (i//2)>=y:
        b_p = 0
        
    price = (c*i)+ a_p + b_p
    l.append(price)


print(min(l))

Measured memory_bytes: 7096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  string S;
  int w;
  int end;

  cin >> S;
  cin >> w;

  if(S.size()%w == 0){
    end = S.size()/w;
  }
  else{
    end = S.size()/w+1;
  }

  REP(i,end){
     cout << S[w*i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

void solve(){
    int n;
    read(n);
    vi h(n);
    REP(i,n) cin >> h[i];
    int min_el = h[0] - 1;
    REP(i,n){
        if(h[i] < min_el) {
            cout << "No\n"; return;
        }else{
            min_el = max(min_el, h[i] -1);
        }
    }
    cout << "Yes\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define ma 2000000
bool sosu[ma]={1,1,0};
int main(){
	for(int i=4;i<ma;i+=2)sosu[i]=1;
	for(int j=3;j<ma;j+=2)if(!sosu[j])
	for(int i=j*3;i<ma;i+=j*2)sosu[i]=1;
	
	int a,b;
	while(cin>>a>>b,a+1){
		int m=0;
		a++;
		vi out;
		int co=-1;
		loop(i,a,1e9){
			if(!sosu[i])co++;
			if(co==b+1){m=i;break;}
		}
		loop(i,a,m){
			if(sosu[i])continue;
			loop(j,i,m)if(!sosu[j])out.pb(i+j);
		}
		sort(all(out));
		cout<<out[b-1]<<endl;
	}
}

Measured memory_bytes: 3224
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
LL c;
int a, b;
int main()
{
	scanf("%d %d",&a, &b);
	c = a * b;
	if(c % 2 == 0) printf("Even\n");
	else printf("Odd\n");
}

Measured memory_bytes: 256
s = input()

first = s[:2]
second = s[2:]

if int(first) <= 12 and int(first) > 0:
    first_m = True
else:
    first_m = False
if int(second) <= 12 and int(second) > 0:
    second_m = True
else:
    second_m = False

if first_m and second_m:
    print("AMBIGUOUS")
elif first_m:
    print("MMYY")
elif second_m:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num[] = new int[3];
        int oddNum = 0;
        for (int i = 0; i < 3; ++i) {
            num[i] = scanner.nextInt();

            if (num[i] % 2 == 1) {
                oddNum++;
            }
        }

        if (oddNum > 0) {
            System.out.println("0");
            return;
        }

        if (num[0] == num[1] && num[1] == num[2]) {
            System.out.println("-1");
            return;
        }

        int ans = 0;
        while (num[0] % 2 == 0 && num[1] % 2 == 0 && num[2] % 2 == 0) {
            int nextNum[] = { num[1] / 2 + num[2] / 2, num[2] / 2 + num[0] / 2, num[0] / 2 + num[1] / 2 };

            for (int i = 0; i < 3; ++i) {
                num[i] = nextNum[i];
            }

            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
lines = $stdin.read
array = lines.split("\n")

INF = 1 << 25

def coin(amount,kind,coins)
  dp = Array.new(amount+1, INF)
  dp[0] = 0
  for i in 0...kind
    for j in coins[i]..amount
      dp[j] = [dp[j], dp[j - coins[i]] + 1].min
    end
  end
  dp
end

N,M = array[0].split(" ").map(&:to_i)
coins = array[1].split(" ").map(&:to_i)

dp = coin(N,M,coins)
#dp.each_with_index{|e,i| puts "#{i},#{e}"}
#puts N
puts dp[N]

Measured memory_bytes: 9284
N=int(input())
W=[]
fw=input()
W.append(fw)
flag=True
for i in range(N-1):
    w=input()
    if w in W or fw[-1]!=w[0]:
        flag=False
    else:
        W.append(w)
        fw=w
if flag==True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,a[N] ,b[N] ,mn=1e9+5 ;
bool is = 1 ;
int main(){
    scanf("%d",&n);
    long long ans = 0;
    for(int i=0;i<n;++i){
        scanf("%d%d",a+i,b+i);
        if(a[i]!=b[i]) is = 0 ;
        ans += b[i] ;
        if(a[i]>b[i]) mn = min(mn,b[i]) ;
    }
    if(is) return cout << 0,0 ;
    cout << ans - mn ;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>

using namespace std;


int main() {
  int N;
  cin >> N;
  
  int d[N];
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  
  sort(d, d+N);
  
  cout << d[N/2]- d[N/2-1] << endl;
  
  return 0;
}


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


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

	string s;
	ll q;
	cin>>s>>q;    
    deque<char> arr;
    For(i,0,s.size())
    	arr.push_back(s[i]);
    ll st = 0, en = int(s.size())-1;
    For(i,0,q){
    	ll t;
    	cin>>t;
    	if(t==1){
    		swap(st,en);
    	}
    	else{
    		ll f;
    		char c;
    		cin>>f>>c;
    		if(f==1){
    			if(st==0)
    				arr.push_front(c),en++;
    			else
    				arr.push_back(c),st++;
    		}
    		else{
    			if(en==0)
    				arr.push_front(c),st++;
    			else
    				arr.push_back(c),en++;
    		}
    	}
    }
    // deb2(st,en);
    if(st == 0)
	    For(i,0,arr.size())
	    	cout<<arr[i];
	else
		for(ll i=arr.size()-1 ; i>=0 ; i--)
			cout<<arr[i];

    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 976
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  string s;
  cin>>s;
  int query;
  cin>>query;
  bool reversed=false;
  string before="";
  string after="";
  for(int i = 1;i<=query;i++){
    int qtype;
    cin>>qtype;
    if(qtype==1){
      reversed=!reversed;
    }
    if(qtype==2){
      int subType;
      char c;
      cin>>subType>>c;
      if(!reversed){
        if(subType==1){
          before+=c;
        }
        if(subType==2){
          after+=c;
        }
      }
      else{
        if(subType==1){
          after+=c;      
        }
        if(subType==2){
          before+=c;
        }
      }

    }
  }
  if(reversed){
    cout<<string(after.rbegin(),after.rend())+string(s.rbegin(),s.rend())+before<<"\n";  
  }
  else{
    cout<<string(before.rbegin(),before.rend())+s+after<<"\n";  
  }  
  return 0;
}

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

#define MAX_N 100

int main(){
    int N;
    cin >> N;
    int A, B;
    cin >> A >> B;
    int P[MAX_N];

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

    int a = 0;
    int ab = 0;
    int b = 0;

    for(i = 0; i < N; i++){
        if(P[i] <= A) a++;
        else if (P[i] > A && P[i] <= B) ab++;
        else b++;
    }

    if(a <= b && a <= ab){
        cout << a << endl;
    }
    else if (b <= a && b <= ab){
        cout << b << endl;
    }
    else
        cout << ab << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,n,p;
  cin>>s>>n>>p;
  char x,y,z;
  x=s[0]-32;
  y=n[0]-32;
  z=p[0]-32;
  cout<<x<<y<<z<<endl;
}


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

int main(){
  int x;cin >> x;
  if(x >= 30)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
'use strict'

function Main(input) {
  const A = Number(input.split(' ')[0]);
  const B = Number(input.split(' ')[1]);

  const plus = A + B;
  const minus = A - B;
  let multi = A * B;

  if(Math.abs(multi) === 0) {
    multi = 0;
  } else {
    multi = A * B;
  }

  console.log(Math.max(plus, minus, multi));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    ll N;
    cin>>N;
    ll E= 0LL;
    rep(i,N-1){
        ll a,b;
        cin>>a>>b;
        ll c = max(a,b);
        ll d = min(a,b);
        E += d * (N-c+1);
    }
    ll t = 0;
    rep(i,N){
        t += (i+1)*(N-i);
    }
    cout<<t-E<<endl;
}

Measured memory_bytes: 3620
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);
//#define Local = 1;
#ifdef Local
#define debug(x) cout << __LINE__ << " " << #x <<"..." << x << endl
#define dev(x) cout << __LINE__ << " " << #x << "..." ; for(auto &it : x) cout<< it << " "; cout << endl;
#define des(x) cout << __LINE__ << " " << #x << "..." << x << endl;
#else
#define debug(x) ;
#define dev(x);
#define des(x)
#endif

const double PI = 3.141592653589793;

void solve()
{
	int q;
	cin >> q;
	vector <pair<int,int>> a(q);
	for(int i=0;i<q;i++)
	{
		cin >> a[i].first >> a[i].second;
	}
	for(int i=0;i<=q-2;i++)
	{
		if( a[i].first != a[i].second ) continue;
		if( a[i+1].first != a[i+1].second) continue;
		if( a[i+2].first != a[i+2].second) continue;
		cout << "Yes\n";
		return ;
	}
	cout << "No\n";
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--) solve();
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int n;
ll ans = 0;
char s[20];

void go(int i, ll sum1, ll sum2) {
	if(i == n) {
		ans += sum1+sum2;
		return ;
	}

	go(i+1, sum1*10+s[i]-'0', sum2);
	if(sum1) {
		sum2 += sum1;
		go(i, 0, sum2);
	}
}

int main() {
	scanf("%s", s);
	n = strlen(s);
	go(0, 0, 0);

	printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
  int d,e;
  int i;
  double min,pre;
  while(1)
    {
      scanf("%d%d",&d,&e);
      if((d==0)&&(e==0)) break;
      min=0.0;
      for(i=0;i<=d;i++)
	{
	  pre=fabs(e-sqrt(i*i+(d-i)*(d-i)));
	  if((pre<min)||(i==0)) min=pre;
	}
      printf("%f\n",min);
    }
  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define PI acos(-1)

using namespace std;

constexpr double EPS = 1e-8;
constexpr int MAXN = 1e5 + 5;
constexpr int INF = 0x3f3f3f3f;

array<int, MAXN> a;

long long n, cnt, d;

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        long long x, y;
        cin >> x >> y;
        if ((x * x + y * y) <= d * d) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=55;
int n,m;
char a[maxn][maxn];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
bool vis[maxn][maxn];
bool valid(int x,int y){
    re (x>=0&&y>=0&&x<n&&y<m&&!vis[x][y]&&a[x][y]=='.');
}
int dot;
int bfs(){
    queue<pair<pair<int,int>,int> > q;
    q.push({{0,0},0});
    while(q.size()){
        int x=q.front().f.f;
        int y=q.front().f.s;
        int cost=q.front().s;
        q.pop();
        if(x==n-1&&y==m-1)re dot-(cost+1);
        for(int i=0;i<4;++i){
            int xx=x+dx[i],yy=dy[i]+y;
            if(valid(xx,yy)){
                q.push({{xx,yy},cost+1});
                vis[xx][yy]=true;
            }
        }
    }
    re -1;
}
int main(){
    IO;
    cin >> n >> m;
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            cin >> a[i][j],dot+=a[i][j]=='.';
    cout<<bfs()<<endl;
    re 0;
}

Measured memory_bytes: 256
#coding-utf-8

def main():
    s = str(input())
    slist = list(s)
#   print(slist)
    stk = []
    c = []
    lenmax = 0
    for i in range(len(slist)):
        if slist[i] == 'A' or slist[i] =='C' or slist[i] =='G' or slist[i] =='T':
            stk.append(slist[i])
            if i == len(slist) - 1:
                c.append(stk)
        else:
            c.append(stk)
            if len(stk) > 0:
                stk = []
                c.append(stk)
            stk = []

#   print(c)

    for j in range(len(c)):
        if len(c[j]) > lenmax:
            lenmax = len(c[j])

    print(lenmax)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
ll N,M;
cin>>N>>M;
vector<pair<ll,ll>> P(N);
for(int i=0;i<N;i++){
    cin>>P.at(i).first>>P.at(i).second;
}
sort(P.begin(),P.end());
ll sum=M,money=0;
ll cost=0;
for(int i=0;i<N;i++){
      money=min(sum,P.at(i).second);
      cost+=money*P.at(i).first;
      sum-=money;
      if(sum==0){
          break;
      }
}
cout<<cost<<endl;
}

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

int main(){
  int k; cin >> k;
  ll sum = 0;

  for(int p = 1; p < k + 1; p++) {
    for(int q = 1; q < k + 1; q++) {
      for(int r = 1; r < k + 1; r++) {
        ll kari;
        kari = gcd(q,r);
        kari = gcd(kari,p);
        sum += kari;
      }
    }
  }

  cout << sum << endl;
}



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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	vector<unsigned long long int> input;

	rep(i, n){
		unsigned long long int a;
		cin >> a;

		if(a == 0){
			cout << 0;
			return 0;
		}

		input.push_back(a);
	}

	unsigned long long ans = input[0];

	REP(i, 1, input.size()){
		if(18 <= log10(ans) + log10(input[i])){
			if(1000000000000000000 / ans == input[i]){
				ans = 1000000000000000000;
			}
			else{
				cout << -1;
				return 0;
			}
		}
		else{
			ans *= input[i];
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i-1] == a[i]){
            a[i] = -1;
            ans ++;
        }
    }

    cout << ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();

		int ans = Integer.MAX_VALUE;
		int end = Math.max(x, y) * 2;
		for (int i = 0; i <= end; i++) {
			int val = c * i * 2 + a * Math.max((x - i), 0) + b * Math.max((y - i), 0);
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

double dp[3010][3010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vd p(n);
    cin >> p;
    dp[0][0] = 1;
    rep(i,n) rep(j,i+1) {
        dp[i+1][j] += dp[i][j]*(1-p[i]);
        dp[i+1][j+1] += dp[i][j]*p[i];
    }
    double ans = 0;
    rep(i,3010) {
        if(i < n-i) continue;
        ans += dp[n][i];
    }
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 69120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
typedef pair<double, long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	ll n, m;
	cin >> n >> m;
	if (n == 1 && m == 0)return cout << 0 << endl,0;
	vector<ll>s(m), c(m);
	rep(i, m)cin >> s[i] >> c[i];
	vector<char>ans(n,'#');
	rep(i, m) {
		if (ans[s[i]-1] == '#' || ans[s[i]-1] == ('0'+c[i])) {
			ans[s[i]-1] = '0' + c[i];
		}
		else {
			return  cout << -1 << endl, 0;
		}
	}
	if (n == 1) {
		return cout << ans[0] << endl,0;
	}
	if (ans[0] == '#')ans[0] = '1';
	if (ans[0] == '0')return cout << -1 << endl,0;
	rep(i, n) {
		if (ans[i] == '#')
			ans[i] = '0';
	}
	string ansS;
	rep(i, n) {
		ansS += ans[i];
	}
	cout << stoll(ansS) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 
int multiply(int a, int b, int in_mod){return (a*b)%in_mod;} 
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}




const int MAXN=2e1+100;
vector<int> adj[MAXN];
map<pair<pair<int, int>, int>  , int> cnt; 
int ans =0;
int k;
int n, m;
vector<vector<int> > a(MAXN, vector<int> (MAXN));
void dfs(int x, int y,int left, int xo=0)
{
    xo = xo^(a[x][y]);
    if(left==0)
    {
        cnt[{{x,y}, xo }]++;
        return;
    }
    if(x!=n-1)
        dfs(x+1, y, left-1, xo);
    if(y!=m-1)
        dfs(x, y+1, left-1, xo);
}


void dfs2(int x, int y,int left, int xo=0)
{
    xo = xo^(a[x][y]);

    if(left==0)
    {
        ans += cnt[{{x,y}, xo^k^a[x][y]}];
        return;
    }
    if(x!=0)
        dfs2(x-1, y, left-1, xo);
    if(y!=0)
        dfs2(x, y-1, left-1, xo);
}



void solve()
{ 
    string s, t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
        if(s[i]!=t[i])
        {
            cout<<"No"<<endl;
            return;
        }
    cout<<"Yes"<<endl;
    return;
}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock(); 
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------     

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
    ll n,k,d,cnt=0;
    cin>>n>>k;
    ll c[n]={0};
    for(ll i=0;i<k;i++)
    {
        cin>>d;
        ll a[d];
        for(ll j=0;j<d;j++)
        {
            cin>>a[j];
            c[a[j]-1]++;
        }

    }
    for(ll i=0;i<n;i++)
    {
        if(c[i]==0)
            cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
  int number_n, i, rice_cake_size, answer = 0;
  scanf("%d", &number_n);
  int count[100] = {};
  for(i = 0; i < number_n; i++) {
    scanf("%d", &rice_cake_size);
    if(count[rice_cake_size-1] == 0) answer++;
    count[rice_cake_size-1]++;
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int ans = 0;
		while (stdIn.hasNext())
		{
			String s = stdIn.next();
			StringBuffer sBuf = new StringBuffer(s);
			sBuf.reverse();
			if(s.equals(sBuf.toString()))
			{
				++ans;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var num = make([]int, n+1)
	for i:=0; i <= n; i++ {
		num[i] = 0
	}
	for i:=1; i <= n; i++ {
		tmp := i
		for tmp <= n {
			num[tmp]++
			tmp = tmp + i
		}
	}
	// fmt.Printf("%v\n", num)

	var result uint64
	for i := 1; i <= n; i++ {
		result = result + uint64(i) * uint64(num[i])
	}
	fmt.Printf("%d", result)
}


Measured memory_bytes: 82568
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


N, Q, *TUV = map(int, open(0).read().split())
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(TUV)] * 3):
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 144932
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  2 13:42:22 2016

"""

while True:
    S = input()
    if S == "END OF INPUT":
        break
    n = 0
    for l in S:
        if l == " ":
            print(n, end="")
            n = 0
        else:
            n += 1
            
    print(n)

Measured memory_bytes: 7308
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);

        long[] dist = new long[n]; // 開始点からの距離dist
        for (int i = 0; i < n; i++)
            dist[i] = long.MaxValue;

        if (Bellman_ford(n, 0, m, dist)) Console.WriteLine("inf");
        else Console.WriteLine(-dist[n - 1]);
    }

    static bool Bellman_ford(int n, int s, int m, long[] dist)
    {
        // グラフの受け取りはこっちでやる
        // a→b(コストc)
        string[] cin;
        int[] a = new int[m];
        int[] b = new int[m];
        long[] c = new long[m];
        for (long i = 0; i < m; i++)
        {
            cin = Console.ReadLine().Split();
            a[i] = int.Parse(cin[0]) - 1;
            b[i] = int.Parse(cin[1]) - 1;
            c[i] = -long.Parse(cin[2]);
        }

        dist[s] = 0;

        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
                    dist[b[j]] = dist[a[j]] + c[j];
            }
        }

        var dist2 = new long[n];
        dist.CopyTo(dist2, 0);

        bool[] negative = new bool[n];

        for (int j = 0; j < m; j++)
        {
            if (dist2[a[j]] != long.MaxValue && dist2[b[j]] > dist2[a[j]] + c[j])
            {
                dist2[b[j]] = dist2[a[j]] + c[j];
                negative[b[j]] = true;
            }
            if (negative[a[j]]) negative[b[j]] = true;
        }

        if (negative[n - 1]) return true;
        else return false;
    }
}


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

const int N = 1e5 + 200 ;
const ll inf = 1e14;
int n;
ll a[N][4] , mem[N][4];

ll dp(int i , int las){
	if(i==n) return 0;
	ll &ret = mem[i][las];
	if(ret!=-1) return ret;
	if(i==0) return ret = max({
		a[i][0] + dp(1,0),
		a[i][1] + dp(1,1),
		a[i][2] + dp(1,2)
	});
	return ret = max(
		a[i][(las+1)%3] + dp(i+1 , (las+1)%3),
		a[i][(las+2)%3] + dp(i+1 , (las+2)%3)
	);
}

int main(){
	memset(mem , -1 , sizeof mem);
	scanf("%d"  ,&n);
	for(int i=0 ; i<n ; i++)
		for(int j=0 ; j<3 ; j++)
			scanf("%lld" , &a[i][j]);
	printf("%lld" , dp(0,0));
}


Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    int N,a,b;
   // sort(M,M+N);
    cin >> N>>a>>b ;N=N-a;
    b-=N;
    if(b>0){
        cout <<b;
    }else cout <<0;
   // int M[N];

}

Measured memory_bytes: 256
from math import sqrt
M, D = map(int, input().split())
ans = 0
for i in range(1, M+1):
    for j in range(1, D+1):
        if j//10 >= 2 and j%10 >= 2:
            if (j//10)*(j%10) == i:
                ans += 1

print(ans)

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

int main() {
	int N,count=0;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++)
		cin >> v[i];
	sort(v.begin(), v.end());
	for (int i = v[(v.size() / 2) - 1]; i < v[(v.size() / 2)]; i++)
	{
		count++;
	}
	cout << count;
	system("pause");
	return 0;
}

Measured memory_bytes: 888
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<bitset>
#include<ctime>
using namespace std;
using ll = long long;

vector<vector<int>> g;

int DFS(int v, int level, int p = -1) {
	int cnt = 1;
	if (level) {
		for (int u : g[v]) {
			if (u != p)
				cnt += DFS(u, level - 1, v);
		}
	}
	return cnt;
}

void Solve() {
	int n, k;
	scanf("%d%d", &n, &k);
	g.assign(n, vector<int>());
	vector<pair<int,int>> edges(n - 1);
	for (int i = 0; i < edges.size(); i++) {
		scanf("%d%d", &edges[i].first, &edges[i].second);
		edges[i].first--;
		edges[i].second--;
		g[edges[i].first].push_back(edges[i].second);
		g[edges[i].second].push_back(edges[i].first);
	}
	int m = 0;
	if (k % 2 == 0) {
		for (int v = 0; v < n; v++)
			m = max(m, DFS(v, k / 2));
	} else {
		for (auto e : edges) {
			int u = e.first;
			int v = e.second;
			m = max(m, DFS(v, k / 2, u) + DFS(u, k / 2, v));
		}
	}
	printf("%d", n - m);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	Solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << endl;
#endif

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;


int main(){
    int N,M;
    cin >> N >> M;
    vector <ll> a(N);
    vector <ll> b(N);
    vector <ll> c(M);
    vector <ll> d(M);
    REP(i,N)
    {
        cin >> a[i] >> b[i];
    }
    REP(i,M)
    {
        cin >> c[i] >> d[i];
    }

    ll res = 0;

    REP(i,N)
    {
        ll imin = INF;
        REP(j,M)
        {
            ll tmp;
            tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);

            if(tmp < imin)
            {
                res = j + 1;
                imin = tmp; 
            }
        }
        cout << res << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];

    vl sum(N, 0);
    sum[0] = A[0];
    FOR(i,1,N) {
        sum[i] = sum[i - 1] + A[i];
    }

    ll ans = LINF;
    if (N==2) {
        ll x = A[0];
        ll y = A[1];
        ans = abs(x - y);
    } else {
        FOR(i,1,N-1) {
            ll x = sum[i];
            ll y = sum[N - 1] - x;
            ans = min(ans, abs(x - y));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
import sys
N=int(input())
A=[int(i) for i in input().split(" ")]
if 0 in A:
    print(0)
    sys.exit(0)
A=sorted(A,reverse=True)
mul=1
for a in A:
    mul*=a

    if mul>10**18:
        print(-1)
        sys.exit(0)

print(mul)


Measured memory_bytes: 21604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int a[4];
  for (int i = 0; i < 4; i++)
  {
    a[i] = s[i] - '0';
  }
  for (int i = 0; i < 8; i++)
  {
    int v = a[0];
    char f[3];
    for (int j = 0; j < 3; j++)
    {
      if (i & (1 << j))
      {
        v += a[j + 1];
        f[j] = '+';
      }
      else
      {
        v -= a[j + 1];
        f[j] = '-';
      }
    }
    if (v == 7)
    {
      cout << a[0] << f[0] << a[1] << f[1] << a[2] << f[2] << a[3] << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x;
	cin>>x;
	for(ll i = -1000; i < 1000; i ++){
		for(ll j = i; j < 1000; j++){
				if( (j*j*j*j*j) - (i*i*i*i*i)  == x){
						cout<< j <<" "<<i <<nl;
						return 0;
				}	
		}
	}
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

map<ll,ll> cnt[2];
ll D;

ll dfs(const vector<ll>& a,ll i,ll sum){
  // if(sum>D*1000||sum<-D*1000)return 0;

  ll n=a.size();
  if(i==n){
    if(sum==D) return 1;
    else return 0;
  }else{
    ll res=0;
    bool done=false;
    repl(c,-9,9+1){
      if(sum+c*a[i]>D){
        res+=dfs(a,i+1,sum+(c-1)*a[i])*cnt[(i!=0?0:1)][c-1];
        res+=dfs(a,i+1,sum+c*a[i])*cnt[(i!=0?0:1)][c];
        done=true;
        break;
      }
    }
    if(!done){
      res+=dfs(a,i+1,sum+9*a[i])*cnt[(i!=0?0:1)][9];
    }
    return res;
  }
}

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

  rep(a,10)rep(b,10){
    cnt[0][b-a]++;
    if(a>0)cnt[1][b-a]++;
  }

  cin>>D;
  ll res=0;
  rep(d,18){
    vector<ll> ds;
    rep(i,d/2+1){
      ll p1=pow(10,i);
      ll p2=pow(10,d-i);

      ll dif=p2-p1;
      ds.push_back(dif);
    }
    ll t=1;
    if(ds.back()==0){
      t*=10; ds.pop_back();
    }
    res+=dfs(ds,0,0)*t;
  }
  cout<<res<<endl;

  return 0;
}


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

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

	int ans = 0;
	string s_temp = "";

	for (auto s_ele : s) {
		if (s_ele == 'A' || s_ele == 'C' || s_ele == 'G' || s_ele == 'T') {
			s_temp += s_ele;
			if (s_temp.size() > ans) {
				ans = s_temp.size();
			}
		} else {			
			s_temp = "";
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256