akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define name(x) #x
using namespace std;


const int INF = INT_MAX;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

template< typename T >
using Edges =vector< edge<T> >;
template< typename T >
using WeightedGraph =vector< Edges<T> >;
using UnWeightedGraph =vector< vector<int> >;
template< typename T >
using Matrix =vector< vector<T> >;


const int MAX_SIZE = 100005;
ll memo[MAX_SIZE][2];
int visited[100005];
int N;
VV(int) a;
UnWeightedGraph G;


ll rec(int parent, int x, int col){
    //メモ化処理
    if(visited[x] == 2){
        return memo[x][col];
    }
    
    ll& ret = memo[x][col];
    ret = 1;
    visited[x] +=1;
    
    //基底
    auto flag = false;

    for(auto v: G[x]){
        
        if (v == parent) continue;
        
        flag = true;
        
        if (col == 0){
            ret *= rec(x,v,1);
        }else{
            ret *= rec(x,v,0) + rec(x,v,1);
        }
        ret %= MOD;
    }
    
    
    return ret;
}


int main() {
    cin >> N;
    int s, t;
    G.resize(N+1);
    for(auto i = 1; i<N; i++){
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
        
    }
    
    cout << (rec(0,1,1) + rec(0,1,0))%MOD << endl;
    
 
    return 0;
}




Measured memory_bytes: 17408
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

static vector<vector<int>> g;
static vector<int> ans;
static vector<bool> visited;
static vector<int> c;

void walk(int e, int cnt) {
  ans[e] = cnt;
  visited[e] = true;
  for (auto i : g[e]) {
    if (!visited[i]) {
      walk(i, cnt + c[i]);
    }
  }
  return;
}

void solve(int n) {
  ans.resize(n + 1, 0);
  visited.resize(n + 1, false);
  walk(1, c[1]);
  for (int i = 1; i < n; i++) {
    printf("%d ", ans[i]);
  }
  printf("%d\n", ans[n]);
}

int main() {
  int n, q;
  cin >> n >> q;
  g.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  c.resize(n + 1, 0);
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    c[p] += x;
  }
  solve(n);
  return 0;
}

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

void solve(){
	long long  a;
	long double b;
	cin>>a>>b;
	long long res=(a*b);
	cout<<res;
	
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}


Measured memory_bytes: 3736
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(b%a==0){
		cout << b+a << endl;
	}else{
		cout << b-a << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
N, x=input().split()
N=int(N)
x=int(x)
#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 elif i==N-1 and x!=0:
    break 
 else:
     j=j+1

print(j)


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005,mod=1e9+7;
int n,m,c[N],k,lst,f[N],pfx[N],ans; char s[N];
inline int sum(CI x,CI y)
{
	int t=x+y; return t>=mod?t-mod:t;
}
namespace SP //one char solver
{
	int f[N][2][2];
	inline int solve(void)
	{
		f[1][0][0]=f[1][1][1]=1; for (RI i=2;i<=n;++i)
		f[i][0][0]=sum(f[i-1][0][0],f[i-1][0][1]),f[i][0][1]=f[i-1][0][0],
		f[i][1][0]=sum(f[i-1][1][0],f[i-1][1][1]),f[i][1][1]=f[i-1][1][0];
		return sum(f[n][0][0],sum(f[n][0][1],f[n][1][0]));
	}
};
int main()
{
	RI i; for (scanf("%d%d%s",&n,&m,s+1),lst=1,i=2;i<=m;++i)
	if (s[i]!=s[i-1]) c[++k]=i-lst,lst=i; c[++k]=n-lst+1;
	if (k==1) return printf("%d",SP::solve()),0; if (n&1) return puts("0"),0;
	if (k&1) --k; int lim=c[1]+!(c[1]&1); for (i=3;i<=k;i+=2) if (c[i]&1) lim=min(lim,c[i]);
	for (n>>=1,lim=lim+1>>1,f[0]=pfx[0]=i=1;i<=n;++i)
	f[i]=sum(pfx[i-1],mod-(i-1-lim>=0?pfx[i-1-lim]:0)),
	pfx[i]=sum(pfx[i-1],f[i]); for (i=1;i<=min(n,lim);++i)
	ans=sum(ans,2LL*f[n-i]*i%mod); return printf("%d",ans),0;
}

Measured memory_bytes: 7008
#include <iostream>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  int R[60] = {0};

  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    ++R[a];
    ++R[b];
  }

  for (int i = 1; i <= N; ++i) {
    cout << R[i] << endl;
  }

  return 0;
}


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

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

