akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e15;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

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


void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int cnt[3][n+1];
    memset(cnt,0,sizeof(cnt));
    map<char,int>mp;
    mp['R']=2;
    mp['B']=0;
    mp['G']=1;
    for(int i=n-1;i>=0;i--)
    {
        for(int j=0;j<3;j++)
            cnt[j][i]=cnt[j][i+1];
        cnt[mp[s[i]]][i]++;
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]!=s[j])
            {
                int d=j-i;
                int z1=mp[s[i]];int z2=mp[s[j]],to=0;
                for(int k=0;k<3;k++)
                    if(z1!=k&&z2!=k)
                        to=k;
                ans=ans+cnt[to][j+1];
                if((j+d)<n&&mp[s[j+d]]==to)
                    ans--;
            }
        }
    }
    cout<<ans<<endl;
    
}


int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;

char S[202020];
ll Sc[202020], Kc[202020];
ll i, j, ans;
int main(){
    scanf("%lld%s", &N,S);
    fornum(i,0,N){
        if(S[i]=='.'){
            Kc[i + 1]++;
        }else{
            Sc[i + 1]++;
        }
        Sc[i + 1] += Sc[i];
        Kc[i + 1] += Kc[i];
    }
    ans = 1e12;
    fornum(i,0,N+1){
        ll a = Sc[i] + Kc[N]-Kc[i];
        //printf("%lld:%lld ", Sc[i],Kc[i]);
        if(a<ans){
            ans = a;
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 3584
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a,b,c = sorted([l[i], l[j], l[k]])
            if a==b or b==c:
                continue
            if a+b>c and b+c>a and c+a>b:
                ans += 1
print(ans)

Measured memory_bytes: 74208
#include<iostream>
using namespace std;
int main(){
	int m,n;
	long long int a,b,c;
	int i,j,k;
	const int MAX=1000000007;
	cin>>m>>n;
	c=m-n;
	if(c<0)c=-c;
	if(c>=2){
		cout<<0<<endl;
		return 0;
	}
	if(c==1){
		if(m>n)a=n;
		else a=m;
	}else a=m;
	for(b=1,i=1;i<=a;i++){
		b*=i;
		if(b>=MAX)b%=MAX;
	}
	b*=b;
	if(b>=MAX)b%=MAX;
	if(c==1)b*=(a+1);
	else b*=2;
	if(b>=MAX)b%=MAX;
	cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys

#1
#a,b=map(int,input().split())
#print(a*b)

#2
n=input()
s=list(map(int,input().split())) 
count=0

if 0 in s:
  print(0)
  sys.exit()
else:
  a=1
  for i in s:
    a*=i
    if a>10**18:
      print(-1)
      sys.exit()

print(a)

Measured memory_bytes: 21792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string>song(N);
  vector<int>time(N);
  for(int i=0;i<N;i++) cin>>song[i]>>time[i];
  string X;
  cin>>X;
  int j=0;
  for(int i=0;i<N;i++){
    if(X!=song[i])j++;
    else break;
  }
  int t=0;
  for(int i=j+1;i<N;i++){
    t+=time[i];
  }
  cout<<t<<endl;
}

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

using namespace std;

int main()
{
    char a[105],b[105],c[105];
    scanf("%s%s%s",a,b,c);
    int a1=0,b1=-1,c1=-1;
    char cc = a[0];
    while(a1!=strlen(a)&&b1!=strlen(b)&&c1!=strlen(c))
    {
        if(cc=='a')
        {
            a1++;
            cc = a[a1];
        }
        else if(cc == 'b')
        {
            b1++;
            cc = b[b1];
        }
        else
        {
            c1++;
            cc = c[c1];
        }
    }
    if(a1==strlen(a))
        printf("A\n");
    else if(b1==strlen(b))
        printf("B\n");
    else printf("C\n");
    return 0;
}

Measured memory_bytes: 256
def calc(n)
  e=["0", "1", "2", "3", "5", "7", "8", "9"]
  sprintf("%o",n).split(//).map{|x| e[x.to_i]}.join
end

if true then
  fh=STDIN
else
  fh=open("in0208.txt")
end
n=-999
while fh.gets do
  n=$_.chomp.to_i
  break if n==0
  puts calc(n)
end
abort ("data strange") if n!=0

Measured memory_bytes: 8896
from collections import deque
from sys import stdin
N, Q = [int(_) for _ in stdin.readline().rstrip().split()]
d = deque(stdin.readline().rstrip().split() for _ in range(N))
finished_time = 0
while len(d) > 0:
    p = d.popleft()
    time = int(p[1])
    remain = time - Q
    if remain > 0:
        d.append([p[0], remain])
        finished_time += Q
    else:
        finished_time += time
        print(p[0], finished_time)


Measured memory_bytes: 17400
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());

            var S = new Dictionary<string, int>();
            for (int i = 0; i < N; i++)
            {
                var input = Console.ReadLine();
                if (S.ContainsKey(input))
                {
                    S[input]++;
                }
                else
                {
                    S.Add(input, 1);
                }
            }
            var sorted_S = S.OrderByDescending(x => x.Value);

            var count = 0;
            var slist = new List<string>();
            foreach (var s in sorted_S)
            {
                if (S[s.Key] < count)
                {
                    break;
                }
                slist.Add(s.Key);
                count = S[s.Key];
            }

            var sorted_slist = slist.OrderBy(x => x, StringComparer.OrdinalIgnoreCase);
            foreach (var s in sorted_slist)
            {
                Console.WriteLine(s);
            }
        }
    }
}

