akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    double p = 0.0;
    REP(i,1,N+1) {
        ll d = 1;
        while(d < (K+i-1)/i) d *= 2;
        p += 1.0 / d;
    }
    cout << setprecision(12) << p / N << endl;

    return 0;
}

/*

1/8+

*/

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll dp[1005][20005];

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

    ll H,N; cin >> H >> N;
    ll A[1003], B[1003];

    for (int i = 0;i < N;i++){
        cin >> A[i] >> B[i];
    }

    for (int i = 0;i <= N;i++){
        for (int j = 0;j <= 20000;j++){
            dp[i][j] = INT_MAX;
        }
    }

    for (int i = 0;i <= N;i++){
        dp[i][0] = 0;
    }

    for (int i = 0;i < N;i++){
        for (int j = 0;j <= 20000;j++){
            if(j < A[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
        }
        //cout << endl;
    }

    ll ans = INT_MAX;
    for (int i = H;i <= 20000;i++){
        //cout << dp[N][i] << endl;
        ans = min(ans,dp[N][i]);
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 156672
#include <iostream>
using namespace std;
int a[100001], dp[100001], n, k;
int solve(int i){
	if(dp[i] != -1){
		return dp[i];
	}
	if(i == n - 1){
		return 0;
	}
	if(i == n - 2){
		return abs(a[i] - a[i + 1]);
	}
	dp[i] = solve(i + 1) + abs(a[i] - a[i + 1]);
	for(int j = 2; j <= k && j + i < n; ++j){
		dp[i] = min(dp[i], solve(i + j) + abs(a[i] - a[i + j]));
	}
	return dp[i];
}
int main() {
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		dp[i] = -1;
	}
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
	}
	cout << solve(0);
	return 0;
}


Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
BIGNUM = 10 ** 9 + 7

if m > 0:
    last_ana = int(input())
    blocks = [last_ana]

    for _ in range(1, m):
        ana = int(input())
        blocks.append(ana - last_ana - 1)
        last_ana = ana
    blocks.append(n - last_ana)
else:
    blocks = [n + 1]

if 0 in blocks:
    ans = 0
else:
    b_max = max(blocks)
    c = [1, 1]
    for i in range(2, b_max):
        ctmp = c[i - 1] + c[i - 2]
        c.append(ctmp % BIGNUM)

    ans = 1
    for num in blocks:
        if num == 1:
            continue
        ans = (ans * c[num - 1]) % BIGNUM
        if ans == 0:
            break

print(ans)

Measured memory_bytes: 7056
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M; cin >> N >> M;
    vi a(M), b(M); REP(i, M)cin >> a[i] >> b[i];

    vvi e(N);

    REP(i,M) {
        e[a[i]-1].push_back(b[i]-1);
        e[b[i]-1].push_back(a[i]-1);
    }

    REP(i,N) cout << e[i].size() << endl;

    return 0;
}

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

const int N = 300010;

int num[N], n;

inline bool check(int l, int r) {
	if (num[l] == l) l++;
	if (num[r] == r) r--;
	if (l > r) return true;
	for (int i = l + 1; i <= r; i += 2) 
		if (num[i] != i) return false;
	for (int i = l; i <= r; i += 2)
		if (num[i] == i) return false;
	int mn = 1e9, mx = 0;
	for (int i = l; i <= r; i++) 
		mn = min(mn, num[i]), mx = max(mx, num[i]);
	if (mn != l || mx != r) return false;
	for (int i = l, a = 0, b = 0; i <= r; i += 2) {
		if (num[i] < i) {
			if (a > num[i]) return false;
			a = num[i];
		} else {
			if (b > num[i]) return false;
			b = num[i];
		}
	} 
	return true;
}

int fuck[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) 
		scanf("%d", &num[i]), fuck[i] = num[i] == i;
	int ls = 1;
	for (int i = 1; i <= n; i++) {
		if (fuck[i] && fuck[i - 1]) {
			if (!check(ls, i - 2)) return puts("No"), 0;
			ls = i + 1;
		} else if (!fuck[i] && !fuck[i - 1]) {
			if (!check(ls, i - 1)) return puts("No"), 0;
			ls = i;
		} 
	}
	if (!check(ls, n)) return puts("No"), 0;
	puts("Yes");
}

Measured memory_bytes: 2560
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
string  a;
bool pd=false,pdd=false; 
int pp;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a;
	for(int i=0;i<a.length();i++)
	{
		if(a[i]=='C')
		{
			pp=i;
			pd=true;
			break;
		}
	}
	if(pd==false)
	{
		cout<<"No";
		return 0;
	}
	for(int i=pp+1;i<a.length();i++)
	{
		if(a[i]=='F')
		{
			pdd=true;
			break;
		}
	}
	if(pdd==true)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
