akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int r,ord[100010],low[100010];
void cdfs(int s,int *ta,int *to,int *nt,int *p){//printf("s%d %d\n",s,r);
  int i;
  ord[s]=low[s]=r++;
  for(i=ta[s];i+1;i=nt[i]){
    if(p[to[i]]==-1){
      p[to[i]]=s;
      cdfs(to[i],ta,to,nt,p);
      low[s]=MIN(low[s],low[to[i]]);
    }
    else if(to[i]-p[s])low[s]=MIN(low[s],ord[to[i]]);
  }
}
int brig(int v,int e,int *a,int *b,int *c,int *d){
  int ta[100010],to[100010],nt[100010],p[100010],ans=0,co=0,i,j,f[100010]={0};
  for(i=0;i<v;i++)ta[i]=p[i]=-1;
  for(p[0]=i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[b[ta[a[i]]=i]]=i+e;
  }
  for(i=r=0;i<v;i++){
    if(r<v)cdfs(i,ta,to,nt,p);
  }
  for(i=1;i<v;i++){//橋を配列に格納していく
    if(ord[p[i]]<low[i]){
      c[co  ]=p[i];
      d[co++]=  i ;
    }
  }
  return co;
}
int main(){
  int n,m,i,a[110],b[110],c[110],d[110];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]--;
  }
  printf("%d\n",brig(n,m,a,b,c,d));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <string.h>
using namespace std;
int main()
{
    char a[60];
    int n, num[30] = {};
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tmp[30] = {};
        cin >> a;
        for (int j = 0; j < strlen(a); j++)
        {
            if (i == 0)
                num[a[j] - 'a']++;
            else
                tmp[a[j] - 'a']++;
        }
        if (i > 0)
        {
            for (int j = 0; j < 26; j++)
            {
                if (tmp[j] < num[j])
                    num[j] = tmp[j];
            }
        }
    }
    string ans = {};
    for (int i = 0; i < 26; i++)
    {
        for (int j = 0; j < num[i]; j++)
        {
            ans += 'a' + i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define rhl (998244353)
#define N (1000005)

using namespace std;

int fac[N],ifac[N],inv[N],n,m,ans;

il int C(RG int n,RG int m){
  return n<m?0:1LL*fac[n]*ifac[m]%rhl*ifac[n-m]%rhl;
}

int main(){
  cin>>n>>m,fac[0]=ifac[0]=1;
  for (RG int i=1;i<=n+m;++i){
    inv[i]=i==1?1:1LL*(rhl-rhl/i)*inv[rhl%i]%rhl;
    fac[i]=1LL*fac[i-1]*i%rhl,ifac[i]=1LL*ifac[i-1]*inv[i]%rhl;
  }
  if (n<m) swap(n,m);
  for (RG int i=1;i<=m;++i)
    ans=(1LL*C(2*i,i)*C(n+m-2*i,n-i)+ans)%rhl;
  ans=1LL*ans*inv[2]%rhl*ifac[n+m]%rhl*fac[n]%rhl*fac[m]%rhl;
  cout<<(ans+n)%rhl; return 0;
}


Measured memory_bytes: 11904
while True :
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1 :
        break

    if m == -1 or f == -1 :
        print("F")
    elif (m + f) >= 80 :
        print("A")
    elif (m + f) >= 65 :
        print("B")
    elif (m + f) >= 50 :
        print("C")
    elif (m + f) >= 30 and r >= 50 :
        print("C")
    elif (m + f) >= 30 :
        print("D")
    else :
        print("F")
    


Measured memory_bytes: 5596
N = int(input())
A = list(map(int,input().split()))
B = [0 for i in range(N+1)]
S = sum(A)
B[0]=1
flag=1
if A[0]>1 :
    flag=0
if A[0]>0 and N>0:
    flag=0

for i in range(N):
    if flag==0:
        break

    S = S-A[i]

    if 2*(B[i]-A[i])<A[i+1]:
        flag = 0

    B[i+1]=min(2*(B[i]-A[i]),S)

if flag==0:
    print(-1)
else:
    res = sum(B)
    print(res)

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

int main()
{
    int n;
    cin >> n;
    vector<int> fib(n + 1, -1);
    fib[0] = 1;
    fib[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
    cout << fib[n] << endl;
}



Measured memory_bytes: 3100
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 15:13:42
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans = 0;
    for (int i = 1; i <= n-1; i++) {
        int left[256], right[256];
        for (char c = 'a'; c <= 'z'; c++)
            left[c] = right[c] = 0;

        //左からカウント
        for (int j = 0; j < i; j++) left[s[j]]++;
        //右からカウント
        for (int j = n-1; j > i-1; j--) right[s[j]]++;

        int cnt = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            if (left[c] > 0 && right[c] > 0) cnt++;
        }
        if (ans < cnt) ans = cnt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String serch =  br.readLine().toUpperCase();//????????????????????????

   int serchcount = 0;//?????????????????????
   while(true){

	  String original =  br.readLine();
	  if( original.equals("END_OF_TEXT") ) break;


     String[] cut =  original.toUpperCase().split(" ");//??§????????????????????????????????????


	 for(int i = 0 ;i < cut.length;i++){

		 if( cut[i].equals(serch) )  serchcount++;

	 }

   }


   System.out.println(serchcount);
  }
}

Measured memory_bytes: 24196
N = int(input())
p = list(map(int, input().split()))

cnt = 0

for i in range(len(p)):
    if p[i] == i+1:
        if p[i] == N:
            p[i-1], p[i] = p[i], p[i-1]
        else:
            p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
    
print(cnt)

Measured memory_bytes: 13880
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;
#define Vi vector<int>
#define ll long long
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i=0;i<n;++i)
int main()
{	
  int n,m,k;
  cin>>n>>m>>k;
  int u=0;
  for(int i=0;i<n;i++){
  int a,b;
    cin>>a>>b;
    if(a>=m&&b>=k){u++;}
  }
  cout<<u<<endl;
return 0;
}


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