Measured memory_bytes: 50032
import java.util.*;

/**
 * ABC086 A問題
 * シカのAtCoDeerくんは二つの正整数a,bを見つけました。 
 * aとbの積が偶数か奇数か判定してください。
 */

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        int a = sn.nextInt();
        int b = sn.nextInt();
        int ans = a * b;
        
        if((ans % 2) == 0) {
            System.out.print("Even");
        } else {
            System.out.print("Odd");
        }
    }
}


Measured memory_bytes: 21588
#include<stdio.h>
int main(void){
	int a,b;
	char str[1];
	while(scanf("%d %c %d",&a,str,&b)){
		if(str[0]=='?'){
			break;
		}
		else if(str[0]=='+'){
			printf("%d\n",a+b);
		}
		else if(str[0]=='-'){
			printf("%d\n",a-b);
		}
		else if(str[0]=='*'){
			printf("%d\n",a*b);
		}
		else if(str[0]=='/'){
			printf("%d\n",a/b);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<string.h>

void main(){
    char str_in[101]={},str_out[101]={};
    unsigned short i=0;
    scanf("%s",str_in);
    
    while(str_in[i] != '\0'){
        str_out[i] = 'x';
        i++;
    }
    str_out[i+1] = '\0';

    printf("%s\n",str_out);

}

Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] c = s.toCharArray();
        
        Set<String> st = new HashSet<String>();

        for (char cc:c) {
            st.add(String.valueOf(cc));
        }
        
        if (s.length()==st.size()) {
            System.out.println("yes");
        }
        else {
            System.out.println("no");
        }

        //System.out.println("yes");
        sc.close();
    }
}

Measured memory_bytes: 35220
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans = 0;
    vector<ll> bc(n);
    rep(i,n) {
        auto it = upper_bound(all(c),b[i]);
        bc[i] = c.end()-it;
    }
    rrep(i,n-1) bc[i] += bc[i+1];
    rep(i,n) {
        auto it = upper_bound(all(b),a[i]);
        if(it == b.end()) continue;
        ans += bc[it-b.begin()];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
  int count = 0;
  int alphabets[26]; for(int i=0;i<26;i++) alphabets[i] = 0;
  string str;
  while(getline(cin,str)){
    for(int i=0;i<str.size();i++){
      if(isalpha(str[i])) alphabets[tolower(str[i])-'a']++;
    }
  }

  for(int i=0;i<26;i++) printf("%c : %d\n",(i+'a'),alphabets[i]);
  return 0;
}


