akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	REP(i,n) cin >> a[i];
	int counter = 0;
	REP(i,n){
		if(a[i] < 0){
			counter++;
			a[i] = -a[i];
		}
	}
	ll sum = 0;
	int min = 1e9;
	REP(i,n){
		sum += a[i];
		if(a[i] < min) min = a[i];
	}
	if(counter % 2 == 0)cout << sum << endl;
	else cout << sum - 2 * min << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int i;
    int height[] = { 0, 0, 0 };
    int inHeight;

    for (i = 0; i < 10; i++) {
        scanf("%d", &inHeight);
        if (inHeight > height[0]) {
            height[2] = height[1];
            height[1] = height[0];
            height[0] = inHeight;
        } else if (inHeight > height[1]) {
            height[2] = height[1];
            height[1] = inHeight;
        } else if (inHeight > height[2]) {
            height[2] = inHeight;
        }
    }
    
    for (i = 0; i < 3; i++) {
        printf("%d\n", height[i]);
    }
    
    return 0;
}            


Measured memory_bytes: 2100
def resolve():
    N=int(input())
    S=[input() for i in range(N)]
    if len(S)!=len(set(S)):
        print('No')
        return
    p=S[0]
    for i in S[1:]:
        if p[-1]!=i[0]:
            print("No")
            return
        p=i
    print('Yes')


if __name__ == "__main__":
    resolve()

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

typedef long long ll;

const int Maxn = 5005;
const ll Inf = 4000000000000000000ll;

int n, a, b;
ll dp[Maxn][Maxn];

int main()
{
    fill((ll*)dp, (ll*)dp + Maxn * Maxn, Inf);
    scanf("%d %d %d", &n, &a, &b);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int num; scanf("%d", &num);
        for (int j = 0; j <= n; j++) if (dp[i][j] < Inf)
            if (j > num) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ll(b));
            else {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + ll(a));
                dp[i + 1][num] = min(dp[i + 1][num], dp[i][j]);
            }
    }
    ll res = Inf;
    for (int i = 0; i <= n; i++)
        res = min(res, dp[n][i]);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 195968
def main():
    s1, s2 = input(), input()
    n, m = len(s1), len(s2)

    dp, previous = [], []
    for i in range(n + 1):
        dp.append([0] * (m + 1))
        previous.append([0] * (m + 1))

    for row in range(1, n + 1):
        for column in range(1, m + 1):
            if s1[row - 1] == s2[column - 1]:
                dp[row][column] = 1 + dp[row - 1][column - 1]
                previous[row][column] = (row - 1, column - 1)
            else:
                dpUp = dp[row - 1][column]
                dpLeft = dp[row][column - 1]

                if dpUp > dpLeft:
                    dp[row][column] = dpUp
                    previous[row][column] = (row - 1, column)
                else:
                    dp[row][column] = dpLeft
                    previous[row][column] = (row, column - 1)

    lcs = ''
    curr = (n, m)

    while True:
        row, column = curr
        if previous[row][column] == 0: break

        if s1[row - 1] == s2[column - 1]:
            lcs = f'{s1[row - 1]}{lcs}'

        curr = previous[row][column]

    print(lcs)

main()


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

int main() {
    string s;
    cin >> s;
    int p_count = 0, g_count = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'p') p_count++;
        else g_count++;
    }
    int rest_count = g_count - p_count;
    cout << rest_count / 2 << endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.*;

class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
                int a, b;

                String line = reader.readLine();
                String[] strAry = line.split(" ");

                a = Integer.parseInt(strAry[0]);
                b = Integer.parseInt(strAry[1]);
                
                if(a < b){
                    System.out.println("a < b");
                }else if(a > b){
                    System.out.println("a > b");
                }else if(a == b){
                    System.out.println("a == b");
                }

        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24112
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

double dot_product(double x1,double y1,double x2,double y2){
	return x1*x2+y1*y2;
}

int main(){
	while(1){
		double xa,ya,xb,yb,xc,yc,xd,yd;
		cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd;
		if(cin.eof()) break;
		if(abs(dot_product(xa-xb,ya-yb,xc-xd,yc-yd))<1e-10) o("YES");
		else o("NO");
	}
}

Measured memory_bytes: 1216
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a <= b){
            System.out.println(a);
        }else{
            System.out.println(a - 1);
        }
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 35568
import sys
  
lines = sys.stdin.readlines()
for line in lines:
    a, b, c, d, e, f = map(float, line.split())
    if a * e - b * d == 0:
        break
    x = (e * c + (-b) * f)/(a * e - b * d)
    y = ((-d) * c + a * f)/(a * e - b * d)
    print('{:.3f} {:.3f}'.format(x+0, y+0))

