akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int F[301][301];//从i->j费用
struct node {
	int to,next,v;
} a[1000001];
int head[100001],cnt,inf;
void add(int x,int y,int c) {
	a[++cnt].next=head[x];
	a[cnt].to=y;
	a[cnt].v=c;
	head[x]=cnt;
}
queue<int> q;
int dis[100001],f[100001],vis[100001],x,y,z,n,m,L;
void spfa(int s) {
	q.push(s);
	memset(dis,127/3,sizeof(dis));
	memset(f,0,sizeof(f));
	memset(vis,0,sizeof(vis));
	inf=dis[s],dis[s]=0,vis[s]=L,f[s]=0;
	while(!q.empty()) {
		int now=q.front();
		f[now]=0,q.pop();
		for(int i=head[now]; i; i=a[i].next) {
			int v=a[i].to;
			if(dis[v]>dis[now]+(vis[now]<a[i].v)) {
				dis[v]=dis[now]+(vis[now]<a[i].v);
				if(vis[now]<a[i].v)
					vis[v]=L-a[i].v;
				else vis[v]=vis[now]-a[i].v;
				if(!f[v]) q.push(v),f[v]=1;
			} else if(dis[v]==dis[now]+(vis[now]<a[i].v)) {
				if(L-a[i].v>vis[v]&&vis[now]<a[i].v) {
					vis[v]=L-a[i].v;
					if(!f[v]) q.push(v),f[v]=1;
				}
				if(vis[now]>a[i].v&&vis[now]-a[i].v>vis[v]) {
					vis[v]=vis[now]-a[i].v;
					if(!f[v]) q.push(v),f[v]=1;
				}
			}
		}
	}
}
main() {
	n=read(),m=read(),L=read();
	for(int i=1; i<=m; i++) {
		x=read(),y=read(),z=read();
		if(z<=L)
			add(x,y,z),add(y,x,z);
	}
	for(int i=1; i<=n; i++) {
		spfa(i);
		for(int j=1; j<=n; j++)
			F[i][j]=dis[j];
	}
	int q=read();
	while(q--) {
		int x=read(),y=read();
		if(F[x][y]==inf) puts("-1");
		else cout<<F[x][y]<<endl;
	}
}


Measured memory_bytes: 9216
#include <iostream>
#include <cmath>
#include <iomanip>

#define PI 3.14159265

using namespace std;

int main() {
    long double a, b, x;
    cin >> a >> b >> x;
    if (2 * x <= (a * a * b)) {
        cout << setprecision(12) << 90.0 - (atan(2 * x / (a * b * b)) * 180 / PI);
    } else {
        cout << setprecision(12) << atan(2 * (a * a * b - x) / (a * a * a)) * 180 / PI;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N,M,S[2000],T[2000];
long mod=1e9+7,dp[2020][2020],sum[2020][2020];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>S[i];
	for(int i=0;i<M;i++)cin>>T[i];
	dp[0][0]=1;
	for(int j=0;j<=M;j++)sum[0][j]=1;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<M;j++)
		{
			if(S[i]==T[j])
			{
				dp[i+1][j+1]=sum[i][j];
			}
		}
		long now=0;
		for(int j=0;j<=M;j++)
		{
			(now+=dp[i+1][j])%=mod;
			sum[i+1][j]=(sum[i][j]+now)%mod;
		}
	}
	cout<<sum[N][M]<<endl;
}


Measured memory_bytes: 63744
// https://atcoder.jp/contests/abc121/tasks/abc121_c

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h1, w1, h2, w2;
    cin >> h1 >> w1 >> h2 >> w2;
    cout << (h1 - h2) * (w1 - w2) << endl;

    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define rREP(i, n) for(int i = n-1; i >= 0; --i)

using namespace std;

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

    int a, z;
    REP(i, s.size())
        if (s[i] == 'A'){
            a = i;
            break;
        }     

    rREP(i, s.size())
        if (s[i] == 'Z'){
            z = i;
            break;
        }   
    cout << z - a + 1 << endl;
}

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


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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