vector<vector<int>> to, from;
deque<int> L;
vector<bool> vis;
void dfs(int tmp) {
  if(!vis[tmp]) {
    vis[tmp] = 1;
    for(int ne: to[tmp]) dfs(ne);
    L.push_front(tmp);
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  to = vector<vector<int>>(N);
  from = vector<vector<int>>(N);
  vis = vector<bool>(N);
  rep(i, N-1+M) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    from[b].push_back(a);
  }
  int root = -1;
  rep(i, N) if(from[i].empty()) root = i;
  dfs(root);
  vector<int> new_num(N);
  int n = L.size();
  rep(i, n) {
    new_num[L.front()] = i;
    L.pop_front();
  }
  rep(i, N) {
    int par = -1;
    for(int j: from[i]) {
      if(new_num[j] > (par == -1 ? -1 : new_num[par])) {
	par = j;
      }
    }
    cout << par+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 17228
import numpy as np
N = int(input())
digit = int(np.log10(N))+1

def ok(s):
  if '7' in s and '5' in s and '3' in s and int(s) <= N:
    return True
  return False

def dfs(cur, s):
  if cur == digit:
    return ok(s)
  else:
    ret = ok(s)
    for i in '357':
      ret += dfs(cur+1, s+i)
  return ret

print(dfs(0, ''))


Measured memory_bytes: 12508
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    cin >> N;
    for (int i = 1; i <= 9; i++)
    {
        if (N % i == 0)
        {
            int tmp = N / i;
            if ((1 <= tmp) && (tmp <= 9))
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

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

using namespace std;

int main () {
    int N, D;
    cin >> N >> D;
    if (N % (2 * D + 1) == 0) {
        cout << (N / (2 * D + 1)) << endl;
    } else {
        cout << (N / (2 * D + 1) + 1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int n; std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    bool vis[1000006] = {};
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (vis[a[i]]) continue;
        if (i == n - 1 || a[i] != a[i + 1]) ans++;
        for (int j = 1; a[i]*j <= 1000000; j++) {
            vis[a[i]*j] = true;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 5104
fn solve(s: &str) -> bool {
    for (i, c) in s.chars().enumerate() {
        if (i + 1) % 2 == 1 && c == 'L' {
            return false;
        }
        if (i + 1) % 2 == 0 && c == 'R' {
            return false;
        }
    }

    true
}

#[test]
fn solve_test() {
    assert_eq!(solve("RUDLUDR"), true);
    assert_eq!(solve("DULL"), false);
    assert_eq!(solve("UUUUUUUUUUUUUUU"), true);
    assert_eq!(solve("RDULULDURURLRDULRLR"), true);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    println!("{}", if solve(&s) { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
}

Measured memory_bytes: 31892
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define PI 3.14159265358979323846
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}

using namespace std;

int gcd(int a, int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }

void solve(){
 
 int x;
 cin>>x;
 int l=lcm(x,360);
 cout<<l/x;
  //cout<<tick()<<endl;	
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
//   int t;
//   cin>>t;
//   while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<queue>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;

#define MAX 100010
string S,T;
int Q,a[MAX],b[MAX],c[MAX],d[MAX];

const string alpha = "AB";
int sumS[2][MAX]; // 0 -> A, 1 -> B
int sumT[2][MAX]; // 0 -> A, 1 -> B

void init_sumST() {
  rep(i,(int)S.size()) {
    rep(j,2) {
      if( i ) sumS[j][i] = sumS[j][i-1];
      if( alpha[j] == S[i] ) ++sumS[j][i];
    }
  }
  rep(i,(int)T.size()) {
    rep(j,2) {
      if( i ) sumT[j][i] = sumT[j][i-1];
      if( alpha[j] == T[i] ) ++sumT[j][i];
    }
  }
}

void compute() {
  init_sumST();
  rep(i,Q) {
    ll SA,SB;
    SA = sumS[0][b[i]];
    if( a[i] - 1 >= 0 ) SA -= sumS[0][a[i]-1];
    SB = sumS[1][b[i]];
    if( a[i] - 1 >= 0 ) SB -= sumS[1][a[i]-1];
    ll miniS = SA + SB * 2LL;
    
    ll TA,TB;
    TA = sumT[0][d[i]];
    if( c[i] - 1 >= 0 ) TA -= sumT[0][c[i]-1];
    TB = sumT[1][d[i]];
    if( c[i] - 1 >= 0 ) TB -= sumT[1][c[i]-1];
    ll miniT = TA + TB * 2LL;
    if( miniS % 3LL == miniT % 3LL ) puts("YES");
    else puts("NO");
  }
}

int main() {
  cin >> S >> T >> Q;
  rep(i,Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i], --b[i], --c[i], --d[i];
  }
  compute();
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/11)*2;
    x %= 11;
    ans += x/6;
    x %= 6;
    ans += (x+4)/5;
    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_i)

ans = 0
while a.even? && b.even? && c.even? do
  ans += 1
  a_t = b/2 + c/2
  b_t = a/2 + c/2
  c_t = a/2 + b/2
  if a==a_t && b==b_t && c==c_t
    ans = -1
    break
  else
    a = a_t
    b = b_t
    c = c_t
  end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x( N ), y( M );
    for( auto &a : x )
    {
        cin >> a;
    }
    for( auto &b : y )
    {
        cin >> b;
    }
    int xmax = *max_element( ALL( x ) ), ymin = *min_element( ALL( y ) );
    REP( i, 100 )
    {
        if( i > xmax && i <= ymin && X < i && i <= Y )
        {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	while( 1 ) {
		int N;
		cin >> N;
		if( N == 0 ) break;
		int ans = 0;

		for(int i = 1; i * i <= N; i++) {
			if( i * i == N ) ans++;
		}

		for(int i = 1; i * i <= N; i++) {
			for(int j = i; i * i + j * j <= N; j++) {
				if( i * i + j * j == N ) ans++;
			}
		}

		for(int i = 1; i * i <= N; i++) {
			for(int j = i; i * i + j * j <= N; j++) {
				for(int k = j; k * k + j * j + i * i <= N; k++) {
					if( i * i + j * j + k * k == N ) ans++;
				}
			}
		}

		for(int i = 1; i * i <= N; i++) {
			for(int j = i; i * i + j * j <= N; j++) {
				for(int k = j; k * k + j * j + i * i <= N; k++) {
					for(int l = k; l * l + k * k + j * j + i * i <= N; l++) {
						if( i * i + j * j + k * k + l * l == N ) ans++;
					}
				}
			}
		}

		cout << ans << endl;

	}

	//while(1){}
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if (a>b) {
             int temp = a;
             a = b;
             b = temp;
        }
    
        if (b>c) {
            int temp = b;
            b = c;
            c = temp;
        }
        
        if (a>b) {
           int temp = a;
           a = b;
           b = temp;
        }
       
        System.out.println(a + " " + b + " " + c);
    }
}
            

Measured memory_bytes: 26104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool f[114514];
int main(){
	ll n;
	cin>>n;
	vector<vector<ll>>ro(n+1);
	vector<pair<ll,ll>>p;
	for(int i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b;
		ro[a].push_back(b);
		ro[b].push_back(a);
		p.push_back({a,b});
	}
	queue<ll>que;
	que.push(1);
	f[1]=1;
	ll ma=0;
	map<pair<ll,ll>,ll>mp;
	vector<ll>yojo(n+1,0);
	while(!que.empty()){
		ll x=que.front();
		que.pop();
		if(ma<ro[x].size())ma=ro[x].size();
		ll now=1;
		for(ll q:ro[x]){
			if(f[q])continue;
			if(now==yojo[x])now++;
			yojo[q]=mp[{x,q}]=mp[{q,x}]=now;
			now++;
			f[q]=1;
			que.push(q);
		}
	}
	cout<<ma<<endl;
	for(pair<ll,ll> q:p)cout<<mp[q]<<endl;
	return 0;
}


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

string s[21];
int w, h, vx[4] = {1, 0, -1, 0}, vy[4] = {0, 1, 0, -1};
bool is_search[21][21];

int dfs(int x, int y) {
  //cout << x << " " << y << endl;
  is_search[x][y] = true;
  int ret = 0, cnt = 0;
  for(int i = 0; i < 4; ++i) {
    if(0 <= x+vx[i] && 0 <= y+vy[i] && x+vx[i] < h && y+vy[i] < w && s[x+vx[i]][y+vy[i]] != '#' && is_search[x+vx[i]][y+vy[i]] == false) {
      ret += dfs(x+vx[i], y+vy[i]);
      cnt++;
    }
  }
  //cout << ret+cnt << endl;
  return ret + cnt;
}

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

  int ans, sx, sy;
  bool flag;

  while(cin >> w >> h, w | h) {
    ans = 0; flag = false;
    for(int i = 0; i < h; ++i) fill(is_search[i], is_search[i] + w, false);
    for(int i = 0; i < h; ++i) cin >> s[i];

    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        if(s[i][j] == '@') {
          sx = i; sy = j;
          flag = true;
          break;
        }
      }
      if(flag) break;
    }

    ans = dfs(sx, sy) + 1;

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,a[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  sort(a+1,a+1+n,greater<int>());LL ans=0;
  ans=a[1];
  int f=n-2;
  int l=2;
  while(f>0){
    ans+=a[l];
    f--;
    if(!f)break;
    ans+=a[l];
    f--;
    l++;
  }
  cout<<ans<<'\n';
  return 0;
}

Measured memory_bytes: 4444
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
string s;
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	if((int)(s.size())%2==1){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<s.size();i+=2){
		if(((s[i]!='h')||(s[i+1]!='i'))){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define unsort(vec) sort(vec);reverse(vec.begin(),vec.end());
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	unsort(a);
	bool x=false;
	for(int i=1;i<n;i++){
		if(a[i]==a[i-1]){
			if(!x){
				ans=a[i];
				x=true;
			}
			else{
				cout<<ans*a[i]<<endl;
				return 0;
			}
			i++;
		}
	}
	cout<<0<<endl;
}

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

int prime[1000010];
bool is_prime[1000010];

void seive(int n){
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i)
			is_prime[j]=false;
		}
	}
}
	
int main() {
	int n;
	
	seive(999999);
	
	while(cin>>n){
		int sum=0;
		
		for(int i=0;i<=n;i++)
		if(is_prime[i])
		sum++;
		
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4324
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
  int n , m;
  cin >> n >> m;
  vector< vector< pair<int, int> > > a(n);
  vector< pair<int ,int> >b(m);
  int p, y;
  for(int i = 0; i < m; i++){
    cin >> p >> y;
    a[p-1].push_back(make_pair(y,i));
  }
  for(int i = 0; i < n; i++){
    sort(a[i].begin(), a[i].end());
    for(int j = 0 ; j < a[i].size(); j++) b[a[i][j].second] = {i,j};
  }
  for(int i = 0; i < m; i++){
      cout << setfill('0') << setw(6) << right << b[i].first+1;
      cout << setfill('0') << setw(6) << right << b[i].second+1 << endl;
  }
}


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

class Dice{
private:
public:

  vector<int> d;
  void spin(string s){
    if(s == "S"){
      swap(d[0],d[4]);
      swap(d[4],d[1]);
      swap(d[4],d[5]);
    }
    if(s == "E"){
      swap(d[0],d[3]);
      swap(d[2],d[3]);
      swap(d[3],d[5]);
    }
    if(s == "N"){
      swap(d[0],d[1]);
      swap(d[1],d[5]);
      swap(d[4],d[5]);
    }
    if(s == "W"){
      swap(d[0],d[2]);
      swap(d[2],d[5]);
      swap(d[3],d[5]);
    }
    if(s == "C"){
      swap(d[1],d[3]);
      swap(d[2],d[3]);
      swap(d[4],d[3]);
    }
  }

  void canonical(){
    string s = "CCCCECCCCECCCCECCCCSCCCCSSCCCC";
    vector<int> can = d;
    for(int i=0; i<s.size(); i++){
      spin(s.substr(i,1));
      if(d < can) can = d;
    }
    d = can;
  }
};



int main(){

  Dice sai[101];
  vector<int> in(6);
  int n; cin >> n;
  for(int j=0; j<n; j++){
    vector<int> in(6);
    for(int i=0; i<6; i++){
      cin >> in[i];
    }
    sai[j].d = in;
  }
  
  string s = "CCCCECCCCECCCCECCCCSCCCCSSCCCC";
  bool is_same = false;

  for(int i=0; i<n; i++){
    sai[i].canonical();
    //    for(int j=0; j<6; j++) cout << sai[i].d[j] << " ";
    //    cout << endl;
  }

  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(sai[i].d == sai[j].d){ is_same = true; break;}
    }
  }

  if(!is_same) cout <<"Yes\n";
  else  cout <<"No\n";

}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

struct ps {
	ll x1, y1;
	ll x2, y2;
};

int main() {
	ll R, C, N; cin >> R >> C >> N;
	vector<ps> pos;
	pos.reserve(N);
	auto ck = [](ll x, ll b) { return x == 0 || x == b; };
	for (int i = 0; i < N; i++) {
		ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		if ((ck(x1, R) || ck(y1, C)) && (ck(x2, R) || ck(y2, C))) {
			pos.push_back({ x1, y1, x2, y2 });
		}
	}
	N = pos.size();
	vector<pair<ll, int>> v;
	auto pb = [&](int i, ll x, ll y) {
		if (x == 0) v.push_back({ y, i });
		else if (y == C) v.push_back({ C + x, i });
		else if (x == R) v.push_back({ R + 2 * C - y, i });
		else if (y == 0) v.push_back({ 2 * R + 2 * C - x, i });
	};
	for (int i = 0; i < N; i++) {
		pb(i, pos[i].x1, pos[i].y1);
		pb(i, pos[i].x2, pos[i].y2);
	}
	sort(v.begin(), v.end());
	vector<int> cnt(N);
	vector<int> st;
	for (int i = 0; i < (int)v.size(); i++) {
		int idx = v[i].second;
		cnt[idx]++;
		if (cnt[idx] <= 1) st.push_back(idx);
		if (cnt[idx] >= 2) {
			if (st.back() != idx) {
				cout << "NO" << endl;
				return 0;
			}
			else st.pop_back();
		}
	}
	cout << "YES" << endl;
	return 0;
}


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

using namespace std;

#define rep(i,a,b) for(int i=int(a),nn=int(b);i<=nn;++i)

const int N = 100100;

typedef long long ll;

int a[N], n;

inline void in(int &x) {
	scanf("%d", &x);
}
inline ll ans(int sg) {
	ll sm = 0, as=0;
	rep(i, 1, n) {
		sm += a[i];
		if (sg > 0&&sm<sg) as+=sg-sm, sm=sg;
		else if (sg<0&&sm>sg) as+=sm-sg, sm=sg;
		sg = 0-sg;
	}
	return as;
}
int main() {
	in(n);
	rep(i, 1, n) in(a[i]);

	printf("%lld\n", min(ans(1),ans(-1)));
	return 0;
}



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

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

int main() {
    long long N;
    cin >> N;
    int digit;
    char name[20];

    int i = 0;
    while(N) {
        digit = N % 26;
        if (digit == 0) digit = 26;
        name[i] = char(96 + digit);
        N -= 1;
        N /= 26;
        i++;
    }

    for(int j=i-1; j >= 0; j--) cout << name[j];
    cout << endl;

    return 0;
}

Measured memory_bytes: 3636
a=int(input())
b=int(input())
c=int(input())
x=int(input())

money = x
cmp = 0

for i in range(0,a+1,1):
  if money < 500*i:
    break
    
  for j in range(0,b+1,1):
    if money - 500*i < 100 * j:
      break
    
    for k in range(0,c+1,1):
      if money - 500*i - 100 * j < 50 * k:
        break
        
      if money == 500*i + 100 * j + 50 * k:
        cmp +=1
        #print(i,j,k)
    
print(cmp)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using Graph=vector<vector<int>>;
template<class T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF=1LL<<60;
const long long MOD=1e9+7;

int h,w;
char a[1010][1010];
long long dp[1010][1010];

int main(){
    cin>>h>>w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin>>a[i][j];
        }
    }

    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(i+1<h&&a[i+1][j]=='.') dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
            if(j+1<w&&a[i][j+1]=='.') dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
        }
    }

    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 9216
import sys
import numpy as np
from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()

    [N, A, B] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    result = (B-A)*(N-2) + 1
    if result < 0:
        result = 0

    print result

if __name__ == '__main__':
    main()


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

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

  int w, a, b;
  cin >> w >> a >> b;

  if ((b + w >= a && b + w <= a + w) || (b >= a && b <= a + w)) cout << 0 << "\n";
  else cout << min(abs(b - a + w), abs(a - b + w)) << "\n";
  return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  int n = s.size();
  int res = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i-1]) ++res;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 512