Measured memory_bytes: 7316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

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

	int x, a, b;
	cin >> x >> a >> b;
	int ans = x - a;
	cout << ans % b << "\n";
	
	return 0;
}

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

bool impossible(vector<int> &t, vector<int> &x, vector<int> &y, int i){
  int time = t.at(i+1) - t.at(i);
  int distx = max(x.at(i),x.at(i+1))-min(x.at(i),x.at(i+1));
  int disty = max(y.at(i),y.at(i+1))-min(y.at(i),y.at(i+1));
  int dist = distx + disty;
  if (time<dist) return true;
  else if ((time-dist)%2 != 0) return true;
  else return false;
}


int main() {
  int n; cin >>n;
  vector<int> t(n+1), x(n+1), y(n+1);
  for (int i=1; i<n+1; i++) cin >>t.at(i) >>x.at(i) >>y.at(i);
  string ans = "Yes";
  for (int i=0; i<n; i++){
    if (impossible(t,x,y,i)){
      ans = "No"; break;
    }
  }
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 1408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
    int n;
    s(n);

    vector<int> prizes(3, 0);
    vector<int> dp(3, 0);
    vector<int> next_dp(3, 0);
    for(int i = 0; i < n; i++){
        f(l, 0, 3){
            s(prizes[l]);
        }
        for(int j = 0; j < 3; j++){
            int idx1 = (j + 1) % 3;
            int idx2 = (j + 2) % 3;
            next_dp[j] = max(dp[idx1] + prizes[idx1], dp[idx2] + prizes[idx2]);
        }
        dp = next_dp;
    }
    int maxx = *max_element(dp.begin(), dp.end());
    p(maxx);
    return;
}

class CVacation {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    CVacation solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int A,B;
    cin >> A >> B;
    int ans = A + B;
    if(ans >= 10){
        cout << "error" << endl;
    }
    else{
        cout << ans << endl;
    }
}



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

struct die_t {
	int top, front, right, left, back, bottom;
};

#define rotate_swap(x,a,b,c,d) swap(x.a, x.b); swap(x.b, x.c); swap(x.c, x.d);
void rotate_right(die_t& x) { rotate_swap(x, top, left, bottom, right); }
void rotate_left(die_t& x) { rotate_swap(x, top, right, bottom, left); }
void rotate_front(die_t& x) { rotate_swap(x, top, back, bottom, front); }
void rotate_back(die_t& x) { rotate_swap(x, top, front, bottom, back); }

int left(int top, int front) {
	int l[4];
	if(top == 1) {
		l[0] = 5, l[1] = 4, l[2] = 2, l[3] = 3;
	}
	else if(top == 2) {
		l[0] = 3, l[1] = 1, l[2] = 4, l[3] = 6;
	}
	else if(top == 3) {
		l[0] = 1, l[1] = 2, l[2] = 6, l[3] = 5;
	}
	else if(top == 4) {
		l[0] = 6, l[1] = 2, l[2] = 1, l[3] = 5;
	}
	else if(top == 5) {
		l[0] = 6, l[1] = 4, l[2] = 1, l[3] = 3;
	}
	else {
		l[0] = 2, l[1] = 4, l[2] = 5, l[3] = 3;
	}
	for(int i = 0; i < 4; i++) {
		if(front == l[i]) return l[(i + 1) % 4];
	}
	exit(1);
}

const int MAX = 250;
const int CENTER = 120;
int b[MAX][MAX];
int h[MAX][MAX];

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

	int n;
	while(cin >> n, n) {
		for(int i = 0; i < MAX; i++) {
			for(int j = 0; j < MAX; j++) {
				b[i][j] = h[i][j] = 0;
			}
		}

		while(n--) {
			int t, f;
			cin >> t >> f;
			int l = left(t, f);
			die_t d = die_t{ t, f, 7 - l, l, 7 - f, 7 - t };
			int ni = CENTER, nj = CENTER;
			h[ni][nj]++;

			int x[] = { 6, 5, 4 };
			bool flag = true;
			while(flag) {
				//if(h[ni][nj] == 1) break;
				flag = false;
				for(int i = 0; i < 3; i++) {
					if(d.front == x[i] && h[ni][nj] - h[ni + 1][nj] >= 2) {
						rotate_front(d);
						h[ni][nj]--;
						h[ni + 1][nj]++;
						ni++;
						flag = true;
						break;
					}
					if(d.back == x[i] && h[ni][nj] - h[ni - 1][nj] >= 2) {
						rotate_back(d);
						h[ni][nj]--;
						h[ni - 1][nj]++;
						ni--;
						flag = true;
						break;
					}
					if(d.left == x[i] && h[ni][nj] - h[ni][nj + 1] >= 2) {
						rotate_left(d);
						h[ni][nj]--;
						h[ni][nj + 1]++;
						nj++;
						flag = true;
						break;
					}
					if(d.right == x[i] && h[ni][nj] - h[ni][nj - 1] >= 2) {
						rotate_right(d);
						h[ni][nj]--;
						h[ni][nj - 1]++;
						nj--;
						flag = true;
						break;
					}
				}
			}
			b[ni][nj] = d.top;
		}

		int c[7] = { 0 };
		for(int i = 0; i < MAX; i++) {
			for(int j = 0; j < MAX; j++) {
				if(b[i][j]) c[b[i][j]]++;
			}
		}

		for(int i = 1; i <= 6; i++) {
			cout << c[i];
			if(i == 6) cout << endl;
			else cout << " ";
		}
	}
}

