akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
    {
        static void Main()
        {
            string line = Console.ReadLine();
            double r = double.Parse(line);

            double area = r * r * Math.PI;
            double around = 2 * Math.PI * r;

            Console.WriteLine(area.ToString("F5") + " " + around.ToString("F5"));
        }
    }

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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" <<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000000 + 7;
long long F[200005] = {1};
long long pwr(long long a, long long b) {
	long long ret = 1;
	while(b) {
		if (b & 1) {
			ret = ret * a % MOD;
		}
		a = a * a % MOD;
		b >>= 1;
	}
	return ret;
}
long long ways(int r, int c, int R, int C) {
	R -= r;
	C -= c;
	if (R < 0 or C < 0) {
		return 0;
	}
	long long num = F[R + C];
	long long den = F[R] * F[C] % MOD;
	den = pwr(den, MOD - 2);
	return num * den % MOD;
}
int main() {
	for (int i = 1; i < 200005; ++i) {
		F[i] = F[i - 1] * i % MOD;
	}
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	a = h - a + 1;
	long long total = ways(1, 1, h, w);
	for (int c = 1; c < b; ++c) {
		total -= ways(1, 1, a, c) * ways(a + 1, c, h, w) % MOD; 
	}
	total -= ways(1, 1, a, b) * ways(a, b, h, w) % MOD;
	total = (total % MOD + MOD) % MOD;
	cout << total;
}

Measured memory_bytes: 1792
#include<stdio.h>
 
int main(){
	int n, l, i, max = 0, nmax, sum;
	int a[100005];
	scanf("%d%d", &n, &l);
	for(i = 0; i < n; i++) scanf("%d", &a[i]);
	
	for(i = 0; i < n - 1; i++){
		sum = a[i] + a[i+1];
		if(max < sum ){
			max = sum;
			nmax = i;
		}
	}
	if(max < l){
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	
	for(i = 0; i < nmax; i++)    printf("%d\n", i + 1);
	for(i = n-2; i >= nmax; i--) printf("%d\n", i + 1);
 
	return 0;
}

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

int main()
{
	int n, i;
	cin >> n;
	int a[n+1], s=0;
	for (i=1; i<=n; i++)
	{
		cin >> a[i];
		if (i!=a[i])
		{
			s++;
		}
	}
	if (s==0 || s==2)
	{
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
	return 0;
}

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

int main(){
  int x,n;cin>>x>>n;
  vector<bool> p(110,true);
  for(int i=0;i<n;i++){
    int a;cin>>a;
    p[a]=false;
  }
  int ans=-1,cnt=100;
  for(int i=110;i>=0;i--){
    if(p[i]){
      if(abs(x-i)<=cnt){ans=i;cnt=abs(x-i);}
    }
  }
  cout<<ans<<endl;
}

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

int main() {
	int n, m, i, j;
	int sum = 0;

	cin >> n >> m;

	int a[n][m];
	int b[m];

	for (i = 0; i<n; i++) {
		for (j = 0; j<m; j++) {
			cin >> a[i][j];
		}
	}
	for (j = 0; j<m; j++) {
		cin >> b[j];
	}

	for (i = 0; i<n; i++) {
		for (j = 0; j<m; j++) {
			sum = sum + a[i][j] * b[j];
		}
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end



int main(){
    int a[4]; rep(i,0,4)scanf("%d",&a[i]);
    ll n; scanf("%lld",&n);
    a[0]=min({4*a[0],2*a[1],a[2]});
    printf("%lld\n",min(n*a[0],a[3]*(n/2)+(n&1?a[0]:0)));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,a,b,c,d;
  long double g,h,f;
  cin >>g>>h>>f;
  double an=g+h;
  if(an+2.0*sqrt(g*h)<f) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;

const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,-1,0,1 };
const int LIT = 1e9 + 7;
int n, m;

vector<int> Map[200001];
set<pair<int, int>> s;

void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        if (s.count({ a,b }) == 0) {
            s.insert({ a,b });
            Map[a].push_back(b);
            Map[b].push_back(a);
        }
    }

    vector<bool> bfs_visited(n + 1, false);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int cnt = 1;
        if (!bfs_visited[i]) {
            queue<int>q;
            q.push(i);
            bfs_visited[i] = true;
            while (!q.empty()) {
                int cur = q.front();
                q.pop();

                for (int j = 0; j < Map[cur].size(); j++) {
                    if (!bfs_visited[Map[cur][j]]) {
                        bfs_visited[Map[cur][j]] = true;
                        cnt++;
                        q.push(Map[cur][j]);
                    }
                }
            }
        }
        ans = max(ans, cnt);
    }

    cout << ans;
}

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


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

N, K, C = map(int, input().split())
S = input()[:-1]
l = []

for i in range(N):
    if S[i]=='o':
        l.append(i)

L = []
prev = -10**18

for li in l:
    if li-prev>C:
        L.append(li)
        prev = li

l = l[::-1]
R = []
prev = 10**18

for li in l:
    if prev-li>C:
        R.append(li)
        prev = li

for i in range(K):
    if L[i]==R[K-i-1]:
        print(L[i]+1)

Measured memory_bytes: 61304
#include <iostream>
using namespace std;
const int INF = 1000000000;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)
            break;
        int t[10][10];
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                if(i==j){
                    t[i][j] = 0;
                }
                else{
                    t[i][j] = INF;
                }
            }
        }
        int m = 0;
        for(int i=0; i<n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            t[a][b] = t[b][a] = c;
            if(a+1>m){
                m = a+1;
            }
            if(b+1>m){
                m = b+1;
            }
        }
    for(int k=0; k<m; k++){
      for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
          if(t[i][j]>t[i][k]+t[k][j]){
            t[i][j] = t[i][k]+t[k][j];
          }
        }
      }
    }
    int ans = INF;
      int T;
      for(int i=0; i<m; i++){
        int sum = 0;
        for(int j=0; j<m; j++){
          sum += t[i][j];
        }
        if(sum<ans){
          ans = sum;
          T=i;
        }
      }
        cout << T << ' ' << ans << endl;
    }
    return 0;
}



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