#define MOD 1000000007

long long mod_pow(long long x, long long n) {
  if (n == 0)
    return 1;
  return n % 2 == 1 ? mod_pow(x * x % MOD, n / 2) * x % MOD
                    : mod_pow(x * x % MOD, n / 2);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> cases(K + 1, 1);
  for (int X = K; X >= 1; --X) {
    cases[X] = mod_pow(K / X, N);
    for (int aX = 2 * X; aX <= K; aX += X)
      cases[X] = (cases[X] + MOD - cases[aX]) % MOD;
  }
  long long ans = 0;
  for (int i = 1; i <= K; ++i)
    ans = (ans + (i * cases[i] % MOD)) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 4004
#include <iostream>
#include <cassert>
#include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

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

  ll S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q;
  cin >> q;

  ll T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }


  int count = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (S[j] == T[i]) {
        count++;
        break;
      }
    }
  }

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <iomanip>
using namespace std;
typedef long long ll;

int main()
{
  ll N,M,mi=0,ma=100000000;
  cin>>N>>M;
  vector<ll> L(M),R(M);
  for(int i=0;i<M;i++){
    cin>>L[i]>>R[i];
    mi=max(L[i],mi);
    ma=min(R[i],ma);
  }
  cout<<max(0ll,ma-mi+1)<<endl;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, M;
struct edge
{
    int from, to, cost;
};
vector<edge> es;
int d[1010];
bool negative[1010];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        es.pb({a, b, -c});
    }
    fill(d, d + N + 1, INFL);
    d[1] = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = 0; j < M; j++){
            edge e = es[j];
            if(d[e.from] != INFL && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    int ans = d[N];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            edge e = es[j];
            if(d[e.from] == INFL)continue;
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.from]){
                negative[e.to] = true;
            }
        }
    }
    if(negative[N]){
        printf("inf\n");
    }
    else{
        printf("%lld\n", -ans);
    }


    return 0;
}
/*


*/


Measured memory_bytes: 384
object Main{
	def main(args:Array[String]){
		val n = new java.util.Scanner(System.in).nextInt
		val a = Array.fill(n + 1,4,4,4)(0L)
		val A = 0
		val C = 1
		val G = 2
		val T = 3
		val mod = 1000000007
		a(0)(T)(T)(T) = 1
		for(i <- 1 to n) {
			for(j <- 0 to 3) {
				for(k <- 0 to 3) {
					for(l <- 0 to 3) {
						for(m <- 0 to 3) {
							if(!(k == A && l == G && m == C ||
									k == G && l == A && m == C ||
									k == A && l == C && m == G ||

									j == A && k == G && m == C ||
									j == A && l == G && m == C
									)) {
								a(i)(k)(l)(m) = (a(i)(k)(l)(m) + a(i - 1)(j)(k)(l)) % mod
							}
						}
					}
				}
			}
		}
		println(a(n).flatten.flatten.sum % mod)
	}
}


Measured memory_bytes: 29408
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

