akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static long C(long n, long k)
        {
            long bunbo = 1;
            long bunsi = 1;
            for (long i = n - k; i <= n; i++)
                bunsi *= i;
            for (long i = 1; i <= n - k; i++)
                bunbo *= i;
            return bunsi / bunbo;
        }
        bool f = false;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var input = Reads();
            var n = input[0];
            var m = input[1];
            var f = new bool[n];
            for (int i = 0; i < n; i++)
            {
                f[i] = false;
            }
            var pcount =new long[n];
            var acount = 0;
            for (int i = 0; i < m; i++)
            {
                var str = Console.ReadLine().Split();
                var p = long.Parse(str[0]);
                var s = str[1];
                if (!f[p - 1])
                {
                    if (s == "AC")
                    {
                        acount++;
                        f[p - 1] = true;
                    }
                    else pcount[p - 1]++;
                }
            }

            long ansp = 0;
            for (int i = 0; i < n; i++)
            {
                if (f[i])
                    ansp += pcount[i];

            }
            Console.WriteLine("{0} {1}", acount, ansp);
            
            

          

      


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 18128
def matDot(A,B,MOD):
    N,M,L = len(A),len(A[0]),len(B[0])
    
    res = [[0]*L for i in range(N)]

    for i in range(N):
        for j in range(L):
            s = 0
            for k in range(M):
                s = (s + A[i][k]*B[k][j]) % MOD
            res[i][j] = s
    
    return res

def matPow(A,x,MOD):
    N = len(A)
    res = [[0]*N for i in range(N)]
    
    for i in range(N):
        res[i][i] = 1
    
    for i in range(x.bit_length()):
        if (x>>i) & 1:
            res = matDot(res,A,MOD)
        A = matDot(A,A,MOD)
    
    return res

n,k = map(int,input().split())
mod = 10**9+7

a = [list(map(int,input().split())) for i in range(n)]
b = matPow(a,k,mod)

ans = 0
for i in range(n):
    for j in range(n):
        ans = (ans+b[i][j])%mod

print(ans)

