akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc155/tasks/abc155_d

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

#define DEBUG 0
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if 1
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(a) if (DEBUG) REP(_i, a.size()) DUMP(a[_i]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(a)
#endif

const int N_MAX = 2*1e5;
const int A_I_MAX = 1e9;
const ll INF = 1e18+1;

int N;
ll K;
vector<ll> A;

ll K2;

bool C(ll x) {
#if DEBUG
  cout << "x=" << x << endl;
#endif
  ll sum = 0;
  ll sum2 = 0;
  int j;
  bool neg_init = true;
  bool pos_init = true;
  REP(i, N) {
    ll v = A[i];
#if DEBUG
    cout << "  A[" << i << "]=" << v;
#endif
    int cnt = 0;
    if (v < 0) {
      if (x >= 0) {
        if (neg_init) { j = N - 1; neg_init = false; }
        while(j >= 0 && A[j] * v <= x) j--;
        cnt = max(0, i - (j + 1));
      } else {
        if (neg_init) { j = 0; neg_init = false; }
        while (j < N && A[j] * v > x) j++;
        cnt = max(0, i - j);
      }
    }
    if (v == 0) {
      cnt = (x >= 0 ? i : 0);
    }
    if (v > 0) {
      if (x >= 0) {
        if (pos_init) { j = N - 1; pos_init = false; }
        while (j >= 0 && A[j] * v > x) j--;
        cnt = min(i, j + 1);
      } else {
        if (pos_init) { j = 0; pos_init = false; }
        while (j < N && A[j] * v <= x) j++;
        cnt = min(i, j);
      }
    }
    sum += cnt;
    sum2 += i - cnt;
#if DEBUG
    cout << ", j=" << j;
    cout << ", cnt=" << cnt;
    cout << ", sum=" << sum;
    cout << ", sum2=" << sum2;
    cout << endl;
#endif
    if (sum >= K) return true;
    if (sum2 > K2) return false;
  }
  return false;
}

ll bsearch() {
  ll hi = INF;
  ll lo = -INF;
  while (hi - lo > 1) {
    ll mi = (hi + lo) / 2;
    if (C(mi)) hi = mi;
    else lo = mi;
  }
  return hi;
}

int main() {
  cin >> N >> K;
  A = vector<ll>(N);
  REP(i, N) cin >> A[i];

  K2 = (ll) N * (N - 1) / 2 - K;
#if DEBUG
  cout << "K=" << K << ", K2=" << K2 << endl;
#endif
  sort(A.begin(), A.end());

  ll ans = bsearch();
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	char alpha;
	cin >> alpha;

	printf("%c\n", alpha+1);

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
lis = []
for _ in range(n):
  lis.append(list(map(int,input().split())))
lis.sort()
ans=0
for i in range(n):
  x,y = lis[i]
  if y >= m:
    ans += x*m
    print(ans)
    quit()
  ans += x * y
  m -= y
print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int x = 0;
    int mx = 0;
    rep(i, n) {
        if(s[i] == 'I') x++;
        else x--;
        mx = max(x, mx);
    }
    cout << mx;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
const ll MOD=1000000007LL;

int main(){
	ll N;
	string S;
	cin >> N >> S;
	ll ans = 1;
	ll cnt = 0;//まだ結ばれてない
	FOR(i,0,2*N){
		if( (cnt%2==0&&S[i]=='B') || (cnt%2==1&&S[i]=='W') ){
			cnt++;
		}else{
			(ans *= cnt) %= MOD;
			cnt--;
		}
		if(cnt<0){
			cout << 0 << endl;
			return 0;
		}
	}
	FOR(i,1,N+1){
		(ans*=i)%=MOD;
	}
	cout << (cnt!=0 ? 0LL : ans) << endl;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ASecurity solver = new ASecurity();
    solver.solve(1, in, out);
    out.close();
  }

  static class ASecurity {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      char[] c = in.next().toCharArray();
      for (int i = 1; i < c.length; i++) {
        if (c[i] == c[i - 1]) {
          out.println("Bad");
          return;
        }
      }
      out.println("Good");
    }

  }


  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

  }
}