Measured memory_bytes: 1688
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;

int main ()
{
    string S;
    cin >> S;
    if (S[2]==S[3] && S[4]==S[5]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 888
import static java.lang.System.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
    int count = 0;
    int a = 0;
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
    for(int i=0; i<n; i++){
      a = ar[i];
      if(a % 2 == 0){
        while(true){
          a = a / 2;
          count = count + 1;
          if(a % 2 != 0){
            break;
          }
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 37316
H, N = map(int, input().split())
ls = []
x = 0
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,b)]
  if a>x:
    x = a

L = x+H+1
dp = [10**9]*L
dp[0] = 0
for i in range(L):
  for j in range(N):
    a, b = ls[j]
    if i>=a:
      dp[i] = min(dp[i], dp[i-a]+b)

ans = min(dp[H:])

print(ans)

Measured memory_bytes: 41964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=205;
ll b[N],a[63];
char ch[N];
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int T=read();
	while(T--){
		int n=read();
		For(i,1,n)b[i]=read();
		scanf("%s",ch+1);
		mem(a);
		int f=0;
		Rep(i,n,1){
			ll x=b[i];
			Rep(j,60,0)if(x>>j&1){
				if(a[j])x^=a[j];
				else{
					if(ch[i]=='0')a[j]=x;
					else f=1; break;
				}
			}
		}
		writeln(f);
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}




int main() {
    int num_monsters;
    cin >> num_monsters;
    vector<ll> hit_point(num_monsters);
    REP(monster_i, num_monsters) {
        cin >> hit_point[monster_i];
    }

    //方針は、hp最小のモンスターが削るだけけずって、ある数までモンスターが減る
    //生き残っているモンスターのうち、最小のhpのモンスターがまた、削る
    //これを最後の1匹になるまで繰り返す
    sort(hit_point.begin(), hit_point.end());
    ll minimum_hp = hit_point[0];
    while(hit_point.size() > 1) {
        FOR(monster_i, 1, hit_point.size()) {
            hit_point[monster_i] %= minimum_hp;
        }
        // hpが０になったものをベクトルから削除
        hit_point.erase(remove(hit_point.begin(), hit_point.end(), 0), hit_point.end());
        sort(hit_point.begin(), hit_point.end());
        minimum_hp = hit_point[0];
    }
    
    cout << minimum_hp << endl;
}


Measured memory_bytes: 1024
// Problem: B - Palindrome-philia
// Contest: AtCoder - AtCoder Beginner Contest 147
// URL: https://atcoder.jp/contests/abc147/tasks/abc147_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
#pragma GCC optimize("-O2")
const int INF = 10000000;
 
void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	int cnt=0;
	string s;
	cin>>s;
	int n=s.length();
	for(int i=0;i<(n/2);i++){
		if(s[i]!=s[n-i-1])cnt++;
	}
	cout<<cnt<<"\n";
    return;
}
// how r u bro

Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define pf push_front
#define popf pop_front
#define popb pop_back
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"

#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only

#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353

#include <boost/algorithm/string/replace.hpp>

using namespace std;


int main()
{
  ll n;
  cin >> n;
  
  ll *t = new ll[n];
  
  for01(0,n)
    cin >> t[i];
  
  ll m;
  cin >> m;
  
  ll *p = new ll[m];
  ll *x = new ll[m];
  
  for01(0,m)
    cin >> p[i] >> x[i];
  
  for02(0,m)
  {
    ll sum = 0;
    
    for01(0,n)
    {
      if( i + 1 == p[j])
        sum += x[j];
      else
        sum += t[i];
      
    }
    
    p1(sum);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n, ans;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    ans = 0;
    for(int i = 1; i < n - 1; i++){
        if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
// 2016-12-02
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	int d, e, x, y;
	float m;
	while (cin >> d >> e, d) {
		for (x = 0, y = d, m = abs(d - e); x <= d / 2; x++, y--) {
			m = min(m, (float)fabs(sqrt(x * x + y * y) - e));
		}
		cout  << fixed << setprecision(4) << m << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        aa: [usize; n-1]
    };

    let mut ans = vec![0; n];

    for a in aa {
        ans[a - 1] += 1;
    }

    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 5520
#include <stdio.h>
long long solve(long long, long long);
long long pow2(long long);
long long a[110] = {0,0, 1, 2, 3, 3,3,3,3,3,3,3,3,3,3,3};
int main()
{
  long long n, x;
  scanf("%lld%lld", &n, &x);
  long long ans;
  ans = solve(n, x);
  printf("%lld\n",ans);
  return 0;
}
long long solve(long long n, long long x)
{
  if(x==0) return 0;
  if(n==1 && x<=5) return a[x];
else if(n==1) return 3;
  long long st = pow2(n+1) - 1, ans;//每行面包 肉饼个数和 的一半 包括中间的
  if (n>1)
  {
    if (x >= st){
      ans = pow2(n) + solve(n-1, x-st);
    }
    else{
      ans = solve(n-1, x-1);
    }
  }
  return ans;
}
long long pow2(long long n)
{
  long long x = 1;
  for (int i = 0; i < n; ++i)
    x *= 2;
  return x;
}


Measured memory_bytes: 128
# 最小公倍数
from fractions import gcd
from functools import reduce
def lcm (x, y):
    return (x * y) // gcd(x, y)

# 最小公倍数(リスト)
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))

lcm_A = lcm_list(A)

ans = 0
for i in range(N):
    ans += lcm_A // A[i]

print(ans % mod)

Measured memory_bytes: 6136
n=int(input())
now=input()
s=set()
s.add(now)
for i in range(n-1):
    now2=input()
    if now[-1]!=now2[0]:
        print("No")
        break
    now=now2
    s.add(now)
else:
    if len(s)==n:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

int main() {
    int H, W;
    cin >> H >> W;
    vvi c(10, vi(10));
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }
    vvi a(H, vi(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> a[i][j];
        }
    }
    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (a[i][j] != -1)
                ret += c[a[i][j]][1];
        }
    }
    cout << ret << endl;
    return 0;
}

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