int main()
{
	speedup_IO;
	ll n,m;
	cin>>n>>m;

	if(n==m)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int row[500000],col[500000];
int main()
{
	int h,w,m;
	cin>>h>>w>>m;
	int maxr = 0, maxc = 0;
	map<pair<int,int>, int> bomb;
	for (int i = 0; i < m; ++i)
	{
		int x,y;
		cin>>x>>y;
		bomb[make_pair(x,y)] = 1;

		row[x]++;
		col[y]++;
		maxr = max(maxr,row[x]);
		maxc = max(maxc,col[y]);
	}
	std::vector<int> r,c;
	for (int i = 0; i < 300001; ++i)
	{
		if(row[i]==maxr)
			r.push_back(i);
	}
	for (int i = 0; i < 300001; ++i)
	{
		if(col[i]==maxc)
			c.push_back(i);
	}
	for (int i = 0; i < r.size(); ++i)
	{
		for(int j = 0; j < c.size();j++)
		{
			int a = r[i];
			int b = c[j];
			if(bomb.find(make_pair(a,b)) == bomb.end())
			{
				printf("%d\n",maxc+maxr);
				return 0;
			}
		}
	}
	printf("%d\n",maxc+maxr-1 );


	
	return 0;
}

Measured memory_bytes: 28424
#include<iostream>
using namespace std;
int main(){
	while (true){
		int n, A[10000] = {}, B[10000] = {}, tenA = 0, tenB = 0;
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			cin >> A[i] >> B[i];
			if (A[i] > B[i]){
				tenA += A[i] + B[i];
			}
			if (A[i] == B[i]){
				tenA += A[i];
				tenB += B[i];
			}
			if (A[i] < B[i]){
				tenB += A[i] + B[i];
			}
		}
		cout << tenA << ' ' << tenB << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include<iostream>
using namespace std;
int main(){
	int m, n, a[100][100], b[100],out;
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n; i++){
		out = 0;
		for (int j = 0; j < m; j++){
			out += a[i][j] * b[j];
		}
		cout << out << endl;
	}
}


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

namespace ConsoleApp2
{
    public class Program
    {

        static long D = (long)Math.Pow(10, 9) + 7;


        public static void Main(string[] args)
        {
            int[] NKQ = Read(Console.ReadLine());

            int N = NKQ[0];
            int K = NKQ[1];
            int Q = NKQ[2];

            int[] Ps = new int[N+1];

            for (int i = 0; i < Q; i++)
            {
                int answer = int.Parse(Console.ReadLine());
                Ps[answer]++;
            }

            for (int i = 1; i < N+1; i++)
            {
                if (Ps[i] + K-Q > 0) Console.WriteLine("Yes");
                else Console.WriteLine("No");
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        private static int[] Read(string input)
        {
            string[] aaa = input.Split(' ');
            int num = aaa.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(aaa[i]);
            }
            
            return ints;
        }


    }


}


Measured memory_bytes: 17600
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	l=int(input())
	print((l/3)**3)




if __name__ == "__main__":
	main()

Measured memory_bytes: 38256
#include<iostream>

using namespace std;

int main(){
  int a,b;
  string op;
  while(cin >> a >> op >> b){
    if(op == "?")
      break;
    else if(op=="+")
      cout << a+b << endl;
    else if(op=="-")
      cout << a-b << endl;
    else if(op=="*")
      cout << a*b << endl;
    else if(op=="/")
      cout << a/b << endl;
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if(d > 0 && d * d > 4 * a * b)
        cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


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

int n, a[51], maxi = 1;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (abs(a[i]) > abs(a[maxi])) maxi = i;
    }
    // Unify all signs of integers
    cout << (n * 2 - 1) << endl;
    for (int i = 1; i <= n; i++) {
        cout << maxi << " " << i << endl;
        a[i] += a[maxi];
    }
    // a[i] <= a[i+1]
    if (a[maxi] > 0) {
        for (int i = 1; i < n; i++) {
            cout << i << " " << i+1 << endl;
            a[i+1] += a[i];
        }
    } else {
        for (int i = n; i > 1; i--) {
            cout << i << " " << i-1 << endl;
            a[i-1] += a[i];
        }
    }

    return 0;
}

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

int main(){
  long N;
  cin >> N;
  vector<long> A(N);
  map<long, long> dict;
  for(long i=0; i<N; i++){
    cin >> A[i];
    if(dict.count(A[i])){dict.at(A[i])++;}
    if(!dict.count(A[i])){dict.emplace(A[i], 1);}
  }
  long allSum=0;
  for(auto a:dict){
    long x = a.second;
    long sum = x*(x-1)/2;
    allSum += sum;
  }
  for(long i=0; i<N; i++){
    cout << allSum - dict.at(A[i])+1<<endl;;
  }
  return 0;
}

Measured memory_bytes: 11008
import re
import sys
from fractions import gcd
from functools import reduce
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = np.asarray(il())
    B = A[A < 0]
    if len(B) % 2 == 0:
        return sum(np.abs(A))
    sorted_A = sorted(np.abs(A))
    return sum(sorted_A[1:]) - sorted_A[0]


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


Measured memory_bytes: 26060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(32005); // TODO : change value as per problem
const ll MOD = 1e9+7;
bool dp[N][N];
bool dp2[N][N];
ll get(ll x){
	return x + 16000ll + 1ll;
}

void solve(){
	string s;
	cin >> s;
	int x,y;
	cin >> x >> y;
	int idx=sz(s);
	int wow = 0;
	for(int i =0;i < sz(s);i++){
		if(s[i] == 'T') {idx = i;break;}
		wow++;
	}
	vll a,b;
	bool ok = false;
	ll c = 0;
	for(int i = idx+1;i<sz(s);i++){
		// cout << s[i] << " " << ok<< endl;
		if(s[i] == 'T'){
			if(ok) a.pb(c);
			else b.pb(c);
			ok ^= true;
			c = 0;
		}
		else{
			c++;
		}
	}
	if(c != 0){
			if(ok) a.pb(c);
			else b.pb(c);
	}
	ll n = sz(a);
	ll m = sz(b);
	
	dp[0][get(wow)] = true;
	
	int sum = 8000;
	
	for(int i =1;i<=n;i++){
		for(int j = -sum;j<=sum;j++){
			dp[i][get(j)] |= dp[i-1][get(j+a[i-1])];
			 dp[i][get(j)] |= dp[i-1][get(j-a[i-1])];
		}
	}
	dp2[0][get(0)] = true;
	for(int i =1;i<=m;i++){
		for(int j = -sum;j<=sum;j++){
			assert(get(j + b[i-1]) < N); 
			assert(get(j - b[i-1]) >= 0); 
			if(get(j-b[i-1]) <0 ){
				cout << j << endl;
			}
			dp2[i][get(j)] |= dp2[i-1][get(j+b[i-1])];
			dp2[i][get(j)] |= dp2[i-1][get(j-b[i-1])];
		}
	}

	if(dp[n][get(x)] && dp2[m][get(y)])
		cout << "Yes\n";
	else 
		cout << "No\n";
}

signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 159436
/*1_2_B*/
#include<stdio.h>
int main(void){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a<b){
      if(b<c){
         printf("Yes\n");
         return 0;
      }
   }
   printf("No\n");
   return 0;
}

Measured memory_bytes: 1748
N=int(input())
hp_list = list(map(int,input().split()))

from functools import reduce
from fractions import gcd

max=0
min=10**9+1
for i in range(N):#O(10**5)
    if max < hp_list[i]:
        max = hp_list[i]
        max_index = i
    if min > hp_list[i]:
        min = hp_list[i]
        min_index = i
    tmp_list=[max,min]
    hp_list[max_index]=reduce(gcd,tmp_list)
#print(max,min)
#print(max_index,min_index)
hp_list = sorted(hp_list, reverse=False)
print(hp_list[0])

Measured memory_bytes: 89748
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int a[] = new int[n];

		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		int sum = 0;
		for(int i = 0; i < k; i++){
			sum += a[i];
		}

		System.out.println(sum);
	}

}