import java.util.*;

public class Main {

    int n;
    int[] a;
    long MOD = (long)1e9 + 7;

    Map<Integer, LinkedList<Integer>> i2ps = new HashMap<>();
    Map<Integer, Long> sum = new HashMap<>();

    void run() {
        Scanner sc = new Scanner(System.in);

        LinkedList<Integer> as = new LinkedList<>();

        n = sc.nextInt();
        as.add(0);
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            if (as.getLast() != x) {
                as.addLast(x);
            }
        }
        n = as.size();
        a = new int[n + 1];
        int idx = 0;
        for (int v: as) {
            a[idx++] = v;
        }

        for (int i = 1; i <= n; i++) {
            LinkedList<Integer> l = i2ps.getOrDefault(a[i], new LinkedList<>());
            l.add(i);
            i2ps.put(a[i], l);
        }

//        debug(a);

        LinkedList<Integer> dum = new LinkedList<>();
        dum.addLast(0);
        i2ps.put(0, new LinkedList<>(dum));

        long[] dp = new long[n + 1];
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            dp[i] = (dp[i - 1] + dp[i]) % MOD;
            LinkedList<Integer> l = i2ps.get(a[i]);
            l.removeFirst();
            if (!l.isEmpty()) {
                int p = l.getFirst();
                sum.put(a[i], (sum.getOrDefault(a[i], 0L) + dp[i]) % MOD);
                dp[p + 1] = (sum.get(a[i]) + dp[p + 1]) % MOD;

            }
            i2ps.put(a[i], l);
//            debug(dp);
        }
        System.out.println(dp[n]);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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