Measured memory_bytes: 41324
#include<bits/stdc++.h>
#define MN 100
#define ll long long 
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll ans=1e18,ans2=1e18;
int n,head[MN+5],cnt,mx[MN+5],dep[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;	
}
void dfs(int x,int fa)
{
	int son=0;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa)
		{
			dep[e[i].to]=dep[x]+1;
			dfs(e[i].to,x);++son;
		}
	mx[dep[x]]=max(mx[dep[x]],son);
}
int main()
{
	n=read();
	for(int i=1;i<n;++i) ins(read(),read());
	for(int i=1;i<=n;++i)
	{
		memset(dep,0,sizeof(dep));
		memset(mx,0,sizeof(mx));
		dfs(i,0);ll res=1;int mxdep=-1;
		for(int j=0;j<=n;++j) if(mx[j]) mxdep=j,res*=mx[j];
		if(mxdep+2<ans||(mxdep+2==ans&&res<ans2))
			ans=mxdep+2,ans2=res;
	}
	for(int i=1;i<=n;++i) 
		for(int j=head[i];j;j=e[j].next) if(e[j].to<i)
		{
			memset(dep,0,sizeof(dep));
			memset(mx,0,sizeof(mx));
			dfs(i,e[j].to);dfs(e[j].to,i);ll res=2;int mxdep=-1;
			for(int j=0;j<=n;++j) if(mx[j]) mxdep=j,res*=mx[j];
			if(mxdep+2<ans||(mxdep+2==ans&&res<ans2))
				ans=mxdep+2,ans2=res;
		}
	printf("%lld %lld\n",ans,ans2);
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int A, B, C, X, Y;
	int price = 0;
	int amount = 0;

	scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

	int minor, major;
	int cost;
	if (X > Y)
	{
		minor = Y;
		major = X;
		cost = A;
	}
	else
	{
		minor = X;
		major = Y;
		cost = B;
	}
	//	better to combine
	if (cost>2*C)
	{
		price = 2 * major*C;
	}
	else if (A+B>=2*C)
	{
		//printf("combine better\n");
		while (amount<minor)
		{
			amount++;
			price += 2 * C;
		}
		while (amount<major)
		{
			amount++;
			price += cost;
		}
	}
	else
	{
		//printf("separate better\n");
		price += A*X + B*Y;
	}
	printf("%d", price);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

struct Edge{
    ll to, cost;
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
ll inf = 1e15;
ll mod = 1e9 + 7;

vll dijkstra(const Graph &g, int s){
    vll d(g.size(), inf);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    while(!que.empty()){
        ll dist = que.top().first;
        int v = que.top().second;
        que.pop();
        if(d[v] < dist) continue;
        for(const auto &e: g[v]){
        if(d[e.to] <= d[v] + e.cost) continue;
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
        }
    }
    return d;
}

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

    ll n;
    cin >> n;
    ll a, b, c;
    Graph g(n);
    REP(i, n - 1){
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back((Edge){b, c});
        g[b].push_back((Edge){a, c});
    }
    vll d = dijkstra(g, 0);
    REP(i, n){
        if(d[i] % 2) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long h = sc.NextLong();
        long w = sc.NextLong();
        long n = sc.NextLong();
        long[] a = sc.LongArray();

        long[,] map = new long[h, w];

        long currentH = 0;
        long currentW = 0;
        for (int i = 0; i < n; i++)
        {
            long count = a[i];
            while (count > 0)
            {
                map[currentH, currentW] = i + 1;
                if (currentH % 2 == 0)
                {
                    currentW++;
                    if (currentW >= w)
                    {
                        currentH++;
                        currentW = w - 1;
                    }
                }
                else
                {
                    currentW--;
                    if (currentW < 0)
                    {
                        currentH++;
                        currentW = 0;
                    }
                }
                count--;
            }
        }


        for (int i = 0; i < h; i++)
        {
            List<long> nums = new List<long>();
            for (int j = 0; j < w; j++)
            {
                nums.Add(map[i, j]);
            }
            Console.WriteLine(string.Join(" ", nums));
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 29464
using System;
using System.Collections.Generic;

class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    const int mod = 1000000007;
    
    // 壊れている段
    var broken = new Queue<int>();
    for(int i = 0; i < M; i++)
    {
      broken.Enqueue(int.Parse(Console.ReadLine()));
    }
    
    // N段目に到達する場合の数
    int[] dp = new int[N + 5];
    dp[0] = 1;
    
    for (int i = 1; i <= N; i++)
    {
      if (broken.Count != 0 && broken.Peek() == i)
      {
        dp[i] = 0;
        broken.Dequeue();
      }
      else
      {
        if(i == 1)
          dp[1] = 1;
        else
          dp[i] = (dp[i - 2] + dp[i - 1]) % mod;
      }
    }
    
    // 出力
    Console.WriteLine(dp[N]);
    
  }
}

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

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  constexpr int64_t INF{1'000'000'000'000'000};
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  int V{};
  for(int i = 0; i < N; ++i)
  {
    cin >> w[i] >> v[i];
    V += v[i];
  }
  vector<int64_t> dp(V + 1, INF);
  dp[0] = 0;
  for(int i = 0; i < N; ++i)
  {
    for(int j = V; j >= v[i]; --j)
    {
      dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
  }
  
  int res{};
  
  for(int i = 0; i <= V; ++i)
  {
    if(dp[i] <= W)
    {
      res = max(res, i);
    }
  }
  
  cout << res << "\n";
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  long n;
  cin >> n;
  int a[n];
  rep(i,0,n) cin >> a[i];
  sort(a, a+n);
  co(a[n-1]-a[0]);
         
         
    
    
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  scanf("%d",&n);
  char *s = (char*)malloc(sizeof(char)*n);
  char *t = (char*)malloc(sizeof(char)*n);
  scanf("%s",s);
  scanf("%s",t);
  for (int i = 0; i < n; ++i)
    printf("%c%c",s[i],t[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int a[300010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    
    rep(i, N * 3) cin >> a[i];
    ll ans = 0;
    sort(a, a + N * 3, greater<int>());
    // rep(i, N * 3) cout << a[i] << " ";
    // cout << endl;
    for(int i = 0; i < N * 2; i += 2) {
        ans += a[i + 1];
    }
    cout << ans << endl;

    return 0;
}
// 1 2 3 4 5 6

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

int main(){
    string a, b;
    cin >> a >> b;
    string s_a , s_b;
    for (int i = 0; i < stoi(b); i++){
        s_a.append(a);
    }
    for (int i = 0; i < stoi(a); i++){
        s_b.append(b);
    }
    ll a_ans = stoi(s_a);
    ll b_ans = stoi(s_b);
    if (stoi(a) <= stoi(b)) cout << a_ans << endl;
    else cout << b_ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){
  string s;cin>>s;
  rep(i,s.size()){
    if(i==4)cout<<" ";
    cout<<s[i];
  }
  cout<<endl;

  return 0;
}


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


int main(void){
    
    int W,H,N;
    
    cin >> W >> H >> N;
    
    vector<pair<int,int>> vec;
    vec.resize(4);
    vec[0] = make_pair(0,0);
    vec[1] = make_pair(W,0);
    vec[2] = make_pair(0,H);
    vec[3] = make_pair(W,H);
    
    int x,y,a;
    
        // cout << vec[0].first << vec[0].second <<endl;
        // cout << vec[1].first << vec[1].second <<endl;
        // cout << vec[2].first << vec[2].second <<endl;
        // cout << vec[3].first << vec[3].second <<endl;
        // cout << "---------------------------------"<<endl;
    
    for(int i = 0; i < N;i++){
        
        cin >> x >> y >> a;
        
        if(a == 2){
            
           if( x< vec[3].first){
               
               vec[1].first = x;
               vec[3].first = x;
               
           } 
            
        }else if(a == 1){
            
            if( x > vec[0].first){
               
               vec[0].first = x;
               vec[2].first = x;
               
           } 
            
            
        }else if(a == 4){
            
            if( y < vec[3].second){
               
               vec[2].second = y;
               vec[3].second = y;
               
           } 
            
            
        }else if(a == 3){
            
            if( y > vec[0].second){
               
               vec[0].second = y;
               vec[1].second = y;
               
           } 
            
        }
     
        // cout << vec[0].first << vec[0].second <<endl;
        // cout << vec[1].first << vec[1].second <<endl;
        // cout << vec[2].first << vec[2].second <<endl;
        // cout << vec[3].first << vec[3].second <<endl;
        // cout << "---------------------------------"<<endl;
    }
    int dx = max((vec[3].first - vec[0].first),0);
    int dy = max((vec[3].second - vec[0].second),0);
    cout << dx*dy<<endl;

    
}


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

using ll = long long;
const int INF = 1e9+7;

void solve()
{
	int n; cin >> n;
	vector<ll> hash(n);
	ll all = 0;
	for(ll &x:hash){
	   cin >> x;
	   all^=x;
	}
	for(int i=0;i<n;++i){
		ll x = all^hash[i];cout << x << '\n';
	}
}

int main()
{
	int t=1;
	//int t;cin >> t;
	while(t--) solve();
}	

Measured memory_bytes: 4764
N, x = map(int,input().split())
a = list(map(int,input().split()))

cnt = 0
for i in range(N-1):
    s = a[i]
    t = a[i+1]
    if s + t <= x:
        continue
    cnt += s + t -x
    if t >= s + t - x:
        a[i+1] -= s + t - x
    else:
        a[i+1] = 0
print(cnt)


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

int main(){
    double a,b,A,B,C,D;cin>>a>>b;
    A=a/0.08;
    C=(a+1)/0.08;
    B=b/0.10;
    D=(b+1)/0.10;
    if(C<=B) cout<<-1<<endl;
    else if(A<=B&&B<C){
        if(B-(int)B==0.5) B+=0.5;
        cout<<B<<endl;
    }
    else if(B<=A&&A<D){
        if(A-(int)A==0.5) A+=0.5;
        cout<<A<<endl;
    }
    else if(D<=A) cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cctype>
#define rep(x,y,z) for(long long x=y;x<z;++x)
#define dwn(x,y,z) for(long long x=y;x>z;--x)
using namespace std;

typedef long long ll;

int main() {
    ll nums[4];
    vector<bool> have_num(10);
    rep(i,0,4) {
        cin >> nums[i];
        have_num[nums[i]] = true;
    }
    if (have_num[1] && have_num[9] && have_num[7] && have_num[4]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
Blist = list(map(int, input().split()))
Alist = []
for i in range(0,N):
    Alist.append(0)
Alist[0] = Blist[0]
Alist[-1] = Blist[-1]
#print(Alist)
#print(Blist)

for i in range(1,N-1):
    Alist[i] = min(Blist[i-1],Blist[i])

ans = 0
for i in Alist:
    ans += i 

print(ans)


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


int N;
double ave = 0;
vector<double> x;
vector<double> y;


int main(){
  cin >> N;
  vector<vector<double>> d(N, vector<double>(N));
  double vx, vy;
  for(int i = 0; i < N; i++){
    cin >> vx >> vy;
    x.push_back(vx); y.push_back(vy);
  }

  /*距離の保存*/
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      d[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }

  /* (N-1)!通りもN!通りの平均なので/Nにかわる*/
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++)
      ave += d[i][j] / (double)N;
  }

  printf("%.7f\n", ave);
  return 0;
}
      

  
    

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;


class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};
    public static int INF = 0x3f3f3f3f;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;
    public static int MOD = 1000000007;

    public static int N;

    public static int[] dist1, dist2;
    public static boolean[] vis;


    public static void dfs(int u, int d, int col){
        for(int v : adjList.get(u)){
            if(vis[v]) continue;
            vis[v] = true;
            if(col == 0){
                dist1[v] = d + 1;
            } else{
                dist2[v] = d + 1;
            }
            dfs(v, d+1, col);
        }
    }


    public static void main(String[] args) throws Exception{
        N = Integer.parseInt(br.readLine());
        adjList = new ArrayList<ArrayList<Integer>>();
        for(int i = 0; i < N; i++){
            adjList.add(new ArrayList<Integer>());
        }

        for(int i = 0; i < N - 1; i++){
            st = new StringTokenizer(br.readLine());
            int u = Integer.parseInt(st.nextToken()) - 1;
            int v = Integer.parseInt(st.nextToken()) - 1;
            adjList.get(u).add(v);
            adjList.get(v).add(u);
        }
        dist1 = new int[N];
        dist2 = new int[N];

        vis = new boolean[N];
        vis[0] = true;
        dfs(0, 0, 0);

        vis = new boolean[N];
        vis[N-1] = true;
        dfs(N-1, 0, 1);

        int a = 0;
        int b = 0;
        for(int i = 0; i < N; i++){
            if(dist1[i] <= dist2[i]){
                a++;
            } else if(dist1[i] > dist2[i]){
                b++;
            }
        }
        pw.print(a > b ? "Fennec\n" : "Snuke\n");


        pw.close(); 
        br.close();
    }
}

class Pair {
    public int a;
    public long b;

    Pair(int a, long b){
        this.a = a;
        this.b = b;
    }

}

Measured memory_bytes: 76792
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int a, e, k;
  foreach (i; 0..6) {
    if (i == 0) a = readln.chomp.to!int;
    else if (i == 4) e = readln.chomp.to!int;
    else if (i == 5) k = readln.chomp.to!int;
    else readln;
  }
  if (e - a <= k) {
    writeln("Yay!");
  } else {
    writeln(":(");
  }
}


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

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

	int v[1000],w[1000];
	for(int i=0;i<N;i++)
		cin>>v[i]>>w[i];

	int DP[101][10001];
	for(int i=0;i<=N;i++)
		DP[i][0]=0;
	for(int j=0;j<=W;j++)
		DP[0][j]=0;

	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(j<w[i-1])
				DP[i][j]=DP[i-1][j];
			else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
			}
		}
	}
	
	cout<<DP[N][W]<<endl;
	
	return 0;
}

	

Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<string> S(n);
  vector<vector<pair<int, int>>> T(4);
  int sum = 0;
  rep(i, n) {
    cin >> S[i];
    int cur = 0; int mn = 0;
    for(char c: S[i]) {
      cur += (c=='(' ? 1 : -1);
      mn = min(cur, mn);
    }
    sum += cur;
    if(cur >= 0) {
      if(mn == 0) T[0].emplace_back(mn, cur);
      else        T[1].emplace_back(mn, cur);
    } else {
      if(mn == cur) T[2].emplace_back(mn-cur, 0-cur);
      else          T[3].emplace_back(mn-cur, 0-cur);
    }
  }
  bool ok = true;
  if(sum != 0) ok = false;
  {
    int cur = 0;
    for(auto ele: T[0]) cur += ele.second;
    sort(all(T[1]), [&](pair<int, int> p1, pair<int, int> p2) {
        if(p1.first == p2.first) return p1.second > p2.second;
        return p1.first > p2.first;
      });
    for(auto ele: T[1]) {
      if(cur+ele.first < 0) ok = false;
      cur += ele.second;
    }
  }
  {
    int cur = 0;
    for(auto ele: T[2]) cur += ele.second;
    sort(all(T[3]), [&](pair<int, int> p1, pair<int, int> p2) {
        if(p1.first == p2.first) return p1.second > p2.second;
        return p1.first > p2.first;
      });
    for(auto ele: T[3]) {
      if(cur+ele.first < 0) ok = false;
      cur += ele.second;
    }
  }
  cout << (ok ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 42452
//24
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int mi;
    double mb=1<<30;
    while(n--){
      int i;
      double h,w;
      cin>>i>>h>>w;
      double mbid=fabs(w*10000/h/h-22);
      if(mbid<mb||mbid==mb&&i<mi){
	mi=i;
	mb=mbid;
      }
    }
    cout<<mi<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
H = list(map(int, input().split(" ")))

max_ = 0
count = 0
for n in range(N):
    if n == 0:
        continue
    if H[n] <= H[n - 1]:
        count += 1
        if count > max_:
            max_ = count
    else:
        count = 0
print(max_)


Measured memory_bytes: 63708
#include<stdio.h>
int main(void)
{
	int a, b, c;
	int xx;
	scanf("%d %d %d", &a, &b, &c);
	if (a > b)
	{
		xx = b;
		b = a;
		a = xx;
	}
	if(b > c)
	{
		xx = c;
		c = b;
		b= xx;
	}
	if (a > b)
	{
		xx = b;
		b = a;
		a = xx;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}


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


int main(){
  long h,w,n,i,j,jud=0,cur,zero=1;
  cin >> h >> w >> n;
  long sy,sx;
  cin >> sy >> sx;
  string s,t;
  cin >> s >> t;
  
  long sn=0,se=0,sw=0,ss=0,tn=0,te=0,tw=0,ts=0;
  for(i=0; i<n; i++){
    if(s[i]=='L') sw++;
    if(s[i]=='R') se++;
    if(s[i]=='U') sn++;
    if(s[i]=='D') ss++;
  }
  if(sw>=sx){
   
    cur=sx;
     for(i=0; i<n; i++){
       if(s[i]=='L') cur--;
       if(cur==0){
         jud=1; break;
       }
       if(t[i]=='R') cur=min(w,cur+1);
     }
  }
  if(jud==0 && se+sx>w){
    
    cur=sx;
    for(i=0; i<n; i++){
       if(s[i]=='R') cur++;
       if(cur>w){
         jud=1; break;
       }
       if(t[i]=='L') cur=max(zero,cur-1);
     }
  }
  if(jud==0 && sn>=sy){
   
    cur=sy;
    for(i=0; i<n; i++){
       if(s[i]=='U') cur--;
       if(cur<=0){
         jud=1; break;
       }
       if(t[i]=='D') cur=min(h,cur+1);
     }
  }
  if(jud==0 && ss+sy>h){
    cur=sy;
   
    for(i=0; i<n; i++){
       if(s[i]=='D') cur++;
       if(cur>h){
         jud=1; break;
       }
       if(t[i]=='U') cur=max(zero,cur-1);
     }
  }
  
  if(jud){
    cout << "NO";
  }else{
    cout << "YES";
  }
}

Measured memory_bytes: 776
#include <cstdio>
#include <algorithm>
#include <deque>

using namespace std;

struct war
{
    int a;
    int b;
};

bool cmp(const war& left, const war& right) {
    return left.b < right.b;
}

int main () {
    int N,M,a,b,sum=0;
    scanf("%d %d",&N,&M);
    war w;
    deque<war> wars;
    for (int i=0; i<M; i++) {
        scanf("%d %d",&a,&b);
        wars.push_back(war{a,b});
    }
    sort(wars.begin(),wars.begin()+M,cmp);
    while (wars.size() != 0) {
        w = wars.front(); wars.pop_front();
        for (size_t i=0; i<wars.size(); i++) {
            if(wars[i].a <= w.b-1) {
                wars.erase(wars.begin()+(int)i);
                i--;
            }
        }
        sum++;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	reverse(a.begin(),a.end());
	vi dp(n+1,inf);
	for(auto i:a){
		int id=upper_bound(dp.begin(),dp.end(),i)-dp.begin();
		dp[id]=i;
	}
	cout<<lower_bound(dp.begin(),dp.end(),inf)-dp.begin()<<endl;
}

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

const int MAX_N = 1000005;
int N;
int prime_arr[MAX_N];
int prime_cts2[MAX_N];
int prime_cts[MAX_N];
int vals[MAX_N];
std::vector<int> primes[MAX_N];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    vals[v]++;
  }

  for (int64_t i = 2; i < MAX_N; ++i) {
    if (prime_arr[i]) continue;
    prime_arr[i] = true;
    primes[i].push_back(i);
    for (int64_t j = i * i; j < MAX_N; j += i) {
      if (prime_arr[j] == 0)  primes[j].push_back(i);
      prime_arr[j] = true;
    }
  }
  bool pairwise = true;
  bool setwise = true;
  for (int i = 0; i < MAX_N; ++i) {
    // printf("I: %d\n", i);
    for (int k = 0; k < vals[i]; ++k) {
      int v = i;
      // printf("v:%d\n", v);
      while (v > 1) {
        int z = v;
        // printf("sz: %d %d\n", primes[z].size(), z);
        for (int p : primes[z]) {
          // printf("%d ", p);
          if (prime_cts[p] && v % p == 0) pairwise =  false;
          bool had_prime = false;
          while (v % p == 0) {
            v /= p;
            had_prime = true;
          }
          if (had_prime) {
            prime_cts[p] = 1;
            prime_cts2[p] += 1;
            if (prime_cts2[p] == N) setwise = false;
          }
        }
      }
      // printf("\n");
    }
  }
  if (pairwise) printf("pairwise coprime\n");
  else if (setwise) printf("setwise coprime\n");
  else printf("not coprime\n");
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint d(n);
  rep(i, n) cin >> d[i];
  sort(all(d));
  d.erase(unique(all(d)), d.end());
  cout << d.size() << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
d1 = 0  # p = 1のときのミンコフスキー距離
d2 = 0  # p = 2のときのミンコフスキー距離
d3 = 0  # p = 3のときのミンコフスキー距離
dx = 0  # p = ∞のときのミンコフスキー距離

for i in range(n):
    t = x[i] - y[i]
    if t < 0:  # 絶対値にするための処理
        t *= -1
    d1 += t
    d2 += t ** 2
    d3 += t ** 3
    if dx < t:
        dx = t
d2 = d2 ** (1.0 / 2.0)
d3 = d3 ** (1.0 / 3.0)
print(d1)
print(d2)
print(d3)
print(dx)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x-(x/y)*y);
}