using namespace std;
using ll = long long;

ll dist[301][301];
ll dist2[301][301];

int main() {
	int N, M, L;
	cin >> N >> M >> L;

	rep(i, N) rep(j, N) dist[i][j] = dist2[i][j] = INF;

	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if (c >= dist[a][b]) continue;
		dist[a][b] = c;
		dist[b][a] = c;
	}

	rep(k, N) rep(i, N) rep(j, N) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}

	rep(i, N) rep(j, N) {
		if (i != j && dist[i][j] <= L) dist2[i][j] = 1;
	}

	rep(k, N) rep(i, N) rep(j, N) {
		dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
	}

	int q;
	cin >> q;
	rep(i, q) {
		int s, t;
		cin >> s >> t;

		ll d = dist2[s - 1][t - 1];

		if (d == INF) { d = -1; }
		else { d -= 1; }

		cout << d << endl;
	}


	return 0;
}

Measured memory_bytes: 1920
#include<cstdio>
long int a,b,G,L,i,j;
long int gcd(long int a,long int b)
{    return(0==b?a:gcd(b,a%b));}
int main()
{
    while(scanf("%ld%ld",&a,&b)!=EOF)
    {
        G=gcd(a,b);
        i=a/G;
        L=b*i;
        printf("%ld %ld\n",G,L);
    }
    return 0;

}

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    char c[h][w];
    int black = 0;
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> c[i][j];
            if(c[i][j] == '#'){
                black++;
            }
        }
    }
    //bit全探索
    for(int bit1 = 0; bit1 < (1<<h); bit1++){
        for(int bit2 = 0; bit2 < (1<<w); bit2++){
            int sum = 0;
            bool d[h][w] = {};
            
            for(int i = 0; i < h; i++){
                if((bit1 >> i) & 1){
                    for(int j = 0; j < w; j++){
                        d[i][j] = 1;
                    }
                }
            }

            for(int i = 0; i < w; i++){
                if((bit2 >> i) & 1){
                    for(int j = 0; j < h; j++){
                        d[j][i] = 1;
                    }
                }
            }

            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(d[i][j] == 1 && c[i][j] == '#'){
                        sum++;
                    }
                    //cout << d[i][j];
                }
                //cout << endl;
            }
            //cout << endl;


            if(sum + k == black){
                ans++;
            }

        }
    }
    cout << ans << endl;

    return 0;
}





Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int xs,ys,xt,yt;cin >> xs >> ys >> xt >> yt;

    int dx=xt-xs,dy=yt-ys;

    cout << string(dy,'U') << string(dx,'R'); 
    cout << string(dy,'D') << string(dx,'L'); 
    cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D'; 
    cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U'; 
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void fmax(int&a,int b){
	if(b>a)a=b;
}
int s[2][1010][1010];
int get(int f,int x1,int y1,int x2,int y2){
	if(x1>x2||y1>y2)return 0;
	return s[f][x2][y2]-s[f][x1-1][y2]-s[f][x2][y1-1]+s[f][x1-1][y1-1];
}
int main(){
	int n,k,i,j,x,y,ans;
	char c[5];
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d%d%s",&x,&y,c);
		j=c[0]=='B';
		if((x/k+y/k)&1)j^=1;
		s[j][x%k+1][y%k+1]++;
	}
	for(i=1;i<=k;i++){
		for(j=1;j<=k;j++){
			s[0][i][j]+=s[0][i-1][j]+s[0][i][j-1]-s[0][i-1][j-1];
			s[1][i][j]+=s[1][i-1][j]+s[1][i][j-1]-s[1][i-1][j-1];
		}
	}
	ans=0;
	for(i=0;i<=k;i++){
		for(j=0;j<=k;j++){
			fmax(ans,s[0][i][j]+get(0,i+1,j+1,k,k)+s[1][i][k]-s[1][i][j]+s[1][k][j]-s[1][i][j]);
			fmax(ans,s[1][i][j]+get(1,i+1,j+1,k,k)+s[0][i][k]-s[0][i][j]+s[0][k][j]-s[0][i][j]);
		}
	}
	printf("%d",ans);
}

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

