akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<u64> a;
  tools::read(a, N);

  if (std::all_of(a.begin(), a.end(), [](const u64 a_i) { return a_i == 0; })) {
    std::cout << "Yes" << std::endl;
  } else if (N % 3 != 0) {
    std::cout << "No" << std::endl;
  } else {
    std::unordered_map<u64, u64> map;
    for (const u64& a_i : a) {
      map.insert(std::make_pair(a_i, 0));
      ++map[a_i];
    }
    if (map.size() == 2) {
      std::vector<u64> keys;
      for (const std::pair<u64, u64>& pair : map) {
        keys.push_back(pair.first);
      }
      std::sort(keys.begin(), keys.end());
      std::vector<u64> values;
      for (const u64& key : keys) {
        values.push_back(map[key]);
      }

      if (keys[0] != 0 || values[0] * 2 != values[1]) {
        std::cout << "No" << std::endl;
      } else {
        std::cout << "Yes" << std::endl;
      }
    } else if (map.size() == 3) {
      std::unordered_set<u64> set;
      for (const std::pair<u64, u64>& pair : map) {
        set.insert(pair.second);
      }
      if (set.size() != 1) {
        std::cout << "No" << std::endl;
      } else {
        std::vector<u64> vector;
        for (const std::pair<u64, u64>& pair : map) {
          vector.push_back(pair.first);
        }
        if ((vector[0] ^ vector[1]) == vector[2]) {
          std::cout << "Yes" << std::endl;
        } else {
          std::cout << "No" << std::endl;
        }
      }
    } else {
      std::cout << "No" << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4260
#include <iostream>
using namespace std;
int main() {
  string s; cin>>s; bool ok=true;
  int n=s.size(); if (n%2) ok=false;
  for(int i=0;i<n;i++) {
    if (i%2==0 && s[i]!='h') ok=false;
    if (i%2==1 && s[i]!='i') ok=false;
  }
  cout<<(ok?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 210000
#define MAXM 410000
#define INF 2147483647
using namespace std;
template <typename T> inline void read(T &s)
{
	s = 0;char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) s = ((s+(s<<2))<<1)+ch-'0',ch = getchar();
}
int hed[MAXN],ed[MAXM<<1],nxt[MAXM<<1],flow[MAXM<<1],tl=1,s,t,dep[MAXN],cur[MAXN],S,T,n,to[MAXN];
inline void Line(int u,int v,int F)
{
	nxt[++tl] = hed[u],hed[u] = tl,ed[tl] = v,flow[tl] = F;
	nxt[++tl] = hed[v],hed[v] = tl,ed[tl] = u,flow[tl] = 0;
}
queue <int> Q;
vector <int> In[MAXN];
inline bool BFS(int s,int t)
{
	while(!Q.empty()) Q.pop();
	Q.push(s),memset(dep,0,sizeof(dep)),dep[s] = 1;
	while(!Q.empty())
	{
		int k = Q.front();Q.pop();
		if(k == t) return 1;
		for(int i = hed[k];i;i=nxt[i]) if(!dep[ed[i]] && flow[i])
			dep[ed[i]] = dep[k] + 1,Q.push(ed[i]);
	}
	return 0;
}
int DFS(int u,int F,int t)
{
	if(u == t) return F;
	for(int fl,&i = cur[u];i;i=nxt[i]) if(flow[i] && dep[ed[i]] == dep[u] + 1)
	{
		if(fl = DFS(ed[i],min(F,flow[i]),t))
			return flow[i] -= fl,flow[i^1] += fl,fl;
	}
	return 0;
}
inline int Dinic(int s,int t)
{
	int Sum = 0,tmp;
	while(BFS(s,t))
	{
		memcpy(cur,hed,sizeof(cur));
		while(tmp = DFS(s,INF,t)) Sum += tmp;
	}
	return Sum;
}
bool vis[MAXN];
int fa[MAXN];
inline void Check()
{
	while(!Q.empty()) Q.pop();
	Q.push(1);
	int Cnt = 0;
	while(!Q.empty())
	{
		int k = Q.front();Q.pop(),Cnt++;
		for(auto v:In[k]) if(!vis[v]) vis[v] = 1,Q.push(to[v]),fa[v] = k;
	}
	if(Cnt != n) return (void) (puts("-1"));
	for(int i = 1;i<n;++i) printf("%d %d\n",fa[i],to[i]);
}
int main()
{
	read(n),S = 1,T = n * 2;
	for(int i = 2;i<=n;++i) Line(S,i,1),Line(i+n-1,T,1);
	for(int i = 1,El,X;i<n;++i)
	{
		read(El);
		while(El--)
		{
			read(X),In[X].push_back(i);
			if(X != 1) Line(X,i+n,1);
		}
	}
	if(Dinic(S,T) != n-1) return puts("-1"),0;
	for(int i = 2;i<=n;++i) for(int j = hed[i];j;j=nxt[j]) if(flow[j]==0)
		to[ed[j]-n] = i;
	Check();
	return 0;
}

Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
using vec = vector < int >;

#define pb push_back
#define F  first
#define S  second
#define int int
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    fast();
    string s1,s2;
    cin >> s1 >> s2;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u==s1){
        cout<<a-1<<" "<<b;
    }
    else
        cout<<a<<" "<<b-1;
    return 0;
}
 

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt1=[0]*n
cnt2=[0]*n
for i in range(n):
    if a[i]>b[i]:
        cnt2[i]=a[i]-b[i]
    else:
        num4=b[i]-a[i]
        cnt1[i]=-(num4//-2)
        cnt2[i]=num4%2
num5=abs(sum(a)-sum(b))
if max(sum(cnt1),sum(cnt2))+abs(sum(cnt1)-sum(cnt2))<=num5:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 10484
import sys, collections

def solve():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    edge = [[] for i in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)

    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p-1] += x
    visited = [False] * N

    q = collections.deque()
    q.append(0)
    while q:
        now = q.popleft()
        if not visited[now]:
            visited[now] = True
            cnow = counter[now]
            for next in edge[now]:
                if not visited[next]:
                    counter[next] += cnow
                    q.append(next)

    print(" ".join(map(str, counter)))

    return 0

if __name__ == "__main__":
    solve()

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int plan1 = N * A;
  int plan2 = B;
  int min;
  if (plan1 <= plan2) {
    min = plan1;
  }
  else {
    min = plan2;
  }
  cout << min << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    set<ll> a;
    ll k = n - 1;
    if(k != 1)
    a.insert(k);
    for (ll i = 2; i * i <= k; i++)
    {
        if (k % i == 0)
        {
            a.insert(k / i);
            a.insert(i);
        }
    }
    set<ll> b;
    b.insert(n);
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            b.insert(n / i);
            b.insert(i);
        }
    }
    ll cnt = 0;
    for (auto v : b)
    {
        ll nn = n;
        while (nn % v == 0)
        {
            nn /= v;
        }
        if (nn % v != 1)
            cnt++;
    }
    cout << a.size() + b.size() - cnt << endl;
}

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

