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

int main(){
  int a,b;
  cin >> a >> b;
  if(b == 1){
    cout << "0";
    return 0;
  }
  for(int i=1;i<3000;i++){
    if(i == 1){
      if(a >= b){
        cout << "1";
        return 0;
      }
    }
    else{
      if((i*a - i + 1) >= b){
        cout << i;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> a(n);
    vector<int> num(pow(10,5),0);
    for(int i=0;i<n;i++){
        cin>>a[i];
        num[a[i]]++;
    }
    sort(a.begin(),a.end());
    long long kazu=0;
    long long ans=num[0]+num[1];
    for(long long i=1;i<=a[n-1];i++){
        kazu=num[i-1]+num[i]+num[i+1];
        ans=max(ans,kazu);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int a1 = a;
     a = b;
     b = a1;
    
    int a2 = a;
     a = c;
     c = a2;
    
    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 21844
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    res = 0
    cnt = 0
    for a, b in ab:
        if cnt + b >= m:
            res += a * (m - cnt)
            print(res)
            return
        res += a * b
        cnt += b
    
if __name__ ==  '__main__':
    main()

Measured memory_bytes: 25828
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

int n, a[100000];
ll dp[100000][2];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	
	for (int i = 0; i < n; i++)
		dp[i][0] = dp[i][1] = -1e18;
	dp[0][0] = a[0];

	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
		dp[i][1] = max(dp[i - 1][0] + 2 * -a[i - 1], dp[i - 1][1] + 2 * a[i - 1]) - a[i];
	}
	printf("%lld\n", max(dp[n - 1][0], dp[n - 1][1]));
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
 
int main() {
  int N; cin >>N;
  vector<int>a(3*N);
  rep(i,3*N){
    cin>>a.at(i);
  }
  sort(all(a));
  long long sum=0;
  if(N==1){
    cout<<a.at(1)<<endl;
    return 0;
  }else if(N==2){
    cout<<a.at(2)+a.at(4)<<endl;
    return 0;
  }else{
    rep2(i,N,3*N){
      sum+=a.at(i);
      //cout<<a.at(i)<<endl;
      i++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1408
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        k: usize,
        a: [usize; k],
    }

    let f = |target| {
        let mut ok = 0;
        let mut ng = INF;
        while ng - ok > 1 {
            let m = (ok + ng) / 2;
            let mut x = m;
            for i in 0..k {
                x = x - x % a[i];
            }
            if x > target {
                ng = m;
            } else {
                ok = m;
            }
        }
        ok
    };

    let l = f(1) + 1;
    let h = f(2);
    if l > h {
        println!("-1");
    } else {
        println!("{} {}", l, h);
    }
}


Measured memory_bytes: 3860
program crested_ibis_vs_monster
  implicit none
  integer :: h, n, a(1000) = 0, b(1000) = 0, i, j, dp(0:20000) = 1e9
  read(*,*) h, n
  do i = 1, n
    read(*,*) a(i), b(i)
  end do
  dp(0) = 0
  do j = 1, 20000
    do i = 1, n
      if (a(i) > j) cycle
      dp(j) = min(dp(j),dp(j-a(i))+b(i))
    end do
  end do
  write(*,'(i0)') minval(dp(h:))
end program crested_ibis_vs_monster

Measured memory_bytes: 768
//n == 2のときは無料にできない.
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
#define INF 100000000
using namespace std;

typedef pair<int,int> P;	//cost,node

int n,m;
int s,t,u;		//s→t→uと来たときのみ無料。したがって、node[s]からnode[u]へグラフを1本張ればよい。
struct NODE
{
	vector<int> et;
	vector<int> ec;
	int size;
}node[100];

int Dijkstra()
{
	int done[100] = {0};
	int mcos[100];
	int i;
	priority_queue< P,vector<P>,greater<P> > que;
	P now;

	for( i = 0;i < n;i++ )
		mcos[i] = INF;

	que.push( P(0,0) );
	while( !que.empty() )
	{
		now = que.top();
		que.pop();
		if( done[ now.second ] )
			continue;
		done[ now.second ] = 1;
		mcos[ now.second ] = now.first;

		NODE *no = &node[ now.second ];
		for( i = 0;i < no->size;i++ ){
			int cost = no->ec[i];
			if( mcos[ no->et[i] ] > mcos[ now.second ] + cost ){
				mcos[ no->et[i] ] = mcos[ now.second ] + cost;
				que.push( P( mcos[ no->et[i] ],no->et[i] ) );
			}
		}
	}
	return mcos[ n-1 ];
}

int main(){
	int i,j,k,l;

	for( i = 0;cin >> n >> m;i++ ){
		int ans = INF;
		s = -1;t = -1;u = -1;
		if( n == 0 && m == 0 )
			break;
		for( i = 0;i < n;i++ ){
			node[i].size = 0;
		}
		for( j = 0;j < m;j++ ){
			int a,b,c;
			cin >> a >> b >> c;
			a--;b--;
			node[a].et.push_back(b);
			node[b].et.push_back(a);
			node[a].ec.push_back(c);
			node[b].ec.push_back(c);
			node[a].size++;
			node[b].size++;
		}

		//無料区間が0
		ans = min( ans,Dijkstra() );

		for( j = 0;j < n; j++){
			s = j;
			for( k = 0;k < node[s].size; k++){
				t = node[s].et[k];
				for(l = 0;l < node[t].size ;l++){
					u = node[t].et[l];
					//無料区間が2
					node[s].et.push_back(u);
					node[u].et.push_back(s);
					node[s].ec.push_back(0);
					node[u].ec.push_back(0);
					node[s].size++;
					node[u].size++;
					ans = min( ans,Dijkstra() );
					node[s].et.pop_back();
					node[u].et.pop_back();
					node[s].ec.pop_back();
					node[u].ec.pop_back();
					node[s].size--;
					node[u].size--;
				}
			}
		}
		cout << ans << endl;
		for( i = 0;i < n;i++ ){
			node[i].ec.clear();
			node[i].et.clear();
			node[i].size = 0;
		}
	}
	return 0;
} 

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n,q;
string s;
int acc[maxn];

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

  cin>>n>>q;
  cin>>s;
  for (int i=1; i<n; i++) {
    if (s[i]=='C' && s[i-1]=='A') {
      acc[i+1]++;
    }
  }
  for (int i=1; i<=n; i++) {
    acc[i]+=acc[i-1];
  }
  
  while (q--) {
    int l, r; cin>>l>>r;
    int ans = acc[r]-acc[l-1];
    l--;
    if (l>0 && s[l]=='C' && s[l-1]=='A') ans--;
    cout<<ans<<"\n";
  }
  

  return 0;
}


Measured memory_bytes: 1488
N = int(input())
SP = []

for i in range(1, N + 1):
    s, p = input().split()
    sp = [s, int(p), i]
    SP.append(sp)

SP.sort(key=lambda x: x[1], reverse=True)
SP.sort(key=lambda x: x[0])

for s in SP:
    print(s[2])

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

string N;

int main() {
    cin >> N;

    int idx = N.find('9');

    if (idx == 0 || idx == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);  
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary 
#define MAXN   1000005
int spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}
int main()
{
      fast;ll t;t=1;
      while(t--)
      {
            sieve();
            ll n,i,a,j,g;
            cin>>n;
            ll k=0;
            map<ll,ll>m;
            for(i=0;i<n;i++)
            {
                  cin>>a;
                  if(i==0){g=a;}
                  else{g=__gcd(g,a);}
                  vector<int>v=getFactorization(a);
                  v.pb(1);
                  sort(v.begin(),v.end());
                  for(j=1;j<v.size();j++)
                  {
                        if(v[j]!=v[j-1]){
                              if(m[v[j]]==1){k=1;}
                              m[v[j]]++;
                              //cout<<v[j]<<" ";
                        }
                  }
            }
            if(k==0){cout<<"pairwise coprime\n";}
            else if(g==1){cout<<"setwise coprime\n";}
            else{cout<<"not coprime\n";}
      }
}

Measured memory_bytes: 12456
#include<iostream>
#include<vector>
using namespace std;
const int MOD=1000000007;
int N,M;
vector<bool> issafe;
int main(){
  cin>>N>>M;
  issafe.assign(N+1,true);
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    issafe[a]=false;
  }
  vector<int> dp(N+1,0);
  dp[0]=1;
  if(issafe[1]) dp[1]=1;
  for(int n=2;n<=N;n++){
    if(issafe[n-1]) dp[n]+=dp[n-1];
    if(issafe[n-2]) dp[n]+=dp[n-2];
    dp[n]%=MOD;
  }
  cout<<dp[N]<<endl;
}
                              


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

typedef long long ll;
const int N = 200010;

int n, m, f[N], g[N], st[N], top;
char s[N];
struct Node {int v, id;};
deque<Node>q;

int main() {
	memset(g, -1, sizeof(g));
	memset(f, 0x3f, sizeof(f));
	scanf("%d%d", &n, &m);
	scanf("%s", s);
	f[0] = 0; q.push_back({f[0], 0});
	for(int i = 1; i <= n; ++i) {
		while(!q.empty() && i - q.front().id > m) q.pop_front();
		if(s[i] == '1') continue;
		if(!q.empty()) f[i] = q.front().v + 1, g[i] = q.front().id;
		while(!q.empty() && q.back().v > f[i]) q.pop_back();
		if(f[i] != 0x3f3f3f3f) q.push_back({f[i], i});
 	}
 	if(g[n] == -1) return puts("-1"), 0;
 	int now = n;
 	while(g[now] != -1) {st[++top] = now - g[now], now = g[now];}
 	while(top) printf("%d ", st[top--]);
	puts("");
}

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

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    ll H,W,A,B;
    cin >> H >> W >> A >> B;

    COMinit();

    ll ans = 0;
    for(int i = B;i < W ; i++){
        addM(ans,COM(H-A-1+i,i)*COM(A-1+W-i-1,W-i-1)%MOD);
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long ans = pow(2, 63);
  for(int i = 1; i <= sqrt(N); i++){
    if(N % i == 0){
      ans = min(ans, (N / i) + i - 2);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, K = [int(_) for _ in input().split()]
A = [None] + [int(_) for _ in input().split()]
nowkaimin = [None] * (N + 1)
now = 1
kai = 0
nowkaimin[now] = kai
while True:
    now = A[now]
    kai += 1
    if kai == K:
        print(now)
        exit()
    if nowkaimin[now] is not None:
        break
    nowkaimin[now] = kai
#nowkaimin[now] to kai ga hitosii
#nowkaimin[now] + (kai - nowkaimin[now]) * Q + R
R = (K - nowkaimin[now]) % (kai - nowkaimin[now])
for i, v in enumerate(nowkaimin):
    if v == nowkaimin[now] + R:
        print(i)
        exit()


Measured memory_bytes: 32324
#include <iostream>
#include <tuple>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#define REP(var, num) for(sll var = 0; var < num; var++)
typedef signed long long sll;
typedef unsigned long long ull;
/*
numeric_limits<sll>::max()
*/

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

    double sum = 0;
    REP(i, n) {
        double x;
        string type;
        cin >> x >> type;

        if (type == "JPY")
            sum += x;
        else
            sum += x * 380000.0;
    }

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

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

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

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int d[10][10];

void wf(){
    rep(k,10){
        rep(i,10){
            rep(j,10) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}
int main(){
    int h,w;
    cin>>h>>w;
    rep(i,10) rep(j,10) cin>>d[i][j];
    wf();
    int ans=0;
    rep(i,h) rep(j,w){
        int x;
        cin>>x;
        if(x==-1)continue;
        ans+=d[x][1];
    }
    cout<<ans<<endl;
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    string s;
    cin >> s;
    ll ans=0;
    int len=s.size();
    for(int i=0;i<(1<<(len-1));i++){
        ll total=s[0]-'0';
        for(int j=0;j<len-1;j++){
            if(i&(1<<j)){
                ans+=total;
                total=0;
            }
            total*=10;
            total+=s[j+1]-'0';
        }
        ans+=total;
    }
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	int n;
	int flag = 1;
	scanf("%d", &n);
	char arr[n+1];
	scanf("%s", arr);
	if(n % 2 == 1){
		puts("No");
	} else{
	for(int i = 0; i < n/2; i++){
		if(arr[i] != arr[n/2 + i]){
			flag = 0;
		} 
	}if(flag == 1){
		puts("Yes");
	} else{
		puts("No");
	}
}
	
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n;

int main(){
    cin >> n;
    if(n >= 1000){
        cout << "ABD\n";
    }
    else{
        cout << "ABC\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>

int main()
{
	std::string s, t;

	std::cin >> s;

	std::sort(s.begin(), s.end());

	t = s;

	s.erase(std::unique(s.begin(), s.end()) - s.begin());

	if (s == t) {
		std::cout << "yes" << std::endl;
	}
	else {
		std::cout << "no" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static long n = long.Parse(Console.ReadLine());
static long[] colors = new long[n];
static long[] distances = new long[n];
static Queue<long> que = new Queue<long>();//幅優先探索用のキュー
static long[,] nextMatrixes = new long[n,n];//隣接行列

	static void Main()
	{
		for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      for(long j = 0; j < nums[1]; j++)
      {
        nextMatrixes[i,nums[j+2]-1] = 1;//隣接行列の作成
      }
    }
    
		BFS(0);//幅優先探索
	}

  static void BFS(long start)//幅優先探索
  {
    que.Enqueue(start);
    for(long i = 0; i < n; i++)
    {
      distances[i] = long.MaxValue;
    }
    distances[0] = 0;
    long poppedMemo = 0;
    while(que.Count > 0)
    {
      poppedMemo = que.Peek();
      que.Dequeue();
    
      for(long partnerNum = 0; partnerNum < n; partnerNum++)
      {
        if(nextMatrixes[poppedMemo, partnerNum] == 0) continue;
        if(distances[partnerNum] != long.MaxValue) continue;
        distances[partnerNum] = distances[poppedMemo] + 1;
        que.Enqueue(partnerNum);
      }
    }

    for(long i = 0; i < n; i++)
    {
      Console.WriteLine((i+1) + " "+ ((distances[i] != long.MaxValue) ? distances[i] : -1));
    }
    
  }
  
}


Measured memory_bytes: 16428
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
typedef long double ld;
typedef long long ll;
typedef long long i64;

int main() {
#ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
#endif
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int A = 0, B = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x & 1)
            ++B;
        else
            ++A;
    }

    A += B / 2;
    B %= 2;
    if (B > 0 && A > 0) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }

}



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

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

int main()
{
    int n;
    cin>>n;
    vector<tuple<string,int,int>> all;
     REP(i,n)
   {
       string s;
       int p;
       cin>>s>>p;
       p=-p;
       int ii=i+1;
       all.push_back(tie(s,p,ii));
   }
    sort(all.begin(),all.end());
    REP(i,n)
    {
        cout<<get<2>(all.at(i))<<endl;
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int ans = 0;
  REP(i, n) {
    int l, r; cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 201001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//ll P[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//ll dp[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
ll H[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．


ll MOD = 1000000007;
int digit_length(int num)
{
    int count = 0;
    while (num) {
        num = num / 10;
        ++count;
    }
    return count;
}


ll gcd(ll a, ll b) {
    ll v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}


// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//ll lcm(ll a, ll b) {
//    return a / (gcd(a, b) % MOD) * (b % MOD);
//}

ll lcm(ll a, ll b) {
    return( (a % MOD) *modinv(gcd(a, b), MOD) * (b % MOD)) % MOD;
}
       // Main program
void solve() {
    string S,T,U;
    ll  A,B;
    cin >> S;
    cin >> T;
    cin >> A;
    cin >> B;
    cin >> U;

    if(S==U){
        A--;
    }
    else{
        B--;
    }
    cout << A;
    cout << " ";
    cout << B;
}



int main() {
    solve();
    return 0;
}








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

int main()
{
    string str;
    cin>>str;
    int k; cin>>k;
    int len=str.length();
    string a="";
    string b="";
    string c="";
    string d="";
    string e="";
    for (int i=0; i<len; i++)
    {
        string tmp="";
        for (int j=i; j<len; j++)
        {
            string tt=str.substr(j,1);
            tmp+=tt;
            //cout<<"tmp="<<tmp<<endl;
            //cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
            if (tmp==a || tmp==b || tmp==c || tmp==d ||tmp==e) continue;
            if (tmp<a || a=="")
            {
                e=d; d=c;c=b;b=a; a=tmp;
                //cout<<"1"<<endl;
            }else if (tmp<b || b=="")
            {
                e=d; d=c; c=b;b=tmp;
                //cout<<"2"<<endl;
            }else if (tmp<c || c=="")
            {
                e=d;d=c;c=tmp;
                //cout<<"3"<<endl;
            }else if (tmp<d || d=="")
            {
                e=d;d=tmp;
                //cout<<"4"<<endl;
            }else if (tmp<e || e=="")
            {
                e=tmp;
                //cout<<"5"<<endl;
            }
        }
    }
    //cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
    if (k==1) cout<<a<<endl;
    else if (k==2) cout<<b<<endl;
    else if (k==3) cout<<c<<endl;
    else if (k==4) cout<<d<<endl;
    else if (k==5) cout<<e<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b;
long long gcd(long long a,long long b){
	if (a % b == 0)
		return b;
	else 
		return gcd(b,a % b);
}
int main(){
	cin >> a >> b;
	cout << a * b / gcd(a,b) << endl;
	return 0;
}

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

const int mod=998244353;
#define ll long long
#define ld long double
#define pb push_back
#define Dracarys ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()

ll po(ll x,ll y,ll md=mod){
	ll res=1;
	x%=md;
	
	while(y){
		if (y&1){
			res=(res*x)%md;
		}
		y>>=1;
		x=(x*x)%md;
	}
	return res;
}

void solve(){
	string s;
	cin>>s;
	ll sz=s.size();
	for (ll i=0;i<sz-1;i++){
		if (s[i]=='P' and s[i+1]=='?')
		s[i+1]='D';
	}
	for (ll i=sz-1;i>0;i--){
		if (s[i]=='D' and s[i-1]=='?')
		s[i-1]='P';
	}
	for (ll i=0;i<sz;i++){
		if (s[i]=='?')
		s[i]='D';
	}
	cout<<s<<"\n";
}

int main(){
	
	Dracarys

	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3768
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

ll n, tmp, ans;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    tmp = sqrt(n);
    for (ll i = tmp; i >= 1; i -- ){
        if (n % i == 0){
            ans = i + n / i - 2;
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import copy

N = int(input())
B = [int(i) for i in input().split()]


def dfs(arr, indexes):
    if len(arr) == 0:
        return indexes

    for idx, elm in enumerate(arr):
        if idx+1 < elm:
            return False

    for i in reversed(range(len(arr))):
        if i+1 == arr[i]:
            _indexes = copy.copy(indexes)
            _indexes.append(i)
            res = dfs(arr[:i] + arr[i+1:], _indexes)
            if res:
                return res
    return False


res = dfs(B, [])
if res:
    for i in reversed(res):
        print(i+1)
else:
    print(-1)


Measured memory_bytes: 39664
#include <stdio.h>

int main()
{
  int i, j, n, q, b, e, t;
  fscanf(stdin, "%d", &n);
  int a[n];
  for (i=0; i<n; i++)
    fscanf(stdin, "%d", &a[i]);

  fscanf(stdin, "%d", &q);
  for (i=0; i<q; i++) {
    fscanf(stdin, "%d %d", &b, &e);
    for (j=b; j<=(b+e-1)/2; j++) {
      t = a[j];
      a[j] = a[b+e-j-1];
      a[b+e-j-1] = t;
    }
  }
  for (i=0; i<n-1; i++)
    printf("%d ", a[i]);
  printf("%d\n", a[i]);
  
  return 0;
}



Measured memory_bytes: 2036
import java.util.*;

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

        int cou = 0;
        for(int i=0; i<S.length()/2; i++){
            if(ss[i]!=ss[S.length()-1-i]){
                cou++;
            }
}
            System.out.print(cou);
        }
     }


Measured memory_bytes: 35736
#include <stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

signed main() {
    int n, k;
    cin>>n>>k;
    int a[n];
    long double b[n];
    for(int j= 0;j<n;j++){
        cin>>a[j];
        b[j] = (long double)(a[j]+1)/2;
    }
    long double pref[n+2];
    pref[0] = 0.0;
    for(int i= 1;i<=n;i++){
        pref[i] = pref[i-1] + b[i-1];
    }
    long double ans = 0.0;
    for(int i= 0;i<=n-k;i++){
        ans = max(ans, pref[i+k]-pref[i]);
    }
    cout<<setprecision(9)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main(){
	long long n;
	cin>>n;
	
	long long sum = 0; 
	for(long long i = 1; i<= n; i++){
		if (((i < 3) || ((i%3) != 0)) && (i<5 || ((i%5) != 0))){
			sum +=i;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <tuple>
 
using namespace std;
 
int main(){
    int n, q;
    scanf("%d %d\n", &n, &q);
 
    vector<tuple<int, int, int> > r;
    for(int i = 0; i < n; ++i){
        int s, t, x;
        scanf("%d %d %d\n", &s, &t, &x);
        r.push_back(make_tuple(s - x, 1, x));
        r.push_back(make_tuple(t - x, 0, x));
    }
    for(int i = 0; i < q; ++i){
        int d;
        cin >> d;
        r.push_back(make_tuple(d, 2, i));
    }
    sort(r.begin(), r.end());
 
    vector<int> ans(q, 0);
    set<int> stops;
    for(auto &tpl : r){
        int type = get<1>(tpl);
        if(type == 1){
            stops.insert(get<2>(tpl));
        }else if(type == 0){
            stops.erase(get<2>(tpl));
        }else{
            int min_x = -1;
            if(!stops.empty()){
                min_x = *stops.begin();
            }
            ans.at(get<2>(tpl)) = min_x;
        }
    }
 
    for(int x : ans){
        cout << x << endl;
    }
 
    return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    char k = s[0];
    int ans = 1;
    for(int i = 1; i < n; i++){
        if (k != s[i]){
            ans++;
            k = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3288
package main

import (
	"fmt"
)

func main() {
	for i := 0; ; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		if x+y == 0 {
			break
		}
		if x <= y {
			fmt.Println(x, y)
		} else {
			fmt.Println(y, x)
		}
	}
}



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

int main()
{
  char S[11];
  char T[11];

  scanf("%s", S);
  scanf("%s", T);

  char copy[11] = {'\0'};
  strncpy(copy, T, strlen(T) - 1);

  if (strcmp(copy, S) == 0)
    printf("Yes");
  else
    printf("No");

  return 0;
}


Measured memory_bytes: 1736
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let mut v = Vec::new();
    let mut sum = 0;
    for z in 0..n {
        let buf: usize;
        input!(buf);
        v.push(buf);
        sum += buf;
    }

    v.sort();
    if sum % 10 != 0 {
        p(sum);
        return;
    }
    for z in v {
        if (sum - z) % 10 != 0 {
            p(sum - z);
            return;
        }
    }
    println!("0");
}

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

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, A, B;
    cin >> N >> A >> B;

    ll sum = 0;
    for(ll i = 1; i <= N; i++){
        string s = to_string(i);
        ll t_sum = 0;
        for(ll j = 0; j < s.length(); j++){
            t_sum += s[j] - '0';
        }
        if(t_sum >= A && t_sum <= B) sum += i;
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  switch(N) {
  case 3:
  case 5:
  case 7:
    cout << "YES" << endl;
    break;
  default:
    cout << "NO" << endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s = 0

for i in range(n):
    for j in range(i,i+2):
        c = b[i] - a[j]
        if c <= 0:
            a[j] -= b[i]
            s += b[i]
            break
        else:
            b[i] -= a[j]
            s += a[j]
            a[j] = 0

print(s)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> check(N, true);
    vector<int> H(N);
    cin >> H;
    vector<set<int>> graph(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        graph[A].insert(B);
        graph[B].insert(A);
    }
    for (int i = 0; i < N; i++) {
        auto itr = graph[i].begin();
        int my_height = H[i];
        while (itr != graph[i].end()) {
            if (my_height > H[*itr]) {
                check[*itr] = false;
            } else if (my_height == H[*itr]) {
                check[*itr] = false;
                check[i] = false;
            } else {
                check[i] = false;
            }
            graph[*itr].erase(i);
            itr = graph[i].erase(itr);
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) if (check[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 17780
#include <stdio.h>
int main(void) {
	int i, n, j, v, k, A[10000];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	for (k = 0; k < n - 1; k++) {
		printf("%d ", A[k]);
	}
	printf("%d\n", A[n - 1]);
	for (i = 1; i <= n - 1; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (k = 0; k < n - 1; k++) {
			printf("%d ", A[k]);
		}
		printf("%d\n", A[n - 1]);
	}
	return 0;
}

Measured memory_bytes: 608
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

fn main() {
	let text = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};

	let mut iter = text.split_whitespace();
	let num: u64 = iter.next().unwrap().parse().unwrap();
	let goal: u64 = iter.next().unwrap().parse().unwrap();

	let mut p_s: f64 = 0.0;

	for current_score in 1..(num + 1) {
		let mut current_score = current_score as u64;
		let mut p: f64 = 1.0;

		while current_score < goal {
			p /= 2.0;
			current_score *= 2;
		}

		p_s += p;
	}

	println!("{}", p_s / (num as f64));
}


Measured memory_bytes: 4352
my $N =<>;

for(my $i=0;$i<$N;$i++ ){
    my $s =<>;chomp $s;
    my @dat = split(/ /,$s);
    if($dat[0] == $dat[1]){
        $count++;
        if($count >=3){
            print "Yes";
            exit;
        }
    }else{
        $count =0;
    }
    
}
print "No";

Measured memory_bytes: 4784
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007

temp2 = 0
temp1 = 0

cand = [0] * (N+1)
cand[0] = 3
ret = 1
for i in range(N):
    ret *= cand[A[i]]
    cand[A[i]+1] += 1
    cand[A[i]] -= 1

print(ret % MOD)


Measured memory_bytes: 13964
/*  */
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) v.begin(),v.end()

int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> v;
  v.reserve(n);
  rep(i,n){
    int a;
    cin>>a;
    auto itr=lower_bound(all(v), a);
    if(itr==v.end())v.push_back(a);
    else *itr=a;
  }
  cout<<v.size()<<endl;
  return 0;
}

Measured memory_bytes: 1524
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m;
char s[120][120];
inline bool cheh(int x){
	fo(i,1,m) if (s[x][i]=='#') return 0;
	return 1;
}
inline void delh(int x){
	fo(i,x,n-1) fo(j,1,m) s[i][j]=s[i+1][j];
	n--;
}
inline bool chel(int x){
	fo(i,1,n) if (s[i][x]=='#') return 0;
	return 1;
}
inline void dell(int x){
	fo(j,x,m-1) fo(i,1,n) s[i][j]=s[i][j+1];
	m--;
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%s",s[i]+1);
	while (1){
		bool ok=0;
		fo(i,1,n) if (cheh(i)){
			delh(i);
			ok=1;//continue;//null
			//break;//
		}
		fo(i,1,m) if (chel(i)){
			dell(i);
			ok=1;//continue;//null
			//break;//
		}
		if (!ok) break;
	}
	//printf("%d %d\n",n,m);
	fo(i,1,n){
		fo(j,1,m) putchar(s[i][j]);
		putchar('\n');
	}
	return 0;
} 

Measured memory_bytes: 888
import math

n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

def search(x, k, A, F):
    for a, f in zip(A, F):
        time = a * f
        if time <= x:
            continue
        else:
            dif = time - x
            training = int(math.ceil(dif/f))
            k -= training

        if k < 0:
            return False
    return True


A.sort()
F.sort(reverse=True)
r= max([a*f for a, f in zip(A, F)])
l = 0
while l < r:
    candidate = (r+l)//2
    if search(candidate, k, A, F):
        r = candidate
    else:
        l = candidate + 1

print(r)

Measured memory_bytes: 119884
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
typedef long long LL;
const int maxn = 1e5 + 5;
const LL mod = 1e9 + 7;
const int inf = 50000;

int n, m, val[maxn], d[maxn], cut, x, y, siz, first[maxn], cnt, ans, res, par[maxn];
int f[maxn], tot, a[maxn];
bool vis[maxn];
struct Edge {
	int to, next;
} e[maxn<<1];

void add(int u, int v) {
	e[cnt] = (Edge) {v, first[u]};
	first[u] = cnt++;
}

void Dfs1(int u, int fa) {
	par[u] = fa;
	d[u] = d[fa] + 1;
	val[u] = (d[u]&1) ? 1:-1;
	vis[u] = 1;
	for(int i = first[u]; i != -1; i = e[i].next) {
		int v = e[i].to;
		if(v == fa) continue;
		if(vis[v]) {
			siz = d[u] + d[v] - 1;
			cut = i;
			x = u, y = v;
			continue;
		}
		Dfs1(v, u);
		val[u] += val[v];
	}
}

void Dfs2(int u, int fa) {
	for(int i = first[u]; i != -1; i = e[i].next) {
		int v = e[i].to;
		if(v == fa || i == cut || (i^1) == cut) continue;
		Dfs2(v, u);
		f[u] += f[v];
	}
}

signed main() {
	cin>>n>>m;
	memset(first, -1, sizeof(first));
	rep(i, 1, m) {
		int u, v;
		cin>>u>>v;
		add(u, v); 
		add(v, u);
	}
	Dfs1(1, 0);
	if(m == n - 1) {
		if(val[1]) cout<<-1<<endl;
		else {
			rep(i, 1, n)
			    ans += abs(val[i]);
			cout<<ans<<endl;
		}
	}
	if(m == n) {
		if(siz&1) {
			if(val[1]%2 != 0) cout<<-1<<endl;
			else {
				res = -val[1]/2;
				while(x) {
					val[x] += res;
					x = par[x];
				}
				while(y) {
					val[y] += res;
					y = par[y];
				}
				rep(i, 1, n)
			    	ans += abs(val[i]);
				cout<<ans + abs(res)<<endl;
			}
		}
		else {
			if(val[1]) cout<<-1<<endl;
			else {
				a[++tot] = 0;
				f[x] = 1, f[y] = -1;
				Dfs2(1, 0);
				rep(i, 1, n) {
				    if(!f[i]) ans += abs(val[i]);
				    else a[++tot] = -f[i]*val[i];
				}
				sort(a + 1, a + tot + 1);
				int vd = a[(tot + 1)/2];
				rep(i, 1, tot)
				    ans += abs(vd - a[i]);
				cout<<ans<<endl;
			}
		}
	}
}

Measured memory_bytes: 17748
import java.util.*;
public class Main {

	public static void main(String[] args) {
		String S = new Scanner(System.in).next();
		int N = S.length();
		int ans = 0;
		int[][] dp = new int[2][2019];
		for(int i = 0; i < N; i++) {
			int s = Character.getNumericValue(S.charAt(i));
			dp[1][s] = 1;
			for(int j = 0; j < 2019; j++)
				dp[1][(j*10+s)%2019] += dp[0][j];
			ans += dp[1][0];
			dp[0] = dp[1].clone();
			Arrays.fill(dp[1], 0);
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 46864
#include<bits/stdc++.h>
#define mod 1000000009
#define int long long 
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
}
signed main() {
    garou;
int x,n;
cin>>x>>n;
if(n==0){
	cout<<x;
	return 0;
}
map<int,int> mp;
int mn=INT_MAX,l=INT_MAX;
for(int i=0;i<n;i++){
	int a;
	cin>>a;
   mp[a]++;
}
for(int j=x;j<=10000;j++){
	if(mp.find(j)==mp.end()){
		int a=abs(x-j);
		if(mn>a){
			mn=a;
            l=j;
		}
		else if(mn==a&&l>j)
		l=j;
	}
}
for(int j=x;j>=-100000;j--){
	if(mp.find(j)==mp.end()){
		int a=abs(x-j);
		if(mn>a){
			mn=a;
            l=j;
		}
		else if(mn==a&&l>j)
		l=j;
	}
}
cout<<l;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void warshall_floyd(Graph &graph) {
    int V = graph.size();
    for (int k = 0; k < V; ++k) {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
}

void Main() {
    Graph graph(10, vector<ll>(10, INF));
    ll H, W;
    cin >> H >> W;
    rep(i, 10) {
        rep(j, 10) {
            ll c;
            cin >> c;
            graph[i][j] = c;
        }
    }
    warshall_floyd(graph);
    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            ll a;
            cin >> a;
            if (a != -1) {
                ans += graph[a][1];
            }
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    long long ans1=a+b;
    long long ans2=c+b;
    long long ans3=a+c;
    long long ans=min(min(ans1,ans2),ans3);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
pair<llong, llong> Reduction(pair<llong, llong> A) {
	llong tmp = gcd(A.first, A.second);
	auto p = make_pair(A.first / tmp, A.second / tmp);
	return p;
}
//ここまで共通
int N;
vector<llong>A;
const llong MOD = 1000000007;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		llong a;
		cin >> a;
		A.push_back(a);
	}

	llong ANS = 0;
	llong tmp = 0;
	for (int i = 0; i < N; i++) {
		ANS += tmp * A[i];
		ANS %= MOD;
		tmp += A[i];
		tmp %= MOD;
	}

	ANS %= MOD;

	cout << ANS << endl;
}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}

int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
int r;
signed main(){
	cin>>r;
	cout<<r*r<<endl;
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<iomanip>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int N;
    int *v;
    int i;
    double max;
    double div;
    cin >> N;
    
    v = new int[N];
    for(i=0;i<N;i++){
        cin >> v[i];
    }
    sort(v,v+N,std::greater<int>());
    div = 1;
    for(i=0;i<N-1;i++){
        div *= 2;
        max += v[i] / div;   
    }
    max += v[i] / div;

    cout << setprecision(10) << max << endl;
    return 0;
}


Measured memory_bytes: 256