#define int long long
typedef pair<int, int> ii;
vector<ii> a;
int n;

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x, y;
		cin >> x >> y;
		a.push_back({y, x});
	}
	sort(a.begin(), a.end());
	int sum = 0;
	for(int i = 0; i < n; i++){
		sum += a[i].second;
		if(sum > a[i].first){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 6384
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
  int n, buf, min=1000001, max=-1000001;
  long sum=0;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> buf;
    if(min > buf)min=buf;
    if(max < buf)max=buf;
    sum+=buf;
  }
  cout << min << ' ' << max << ' ' << sum << endl;
  return 0;
}



Measured memory_bytes: 3112
N = int(input().rstrip())
numbers =[ int(i) for i in input().rstrip().split()]
   

n_dic = {str(i):0 for i in set(numbers)}


for i in numbers:
    n_dic[str(i)] += 1
  
count = 0

for i,j in n_dic.items():
    if int(i) < j:
        count += j - int(i)
    
    elif int(i) > j:
        count += j
        
print(count)

Measured memory_bytes: 28660
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;
   
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(B, N*A) << endl;

    return 0;
}

Measured memory_bytes: 256
s = str(input())
n = len(s)

ans = 'Yes'
if s != s[::-1]:
    ans = 'No'
elif s[:int((n-1)/2)] != s[:int((n-1)/2)][::-1]:
    ans = 'No'
elif s[int(((n+3)/2)-1):] != s[int(((n+3)/2)-1):][::-1]:
    ans = 'No'

print(ans)

Measured memory_bytes: 3064
fun main() {
    val k = readLine()!!.toInt()
    val ab = readLine()!!.split(" ").map { it.toInt() }
    val a = ab[0]
    val b = ab[1]
    var tmp = k
    while (tmp <= b) {
        if (a <= tmp) {
            println("OK")
            return
        }
        tmp += k
    }

    println("NG")
}



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

int main(){
    ll n,m;
    cin >> n >> m;
    ll sum = 0;
    ll a;
    for (ll i = 0; i < m; i++){
        cin >> a;
        sum += a;
    }
    cout << (sum <= n ? n - sum : -1) << endl;
}

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

typedef long long ll;
const int NMAX = 1e3 + 5;
const int MOD = 1e9 + 7;
char mmap[NMAX][NMAX];
int minn[NMAX][NMAX];

typedef struct Node
{
	int x,y,t;
	Node(int x,int y,int t):x(x),y(y),t(t){}
	bool operator < ( const Node& b)const
	{
		return t > b.t;   
	}

}Node;

int dir[4][2] = {0,-1,-1,0,0,1,1,0};