Measured memory_bytes: 23380
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n = int(input())
a=list(map(int,input().split()))

import numpy as np
r=0
s=sum(a)-a[0]
m=7+10**9
for ii in range(n-1):
  r+=(a[ii]*s)%m
  s-=a[ii+1]

#print(m)
print(r%m)


Measured memory_bytes: 34236
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var no = input.split(' ').map(Number);
var a = no[0];
var b = no[1];
var c = no[2];
var divisors = [];
for(var i = a; i <= b; i++){
    if(c % i === 0){
        divisors.push(i);
    }
}
console.log(divisors.length);


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


def solve(inputs):
    [P, Q, R] = list(map(lambda x: int(x), inputs[0].split()))
    l = []
    l.append(P + Q)
    l.append(P + R)
    l.append(Q + R)

    min = P + Q
    for i in l:
        min = i if min > i else min
    return min


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

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin >> N >> M;
  vector<bool> can(10,false);
  for(int i=0; i<M; i++){
    int a;
    cin >> a;
    can[a] = true;
  }
  vector<int> num = {0,2,5,5,4,5,6,3,7,6};
  vector<pair<int,string>> dp(N+1,pair<int,string>(0,""));
  for(int i=0; i<N; i++){
    if(i && dp[i].first == 0) continue;
    for(int j=1; j<10; j++){
      if(!can[j]) continue;
      if(i+num[j] <= N){
        pair<int,string> now = dp[i];
        now.first++;
        now.second += j + '0';
        chmax(dp[i+num[j]],now);
      }
    }
  }
  // for(int i=0; i<=N; i++){
  //   cout << i << " " << dp[i].second << "\n";
  // }
  cout << dp[N].second << "\n";
  return 0;
}