Measured memory_bytes: 30448
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

string S;

int main() {
  cin >> S;
  char color = S[0];
  int cnt = 1;
  rep(i, 1, S.size()) {
    if (S[i] != color) {
      color = S[i];
      ++cnt;
    }
  }

  cout << cnt - 1 << endl;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = (b > d) ? d : b;
    ans -= (a > c) ? a : c;
    if(ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int n, m;
vvi g;
vector<bool> reached;
vi previous;

deque<int> dfs(int s) {
  deque<int> stk;
  stk.push_back(s);
  reached.assign(n, false);
  reached[s] = true;
  previous.assign(n, -1);

  while (!stk.empty()) {
    int u = stk.back();
    for (auto v : g[u]) {
      if (reached[v]) { continue; }
      reached[v] = true;
      previous[v] = u;
      stk.push_back(v);
    }
    if (stk.back() == u) {
      deque<int> ret;
      for (int i = u; i != -1; i = previous[i]) {
        ret.push_front(i);
      }
      return ret;
    }
  }
}

deque<int> dfs(deque<int> &di) {
  reached.assign(n, false);
  int n_ = di.size();
  rep (i, n_) {
    reached[di[i]] = true;
  }
  previous.assign(n, -1);
  FOR (i, 1, n_) {
    previous[di[i]] = di[i-1];
  }
  deque<int> stk;
  stk.push_back(di.back());

  while (!stk.empty()) {
    int u = stk.back();
    for (auto v : g[u]) {
      if (reached[v]) { continue; }
      reached[v] = true;
      previous[v] = u;
      stk.push_back(v);
    }
    if (stk.back() == u) {
      deque<int> ret;
      for (int i = u; i != di.back(); i = previous[i]) {
        ret.push_front(i);
      }
      ret.insert(begin(ret), all(di));
      return ret;
    }
  }
}

bool check_tail(deque<int> &di) {
  reached.assign(n, false);
  int n_ = di.size();
  rep (i, n_) {
    reached[di[i]] = true;
  }
  int goal = di.back();
  for (int u : g[goal]) {
    if (!reached[u]) {
      return false;
    }
  }
  return true;
}

void print_path(deque<int> &path) {
  int n_ = path.size();
  printf("%d\n", n_);
  rep (i, n_) {
    printf("%d ", path[i] + 1);
  }
  printf("\n");
  exit(0);
}

int main() {
  scanf("%d%d", &n, &m);
  g.resize(n);
  rep (i, m) {
    int a, b;
    scanf("%d%d", &a, &b);
    a -= 1; b -= 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  auto path = dfs(0);
  while (!check_tail(path)) {
    path = dfs(path);
  }
  reverse(all(path));
  while (!check_tail(path)) {
    path = dfs(path);
  }
  print_path(path);

  return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

bool used[100005];

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    deque<int> deq;
    deq.push_back(0);
    used[0] = true;
    bool update = true;
    int cur = 0;
    while(update){
        update = false;
        for(int v : graph[cur]){
            if(used[v]) continue;
            deq.push_back(v);
            used[v] = true;
            cur = v;
            update = true;
            break;
        }
    }

    cur = 0;
    update = true;
    while(update){
        update = false;
        for(int v : graph[cur]){
            if(used[v]) continue;
            deq.push_front(v);
            used[v] = true;
            cur = v;
            update = true;
            break;
        }
    }

    cout << deq.size() << '\n';
    while(!deq.empty()){
        cout << deq.front() + 1;
        deq.pop_front();
        cout << ((deq.size()) ? ' ' : '\n');
    }
}

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

int main() {
  // 入力される(c11,c12,c13)をs1, (c21,c22,c23)をs2として入力
  string s1, s2;
  cin >> s1 >> s2;

  // s2をreverse関数を用いて反転させる
  reverse(s2.begin(), s2.end());

  //「s1」と「反転させたs2」が同じなら 'YES' と表示
  if(s1 == s2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    long long x, y=100, cnt=0;
    cin>>x;
 
    while(true){
        if(x<=y){
            cout<<cnt<<endl;
            return 0;
        }
        cnt++;
        y=y+y/100;
    }
}

Measured memory_bytes: 3672
import java.util.Scanner;
//https://atcoder.jp/contests/abc162/tasks/abc162_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		// TODO 自動生成されたメソッド・スタブ
				 Scanner sc = new Scanner(System.in);
				 int name=sc.nextInt();
				 boolean k=false;
				 for(int i=1;i<=3;i++){
					 if(name%10==7)
						 k=true;
					 name=name/10;
				 }
				 if(k){
					 System.out.print("Yes");
				 }else{
					 System.out.print("No");
				 }

	}

}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P.at(i);
  }
  sort(P.begin(), P.end());
  long long ans = 0;
  for (int i = 0; i < K; i++){
    ans += P.at(i);
  }
  cout << ans << endl;
}

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