const int maxn = 3003;
ll dp[maxn][maxn];
bool done[maxn][maxn];

//状態としては 1: どちらの手番か？ 2: 残りの数列
ll dfs(int l, int r, vector<ll> &a) {
    if (l > r) return 0;
    if (done[l][r]) return dp[l][r];
    if ((a.size() - (r - l)) % 2 == 1) { // 先攻
        dp[l][r] = max(dfs(l+1, r, a) + a[l], dfs(l, r-1, a) + a[r]);
    } else { // 後攻
        dp[l][r] = min(dfs(l+1, r, a) - a[l], dfs(l, r-1, a) - a[r]);
    }
    done[l][r] = true;
    return dp[l][r];
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    rep(i, maxn) {
        rep(j, maxn) done[i][j] = false;
    }
    ll ans = dfs(0, a.size()-1, a);
    cout << ans << endl;
}

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

int n;
int ans;

/*xに3,5,7がそれぞれ1回以上現れるかチェック*/
void check(ll x_num) {

  string x = to_string(x_num);             // xをstring型に変換
  bool v3 = (x.find("3") != string::npos); // xに3が含まれていればtrue
  bool v5 = (x.find("5") != string::npos); // xに5が含まれていればtrue
  bool v7 = (x.find("7") != string::npos); // xに7が含まれていればtrue

  /*xに3,5,7がそれぞれ1回以上現れればansを1増やす*/
  if (v3 && v5 && v7) {
    ans++;
  }

  return;
}

/*check()を再帰する関数*/
void dfs(ll x) {
  if (x <= n) {
    check(x);
    dfs(x * 10 + 3);
    dfs(x * 10 + 5);
    dfs(x * 10 + 7);
  }

  return;
}