Measured memory_bytes: 54832
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y[x];
    int q[x];
    for (int i=0;i<x;i++){
        cin>>y[i];
        q[i]=y[i];
    }
    sort(q,q+x);
    int c=0;
    for (int i=0;i<x;i++){
        if (q[i]!=y[i])
            c++;
    }
    if (c<=2)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n = 1;
  while(n != 0){
  cin >> n;
    
  double sum = 0, disp = 0;
    if( n == 0 ) break;
  
  vector<int> score(n);
  
  for(int i = 0; i < n; i++){
    cin >> score.at(i);
    sum += score.at(i);
  }
  sum = sum / n;
  for(int i = 0; i < n; i++){
    disp += (sum - score.at(i)) * (sum - score.at(i));
  }
  disp = sqrt(disp / n);
  printf("%.8lf\n", disp);
  }
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#include <functional>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //aからb - 1まで
#define p(x) cout<<x<<endl  //xを改行付きで出力
const int INF = 1000000007;  //最大値兼MOD
//  cin.tie(0);
//  ios::sync_with_stdio(false);
typedef long long ll;
using namespace std;
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; }
int main(){
  int n;
  cin >> n;
  if(65 <= n && n <= 90)p(1);
  else if(97 <= n && n <= 122)p(2);
  else p(0);
  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool used[26] = {};
    for(char c : s) used[c - 'a'] = 1;
    for(int i = 0; i < 26; i++){
        if(!used[i]){
            cout << s + (char)('a' + i) << endl;
            return 0;
        }
    }
    string t = s;
    if(next_permutation(s.begin(), s.end())){
        int len = s.size();
        while(0 < len && t < s.substr(0, len - 1)) len--;
        cout << s.substr(0, len) << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

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

int main() {
  string name1, name2;
  string sbuff;
  
  cin >> name1;
  cin >> name2;
  
  sbuff = name2.substr(0, name1.size());
  if (sbuff == name1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	buttons := make([]int, N)
	for i := 0; i < N; i++ {
		buttons[i] = nextInt()
	}
	var next, count int
	seen := make(map[int]bool)
	for next != 1 && !seen[next] {
		seen[next] = true
		next = buttons[next] - 1
		count++
	}
	if next == 1 {
		fmt.Println(count)
	} else {
		fmt.Println(-1)
	}
}


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

int main(){
  int N;
  cin>>N;
  int A[N];
  int cnt=0;
  for(int i=0;i<N;i++){
    cin >>A[i];
    if((i+1)%2==1 && A[i]%2==1){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

  
 
  
  
  

  

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

int main(){
	int x,y;
	while(1){
		cin >> x >> y;
		if (x==0 && y==0) break;
		if (x<y){
		}else{
			swap(x,y); // swap(x,y)??§x,y?????????????????????
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 2984
// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ans=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        ans+= s[i]-'0';
    if(ans%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



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

using namespace std;

int main()
{
    int n,k,x,y;
    cin >> n >> k>>x>>y;
    if(n<=k)
        cout << n*x << endl;
    else{
        cout << k*x+(n-k)*y << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// C
#include<bits/stdc++.h>
#define pb push_back 
#define mp make_pair
using namespace std;

const int maxn=2e5+7;
typedef long long ll;

int n,m;
int f[maxn][128];

int num;
int l[maxn],r[maxn];

char s[maxn];

string ans;

int main()
{
/* 
#ifndef LOCAL
	freopen("","r",stdin);
	freopen("","w",stdout);
#endif*/

	int i,j,k,T;
	scanf("%s",s);
	int len=strlen(s);
	
	int t=0;
	r[num]=len-1;
	for(i=len-1;i>=0;--i)
	{
		if(f[num][s[i]]==0)
		{
			t++;
		}
		f[num][s[i]]++;
		if(t==26)
		{
			t=0;
			l[num]=i;
			num++;
			r[num]=i-1;
		}
	}
	
	for(j='a';j<='z';++j)
	{
		if(f[num][j]==0)
		{
			ans+=j;
			break;
		}
	}
	
	char pre=j;
	while(num)
	{
		num--;
		char minv=s[l[num]];
		for(i=l[num];;i++)
		{
			f[num][s[i]]--;
			if(f[num][s[i]]==0)
			  minv=min(minv,s[i]);
			if(s[i]==pre)
			{
				break;
			}
		}
		ans+=minv;
		pre=minv;
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  string s,t;
  cin>>s;
  t=s;
  reverse(s.begin(),s.end());
  if(t==s){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N,K;
  in(N,K);
  string S;
  in(S);
  int score=0;
  rep(i,N-1)if(S[i]==S[i+1])score++;
  out(min(score+2*K,N-1));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		//train
		int train = N * A;
		
		if (train < B){
			System.out.println(train);
		
		}else{
			System.out.println(B);
		}
    }
}

Measured memory_bytes: 23764
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define double long double
#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define pi acos(-1.0)

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int k;
    cin >> k;
    string s;
    cin >> s;
    if (k >= sz(s)) {
        cout << s;
    } else {
        cout << s.substr(0, k) << "...";
    }

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int ret;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		while(x%2==0) ret++, x/=2;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VMM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

uread v i = unsafePerformIO $ VM.read v i
uwrite v i a = unsafePerformIO $ VM.write v i a >> return v
umodify v f i = unsafePerformIO $ VM.modify v f i >> return v
uthaw = unsafePerformIO . VU.thaw
ufreeze = unsafePerformIO . VU.freeze

umodifyV v f i = unsafePerformIO $ VMM.modify v f i >> return v
uthawV = unsafePerformIO . V.thaw
ufreezeV = unsafePerformIO . V.freeze

dijkstra
  :: Int  -- ^ nodes
  -> V.Vector [(Int, Int)]  -- ^ edges from i-th node: (end, cost)
  -> Int  -- ^ start node
  -> Int  -- ^ end node
  -> VU.Vector Int  -- ^ constructed graph
dijkstra n edges s t = ufreeze $ snd $ fix (\f (nodes,costs) -> case S.minView nodes of
    Nothing -> (S.empty,costs)
    Just ((c,n), nodes) ->
      if c <= uread costs n
        then
          let es = edges V.! n in
            f $ foldl' (\(ns,cs) (e,ec) ->
              let c' = c + ec in if c' < uread costs e
                then (S.insert (c',e) ns, uwrite cs e c')
                else (ns,cs)
              ) (nodes,costs) es
        else f (nodes,costs)) (nodes0,costs0)
  where
    costs0 :: VM.IOVector Int
    costs0 = uwrite (uthaw $ VU.replicate n maxBound) s 0

    nodes0 :: S.Set (Int,Int)
    nodes0 = S.singleton (0,s)

solve :: Int -> Int -> Int -> Int -> VU.Vector (Int,Int,Int,Int) -> [Int]
solve n m s t trains = map (10^15 -) $ fst $ foldl' (\(acc,prev) i -> let cur = calcCost i `min` prev in (cur:acc,cur)) ([],10^15 :: Int) [n-1,n-2..0]
  where
    yenGraph = dijkstra n (ufreezeV $ VU.foldl' (\gr (u,v,a,b) -> umodifyV (umodifyV gr ((v,a) :) u) ((u,a) :) v) (uthawV $ V.replicate n []) trains) s t
    snookGraph = dijkstra n (ufreezeV $ VU.foldl' (\gr (u,v,a,b) -> umodifyV (umodifyV gr ((v,b) :) u) ((u,b) :) v) (uthawV $ V.replicate n []) trains) t s

    calcCost i = yenGraph VU.! i + snookGraph VU.! i

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n,m,s,t) <- (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2 - 1, vec VU.! 3 - 1)) . VU.unfoldrN 4 readInt <$> B.getLine
  uvab <- VU.replicateM m $ (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 readInt <$> B.getLine
  mapM_ print $ solve n m s t uvab


Measured memory_bytes: 81532
N, M = map(int, input().split())
A = list(map(int, input().split()))

t = 0 
c = 0 

for i in A:
        t += i

for i in A:
        if i >= (t / (4*M)):
                c += 1
if c >= M:
        print("Yes")
else:
        print("No") 

Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

#define rep(i, N) for (int i = 0; i < N; i++)

using namespace std;
int main() {
  int X,A,B;
  cin >> X >> A >> B;
  cout << (X-A)%B << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N; 
    vector<int>a(N);
    map<int,int>Map;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        Map[a[i]]++;
    }
    int ans = 0;
    for(auto x:Map) {
        int X = x.first;
        int Y = x.second;
        if(X <= Y) {
            ans+=(Y-X);
        }
        else {
            ans+=Y;
        }
    }
    cout <<  ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum=0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
	int l, r;
    cin >> l >> r;

    sum += r-l+1;
    
  }
  
  cout << sum << endl;
  
 }
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> nt(n), na(n);
    rep(i, 0, n) {
        ll t, a;
        cin >> t >> a;
        if (i == 0) nt[i] = t, na[i] = a;
        else {
            nt[i] = (t * max((nt[i-1]+t-1)/t, (na[i-1]+a-1)/a));
            na[i] = (a * max((nt[i-1]+t-1)/t, (na[i-1]+a-1)/a));
        }
    }
    cout << nt[n-1] + na[n-1] << endl;
}

Measured memory_bytes: 256
import math
a, b, x = map(int, input().split())
if 2 * x > a**2 * b:
    aa = 2 * a**2 * b - 2 * x
    bb = a**3
else:
    aa = a * b**2
    bb = 2 * x
print(math.degrees(math.atan2(aa, bb)))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(){}
  UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  UnionFind uf(n),bp(n*2);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    u--;v--;
    uf.unite(u,v);
    bp.unite(u+0,v+n);
    bp.unite(u+n,v+0);
  }
  using ll = long long;
  ll odd=0,eve=0,iso=0;
  for(int i=0;i<n;i++){
    if(uf.find(i)!=i) continue;
    if(uf.size(i)==1){
      iso++;
      continue;
    }
    if(bp.same(i,i+n)) odd++;
    else eve++;
  }
  ll ans=(ll)n*n-(n-iso)*(n-iso);
  ans+=(odd+eve)*(odd+eve);
  ans+=eve*eve;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if (a<b)
	{
		cout<<"a < b"<<endl;
	}
	else if(a>b)
	{
		cout<<"a > b"<<endl;
	}
	else
	{
		cout<<"a == b"<<endl;
	}
	return 0;
 } 


Measured memory_bytes: 3080
n = int(input())
s = list(map(str, input().strip()))
seed = 131
mod1 = 10 ** 9 + 9
mod2 = 10 ** 9 + 7
lsd = [1] * 6000
lsd2 = [1] * 6000
hs = [1] * 6000
hs2 = [1] * 6000
hs[0] = ord(s[0]) - ord('a')
hs2[0] = ord(s[0]) - ord('a')
for i in range(1, n):
    lsd[i] = lsd[i - 1] * seed % mod1
    lsd2[i] = lsd2[i - 1] * seed % mod2
    hs[i] = (hs[i - 1] * seed + ord(s[i]) - ord('a')) % mod1
    hs2[i] = (hs2[i - 1] * seed + ord(s[i]) - ord('a')) % mod2


def check(x):
    from collections import defaultdict
    g = defaultdict(int)
    for i in range(n - x + 1):
        if i:
            t = (hs[i + x - 1] - hs[i - 1] * lsd[x]) % mod1
        else:
            t = hs[i + x - 1]
        # print(i,t)
        if not g[t]:
            g[t] = i + 1
        elif g[t] + x - 1 <= i:
            return True
    return False


l = 0
r = n
while l < r - 1:
    m = (l + r) // 2
    if check(m):
        l = m
    else:
        r = m - 1

if check(r):
    print(r)
else:
    print(l)


Measured memory_bytes: 44016
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> c(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j =0; j < W; j++) cin >> c[i][j];
    }
    int ans = 0;
    for(int bit1 = 0; bit1 < (1 << H); bit1++){
        vector<int> useh(H, 0);
        for(int i = 0; i < H; i++){
            if(bit1 & (1 << i)) useh[i]++;
        }
        for(int bit2 = 0; bit2 < (1 << W); bit2++){
            int cnt = 0;
            vector<int> usew(W, 0);
            for(int i = 0; i < W; i++){
                if(bit2 & (1 << i)) usew[i]++;
            }
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(useh[i] == 0 && usew[j] == 0 && c[i][j] == '#') cnt++;
                }
            }
            if(cnt == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main() {
  int N;
  int otsuri = 0;
  scanf("%d", &N);
  otsuri = 1000 - N;
  while (otsuri < 0) {
    otsuri = otsuri + 1000;
  }
  printf("%d\n", otsuri);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define ll long long
#include <numeric>
using namespace std;
const int sz = 1e7+5;
ll int arr[sz], arr1[sz];
//ll int arr[100][100]= {0};
bool prime[sz]= {0};
vector <ll int> pr,vec1,vec2;
//vector <pair <int,int>> vec;
 
 
void NOD ( ll int n ) {
 
  for(int i=1;i<=n;i++)
    for(int j=i;j<=n;j+=i)
        arr[j]++;
 
 
}
 
int main()
{
	NOD(1e7); 
    ll int n;
    cin>>n;

    unsigned ll int k =0;
    for(int i=1;i<=n;i++)
    {
        k+=(arr[i]*i);
    }
 
    cout<<k<<endl;
}

Measured memory_bytes: 81708
n,k=map(int,input().split())
m=(n-1)*(n-2)/2
ans=[]
if m<k:
  print(-1)
  exit()
else:
  for i in range(2,n+1):
    ans.append([1,i])
  a=m-k
  for i in range(2,n+1):
    for j in range(i+1,n+1):
      if a>0:
        a-=1
        ans.append([i,j])
      else:
        continue

print(len(ans))
for i , j in ans:
  print(i,j)


Measured memory_bytes: 43504
n,a,b=map(int,input().split())
if a>b:
  print(0)
  exit()
if n == 1:
  if a == b:
    print(1)
  else:
    print(0)
  exit()
if n == 2:
  print(1)
  exit()
print((b-a)*(n-2)+1)

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline

N=int(input())

X1={}
X2={}

X={}
Y={}

for i in range(N):
    x,y,u=input().split()
    x=int(x)
    y=int(y)
    if x+y not in X1:
        X1[x+y]=[[x,u]]
    else:
        X1[x+y].append([x,u])
    if y-x not in X2:
        X2[y-x]=[[x,u]]
    else:
        X2[y-x].append([x,u])
    if x not in X:
        X[x]=[[y,u]]
    else:
        X[x].append([y,u])
    if y not in Y:
        Y[y]=[[x,u]]
    else:
        Y[y].append([x,u])


Dead=10**9


for k,v in X1.items():
    D=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="D":
            D=a
        elif u=="R":
            R=a
        elif u=="L":
            if D>=0:
                Dead=min(Dead,(a-D)*10)
        elif u=="U":
            if R>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X2.items():
    U=-1
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="R":
            R=a
        elif u=="L":
            if U>=0:
                Dead=min(Dead,(a-U)*10)
        elif u=="D":
            if R>=0:
                Dead=min(Dead,(a-R)*10)
for k,v in X.items():
    U=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="U":
            U=a
        elif u=="D":
            if U>=0:
                Dead=min(Dead,(a-U)*5)
for k,v in Y.items():
    R=-1
    v.sort()
    #print(v)
    for a,u in v:
        if u=="R":
            R=a
        elif u=="L":
            if R>=0:
                Dead=min(Dead,(a-R)*5)
if Dead==10**9:
    print("SAFE")
else:
    print(Dead)

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n, k;
V<int> h;
V<int> d;
V<int> s;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> n; cin >> k;
    h.resize(n,0);
    REP(i, n) cin >> h[i];
    std::sort(ALL(h),ASC(int));

    d.resize(n+1,0);
    FOR(i,1,n) d[i] = abs(h[i]-h[i-1]);
    s.resize(n+1,0);
    FOR(i,1,n) s[i] = s[i-1] + d[i];

    int ans = 1000000001;
    for(int i = 0, j = k-1; j < n; i++,j++) {
        CHMIN(ans, s[j]-s[i]);
    }
    OUT(ans) NL;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<bits/stdc++.h>
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
using namespace std;
int fac(int n)
{
    int fct = 1;
    for(int i=2; i<=n; i++) fct *= i;
    return fct;
}
int main() {
    Fast;
    int n;
    cin >> n;
    vector<pair<int, int>> cords;
    int i;
    for(i=0; i<n; i++){
        int x, y;
        cin >> x >> y;
        cords.pb(mp(x, y));
    }
    int j;
    double len = 0;
    for(i=0; i<n-1; i++){
        for(j=i; j<n; j++){
            len += sqrt((cords[i].first - cords[j].first)*(cords[i].first - cords[j].first) + (cords[i].second - cords[j].second)*(cords[i].second - cords[j].second));
        }
    }
    //double avg = (2.0*len)/(1.0*fac(n)*n) << endl;
    double ans = len*2/n;
    std::cout << std::fixed<<std::setprecision(19);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3832
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    string S;
    cin >> S;
    if(((S[0]==S[S.size()-1])^(S.size()%2))){
        cout << "First\n";
    }else{
        cout << "Second\n";
    }
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<Mint> f(n + 1), sf2(n + 2), sf1(n + 2);
	Mint ans = 1;
	for (int i = n; i >= 1; --i) {
		if (i == n) {
			f[n] = n - 1;
		} else {
			f[i] = (n - 1) + Mint(n - 1) * (n - 1);
			if (i + 3 <= n) f[i] += sf2[i + 3] - (i + 2) * sf1[i + 3];
		}
		sf2[i] = f[i] * i + sf2[i + 1];
		sf1[i] = f[i] + sf1[i + 1];
		ans += f[i];
	}
	printf("%d\n", ans.val);
}


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

int main() {
    vector<char> s(19);
    for (int i = 0; i < 19; i++) {
        cin >> s.at(i);
        if (s.at(i) == ',') s.at(i) = ' ';
        
        if (i + 1 == 19) {
            cout << s.at(i) << endl;
        }
        else {
            cout << s.at(i);
        }
    }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    int t = 1000 - N % 1000;
    if(N % 1000 == 0) t = 0;
    cout << t << endl;
    return 0;
}



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

const int N = 1e5 + 5;

int n, k;
long long x[N];

int main(void) {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++ i) {
		scanf("%lld", &x[i]);
	}
	
	long long ans = 1e17;
	for (int i = 1; i <= n; ++ i) {
		int j = i + k - 1; if (j > n) break;
		long long cur = abs(x[j] - x[i]);
		ans = min(ans, cur + min(abs(x[i]), abs(x[j])));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	long long int a, b, x;
	cin >> a >> b >> x;
	long long int aa, bb;
	aa = a/x;
	bb = b/x;
	if (a%x!=0) {
		aa++;
	}
	cout << bb-aa+1 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
namespace inonoa{
    class Ino{
        static void Main(){
            long n = long.Parse(Console.ReadLine());
            double rt = Math.Sqrt(n);
            long a = 0;
            for(int i=1;i<=rt;i++){
                if(n%i==0){
                    a = n/i;
                }
            }
            Console.WriteLine((int)Math.Log10(a)+1);
        }
    }
}

Measured memory_bytes: 11092
<?php
while (true) {
    list($height, $width) = getSpacesByExplodeTrimInput();
    $lines = array();

    if ($height == 0 && $width == 0) {
        break;
    }

    for ($i = 0; $i < $height; $i++) {
        if ($i % 2) {
                $lines[] = setEvenNumLine($width);
        } else {
                $lines[] = setOddNumLine($width);
        }
    }

    echo implode($lines), PHP_EOL;
}
  
function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}

function setEvenNumLine($width)
{
    for ($i = 0; $i < $width; $i++) {
        $symbols[] = $i % 2 ? "#" : ".";
    }
    return implode($symbols).PHP_EOL;
}

function setOddNumLine($width)
{
    for ($i = 0; $i < $width; $i++) {
        $symbols[] = $i % 2 ? "." : "#";
    }
    return implode($symbols).PHP_EOL;
}

Measured memory_bytes: 15428
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long A = scan.nextLong();
        long B = scan.nextLong();
        long d = N / (A+B);
        long ans = A * d;
        long m = N % (A+B);
        ans += Math.min(m, A);
        System.out.println(ans);
    }
}


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

void dfs(vector<vector<int> > &graph, vector<bool> &visited, vector<int> &maxl, int x) {
    if (!visited.at(x) && !graph.at(x).empty()) {
        visited.at(x) = true;
        for (int y: graph.at(x)) {
            dfs(graph, visited, maxl, y);
            maxl.at(x) = max(maxl.at(x), maxl.at(y) + 1);
        }
    }
    return;
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > graph(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        graph.at(x-1).push_back(y-1);
    }
    vector<int> maxl(n, 0);
    vector<bool> visited(n, false);
    for (int i = 0; i < n; i++) {
        dfs(graph, visited, maxl, i);
    }
    int maximum = 0;
    for (auto x: maxl) {
        maximum = max(maximum, x);
    }
    cout << maximum << endl;
}

Measured memory_bytes: 9472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Gcd(long a, long b)
        {
            return (a < b) ? Gcd(b, a)
                 : (b > 0) ? Gcd(b, a % b)
                           : a;
        }

        static long Gcd(IEnumerable<long> values)
        {
            return values.Aggregate(Gcd);
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(Gcd(A));
        }
    }
}


Measured memory_bytes: 21088
import Data.Char

solve :: String -> String -> Int
solve s w = length $ filter (\x -> map toLower x == lw) $ takeWhile (\x -> x /= "END_OF_TEXT") $ words s
    where lw = map toLower w

main :: IO ()
main = do
    w <- getLine
    s <- getContents
    putStrLn $ show $ solve s w

Measured memory_bytes: 3572
import scala.io.StdIn.readLine

object Main {
  def isPrime(n:Int):Boolean = (2 to Math.sqrt(n).toInt).forall(n%_ != 0)

  def scan(i:Int,s:Int,e:Int,len:Int,mid:Int):Int = {
    if(i < e) {
        (s-1)*s*10 + mid*s + (s-1).toString.reverse.toInt
    } else {
      val x = i*s*10 + mid*s + i.toString.reverse.toInt
      if(isPrime(x)) x
      else scan(i-1,s,e,len,mid)
    }
  }

  def main(args:Array[String]) = {
    val n = readLine.split(" ").map(_.toInt)
    if(n(1)<0) {
      if(n(0)==1) println(11)
      else println( (0 until n(0)).map(_=>"99").mkString )
    } else {
      val r = scan(Math.pow(10,n(0)).toInt-1,Math.pow(10,n(0)).toInt,Math.pow(10,n(0)-1).toInt,n(0),n(1))
      println(r)
    }
  }
}

Measured memory_bytes: 44508
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)
else:
    None


Measured memory_bytes: 61760
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    while(sc.hasNext()) {
      final int n = sc.nextInt();

      if(n == 0) break;

      Map<String, Integer> prices = new HashMap<String, Integer>();

      for(int i = 0; i < n; i++) {
        final String name = sc.next();
        final int price = sc.nextInt();

        prices.put(name, price);
      }

      final int m = sc.nextInt();
      final Map<String, List<String>> recipes = new HashMap<String, List<String>>();

      for(int i = 0; i < m; i++) {
        final String item = sc.next();
        final int k = sc.nextInt();

        final List<String> ingredients = new ArrayList<String>();
        for(int j = 0; j < k; j++) {
          ingredients.add(sc.next());
        }

        recipes.put(item, ingredients);
      }


      for(int i = 0; i < m; i++) {
        Map<String, Integer> new_prices = new HashMap<String, Integer>(prices);

        for(Map.Entry<String, List<String>> e : recipes.entrySet()) {
          final String item = e.getKey();

          final int price = prices.containsKey(item) ? prices.get(item) : INFINITY;

          int sum = 0;
          for(String ingr : e.getValue()) {
            sum += prices.containsKey(ingr) ? prices.get(ingr) : INFINITY;
          }

          if(sum < price) new_prices.put(item, sum);
        }

        prices = new_prices;
      }

      final String item = sc.next();

      System.out.println(prices.get(item));
    }
  }

  private Scanner sc = new Scanner(System.in);
  private static final int INFINITY = 100000000;
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long A,B,C,X,Y,ans1,ans2,ans3,i=0;
	cin>>A>>B>>C>>X>>Y;
	ans1=A*X+B*Y;
	ans2=C*max(X,Y)*2;
	if(X>Y){i=(X-Y)*A;}
	if(Y>X){i=(Y-X)*B;}
	ans3=C*min(X,Y)*2+i;
	ans1=min(ans1,ans2);
	cout<<min(ans1,ans3);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;



int n;
vector<P> v;

int calc1() {
	vector<int> vle, vri;
	rep(i, n) {
		vle.push_back(v[i].first);
		vri.push_back(v[i].second);
	}
	sort(vle.begin(), vle.end());
	sort(vri.begin(), vri.end());
	int ret = 0;
	rep(i, n) {
		int cle = upper_bound(vri.begin(), vri.end(), v[i].first) - vri.begin();
		int cri = lower_bound(vle.begin(), vle.end(), v[i].second) - vle.begin();
		cri = n - cri;
		//cout << i<<" "<<cle << " " << cri << endl;
		ret = max(ret, n-1 - cle - cri + 1);
	}
	return ret;
}

int calc2() {
	vector<P> z;
	rep(i, v.size()) {
		z.push_back({ v[i].first,0 });
		z.push_back({ v[i].second,1 });
	}
	sort(z.begin(), z.end());
	int ret = 0;
	int cnt = 0;
	int len = z.size();
	rep(i, len) {
		if (z[i].second)cnt--;
		else cnt++;
		while (i + 1 < len&&z[i].first == z[i + 1].first) {
			i++;
			if (z[i].second)cnt--;
			else cnt++;
		}
		ret = max(ret, cnt);
	}
	return ret;
}
void solve() {
	cin >> n;
	v.resize(n);
	rep(i, n) {
		cin >> v[i].first >> v[i].second;
		v[i].first--; v[i].second--;

	}
	cout << calc1() << " " << calc2() << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 8608