int main(){

  ll A,B,C,D;
  IN(A,B,C,D);

  ll N_total = (B-A)+1;

  ll C_num = (B/C)-(A/C);
  if(A%C==0) C_num++;

  ll D_num = (B/D)-(A/D);
  if(A%D==0) C_num++;

  ll CD = C*(D/gcd(C,D));
  ll CD_num = (B/CD)-(A/CD);
  if(A%CD==0) CD_num++;

  ll N = 0;
  N += C_num;
  N += D_num;
  N -= CD_num;

  OUT(N_total - N);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

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

int main() {
  int n; cin >> n;
  vi a(n);
  int m; cin >> m;
  Loop(i, m) {
    int x, y; cin >> x >> y;
    if (x != 1) {
      a[x - 1]++;
    }
    if (y != 1) {
      a[y - 1]++;
    }
  }
  bool ans = true;
  Loop(i, n) {
    if (a[i] % 2 == 1) ans = false;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void) {
	int n;
	int na;
	int i;
	i = 1;
	int ans;

	
	scanf("%d", &n);
	na = n;

	while (na >= 10) {
		na = na / 10;
		i++;
	}

	switch (i)
	{
	case 1:ans = n;
		break;
	case 2:ans = 9;
		break;
	case 3:ans = n - 90;
		break;
	case 4:ans = 909;
		break;
	case 5:ans = n - 9090;
		break;
	case 6:ans = 90909;
		break;
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))

t = [0]+t+[t[-1]]
a = [a[0]]+a+[0]

ans = 1

for i in range(1,n+1):
    if t[i]==t[i-1] and a[i]==a[i+1]:
        ans *= min(t[i],a[i])
        ans %= 10**9+7
    elif t[i]!=t[i-1] and a[i]!=a[i+1]:
        if t[i]!=a[i]:
            print(0)
            exit()
    elif t[i]!=t[i-1] and t[i]>a[i]:
        print(0)
        exit()
    elif a[i]!=a[i+1] and a[i]>t[i]:
        print(0)
        exit()

print(ans)

Measured memory_bytes: 86500
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize, usize); m],
    }
    let mut d = vec![0; n];
    let mut g = vec![vec![]; n];
    for (s, t) in e {
        g[s].push(t);
        d[t] += 1;
    }
    let mut q = std::collections::VecDeque::new();
    for (v, d) in d.iter().enumerate() {
        if *d == 0 {
            q.push_back(v);
        }
    }
    while let Some(v) = q.pop_front() {
        for &u in g[v].iter() {
            d[u] -= 1;
            if d[u] == 0 {
                q.push_back(u);
            }
        }
    }
    if d.iter().any(|x| *x > 0) {
        println!("1");
    } else {
        println!("0");
    }
}