int main() {
  cin >> n;

  ans = 0;

  dfs(0);

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

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

int main() {
    int N; cin >> N;
    vector<vector<pair<int, int>>> T(N);
    for(int i = 0; i < N; ++i) {
        int A; cin >> A;
        while(A--) {
            int x, y; cin >> x >> y;
            T[i].emplace_back(x - 1, y);
        }
    }
    int ans = 0;
    for(int bit = 0; bit < (1 << N); ++bit) [&](){
        bitset<20> bs(bit);
        for(int i = 0; i < N; ++i) {
            if(!bs[i]) continue;
            for(auto t : T[i]) {
                int x, y; tie(x, y) = t;
                if(bs[x] != y) return;
            }
        }
        ans = max(ans, (int)bs.count());
    }();
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)


ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main(){
    int K;
    cin >> K;
    int i, j, k;
    ll ans = 0;
    ll gcd_1, gcd_2;
    for(i=1;i<=K;i++){
        for(j=1;j<=K;j++){
            for(k=1;k<=K;k++){
                gcd_1 = GCD(i, j);
                gcd_2 = GCD(gcd_1, k);
                /*
                if(i==j && j!=k){ans += 3*gcd_2;}
                if(i!=j && j==k){ans += 3*gcd_2;}
                if(i!=j && j!=k){ans +=   gcd_2;}
                if(i==j && j==k){ans +=   gcd_2;}
                cout << i << " " << j << " " << k << " " << gcd_2 << endl;
                */
                ans += gcd_2;

    }}}
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s.at(i)=='1')s.at(i)='9';
        else if(s.at(i)=='9')s.at(i)='1';
    }
    cout<<s<<endl;
}


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

int main()
{
	int64_t A;
	int64_t B[2];
	char c;
	std::cin >> A >> B[0] >> c >>  B[1];
	int64_t C = B[0] * 100 + B[1];
	std::cout << (int64_t(A * C) / 100) << std::endl;

	return 0;
}

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

int main() {
  int K ;
  int N ;
  int A1 ;
  int A2 ;
  int T ;
  int i=3 ;

  cin >> K>>N>>A1>>A2 ;
  T = A2-A1;
    while(i<=N)
    {int Ai ;
      cin >>Ai ;
       if((Ai-A2)>T)
       {T=(Ai-A2);}
      A2=Ai;
    i++;
    }
   if((K-A2+A1)>T)
    {T=(K-A2+A1);} 
      
     cout<< K-T <<endl;
    }

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);

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

  ll sum = 0;
  for (auto a : A) {
    sum += a;
  }

  // cout << sum << endl;

  ll count = 0;
  for (auto a : A) {
    ll b = sum / (4 * M);

    if (sum % (4 * M) == 0) {
      if (a >= b) {
        count++;
      }
    } else if (sum < (4 * M)) {
      if (a > b) {
        count++;
      }
    } else {
      if (a > b) {
        count++;
      }
    }
  }

  // cout << count << endl;

  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    int total=0;
    int totalten=0;      //useful
    int totalother;
    int minother;
    bool ii = true;
    for(int i = 0; i < n; i++){
        if(s[i]%10==0){
            totalten += s[i];
            s[i] = 0;
        }else{
            if(ii){
                minother = s[i];
            }else{
                if(s[i]<minother){
                    minother = s[i];
                }
            }
            ii = ii && false;
        }
        total += s[i];
    }
    total += totalten;
    if(total%10==0){
        total -= minother;
    }
    if(total%10==0){
        total = 0;
    }
    cout << total << endl;

    return 0;
}


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

int main() {
  string S, s;
  cin >> S >> s;
  if(S.at(2) == s.at(0) && S.at(1) == s.at(1) && S.at(0) == s.at(2)){
      cout << "YES" << endl;
  }
  else cout << "NO" << endl;
  
}

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

typedef std::numeric_limits< double > dbl;

int main()
{
    int n;
    cin >>n;
    double p[n+1];
    // dp[i][j] -- probability of getting j heads out of i coins
    double dp[n+1][n+1];
    for(int i=1;i<=n;++i) cin >> p[i];

    for(int i=0;i<=n;++i)
    {
        for(int j=0;j<=n;++j)
        {
            if(j>i){
                dp[i][j]=0;
                continue;
            }
            if(i==0) dp[i][j] = 1.0;
            else if(j==0) dp[i][j] = dp[i-1][j]*(1-p[i]);
            else dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
        }
    }
    int start = n/2 +1;
    double ans =0;
    for(int i=start;i<=n;++i)
    {
        ans += dp[n][i];
    }
    cout.precision(10);
    cout << fixed << ans << endl;
}

Measured memory_bytes: 74112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#include <functional>

template< typename T, typename S >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<S> lazy;
    T te;
    S se;

    inline void merge_functions(S& lazy,S val){
        //lazy+=val;
        lazy=val;
    }
    inline void operate(T& data,S val,int len){
        //data+=val*len;
        //data=val*len;
        //data+=val;
        data=val;
    }
    inline T merge_values(T& x,T& y){
        //return x+y;
        return min(x,y);
        //return max(x,y);
    }

    LazySegmentTree(){}
    LazySegmentTree(int sz,T te,S se):te(te),se(se){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,se);
    }

    void build(vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==se) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]+(r-l)/2);
        }
        lazy[k]=se;
    }

    void update(int a,int b,S val,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            merge_functions(lazy[k],val+l-a);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }
};