Measured memory_bytes: 3292
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 200
#define S 0
#define T 201
#define MV 10000000
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;
}
bool b[MV+5],B[MV+5];
int n,a[MN+5],head[MN+5],c[MN+5],d[MN+5],q[MN+5],top,cnt=1,s[MV/5],num,ans,cc,Num[2];
struct edge{int to,next,w;}e[MN*MN*10+5];
inline void ins(int f,int t,int w)
{
    e[++cnt]=(edge){t,head[f],w};head[f]=cnt;
    e[++cnt]=(edge){f,head[t],0};head[t]=cnt;
}
inline int Abs(int x){return x<0?-x:x;}
bool bfs()
{
    memset(d,0,sizeof(d));int i,j;
    for(d[q[top=i=1]=S]=1;i<=top;++i)
        for(j=c[q[i]]=head[q[i]];j;j=e[j].next)
            if(e[j].w&&!d[e[j].to]) d[q[++top]=e[j].to]=d[q[i]]+1;
    return d[T];
}
int dfs(int x,int f)
{
    if(x==T) return f;int used=0;
    for(int&i=c[x];i;i=e[i].next)
        if(e[i].w&&d[e[i].to]==d[x]+1)
        {
            int w=dfs(e[i].to,min(f-used,e[i].w));
            used+=w;e[i].w-=w;e[i^1].w+=w;
            if(used==f) return f;
        }
    return d[x]=-1,used;
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),B[a[i]]^=1,B[a[i]+1]^=1;
    for(int i=2;i<=MV;++i)
    {
        if(!b[i]) s[++num]=i;
        for(int j=1;s[j]*i<=MV;++j)
        {
            b[s[j]*i]=1;
            if(i%s[j]==0) break;
        }
    }
    for(int i=1;i<=n;++i)
    {
        if(B[a[i]]) s[++cc]=a[i],++Num[a[i]&1];
        if(B[a[i]+1]) s[++cc]=a[i]+1,++Num[(a[i]&1)^1];
    }
    for(int i=1;i<=cc;++i)
    {
        if(s[i]&1) ins(S,i,1); else ins(i,T,1);
        if(s[i]&1)for(int j=1;j<=cc;++j)if((~s[j]&1)&&Abs(s[i]-s[j])>2&&!b[Abs(s[i]-s[j])]) ins(i,j,1);
    }
    while(bfs()) ans+=dfs(S,10000);
    printf("%d",ans+(Num[0]-ans)/2*2+(Num[1]-ans)/2*2+((Num[0]-ans)&1)*3);
    return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll case1=x*a+y*b;
    ll case2=max(x,y)*2*c;
    ll case3=min(x,y)*2*c+abs(x-y)*(x>y?a:b);
    //cout<<case1<<" "<<case2<<" "<<case3<<endl;
    cout<<min({case1,case2,case3})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include<queue>

using namespace std;

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

Measured memory_bytes: 256
(function(stdin){
	var lines = stdin.toString().split(' ').map(Number);
	var resolt = (function (a,b,c){
		return (a < b && b < c)? "Yes":"No";
	}(lines[0],lines[1],lines[2]));
	console.log(resolt);
}(require('fs').readFileSync('/dev/stdin','utf8')));