int main(void)
{
    //入力
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    int a[N];
    int tmp[300];
    for( int i = 0; i < N; i++){
        cin >> a[i];
    }


    int k = 1;
    for( int i = 0; i < H; i++){
        for( int j = 0; j < W; j++){
            tmp[j] = k;
            a[k-1]--;
            if( a[k-1] == 0){
                k++;
            }
        }

        if( i % 2 == 1){
            for( int j = 0; j < W/2; j++){
                tmp[j] += tmp[W-1-j];
                tmp[W-1-j] = tmp[j] - tmp[W-1-j];
                tmp[j] -= tmp[W-1-j];
            } 
        }

        for( int j = 0; j < W; j++){
            printf("%d ", tmp[j]);
        }
        puts("");
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 String str = sc.next();
		 if(str.charAt(str.length()-1) == 's'){
			 System.out.println(str + "es");
		 }else {
			 System.out.println(str + "s");
		 }
		

	}

}


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

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

  cout << s[0] << s.size() - 2 << s[s.size()-1] << endl;
  return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
int main(void){
	int n, y,a,b,c;
	scanf("%d %d",&n,&y);
	y/=1000;
	a=max((y-n-4*min(y/5,n))/9,0);
	c=min((y-n)/9,min(y/10,n));
	for(;a<=c;a++){
		b=y-n-9*a;
		if(b%4==0){
			if(0<=n-a-b/4){
				printf("%d %d %d",a,b/4,n-a-b/4);
				return 0;
			}
		}
	}
	printf("-1 -1 -1");
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}