int main(void) {
  int n, m;
  cin >> n >> m;
  pair<int, int> ab[n];
  rep (i, n) cin >> ab[i].first >> ab[i].second;

  sort(ab, ab + n);

  priority_queue<int> Q;
  int nowId = 0;

  ll ans = 0;
  for (int i = 1; i <= m; i++) {
    if (nowId < n) {
      while (ab[nowId].first <= i) {
        Q.push(ab[nowId].second);
        nowId++;
        if (nowId >= n) break;
      }
    }
    if (!Q.empty()) {ans += Q.top(); Q.pop();}
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1660
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[[0 for j in range(26)] for i in range(D)]
manzokudo=0
for d in range(D):
    k=0
    manzokudomax=-10**30
    nowmanzoku=manzokudo
    for i in range(26):
        if d!=0:
            last[d][i]=last[d-1][i]
    for j in range(26):
        tmp=last[d][j]
        last[d][j]=d+1
        nowmanzoku+=s[d][j]
        for i in range(26):
            nowmanzoku-=c[i]*(d+1-last[d][i])
        if nowmanzoku>manzokudomax:
            k=j
            manzokudomax=nowmanzoku
        last[d][j]=tmp
    for i in range(26):
        if d!=0:
            last[d][i]=last[d-1][i]
    last[d][k]=d+1
    nowmanzoku+=s[d][k]
    for i in range(26):
        nowmanzoku-=c[i]*(d+1-last[d][i])
    manzokudo=nowmanzoku
    print(k+1)


Measured memory_bytes: 9516
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a))cin >> a[i]
#define ccin(i, j, a) rep(i, length(a))rep(j, length(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
int main(){
    string s;
    cin >> s;
    bool flag = true;
    intl n = s.length();
    rep(i,n){
        if(s[i] != s[n - i - 1])flag = false;
    }
    rep(i,(n-1)/2){
        if(s[i] != s[(n-1)/2-i-1])flag = false;
    }
    repi(i,(n+3)/2,n){
        if(s[i] != s[n-i-1])flag = false;
    }
    fp(flag);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <tuple>
#include <unordered_map>
using namespace std;
const int mod = 1000000007;

int main() {


		
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a;
	unordered_map<int, int> mp;
	bool flag = true;
	while (mp.find(sum%b) == mp.end()) {
		if (sum % b == c) {
			cout << "YES" << endl;
			flag = false;
			break;
		}
		mp[sum % b]++;
		sum += a;
		
	}
	
	
	if (flag == true) {
		cout << "NO" << endl;
	}
	
	
	

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
#include <cmath>
#include <iomanip> //setprecision(2)
#include <set>
using namespace std;
int n;
set <int> mochi;
int main(){
        cin>>n;
        for(int i=0; i<n; i++) {
                int t;
                cin>>t;
                mochi.insert(t);
        }
        cout<<mochi.size()<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 ll n,k;
 ll max(ll a, ll b) { return (a > b)? a : b; }  
 
 
 
 
 
 
 
ll solve(ll a[],ll b[],ll i,ll k){
  ll arr[i+1][k+1]={0};
    
    for(int j=0;j<=i;j++){
        
        for(int w=0;w<=k;w++){
            
            
            if(j==0||w==0)arr[j][w]=0;
            
            
            else if(a[j-1]<=w){
                arr[j][w]=max(b[j-1]+arr[j-1][w-a[j-1]],arr[j-1][w]);
                
            }else arr[j][w]=arr[j-1][w];
            
            
            
        }
    }
    
    
    return arr[i][k];
    
    }


int main(){
    
   
    cin>>n>>k;
    ll a[n];
    ll b[n];
    for(ll i=0;i<n;i++){cin>>a[i];
    
    cin>>b[i];
        
    }
//   vector<vector<int>>v;
//   for(int i=0;i<n;i++){
//       cin>>v[i][0];
//       cin>>v[i][1];
  
  
    
  ll t = solve(a,b,n,k);
    cout<<t<<endl;
    
    
}

Measured memory_bytes: 79104
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N, K;
  cin >> N >> K;
  if (N == K) {
    cout << 1 << endl;
  } else {
    cout << 1 + (N - 2) / (K - 1) << endl;
  }
  return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int cnt[10][10];

int countDigit(int n){
    int digit = 1;
    clock_t start,end;

    start = clock();

    while((n /= 10) != 0)
        digit++;
    return digit;
}

int main(){
    int N;
    string str;
    cin >> N;
    REP(i,0,10){
        REP(j,0,10){
            cnt[i][j]=0;
        }
    }
    REP(i,1,N+1){
        str = to_string(i);
        cnt[str[0]-'0'][str[str.size()-1]-'0']++;
    }
    int ans=0;
    REP(i,0,10){
        REP(j,0,10){
            ans+=cnt[i][j]*cnt[j][i];
        }
    }
    P(ans);
}

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

int main() {
  int N;
  cin >> N;
  string S,a = "Three";
  for (int i = 0; i < N; i++) {
    cin >> S;
    if(S == "Y") {
      a = "Four";
      break;
    }
  }
  cout << a << endl;
}

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

using ll=long long;
const ll MOD=924844033;
int main(){
    int n,k;
    cin>>n>>k;
    vector<vector<ll>> dps(k);
    for(int i=0;i<k;i++){
        int sz=n/k+(int)(i<n%k);
        vector<vector<vector<vector<int>>>> dp(2,vector<vector<vector<int>>>(sz+1,vector<vector<int>>(2,vector<int>(2))));
        dp[0][0][1][0]=1;
        for(int i=0;i<sz;i++){
            for(int j=0;j<=sz;j++){
                for(int v0=0;v0<2;v0++){
                    for(int v1=0;v1<2;v1++){
                        dp[(i+1)&1][j][v0][v1]=0;
                    }
                }
            }
            for(int j=0;j<=sz;j++){
                for(int v0=0;v0<2;v0++){
                    for(int v1=0;v1<2;v1++){
                        (dp[(i+1)&1][j][v1][0]+=dp[i&1][j][v0][v1])%=MOD;
                        if(j+1<=sz){
                            (dp[(i+1)&1][j+1][v1][1]+=dp[i&1][j][v0][v1])%=MOD;
                            if(v0==0) (dp[(i+1)&1][j+1][v1][0]+=dp[i&1][j][v0][v1])%=MOD;
                        }
                    }
                }
            }
        }
        // cerr<<i<<endl;
        dps[i].resize(sz+1);
        for(int j=0;j<=sz;j++){
            dps[i][j]=(dp[sz&1][j][0][0]+dp[sz&1][j][1][0])%MOD;
        }
        // cerr<<i<<endl;
    }
    // for(int i=0;i<k;i++){
    //     for(int j=0;j<dps[i].size();j++){
    //         cerr<<i<<" "<<j<<" "<<dps[i][j]<<endl;
    //     }
    // }
    // cerr<<"#"<<endl;
    vector<int> dp(1);
    dp[0]=1;
    for(int i=0;i<k;i++){
        vector<int> nex(dp.size()+dps[i].size()-1);
        for(int j0=0;j0<dp.size();j0++){
            for(int j1=0;j1<dps[i].size();j1++){
                (nex[j0+j1]+=ll(dp[j0])*dps[i][j1]%MOD)%=MOD;
            }
        }
        dp=nex;
    }
    // cerr<<dp.size()<<endl;
    assert(dp.size()==n+1);
    ll res=0;
    vector<ll> fact(n+1);
    fact[0]=1;
    for(int i=1;i<=n;i++){
        fact[i]=fact[i-1]*i%MOD;
    }
    for(int i=0;i<=n;i++){
        ll v=ll(dp[i])*fact[n-i]%MOD;
        // cerr<<v<<endl;
        if(i%2==0) res+=v;
        else res-=v;
    }
    res=(res%MOD+MOD)%MOD;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
        long long int n,m;
        cin>>n>>m;
        long long int ans=0;
        if(n==1&&m==1){ans=1;}
        else if(n==1||m==1){ans=max(n,m);ans-=2;}
        else {ans=(n-2)*(m-2);}
        cout<<ans<<endl;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
#[allow(unused_imports)]
use std::io::{stdout, Write};
fn main() {
    let strin: String = read();
    let v: Vec<u32> = strin.chars().map(|x| x.to_digit(10).unwrap()).collect();
    let v:Vec<i32> = v.into_iter().map(|x| x as i32).collect();
    if v[0] + v[1] + v[2] + v[3]  == 7 {
        println!("{}+{}+{}+{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] - v[1] + v[2] + v[3]  == 7 {
        println!("{}-{}+{}+{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] + v[1] - v[2] + v[3]  == 7 {
        println!("{}+{}-{}+{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] - v[1] - v[2] + v[3]  == 7 {
        println!("{}-{}-{}+{}=7", v[0], v[1], v[2], v[3]); //4
    } else if v[0] + v[1] + v[2] - v[3]  == 7 {
        println!("{}+{}+{}-{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] - v[1] + v[2] - v[3]  == 7 {
        println!("{}-{}+{}-{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] + v[1] - v[2] - v[3]  == 7 {
        println!("{}+{}-{}-{}=7", v[0], v[1], v[2], v[3]);
    } else if v[0] - v[1] - v[2] - v[3]  == 7 {
        println!("{}-{}-{}-{}=7", v[0], v[1], v[2], v[3]); //8
    }
}


Measured memory_bytes: 4352
import kotlin.math.*
import java.util.*
import java.io.*

fun main() {
    val (d,t,s) = readLine()!!.split(" ").map { it.toLong() }
    val time:Long = d/s
    val rest:Long = d%s
    if(time < t){
        println("Yes")
    }
    else if(time == t && rest == 0L)
    {
        println("Yes")
    }
    else{
        println("No")
    }
}

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x, n = input_to_int_map()
    p_list = input_to_int_tuple()

    target = []
    for i in range(-1, 102):
        if i not in p_list:
            target.append(i)

    sa = 200
    ret = x
    for val in target:
        t_sa = abs(x - val)
        if sa > t_sa:
            sa = t_sa
            ret = val

    return ret



if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9216
N = int(input())
S = input()
ans = 0
for i in range(1000):
  p = str(i).zfill(3)
  if S.find(p[0])==-1:
    continue
  S1 = S[S.find(p[0])+1:]
  if S1.find(p[1])==-1:
    continue
  S2 = S1[S1.find(p[1])+1:]
  if S2.find(p[2])==-1:
    continue
  ans+=1
print(ans)

Measured memory_bytes: 9232
#include <stdio.h>
#include <string.h>
int main()
{
    int i;
    char a[10000];
    gets(a);
    if(a[0]<='Z'&&a[0]>='A')printf("%c",a[0]);
    for(i=0; i<strlen(a); i++)
        if(a[i]==' '&&a[i+1]<='Z'&&a[i+1]>='A')printf("%c",a[i+1]);
    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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int L[n];
    REP(i,n) cin >> L[i];
    sort(L,L+n);

    int ans = 0;
    REP(i,n){
        FOR(j,i+1,n){
            int wa = L[i] + L[j];
            int l = j;
            int r = n;
            while(l + 1 < r){
                int mid = (l + r) / 2;
                if(L[mid] < wa){
                    l = mid;
                }
                else r = mid;
            }
            ans += l - j;
        }

    }
    cout << ans << endl;
}

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

int main()
{
	int r, n;

	cin >> n;

	int maxv = INT_MIN;
	int minv = INT_MAX;

	for (int i = 0; i < n; i++) {
		cin >> r;
		maxv = max(maxv, r - minv);
		minv = min(minv, r);
	}

	cout << maxv << endl;

	return 0;
}



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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 2.1e5;
int N;
string S;
int op[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> S;
	S.insert(S.begin(), 'W');
	op[0] = 0;
	for (int i = 1; i <= 2*N; i++) {
		op[i] = (op[i-1] ^ (S[i-1] == S[i]));
	}

	int cnt = 0;
	num ans = 1;
	for (int i = 1; i <= 2*N; i++) {
		if (op[i] == 1) {
			ans *= cnt--;
		} else {
			cnt++;
		}
	}
	if (cnt) {
		ans = 0;
	}
	for (int i = 1; i <= N; i++) {
		ans *= i;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1360
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    vector<string> v;
    vector<int> vn;
    int n;
    cin >> n;
    string st;
    string checks = "???";
    int ans =0;
    int count=0;
    rep(i,n){
        cin >>st;
        v.push_back(st);
    }
    sort(v.begin(),v.end());
    v.push_back("dummy2");

    rep(i,v.size()){
        if(checks == v[i]){
            count ++;
        }else{
            if(ans ==count&&i!=0){
                vn.push_back(i-1);
            }else if(ans<count){
                ans = count;
                vn.clear();
                vn.push_back(i-1);
            }
            count = 1;
        } 
        checks = v[i];
    }
    rep(i,vn.size()){
        cout<<v[vn[i]]<<endl;
    }
}

Measured memory_bytes: 9708
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Mi(int X,int Mod)
{
	if(X==0)
		return 1;
	int res=Mi(X/2,Mod);
	res*=res;
	if(X%2)
		res*=2;
	return res%Mod;
}
int Ex(int X)
{
	if(X==0)
		return 0;
	return Ex(X%__builtin_popcount(X))+1;
}
signed main()
{
	int mod1=0,mod2=0;
	int N;
	cin>>N;
	string S;
	cin>>S;
	for(int i=0;i<N;i++)
		if(S[i]=='1')
			mod1++,
			mod2++;
	mod1++;
	mod2--;
	int X1=0,X2=0;
	for(int i=0;i<N;i++)
	{
		X1=(X1+X1)%mod1;
		if(S[i]=='1')
			X1++;
		X1%=mod1;
		if(!mod2)
			continue;
		X2=(X2+X2)%mod2;
		if(S[i]=='1')
			X2++;
		X2%=mod2;
	}
	for(int i=0;i<N;i++)
		if(S[i]=='1')
		{
			if(!mod2)
			{
				cout<<0<<endl;
				continue;
			}
			int Tmp=X2;
			Tmp-=Mi(N-i-1,mod2);
			Tmp%=mod2;
			Tmp+=mod2;
			Tmp%=mod2;
			cout<<Ex(Tmp)+1<<endl;
		}
		else
		{	
			int Tmp=X1;
			Tmp+=Mi(N-i-1,mod1);
			Tmp%=mod1;
			Tmp+=mod1;
			Tmp%=mod1;
			cout<<Ex(Tmp)+1<<endl;
		}
	return 0;
}

Measured memory_bytes: 3756
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	int n, h[30], i, ans = 0 , k = 0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> h[i];
		k = max(k, h[i]);
		if (k <= h[i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N, M;
int A[200000];
int main() {
	cin >> N >> M;
	REP(i, 0, M) {
		int a, b;
		cin >> a >> b;
		if (a > b) swap(a, b);
		if (a == 1) A[b] |= 1;
		if (b == N) A[a] |= 2;
	}
	cout << (find(A, A + N, 3) == A + N ? "IM" : "") << "POSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1024
char*p[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
a[12]={31,29,31,30,31,30,31,31,30,31,30,31},i,m,d,t;
main(){
    for(;~scanf("%d%d",&m,&d);){
        if(!m)return 0;
        for(i=t=0;i<m-1;t+=a[i++]);
        printf("%s\n",p[(t+d)%7]);
    }
}

Measured memory_bytes: 1732
#include <algorithm>
#include <iostream>

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

const long long INF = 1LL << 60;
using namespace std;

const int MAX_N = 110;
const int MAX_V = 100100;

long long dp[MAX_N][MAX_V];

int main() {
	int N, W; cin >> N >> W;
	long long weight[MAX_N], value[MAX_V];

	for (int i = 0; i < N; i++) scanf("%lld%lld", &weight[i], &value[i]);

	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_V; j++) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
			if (sum_v - value[i] >= 0) {
				chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
			}
			chmin(dp[i + 1][sum_v], dp[i][sum_v]);
		}
	}

	long long res = 0;
	for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
		if (dp[N][sum_v] <= W) res = sum_v;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 86272
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vl divisor(ll k){
	vl c;
	for(ll i=1; i*i<=k; i++){
		if(k % i == 0){
			c.push_back(i);
			if((k / i) != i){
				c.push_back(k/i);
			}
		}
	}
	sort(c.begin(), c.end());
	return c;
}

int main(){
	ll n; cin >> n;
	vl div = divisor(n);
	ll ans = 0;
	for(auto q : div){
		ll m = n / q;
		if(m-1 > q) ans += m-1;
	}
	cout << ans << endl;
}

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

//桁和
int digsum(int n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}


int main() {
    string S; cin >> S;
    ll D; cin >> D;
    ll N = S.size();

    if(N <= 7){
        ll cnt = 0;
        for(int i = 1; i <= stoll(S); i++){
            if(digsum(i) % D == 0) cnt++;
        }
        cout << cnt%MOD << endl;
        return 0;
    }
    vector<vector<vector<ll>>> DP(N, vector<vector<ll>>(10, vector<ll>(D)));
    vector<vector<ll>> SUM(N, vector<ll>(D));

    for(int i = 0; i <= 9; i++) {
        DP[0][i][i%D]++;
        SUM[0][i%D]++;
    }

    // 下からi桁目の数がjの時のdigsumが k (mod D)
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < D; k++){
                DP[i][j][(j+k)%D] = SUM[i-1][k]%MOD;
                SUM[i][(j+k)%D] += SUM[i-1][k]%MOD;
                DP[i][j][(j+k)%D]%=MOD;
                SUM[i][(j+k)%D]%=MOD;
            }
        }
    }
    ll ans = SUM[N-2][0];
    ll temp = 0;
    //cout << ans << endl;
    for(int i = N-1; i >= 0; i--){
        ll d = S[N-1-i]-48;
        for(int j = 0; j <= d; j++) {
            if(i == N-1 && j == 0) continue;
            if(j == d && i != 0) continue;
            ll n = (temp)%D;
            ans += DP[i][j][(D-n)%D]; // i桁目がjの時にDの倍数になるもの
            //cout << i << " " << j << " " << (D-n)%D << " " << DP[i][j][(D-n)%D] << endl;
            ans %= MOD;
        }
        temp += d;
    }
    cout << (ans-1+MOD)%MOD << endl;;

}

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

int main(){
    string str;
    cin >> str;
    reverse(str.begin(), str.end());

    int i = 0;
    while(str[i] != '\0'){
        if(str[i] == 'm'){
            if(str[i + 1] == 'a' && str[i + 2] == 'e' && str[i + 3] == 'r' &&
                str[i + 4] == 'd'){
                    i += 5;
            }
            else{
                cout << "NO" << endl;
                return 0;
            }
        }
        else if(str[i] == 'r'){
            if(str[i + 1] == 'e' && str[i + 2] == 'm'){
                if(str[i + 3] == 'a' && str[i + 4] == 'e' && str[i + 5] == 'r' &&
                    str[i + 6] == 'd'){
                        i += 7;
                }
                else{
                    cout << "NO" << endl;
                    return 0;
                }
            }
            else if(str[i + 1] == 'e' && str[i + 2] == 's'){
                if(str[i + 3] == 'a' && str[i + 4] == 'r' && str[i + 5] == 'e'){
                    i += 6;
                }
                else{
                    cout << "NO" << endl;
                    return 0;
                }
            }
            else{
                cout << "NO" << endl;
                return 0;
            }
        }
        else if(str[i] == 'e'){
            if(str[i + 1] == 's' && str[i + 2] == 'a' && str[i + 3] == 'r' &&
                str[i + 4] == 'e'){
                    i += 5;
            }
            else{
                cout << "NO" << endl;
                return 0;
            }
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
const int maxk=100001;
using namespace std;
int main()
{
   long long x;
   cin>>x;
   long long z=100;
   int i;
   for(i=1;z<x;i++) {
        z = (long long)(z * 1.01);
   }
   cout<<i-1;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
 
int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(n);
    string s;
    getline(cin,s);
    for(int j=0; j<n; j++) {
      getline(cin,s);
      stringstream ss;
      ss << s;
      ss >> a[j].second;
      a[j].second*=-1;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      while(i<b.size()) {
        k++;
        a[j].first+=b[i];
        if(i&&c[i-1]) a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i]==10) {
          if(k<10)c[i]=2;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i-1]+b[i]==10) {
          if(k<10)c[i]=1;
          i++;
          continue;
        }
        i++;
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << -a[i].second << " " << a[i].first << endl;
  }
  return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    vector<int> p; // 正
    vector<int> m; // 負

    vector<int> a(N);
    REP(i,N) cin >> a[i]; 
    sort(all(a));

    ll M=0;
    REP(i,N){
        int tmp = a[i];
        if(i==0) {
            m.push_back(tmp);
            M -= tmp;
        } else if(i==N-1) {
            p.push_back(tmp);
            M += tmp;
        } else {
            if(a[i]>0) {
                p.push_back(a[i]);
                M += tmp;
            } else {
                m.push_back(a[i]);
                M -= tmp;
            }
        }
    }

    pl(M)

    REP(i,p.size()-1){
        cout << m[0] << " " << p[i+1] << endl;
        m[0] -= p[i+1];
    }

    REP(i,m.size()){
        cout << p[0] << " " << m[i] << endl;
        p[0] -= m[i];
    }

    return 0;
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll K;
    cin >> K;
    queue<ll> qu;

    ll cnt = 0;
    REP(i, 9) qu.push(i+1);
    while(1){
        ll val = qu.front();
        cnt++;
        if(cnt==K){
            cout << val << endl;
            return 0;
        }
        qu.pop();
        if(val%10>0) qu.push(10*val + (val%10)-1);
        qu.push(10*val + (val%10));
        if(val%10<9) qu.push(10*val + (val%10)+1);
    }

    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int i;
	for (i = 0; i < S.size(); ++i) {
		if (i % 2) {
			if ('R' == S[i]) break;
		}
		else {
			if ('L' == S[i]) break;
		}
	}
	if (S.size() == i) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 500000

void mergeSort(int [ ], int , int);

int cnt=0,n,s[N];

int main()
{
  int i,S[N];

  while(1)
    {
      scanf("%d",&n);
      if(n <= N && n > 0) break;
    }

  for(i=0;i<n;i++)
      scanf("%d",&S[i]);

  mergeSort(S,0,n-1);

  for(i=0;i<n-1;i++)
    printf("%d ",S[i]);
  
  printf("%d\n%d\n",S[i],cnt);
  
  return 0;
}

void mergeSort(int A[ ], int left, int right)
{
  int mid,i,j,k;
  if(left < right)
    {
      mid = (left + right) / 2;
      mergeSort(A,left,mid);
      mergeSort(A,mid+1,right);

      for (i = left; i <= mid; i++)
        s[i] = A[i];
      
      for (i = mid + 1, j = right; i <= right; i++, j--)
        s[i] = A[j];
      
      i = left;         
      j = right;       
    
      for (k = left; k <= right; k++)
	{
	  if (s[i] <= s[j])        
	    A[k] = s[i++];
	  else
	    A[k] = s[j--];
	  cnt++;
	}
    }
}




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


int main() {
    ll n; cin >> n;
    vector<ll> x(n),y(n);
    rep(i,n){
        cin >> x[i];
        y[i]=x[i];
    }
    sort(y.begin(),y.end());
    ll MID = n/2;
    ll mid = n/2-1;
    ll M=y[MID];
    ll m=y[mid];
    rep(i,n){
        if(x[i]>=M) cout << m;
        else cout << M;

        cout << endl;
    }
}

Measured memory_bytes: 5376
import Data.Functor( (<$>))
import Text.Printf( printf)

main = do
    [a,b,c] <- (read <$>) . words <$> getLine::IO [Double]
    let
	θ = pi * c/180

	s = a * h / 2
	l = a + b + sqrt (a^2 + b^2 - 2 * a * b * cos θ)
	h = b * sin θ

    printf "%.5f\n" s
    printf "%.5f\n" l
    printf "%.5f\n" h



Measured memory_bytes: 4264
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
using namespace std;
#define N (1000000000+7)
typedef long long ll;
typedef pair<int, int> P;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
ll dp[100010][3];

int main(void) {
	int n;
	cin >> n;
	vector<ll>a(n), b(n), c(n);
	for (int i = 0;i < n;i++)cin >> a[i] >> b[i] >> c[i];
	//0,1,2の順にa,b,cを考える
	dp[1][0] = a[0], dp[1][1] = b[0], dp[1][2] = c[0];
	for (int i = 2;i <= n;i++) {
		for (int j = 0;j <= 2;j++) {
			if (j == 0) {
				ll d1 = dp[i - 1][1] + a[i-1];
				ll d2 = dp[i - 1][2] + a[i-1];
				dp[i][0] = max(d1, d2);
			}
			else {
				if (j == 1) {
					ll d1 = dp[i - 1][0] + b[i-1];
					ll d2 = dp[i - 1][2] + b[i-1];
					dp[i][1] = max(d1, d2);
				}
				else {
					ll d1 = dp[i - 1][0] + c[i-1];
					ll d2 = dp[i - 1][1] + c[i-1];
					dp[i][2] = max(d1, d2);
				}
			}
		}
	}
	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
#include <iomanip>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359
LL A[200000],wa[200001];
int main(){
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	
	wa[0] = 0;
	map<LL,int> mp;
	mp[0]++;
	LL ans = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		wa[i+1] = wa[i] + A[i];
		ans += mp[wa[i+1]];
		mp[wa[i+1]]++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int num;
    Map<String, Integer> map = new HashMap<>();

    for(int i=0; i<n; i++){
      String s = sc.next();
      if(map.containsKey(s)){
        num = map.get(s) + 1;
        map.replace(s,num);
      }else{
        map.put(s,1);
      }
    }

    int count_max = 0;

    for(String key:map.keySet()){
      if(count_max<map.get(key)){
        count_max = map.get(key);
      }
    }

    ArrayList<String> list = new ArrayList<>();
    for(String key:map.keySet()){
      if(count_max==map.get(key)){
        list.add(key);
      }
    }

    Collections.sort(list);
    for(String s: list){
      System.out.println(s);
    }



  }
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<bool, int>> v(n + 1, { false, 0 });
	pair<int, int> ans{0,0};
	for (int i = 0; i < m; ++i ) {
		int j;
		string k;
		cin >> j >> k;
		if (v[j].first) {
			continue;
		}
		if (k == "WA") {
			v[j].second++;
		}
		else {
			v[j].first = true;
			ans.first++;
			ans.second += v[j].second;
		}
	}
	cout << ans.first << " " << ans.second << endl;

	return 0;
}


Measured memory_bytes: 1024