int main()
{
	long long A;
	long double B;
	std::cin >> A >> B;

	std::string ans = std::to_string(A * B);
	for (char x : ans)
	{
		if (x == '.') break;
		std::cout << x;
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3832
# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	c = input()
	rcnt = 0
	wcnt = 0
	for i in c:
		if i == "R":
			rcnt += 1
		else:
			wcnt += 1

	change = 0
	for i in range(N):
		if i < rcnt:
			if c[i] == "W":
				change += 1
		else:
			if c[i] == "R":
				change += 1

	ans = int(change // 2)
	print(ans)

if __name__ == '__main__':
	main()

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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

typedef pair < int ,int > pii;
typedef long long ll;
typedef complex < ll > pt;

const int MAX_N = 100005;
const int MOD = 1e9 + 7;

int n, maxi;
int arr[MAX_N];

bool can ( int val ) {
  bool passOne = false;
  int firstVal = val;
  for ( int i = 0; i < n; ++i ) {
    if ( arr[i] == firstVal and !passOne ) {
      passOne = true;
      continue;
    }
    if ( arr[i] <= 2*val )
      val += arr[i];
    if ( 2*val >= maxi )
      return true;
  }
  return false;
}

int binSearch () {
  int fr = 0, to = n-1, mid;
  while ( fr < to ) {
    mid = (fr+to) / 2;
    if ( can ( arr[mid] ) )
      to = mid;
    else
      fr = mid+1;
  }
  return fr;
}

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  scanf ( "%d", &n );
  for ( int i = 0; i < n; ++i )
    scanf ( "%d", arr+i );

  sort ( arr, arr+n );
  maxi = arr[n-1];

  printf ( "%d\n", n-binSearch () );

  return 0;

}

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

using LL = long long;

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

  int ans = 0;
  int N, X;
  cin >> N >> X;

  int temp = X;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
    temp -= vec[i];
  }
  ans += N;

  int min = *min_element(vec.begin(), vec.end());
  ans += (temp / min);

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=1;i<b;i++){
      if(a*i%b==c){
          cout<<"YES"<<endl;
          return 0;
      }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w;
		int money;
		
		while (true) {
			w = sc.nextInt();
			if (w == -1) {
				break;
			}
			
			money = 0;
			if (30 < w) {
				money += (w - 30) * 160;
				w = 30;
			}
			if (20 < w) {
				money += (w - 20) * 140;
				w = 20;
			}
			if (10 < w) {
				money += (w - 10) * 125;
				w = 10;
			}
			if (0 <= w && w <= 10) {
				money += 1150;
			}
			System.out.println(4280 - money);
		}
	}
}