Measured memory_bytes: 256
# まず底をみつけてそのあと山で売るを繰り返す
n = int(input())
arr = list(map(int, input().split()))
arr2 = []
cur = arr[0] if arr[0] < arr[1] else 10**10
f = 1
for i in range(1, n):
    if f == 1:
        # print("底値を求める")
        if cur < arr[i]:
            arr2.append(cur)
            f *= -1
    else:
        # print("天井を求める")
        if cur > arr[i]:
            arr2.append(cur)
            f *= -1
    cur = arr[i]
if f == -1:
    arr2.append(cur)
ans = 1000
stock = 0
for i, a in enumerate(arr2):
    if i % 2 == 0:
        # 買いまくる
        stock = ans // a
        ans %= a
    else:
        # うりまくる
        ans += stock * a
        stock = 0
print(ans)

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    while(cin>>n){
       int cnt=0;
       for(int i=1,j=n-1;i<j;i++,j--){
        cnt++;
       }
       cout<<cnt<<endl;
    }
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        out.println(2.0*Math.PI*Double.parseDouble(f.readLine()));

        out.close();
    }
}


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

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if	  ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
	
	int i;
	long long key = getKey(str);

	for( i=0; i<M; i++) {
		if(H[(h1(key)+i*h2(key))%M][0] == '\0') {
			return 0;
		}
		if(strcmp(H[(h1(key)+i*h2(key))%M], str) == 0) {
			return 1;
		}
	}
	return 0;
		
}