Measured memory_bytes: 7380
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){FIN

    int n,m;cin>>n>>m;
    UnionFind tree(n);
    int count=0;
    REP(i,m){
        int x,y,z; cin>>x>>y>>z; 
        x--; y--;
        if (tree.same(x,y)) continue;
        tree.unite(x,y);
        count++;
    }

    cout<<n-count<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long double db;
int n,l;
int a[3000];
int main()
{
	std::ios::sync_with_stdio(false),std::cin.tie(0);
	std::cin >> n >> l;
	db x = 0,y = 0;
	for(int i = 0;i < n;++i) std::cin >> a[i];
	const db pi = std::acos(-1);
	for(int i = 0;i < n;++i){
		for(int j = 0;j < i;++j){
			x += std::cos(pi * (a[i] + a[j]) / l) * (n - (i - j) * 2);
			y += std::sin(pi * (a[i] + a[j]) / l) * (n - (i - j) * 2);
		}
	}
	x /= (db) n * (n - 1) * (n - 2) / 6;
	y /= (db) n * (n - 1) * (n - 2) / 6;
	printf("%.18Lf %.18Lf\n",x,y);
}


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

using namespace std;

int main()
{
   int n;
   cin>>n;
   int c=0;
   for(int i=0;i<n;i++)
   {	int x;cin>>x;
      if(i%2==0 && x%2==1)
      {
         ++c;
      }
   }
   cout<<c<<'\n';
  return 0;
}

Measured memory_bytes: 3532
from collections import deque
N,M,P = map(int,input().split())
INF = 10**18
edge = []
rev_edge = [[] for _ in range(N+1)]
dis = [INF]*(N+1)
dis[1] = 0
for i in range(M):
    A,B,C = map(int,input().split())
    edge.append((A,B,P-C))
    rev_edge[B].append(A)
d = deque()
can_arrive = set()
d.append(N)
can_arrive.add(N)
while d:
    x = d.popleft()
    for y in rev_edge[x]:
        if not y in can_arrive:
            d.append(y)
            can_arrive.add(y)

for i in range(N):
    update = False
    for j in range(M):
        A,B,cost = edge[j]
        if dis[A] != INF and dis[B] > dis[A]+cost:
            dis[B] = dis[A]+cost
            if B in can_arrive:
                update = True
ans = dis[N]
if update:
    print(-1)
else:
    print(max(0,-ans))

Measured memory_bytes: 76092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 int main() {
	int N;
   cin>>N;
   int check=0;
   for (size_t i = 0; i < 50000; i++)
   {
      if(floor(i*1.08)==N){cout<<i<<endl;
      check++;
      break;}
      
   }
   if(check!=1){{cout<< ":("<<endl;}}
   
	}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string A, B, C;
  cin >> A >> B >> C;

  long a = 0, b = 0, c = 0;
  long current = 'a';

  while (true) {
    if (current == 'a') { if (a == A.size()) { cout << "A" << endl; return; } else { current = A[a]; a++; } }
    if (current == 'b') { if (b == B.size()) { cout << "B" << endl; return; } else { current = B[b]; b++; } }
    if (current == 'c') { if (c == C.size()) { cout << "C" << endl; return; } else { current = C[c]; c++; } }
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << #x << ": " << x << '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r; cin >> r;
  cout <<  r * r << '\n';
}


Measured memory_bytes: 256
#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;}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  vector<ll> pls,mis;
  int zero=0;
  rep(i,N){
    if(A[i]>0) pls.push_back(A[i]);
    else if(A[i]<0) mis.push_back(abs(A[i]));
    else zero++;
  }
  sort(all(pls));
  sort(all(mis));
  reverse(all(pls));
  reverse(all(mis));

  if(pls.size()+mis.size()<K){
    cout<<0<<endl;
    return 0;
  }else if(pls.size()+mis.size()==K){
    if(mis.size()%2){
      if(zero) cout<<0<<endl;
      else{
        ll ans=1;
        rep(i,N) mul(ans,abs(A[i]));
        ans=MOD-ans;
        add(ans,MOD);
        cout<<ans<<endl;
      }
    }else{
      ll ans=1;
      rep(i,pls.size()) mul(ans,pls[i]);
      rep(i,mis.size()) mul(ans,mis[i]);
      cout<<ans<<endl;
    }
    return 0;
  }

  if(K%2==0||pls.size()>0){
    int p=0,m=0;
    vector<ll> v;
    int pari=0;
    rep(i,K){
      if(p==pls.size()){
        m++;
        pari^=1;
      }else if(m==mis.size()){
        p++;
      }else{
        if(pls[p]>=mis[m]) p++;
        else{
          m++;
          pari^=1;
        }
      }
    }

    if(pari){
      if((p>0&&m<mis.size())&&(m>0&&p<pls.size())){
        if(mis[m-1]*mis[m]<pls[p-1]*pls[p]){
          m--;p++;
        }else{
          m++;p--;
        }
      }else if(p>0&&m<mis.size()){
        p--;m++;
      }else if(m>0&&p<pls.size()){
        m--;p++;
      }
    }

    ll ans=1;
    rep(i,p) mul(ans,pls[i]);
    rep(i,m) mul(ans,mis[i]);
    cout<<ans<<endl;
    return 0;
  }else if(zero){
    cout<<0<<endl;
    return 0;
  }else{
    ll ans=1;
    reverse(all(mis));
    rep(i,K) mul(ans,mis[i]);
    ans=MOD-ans;
    add(ans,MOD);
    cout<<ans<<endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 6820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;
int main()
{
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = x * a + y * b;
    ans = min(ans, max(x, y) * c * 2);
    ans = min(ans, x * c * 2 + max(0LL, y-x) * b);
    ans = min(ans, y * c * 2 + max(0LL, x-y) * a);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a, b;
    char op;
    while (1) {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?') break;
        if (op == '+') a += b;
        else if (op == '-') a -= b;
        else if (op == '*') a *= b;
        else if (op == '/') a /= b;
        printf("%d\n", a);
    }
    return 0;
}


Measured memory_bytes: 1964
#include<stdio.h>

int fibo[50];

int  fib(int n){
  if(n == 0 || n == 1){
    fibo[n] = 1;
    return fibo[n];
  }
  if(fibo[n] != 0)return fibo[n];
  fibo[n] = fib(n-1) + fib(n-2);
  return fibo[n];
}

int main(){
  int i,n;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    fibo[i]=0;
  }

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

  return 0;
}
  



Measured memory_bytes: 2112
// ABC138B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<iomanip>
#include<vector>

using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	vector<double> R(N);
	double ans_R=0.0;
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
		R.at(i) = 1.0 / (double)A.at(i);
		ans_R += R.at(i);
	}
	double ans = 1.0 / ans_R;
	cout << defaultfloat<< setprecision(14);
	cout << fixed<< ans << endl;
}


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

