akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int ccmp(const void *a, const void *b){
	return *(char*)a - *(char*)b;
}

int scmp(const void *a, const void *b){
	return strcmp(*(char**)a, *(char**)b);
}

int main(void){
	int n;
	char **str;
	scanf("%d", &n);
	str = malloc(sizeof(char*) * n);
	for(int i = 0; i < n; i++){
		str[i] = malloc(sizeof(char) * 11);
		scanf("%s", str[i]);
		qsort(str[i], 10, sizeof(char), ccmp);
	}
	qsort(str, n, sizeof(char*), scmp);
	long count = 0;
	int last = 0;
	for(int i = 1; i < n; i++){
		if(strcmp(str[last], str[i]) == 0){
			count += i - last;
		}else
			last = i;
	}
	printf("%ld\n", count);
	return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007


int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int count=0;
    bool devide=true;
    while(devide){
        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                a[i] /= 2;
            }
            else{
                devide=false;
            }
        }
        if(devide){
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b){
        for(int i=0;i<a;i++)  cout << b;
    }
    else{
        for(int i=0;i<b;i++)  cout << a;
    }
}   

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

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

#define INF 1000000000

typedef unsigned long long ull;
typedef signed long long ll;

using namespace std;

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

    ll x = (N / B) * B - 1;
    if (x == -1) x = N;

    cout << (A * x) / B - A * (x / B) << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  vint a(3),b(3),c(3);
  for (ll i=0;i<3;i++) cin >> a.at(i);
  for (ll i=0;i<3;i++) cin >> b.at(i);
  for (ll i=0;i<3;i++) cin >> c.at(i);
  ll p=a.at(1)-a.at(0),q=a.at(2)-a.at(1),judge=0;
  if (b.at(1)-b.at(0)!=p || b.at(2)-b.at(1)!=q || c.at(1)-c.at(0)!=p || c.at(2)-c.at(1)!=q) {
    judge=1;
  }
  if (judge==1) cout << "No";
  else cout << "Yes";
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
        //出力
        if (a < b && b < c ) Console.WriteLine("Yes");
        else Console.WriteLine("No");

    }
}


Measured memory_bytes: 15968
import sys
sys.setrecursionlimit(10**6)

def dfs(pos):
  i = pos[0]
  j = pos[1]
  seen[j][i] = True
  for k in range(-1+i,2+i):
    for l in range(-1+j,2+j):
      if 0 <= k < w and 0 <= l < h:
        if field[l][k] == 1 and (not seen[l][k]):
          dfs([k,l])

while True:
  w, h = map(int,input().split())
  if w == 0 and h == 0:
    break
  field = [list(map(int,input().split())) for _ in range(h)]
  seen = [[False]*w for _ in range(h)]
  count = 0
  for i in range(w):
    for j in range(h):
      if field[j][i] == 1 and (not seen[j][i]):
        dfs([i,j])
        count += 1
  print(count)


Measured memory_bytes: 8112
s = gets.chomp
k = gets.chomp.to_i

if k == 1 then
  puts s[0]
else
  ones = 0
  s.each_char do |c|
    ones += 1 if c == "1"
    break if c != "1"
  end
  if k <= ones then
    puts "1"
  else
    puts s[ones]
  end
end

Measured memory_bytes: 1916
require 'matrix'

h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.chars.map{|c| (c == '#') ? 1 : 0}}
cnt = 0
[0, 1].repeated_permutation(h).each do |x|
  m = Matrix.rows(rows.dup.shift(h))
  x.each_with_index do |y, i|
    next if y == 0
    w.times do |j|
      m[i, j] = 0
    end
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = m.dup
    u.each_with_index do |v, j|
      next if v == 0
      h.times do |i|
        mc[i, j] = 0
      end
    end
    cnt += 1 if mc.sum == k
  end
end
puts cnt

Measured memory_bytes: 15016
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dx[4]={1, 0, 0,-1};
int dy[4]={0, 1,-1, 0};

int search(int y, int x, int step, vector<vector<int> >& map){
	if(step>10) return -1;
	int ret=1e9;
	for(int i=0; i<4; i++){
		int ny=y+dy[i], nx=x+dx[i];
		if(map[ny][nx]==1) continue;
		while(1){
			if(map[ny][nx]==1){
				map[ny][nx]=0;
				int next = search(ny-dy[i], nx-dx[i], step+1, map);
				if(next!=-1){
					ret = min(next, ret);
				}
				map[ny][nx]=1;
				break;
			}
			if(map[ny][nx]==3){
				return step;
			}
			if(map[ny][nx]==4){
				break;
			}
			ny += dy[i];
			nx += dx[i];
		}
	}
	if(ret == 1e9){
		return -1;
	}
	return ret;
}

int main(){
	while(1){
		int w,h;
		cin >> w >> h;
		if(w==0) break;
		
		vector<vector<int> > map(h+2, vector<int>(w+2, 4));
		int sy, sx;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				cin >> map[i][j];
				if(map[i][j]==2){
					sy = i;
					sx = j;
				}
			}
		}
		
		cout << search(sy, sx, 1, map) << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