Measured memory_bytes: 104764
import java.util.*;
public class Main {
    
    public static void main(String[] args) throws InterruptedException{
        Scanner sc = new Scanner(System.in);

        StringBuffer s = new StringBuffer(sc.nextLine());
        int k = sc.nextInt();
            
            for(int i = 0;i<s.length()-1;i++){
                if(s.charAt(i) != 'a' && k - ( 26 - ( (int)s.charAt(i) - 97 ) ) >= 0){
                    k -= ( 26 - ( (int)s.charAt(i) - 97 ) );
                    s.setCharAt(i, 'a');
                }
            }
//        System.out.println(26-(int)'i' + 97);
        
        k = k % 26;
        if(s.charAt(s.length()-1) + k > 122){
            s.setCharAt(s.length()-1, (char)(s.charAt(s.length()-1) + k-26));
        }else{
            s.setCharAt(s.length()-1, (char)(s.charAt(s.length()-1) + k));
        }
        System.out.println(s);
        
//        System.out.println(100-('c'-96+21));
//        System.out.println(26-( (int)'o' - 97));
        
        
    }
}

Measured memory_bytes: 14124
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

int main(){
  queue<P> que;
  int H, W;
  cin >> H >> W;
  vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  vector<vector<char>> field(H, vector<char> (W));
  vector<vector<int> > dist(H, vector<int> (W, INF));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> field[i][j];
      if(field[i][j] == '#'){
        que.push(P(i, j));
        dist[i][j] = 0;
      }
    }
  }
  while(que.size()){
    P p = que.front(); que.pop();
    for(int i = 0; i < 4; i++){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(dist[nx][ny] == INF){
        dist[nx][ny] = min(dist[nx][ny], dist[p.first][p.second] + 1);
        que.push(P(nx, ny));
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      ans = max(ans, dist[i][j]);
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 13456
N = int(input())
A = [int(x) for x in input().split()]

ans_plus = ans = 0
l = r = 0
sum = A[0]
xorsum = A[0]

while 1:
    if sum == xorsum:
        ans_plus += 1
        ans += ans_plus
        if r == N - 1:
            break
        else:
            r += 1
        sum += A[r]
        xorsum ^= A[r]
    else:
        ans_plus -= 1
        sum -= A[l]
        xorsum ^= A[l]
        l += 1

print(ans)


Measured memory_bytes: 24584
#include <iostream>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC75(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC70();
}

void ABC70(void){
    int n;
    cin>>n;
    if(n/100==n%10)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

const int INF = 1e9 + 10;

int A, B;


int main() {
    cin >> A >> B;
    cout << A * B << endl;
}

Measured memory_bytes: 3612
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var Q = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        var amax = a[n - 1];
        var b = new int[amax + 1];
        setB(a, b);
        for (int i = 0; i < Q; i++)
        {
            var q = int.Parse(Console.ReadLine().Trim());
            getAns(b, q);
        }
    }
    public static void getAns(int[] b, int q)
    {
        var ans = 0;
        var na = b[b.Length - 1];
        while (true)
        {
            na = b[na];
            var w = na % q;
            if (w == q - 1) { Console.WriteLine(q - 1); return; }
            ans = Max(ans, w);
            if (w == 0) na -= 1;
            else na -= w;
            if (na <= 0) break;
        }
        Console.WriteLine(ans);
    }
    public static void setB(int[] a, int[] b)
    {
        var aL = a.Length;
        var bL = b.Length;
        for (int i = 0; i < aL; i++)
            b[a[i]] = a[i];
        for (int i = a[0] + 1; i < bL; i++)
            if (b[i] == 0) b[i] = b[i - 1];
    }
}





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

int main() {
    int n, m, ans = 0;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string str;
        cin >> str;
        mp[str]++;
    }
    cin >> m;
    rep(i, m) {
        string str;
        cin >> str;
        mp[str]--;
    }
    for(pair<string, int> p : mp) if(p.second > ans) ans = p.second;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m, q;
	cin>>n>>m>>q;
	P p[200000];
	for(int i=0; i<m; i++){
		int l, r;
		cin>>l>>r;
		p[i]=P(r, l);
	}
	sort(p, p+m);
	int d=450;
	int ct[450][502]={};
	for(int i=0; i<m; i++){
		ct[i/d][p[i].second]++;
	}
	for(int i=0; i<=(m-1)/d; i++){
		for(int j=n; j>=1; j--){
			ct[i][j]=ct[i][j]+ct[i][j+1];
		}
	}
	for(int k=0; k<q; k++){
		int x, y;
		cin>>x>>y;
		int i0=upper_bound(p, p+m, P(y, 502))-p;
		if(i0==0){
			cout<<0<<endl;
			continue;
		}
		int ans=0;
		for(int i=0; i<(i0-1)/d; i++){
			ans+=ct[i][x];
		}
		for(int i=(i0-1)/d*d; i<i0; i++){
			if(p[i].second>=x) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328
//
//  respect the past, embrace the future
//

#include  <algorithm>
#include  <iostream>
#include  <climits>
#include  <cstdlib>
#include  <cstring>
#include  <cmath>
#include  <cstdio>
#include  <unordered_map>
#include  <map>
#include  <set>
#include  <stack>
#include  <string>
#include  <vector>
#include  <queue>

using namespace :: std;

using vpll = vector <pair <long long, long long> >;
using pll = pair <long long, long long>;
using vll = vector <long long>;
using ll = long long;

#define W (ll) (5e3 + 7)
#define N (ll) (2e6 + 7)
#define M (ll) (1e9 + 7)
#define INF (ll) (2e18)
#define F first
#define S second

inline void fastInputOutput () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
}

inline void ReadWriteFromFile () {
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
}

int n, m, a[N], pre[N], suf[N];
int ans = -M;

int32_t main (int argc, char *argv[]) {
  fastInputOutput();
  // ReadWriteFromFile();
  
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = __gcd(pre[i - 1], a[i]);
  }
  for (int i = n; i >= 1; i--)
    suf[i] = __gcd(suf[i + 1], a[i]);
  for (int i = 1; i <= n; i++)
    ans = max(ans, __gcd(pre[i - 1], suf[i + 1]));
  cout << ans;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+9;
ll arr[maxn];
int main(){
    ios::sync_with_stdio(0);
    ll a,b,c,d,e,f,g,h,n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>arr[i];
    g=h=0;
    e=0;
    for(int i=1;i<=n;i++){
        if(i%2){
            if(e+arr[i]<=0){
                g+=-(e+arr[i])+1;
                e=1;
            }
            else{
                e+=arr[i];
            }
        }
        else{
            if(e+arr[i]>=0){
                g+=(e+arr[i])+1;
                e=-1;
            }
            else{
                e+=arr[i];
            }
        }
    }
    e=0;
    for(int i=1;i<=n;i++){
        if(i%2==0){
            if(e+arr[i]<=0){
                h+=-(e+arr[i])+1;
                e=1;
            }
            else{
                e+=arr[i];
            }
        }
        else{
            if(e+arr[i]>=0){
                h+=(e+arr[i])+1;
                e=-1;
            }
            else{
                e+=arr[i];
            }
        }
    }
    //cout<<g<<' '<<h<<endl;
    cout<<min(g,h)<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = 0;
        int c,d;
        for(int i=0;i<a;i++){c = sc.nextInt();
                             d = sc.nextInt();
                             b+=d-c+1;}	
		System.out.println(b);
	}
}


Measured memory_bytes: 24676
"""

i回目では前からi人目の持っていた任意のボールを置ける
赤を何回採用したかでDP


"""

S = input()
N = len(S)
mod = 998244353

lis = [0] * (2*N+1)
lis[0] = 1
R = 0
B = 0

c = 0
for n in S:

    if n == "0":
        R += 2
    elif n == "1":
        R += 1
        B += 1
    else:
        B += 2

    nlis = [0] * (2*N+1)
    
    for i in range(2*N):

        if i < R:
            nlis[i+1] += lis[i]
            nlis[i+1] %= mod

        if c-i < B:
            nlis[i] += lis[i]
            nlis[i] %= mod

    lis = nlis
    c += 1


for loop in range(N):
    
    nlis = [0] * (2*N+1)
    
    for i in range(2*N):

        if i < R:
            nlis[i+1] += lis[i]
            nlis[i+1] %= mod

        if c-i < B:
            nlis[i] += lis[i]
            nlis[i] %= mod

    lis = nlis
    c += 1

print (sum(lis) % mod)

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

using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string t;
    cin >> t;
    if (t.find("AC") != string::npos)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, k;
    set < int > s;
    cin >> a >> b >> k;
    if (abs(b - a) <= k)
    {
        for(int i = a; i <= b; i++)
        {
            cout << i << endl;
        }
    }
    else
    {
        for(int i = 1; i <= k; i++)
        {
            s.insert(a);
            a++;
            s.insert(b);
            b--;
        }
        for(auto it: s)
        {
            cout << it << endl;
        }
    }
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

const int M_N=200001;

struct UnionFind{
    int par[M_N];
    int rank[M_N];
    LL number[M_N];
 
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
            number[i]=1;
        }
    }
 
    int find(int x){
        if(par[x]==x){
            return x;
        }
        else{
            return par[x]=find(par[x]);
        }
    }
 
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){
            par[x]=y;
            number[y]+=number[x];
        }
        else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
            number[x]+=number[y];
        }
    }
 
    bool same(int x,int y){
        return find(x)==find(y);
    }
 
    int get(int x){
        return number[find(x)];
    }
 
};