int main() {
	long long N, a[6];
	cin >> N;
	for (int i = 0; i < 5; i++)cin >> a[i];
	long long mi = a[0];
	for (int i = 1; i < 5; i++)mi = min(a[i], mi);
	cout<< (N/mi)+5-(N%mi==0)<<endl;

}


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

int main()
{
    int a, b;

    while (cin >> a >> b) {
        if (a == 0 && b == 0)
            break;
        if (a > b)
            swap(a, b);
        cout << a << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 
	 int n=sc.nextInt();
	 
	 List<Long> a=new ArrayList<Long>();
	
	 for(int i=0;i<n;i++) {
		 long tmp=sc.nextLong();
		 a.add(tmp);
	 }
	 
	 Collections.sort(a);
	 
	long result = a.get(0);
	long max = a.get(n-1);
	
	

	
	double temp2=Math.abs(max/2.0-(double)a.get(0));
	
    for(int i=1;i<n;i++) {
    	
		if(Math.abs(max/2.0-(double)a.get(i))>temp2) {
			break;
		}else if(Math.abs(max/2.0-(double)a.get(i))<temp2){
			temp2 = Math.abs(max/2.0-(double)a.get(i));
			result = a.get(i);
		}
	}
	
	
	
	System.out.println(max+" "+result);
	
	
	
	
	 
	 
	 
	
	 
	 
	 
 }
	


}


Measured memory_bytes: 61644
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n;
    cin>>n;
    int c[n],v[n];
    loop(n,i,0)
        cin>>v[i];
    loop(n,i,0)
        cin>>c[i];
    int res=0;
    loop(n,i,0){
        if(v[i]>c[i])
            res+=(v[i]-c[i]);
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int H,W,K; cin >> H >> W >> K;
    VI x(4); REP(i,4){cin >> x[i]; x[i]--;}
    char c[H][W]; REP(i,H)REP(j,W) cin >> c[i][j];

    int d[H][W]; REP(i,H)REP(j,W) d[i][j] = INF;
    d[x[0]][x[1]] = 0;

    queue<int> q; q.emplace(x[0]*W+x[1]);
    while(!q.empty()){
        int loc = q.front(); q.pop();
        int s = loc/W, t = loc%W;
        int cost = d[s][t];

        REP(i,K){
            if(s-i-1<0 || c[s-i-1][t]=='@') break;
            if(d[s-i-1][t] <= cost) break;
            if(chmin(d[s-i-1][t], cost+1)) q.emplace((s-i-1)*W+t);
        }
        REP(i,K){
            if(s+i+1>=H || c[s+i+1][t]=='@') break;
            if(d[s+i+1][t] <= cost) break;
            if(chmin(d[s+i+1][t], cost+1)) q.emplace((s+i+1)*W+t);
        }
        REP(i,K){
            if(t-i-1<0 || c[s][t-i-1]=='@') break;
            if(d[s][t-i-1] <= cost) break;
            if(chmin(d[s][t-i-1], cost+1)) q.emplace(s*W+t-i-1);
        }
        REP(i,K){
            if(t+i+1>=W || c[s][t+i+1]=='@') break;
            if(d[s][t+i+1] <= cost) break;
            if(chmin(d[s][t+i+1], cost+1)) q.emplace(s*W+t+i+1);
        }
    }

    int ans = d[x[2]][x[3]]<INF ? d[x[2]][x[3]] : -1;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 8812
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<long long> p(a);
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }

    vector<long long> q(b);
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }

    vector<long long> r(c);
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }

    sort(p.begin(), p.end(), greater<long long>());
    sort(q.begin(), q.end(), greater<long long>());
    sort(r.begin(), r.end(), greater<long long>());

    long long res = 0;
    for (int i = 0, j = 0, k = 0; i + j + k < x + y; ) {
        long long pi = (i < x ? p[i] : 0);
        long long qj = (j < y ? q[j] : 0);
        long long rk = (k < c ? r[k] : 0);
        long long m = max({ pi, qj, rk });

        res += m;
        if (pi == m) {
            i++;
        } else if (qj == m) {
            j++;
        } else {
            k++;
        }
    }

    cout << res << endl;
}


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

#define Bye return 0
#define ll long long
const int MAX = 1e9+7;
const int SIZE = 1e5+1;