/*
  LazySegmentTree<ll,ll> seg(N,te,se);
  vector<ll> init(N,0);
  seg.build(init);
*/

const ll INF=1e6;

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

  int H,W;
  cin>>H>>W;
  vector<int> L(H),R(H);
  rep(i,H) cin>>L[i]>>R[i];

  rep(i,H){
    L[i]--;R[i]--;
  }

  ll se=0,te=INF;
  LazySegmentTree<ll,ll> seg(W,te,se);
  vector<ll> init(W,0);
  seg.build(init);

  int left=0;
  vector<int> ans(H,0);
  rep(i,H) ans[i]=i+1;
  rep(i,H){
    ll val=INF;
    if(L[i]>0) val=seg.query(L[i]-1,L[i]);
    chmin(val,INF);

    seg.update(L[i],R[i]+1,val+1);
    ll res=seg.query(0,W);
    if(res>=INF) ans[i]=-1;
    else ans[i]+=res;
  }

  rep(i,H) cout<<ans[i]<<"\n";


  return 0;
}


Measured memory_bytes: 15360
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#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;

int main(){
	int e;
	while (cin >> e && e){
		int ans = 1e9;
		for (int z = 0; z*z*z <= e; z++){
			for (int y = 0; z*z*z + y*y <= e; y++){
				int x = e - z*z*z - y*y;
				ans = min(ans, x+y+z);
			}
		}
		cout << ans << endl;
	}

    return 0;
}

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

int main(void) {
  int n, t, a, h[100000], kari = 1000000, ans;

  if(scanf("%d %d %d", &n, &t, &a) != 0);
  t = t * 1000;
  a = a * 1000;

  for(int i = 0; i < n; i++) {
    if(scanf("%d", &h[i]) != 0);
    h[i] = h[i] * 1000;
    if(kari > abs((t - h[i] * 0.006) - a)) {
      ans = i + 1;
      kari = abs((t - h[i] * 0.006) - a);
    }
  }

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

  return 0;
}


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

    using namespace std;
    #define ull unsigned long long
    #define ll long long
    /*-----------------------------------------------------MATH------------------------------------------------*/
    inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; }
    inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
    inline int pwm(ll xx, ll pow, int MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return (int)mlt; }
    inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; }ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; }
    inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }
    /*-----------------------------------------------------MATH------------------------------------------------*/

    const int inf = 1e6;
    const int MAXN = 2e5 + 10;
    ll mod =998244353;
    void solve() {
        int n;
        string s,t;
        cin>>n>>s>>t;
        for(int i=0;i<n;i++){
            cout<<s[i]<<t[i];
        }


    }

    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n=1;
        for (int i = 0; i < n; i++) solve();
        return 0;
    }

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

void solve() {
    int h, w, k;
    std::cin >> h >> w >> k;

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    int ans = 0;
    for (int bx = 0; bx < (1 << h); ++bx) {
        for (int by = 0; by < (1 << w); ++by) {
            int cnt = 0;

            for (int x = 0; x < h; ++x) {
                if ((bx >> x) & 1) continue;
                for (int y = 0; y < w; ++y) {
                    if ((by >> y) & 1) continue;
                    if (ss[x][y] == '#') ++cnt;
                }
            }

            if (cnt == k) ++ans;
        }
    }

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

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

    solve();

    return 0;
}


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

#define FOR(i, a, b) for (int i=(a); i < (b); i++)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 10100;


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	LL x,y;
	LL mx=1,my=1;
	LL m=1;
	FOR(i,0,n)
	{
		cin>>x>>y;

		LL k1 = (mx+x-1)/x;
		LL k2 = (my+y-1)/y;
		k1=max(k1,k2);
		x*=k1;
		y*=k1;

		mx=max(mx,x);
		my=max(my,y);

		//cerr<<x<<" "<<y<<endl;
		//k1=max(k1,k2);
		//m=max(m,k1);
		//cerr<<k1<<" "<<k2<<" "<<m<<endl;
	}

	cout<<(x+y);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  long long cnt =0;
  long long ans=0;
  cin>>n;
  map<string,long long> mp;
  while(cnt<n){
    string s;
    cin>>s;
    vector<char> ch(10);
    for(int i=0;i<(int)s.size();i++){
      ch[i]=s[i];
    }
    sort(ch.begin(),ch.end());
    for(int i=0;i<(int)s.size();i++){
      s[i]=ch[i];
    }
    if(mp.count(s)!=0){
      mp[s]++;
      ans+=mp[s];
    }else{
      mp[s]=0;
    }
    cnt++;
  }
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 11136
n, y = gets.chomp.split.map(&:to_i)