n = int(input())
list_a = list(map(int, input().split()))
count = 0
while True:
  sub_list = [int(one_a / 2) for one_a in list_a if one_a % 2 == 0]
  if len(list_a) == len(sub_list):
    count += 1
    list_a = sub_list
  else:
    print(count)
    exit()

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#define max 200000
int main()
{int n,a[max],i,k=0,t;
scanf("%d",&n);
for(i=0;i<n;i++)
	scanf("%d",&a[i]);
t=0;
for(i=0;i<n;i++)
	if(a[i]==t+1)
	t=t+1;
	else
	k++;
if(t==0)
printf("-1");
else
printf("%d",k);
}

Measured memory_bytes: 896
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))

a = sorted(A, reverse=True)
b = []

i = 0
while i<N-1:
    if ( a[i]==a[i+1] ):
        b+=[a[i]]
        i+=2
    else:
        i+=1
    if (len(b)>1):
        break

if (len(b)<2):
    print(0)
else:
    print(b[0]*b[1])

Measured memory_bytes: 14244
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#define MAX 10000000

struct  node {
	int  key;
	struct node *parent;
	struct node *right;
	struct node *left; 
} ;
typedef struct node * Node;

Node root, noParent;

void insert (int k) {
	 Node y = noParent;
	 Node x = root;
	 Node z;
	
	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = noParent;
	z->right = noParent;
	
	while(x != noParent){
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
		z->parent = y;
		
		if(y == noParent) {
			root = z;
		} else {
			if (z->key < y->key) {
				y->left = z;
			} else y->right = z;
	}
}

void inorder (Node x){
	if(x == noParent) return;
	inorder(x->left);
	printf(" %d",x->key);
	inorder(x->right);
}

void preorder (Node x){
	if(x == noParent) return;
	printf(" %d",x->key);
	preorder(x->left);
	preorder(x->right);
}

int main(){
  int i,n,a;
  char sentence[20];

	scanf("%d", &n);
	for(i=0;i < n;i++){
		scanf("%s",sentence);
		if( strcmp(sentence, "insert") == 0) {
			scanf("%d",&a);
			insert(a);
		} else if(strcmp(sentence,"print") == 0) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}	
	return 0;
}


Measured memory_bytes: 25300
n,m,t=map(int,input().split())

grid=[]

row=[0]*n
col=[0]*m

for _ in range(t):
    x,y=map(int,input().split())
    grid.append((x-1,y-1))
    row[x-1]+=1
    col[y-1]+=1

prow=[]
pcol=[]
qr=max(row)
for i in range(n):
    if row[i]==qr :
        prow.append(i)

qc=max(col)
for i in range(m):
    if col[i]==qc :
        pcol.append(i)

num=len(prow)*len(pcol)
ans=qr+qc
for i in grid:
    if row[i[0]]==qr and col[i[1]]==qc :
        num-=1
if num>0:
    print(ans)
else:
    print(ans-1)

Measured memory_bytes: 152348
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=1e5+5;

int t,n,a[N],b[N],c[N],mem[N][5],k;

int dp(int pos,int last)
{
    if (pos==n)return 0;
    if (mem[pos][last]!=-1)return mem[pos][last];
    int ans=-1e9;
    if (last!=1)ans=max(ans,a[pos]+dp(pos+1,1));
    if (last!=2)ans=max(ans,b[pos]+dp(pos+1,2));
    if (last!=3)ans=max(ans,c[pos]+dp(pos+1,3));
    return mem[pos][last]=ans;
}

int main()
{
    t=1;
    while(t--)
    {
        memset(mem,-1,sizeof mem);
        cin >> n;
        for (int i=0;i<n;i++)
        {
            cin >> a[i] >> b[i] >> c[i];
        }
        cout << dp(0,4) << endl;
    }
}


Measured memory_bytes: 8064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o; for (auto e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

//pair?????????
template<typename T1, typename T2>
ostream &operator << (ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; }

//??§?¨???§???
//v: ??§???????????§?¨??????? ????????????
template<typename T>
void compress(vector<T> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

//??§?¨???§???(map)
//v: ??§???????????§?¨??????? ????????????
//?????????: zip[??§???????????§?¨?]:??§???????????§?¨? (zip.size()<=10^5?????????????????????)
template<typename T>
map<T, T> compressMap(vector<T> &v) {
	map<T, T> zip;
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (T i = 0; i < v.size(); i++) zip[v[i]] = i;
	return zip;
}

//??§???????????§?¨?
//index(??§???????????§?¨?, ??§???????????§?¨??????????(??????) )
//template<typename T>
//int index(vector<T> v, T i) { return lower_bound(v.begin(), v.end(), i) - v.begin(); }
#define index(v,i) lower_bound((v).begin(), (v).end(), (i)) - (v).begin();

//2?¬????imos???
class Imos {
public:
	using vvi = vector<vector<int> >;
	int X, Y;
	vvi s; //?´???????
	//f:field
	Imos(vvi &f) {
		X = f.size();
		Y = f[0].size();
		//one-based
		//(x,y)?????§????´??????????(x+1,y+1)
		s = vvi(X + 1, vector<int>(Y + 1));
		for (int y = 0; y < Y; y++)
			for (int x = 0; x < X; x++)
				s[x + 1][y + 1] += s[x + 1][y] + s[x][y + 1] - s[x][y] + f[x][y];
	}
	//[x1,x2)??????[y1,y2)???field??????????±???????
	//one-based????????????????§?
	int sum(int x1, int y1, int x2, int y2) { return s[x2][y2] - s[x2][y1] - s[x1][y2] + s[x1][y1]; }
};

int main() {
	int n, m; cin >> n >> m;
	vector<int> xs(n), ys(n);
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &xs[i], &ys[i]);
		x[i] = xs[i]; y[i] = ys[i];
	}
	compress(x);
	compress(y);

	//map<int, int> zipx(compressMap(x));
	//map<int, int> zipy(compressMap(y));
	//dump(x);
	//dump(zipx);
	//dump(y);
	//dump(zipy);

	vector<vector<int> > f(x.size(), vector<int>(y.size()));

	for (int i = 0; i < n; i++) {
		int vx = index(x, xs[i]);
		int vy = index(y, ys[i]);
		f[vx][vy]++;
	}

	//for (int vx = 0; vx < x.size(); vx++) dump(f[vx]);

	Imos imos(f);

	for (int i = 0; i < m; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		x1 = index(x, x1);
		y1 = index(y, y1);
		x2 = index(x, x2 + 1); //Imos???sum???one-based?????????+1
		y2 = index(y, y2 + 1);
		cout << imos.sum(x1, y1, x2, y2) << endl;
	}
	return 0;
}


//Sample2
//https://gyazo.com/39c67d1abe7a6a686acb52285f8a0bc9

Measured memory_bytes: 198800
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

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

using namespace std;

struct Node{
  int data;
  Node *parent,*left,*right;
};

Node *root;

bool find(int a){
  Node *r = root;
  while(r != NULL){
    if(r->data == a){
      return true;
    }
    else if(a < r->data){
      r = r->left;
    }
    else {
      r = r->right;
    }
  }
  return false;
}

void insert(int a){
  Node *root_tmp = root;
  Node *elem;

  elem = (Node *)malloc(sizeof(Node));
  elem->data = a;
  elem->left = NULL;
  elem->right = NULL;

  Node *prev = NULL;

    while(root_tmp != NULL){
      prev = root_tmp;
      if(elem->data < root_tmp->data){
	root_tmp = root_tmp->left;
      }
      else {
	root_tmp = root_tmp->right;
      }
    }

    elem->parent = prev;

    if(elem->parent == NULL){
      root = elem;
    }
    else{
        if(elem->parent->data < elem->data){
      elem->parent->right = elem;
    }
    else {
      elem->parent->left = elem;
    }
  }
}

void preorder(Node *u){
  if(u == NULL) return;
  cout << " " << u->data;
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node *u){
  if(u == NULL) return;
  inorder(u->left);
  cout << " " << u->data;
  inorder(u->right);
}

 signed main(){
  int n;
  string command;
  int elem;

  cin >> n;
  rep(i,n){
    cin >> command;
    if(command == "insert"){
      cin >> elem;
      insert(elem);
    }
    else if(command == "find"){
      cin >> elem;
      if(find(elem)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else{
      inorder(root);
      cout << "\n";
      preorder(root);
      cout << "\n";
    }
  }
}

  



Measured memory_bytes: 21884
#include <iostream>
using namespace std;
int main() {
    int A, B, X;
    cin >> X >> A >> B;
    if (A >= B) {
        cout << "delicious" << endl;
    } else if (A + X >= B) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define ll long long
int main()
{
    ll t,n,i,j,k,l,m,f,a,b,c,d,s;
    string s1,s2,s3;
    cin>>a>>b;
    b*=2;
    if(a>b){cout<<a-b<<endl;}
    else{cout<<0<<endl;}
    return 0;
}


Measured memory_bytes: 256
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=100;
int n,val[NMAX];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	for(int i=0;i<n;i++) cin >> val[i];
	
	sort(val,val+n);
	
	int compteur=1,i=1;
	
	while(n>i){
		if(val[i]!=val[i-1]) compteur++;
		i++;
	}
	
	cout << compteur << '\n';
	
	
}

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;
typedef pair<int,int> P;

int d[30][30];

int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s; cin>>s;
        string t;
        if(count(s.begin(),s.end(),'.')!=0){
            while(s.back()!='.'){
                t.push_back(s.back());
                s.pop_back();
            }
            s.pop_back();
            reverse(t.begin(),t.end());
        }
        while((int)t.size()<9)t.push_back('0');
        ll x=stoi(s)*1000000000LL+stoi(t);
        int two=0,five=0;
        while(x%2==0){
            x/=2;
            two++;
        }
        while(x%5==0){
            x/=5;
            five++;
        }
        if(two>18)two=18;
        if(five>18)five=18;
        d[two][five]++;
    }
    ll ans=0;
    rep(i,19)rep(j,19)rep(k,19)rep(l,19){
        if(i+k<18||j+l<18)continue;
        if(i==k&&j==l){
            ans+=(ll)d[i][j]*(d[k][l]-1);
        }
        else{
            ans+=(ll)d[i][j]*d[k][l];
        }
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 3580
n, m, x, y = map(int, input().split())
xlst = list(map(int, input().split()))
ylst = list(map(int, input().split()))
xlst += [x]
ylst += [y]
xmax = max(xlst)
ymin = min(ylst)
if xmax < ymin:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		fill(ALL(dist),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in();
	ConnectNodeInfo connect(N);
	REP(i,M){
		string S=in<string>();
		int a,b,c,d;
		sscanf(S.c_str(),"%d,%d,%d,%d",&a,&b,&c,&d);
		connect.AddDirectionalConnection(a-1,b-1,c);
		connect.AddDirectionalConnection(b-1,a-1,d);
	}
	string S=in<string>();
	int s,g,V,P;
	sscanf(S.c_str(),"%d,%d,%d,%d",&s,&g,&V,&P);

	Dijkstra Dij;
	Dij.CalcShortestPath(s-1,connect);
	auto dist1 = Dij.GetDistance(g-1);
	Dij.CalcShortestPath(g-1,connect);
	auto dist2 = Dij.GetDistance(s-1);

	out(V-P-dist1-dist2);
	return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;



 
int main(){
    ll N, C, K; cin >> N >> C >> K;

    vector<ll> T(N); for(int i = 0; i < N; i++) cin >> T[i];
    sort(T.begin(), T.end());
    queue<ll> Q; 
    for(int i = 0; i < N; i++) Q.push(T[i]);
    ll ans = 0;
    while(!Q.empty()){
        ans++;
        ll time = Q.front() + K;
        Q.pop();
        for(int i = 0; i < C-1; i++){
            if(!Q.empty()){
                if(Q.front() <= time)Q.pop();
                else break;
            } 
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
using namespace std;
int str_num(string xx){
	int nn=0;
	for(int i=0;i<xx.size();i++){
		nn=nn*10+(xx[i]-'0');
	}
	return nn;
}
string a,b;
int main(){
	cin >> a >> b;
	a=a+b;
	int n=str_num(a);
	if(n==(int)(sqrt(n))*(int)(sqrt(n))){
		cout << "Yes";
	}else{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
main = getContents >>= putOut.formatOut.map calc.formatIn
  where putOut s | last s == '\n' = putStr s
                 | otherwise      = putStrLn s

formatIn :: String -> [[Int]]
formatIn = map ((map (read :: String -> Int)).words).takeWhile (/="0 0").lines

formatOut :: [String] -> String
formatOut = unlines

calc :: [Int] -> String
calc (h:w:_) = unlines $replicate h (replicate w '#')

Measured memory_bytes: 6036
#include <bits/stdc++.h>
#define tt this->
#define ll long long
using namespace std;
int main ()
{
long long x,score=0;
cin>>x;
while (x>=5)
{
    if (x>=500)
    {
        x=x-500;
        score=score+1000;
    }
    else if (x<500)
    {
        x=x-5;
        score=score+5;
    }

}

cout<<score<<endl;
    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    string s,t; cin >> s >> t;

    int ans = 0;
    REP(i,s.size()) {
        if (s[i] == t[i]) ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def get_det(a, b, c):
    a1, a2, a3 = a
    b1, b2, b3 = b
    c1, c2, c3 = c
    return a1 * b2 * c3 + a3 * b1 * c2 + a2 * b3 * c1 \
            - a3 * b2 * c1 - a2 * b1 * c3 - a1 * b3 * c2

def solve():
    import sys
    f_i = sys.stdin
    
    Sx, Sy, Sz = map(int, f_i.readline().split())
    Ex, Ey, Ez = map(int, f_i.readline().split())
    B1x, B1y, B1z = map(int, f_i.readline().split())
    B2x, B2y, B2z = map(int, f_i.readline().split())
    B3x, B3y, B3z = map(int, f_i.readline().split())
    
    a = (B2x - B1x, B2y - B1y, B2z - B1z)
    b = (B3x - B1x, B3y - B1y, B3z - B1z)
    c = (Sx - Ex, Sy - Ey, Sz - Ez)
    
    detA = get_det(a, b, c)
    
    # the barrier looks like a line segment
    if detA == 0:
        print("HIT")
        return
    
    d = (Sx - B1x, Sy - B1y, Sz - B1z)
    
    s = get_det(d, b, c)
    t = get_det(a, d, c)
    u = get_det(a, b, d)
    if detA > 0:
        if s >= 0 and t >= 0 and s + t <= detA and 0 <= u <= detA:
            print("MISS")
        else:
            print("HIT")
    else:
        if s <= 0 and t <= 0 and s + t >= detA and detA <= u <= 0:
            print("MISS")
        else:
            print("HIT")

solve()


Measured memory_bytes: 5616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    FOR(i,1,b){
        if (a * i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }  
    cout << "NO" << endl;
    return 0;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll h,n;
    cin >> h >> n;
    vector<ll> a(n);
    ll sum = 0;

    rep(i,n)
    {
        cin >> a[i];
    }
    rep(i,n)
    {
        sum+= a[i];
    }

    if (sum>=h)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    

}

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

int main(){
	int N;
	int a[110];
	cin >> N;
	for(int i = 0; i < N; ++i) cin >> a[i];
	int ave = round(accumulate(a, a+N, 0.0) / N);
	int ans;
	for(int i =0; i < N; ++i){
		ans += pow((ave - a[i]),2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
monster = list(map(int, input().split()))
hero = list(map(int, input().split()))

count = 0
for i in range(N):
  k = min(monster[i], hero[i])
  l = min(monster[i+1], hero[i]-k)
  count += k+l
  monster[i+1] -= l
print(count)    

Measured memory_bytes: 19116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);

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

    int S = (a + b) * h / 2;

    cout << S << endl;

    return 0;
    
}

Measured memory_bytes: 256
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)
def factorize(n):
    f=[]
    p=2
    while p**2<=n:
        while n%p==0:
            n=n//p
            f.append(p)
        p+=1
    if n!=1:
        f.append(n)
    return f

def main():
    a,b=map(int,input().split())
    g=gcd(a,b)
    F=factorize(g)
    print(len(set(F))+1)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 38512
N,A,B=map(int,input().split())
SUM=0

for i in range(N+1):
  output=0
  c=i
  for p in range(4,-1,-1):
    order=int(c/10**p)
    c=c-order*10**p
    output+=order
  if output>=A and output<=B:
    #print(i)
    SUM+=i
    
print(SUM)



Measured memory_bytes: 3060
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
  ans+=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i]+a[i+1]>x:
    ans+=a[i]+a[i+1]-x
    a[i+1]=x-a[i]
print(ans)

Measured memory_bytes: 14252
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

former = -10
satisfy = 0
for i in a:
    satisfy += b[i-1]
    if i == former + 1:
        satisfy += c[i-2]
    former = i
print(satisfy)

Measured memory_bytes: 3064
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int N = cin(); string S = ReadStr(); int K = cin();
    char keep = S[K-1];
    string ans = "";
    for (int i = 0; i < N; i++) {
      if (S[i] == keep) {
        ans += keep.ToString();
      } else {
        ans += "*";
      }
    }
    Console.WriteLine(ans);
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 11348
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		execute2();
	}
	
	private static void execute2() {
		try (Scanner sc = new Scanner(System.in)) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			String[] a = new String[H];
			int[] di = {0,-1,1,0};
			int[] dj = {1,0,0,-1};
			
			for(int i=0; i<H;i++) {
				a[i] = sc.next();
			}
			
			
			
			int ans = 0;
			for(int i =0; i<W; i++) {
				for(int j=0;j<H;j++) {
					int maxdist = 0;
					int dist[][] = new int[H][W];
					for(int m=0;m<H;m++) {
						for(int n=0;n<W;n++) dist[m][n]=Integer.MAX_VALUE;
					}
					
					char c = a[j].charAt(i);
					if(c=='#') continue;
					Queue<List<Integer>> q = new ArrayDeque<>();
					q.add(Arrays.asList(j,i));
					dist[j][i]=0;
					while(!q.isEmpty()) {
						List<Integer> l=q.poll();
						int nj= l.get(0);
						int ni = l.get(1);
						maxdist = Math.max(maxdist, dist[nj][ni]);
						for(int d=0;d<4;++d) {
							int mj=nj+dj[d];
							int mi=ni+di[d];
							if(mj>=H||mj<0||mi>=W||mi<0) continue;
							if(a[mj].charAt(mi)=='.' && dist[mj][mi]==Integer.MAX_VALUE) {
								q.add(Arrays.asList(mj,mi));
								dist[mj][mi] = dist[nj][ni]+1;
							}
						}
					}
					ans = Math.max(ans, maxdist);
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 33284
def main():

    H, W, M = map(int, input().split())
    h_dic = [0] * H
    w_dic = [0] * W
    boms = set()
    for _ in range(M):
        h, w = map(int, input().split())
        h, w = h-1, w-1
        h_dic[h] += 1
        w_dic[w] += 1
        boms.add((h, w))

    hmax = max(h_dic)
    wmax = max(w_dic)

    h_maxs = [idx for idx, v in enumerate(h_dic) if v==hmax]
    w_maxs = [idx for idx, v in enumerate(w_dic) if v==wmax]

    # 爆弾数はたかだか3*10~5なので、総当りで解ける
    for h in h_maxs:
        for w in w_maxs:
            if (h, w) not in boms:
                print(hmax + wmax)
                return
    print(hmax + wmax - 1)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 176972
# -*- coding: utf-8 -*-

N = int(input())
aN = list(map(str, input().split()))

done = False
cnt = 0
while not done:
    done = True
    for i in range(N-1, 0, -1):
        if int(aN[i]) < int(aN[i-1]):
            tmp = aN[i]
            aN[i] = aN[i-1]
            aN[i-1] = tmp
            done = False
            cnt += 1
print(' '.join(aN))
print(cnt)



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

int main()
{
	int a,b;
	int A[] = {1,3,5,7,8,10,12};
	int B[] = {4,6,9,11};
	int C = 2;
	cin >> a >> b;
	
	if(a == b && a == C){
		cout << "Yes" << endl;
		return 0;
	}
	int f1=0;
	for(auto i: A){
		if(a == i){
			f1++;
		}
		if(b == i){
			f1++;
		}
		if(f1 == 2){
			cout << "Yes" << endl; 
			return 0;
		}
	}
	
	int f2 = 0;
	for(auto i: B){
		if(a == i){
			f2++;
		}
		if(b == i){
			f2++;
		}
		if(f2 == 2){
			cout << "Yes" << endl; 
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
 int n,l,r;
 cin>>n>>l>>r;
 if(n==0)return 0;
 V<int> a(n);
 for(int i=0;i<n;i++)cin>>a[i];
 int ans=0;
 for(int i=l;i<=r;i++){
   int j;
   for(j=0;j<n;j++){
     if(i%a[j]==0)break;
   }
   if(j%2==0)ans++;
 }
 cout<<ans<<"\n";
}
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(void)
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>>in(h);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char tmp;
            cin >> tmp;
            in[i].push_back(tmp);
        }
    }

    int row = pow(2, h);
    int col = pow(2, w);
    int ans = 0;
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            vector<vector<char>>tmp_in = in;
            for (int k = 0; k < h; k++)
            {
                int shifted = i >> k;
                int lastbit = shifted & 1;
                if (lastbit == 1)
                {
                    for (int l = 0; l < w; l++) 
                    {
                        tmp_in[k][l] = 'r';
                    }
                }
            }

            for (int k = 0; k < w; k++)
            {
                int shifted = j >> k;
                int lastbit = shifted & 1;
                if (lastbit == 1)
                {
                    for (int l = 0; l < h; l++)
                    {
                        tmp_in[l][k] = 'r';
                    }
                }
            }

            int blackCnt = 0;
            for (int k = 0; k < h; k++)
            {
                for (int l = 0; l < w; l++)
                {
                    if (tmp_in[k][l] == '#') blackCnt++;
                }
            }

            if (blackCnt == k)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4076
#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 n, k;
    cin >> n >> k;
    vector<int> snk(n); 
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a; --a;
            snk[a] = 1;
        }
    }
    int cnt = 0;
    rep(i,n){
        if(snk[i] == 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

struct Edge {
    int from;
    int to;
    int weight;
    Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {
    }
    
    int other(int u) {
        return u == from ? to : from;
    }
};

struct TreeDepth {
    int n;
    vector<vector<int>> g;
    vector<Edge> edges;
    int bestDist;
    int bestNode;
  
    TreeDepth(int n) : n(n) {
        g.assign(n, vector<int>());
    }
    
    void addEdge(int from, int to, int w) {
        edges.push_back(Edge(from, to, w));
        g[from].push_back(edges.size() - 1);
        g[to].push_back(edges.size() - 1);
    }
    
    int solve(vector<int>& ans) {
        
        bestDist = 0;
        bestNode = -1;
        vector<int> dists(n);
        dfs(0, -1, 0, dists);
        
        bestDist = 0;
        //cout << "X" << bestNode << endl;
        vector<int> distsX(n);
        dfs(bestNode, -1, 0, distsX);
        
        bestDist = 0;
        //cout << "Y" << bestNode << endl;
        vector<int> distsY(n);
        dfs(bestNode, -1, 0, distsY);
        
        for (int i = 0; i < n; i++) {
           ans[i] = max(distsX[i], distsY[i]); 
        }
        return bestDist;
    }
     
    void dfs(int u, int p, int d, vector<int>& dists) {
        if (d > bestDist) {
            bestDist = d;
            bestNode = u;
        }
        dists[u] = d;
        for (int e : g[u]) {
            Edge edge = edges[e];
            int v = edges[e].other(u);
            if (v != p) {
                dfs(v, u, d +  edge.weight, dists);
            }
        }
    }   
};

int main() {
    int n;
    cin >> n;
    
    TreeDepth d(n);
    for (int i = 0; i < n - 1; i++) {
        int from, to, w;
        cin >> from >> to >> w;
        d.addEdge(from, to, w);
    }
    vector<int> ans(n);
    d.solve(ans);
    
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

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

const int N=1e5+5;
int A[N], B[N], C[N];
long long D[N];
int main() {
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++) scanf("%d", &A[i]);
	for(int i=0; i<n; i++) scanf("%d", &B[i]);
	for(int i=0; i<n; i++) scanf("%d", &C[i]);
	sort(A, A+n);
	sort(B, B+n);
	sort(C, C+n);
	int j=0;
	for(int i=0; i<n; i++) {
		while(j<n && B[i]>=C[j]) j++;
		D[i]+=n-j;
	}
	for(int i=n-2; i>=0; i--) D[i]+=D[i+1];
	// for(int i=0; i<n; i++) printf("%d ", D[i]); puts("");
	j=0;
	long long ans=0;
	for(int i=0; i<n; i++) {
		while(j<n && A[i]>=B[j]) j++;
		ans+=D[j];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    int n;
    cin >> n;

    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "data"
using namespace std;
typedef long long LL;
typedef double DB;
typedef pair <LL, LL> pLL;
const int NMAX = 1e5+3;
const long long MOD = 1e9+7;

int n, a[2009];
LL res, k;

LL calc(LL x, LL y) {
    y = y * k % MOD;
    x = (k * (k-1) / 2) % MOD * x % MOD;
    return (x + y) % MOD;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> n >> k;
    /*for(int i = 0; i < n; ++i) 
        cin >> a[i];
    for(int i = 0; i < n*k; ++i) 
    for(int j = i+1; j < n*k; ++j) {
        int x = a[i%n];
        int y = a[j%n];
        if(x > y) res++;
    }
    cout << res;
    return 0;*/

    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i) {
        LL x = 0, y = 0;
        for(int j = 1; j <= n; ++j) {
            if(a[i] > a[j]) {
                x++;
                if(j > i) y++;
            }
        }
        //cerr << x << ' ' << y << ' ' << calc(x, y) << endl;
        res = (res + calc(x, y)) % MOD;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc045c()
}

fun abc045c() {
    val s = readLine()!!
    if (s.length == 1) return println(s)

    val answer = (0..bits(s.length - 1)).map { i ->
        val expression = listOf(s.first().toString()) +
                s.drop(1).withIndex().map { (if ((i shr it.index) % 2 == 0) "+" else "") + it.value.toString() }
        expression.joinToString("").split("+").map { it.toLong() }.sum()
    }.sum()

    println(answer)
}

private fun bits(x: Int): Int {
    var ret = 1
    repeat(x) { ret *= 2 }
    return ret - 1
}


Measured memory_bytes: 39056
# input_first= 5
# input_second=[2,6,1,4,5] 
input_first = input()
input_second= input().split()
N = int(input_first)
in_list = [int(i) for i in input_second]


check_dic = {}
flag  =0
for i in in_list:
    if i in check_dic.keys():
        # print(i)
        print("NO")
        flag = 1
        break
    else:
        check_dic[i] = True
    

# print(check_dic)
if flag ==0:
    print("YES")

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


int n;
int mat[100005][3];
int dp[100005][3]={0};

void func(){
    for(int i=0;i<3;i++){
        dp[0][i]=mat[0][i];
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int maxi=INT_MIN;
            for(int k=0;k<3;k++){
                if(k!=j)
                  maxi=max(maxi,dp[i-1][k]);
            }
            dp[i][j]=mat[i][j]+maxi;
        }
    }


    int ans=INT_MIN;
    for(int i=0;i<3;i++){
        ans=max(ans,dp[n-1][i]);
    }

    cout<<ans<<endl;
}


int main(){



   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
   #endif
   cin>>n;
   for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
        cin>>mat[i][j];
      }
   }
   func();
}

Measured memory_bytes: 5940
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    let mut ans = 0;
    for i in 0..n {
        aseq[i] = read::<usize>();
        let mut v = aseq[i];
        while v % 2 == 0 {
            v /= 2;
            ans += 1;
        }
    }
    println!("{}", ans);
}


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


const int MAXN = 312;
const int MAXV = (MAXN * MAXN);
const long long MOD = 998244353;

int n;
int s;
int v[MAXN];
long long memo[MAXN][MAXV];

long long solve (int x, int sum) {
	if (x == n) return (sum >= s - sum);

	long long & p = memo[x][sum];
	if (p + 1) return p;

	p = 0;
	p += solve (x + 1, sum + v[x]);
	p += 2LL * solve (x + 1, sum);
	
	while (p >= MOD) p -= MOD;

	return p;
}

long long solve2 (int x, int sum) {
	if (x == n) return (sum == s - sum);

	long long & p = memo[x][sum];
	if (p + 1) return p;

	p = 0;
	p += solve2 (x + 1, sum + v[x]);
	p += solve2 (x + 1, sum);
	
	while (p >= MOD) p -= MOD;

	return p;
}

int main () {

	cin >> n;

	long long p3 = 1;

	for (int i = 0; i < n; ++i) {
		scanf ("%d", v + i);
		s += v[i];
		p3 *= 3;
		p3 %= MOD;
	}

	memset (memo, -1LL, sizeof memo);
	long long ans = solve (0, 0);
	memset (memo, -1LL, sizeof memo);
	ans -= solve2 (0, 0);
	ans *= 3LL;
	ans %= MOD;
	ans = p3 - ans;
	while (ans < 0) ans += MOD;
	ans %= MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 237568
#include <stdio.h>
#include <string.h>
int main(void) {
  char s[7][10] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  char t[10];
  int i;
  scanf("%s", t);
  
  for(i = 0; i < 7; i++) if(strcmp(t, s[i]) == 0) break;
  
  printf("%d\n", 7-i);
  
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
n = int(input())
h = list(map(int, input().split()))
counter = 0
for i in h:
    if counter == 0:
        counter = counter + 1
        max_h = i
    else:
        if max_h <= i:
            counter = counter + 1
            max_h = i
        else:
            pass
print(counter)

Measured memory_bytes: 2940
while True:
	table=input().split()
	a=int(table[0])
	op=table[1]
	b=int(table[2])
	if op=='?':
		break
	if op=='+':
		ans=a+b
		print(ans)
	elif op=='-':
		ans=a-b
		print(ans)
	elif op=='*':
		ans=a*b
		print(ans)
	elif op=='/':
		ans=a//b
		print(ans)

	




Measured memory_bytes: 5592
function main(input) {
  const args = input.split("\n");
  const [N, K] = args[0].split(" ").map((n) => parseInt(n, 10));
  const sunukes = new Array(N).fill(false);

  for (let i = 2; i <= K * 2; i += 2) {
    args[i].split(" ").map((n) => parseInt(n, 10))
      .map((A) => { sunukes[A - 1] = true; });
  }

  console.log(sunukes.reduce((num, sunuke) => sunuke ? num : num + 1, 0));
}

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


Measured memory_bytes: 32048
#include<bits/stdc++.h>
#define int long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}

bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
}
signed main()
{
     // #ifndef ONLINE_JUDGE
     //    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
     //     #endif 
  int t=1;
  //cin>>t;
  while(t--){
  solve(); 
  cout<<"\n";
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  


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

#define Max(a,b) max({a,b})
#define Min(a,b) min({a,b})
#define rep(i,m,n) for(int (i)=(m);(i)<(int)(n);(i)++)
#define len(n) n.size()
#define print(n) cout << (n) << endl;


// s.substr(i,n)

typedef long long ll;

using namespace std;

//char a = 65;
long long int inf = 1000000007;
int n,m,a,b,c,d,cou,co,p;
long long int lla,llb,llc;
double k;
const ll LINF = 1e18;
char num = 65;
string s,t;
int li[20];
/*
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
*/
int w[400000];
int e[400000];
int an[400000] = {};

int main(){
    
    cin >> n;
    cou = 0;
    co = 0;
    cin >> s;

    w[0] = 0;
    e[n-1] = 0;
    int wcou = 0;

    for(int j = 1;j < n; j++){
        if(s[j-1] == 'W'){
            cou += 1;
            wcou += 1;
        }
        w[j] = cou;
        if(s[n-j] == 'E'){
            co += 1;
        }
        e[n-(j+1)] = co;
        an[j] += cou;
        an[n-(j+1)] += 0;
    }
    
    int ans = inf;
    

    rep(i,0,n) ans = min(ans,w[i]+e[i]);
    print(ans)


    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    
    int N = (int)S.size();
    
    bool check = true;
    
    for(int i = 0;i < N;i++)
    {
        if(S[i] != S[N -1 - i])
        {
            check = false;
            break;
        }
    }
    
    if(check)
    {
        for(int i = 0;i <N/2;i++)
        {
            if(S[i] != S[N/2 -1 - i])
            {
                check = false;
                break;
            }
            if(S[i + N/2 + 1] != S[N - 1 - i])
            {
                check = false;
                break;
            }
        }
    }
    
    if(check)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    //cout << ans << endl;
    
    return 0;
}

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

using namespace std;
typedef long long ll;
const int N = 110;
int _w;

int n, k, change[N], c1, c0;
char s[N];

int solve1() {
	int ans = 0;
	for( int i = 2; i <= n; ++i ) {
		if( s[i] == s[i-1] ) {
			change[i] = true;
			++i;
			++ans;
		}
	}
	return c1 = ans;
}

int solve2() {
	memset(change, 0, sizeof change);
	s[0] = s[n];
	int ans = 0;
	for( int i = 1; i <= n; ++i ) {
		if( s[i] == s[i-1] ) {
			change[i] = true;
			++i;
			++ans;
		}
	}
	return c0 = ans;
}

ll solve() {
	solve1();
	if( change[n] ) {
		return ll(k) * c1;
	} else {
		solve2();
		if( change[n] ) {
			return c0 * ll(k/2) + c1 * ll(k-k/2);
		} else {
			return c1 + ll(k-1) * c0;
		}
	}
}

int main() {
	_w = scanf( "%s", s+1 );
	n = (int)strlen(s+1);
	_w = scanf( "%d", &k );
	printf( "%lld\n", solve() );
	return 0;
}


Measured memory_bytes: 3700