void solve(){
    int n; cin>>n;
    
    int a[n+1];
    memset(a, 0, sizeof a);
    bool no_solution = false; 
    for (int i=1; i<=n; i++){
        int e; cin>>e; a[e]++;
    }

    int counter = (n%2 == 0) ? n/2 : (n-1)/2;

    int res = 1;
    for (int i=1; i<=counter; i++)
        res = (res*2)%MAX;

    if(n%2 == 0){
        for (int i=1; i<=n-1; i+=2)
            if(a[i] != 2) {res = 0; break;}
    } else 
        for (int i=2; i<n; i+=2)
            if(a[i]!=2) {res = 0; break;}
    
    cout<<res<<endl;
}

int main()
{
    solve();
    Bye;
}

Measured memory_bytes: 4016
"use strict"
function main(arg) {
    var t = arg.trim().split("\n")[0].split(" ").map(Number)
    var r = t[0]
    var D = t[1]
    var startX = t[2]

    var prev = startX
    for (var i = 0; i < 10; i ++) {
        var tmp = r * prev - D
        console.log(tmp)
        prev = tmp
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21448
#include <stdio.h>

int main(){

  int Num;
  scanf("%d",&Num);
  int A[Num];

  for(int a = 0; a < Num; a++){
  scanf("%d",&A[a]);
  }

  for(int c = 0; c < Num ; c++){
    if(c < Num-1)
    {
        printf("%d ",A[c]);
        continue;
    }
    else
    printf("%d",A[c]);
  }
  printf("\n");

int j;
for(int i = 1; i < Num; i++){
  
  int key = A[i];
  j = i - 1;
  while(j >= 0 && A[j] > key){
    A[j+1] = A[j];
    j--;
    A[j+1] = key;
  }
  for(int c = 0; c < Num ; c++){
    if(c < Num-1)
    {
        printf("%d ",A[c]);
        continue;
    }
    else
    printf("%d",A[c]);
  }
  printf("\n");
}

return (0);
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  char a='a';
  for(int i=0;i<26;i++){
    if(!count(s.begin(),s.end(),a)){
      cout<<a;
      return 0;
    }
    a++;
  }
  cout<<"None";
}
  

Measured memory_bytes: 512
import sys
from collections import deque
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    N = int(input())
    red = []
    for _ in range(N):
        a, b = map(int, input().rstrip().split())
        red.append((a, b))
    blue = []
    for _ in range(N):
        c, d = map(int, input().rstrip().split())
        blue.append((c, d))
    red.sort(key=lambda x:x[1], reverse=True)
    blue.sort()

    count = 0
    blue = deque(blue)
    used = set()
    for b in blue:
        for i, r in enumerate(red):
            if i not in used:
                if r[0] < b[0] and r[1] < b[1]:
                    count += 1
                    used.add(i)
                    break
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39024
import java.util.Scanner;

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

        String[] s = sc.nextLine().split(" ");

        int matches = 0;
        if (s[0].equals(s[1])) {
            matches++;
        }
        if (s[1].equals(s[2])) {
            matches++;
        }
        if(s[0].equals(s[2])) {
            matches++;
        }

        if(matches == 1) {
            System.out.println("Yes");
        } else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long int
//#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(b<=a)
    {
        while(1)
        {
            b=b*2;
            k--;
            if(b>a || k<=0)
            break;
        }
    }
    if(b<=a)
    cout<<"No"<<endl;
    else if(c<=b && k<=0)
    cout<<"No"<<endl;
    else
    {
        while(1)
        {
            c=c*2;
            k--;
            if(c>b || k<=0)
            break;
        }
        if(b>a && c>b)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}

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

void irekae(char **a,int i,int h,int w);
void irekae2(char **a,int i,int h,int w);

int main(void)
{
        int h,w,hh;
        int i,j;
        char **a;

        scanf("%d%d",&h,&w);

        hh = h;


        //領域確保
        a = malloc(sizeof(char *)*h);
        for(i=0;i<h;i++)
                *(a+i) = malloc(sizeof(char)*w);


        //文字の読み込み
        for(i=0;i<h;i++){
                scanf("%s",*(a+i));
        }


        //取り除く
        for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                        if(*(*(a+i)+j)=='#')
                                j = 102;
                }
                if(j<102){
                        irekae(a,i,h,w);
                        i--;
                        h--;
                }
        }
        for(i=0;i<w;i++){
                for(j=0;j<h;j++){
                        if(*(*(a+j)+i)=='#')
                                j=102;
                }
                if(j<102){
                        irekae2(a,i,h,w);
                        i--;
                        w--;
                }
        }



        //文字の書き出し
        printf("\n");
        for(i=0;i<h;i++){
                for(j=0;j<w;j++)
                        printf("%c",*(*(a+i)+j));
                printf("\n");
        }


        //領域の開放
        for(i=0;i<hh;i++)
                free(*(a+i));
        free(a);


        return 0;
}