vector<int> v[100001],u[100001];

int main(){
    int n;cin >> n;
    UnionFind uf;
    uf.init(100001);
    for (int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        v[x].pb(y);
        u[y].pb(x);
    }
    for (int i = 1; i <= 100000; i++) {
        for (int j = 1; j < u[i].size(); j++) {
            uf.unite(u[i][j],u[i][j-1]);
        }
    }
    LL ans = 0;
    vector<bool> used(100001,false);
    for (int i = 1; i <= 100000; i++) {
        if(used[uf.find(i)]) continue;
        if(uf.get(i)==1){
            ans += (LL)v[i].size();
            continue;
        }
        LL t = 1;
        bitset<100001> bs;
        for (int j = 0; j < v[i].size(); j++) {
            bs[v[i][j]]=1;
        }
        for (int j = i+1; j <= 100000; j++) {
            if(!uf.same(i,j)) continue;
            t++;
            for (int k = 0; k < v[j].size(); k++) {
                bs[v[j][k]]=1;
            }
        }
        used[uf.find(i)]=true;
        ans += bs.count()*t;
    }
    cout << ans-n << endl;
    return 0;
}


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

using i64 = int64_t;

int main(){
    i64 n, k;
    cin >> n >> k;

    cout << (n/k)*(n/k)*(n/k) + (k%2 ? 0 : (n >= k/2 ? ((n-k/2)/k+1)*((n-k/2)/k+1)*((n-k/2)/k+1) : 0)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 #include <math.h>
 #include <string>
 using namespace std;
 
 int main(){
    string S,S_tmp;
    int i, S_l, tmp;
    int ans = 10000;

    cin >> S;
    S_l = S.length();

    for (i=0; i<S_l-2; i++){
        S_tmp = S.substr(i, 3);
        tmp = stoi(S_tmp);
        if(ans > abs(753-tmp))
            ans =  abs(753-tmp);
    }

    cout << ans << endl;
    return 0;
 }
 



Measured memory_bytes: 256
import sys
import numpy as np

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

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

N, D = lr()
X = np.array([lr() for _ in range(N)])
answer = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = (((X[i] - X[j]) ** 2).sum()) **.5
        if is_integer_num(a):
            answer += 1

print(answer)


Measured memory_bytes: 12448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	ll n; cin >> n;
	bool f = false;
	for(int i = 0; i < n; ++i){
		ll a; cin >> a;
		if (a % 2 != 0) f = true;
	}
	string ans = "second";
	if (f) ans = "first";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab=[]
for _ in range(M):
    ab.append(tuple(map(int, input().split())))
#print(ab)

from_1=set([el[1] for el in ab if el[0]==1])
from_N=set([el[0] for el in ab if el[1]==N])
#print(from_1, from_N)
if from_1 & from_N:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 93524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

struct Card{
   char ch;
   int num;
};

Card A[100'000]; //For Merge
Card B[100'000]; //For Quick 
Card L[100'000/2+1], R[100'000/2+1];

int partition(int p, int r){
   int x=B[r].num;
   int i=p-1;
   for(int j=p; j<r; j++){
      if(B[j].num<=x){
         i++;
         Card tmp=B[i]; B[i]=B[j]; B[j]=tmp;
      }
   }
   Card tmp=B[i+1]; B[i+1]=B[r]; B[r]=tmp;
   return i+1;
}

void Quick_Sort(int p, int r){
   if(p < r){
      int q = partition(p, r);
      Quick_Sort(p, q-1);
      Quick_Sort(q+1, r);
   }
}

//StableSort!
void Merge(int left, int mid, int right){
   int n1=mid-left;
   int n2=right-mid;
   int i, j, k;

   for(i=0; i<n1; i++) L[i]=A[left+i];
   for(i=0; i<n2; i++) R[i]=A[mid+i];
   L[n1].num=1000000000;
   R[n2].num=1000000000;

   i = j = 0;
   for(k=left; k<right; k++){
      if(L[i].num<=R[j].num){
         A[k]=L[i];
         i++;
      }else{
         A[k]=R[j];
         j++;
      }
   }
}

void Merge_Sort(int left, int right){
   int mid, res=0;
   if(left+1<right){
      mid=(left+right)/2;

      Merge_Sort(left, mid);
      Merge_Sort(mid, right);
      Merge(left, mid, right);
   }
}

int main(){
   int n;
   cin >> n;
   for(int i=0; i<n; i++){
      cin >> A[i].ch;
      cin >> A[i].num;
      B[i].ch = A[i].ch;
      B[i].num = A[i].num;
   }

   Merge_Sort(0, n);
   Quick_Sort(0, n-1);

   bool stable = true;
   for(int i=0; i<n; i++){
      if(A[i].ch != B[i].ch) stable = false;
   }

   if(stable) cout << "Stable" << endl;
   else cout << "Not stable" << endl;
   for(int i=0; i<n; i++){
      cout << B[i].ch << " " << B[i].num << endl;
   }

   return 0;
}


Measured memory_bytes: 5368
#include <iostream>
using namespace std;
int main(void){

    string s;
    cin >> s;
    //cout << s[5] << s[4] << s[3] << s[4];
    if(s[5] == s[4] && s[3] == s[2]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256