int main() {
	rep(i,0,4000) {
			int x, y;
			cin >> x >> y;

			if (x == 0 and y == 0) {
					return 0;
			}
			
			if (x > y) {
					int tmp = x;
					x = y;
					y = tmp;
			}

			cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

	ll ans = 1e12;
	ll temp;
	ll sa, sb, sc;
	for (ll h = 1; h <= H; h++) {
		sa = h * W;
		sb = (H - h) * (W / 2);
		sc = H * W - sa - sb;
		temp = max(max(abs(sa - sb), abs(sb - sc)), abs(sc - sa));
		ans = min(ans, temp);

		sb = ((H - h) / 2) * W;
		sc = H * W - sa - sb;
		temp = max(max(abs(sa - sb), abs(sb - sc)), abs(sc - sa));
		ans = min(ans, temp);
	}

	for (ll w = 1; w <= W; w++) {
		sa = H * w;
		sb = H * ((W - w) / 2); 
		sc = H * W - sa - sb;
		temp = max(max(abs(sa - sb), abs(sb - sc)), abs(sc - sa));
		ans = min(ans, temp);

		sb = (H /2)* (W - w);
		sc = H * W - sa - sb;
		temp = max(max(abs(sa - sb), abs(sb - sc)), abs(sc - sa));
		ans = min(ans, temp);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

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

d = {}

for i in range(N):
    d[i+1] = 0

for a in A:
    d[a] += 1

for k, v in d.items():
    print(v)


Measured memory_bytes: 38920
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s[] = { "Sunny",
				   "Cloudy",
				   "Rainy" };
	string st;
	cin>>st;
	for(int i=0;i<3;i++)
	{
		if(st==s[i])
		{
			cout<<s[(i+1)%3]<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a * b - (a * 1 + b * 1 - 1));
    return 0;
}

Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())

path_matrix = []

# 無向グラフの作成
for n in range(N):
    path_matrix.append([0] * N)

for m in range(M):
    paths = [int(i) - 1 for i in input().split()]
    path_matrix[paths[0]][paths[1]] = 1
    path_matrix[paths[1]][paths[0]] = 1

list_per = list(itertools.permutations(range(N)))
ans = 0

for i in list_per:
    if i[0] != 0:
        break
    cnt = 1
    for index in range(N - 1):
        cnt *= path_matrix[i[index]][i[index + 1]]
    ans += cnt
    
print(ans)


Measured memory_bytes: 8052
#https://kyopro-friends.hatenablog.com/entry/2019/01/12/231000

N = gets.to_i
P = [0.0] + gets.split.map(&:to_f)

dp = Array.new(N+1){Array.new(N+1, 0.0)}
dp[0][0] = 1
1.upto(N) do |i|
  0.upto(N < i+1 ? N : i+1) do |j|
    dp[i][j] = dp[i-1][j-1] * P[i] + dp[i-1][j] * (1 - P[i])
  end 
end

ans = 0.0
(N/2 + 1).upto(N) do |i|
  ans += dp[N][i]
end
p ans

Measured memory_bytes: 184188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vi v(n+m);
        rep(i, n+m) cin >> v[i];
        v.pb(0);
        sort(all(v));
        int ans = 0;
        rep(i, n+m) ans = max(ans, v[i+1]-v[i]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1312
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
//
	int a, b;
	cin >> a >> b;
	cout << abs(a - b) << endl;
	return 0;
}


Measured memory_bytes: 3212
# coding: utf-8


def calc(rate, diff, v, counter, lst):
    if counter >= 2010:
        return lst
    next = rate * v - diff
    lst.append(next)
    return calc(rate, diff, next, counter + 1, lst)


r, d, x_2000 = [int(x) for x in input().rstrip().split(" ")]
result = calc(r, d, x_2000, 2000, [])
print("\n".join([str(x) for x in result]))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

#define ll long long

int main()
{
    ll N, K;
    scanf("%lld %lld", &N, &K);

    vector<bool> sunuke(N, false);
    for (ll i = 0; i < K; i++)
    {
        ll d;
        scanf("%lld", &d);
        for (ll j = 0; j < d; j++)
        {
            ll a;
            scanf("%lld", &a);
            sunuke[a - 1] = true;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        if (!sunuke[i])
        {
            ans++;
        }
    }
    printf("%lld\n", ans);
}


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

typedef long long ll;
typedef long double ld;

void solve(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b > a){
        cout << "No\n";
        return;
    }
    if(b > d){
        cout << "No\n";
        return;
    }
    ll nzd = __gcd(b, d);
    ll x = a%nzd;
    ll k = c-b+1;
    if(k >= 0){
        cout << "Yes\n";
        return;
    }
    if(abs(k) >= nzd){
        cout << "No\n";
        return;
    }
    if(nzd-x <= -k) cout << "No\n";
    else cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int N, m=0, ans=0;
  cin >> N;
  REP(i,N) {
    int p;
    cin >> p;
    ans += p;
    chmax(m,p);
  }
  ans -= m/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pushb(x) push_back(x)
#define popb() pop_back()
#define makep make_pair
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);
template<typename T> ll gcd(T a,T b);
template<typename T> ll lcm(T a,T b);
int main(){
    int n,k;cin>>n>>k;
    int l=(n-1)*(n-2)/2-k;
    if((n-1)*(n-2)<2*k){
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<n-1+l<<endl;
    rep(i,n-1){
        cout<<'1'<<' '<<i+2<<endl;
    }
    rep(i,2,n){
        rep(j,i+1,n+1){
            if(l==0){
                break;
            }
            cout<<i<<' '<<j<<endl;
            l--;
        }
        if(l==0)break;
    }


    return 0;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << ' ';
    }
    return s;
}
template<typename T> ll gcd(T a,T b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
template<typename T> ll lcm(T a,T b){
    return a*b/gcd(a,b);
}

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

int main() {
  string s;
  cin >> s;
  string ans;
  for (char c : s) {
    if (c == 'B') {
      if (!ans.empty())
        ans.pop_back();
    } else {
      ans.push_back(c);
    }
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int Q=1505;
char a[Q][Q];
int f[Q][Q],l[Q][Q],r[Q][Q];
int n;
int Ok(int x,int y)
{return (x<=n)&(y<=n)&(a[x][y]!='#');}
int main()
{
    ll als=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int i=n;i;--i)
        for(int j=n;j;--j){
            if(!Ok(i,j)){
                l[j][i]=n+1,r[j][i]=-1;
                continue;
            }
            int D=Ok(i+1,j),R=Ok(i,j+1);
            int val=a[i][j]-'0';
            if(!(D|R)){
                f[j][i]=val;
                l[j][i]=r[j][i]=j;
                for(int k=i+1;k<=n;k++)
                    l[j][k]=n+1,r[j][k]=0;
            }
            else if(D&R){
                int tmp=f[j][i+1]+f[j+1][i]+val;
                for(int k=i+1,mxr=0,lv,rv;k<=n;k++){
                    lv=l[j+1][k],rv=r[j+1][k];
                    if(lv>mxr&&lv<=r[j][k])tmp-=f[lv][k];
                    mxr=max(mxr,r[j][k]);
                    l[j][k]=min(l[j][k],lv);
                    r[j][k]=max(r[j][k],rv);
                }
                f[j][i]=tmp;
                l[j][i]=j;
                r[j][i]=r[j+1][i];
            }
            else if(D){
                f[j][i]=f[j][i+1]+val;
                l[j][i]=r[j][i]=j;
            }
            else{
                f[j][i]=f[j+1][i]+val;
                for(int k=i;k<=n;k++)
                    l[j][k]=l[j+1][k],r[j][k]=r[j+1][k];
                l[j][i]=j;
            }
            als+=1LL*val*(f[j][i]-val);
        }
    printf("%lld\n",als);
    return 0;
}

Measured memory_bytes: 29056
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

d = ii()
if d == 25:
    print("Christmas")
elif d == 24:
    print("Christmas Eve")
elif d == 23:
    print("Christmas Eve Eve")
elif d == 22:
    print("Christmas Eve Eve Eve")

Measured memory_bytes: 9384
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
using namespace std;

int main(void)
{
	int N, T;
	cin >> N >> T;

	int minc, c, t;
	minc = INT_MAX;
	for(int i=0; i<N; i++){
		cin >> c >> t;

		if(t <= T)
			minc = min(minc, c);
	}

	if(minc == INT_MAX)
		cout << "TLE" << endl;
	else
		cout << minc << endl;

	return 0;
}


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

ans = []
def dfs(x):
    if '3' in x and '5' in x and '7' in x and int(x) <= n:ans.append(x)
    if len(x) > 0 and int(x) > n:return
    dfs(x+'3')
    dfs(x+'5')
    dfs(x+'7')
        

    
    
    
    
    
dfs('')
print(len(ans))


Measured memory_bytes: 4804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl;
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	string s;
	cin>>s;
	int l=s.size();
	int ans=0;
	for(int i=0;i<l/2;i++)
	{
		if(s[i]!=s[l-i-1])
		ans++;
	}
	cout<<ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <iomanip>
#include <time.h>
using namespace std;

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


int main()
{
    int H,W,M;
    cin >> H >> W >> M;
    
    map<int,int> height,width;
    vector<P> bombs(M);
    for(int i=0; i<M; i++){
        int h,w;
        cin >> h >> w;
        bombs[i]=(P(h,w));
        height[h]++;
        width[w]++;
    }

    int h_max=0,w_max=0;
    vector<int> hargs,wargs;
    for(auto& x:height){
        if(x.second>h_max){
            hargs.clear();
            h_max=x.second;
            hargs.push_back(x.first);
        }else if(x.second==h_max){
            hargs.push_back(x.first);
        }
    }
    for(auto& x:width){
        if(x.second>w_max){
            wargs.clear();
            w_max=x.second;
            wargs.push_back(x.first);
        }else if(x.second==w_max){
            wargs.push_back(x.first);
        }
    }

    sort(hargs.begin(),hargs.end());
    sort(wargs.begin(),wargs.end());

    int ans=w_max+h_max;
    int cnt=0;
    for(int i=0; i<M; i++){
        int h=bombs[i].first,w=bombs[i].second;
        if(binary_search(hargs.begin(),hargs.end(),h) && binary_search(wargs.begin(),wargs.end(),w)) cnt++;
    }
    
    if(cnt>=(hargs.size()*wargs.size())) ans--;

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 37740
trait BinarySearch<T> {
	#[allow(patterns_in_fns_without_body)]
	fn binary_search_by<F>(&self, mut f: F) -> Result<T, T>
	where
		F: FnMut(&T) -> std::cmp::Ordering;
}

impl<
		T: Sized
			+ PartialOrd
			+ std::ops::Add<Output = T>
			+ std::ops::Sub<Output = T>
			+ std::ops::Div<Output = T>
			+ Copy
			+ Clone
			+ std::fmt::Display
			+ From<u8>,
	> BinarySearch<T> for std::ops::Range<T>
{
	fn binary_search_by<F>(&self, mut f: F) -> Result<T, T>
	where
		F: FnMut(&T) -> std::cmp::Ordering,
	{
		use std::cmp::Ordering::*;
		if self.end <= self.start {
			return Err(self.start);
		}
		let mut base = self.start;
		let mut size = self.end - base;
		loop {
			let half = size / T::from(2);
			let mid = base + half;
			let cmp = f(&mid);
			match cmp {
				Less => base = mid,
				Equal => return Ok(mid),
				_ => {}
			}
			if size <= half || T::from(0) == half {
				return Err(base + T::from((cmp == Less) as u8));
			}
			size = size - half;
		}
	}
}

fn main() {
	let n: usize;
	let k: i64;
	let a: Vec<i64>;

	text_io::scan!("{} {}", n, k);
	a = (0..n).map(|_| text_io::read!()).collect();

	use std::cmp::Ordering::*;
	let ans = (0..1_000_000_001)
		.binary_search_by(|m| {
			if 1 == *m {
				return Equal;
			};
			if k >= a.iter().map(|a| (a + m - 1) / m - 1).sum() {
				Greater
			} else {
				Less
			}
		})
		.and_then(|q: i64| -> Result<i64, i64> { Err(q) })
		.err();
	println!("{}", ans.unwrap());
}


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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    char s;
    cin>>s;
    if(s>='A' && s<='Z')
        cout<<"A"<<nl;
    else cout<<"a"<<nl;

    return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    int a=0,b=0,c=0;
    bool ok = true;
    rep(i,s.size()){
        if(s[i] == 'a') a++;
        if(s[i] == 'b') b++;
        if(s[i] == 'c') c++;
    }
    int k = min(a,min(b,c));
    if(a-k > 1 || b-k > 1 || c-k > 1) ok = false;
    if(ok) cout << "YES" <<endl;
    else cout << "NO" <<endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main(){
  int n,q,ans=0,i,j,l,r;
  scanf("%d%d",&n,&q);
  int t[n];
  char s[n];
  scanf("%s",s);
  t[0]=0;
  for(i=1;i<n;i++){
    if(s[i]=='C'&&s[i-1]=='A')t[i]=t[i-1]+1;
    else t[i]=t[i-1];
  }
  for(i=0;i<q;i++){
    scanf("%d%d",&l,&r);
    printf("%d\n",t[r-1]-t[l-1]);
    ans=0;
  }
}

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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int x, y;

	scanf("%d %d", &x, &y);

	bool ans = false;

	for (int c = 0; c <= 100; c++){
		for (int t = 0; t <= 100; t++){
			if (2*c + 4*t == y && c + t == x)
				ans = true;
		}
	}

	printf("%s\n", ans ? "Yes" : "No");

	return 0;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  fastIO;
  int a, b;
  cin >> a >> b;
  if(a <= 5) cout << 0;
  else if(a > 12) cout << b;
  else cout << b/2;
  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    for i in range(1, 10):
        a, b = i, N//i
        if N % i != 0:
            continue
        if b >= 10:
            continue
        print('Yes')
        return
    print('No')
    

main()



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

void dfs(int x, vector<int> &now, int n, int m, const vector<int>& a,
         const vector<int> &b, const vector<int>& c, const vector<int> &d,
         int* mx) {
  if (x >= n) {
    int q = a.size(), s = 0;
    for (int i = 0; i < q; i++)
      if (now[b[i]] - now[a[i]] == c[i])
        s += d[i];
    if (s > *mx) *mx = s;
  }
  else {
    int last = 1;
    if (!now.empty()) last = now.back();
    for (int i = last; i <= m; i++) {
      now.push_back(i);
      dfs(x + 1, now, n, m, a, b, c, d, mx);
      now.pop_back();
    }
  }
}

int main() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
    a[i]--, b[i]--;
  }

  int ans = 0;
  vector<int> now;
  dfs(0, now, n, m, a, b, c, d, &ans);
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using ipair = pair<ll,ll>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}


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

  vector<int> node_to_group(N, -1);
  vector<int> group_node_cnts(N, -1);
  vector<vector<int>> friend_list(N);
  vector<vector<int>> block_list(N);
  vector<int> blocked_node_in_group(N, 0);

  rep(i, M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    friend_list[a].emplace_back(b);
    friend_list[b].emplace_back(a);
  }

  rep(i, K){
    int c, d;
    cin >> c >> d;
    c--; d--;
    block_list[c].emplace_back(d);
  }

  // G分け

  // cout << ">> G分け" << endl << endl;

  int group_cnt = 0;
  rep(i, N){
    if(node_to_group[i] != -1) continue;

    queue<int> que;

    que.push(i);

    while(!que.empty()){
      int node = que.front(); que.pop();
      node_to_group[node] = group_cnt;
      group_node_cnts[group_cnt]++;

      for(int next_node: friend_list[node]){
        if(node_to_group[next_node] != -1) continue;
        node_to_group[next_node] = group_cnt;
        que.push(next_node);
      }
    }

    group_cnt++;
  }

  // 
  // cout << "node_to_cnts確認" << endl;
  // for(int i=0; i<= group_cnt; i++){
  //   cout << "group: " << i << ", cnt: " << group_node_cnts[i] << endl;
  // }

  // cout << ">> block in group" << endl << endl;

  // block in group
  rep(node, N){
    for(int blocked_node: block_list[node]){
      // 両方とも入れる
      if(node_to_group[node] == node_to_group[blocked_node]){
        blocked_node_in_group[node]++;
        blocked_node_in_group[blocked_node]++;
      }
    }
  }

  // cout << ">> node確認" << endl << endl;

  // 各node確認
  vector<int> ans;
  rep(node, N){
    // cout << "===" << endl;
    // cout << "node:" << node << endl;

    ll group = node_to_group[node];
    // cout << "group:" << group << endl;
    ll group_size = group_node_cnts[group];
    // cout << "group_size:" << group_size << endl;
    ll block_in_group_size = blocked_node_in_group[node];
    // cout << "sub_size:" << block_in_group_size << endl;

    ans.push_back(group_size - block_in_group_size - friend_list[node].size());
    // TODO: enable
  }

  rep(i, N){
    if(i!=0) cout << " ";
    cout << ans[i];
  }
  cout << endl;



  return 0;
}


Measured memory_bytes: 12664
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;

static const int MAX_N = 1400;

struct Rectangle {
  int height;
  int pos;
};

int masu[MAX_N][MAX_N];

int main(void) {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> masu[i][j];
      masu[i][j] = (masu[i][j] + 1) % 2;
    }
  }
  for (int i = 1; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (masu[i][j]) {
        masu[i][j] += masu[i-1][j];
      }
    }
  }

  Rectangle rect;
  int maxArea = 0;
  for (int i = 0; i < H; i++) {
    stack<Rectangle> stk;
    for (int j = 0; j < W; j++) {
      rect.height = masu[i][j];
      rect.pos = j;
      if (stk.empty()) {
        stk.push(rect);
      } else {
        if (stk.top().height < rect.height) {
          stk.push(rect);
        } else if (stk.top().height > rect.height) {
          int target = j;
          while (!stk.empty() && stk.top().height >= rect.height) {
            Rectangle pre = stk.top(); stk.pop();
            int area = pre.height * (j - pre.pos);
            maxArea = max(maxArea, area);
            target = pre.pos;
          }
          rect.pos = target;
          stk.push(rect);
        }
      }
    }

    while (!stk.empty()) {
      Rectangle pre = stk.top(); stk.pop();
      int area = pre.height * (W - pre.pos);
      maxArea = max(maxArea, area);
    }
  }

  cout << maxArea << endl;

  return 0;
}