void irekae(char **a,int i,int h,int w)
{
        int ii,jj;

        for(ii=i;ii<h-1;ii++){
                for(jj=0;jj<w;jj++){
                        a[ii][jj] = a[ii+1][jj];
                }
        }

        return;
}

void irekae2(char **a,int i,int h,int w)
{
        int ii,jj;

        for(ii=i;ii<w-1;ii++){
                for(jj=0;jj<h;jj++){
                        a[jj][ii] = a[jj][ii+1];
                }
        }
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1, n-1):
    if p[i-1] > p[i] and p[i] > p[i+1]:
        cnt += 1

    elif p[i-1] < p[i] and p[i] < p[i+1]:
        cnt += 1

print(cnt)

Measured memory_bytes: 9184
#include <iostream>
#include <sstream>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
    char chara[100];

    cin >> chara;

    int box[150]={};

    for(int i=0;i<strlen(chara);i++){
        box[(int)chara[i]] ++;
    }

    bool check = true;
    for(int i=0;i<150;i++){
        if(box[i]%2!=0){
            check = false;
        }
    }

    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;

}

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

int main() {
  int N;
  vector<int64_t> ln(87);
  ln.at(0) = 2LL;
  ln.at(1) = 1LL;
  scanf("%d",&N);
  for (int i = 2; i <= N; i++) {
    ln.at(i) = ln.at(i - 1) + ln.at(i - 2);
  }
  printf("%ld\n",ln.at(N));
}

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

using namespace std;

#define endl '\n'

typedef long long ll;

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

ll dp[maxn][2];
vector<int> g[maxn];
int n;

ll dfs(int u, int p, int c){
	
	if(dp[u][c] != -1)
		return dp[u][c];
	
	ll ans = 1;
	
	for(auto &v : g[u]){
		if(v != p){
			ll s = 0;
			s += dfs(v, u, 1);
			s %= mod;
			if(c == 1)
				s += dfs(v, u, 0), s %= mod;
			ans *= s;
			ans %= mod;
		}
	}
	
	return dp[u][c] = ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	if(n == 1){
		cout << 2 << endl;
		return 0;
	}
	
	memset(dp, -1, sizeof(dp));
	
	cout << (dfs(1, 0, 0) + dfs(1, 0, 1)) % mod << endl;
	
	return 0;
}

Measured memory_bytes: 15616
#include <stdio.h>
  int main() {
      int  A, B, i, j, k;
      
    
      scanf("%d %d" ,&A ,&B);
      
     i = (A+B)%3;
     j = A%3;
     k = B%3;   
      if(i == 0){
      printf("Possible\n");
      }
      else if(j == 0){
      printf("Possible\n");
      }
      else if(k == 0){
      printf("Possible\n");
      }
       else {
       printf("Impossible\n");
     }
      return 0;
  }
      
      

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class a, int N, class T>
void fillArray(a(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

template<typename T>
class BIT {
public:
    BIT(int n = 0) :n(n), d(n + 1) {}
    void add(int i, T x) {
        for (i++; i <= n; i += i & -i) d[i] += x;
    }
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i & -i) x += d[i];
        return x;
    }
private:
    int n;
    vector<T> d;
};


int n;
ll a[100005];
ll b[100005];
int s[100005];
void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];
    copy(a, a + n, b);
    sort(b, b + n);
    ll m = (((ll)n) * ((ll)n + 1) / 2 + 1) / 2;
    ll l = 0, r = n;
    while (r - l > 1) {
        auto mid = (l + r) / 2;
        auto x = b[mid];
        vector<int> s(n + 1);
        reps(i, n) s[i] = (a[i - 1] < x ? -1 : 1) + s[i - 1];
        BIT<ll> bit(n + 200005);
        ll res = 0;
        rep(i, n + 1) {
            res += bit.sum(s[i] + 100002);
            bit.add(s[i] + 100002, 1);
        }
        if (res >= m) l = mid;
        else r = mid;
    }
    cout << b[l] << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 4608
#include<algorithm>
#include<iostream>
#include<iterator>
#include<vector>

int n, m;
int k;
std::vector<int> v;