x, a = y.divmod(10000)
y, b = a.divmod(5000)
z, c = b.divmod(1000)

p = n - (x + y + z)
if p < 0
  puts '-1 -1 -1'
  exit
end
m, u = p.divmod(9)
if m <= x
  x -= m
  z += 10 * m
else
  z += 10 * x
  u += (m-x) * 9
  x = 0
end
k, l = u.divmod(4)
if k <= y
  y -= k
  z += 5 * k
else
  z += 5 * y
  l += (k-y) * 4
  y = 0
end

if l <= x
  x -= l
  y += 2 * l
else
  puts '-1 -1 -1'
  exit
end

puts "#{x} #{y} #{z}"


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 111;

int n, x, y, i, n1, n2;
vector<int> list[maxN];
pair<int, int> best;
vector<int> way, aux;
ll colors, leaves;

bool us[maxN];
int maxi[maxN];
queue< pair<int, int> > Q;

void dfs(int node, int root, int d) {
    best = max(best, mp(d, node));
    for (auto to : list[node])
        if (to != root)
            dfs(to, node, d + 1);
}

void get_way(int node, int root, int dest) {
    aux.pb(node);

    if (node == dest) way = aux;
    for (auto to : list[node])
        if (to != root)
            get_way(to, node, dest);

    aux.pop_back();
}

ll check(ll n1, ll n2 = 0) {
    int i, j;

    memset(us, 0, sizeof(us));
    memset(maxi, 0, sizeof(maxi));
    Q.push(mp(n1, 0));
    if (n2 != 0) Q.push(mp(n2, 0));
    us[n1] = us[n2] = true;

    while (!Q.empty()) {
        int act = Q.front().first;
        int lvl = Q.front().second;
        Q.pop();

        int down = 0;
        for (auto to : list[act]) {
            if (us[to]) continue;
            down++;
            Q.push(mp(to, lvl + 1));
            us[to] = true;
        }

        maxi[lvl + 1] = max(maxi[lvl + 1], down);
    }

    ll ans = 1;
    for (i = 1; maxi[i] > 0; i++)
        ans *= 1LL * maxi[i];

    return ans * (n2 != 0 ? 2 : 1);
}

void solve() {
    int sz = way.size();
    int R;
    colors = (sz + 1) / 2;

    if (sz % 2 == 0) {
        leaves = check(way[(sz / 2) - 1], way[sz / 2]);
    } else {
        R = way[sz / 2];
        leaves = check(R);
        for (auto to : list[R])
            leaves = min(leaves, check(R, to));
    }

    printf("%lld %lld", colors, leaves);
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    best = mp(0, 0);
    dfs(1, 0, 1);
    n1 = best.second;

    best = mp(0, 0);
    dfs(n1, 0, 1);
    n2 = best.second;

    get_way(n1, 0, n2);

    solve();

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
H, W, N = map(int, input().split())
D = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for y in range(3):
        for x in range(3):
            if 0 < a - y <= H - 2 and 0 < b - x <= W - 2:
                D[(a - y, b - x)] += 1

C = Counter(D.values())
SUM = sum(C.values())

print((H - 2) * (W - 2) - SUM)
for i in range(1, 10):
    print(C[i])


Measured memory_bytes: 166860
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)



int main() {
    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll hanten=0;
    string front="";//後で反転
    string back="";
    rep(i,q){
        ll t;
        cin >> t;
        if(t==1){
            hanten++;
            hanten%=2;
        }
        else{
            ll f;
            char c;
            cin >> f >> c;
            if(hanten==0){//正常
                if(f==1){
                    front+=c;
                }
                else{
                    back+=c;
                }
            }
            else{
                if(f==1){
                    back+=c;
                }
                else{
                    front+=c;
                }
            }
        }
    }
    reverse(front.begin(),front.end());
    string ans="";
    ans+=front+s+back;
    if(hanten==1) reverse(ans.begin(),ans.end());
    cout << ans << endl;
}