fn main() {
    run();
}



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

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

 for(int a=1;a<=9;a++)
    for(int b=1;b<=9;b++){if(a*b==n){cout<<"Yes";

return 0;
    }
    }

{cout<<"No";}
 }


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(void){
	int n;
	
	cin >> n;
	for(int i=0;i<n;i++){
		int hh,mm;
		double l,s,arg;
		cin >> hh;
		cin.ignore();
		cin >> mm;
		
		l = mm*6;
		s = hh*30+mm*0.5;
		l>s?arg = l-s:arg= s-l;
		
		if(arg > 180){
			arg = 360-arg;
		}
		if(arg < 30){
			cout << "alert" << endl;
		}else if(90 <= arg){
			cout << "safe" << endl;
		}else{
			cout << "warning" << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define inf 1e9+7
#define ll long long
#define clr(c) memset(c,0,sizeof(c))
const int M=2e5+10;
const int N=1e5+10;
using namespace std;
inline ll read()
{
	ll sum=0,b=1; char c=getchar();
	while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
	while(isdigit(c)){sum=sum*10+c-48; c=getchar();}
	return b*sum;
}
ll n,m,b,a;
char s[1000],t[1000],u[1000];
int main()	
{	
	ll i,j;
	scanf("%s %s",s,t);
	a=read(),b=read();
	scanf("%s",u);
	if(strcmp(s,u)==0)a--;
	else b--;
	printf("%d %d",a,b);
	return 0;
} 

Measured memory_bytes: 256
h1, h2 = map(int, raw_input().split())
k1, k2 = map(int, raw_input().split())
a, b, c, d = map(int, raw_input().split())

calc = lambda p, q: p*a+p/10*c+q*b+q/20*d
v1 = calc(h1, h2); v2 = calc(k1, k2)
print["hiroshi", "even", "kenjiro"][(v1<v2)+(v1<=v2)]

Measured memory_bytes: 6456
n = int(input())
t = 0
x = 0
y = 0
for i in range(n):
    nt , nx , ny = map(int,input().split())
    if nt - t >= nx - x + ny -y and ((nt - t) - (nx -x + ny -y)) % 2 == 0:
        t = nt
        x = nx
        y = ny
    else:
        print("No")
        exit()
print("Yes")

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

vector<int> tr[100001];

int go(int v = 1, int p = 0){
	int an = 0;
	f(i, 0, tr[v].size()){
		int u = tr[v][i];
		if (u == p)continue;
		an ^= 1 + go(u, v);
	}
	return an;
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	printf("%s\n", go() ? "Alice" : "Bob");
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

template<typename T> inline T gcd(T a, T b){T t;while(b){t=a;a=b;b=t%b;}return a;}
template<typename T> inline T lcm(T a, T b){return a*(b/gcd(a,b));}

string s;

int main()
{
  while(cin >> s, s != "#"){
    string t = "";
    vrep(v, s) if(*v == 'n' || *v == 'w') t += *v;
    ll q = (double)(1LL << (t.size()));
    ll p = 0LL;
    ll n = q / 2LL;
    if(t[t.size()-1] == 'w') p += 90LL * q;
    rev(i, t.size()-1){
      if(t[i] == 'n') p -= 90LL * n;
      if(t[i] == 'w') p += 90LL * n;
      n /= 2LL;
    }

    ll g = gcd(p, q);
    p /= g;
    q /= g;

    if(q == 1LL) cout << p << endl;
    else cout << p << "/" << q << endl;
  }

  return 0;
}

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

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

    for (int i = 0; i < (1 << 3); i++) {
        int sum = S[0] - '0';
        vector<bool> plus(3);
        for (int j = 0; j < 3; j++) {
            if ((i >> j) & 1) {
                sum += (S[j + 1] - '0');
                plus[j] = true;
            } else{
                sum -= (S[j + 1] - '0');
                plus[j] = false;
            }
        }

        vector<char> ops(3);
        for (int j = 0; j < 3; j++) {
            ops[j] = plus[j] ? '+' : '-';
        }

        if (sum == 7) {
            cout << S[0] << ops[0] << S[1] << ops[1] << S[2] << ops[2] << S[3] << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

pii p[400111];
int timer,tag[400111],f[400111],bit[400111];
void change(int x,int v)
{
	for(;x<400111;x+=(x&-x))
	{
		if(tag[x]!=timer)
		{
			tag[x]=timer;
			bit[x]=v;
		}
		else bit[x]=max(bit[x],v);
	}
}
int query(int x)
{
	int ret=0;
	for(;x>0;x-=(x&-x))
		if(tag[x]==timer)
			ret=max(ret,bit[x]);
	return ret;
}
void solve(int l,int r)
{
	if(l==r)return;
	int mid=(l+r)>>1;
	solve(l,mid);
	vector<pair<pii,int> >v;
	for(int i=l;i<=r;i++)
		v.pb(mp(mp(p[i].ff,-i),p[i].ss));
	sort(v.begin(),v.end());
	timer++;
	for(int i=0;i<(int)v.size();i++)
	{
		v[i].ff.ss=-v[i].ff.ss;
		if(v[i].ff.ss<=mid)change(v[i].ss,f[v[i].ff.ss]);
		else
		{
			int tmp=query(v[i].ss-1);
			if(tmp+1>f[v[i].ff.ss])
				f[v[i].ff.ss]=tmp+1;
		}
	}
	solve(mid+1,r);
}
pii a[400111];
int n,nn,x,y,xx,yy;
void go()
{
	vector<int> vy;
	for(int i=1;i<=n;i++)vy.pb(p[i].ss);
	sort(vy.begin(),vy.end());vy.erase(unique(vy.begin(),vy.end()),vy.end());
	for(int i=1;i<=n;i++)
		p[i].ss=upper_bound(vy.begin(),vy.end(),p[i].ss)-vy.begin();
}
int main()
{
	get2(x,y);get2(xx,yy);get1(n);
	for(int i=1;i<=n;i++)get2(a[i].ff,a[i].ss);
	if((x<xx&&y>yy)||(x>xx&&y<yy))
	{
		x=99999999-x;xx=99999999-xx;
		for(int i=1;i<=n;i++)a[i]=mp(99999999-a[i].ff,a[i].ss);
	}
	if(x>xx)
	{
		swap(x,xx);
		swap(y,yy);
	}
	if(x>xx||y>yy)puts("baojing");
	for(int i=1;i<=n;i++)if(a[i].ff>=x&&a[i].ff<=xx&&a[i].ss>=y&&a[i].ss<=yy)p[++nn]=a[i];
	n=nn;p[++n]=mp(xx+1,yy+1);
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)f[i]=1;
	go();
	solve(1,n);
	f[n]--;
//	printf("f= %d\n",f[n]);
	if(xx-x!=f[n]-1&&yy-y!=f[n]-1)printf("%.15lf\n",(yy-y)*100.0+(xx-x)*100.0-f[n]*(20-5*pi));
	else if(f[n]>0)printf("%.15lf\n",(yy-y)*100.0+(xx-x)*100.0-(f[n]-1)*(20-5*pi)-(20-10*pi));
	else printf("%.15lf\n",(yy-y)*100.0+(xx-x)*100.0);
	return 0;
}

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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;
const int MOD = 1e9 + 7;

const double PI = acos(-1);

int fact(int x) {
    if (x == 1)
        return 1;
    return x * fact(x - 1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    pair<double, double> a[n];
    for (auto& x : a)
        cin >> x.first >> x.second;
    double ans = 0;
    sort(a, a + n);
    do {
        for (int i = 0; i < n - 1; i++)
            ans += sqrt((a[i].first - a[i + 1].first) * (a[i].first - a[i + 1].first) + (a[i].second - a[i + 1].second) * (a[i].second - a[i + 1].second));
    } while (next_permutation(a, a + n));
    cout << setprecision(10) << ans / fact(n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t H;
    cin >> H;
    int64_t count = 1;
    int64_t sum = 1;
    while (H > 1) {
        H = H / 2;
        count = count * 2;
        sum += count;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a 
#define vb vector<long long int> b
const ll M = 1e9+7;
const ll inf = 1e18+5;
const ll INF=INT_MAX;
using namespace std;
void fast(){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);}
ll bs(ll arr[], ll l, ll r, ll x){
	ll mid=0;
    if (r >= l){
		if (arr[mid] == x) return mid; 
        if (arr[mid] > x) return bs(arr, l, mid - 1, x); 
        return bs(arr, mid + 1, r, x); 
    }
    return -1;
}
ll power(ll x,ul y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}
ll arr[500000],st[500000];
void buildtree(int si,int ss,int se){
	if(ss==se){
		st[si]=arr[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	buildtree(2*si,ss,mid);
	buildtree(2*si+1,mid+1,se);
	st[si]=min(st[2*si],st[2*si+1]);
}
int query(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return INF;
	if(ss>=qs && se<=qe)
		return st[si];
	int mid=ss+(se-ss)/2;
	int l=query(2*si,ss,mid,qs,qe);
	int r=query(2*si+1,mid+1,se,qs,qe);
	return min(l,r);
}
void update(int si,int ss,int se,int qi){
	if(ss==se){
		st[si]=arr[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	if(qi<=mid) update(2*si,ss,mid,qi);
	else update(2*si+1,mid+1,se,qi);
	st[si]=min(st[2*si],st[2*si+1]);
}

int numLen(int K) 
{ 

	// If K is a multiple of 2 or 5 
	if (K % 2 == 0 || K % 5 == 0) 
		return -1; 

	int number = 0; 

	int len = 1; 

	for (len = 1; len <= K; len++) { 

		// Instead of generating all possible numbers 
		// 1, 11, 111, 111, ..., K 1's 
		// Take remainder with K 
		number = (number * 10 + 1) % K; 

		// If number is divisible by k 
		// then remainder will be 0 
		if (number == 0) 
			return len; 
	} 

	return -1; 
} 

// Driver code 
int main() 
{ 
	fast();
	int k;
	cin>>k;
	if(k%7==0)
	k=k/7;
	cout << numLen(k); 

	return 0; 
} 


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  int t=0;
  
  vector<double> A(N);
  for (int i = 0; i < N; i++) {
  cin >> A.at(i);
  }
  
  
  for(int i=0; i<N; i++){
    
    double S,T,U;
    S=A.at(i)/6;
    T=A.at(i)/10;
    U=A.at(i)/2;
    
    int V,W,X;
    V=A.at(i)/6;
    W=A.at(i)/10;
    X=A.at(i)/2;
    
    
    if(V==S || W==T || X!=U ){
      t++;
    }
    
    else{
      t+=0;
    }
  }
  
  if(t==N){
    cout << "APPROVED" << endl;
  }
    
  else{
    cout << "DENIED" << endl;  
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define mod 1000000009
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int a, b;
char op;

int main() {
  // ios::sync_with_stdio(false);
  cin >> a >> op >> b;
  if (op == '-') cout << a - b;
  else cout << a + b;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int maxn = 18;
typedef long long ll;
ll dp[maxn][maxn][1 << maxn];
int a[maxn],n;
inline ll dfs(int l,int r,int lv,int rv,int st){
	if(~dp[l][r][st]) return dp[l][r][st];
	if(l + 1 == r) return (ll) lv * a[l] + (ll) rv * a[r];
	ll & ans = dp[l][r][st] = 1e18;
	for(int i = l + 1;i < r;++i){
		ans = std::min(ans,dfs(l,i,lv,lv + rv,st << 1) + dfs(i,r,lv + rv,rv,st << 1 | 1) - a[i] * ll(lv + rv));
	}
	return ans;
}
int main(){
	std::cin >> n, memset(dp,-1,sizeof dp);
	for(int i = 0;i < n;++i) std::cin >> a[i];
	std::cout << dfs(0,n - 1,1,1,1) << '\n';
}


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

using namespace std;

int dp[105][105];

int main() {
	int h, w; cin >> h >> w;
	vector<string> s(h);
	for (auto& e : s) cin >> e;
	for (int i = 0; i <= h; ++i)
		for (int j = 0; j <= w; ++j)
			dp[i][j] = 1e9;
	dp[0][0] = (s[0][0] == '#' ? 1 : 0);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (i + 1 < h) dp[i + 1][j] = min(dp[i][j] + (s[i][j] == '.' && s[i + 1][j] == '#' ? 1 : 0), dp[i + 1][j]);
			if (j + 1 < w) dp[i][j + 1] = min(dp[i][j] + (s[i][j] == '.' && s[i][j + 1] == '#' ? 1 : 0), dp[i][j + 1]);
		}
	}
	cout << dp[h - 1][w - 1] << endl;

	return 0;
}

Measured memory_bytes: 256