int main(int argc, char const *argv[])
{
	int h , w;
	int x1 , y1 , x2 , y2;
	scanf("%d%d",&h,&w);
	scanf("%d%d",&x1,&y1);
	scanf("%d%d",&x2,&y2);
	for(register int i = 1; i <= h;i++)
		scanf("%s",mmap[i] + 1);
	memset(minn,0x3f3f3f3f,sizeof(int)*NMAX*NMAX);
	priority_queue<Node> q;
	q.push(Node(x1,y1,0));
	while(!q.empty())
	{
		Node now  = q.top(); q.pop();
		// printf("%d %d %d\n",now.x,now.y,now.t );
		if(now.x == x2 && now.y == y2)
		{
			printf("%d\n", now.t);
			return 0;
		}
		for(register int i = -2;i <= 2;i++)
			for(register int j = -2;j <= 2;j++)
			{
				if(i == j && i == 0)	continue;
				int next_x = now.x + i;
				int next_y = now.y + j;
				if(next_x < 1 || next_x > h || next_y < 1 || next_y > w || mmap[next_x][next_y] == '#')
					continue;
				int delta = 1;
				for(register int k = 0;k < 4;k++)
				{
					if(i == dir[k][0] && j == dir[k][1])
						delta = 0;
				}
				if(minn[next_x][next_y] > now.t + delta)
				{
					minn[next_x][next_y] = now.t + delta;
					q.push(Node(next_x,next_y,now.t+delta));
				}
			}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 8700
int main(void) {
    int a, b;

    scanf("%d%d", &a, &b);
    int ans[3];

    ans[0] = a + b;
    ans[1] = a - b;
    ans[2] = a * b;

    int max = ans[0];
    if (max < ans[1]) max = ans[1];
    if (max < ans[2]) max = ans[2];

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 128
program prob4
    implicit none
    integer::N, i, j, ans, p, cnt
    integer, allocatable::A(:)
    read(*,*) N
    allocate(A(N))
    read(*,*) A

    ans = 1
    p = 0
    cnt = 0
    do i = 2, N
        if(p == 0) then
            if(A(i) > A(i-1)) then
                p = 1
                cnt = 1
            else if(A(i) < A(i-1)) then
                p = -1
                cnt = 1
            end if
        else
            if(p == 1) then
                if(A(i) < A(i-1)) then
                    p = 0
                    ans = ans + 1
                    cnt = 0
                end if
            else
                if(A(i) > A(i-1)) then
                    p = 0
                    ans = ans + 1
                    cnt = 0
                end if
            end if
        end if
    end do

    write(*,*) ans
    stop
end program

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

int main() {
  int N,A,a,b;
  cin >> N >> A;
  
  a = N % 500;
  b = N / 500;
  if(N <= 500){
    if(A >= N){
     cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (N >= 500){
   if(A >= a){
     cout << "Yes" << endl;
   }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 384
N = int(input())
ans = 0
bool1 = False

a0 = int(input())
if N == 1:
    if a0 != 0:
        print(-1)
    else:
        print(0)

else:
    for i in range(N-1):
        a1 = int(input())
        if i == 0 and a0 != 0:
            bool1 = True
            break
        if a1 - a0 > 1:
            bool1 = True
            break
        elif a1 - a0 == 1:
            a0 = a1
            continue
        else:
            ans += a0
            a0 = a1

    if bool1 == True:
        print(-1)
    else:
        print(ans + a1)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	int k,ans;

	scanf("%d", &k);

	if (k % 2 == 0)
		ans = (k / 2)*(k / 2);
	else
		ans = (k / 2)*(k / 2 + 1);

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

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N;cin>>N;
    if(N<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,a,b;cin >> n >> a >> b;
  cout << min(n*a,b) << "\n";
  return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<queue<int>> v(3);
	string s;
	for (int i=0; i<3; i++) {
		cin>>s;
		for (char ch : s)
			v[i].push(ch-'a');
	}
	int cur=0;
	while(1) {
		if(v[cur].empty()) { cout << char('A'+cur) << endl; return 0; }
		int nxt=v[cur].front();
		v[cur].pop();
		cur=nxt;
	}
	return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string & str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	int ans = 0;
	rep(i, n) {
		if (i % 2 == 0 and a[i] % 2 == 1)++ans;
	}
	printf("%d\n", ans);

	Please AC;
}

Measured memory_bytes: 3812
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};
typedef Point Vector;

struct Circle{
	Point center;
	double r;
};

double arg(Vector p){
	return atan2(p.y,p.x);
}

Vector polar(double a,double r){
	return Point(cos(r)*a,sin(r)*a);
}

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

vector<Point> getCrossPoints(Circle c1,Circle c2){

	vector<Point> res;

	double d = abs(c1.center-c2.center);
	double a = acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
	double t = arg(c2.center-c1.center);

	res.push_back(Point(c1.center+polar(c1.r,t+a)));
	res.push_back(Point(c1.center+polar(c1.r,t-a)));

	return res;
}


int main(){

	Circle c1,c2;

	scanf("%lf %lf %lf",&c1.center.x,&c1.center.y,&c1.r);
	scanf("%lf %lf %lf",&c2.center.x,&c2.center.y,&c2.r);

	vector<Point> ans = getCrossPoints(c1,c2);

	if((ans[0].x > ans[1].x) || (fabs(ans[0].x-ans[1].x) < EPS && ans[0].y > ans[1].y)){
		swap(ans[0],ans[1]);
	}

	printf("%.10lf %.10lf %.10lf %.10lf\n",ans[0].x,ans[0].y,ans[1].x,ans[1].y);

	return 0;
}




Measured memory_bytes: 3672
import numpy as np
N,M = map(int,input().split())
A = np.empty(N,dtype=np.int64)
B = np.empty(N,dtype=np.int64)
for i in range(N):
    A[i],B[i] = map(np.int64, input().split())

order = A.argsort()
A = A[order]
B = B[order]
Y = 0
for i in range(N):
    if B[i] >= M:
        Y += A[i]*M
        break
    else:
        Y += A[i]*B[i]
        M -= B[i]

print(Y)

Measured memory_bytes: 15576
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;


vl pow_;
vector<vl> pow_23;
void pow_ini(ll n) {
	pow_.push_back(n);
	rep(j, 62) {
		ll nxt = pow_[j] * pow_[j];
		nxt %= mod;
		pow_.push_back(nxt);
	}
	for (ll i = 2; i <= 3; i++) {
		vl powtmp;
		powtmp.push_back(i);
		rep(j, 62) {
			ll nxt = powtmp[j] * powtmp[j];
			nxt %= mod;
			powtmp.push_back(nxt);
		}
		pow_23.push_back(powtmp);
	}
	return;
}

ll pow1(ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_[ntmp];
			ans %= mod;
		}
	}
	return ans;
}

ll pow1_23(ll i, ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_23[i - 2][ntmp];
			ans %= mod;
		}
	}
	return ans;
}

vl fact;
vl fact_inv;

void fact_ini(ll n) {
	fact.push_back(1);
	fact.push_back(1);
	for (ll i = 2; i <= n; i++) {
		ll fact_tmp = fact[i - 1] * i;
		fact_tmp %= mod;
		fact.push_back(fact_tmp);
	}
	fact_inv.resize(n + 1);
	pow_ini(fact[n]);
	fact_inv[n] = pow1(mod - 2);
	for (ll i = n - 1; i >= 0; i--) {
		fact_inv[i] = fact_inv[i + 1] * (i + 1);
		fact_inv[i] %= mod;
	}
}

ll nCm(ll n, ll m) {
	ll ans = fact[n] * fact_inv[m];
	ans %= mod;
	ans *= fact_inv[n - m];
	ans %= mod;
	return ans;
}

int main() {
	fact_ini(10000000);
	ll X, Y;
	cin >> X >> Y;
	ll sum = X + Y;
	ll ans = 1;
	if (sum % 3 != 0)
		ans = 0;
	if (X < sum / 3)
		ans = 0;
	if (Y < sum / 3)
		ans = 0;
	ll n = sum / 3;
	ll r = X - n;
	if (ans != 0) {
		ans = nCm(n, r);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 158680
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> a(n);
    ld sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }

    int x = floor(sum / n);
    int y = ceil(sum / n);
    int ans1 = 0, ans2 = 0;

    rep(i, n){
        ans1 += (a[i] - x) * (a[i] - x);
        ans2 += (a[i] - y) * (a[i] - y);
    }

    cout << min(ans1, ans2) << endl;

return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    int[] numPatternCount = new int[19];
    int i, j, k, l;
    int size = 9;
    int sum = 0;
    for (i = 0; i <= size; i++)
      for (j = 0; j <= size; j++)
        for (k = 0; k <= size; k++)
          for (l = 0; l <= size; l++) {
            sum = i + j + k + l;
            if (sum > 18)
              continue;
            numPatternCount[i + j + k + l]++;
          }
    while ((readStr = reader.readLine()) != null) {
      int n = Integer.parseInt(readStr);
      System.out.println(
              n > 36 ? 0 : 
                      numPatternCount[n > 18 ? numPatternCount.length - (n - numPatternCount.length) - 2 : n]
      );
    }
  }

}

Measured memory_bytes: 16872
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner io = new Scanner(System.in);	
		int N = io.nextInt();
		int Ma = io.nextInt();
		int Mb = io.nextInt();
		int[][] data = new int[N+1][3];
		for (int i = 1; i <= N; i++) {
			data[i][0] = io.nextInt();
			data[i][1] = io.nextInt();
			data[i][2] = io.nextInt();
		}
		
		int[][][] table = new int[N+1][N*10+1][N*10+1];
		for (int i = 0; i < N+1; i++) {
			for (int j = 0; j < N*10+1; j++) {
				for (int j2 = 0; j2 < N*10+1; j2++) {
					table[i][j][j2] = 10000;
				}
			}
		}
		table[0][0][0] = 0;
		int na , nb ,value;
		for (int i = 1; i <= N; i++) {
			na = data[i][0];
			nb = data[i][1];
			value = data[i][2];
			for (int j = 0; j < N*10+1; j++) {
				for(int k = 0; k < N*10+1; k++){
					if(j-na<0||k-nb<0)
						table[i][j][k] = table[i-1][j][k];
					else
						table[i][j][k] = 
							Math.min(table[i-1][j][k],
									table[i-1][j-na][k-nb]+value);
				}
			}
		}
		int ans = 10000;
		for(int i=0;i<N*10+1;i++){
			for(int j=0;j<N*10+1;j++){
				if(i==0&&j==0) continue;
				if(i*Mb == j*Ma) ans = Math.min(ans,table[N][i][j]);
			}
		}
		
		System.out.println((ans==10000)?-1:ans);
		
	}
}