Measured memory_bytes: 1396
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	if(s[0]==s[1] && s[1]==s[2])
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
int factorial(int n) { //階乗
  double ans = 0;
  double ansa = 1;
  double answ = 1;
  for(int i = 1; i <= n; i++) {
    ansa *= i;
  }
   for(int j = 1; j <= n-2; j++) {
    answ *= j;
  }
  
  ans = ansa /(2 * answ); 
  return ans;
}
    int main() {
      int N = 0; //偶数の数
      int M = 0; //奇数の数
      int count1 = 0;
      int count2 = 0;
      cin >> N >> M;
      
      if(N != 0 && N != 1 && N != 2){
      count1 = factorial(N);
       }
      
      else if(N == 2){
        count1 = 1;
      }
      
      else{
        count1 = 0;
      }
      
      if(M != 0 && M != 1 && M != 2){
        count2 = factorial(M);
      }
      
      else if(M == 2){
        count2 = 1;
      }
      
      else{
        count2 = 0;
      }
      
      cout << count1 + count2 << endl;
    }


Measured memory_bytes: 256
N,M = gets.split.map(&:to_i)
INF = M*1000*10
nodes = (1..N).to_a
es = {}
unused = {}
M.times {
  a,b,c = gets.split.map(&:to_i)
  a,b = b,a if a > b
  es[a] ||= {}; es[b] ||= {}
  es[a][b] = es[b][a] = c
  unused[(a-1)*N+(b-1)] = 1
}

def dijk(start, nodes, edges)  
  froms = nodes.map{ nil }
  ds = nodes.map{ INF }
  ds[start-1] = 0
  queue = [start]
  while f = queue.shift
    #p queue
    u = ds[f-1]
    edges[f].each{ |t,c|
      v = ds[t-1]
      next if u+c >= v
      ds[t-1] = u+c
      queue.push(t)
      froms[t-1] = f
    }
  end
  #p ds
  froms.map.with_index{ |f,i| f ? [f, i + 1].sort : nil }.compact
end

nodes.each{ |s|
	dijk(s, nodes, es).each{ |f,t|
      unused.delete((f-1)*N+(t-1))
    }
}

puts unused.size

Measured memory_bytes: 2044
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.chomp.to_i
puts nums[k-1]

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

int N, D, Q;
vector<int> vD, A, B;

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

	cin >> N >> D;
	vD.resize(N + 1);
	vD[0] = 0;
	A.resize(N + 1);
	A[0] = D;
	for (int i = 1; i <= N; ++i) {
		int d;
		cin >> d;
		vD[i] = d;
		if (d <= A[i - 1])
			A[i] = A[i - 1] - d;
		else {
			int d2 = d - A[i - 1];
			A[i] = (d2 > A[i - 1]) ? A[i - 1] : d2;
		}
	}
	B.resize(N + 2);
	B[N + 1] = 1;
	for (int i = N; i > 0; --i) {
		if (B[i + 1] <= vD[i] / 2)
			B[i] = B[i + 1];
		else
			B[i] = B[i + 1] + vD[i];
	}
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int q;
		cin >> q;
		if (A[q - 1] == 0 || B[q + 1] > A[q - 1])
			cout << "NO\n";
		else
			cout << "YES\n";
	}
	return 0;
}


Measured memory_bytes: 7808
program main
  implicit none
  integer i,A,B
  !read(*, *) (L(i), i = 1,N)
  read(*, *)A, B
  i = (A+B)/2
  if (mod(A+B,2) == 0) then
    write(*, *) i
  else
    write(*, *) 'IMPOSSIBLE'
  end if
end program main


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int l=s.size();
    set<char> st;
    for(int i=0;i<l;i++)
      st.insert(s[i]);
      if(st.size()==2)
       cout<<"Yes";
       else
       cout<<"No";

    return 0;
}


Measured memory_bytes: 256
import bisect

S=[]

q=int(input())

def find(x):
    index=bisect.bisect_left(S,x)
    if index==len(S):
        return False
    return S[index]==x


for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        if find(query[1]):
            pass
        else:
            bisect.insort_left(S, query[1])
        print(len(S))
    elif query[0]==1:
        if find(query[1]):
            print(1)
        else:
            print(0)
    elif query[0]==2:
        if find(query[1]):
            S.remove(query[1])
    else:
        L,R=query[1],query[2]
        indL=bisect.bisect_left(S,L)
        indR=bisect.bisect_right(S,R)
        for s in S[indL:indR]:
            print(s)



Measured memory_bytes: 15648
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> height = new ArrayList<>();
		List<Integer> width = new ArrayList<>();
		int h = 0;
		int w = 0;


		int count = 0;
		boolean judge = false;
		while(!judge){
			h = sc.nextInt();
			w = (sc.nextInt());

			if(h == 0 && w == 0){
				judge = true;
			}else{
				height.add(h);
				width.add(w);
				count++;
			}
		}
		for(int i = 0; i < count; i++){
			for(int j = 0; j < height.get(i); j++){
				for(int k = 0; k < width.get(i); k++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}


	}

}


Measured memory_bytes: 32924