Measured memory_bytes: 18708
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int X[100005],L[100005];
pair<long long int,long long int>XL[100005];
int main() {
	cout << fixed << setprecision(18);
	long long int N,K,S;
	cin>>N>>K>>S;
	if(S!=1000000000){
		for(int i=0;i<K;i++){
			cout<<S<<" ";
		}
		for(int i=K;i<N;i++){
			cout<<S+1<<" ";
		}
	}else{
		for(int i=0;i<K;i++){
			cout<<S<<" ";
		}
		for(int i=K;i<N;i++){
			cout<<1<<" ";
		}
	}
} 

Measured memory_bytes: 1280
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    map<int,int> mp;
    for(int i=2;i<100000;i++){
        if(i*(i-1)/2<=100000){
            mp[i*(i-1)/2]=i;
        }
        else{
            break;
        }
    }
    if(mp[n]==0){
        cout<<"No"<<endl; return 0;
    }
    cout<<"Yes"<<endl;
    int sz=mp[n];
    cout<<sz<<endl;
    vvec s(sz);
    int cnt=1;
    for(int i=0;i<sz-1;i++){
        for(int j=i+1;j<sz;j++){
            s[i].pb(cnt);
            s[j].pb(cnt);
            cnt++;
        }
    }
    rep(i,sz){
        cout<<s[i].size()<<endl;
        rep(j,s[i].size()){
            cout<<s[i][j]<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3328
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int main(void) {
  int n, m, i, j, k, ans = 0, l;
  scanf("%d%d%d", &n, &m, &k);
  char a[n][m + 10];
  rep(i, n) scanf("%s", a[i]);
  rep(i, n) rep(j, m - k + 1) {
    int s = 1;
    rep(l, k) {
      if(a[i][j + l] == '#') {
        s = 0;
        break;
      }
    }
    if(s) ++ans;
  }
  rep(i, m) rep(j, n - k + 1) {
    int s = 1;
    rep(l, k) {
      if(a[j + l][i] == '#') {
        s = 0;
        break;
      }
    }
    if(s) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2716
#include <cstdio>

int a, b, c, k, ans;

int main() {
    scanf("%d%d%d%d", &a, &b, &c, &k);
    if (a >= k) {
        printf("%d", k);
        return 0;
    }
    ans = a, k -= a;
    if (b >= k) {
        printf("%d", ans);
        return 0;
    }
    k -= b;
    printf("%d", ans - k);
}


Measured memory_bytes: 1728
/* ex4-1
  kt125 */

#include<stdio.h>

int main(void){
    int number, range; 
    scanf("%d %d", &number, &range);

    int ans = 0; //answer
    while(number > 0){
        number -= (2*range+1);  //カッコ内は一人の監視員が見れる本数
        ans ++;
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w1;
	cin>>n>>w1;
	int mat[n][2];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<2;j++)
		{
			cin>>mat[i][j];
		}
		
	}
	int w[n],p[n];
	int k=0,m=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<2;j++)
		{
			if(j==0)
			{
				w[m++]=mat[i][j];
			}
			else
			{
				p[k++]=mat[i][j];
			}
		}
		
	}
	ll mat1[n+1][w1+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w1;j++)
		{
			if(i==0 || j==0)
			{
				mat1[i][j]=0;
			}
			else if(j<w[i-1])
			{
				mat1[i][j]=mat1[i-1][j];
			}
			else
			{
				mat1[i][j]=max(mat1[i-1][j],p[i-1]+mat1[i-1][j-w[i-1]]);
			}
		}
	}
	cout<<mat1[n][w1];
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(),greater<int>());//降順
  ll res = a[0];
  int j = 2;
  for(int i = 1;i<n;i++){
    if(j >= n){break;}
    res += a[i];
    j++;
    if(j >= n){break;}
    res += a[i];
    j++;
    if(j >= n){break;}
  }
  
  cout << res;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll gcd(ll a, ll b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

int main() {
    ll N,X;
    cin >> N >> X;
    vector<ll> x(N); 
    REP(i,N) cin >> x[i];
    ll D = abs(X-x[0]);
    REP(i,N){
        ll dist = abs(X-x[i]);
        D = gcd(dist, D);

    }
    cout << D << endl;
    
    return 0;
}

Measured memory_bytes: 1024
S = list(input())
S.pop(len(S) - 1)
count = 0
while True:
    if len(S) % 2 != 0:
        S.pop(len(S) - 1)
        continue
    mid = int(len(S) / 2)
    for i in range(mid):
        if S[i] == S[i + mid]:
            count += 1
    else:
        if count == mid:
            print(len(S))
            break
        else:
            count = 0
            S.pop(len(S) - 1)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

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

vector<vector<int>> q;
int N, M, Q;
long long ans = -1;
vector<int> a;

int dfs(int n, int mi) {
    if (n == N+1) {
        long long sum = 0;
        for (int i = 0; i < q.size(); i++) {
            if (a[q[i][1]] - a[q[i][0]] == q[i][2]) {
                sum += q[i][3];
            }
        }
        // for (int i = 0; i < N; i++) {
        //     cout << a[i] << " ";
        // }
        // cout << endl;
        ans = max(ans, sum);
        return 0;
    }

    for (int i = mi; i <= M; i++) {
        a.push_back(i);
        dfs(n+1, i);
        a.pop_back();
    }
    return 0;
}

int main(void) {
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        vector<int> tmp;
        int a, b, c, d; cin >> a >> b >> c >> d;
        a--;
        b--;
        tmp.push_back(a);
        tmp.push_back(b);
        tmp.push_back(c);
        tmp.push_back(d);
        q.push_back(tmp);
    }

    dfs(1, 1);
    cout << ans << endl;
}


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