int main()
{
	std::cin >> n >> m;
	for( int i = 1; i <= 2 * n; i++ ){
		v.push_back( i );
	}
	
	for( int i = 0; i < m; i++ ){
		std::cin >> k;
		if( !k ){
			std::vector<int> temp1, temp2;
			std::copy( v.begin(), v.begin() + n, std::back_inserter( temp1 ) );
			std::copy( v.begin() + n, v.end(), std::back_inserter( temp2 ) );
			for( int i = 0; i < 2 * n; i++ ){
				if( i % 2 ){
				 	v[i] = temp2[ i / 2 ];
				}
				else{
				 	v[i] = temp1[ ( i + 1 ) / 2 ];
				}
			}
		}
		else{
		 	std::vector<int> temp;
			std::copy( v.begin() + k, v.end(), std::back_inserter( temp ) );
			std::copy( v.begin(), v.begin() + k, std::back_inserter( temp ) );
			v = temp;
		}
	}
	
	for( int i = 0; i < 2 * n; i++ ){
		std::cout << v[i] << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1220
N = int(input())
A = list(map(int,input().split()))
# print(N,A,sep="\n")
data = set(A)

def gdc(a,b):
  if b==0:
    return a
  else:
    return gdc(b,a%b)

def culc(data):
  A_min=min(data)
  if set(map(lambda x: x%A_min,data))=={0}:
    return A_min
  A.sort()
  ans = A_min
  for i in A[1:]:
    ans=gdc(ans,i)
    if set(map(lambda x: x%ans,data))=={0}:
      return ans
  return ans

print(culc(data))

Measured memory_bytes: 14356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  int H, W;
  cin >> H >> W;
  vector<string> A(H + 2, string(W + 2, '#'));
  rep(i, 1, H + 1) {
    cin >> A[i];
    A[i] = '#' + A[i] + '#';
  }
  for (auto a : A) {
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
int main()
{
  //freopen("final_input.txt", "r", stdin);
  int n;
  cin>>n;
  int k;
  cin>>k;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    dp[arr[i]]=1;
  }
  dp[0]=0;

  for(int i=1;i<=k;i++)
  {
    for(int j=0;j<n;j++)
    {
      if((i-arr[j])<0)
      {
        dp[i]=0;
      }
      else
      {
          dp[i]=!dp[i-arr[j]];
          if(dp[i]==1)
          {
            break;
          }
      }

    }
  }

  if(dp[k]==1)
  {
    cout<<"First"<<endl;
  }
  else{
    cout<<"Second"<<endl;
  }



}


Measured memory_bytes: 4012
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int N,a,b,c,x,y,t,vis = 1,p;
	scanf("%d",&N);
	a = 0;
	b = 0;
	c = 0;
	while(N--)
	{
		scanf("%d %d %d",&t,&x,&y);
		a = t - a;
		b = abs(x - b);
		c = abs(y - c);
		p = abs(b+c-a);
		if(b+c > a) vis = 0;
		else if(p%2!=0) vis = 0;
		a = t;
		b = x;
		c = y;
	}
	if(vis == 1) printf("Yes\n");
	else printf("No\n");
}

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

int main(){
    vector<vector<int>> data(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> data.at(i).at(j);
        }
    }

    int n;
    cin>>n;
    int num;
    rep(a,n){
        cin>>num;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if(data.at(i).at(j)==num){
                    data.at(i).at(j)=0;
                }
            }
        }
    }

    bool flg=false;
    if(data.at(0).at(0)==0&&data.at(0).at(1)==0&&data.at(0).at(2)==0)flg=true;
    else if(data.at(1).at(0)==0&&data.at(1).at(1)==0&&data.at(1).at(2)==0)flg=true;
    else if(data.at(2).at(0)==0&&data.at(2).at(1)==0&&data.at(2).at(2)==0)flg=true;
    else if(data.at(0).at(0)==0&&data.at(1).at(0)==0&&data.at(2).at(0)==0)flg=true;
    else if(data.at(0).at(1)==0&&data.at(1).at(1)==0&&data.at(2).at(1)==0)flg=true;
    else if(data.at(0).at(2)==0&&data.at(1).at(2)==0&&data.at(2).at(2)==0)flg=true;
    else if(data.at(0).at(0)==0&&data.at(1).at(1)==0&&data.at(2).at(2)==0)flg=true;
    else if(data.at(2).at(0)==0&&data.at(1).at(1)==0&&data.at(0).at(2)==0)flg=true;

    if(flg==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


}


Measured memory_bytes: 3608