Measured memory_bytes: 41932
#include<iostream>
using namespace std;
int main(){
  char t[4], s[4];
  scanf("%s", t);
  scanf("%s", s);
  int cnt = 0;
  for(int i =0; i<3; i++){
    if(s[i] == t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect

n = int(input())

a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

sum = 0
for i in range(len(b)):
    ai = bisect.bisect_left(a, b[i])
    ci = bisect.bisect_right(c, b[i])
    sum += ai * (n - ci)

print(sum)

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

int main() {
    int N;
    cin >> N;
    string S;
    bool flag = false;
  
    for (int i = 0; i < N; i++) {
        cin >> S;
        if (S == "Y"){
            flag = true;
        }
    }

    if (flag){
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
    
}


Measured memory_bytes: 256
<?php
	$n = trim( fgets(STDIN) );
	$x = explode( " ", trim( fgets(STDIN) ) );
	$y = explode( " ", trim( fgets(STDIN) ) );
	
	list( $Dxy, $Dxy2, $Dxy3, $Dmax ) = array_fill( 0, 4, 0 );
	for( $i=0; $i<$n; $i++ ) {
		$t = abs( $x[$i]-$y[$i] );
		$Dxy += $t;
		$Dxy2 += pow( $t, 2 );
		$Dxy3 += pow( $t, 3 );
		$Dmax = max( $t, $Dmax );
	}
	print $Dxy.PHP_EOL;
	print pow( $Dxy2, 1/2 ).PHP_EOL;
	print pow( $Dxy3, 1/3 ).PHP_EOL;
	print $Dmax;
?>

Measured memory_bytes: 15776
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
    return 0;
}

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

int a[Maxn],n,cnt[2];
map<int,int>M;
struct data{
	int Num,Cnt;
}num[2][Maxn];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();
	while(!isdigit(ch)){
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	read(n);
	for(int i=1;i<=n;++i)
	read(a[i]);
}

bool Cmp(data Cmp1,data Cmp2){
	return(Cmp1.Cnt>Cmp2.Cnt);
}

int main(){
	init();
	cnt[0]=cnt[1]=0;
	
	M.clear();
	for(int i=1;i<=n;i+=2)
	M[a[i]]++;
	for(int i=1;i<=n;i+=2)
	if(M[a[i]]>0)
	++cnt[0],num[0][cnt[0]].Cnt=M[a[i]],num[0][cnt[0]].Num=a[i],M[a[i]]=0;
	
	for(int i=2;i<=n;i+=2)
	M[a[i]]++;
	for(int i=2;i<=n;i+=2)
	if(M[a[i]]>0)
	++cnt[1],num[1][cnt[1]].Cnt=M[a[i]],num[1][cnt[1]].Num=a[i],M[a[i]]=0;
	
	sort(num[0]+1,num[0]+cnt[0]+1,Cmp);
	sort(num[1]+1,num[1]+cnt[1]+1,Cmp);
	
	if(num[0][1].Num==num[1][1].Num){
		if(cnt[0]==1&&cnt[1]==1){
			cout<<n/2<<endl;
		}
		if(cnt[0]==1&&cnt[1]>1){
			cout<<n-num[0][1].Cnt-num[1][2].Cnt<<endl;
		}
		if(cnt[1]==1&&cnt[0]>1){
			cout<<n-num[1][1].Cnt-num[0][2].Cnt<<endl;
		}
		if(cnt[1]>1&&cnt[0]>1){
			cout<<n-max(num[1][1].Cnt+num[0][2].Cnt,num[1][2].Cnt+num[0][1].Cnt)<<endl;
		}
	}
	else{
		cout<<n-num[0][1].Cnt-num[1][1].Cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
n = int(input())
a = [int(input()) for i in range(n)]
m1 = max(a)
c = a.count(m1)
if len(set(a)) == 1:
	for i in range(n):
		print(m1)
else:
	m2 = sorted(set(a))[-2]
	for i in range(n):
		if a[i] < m1:
			print(m1)
		elif a[i] == m1:
			if c > 1:
				print(m1)
			else:
				print(m2)
		else:
			print(m2)

Measured memory_bytes: 19116
def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i-1
                # print(p)
                # print(temp[p:])
                q=[k for k in temp[p:] if k>temp[p]] 
                print("".join(temp[:p])+min(q))
                exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    t = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    r = [[1, 10 ** 9 + 1] for _ in range(n)]
    r[0][0], r[0][1] = t[0], t[0]

    for i, x in enumerate(t[1:], 1):
        if t[i - 1] < t[i]:
            r[i][0], r[i][1] = t[i], t[i]
        else:
            r[i][0], r[i][1] = 1, t[i]

    s = [[1, 10 ** 9 + 1] for _ in range(n)]
    a_rev = a[::-1]
    s[0][0], s[0][1] = a[0], a[0]

    for i, x in enumerate(a_rev[1:], 1):
        if a_rev[i - 1] < a_rev[i]:
            s[i][0], s[i][1] = a_rev[i], a_rev[i]
        else:
            s[i][0], s[i][1] = 1, a_rev[i]

    s = s[::-1]
    ans = 1

    for i in range(n):
        lower = max(r[i][0], s[i][0])
        upper = min(r[i][1], s[i][1])
        d = max(upper - lower + 1, 0)
        ans *= d
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 108060
/**
*    created: 23.05.2020 02:40:37
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int a, b;
    cin >> a >> b;
    if (b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int main() {
	int a[8] = {};
	TFOR(i, 3) {
		int n;
		cin >> n;
		a[n]++;
	}
	cout << (a[5]==2&&a[7]==1?"YES":"NO") << endl;
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		V[i] -= C[i];
	}
	sort(V.rbegin(), V.rend());
	int res = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] < 0) break;
		res += V[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
max_value = 0
ans = 0
for i in range(1, n+1):
    cnt = 0
    num = i
    while True:
        if num % 2 != 0:
            break
        num //= 2
        cnt += 1
    if max_value < cnt:
        max_value = cnt
        ans = i
if max_value == 0:
    print(n)
else:
    print(ans)

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

using namespace std;

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

    long n;
    cin >> n;
    char s[n];
    cin >> s;
    long right_e = 0;
    for (long i = 1; i < n; i++) right_e += (s[i] == 'E');
    long min_count = right_e;
    for (long i = 1; i < n; i++) {
        if (!min_count) break;
        right_e -= s[i] == 'E';
        right_e += s[i - 1] == 'W';
        min_count = min(min_count, right_e);
    }
    cout << min_count << '\n';
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    reverse(t.begin(), t.end());
    if (s == t)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
  
#define repd(i,a,b) for (int i=(a);i<=(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}


  
int main()
{
  int n,i,j,k;
  char s[10],u;
  string str,t;
  cin >> n;
  map<string, ll> check;
  ll ans = 0;

  for(i=0;i<n;i++){
      cin >> str;
      for(j=0;j<10;j++){s[j] = str[j];}
      for(j=0;j<9;j++){
          for(k=j+1;k<10;k++){
              if(s[j] > s[k]){
                  u = s[j]; s[j] = s[k]; s[k] = u;
              }
          }
      }
      //std::string t{s};
      t = s;

      if(check.count(t) == 0){
          check[t] = 1;
      }
      else{check[t]++;}
  }

    for(auto itr = check.begin(); itr != check.end(); ++itr) {
        if(itr->second > 1){
            ans += (ll)(itr->second * (itr->second - 1) / 2);
        }
    }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

int arr[405];
ll int dp[405][405];
ll int psum[405];

ll int kil(int s, int l)
{
  if(s == l)
  {
    return 0;
  }

  if(dp[s][l] != -1)
    return dp[s][l];

  dp[s][l] = 1e15;
  for(int i=s;i<l;i++)
  {
    dp[s][l] = min(dp[s][l], kil(s, i) + kil(i+1, l));
  }
  dp[s][l] += psum[l] - psum[s-1];

  return dp[s][l];
}

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

  memset(dp, -1, sizeof dp);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>arr[i];
    psum[i] = psum[i-1] + arr[i];
  }
  cout<<kil(1, n)<<endl;

  return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int a,b,c,d;
    a=b=c=d=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='S') a=1;
        if(s[i]=='N') b=1;
        if(s[i]=='E') c=1;
        if(s[i]=='W') d=1;
    }

    if(a==b && c==d) cout<<"Yes";
    else cout<<"No";
}



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

int main()
{
  int d,t,s;
  cin>>d>>t>>s;
  double time=(double)d/s;
  if(time<=t)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}
     

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

const int N = 30;

int main(void){
    vector<bool> safe(N);
    rep(i, N) safe[i] = false;
    for(int n; cin >> n; safe[n - 1] = true) ;
    rep(i, N) if(!safe[i]) cout << i + 1 << endl;
 
    return 0;
}

Measured memory_bytes: 1192
import java.util.*;

public class Main{
  static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int gg = gcd(a,b);//最大公約数
    int a_in = a/gg;
    int b_in = b/gg;
    long ans = (long)a * (long)b_in;

    System.out.println(ans);

  }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

struct edge{
    int src, to, cost;
};
using Edges = vector<edge>;

vector<int> bellman_ford(Edges &E, int V, int st){
    vector<int> dist(V, INF);
    dist[st] = 0;
    rep(i, V-1){
        for(auto &e: E){
            if(dist[e.src] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.src]+e.cost);
        }
    }
    for(auto &e: E){
        if(dist[e.src] == INF) continue;
        if(dist[e.to] > dist[e.src]+e.cost){
            // 負閉路が存在
            return vector<int>();
        }
    }
    return dist;
}
using Graph = vector<vector<int>>;

void dfs(Graph &G, vector<int> &ts, int v){
    ts[v] = 1;
    repe(i, G[v]){
        if(!ts[i]) dfs(G, ts, i);
    }
}

int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(m), b(m), c(m);
    rep(i, m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }
    Graph G(n);
    rep(i, m){
        G[b[i]].push_back(a[i]);
    }
    vector<int> ts(n, 0);
    dfs(G, ts, n-1);
    if(ts[0] == 0){
        cout << "-1" << endl;
        return 0;
    }

    Edges E;
    rep(i, m){
        if(ts[a[i]] && ts[b[i]]){
            E.push_back((edge){a[i], b[i], -c[i]+p});
        }
    }
    vector<int> ans = bellman_ford(E, n, 0);
    if(ans == vector<int>()){
        cout << -1 << endl;
    }else{
        cout << max(-ans[n-1], 0) << endl;
    }


}

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

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i, n){
    cin >> vec.at(i);
  }
  for(int i = n-1;i > 0; i--){
    cout << vec.at(i) << " ";
   }
  cout << vec.at(0) <<endl;


}



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

int main(){
  
  int a,b; cin >> a >> b;
  
  if((a*b) % 2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX =200000;
int main(){
    int R[MAX],n;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> R[i];
    int maxv = -2000000000;
    int minv = R[0];

    for(int i=1;i<n;i++){
        maxv = max(maxv,R[i]-minv);
        minv = min(minv,R[i]);
    }
    cout << maxv << endl;
}

Measured memory_bytes: 1940
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.io.Serializable;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int score = 0;

        while(k > 0){
            if(a != 0){
                score += 1;
                a--;
            }else if(b != 0){
                b--;
            }else{
                score -= 1;
                c--;
            }

            k--;
        }
        System.out.println(score);

        


    }
}

Measured memory_bytes: 35768
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


std::vector<std::vector<int>> G;


bool visit[111111];

void optimize(int i)
{
  visit[i] = true;

  for (int k = 0, size = G[i].size(); k < size; ) {
    assert(G[i].size() == size);
    assert(k < size);
    
    if (visit[G[i][k]]) {
      G[i][k] = G[i].back();

      G[i].pop_back();

      size --;
    }
    else {
      optimize(G[i][k]);
      
      k ++;
    }
  }
}

int memo[111111][2];

int dfs(int i, int j)
{
  if (memo[i][j] >= 0)
    return memo[i][j];

  if (G[i].empty())
    return memo[i][j] = 1;

  long long c = 1;

  for (const auto& k : G[i])
    if (j == 0) {
      (c *= (dfs(k, 0) + dfs(k, 1)) % MOD) %= MOD;
    }
    else {
      (c *= dfs(k, 0)) %= MOD;
    }

  return memo[i][j] = c;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, x, y;

  std::cin >> N;

  G.resize(N);

  for (int i = 0; i < N - 1; i ++) {
    std::cin >> x >> y;

    x --;
    y --;
    
    G[x].push_back(y);
    G[y].push_back(x);
  }

  memset(visit, 0, sizeof(visit));

  optimize(0);

  memset(memo, -1, sizeof(memo));

  std::cout << (dfs(0, 0) + dfs(0, 1)) % MOD << std::endl;

  return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    int ans = 0;
    cin >> N;
    vector<int> vals(N);
    for(int i = 0; i < N; i++){
        int t;
        cin >> t;
        vals.push_back(t);
        ans+=t;
    }
    sort(vals.begin(), vals.end());
    if(ans%10==0){
        for(int i = 0; i < vals.size(); i++){
            if((ans-vals[i])%10!=0){
                ans-=vals[i];
                break;
            }
        }
        if(ans%10==0){
            ans = 0;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256