Measured memory_bytes: 8856
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long d = sc.nextLong();
        d *= d;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            long s = x*x + y*y;
            if(s <= d) ans++;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 58840
alpha = "abcdefghijklmnopqrstuvwxyz"
s = list(input())
from copy import deepcopy
ans = 10**9
for c in s:
    s_c = deepcopy(s)
    counter = 0
    while set(s_c) != {c}:
        counter += 1
        new = []
        for i in range(len(s_c)-1):
            if s_c[i] == c or s_c[i+1] == c:
                new.append(c)
            else:
                new.append(0)
        s_c = new
    ans = min(ans, counter)
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;
 
int main() {
    string s;
    int k;
    cin >> k;
    cin >> s;
    if(s.size()<=k){
        cout << s << endl;
    }
    else{
        cout << s.substr(0,k);
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
x,k,d = gets.chomp.split(" ").map(&:to_i)

minus = false

if x < 0
  minus = true
  x *= -1
end

ans = x

y = x/d
r = x%d

if k < y
  ans -= k*d
else
  ans = r
  if ((k-y)%2) == 1
    ans -= d
  end
end

if minus
  ans *= -1
end

puts("#{ans.abs}")

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.being(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;
typedef double Double;

inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

int K;
Double R, L;
Double P, E, T;

Double ans;

lint combination(int n, int m) {
	lint res = 1;
	if (2 * m > n) m = n - m;
	for_(i,0,m) res = res * (n - i) / (i + 1);
	return res;
}

void rec(int k, Double lb, Double ub, Double p) {
	if (k == K) {
		Double T_ = (lb + ub) / 2.;
		if (abs(T_ - T) < E) ans += p;
		return;
	}
	
	if (T - E - lb < -EPS && EPS < T + E - ub) {
		int rem = K - k;
		for_(i,0,rem+1) {
			Double pp = combination(rem, i) * pow(P, i) * pow(1.0 - P, rem - i);
			ans += p * pp;
		}
		return;
	}
	
	if (T - E - ub > EPS || T + E - lb < -EPS) return;
	
	Double med = (lb + ub) / 2.;
	
	if (med - T > EPS) {
		rec(k + 1, lb, med, p * (1.0 - P));
		rec(k + 1, med, ub, p * P);
	} else {
		rec(k + 1, med, ub, p * (1.0 - P));
		rec(k + 1, lb, med, p * P);
	}
}

void solve() {
	ans = 0;
	rec(0, R, L, 1.0);
	printf("%.9lf\n", ans);
}

int main() {
	cin >> K >> R >> L;
	cin >> P;
	cin >> E;
	cin >> T;
	solve();
	return 0;
}

Measured memory_bytes: 1256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
A = np.arange(1, K+1, dtype=np.int32)
B = np.gcd.outer(np.gcd.outer(A, A), A)
answer = B.sum()
print(answer)


Measured memory_bytes: 57432
#include <bits/stdc++.h>
#define ll long long
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9 +5;
using namespace std;

int main() {
	fastio;
	int n;  cin>>n;
	vector<int> dp(3);
	// dp[i] - the total cost such that we did activity i on the last considered day
	for(int day=0;day<n;day++){
	    vector<int> new_dp(3,0);
	    vector<int> c(3);       // c -cost
	    for(int i=0;i<3;i++)
	        cin>>c[i];
	    for(int i=0;i<3;i++){
	        for(int j=0;j<3;j++){
	            if(i!=j){
	                new_dp[j]=max(new_dp[j], dp[i]+c[j]);
	            }
	        }
	    }
	    dp=new_dp;
	}
	cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

Measured memory_bytes: 384
/*
   Author : BabaYaga42,
   BITS Pilani, Hyderabad.
   Don't give up ;)
   */  
#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);
#define int long long
 
int32_t main()
{
	IOS;	
	int n;
	cin >> n;
	int ans = n*(n-1)/2;
	cout << ans <<endl;
	return 0;
}

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



int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i = 0 ; i < n ; i++){
        cin >> v[i];
    }
    long long ans = 0;
    for(int i = 0 ; i < n-1 ; i++){
            int curr = v[i];
        for(int j = i +1 ; j < n ; j++){
            ans += (v[i] * v[j]);
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
# 全て1食800円のレストラン
# 15食食べるごとにその場で200円もらえる
# 合計N食たべた。払った金額=x円、もらった金額をy円としてx-yを求める

# 入力されたNを数値に変換
N = int(input())

# 払った金額=x円を求める
x = 800 * N

# もらった金額=y円を求める
# 200円 * 回数Nを15で割った時の整数の商
y = 200 * (N // 15)

print(x-y)


Measured memory_bytes: 9056
#include "bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define INF 999999999

vector<int> pass[6000];
int n,k;
int c[6000],r[6000];

int d[6000];
bool used[6000];

void dfs(int v,int u,int f,int end,bool visited[6000]){
    if(visited[u])return ;
    visited[u] = true;
    d[u] = min(d[u],d[v]+c[v]);
    if(f>=end)return ;
    rep(i,pass[u].size()){
        dfs(v,pass[u][i],f+1,end,visited);
    }
}

int dijk(int s,int g){
    rep(i,6000)d[i]=INF;
    rep(i,6000)used[i]=false;
    
    d[s]=0;
    while(1){
        int v=-1;
        rep(u,n){
            if(!used[u] && (v==-1||d[u]<d[v]))v=u;
        }
        if(v==-1)break;
        used[v]=true;
        rep(i,pass[v].size()){
            bool visited[6000]={};
            dfs( v,pass[v][i],1,r[v],visited );
        }
    }
    return d[g];
}


int main(){
    cin>>n>>k;
    rep(i,n) cin>>c[i]>>r[i];
    rep(i,k){
        int a,b;
        cin>>a>>b;
        a--,b--;
        pass[a].pb(b);
        pass[b].pb(a);
    }
    
    cout<<dijk(0,n-1)<<endl;
}

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

using namespace std;

int main() {
    int N; cin>>N;
    vector<int> ln(N);
    for (int i=0;i<N;i++) cin>>ln[i];

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

    int sum=0;
    for (int i=0;i<N-1;i++) {
        sum += ln[i];
    }

    cout << ((ln[N-1]<sum)?"Yes":"No") << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int A[n], mi = 1e9, ma = -1e9;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        ma = max(ma, A[i]);
        mi = min(mi, A[i]);
    }
    int ans = 1e9;
    for(int i = mi; i <= ma; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += abs(A[j] - i) * abs(A[j] - i);   
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!{
        n: usize,
        a: [u64; n]
    };
    let s = a[2..n].iter().fold(0, |x, y| x^y);
    let mut dp = [[[a[0]; 2]; 2]; 45];
    dp[0][0][0] = 0;
    for i in 0..44 {
        for j in 0..2 {
            for k in 0..2 {
                if dp[i][j][k] == a[0] { continue; }
                let x = a[0] - (j << i) as u64;
                let y = a[1] + (k << i) as u64;
                if ((x^y^s) >> i) % 2 == 1 { continue }
                let x0 = (a[0] >> i) % 2;
                let y0 = (a[1] >> i) % 2;
                for l in 0..2 {
                    if (l << i) as u64 >= x { continue }
                    let nj = if x0 < (j + l) as u64 { 1 } else { 0 };
                    let nk = if y0 + (k + l) as u64 >= 2 { 1 } else { 0 };
                    dp[i+1][nj][nk] = std::cmp::min(dp[i+1][nj][nk], dp[i][j][k] + (l << i) as u64);
                }
            }
        }
    }
    let mut res = a[0];
    for i in 0..2 {
        for j in 0..2 {
            res = std::cmp::min(res, dp[44][i][j]);
        }
    }
    if res < a[0] {
        println!("{}", res);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2180
import bisect
# 三角形の条件: c < a+b 

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-1, 1, -1):
  a = 0
  b = i-1
  while a<b:
    if L[a]+L[b] > L[i]:
      ans += b-a
      b -= 1
    else:
      a += 1
          
print(ans)    

Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>

int main(){
	double x,y,angle,angle1,r;
	double PI=3.14159265;
	x=0;
	y=0;
	angle=PI/2;
	while(0<=scanf("%lf,%lf",&r,&angle1)){
		if((r==0) & (angle1==0)){
			break;
		}
		x=x+r*cos(angle);
		y=y+r*sin(angle);
		angle=angle-angle1*PI/180;
	}
	if(x<0){
		printf("%.0lf\n",x+0.5);
	}else{
		printf("%.0lf\n",x-0.5);
	}
	
	if(y<0){
		printf("%.0lf\n",y+0.5);
	}else{
		printf("%.0lf\n",y-0.5);
	}
	
	return 0;
}

Measured memory_bytes: 0
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back   
#define sz(a) ((int)a.size())
using namespace std;
typedef long long ll ;
const int mod = 1e9 + 7;
const int N = 1e5 + 1;
const ll inf = 1e18 ;
ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int n , k;
vector<int> g[N];

ll dfs(int u , int p = -1){
    int use = k - 1 - (p != -1);
    ll ans = (p == -1 ? k : 1); 
    for(int& v : g[u]){
        if(v == p) continue ;
        ans = (1LL * ans * (use--)) % mod;
        ans = (1LL * ans * dfs(v , u)) % mod ;
    }
    return ans ;
}


void solve(){
    cin >> n >> k ;
    for(int i = 0 ; i < n - 1; ++i){
        int x , y;
        cin >> x >> y;
        --x , --y ;
        g[x].pb(y);
        g[y].pb(x);
    }
    cout << dfs(0) % mod ;
}

int main()
{
    ios::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
    int TC = 1, t = 0;
    // cin >> TC ;
    while(t++ < TC)
    {
        // cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 14844
#include<bits/stdc++.h>
    using namespace std;
	#define ll long long int
    int main(){
    	ll ar[4],i,j;
      	for(i=0;i<4;i++){
        	cin>>ar[i];
        }
      	sort(ar,ar+4);
      	if(ar[0]==1&&ar[1]==4&&ar[2]==7&&ar[3]==9){
        	cout<<"YES";
        }
      	else cout<<"NO";
    	return 0;
    }

Measured memory_bytes: 256