int insert(char str[]){

	int i=0;
	long long key = getKey(str);

    while(1) {
    	
    	if(H[(h1(key)+i*h2(key))%M][0] == '\0') {
    		strcpy(H[(h1(key)+i*h2(key))%M], str);
    		break;
    	}
    	i++;
    }
    
    return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    
    /* ???????????\?????????????????? */
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>

uint64_t add(uint64_t a, uint64_t b) {
	if (a > UINT64_MAX - b) {
		printf("overflow: %" PRIu64 " + %" PRIu64 "\n", a, b);
		exit(2);
	}
	return a + b;
}

uint64_t mul(uint64_t a, uint64_t b) {
	if (b > 0 && a > UINT64_MAX / b) {
		printf("overflow: %" PRIu64 " * %" PRIu64 "\n", a, b);
		exit(2);
	}
	return a * b;
}

int N;
uint64_t A[256];

int main(void) {
	uint64_t tokisyuniti = 1000; /* ときは金なり */
	uint64_t kabu = 0;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu64, &A[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (i + 1 < N && A[i] < A[i + 1]) {
			uint64_t asumisu = tokisyuniti / A[i];
			kabu = add(kabu, asumisu);
			tokisyuniti -= mul(A[i], asumisu);
		}
		if (i + 1 >= N || A[i] > A[i + 1]) {
			tokisyuniti = add(tokisyuniti, mul(A[i], kabu));
			kabu = 0;
		}
	}
	printf("%" PRIu64 "\n", tokisyuniti);
	return 0;
}

/*

極小で買って極大で売る

*/


Measured memory_bytes: 1732
#include <bits/stdc++.h>
//<(") 
#define ll long long
#define double long double
using namespace std;

const ll siz = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll MAXX = 1e17;
const ll base = 31;

ll n, m, k;
ll par[siz];
ll big[siz];
ll hate[siz];
set<ll> graph[siz];

void setup() {
	for (ll i = 1; i <= n; i++) {
		par[i] = i;
		big[i] = 1;
	}
}

ll findPar(ll node) {
	if (par[node] == node) {
		return node;
	}
	return par[node] = findPar(par[node]);
}

void join(ll a, ll b) {
	ll x = findPar(a), y = findPar(b);
	if (x == y) {
		return;
	}
	par[x] = y;
	big[y] += big[x];
	big[x] = 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("INP.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);
	cin >> n >> m >> k;
	setup();
	for (ll i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		graph[a].insert(b);
		graph[b].insert(a);
		join(a, b);
	}
	for (ll i = 0; i < k; i++) {
		ll a, b;
		cin >> a >> b;
		if (graph[a].count(b) == 0 && (findPar(a) == findPar(b))) {
			hate[a]++; hate[b]++;
		}
	}
	for (ll i = 1; i <= n; i++) {
		//cerr << big[findPar(i)] << ' ' << hate[i] << ' ' << graph[i].size() << '\n';
		cout << big[findPar(i)] - hate[i] - graph[i].size() - 1 << ' ';
	}
    return 0;
}

Measured memory_bytes: 17920
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <iostream>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;

void fail(){
  cout<<"No"<<endl;
  exit(0);
}

void reg(map<char,char>&a,char b,char c){
  if(a.count(b)){
    if(a[b]!=c)fail();
  }else a[b]=c;
}

int main(void){
  string s,t;
  cin>>s>>t;
  map<char,char>tbl,inv;
  int n=s.size();
  REP(i,0,n){
    reg(tbl,s[i],t[i]);
    reg(inv,t[i],s[i]);
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
main(){
  int n,x,ans=0;
  cin>>n>>x;
  vector<P>v,v1;
  r(i,n){
    int s,t;
    cin>>s>>t;
    v.push_back(P(s,-t));
    v1.push_back(P(t,s));
  }
  sort(v.begin(),v.end(),greater<P>());
  r(i,n)v[i].second*=-1;
  r(i,n){
    if(v1[i].second==v[0].first&&v1[i].first==v[0].second){
      v1.erase(v1.begin()+i);
      break;
    }
  }
  sort(v1.begin(),v1.end(),greater<P>());
  int X=v[0].first;
  int sum=0;
  r(i,n-1){
    if(X>v1[i].first)break;
    x-=v1[i].first;
    ans++;
    if(x<=0){
      cout<<ans<<endl;
      return 0;
    }
  }
  while(1){
    if(x-v[0].second<=0)x=0;
    else x-=v[0].first;
    ans++;
    if(x<=0){
      cout<<ans<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3564
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;

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

    int res = 1;
    rep(i, N - 1)if (s[i] != s[i + 1])res++;
    cout << res << endl;
    return 0;
}


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

int q1,q2,b,c1,c2,ans1,ans2;

bool solve(){
	if(!q2)
		return false;
	ans1 = q2;
	ans2 = 0;
	while(ans1*c1 + ans2*c2 <= b)
		ans2++;
	if(ans2)
		ans2--;
	if(ans1 + ans2 >= q1 && ans1*c1 + ans2*c2 <= b)
		return true;
	while(true){
		ans1--;
		if(!ans1)
			return false;
		while(true){
			ans2++;
			if(ans1*c1 + ans2*c2 > b){
				ans2--;
				break;
			}
		}
		if(ans1*c1 + ans2*c2 <= b && ans1 + ans2 >= q1)
			return true;
	}
}

int main(){
	while(true){
		cin >> q1;
		if(!q1)
			return 0;
		cin >> b >> c1 >> c2 >> q2;
		if(solve())
			cout << ans1 << ' ' << ans2 << endl;
		else
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>

#define N 101

#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs();
void visit(int);

int A[N][N] = {0};
int color[N] = {0};
int d[N] = {0};
int f[N] = {0};
int num ,time;

int main(){
  int inum, jnum, count, i, j;
  
  scanf("%d", &num);
  
  for(i = 1; i <= num; i++){
    scanf("%d %d", &inum, &count);  
    for(j = 1; j <= count; j++){
      scanf("%d", &jnum);
      A[inum][jnum] = 1;
    }
  }
  
  dfs();
  
  for(i = 1; i <= num; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  
  
  return 0;
}

void dfs(){
  int i;

  time = 0;
  
  for(i = 1; i <=num; i++){
    if(color[i] == WHITE){
      visit(i);
    }
  }
}

void visit(int u){
  int i;

  //printf("num %d visit", u);
  
  color[u] = GRAY;
  d[u] = ++time;

  for(i = 0; i <=num; i++){
    if(A[u][i] == 1 && color[i] == WHITE){
      visit(i);
    }
  }

  color[u] = BLACK;
  f[u] = ++time;
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int X, A; cin >> X >> A;
	cout << (X<A?"0":"10") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<((f)?YES:NO)<<"\n";

void solve(long long H, long long N, std::vector<long long> A){
    judge(H<=vsum(A));
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
//#include "./libb/lib.hpp"

using namespace std;

int main()
{
    uint32_t nn;
    uint32_t mm;
    cin >> nn >> mm;

    uint32_t sum = 0;
    uint32_t temp = 0;

    for(int i = 0; i < mm; i++){
        cin >> temp;
        sum += temp;
    }

    if(sum > nn){
        cout << -1 << endl;
    }else{
        cout << (nn - sum) << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    const [n, x, t] = input.split(" ").map(v => parseInt(v, 10));
    

	//出力
	console.log(Math.ceil(n / x) * t);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29644
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long  y){
    if(x == 0 || y == 0) return x+y;
    else return gcd(y,x%y);
}

long long num(long long X,long long c,long long d){
    return X - X/c - X/d + X/(c*d/gcd(c,d));
}

int main(){
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << num(B,C,D) - num(A-1,C,D) << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

N = int(input())
A = list(map(int, input().split()))

D = getD(max(A))

flag = True

d_set = set()
for k in A:
    while k != 1:
        div = D[k]
        if div in d_set:
            flag = False
            break
        else:
            d_set.add(div)
        
        while k % div == 0 and k > 1:
            k = k // div

if flag:
    print('pairwise coprime')
    exit()

if reduce(math.gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 127664
N = gets.chomp.to_i

a = gets.chomp.split.map(&:to_i)
l = a.max.to_s(2).length

MOD = 10**9 + 7
ans = 0
(l+1).times do |i|
  n0 = a.count{ |x| x[i] == 0}

  # 全体のうちi桁目が0でないものは1であるため
  n1 = a.size - n0

  ans += n0*n1*2**i
  ans %= MOD
end

p ans


Measured memory_bytes: 42372
h , w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
zyun = []
for i in range(1,h+1):
    if i % 2 == 1:
        for j in range(1,w+1):
            zyun.append((i,j))
    elif i % 2 == 0:
        for j in reversed(range(1,w+1)):
            zyun.append((i,j))
p = 0
cou = 0
ans = []
for y , x in zyun:
    if p == 0 and a[y-1][x-1] % 2 == 1:
        maey = y
        maex = x
        p = 1
    elif p == 1:
        ans.append([maey,maex,y,x])
        cou += 1
        if a[y-1][x-1] % 2 == 0:
            maey = y
            maex = x
        elif a[y-1][x-1] % 2 == 1:
            p = 0
print(cou)
for i in range(len(ans)):
    print(*ans[i])

Measured memory_bytes: 45588
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

/* 数列aの任意の二つの和に対して、xより大きい物の数を返す*/
ll query(int x, vector<int> &a){
    ll cnt = 0;
    rep(i, a.size()){
        cnt += a.end() - lower_bound(a.begin(), a.end(), x - a[i]);
    }
    return cnt;
}

ll sumans(int x, ll m, vector<int> &a){
    vector<ll> sum;
    ll s = 0;
    rep(i, a.size()){ sum.push_back(s); s += a[i]; }
    sum.push_back(s);

    ll ans = 0;
    ll shake_cnt = 0;
    rep(i, a.size()){
        int itr = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();
        ans += sum[a.size()] - sum[itr] + ((ll)a[i] * (a.size() - itr));
        shake_cnt += a.size() - itr;
    }
    if (shake_cnt > m) ans -= (ll)x*(shake_cnt - m);
    return ans;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}
    sort(a.begin(), a.end());
    //show(a);
    //cout << endl;
    //rep(i, 10) cout << i*10 << " " << query(i*10, a) << endl;

    int left = -1;
    int right = 200001;
    //入力mに対して、選ばれる数の下限を導出する
    //閾値を大きくすればmは減る
    while (abs(right - left) > 1){
        int mid = (left + right) / 2;
        if (m <= query(mid, a)){
            left = mid;
        } else {
            right = mid;
        }
    }
    //left以上の和がmパターン持つ事を補償している。
    //right以上の和がmパータン持たない事を補償している。
    //std::cout << "left:"<<left << endl;
    //std::cout << right << endl;

    std::cout << sumans(left, m, a) << endl;
}



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

using namespace std;

#define ll long long int

ll mod=1000000007;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll rem = 1;
    for(int i=0;i<n;i++){
        rem *= 10;
        rem %= mod;
    }
    ll r2 = 2;
    for(int i=0;i<n;i++){
        r2 *= 9;
        r2 %= mod;
    }
    ll r3 = 1;
    for(int i=0;i<n;i++){
        r3 *= 8;
        r3 %= mod;
    }
    ll p = rem - r2 + r3;
    if(p >0){
        cout<<p%mod<<endl;
    }else{
        cout<<(mod+p)%mod<<endl;
    }

    return 0;
}

Measured memory_bytes: 3644
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [a, b] = string_to_int(inputs[0])

    ret = 0
    if a > b:
        ret += a
        a -= 1
    else:
        ret += b
        b -= 1
    if a > b:
        ret += a
    else:
        ret += b

    return ret


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3316
import sys


def check(p):
    tmp = 0
    cnt = 1
    flag = 0
    for w in w_list:
        if w > p:
            flag = -1
            break
        tmp += w
        if tmp > p:
            cnt += 1
            tmp = w
        if cnt > k:
            flag = -1
            break
    return flag


def solve():
    left = 0
    right = w_max
    while (right - left > 1):
        mid = int((left + right) / 2)
        flag = check(mid)
        if flag == 0:
            right = mid
        else:
            left = mid
    return right


input = sys.stdin.readline
n, k = map(int, input().split())
w_list = []
w_max = 0
for _ in range(n):
    w = int(input())
    w_max += w
    w_list.append(w)
print(solve())



Measured memory_bytes: 9552
/*  ex4_2
    potter0723sw  */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void) {
	double lengtha,lengthb,hour,minute,radian,mid,ans;
	scanf("%lf %lf %lf %lf", &lengtha, &lengthb, &hour, &minute);
	radian = fabs(5.5 * minute - 30 * hour) * M_PI / 180;
	//5.5は6-0.5で長針の1分6度の動きから短針の1分0.5度の動きの差をとったもの
	mid = pow(lengtha,2)+ pow(lengthb,2) - 2*lengtha*lengthb * cos(radian);//余弦定理
	ans = sqrt(mid);//平方根をとって答え
	printf("%13.10lf\n", ans);
	//誤差を減らすために小数点以下第10位まで出力
	return 0;
}


Measured memory_bytes: 2600
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main(){
  int n,k,ans=0;
  cin>>n>>k;
  int hei[n];
  rep(i,n)cin>>hei[i];
  rep(j,n){
    if(hei[j]>=k)ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d %d", $x2, $y2, $n);
$x1 = $y1 = 0;
for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d %d %d", $x, $y, $a);
	if ($a == 1 && $x > $x1) {
		$x1 = $x;
	} elseif ($a == 2 && $x < $x2) {
		$x2 = $x;
	} elseif ($a == 3 && $y > $y1) {
		$y1 = $y;
	} elseif ($a == 4 && $y < $y2) {
		$y2 = $y;
	}
}
$w = $x2 - $x1;
$h = $y2 - $y1;
echo $w > 0 && $h > 0 ? $w * $h : 0, "\n";

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

int main()
{
  int N;

  cin >> N;

  long long MAX=1000000000000000000LL;
  vector<long long>A(N);
  long long ans=1;


  for(int i=0;i<N;i++){
    cin >> A.at(i);

    if(A.at(i)==0LL){
      cout << 0 << endl;
      return 0;
    }
  }

  sort(A.begin(),A.end());


  for(int i=0;i<N;i++){


    if(MAX / ans < A.at(i)){
      cout << -1 << endl;
      return 0;
    }
      ans*=A.at(i);
  }

  cout << ans;

return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = (1LL<<40);
using namespace std;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}

int main(int argc,char ** argv){
	dhoom;
	int n;
	cin >> n;
	int a[n + 2];
	a[0] = a[n+1] = 0;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
	}
	ll sum = 0;
	for(int i = 1 ; i <= n + 1 ; i++)
		sum += abs(a[i] - a[i-1]);
	for(int i = 1 ; i <= n ; i++){
		cout << sum + abs(a[i+1] - a[i - 1]) - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
bool comp(string s1,string s2){
    return s1.length()<s2.length();
}
int main(){
	FIO;
	int n;cin>>n;
	vpi vec[n];
	for(int i=0;i<n;i++){
		int k;cin>>k;
		for(int j=0;j<k;j++){
			int u,v;cin>>u>>v;
			vec[i].emplace_back(u-1,v);
		}
	}
	int ans=0;
	for(int i=1;i<(1<<n);i++){
		int st=__builtin_popcount(i);
		bool ok=true;
		for(int j=0;j<n;j++){
			if((i&(1<<j))==0) continue;
			for(auto it:vec[j]){
				if((i&(1<<it.f))){
					if(it.se==0) ok=false;
				}
				else{
					if(it.se==1) ok=false;
				}
			}
		}
		if(ok){
			ans=max(ans,st);
		}
	}
	cout<<ans;
} 
 

Measured memory_bytes: 256
--editorial
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r' :: IO [Int]
r'  = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    [n,m] <- r'
    as <- sort <$> r'
    bcs<- sortBy (flip $ comparing snd) <$> replicateM m rp
    let bcsx = concat (map (uncurry replicate) bcs) ++ repeat 0
    print $ sum (zipWith max bcsx as)

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

using ll = long long;
#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)

//int#define INF 1e9
const ll INF = 1LL << 61;

int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  REP(i, N){
    cin >> a[i];
  }
  ll ans = INF;
  REP(b, 1<<N){
    ll pre = 0;
    ll cost = 0;
    int cnt = 0;
    REP(i, N){
      if(b>>i & 1){
        ll diff = max(0LL, pre-a[i]+1);
        assert(diff >= 0);
        cost += diff;
        pre = a[i] + diff;
        cnt++;
      }
      else{
        pre = max(pre, a[i]);
      }
    }
    if(cnt >= K){
      ans = min(ans, cost);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())

    ans = 2000000000000
    a = 1 + int(n**0.5)

    for i in range(1,a):
        if n%i == 0:
            if ans > i + (n//i):
                ans = i +(n//i)

    ans -= 2
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188