int main() {
    int N, D;
    scanf("%d%d", &N, &D);
    vector<vector<int>> P(N, vector<int> (D, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            scanf("%d", &P.at(i).at(j));
        }
    }
    int count = 0;
    for(int i = 0; i < N; i++) {
        for (int j = 1; i + j < N; j++) {
	        float X = 0;
        	for (int k = 0; k < D; k++) {
            	X += pow(P.at(i).at(k) - P.at(i+j).at(k), 2.0);
        	}
        	float S = sqrt(X);
       		float integernal_part = 0;
        	float fractional_part = modf(S, &integernal_part);
        	if (fractional_part == 0) {
            	count++;
        	}
        }
    }
    printf("%d", count);
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
use std::cmp::*;

const INF: usize = 1000_000_000_000;
fn main() {
    input! {
        N: usize,
        M: usize,
        S: usize,
        mut UVAB: [(Usize1,Usize1,usize,u64);M],
        CD:[(usize,u64);N]
    }
    // g[i] = (j, a,b)なら、iからjへ、a円 b時間
    let mut g = vec![vec![]; N];
    for &(u, v, a, b) in UVAB.iter() {
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }
    // 銀貨最大値
    let w = 50 * 49;
    let mut dp = vec![vec![std::u64::MAX; w + 1]; N];
    // 都市0で銀貨S枚持つまでに0分かかる。
    dp[0][min(w, S)] = 0;
    let mut h = std::collections::BinaryHeap::new();
    // 謎。Heapに、逆順を指定したうえでタプルを加えている模様。
    h.push(Reverse((0, 0, min(w, S))));
    // hからpop出来る限り繰り返す。
    while let Some(Reverse((d, v, k))) = h.pop() {
        // heap はdpに加わったばかりの場所。
        // 既に訪れたHeapについて、dp[v][k]のより小さいものが見つかったとしたら、無視。
        // 最初は0,0,Sであり、dp[0][S]=0だから、if式はfalse。
        if d > dp[v][k] {
            continue;
        }
        for &(u, a, b) in g[v].iter() {
            // 移動可能な場所uへの運賃aが、所持金より多い場合、移動不可。
            if a > k {
                continue;
            }
            // そうでなければ移動。
            // 所持金をa減らしてuに到着した場合の時刻がd+bとなるので、
            // dが過去に計算されたdp[u][k-a]を更新できるなら、更新し、
            // hに、検査対象の (d+b,u,k-a)を追加する。
            let next_d = d + b;
            let next_k = k - a;
            if next_d < dp[u][next_k] {
                dp[u][next_k] = next_d;
                for tmp_k in (0..next_k).rev() {
                    if dp[u][tmp_k] > dp[u][next_k] {
                        dp[u][tmp_k] = dp[u][next_k];
                    } else {
                        break;
                    }
                }
                h.push(Reverse((next_d, u, next_k)));
            }
            // 以上を、vから移動可能な路線(u,a,b)のすべてについてチェックする。。
        }
        // 次に換金時間を足す。dは時刻、kは所持金
        let next_d = d + CD[v].1;
        let next_k = min(k + CD[v].0, w);
        if dp[v][next_k] > next_d {
            dp[v][next_k] = next_d;
            for tmp_k in (0..next_k).rev() {
                if dp[v][tmp_k] > dp[v][next_k] {
                    dp[v][tmp_k] = dp[v][next_k];
                } else {
                    break;
                }
            }
            h.push(Reverse((next_d, v, next_k)));
        }
    }

    //println!("dp[0]={:?}", &dp[0][0..10]);
    //println!("dp[1]={:?}", &dp[1][0..10]);
    for v in 1..N {
        println!("{}", dp[v].iter().min().unwrap());
    }
}


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

    // Your code here!
    


int main(){
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            int val=i*j;
            cout<<i<<'x'<<j<<'='<<val<<endl;
        }
        ;
    }
    return 0;
}
    


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
char s[N];
int sum;
int main()
{
    std::ios::sync_with_stdio(false);
    cin >> s;
    for(int i = 0; s[i]; i++) sum += s[i] - '0';
    if(sum % 9) cout << "No" << endl;
    else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3796
#!/usr/bin/perl
use POSIX qw(floor);

my ($X,$Y) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $k2 = $Y - 2 * $X;

if( $k2 < 0 or $k2 % 2 == 1 ){
  print "No\n";
  exit(0);
}
my $k = $k2 / 2;

if( $k < 0 ){
  print "No\n";
  exit(0);
}

my $t = $X - $k;
if( $t < 0 ){
  print "No\n";
  exit(0);
}

print "Yes\n";




Measured memory_bytes: 6612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
#define sz(s) (int)(s.size())

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e6+5;
const  double EPS = 1e-14;
const int MOD = 1e9+7;

ll GCD(ll a,ll b){return (a)?GCD(b%a,a):b;}
ll LCM(ll a, ll b){return a*b/GCD(a,b);}
ll fastpow(ll b, ll p){if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
   //  freopen("in.txt", "r", stdin);
#endif
     int r,c,n,ans=0,cnt=0;
     cin>>r>>c>>n;
     int mx=max(r,c);
     for(int i=1;;i++)
     {
         ans=mx*i;
         if(ans>=n){
            cnt=i;
            break;
         }
     }
     cout<<cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<bool>	vb;
ll mod = 1e9 + 7;



int main(){  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    char a;
    cin >> a;
    if(a >= 'a' && a <= 'z') cout << 'a';
    else cout << 'A';
    
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string X, string Y) {
  if (X == Y) {
    cout << "=" << endl;
    return;
  }

  cout << (X > Y ? ">" : "<") << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string Y;
  string X;
  cin >> X;
  cin >> Y;
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 768
kn = input('').split(' ')
k = int(kn[0])
n = int(kn[1])
a = input('').split(' ')

d = []
d.append(k - int(a[n-1])+int(a[0]))
xd = d[0]
for i in range(1,n):
  d.append(int(a[i]) - int(a[i-1]))
  if xd < d[i]:
    xd = d[i]
print(k - xd)


Measured memory_bytes: 19052
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

const int MOD = 998244353;

inline int add(int x, int y){
	int res = x + y;	
	while(res >= MOD)res-=MOD;
	return res;
}

inline int mul(int x,int y){
	return (1LL * x * y) % MOD;
}

int modpow(int x,int p){
	int res = 1;
	while(p){
		if(p&1)gmul(res,x);
		gmul(x,x);
		p/=2;
	}
	return res;
}

inline int invert(int x){
	return modpow(x,MOD - 2);
}

const int N = 2e5 + 5;

int fac[N], inv[N];

void init(int n){
	fac[0] = inv[0] = 1;
	for(int i = 1;i < n; ++i){
		fac[i] = mul(fac[i-1], i);	
		inv[i] = invert(fac[i]); 
	}
}

int comb(int n,int k){
	return mul(fac[n],mul(inv[k], inv[n-k]));	
}


int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	init(N);
	int n,m,k;
	cin >> n >> m >> k;
	int ans = 0;
	rep(i,0,k+1){
		int tmp = mul(modpow(m-1,n-i-1),comb(n-1,i));	
		gmul(tmp,m);
		gadd(ans,tmp);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5216
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,lc[10000005],rc[10000005],s1[10000005],s2[10000005],rt[100005],dis[100005],dep[100005],fa[100005][19],ans,cnt,t1,t2;
vector<pair<long long,pair<long long,long long> > > bi[100005];
vector<pair<long long,long long> > q[100005];
long long sgn(long long x)
{
	if(x>0)return 1;
	if(x<0)return -1;
	if(x==0)return 0;
}
long long nwnd(long long x)
{
	cnt++;lc[cnt]=lc[x];rc[cnt]=rc[x];s1[cnt]=s1[x];s2[cnt]=s2[x];
	return cnt;
}
void update(long long &x,long long l,long long r,long long c,long long d)
{
	x=nwnd(x);
	s1[x]++;
	s2[x]+=d;
	if(l==r){
		return;
	}int mid=(l+r)/2;
	if(c<=mid)update(lc[x],l,mid,c,d);else update(rc[x],mid+1,r,c,d);
}
void query(long long x,long long l,long long r,long long c)
{
	if(!x)return;
	if(l==r){
		t1+=s1[x];t2+=s2[x];
		return;
	}int mid=(l+r)/2;
	if(c<=mid)query(lc[x],l,mid,c);else query(rc[x],mid+1,r,c);
}
void dfs1(long long x,long long p)
{
	fa[x][0]=p;
	ff(bi[x],it)if(it->first!=p){
		dep[it->first]=dep[x]+1;
		dis[it->first]=dis[x]+it->second.second;
		rt[it->first]=rt[x];
		update(rt[it->first],1,n-1,it->second.first,it->second.second);
		dfs1(it->first,x);
	}
}
long long lca(long long x,long long y)
{
	if(dep[x]<dep[y])swap(x,y);
	long long t=(dep[x]-dep[y]),i;
	fd0g(i,18)if((t>>i)&1){
		x=fa[x][i];
	}if(x==y)return x;
	fd0g(i,18)if(fa[x][i]!=fa[y][i]){
		x=fa[x][i];y=fa[y][i];
	}return fa[x][0];
}
int main()
{
	scanf("%lld%lld",&n,&m);
	fz1(i,n-1){
		long long x,y,c,d;
		scanf("%lld%lld%lld%lld",&x,&y,&c,&d);
		bi[x].push_back(make_pair(y,make_pair(c,d)));
		bi[y].push_back(make_pair(x,make_pair(c,d))); 
	}
	dep[1]=1;dfs1(1,0);
	fz1(j,18)fz1(i,n)fa[i][j]=fa[fa[i][j-1]][j-1];
	fz1(i,m){
		long long x,y,z,ans,c,d;
		scanf("%lld%lld%lld%lld",&c,&d,&x,&y);
		z=lca(x,y);ans=dis[x]+dis[y]-2*dis[z];
		t1=0;t2=0;query(rt[x],1,n-1,c);ans-=t2;ans+=t1*d;
		t1=0;t2=0;query(rt[y],1,n-1,c);ans-=t2;ans+=t1*d;
		t1=0;t2=0;query(rt[z],1,n-1,c);ans+=2*t2;ans-=2*t1*d;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 94976
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll check[100005],shiro[100005],kuro[100005];
ll solv(ll v,vvl &graph) {
	check[v] = 1;
	ll shi = 1, ku = 1;
	for (ll nextv : graph[v]) {
		if (check[nextv] == 1)continue;
		solv(nextv, graph);
		shi *= (shiro[nextv] + kuro[nextv]) % MOD;
		shi %= MOD;
		ku *= shiro[nextv] % MOD;
		ku %= MOD;
	}
	shiro[v] = shi; kuro[v] = ku;
	return (shi + ku) % MOD;
}


int main() {
	ll n;
	cin >> n;
	vvl graph(n,vl(0));
	rep(i, 0, n-1) {
		ll x, y;
		cin >> x >> y;
		graph[x - 1].push_back(y - 1);
		graph[y - 1].push_back(x - 1);
	}
	printf("%lld\n", solv(0, graph));
}

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

using namespace std;

int a, b;

int main()
{
    cin >> a >> b;
    if(a <= 0 && b >= 0)
    {
        cout << "Zero\n";
        return 0;
    }
    if(max(min(0, b) - a + 1, 0) & 1)
        cout << "Negative\n";
    else
        cout << "Positive\n";
    return 0;
}


Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long
#define sz(x) (int)x.size()
const int mx = 1000 * 100 + 5;
bool r[mx];
int siz[mx];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n, m, a, b, ans = 0;
	r[1] = 1;
	cin >> n >> m;
	fill(siz , siz + n + 1 , 1);
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		if(r[a])
			r[b] = 1;
		if(siz[a] == 1)
			r[a] = 0;
		siz[a]--;
		siz[b]++;
	}
	for(int i = 1; i <= n; i++)
		if(r[i])
			ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1152
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		String result = "Impossible";
		if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) result = "Possible";
		
		
		// 出力
		System.out.println(result);
	}

}




Measured memory_bytes: 21844
#include<stdio.h>
int main() {
    long long a[333], b[333], c[333], d[333], t, i,r,p,cb,cd,ca,flag;
    scanf("%lld", &t);
    for (i = 0; i < t; i++) 
        scanf("%lld%lld%lld%lld", &a[i], &b[i], &c[i], &d[i]);
    for (i = 0; i < t; i++) {
        flag = 1;
        cb = b[i];
        cd = d[i];
        if (cb > cd) {
            p = cb;
            cb = cd;
            cd = p;
        }
        p = cb;
        while (cd%p != 0) {
            cb = cd % p;
            cd = p;
            p = cb;
        }
        ca = a[i] % b[i];
        ca=b[i]-p+(ca%p);
        if (a[i] < b[i])
            flag = 0;
        if (d[i] < b[i])
            flag = 0;
        if (ca > c[i])
            flag = 0;
        if (flag == 1)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b;
	c=a*b;
	if((a==1)||(b==1))
	 cout<<"1\n";
	 else
	 {
	if(c%2==0)
	cout<<c/2<<"\n";
	else
	cout<<c/2+1<<"\n";
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            chmax(ans, abs(A[i] - A[j]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};

vector<mint> vec;
vector<mint> sum, sum2;

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

	if(K > N){
		cout << 1 << endl;
		return 0;
	}

	vec.resize(N+1);
	for(ll i = 0; i < N+1; i++){
		vec[i] = i; 
	}
	
	mint front_sum = 0;
	rep(i,K){
		front_sum = front_sum + vec[i];
	}
	mint back_sum = 0;
	rep(i,K){
		back_sum = back_sum + vec[N-i];
	}
	mint total = back_sum - front_sum + 1;

	for(int i = K; i <= N; i++){
		front_sum = front_sum + vec[i];
		back_sum = back_sum + vec[N-i];
		total = total + (back_sum - front_sum + 1);
	}
	cout << total << endl;

}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << en; cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << en; cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
ll n;
ll dp[200003];
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll x=0, m=0, y=0, d=1, k=mod;
		cin >> n;
		ll a[n];
		memset( dp, -1, sizeof(dp) );
		for(int i = 0; i < n; i++)
			cin >> a[i];

		dp[n - 1] = 0;
		dp[n - 2] = abs(a[n - 1] - a[n - 2]);

		for(int i = n-3; i >= 0; i--)
			dp[i] = min(abs(a[i + 1] - a[i]) + dp[i + 1], abs(a[i + 2] - a[i]) + dp[i + 2]);
		
		cout << dp[0] << endl;
	}
}


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int a,b; cin >> a >> b;
    cout << (abs(a-b)>1 ? 2*max(a,b)-1 : a+b) << endl;
	return 0;
}


Measured memory_bytes: 256
n, m, s, t = map(int, input().split())
s, t = s-1, t-1
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u, v = u-1, v-1
    edges[u].append((v, a, b))
    edges[v].append((u, a, b))

from heapq import heappop, heappush
inf = 10 ** 15
cost_a = [inf] * n
cost_a[s] = 0
que = [(cost_a[s], s)]
while que:
    cost, cur = heappop(que)
    if cost > cost_a[cur]:
        continue
    for to, a, _ in edges[cur]:
        if cost_a[to] > cost + a:
            cost_a[to] = cost + a
            heappush(que, (cost_a[to], to))

cost_b = [inf] * n
cost_b[t] = 0
que = [(cost_b[t], t)]
while que:
    cost, cur = heappop(que)
    if cost > cost_b[cur]:
        continue
    for to, _, b in edges[cur]:
        if cost_b[to] > cost + b:
            cost_b[to] = cost + b
            heappush(que, (cost_b[to], to))

ans = [10 ** 15]
for i in range(n-1, -1, -1):
    ans.append(min(ans[-1], cost_a[i] + cost_b[i]))
for i in range(1, n+1):
    print(10 ** 15 - ans[-i])

Measured memory_bytes: 61248
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;


int main(){
	int h,w,k;
	cin >> h >> w >> k;
	vector<vector<char>> c(h,vector<char>(w));
	REP(i,h) REP(j,w) cin >> c[i][j];
	
	int ans=0;
	for(int bit=0; bit<(1<<(h+w)); ++bit){
		int a=0;
		REP(i,c.size()){
			if(bit & (1<<i)) continue;
			REP(j,c[i].size()){
				if(bit & (1<<(j+h))) continue;
				if(c[i][j]=='#') a++;
			}
		}
		
		if(a==k) ans++;
	}
	
	cout << ans <<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define maxN 100005
#define ll long long
#define inf 1000000000000000000LL

using namespace std;

//FILE *fin = freopen("d.in", "r", stdin);

int n, v[maxN * 3];

priority_queue < int > q;
ll prefSum[maxN * 2], suffSum[maxN * 2]; /// pref --> last 2 * N, suff --> first 2 * N

ll ans;

void precompSuff()
{
    ll sum = 0;
    int j = -1;
    while (!q.empty())
        q.pop();
    for (int i = 3 * n; i >= 1; -- i)
    {
        sum += 1LL * v[i];
        q.push(v[i]);
        if (i <= 2 * n + 1)
        {
            if (i < 2 * n + 1)
            {
                sum -= 1LL * q.top();
                q.pop();
            }
            suffSum[++ j] = sum;
        }
    }
}

int main()
{
    scanf("%d", &n);
    ll sum = 0;
    for (int i = 1; i <= 3 * n; ++ i)
    {
        scanf("%d", &v[i]);
        sum += 1LL * v[i];
        q.push(-v[i]);
        if (i >= n)
        {
            if (i > n)
            {
                sum += 1LL * q.top();
                q.pop();
            }
            prefSum[i - n] = sum;
        }
    }

    precompSuff();
    ans = -inf;
    for (int i = n; i <= 2 * n; ++ i)
        ans = max(ans, prefSum[i - n] - suffSum[2 * n - i]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5112
package main

import (
	"fmt"
)

func main() {
	var (
		N, M int
	)

	fmt.Scanf("%d %d\n", &N, &M)
	diffs := make([]int, 0, M-1)
	Xs := make([]int, 0, M)
	var prevX, X int

	for i := 0; i < M; i++ {
		fmt.Scanf("%d", &X)
		Xs = append(Xs, X)
	}
	Xs = MergeSort(Xs)
	prevX = Xs[0]
	for _, X := range Xs[1:] {
		diffs = append(diffs, abs(X-prevX))
		prevX = X
	}

	var res int
	diffs = MergeSort(diffs)
	for i := 0; i < M-N; i++ {
		res += diffs[i]
	}

	fmt.Println(res)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func MergeSort(slice []int) []int {

	if len(slice) < 2 {
		return slice
	}
	mid := (len(slice)) / 2
	return Merge(MergeSort(slice[:mid]), MergeSort(slice[mid:]))
}

func Merge(left, right []int) []int {

	size, i, j := len(left)+len(right), 0, 0
	slice := make([]int, size, size)

	for k := 0; k < size; k++ {
		if i > len(left)-1 && j <= len(right)-1 {
			slice[k] = right[j]
			j++
		} else if j > len(right)-1 && i <= len(left)-1 {
			slice[k] = left[i]
			i++
		} else if left[i] < right[j] {
			slice[k] = left[i]
			i++
		} else {
			slice[k] = right[j]
			j++
		}
	}
	return slice
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
double PI=acos(-1.0);
signed main(){
    long double a,b;cin>>a>>b;
    long double c=a*b;
    ll ans=c;
    cout<<ans<<endl;
}

Measured memory_bytes: 3788
#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<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#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++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll blue = 0;

    if(a == 0){
        blue = 0;
    }
    else if(b == 0 || a > n){
        blue = n;
    }
    else if(a + b >= n){
        blue = a;
    }
    else{

        ll times = n / (a+b);
        ll amari = n % (a+b);

        blue += a * times;

        if(amari < a) blue += amari;
        else blue += a;
    }

    cout << blue << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stopBBB
        return 0;
}

Measured memory_bytes: 256