akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#define MN 16
const int MOD=1e9+7;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
int a[MN+5];mint f[1<<MN],F[1<<MN],R[1<<MN],ans;
inline mint C(int n,int m){return n<m?0:F[n]*R[m]*R[n-m];}
int main()
{
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)scanf("%d",&a[i]);
	for(F[0]=i=1;i<1<<n;++i)F[i]=F[i-1]*i;
	for(--i,R[i]=~F[i];i--;)R[i]=R[i+1]*(i+1);
	for(f[0]=1<<n,i=m;i;--i)for(j=1<<n;--j;)for(k=0;k<n;++k)if(j&(1<<k))
		f[j]-=f[j^(1<<k)]*C((1<<n)-a[i]-(j^(1<<k)),(1<<k)-1)*F[1<<k];
	for(j=0;j<1<<n;++j)ans+=f[j]*F[(1<<n)-1-j];
	printf("%d",ans);
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
int dp[100010];
int main(){
    int n;
    cin >> n;
    vector<int> h(n + 1);
    dp[0] = 0;
    for (int i = 1;i <= n;i++){
        cin >> h[i];
    }
    dp[1] = 0;
    for (int i = 2;i <= n;i++){
        if (i == 2){
            dp[i] = abs(h[i] - h[i-1]);
            continue;
        }

        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 4048
#include <stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    for(i=0; i<H; i++){
      for(j=0; j<W; j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */


int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        string s;
        cin >> s;

        ll n = s.size();
        // dp[i][j] : i桁目までを観て、13で割った余りがjのものかず
        vvl dp(n + 1, vl(13));
        dp[0][0] = 1;

        for (ll i = 0; i < n; ++i) {
            ll now;
            if (s[i] == '?') now = -1;
            else now = s[i] - '0';

            for (ll j = 0; j < 10; ++j) {
                for (ll k = 0; k < 13; ++k) {
                    if (now == j) {
                        dp[i + 1][(k * 10 + now) % 13] += dp[i][k];
                    } else if (now == -1) {
                        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                    }
                }
            }
            for (ll j = 0; j < 13; ++j) dp[i + 1][j] %= mod;
        }
        cout << dp[n][5] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")

using namespace std;

#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileInOut freopen(inp,"r",stdin);freopen(out,"w",stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int,int>
#define ppiii pair< pair <int,int> ,int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const int mod=1e9+7;
int test=1;
/*-----------------------------------------------*/
void nathan_on_osu()
{
    FAST
    #ifndef ONLINE_JUDGE
    //FileInOut
    #endif // ONLINE_JUDGE
}
/*-----------------------------------------------*/

int n;
pair<ll,ll> a[200200];

bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.Y==b.Y) return a.X<b.X;
    return a.Y<b.Y;
}

int main()
{
    nathan_on_osu();
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i].X>>a[i].Y;
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=a[i].X;
        if(sum>a[i].Y)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


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

int A;
int B;

int main()
{
	cin >> A;
	cin >> B;

	if( A %3==0 || B %3==0 || (A + B) %3==0)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
	}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        int V[] = new int[N];
        int C[] = new int[N];
        for (int i = 0; i < N; i++) {
            V[i] = sc.nextInt();
        }
        sc.nextLine();
        for (int i = 0; i < N; i++) {
            C[i] = sc.nextInt();
        }
        sc.close();

        int max = 0;
        for (int i = 0; i < N; i++) {
            if (V[i] > C[i]) {
                max += V[i] - C[i];
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    ll n, x; cin >> n >> x;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    ll ans = 0;
    rep(i,n){
        ans += max(0LL,ar[i] - x);
        ar[i] = min(ar[i],x);
    }
    rep(i,n-1){
        ans += max(0LL,-x + ar[i] + ar[i+1]);
        ar[i+1] = min(ar[i+1],x - ar[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4032
from collections import deque

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
MOD = 10**9 + 7

d = deque([[0,0]])
n_pattern = [[0]*W for _ in range(H)]
n_pattern[0][0] = 1

while d:
    y, x = d.popleft()
    for new_y, new_x in ([int(y)+1, int(x)], [int(y), int(x)+1]):
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1 and a[new_y][new_x] == ".":
            if n_pattern[new_y][new_x] > 0:
                once_updated_flg = 1
            else:
                once_updated_flg = 0
            n_pattern[new_y][new_x] += n_pattern[y][x]
            n_pattern[new_y][new_x] %= MOD
            if once_updated_flg == 0:
                d.append([new_y, new_x])

print(n_pattern[H-1][W-1])

Measured memory_bytes: 102748
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int N;

void solve(string);

signed main(){
  cin >> N;

  solve("a");

  return 0;
}

void solve(string s) {
  if (s.length() >= N) {
    cout << s << endl;
    return;
  }

  char last = s[s.length() - 1];

  char max = s[0];
  int i;
  for (i = 0; i < s.length() - 1; i++) {
    if (max < s[i]) max = s[i];
  }

  for (char ci = 'a'; ci <= last + 1 || ci <= max + 1; ci++) {
    string next_s = s + ci;
    solve(next_s);
  }
}

Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 3000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
} f;

int dp[3001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N, S;
	scanf("%d %d", &N, &S);

	int A[3001] = {};
	rep(i, N) {
		int a;
		scanf("%d", &a);
		A[a]++;
	}

	ll k2 = modpow(2, mod - 2);
	dp[0] = modpow(2, N);
	int s = 0;
	ll kotae1 = 0, kotae2 = 0;
	rep1(a, S) {
		if (A[a] == 1) {
			s = min(S - a, s + a);
			if (S >= a) kotae1 += dp[S - a];
			for (int j = s; j >= a; j--) {
				dp[j] = (dp[j] + dp[j - a] * k2) % mod;
			}
		}
		else if (A[a]) {
			int B[3001];
			B[0] = 1;
			rep1(b, A[a]) {
				B[b] = k2 * B[b - 1] % mod * (A[a] - b + 1) % mod * f.inv[b] % mod;
			}

			s = min(S - a, s + a * A[a]);
			if (S >= a) {
				for (int b = 1; S - a * b >= 0 && b <= A[a]; b++) {
					kotae2 += ll(dp[S - a * b]) * B[b] % mod;
				}
			}
			for (int j = s; j >= a; j--) {
				ll tmp = dp[j];
				for (int b = 1; j - a * b >= 0 && b <= A[a]; b++) {
					tmp += ll(dp[j - a * b]) * B[b] % mod;
				}
				dp[j] = tmp % mod;
			}
		}
	}

	printf("%lld\n", (kotae1 % mod * k2 + kotae2) % mod);

	Would you please return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
struct P{
    int x,y;
    const bool operator < (const P &b){
        if(x!=b.x) return x<b.x;
        else return y<b.y;
    }
};
int main()
{
   int n;
   cin>>n;
   P p[n];
   for(int i=0;i<n;i++){cin>>p[i].x>>p[i].y;}
   sort(p,p+n);
   for(int i=0;i<n;i++){cout<<p[i].x<<" "<<p[i].y<<"\n";}


}


Measured memory_bytes: 3896
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Player p1 = new Player();
        Player p2 = new Player();
        Game game = new Game(p1,p2);
        game.setTime(sc.nextInt());
        while(true){
            if(game.checkZero()){
                break;
            }
            p1.clear();
            p2.clear();
            for(int i=0; i<game.getTime();i++) {
                sc.reset();
                p1.setCardNumber(sc.nextInt());
                p2.setCardNumber(sc.nextInt());
                game.game();
            }
            game.showResult();
            game.setTime(sc.nextInt());
        }
    }
}

class Player{

    private int score;
    private int cardNumber;

    int getScore(){
        return this.score;
    }

    int getCardNumber(){
        return this.cardNumber;
    }

    void setCardNumber(int cardNumber){
        this.cardNumber = cardNumber;
    }

    void addScore(int score){
        this.score += score;
    }

    void clear(){
        this.cardNumber = 0;
        this.score = 0;
    }
}

class Game{

    private int time;
    private boolean zero;

    Player p1;
    Player p2;

    Game(Player p1, Player p2){
        this.p1 = p1;
        this.p2 = p2;
    }
    void setTime(int time){
        this.time = time;
    }
    int getTime(){
        return this.time;
    }

    void game(){
        if(p1.getCardNumber()>p2.getCardNumber()){
            p1.addScore(p1.getCardNumber() + p2.getCardNumber());
        }else if(p2.getCardNumber()>p1.getCardNumber()){
            p2.addScore(p1.getCardNumber() + p2.getCardNumber());
        }else{
            p1.addScore(p1.getCardNumber());
            p2.addScore(p2.getCardNumber());
        }
    }

    void showResult(){
        System.out.println(p1.getScore() + " " + p2.getScore());
    }

    boolean checkZero(){
        if(this.time == 0){
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 59040
#include <stdio.h>
int main()
{
	int a,n,cnt=1;
	char s[100000];
	scanf("%d",&n);
	getchar();
	for(a=0;a<n;a++){
		scanf("%c",&s[a]);
	}
	for(a=0;a<n-1;a++){
		if(s[a]!=s[a+1]){
			cnt++;
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int a, b;
	cin >> a >> b;
	if(a+b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
h, w, m = map(int, input().split())

h_b_list = [0 for i in range(h)]
w_b_list = [0 for i in range(w)]

targets = set()
for i in range(m):
  bh, bw = map(int, input().split())
  targets.add((bh, bw))
  h_b_list[bh-1] += 1
  w_b_list[bw-1] += 1
  
h_max = max(h_b_list)
w_max = max(w_b_list)

h_cans = []
w_cans = []
for i in range(h):
  if h_b_list[i] == h_max:
    h_cans.append(i)
    
for i in range(w):
  if w_b_list[i] == w_max:
    w_cans.append(i)

for hi in h_cans:
  for wi in w_cans:
    if (hi+1, wi+1) not in targets:
      print(h_max+w_max)
      exit()
else:
  print(h_max+w_max-1)



Measured memory_bytes: 158880
package main

import (
	"fmt"
)

func main() {
	var n byte
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	sRune := []rune(s)

	for _, c := range sRune {
		rot := (byte(c)-'A'+n)%26 + 'A'
		fmt.Printf("%s", string(rot))
	}
}


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

int mat[25][25];

typedef long long ll;

ll dp[1 << 21];

const ll mod = 1e9 + 7;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n ; i++)
    {
        for(int j = 0; j < n; j++)
        {
            scanf("%d",&mat[i][j]);
        }
    }
    
    dp[0] = 1;

    for(int mask = 1; mask < (1 << n) ; mask++)
    {
        int pos = __builtin_popcount(mask) - 1;
        for(int i = 0; i < n ; i++)
        {
            if(mask & ( 1 << i ) && mat[pos][i])
            {
                dp[mask] += dp[mask ^ (1 << i)];
                dp[mask] %= mod;
            }
        }
    }
    printf("%lld\n",dp[(1 << n) - 1]);



    return 0;
}

Measured memory_bytes: 16640
// Try DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let x = get!();
    let y = get!();
    
    let mut prize = if x == 1 && y == 1 { 400000 } else { 0 };
    
    prize += match x {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    
    prize += match y {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    
    println!("{}", prize);
}

Measured memory_bytes: 4352
# coding: utf-8
# Your code here!
import bisect

N=input()
S=input()

R=[]
G=[]
B=[]
for i in range(len(S)):
    if S[i]=="R":
        R.append(i)
    elif S[i]=="G":
        G.append(i)
    else:
        B.append(i)

ans=0

def calc(lis0,lis1,lis2):
    temp=0
    for l0 in lis0:
        for l1 in lis1:
            if l1<l0:
                continue
            start=bisect.bisect_right(lis2,l1)
            temp+=len(lis2)-start
            index=bisect.bisect_left(lis2,2*l1-l0)
            #if 2*l1-l0 in lis2:
            #    temp-=1
            if index!=len(lis2):
                if lis2[index]==2*l1-l0:
                    temp-=1
    return temp

ans=calc(R,G,B)+calc(R,B,G)+calc(G,R,B)+calc(G,B,R)+calc(B,R,G)+calc(B,G,R)
            
print(ans)


    



Measured memory_bytes: 81528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

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

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
using namespace std; 
typedef long long ll ;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;
    cin >> a >> b >> c;
    ll d=c-a-b ;
    if(d > 0 && d*d > 4*a*b) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, M; string S;
set<int> E[201010];
int ok[201010], ok2[201010];
int acnt[201010], bcnt[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> S;
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].insert(b);
        E[b].insert(a);
    }

    rep(cu, 0, N) {
        int a = 0, b = 0;
        fore(to, E[cu]) {
            if (S[to] == 'A') a++;
            else b++;
        }
        if (a and b) ok[cu] = 1;
    }

    rep(i, 0, 4) {
        rep(cu, 0, N) ok2[cu] = ok[cu];

        queue<int> ng;
        rep(cu, 0, N) if (ok[cu]) {
            fore(to, E[cu]) if (ok2[to]) {
                if (S[to] == 'A') acnt[cu]++;
                else bcnt[cu]++;
            }
            if (acnt[cu] == 0 or bcnt[cu] == 0) {
                ng.push(cu);
                ok[cu] = 0;
            }
        }

        while (!ng.empty()) {
            int cu = ng.front(); ng.pop();

            fore(to, E[cu]) if (ok[to]) {
                if (S[cu] == 'A') acnt[to]--;
                else bcnt[to]--;

                if (acnt[to] == 0 or bcnt[to] == 0) {
                    ng.push(to);
                    ok[to] = 0;
                }
            }
        }
    }

    

    int ans = 0;
    rep(cu, 0, N) if (ok[cu]) ans = 1;

    if (ans) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 30928
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
const long long INF = 1LL<<60;

int main(){
	int n; cin >>n;
	vector<string> s(n);
	cinf(n,s);
	int cnt[n][26];
	for(int i=0;i<n;i++){
		for(int j=0;j<26;j++){
			cnt[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<s[i].size();j++){
			cnt[i][s[i][j]-'a']++;
		}
	}
	for(int i=0;i<26;i++){
		int Min=cnt[0][i];
		for(int j=0;j<n;j++){
			Min=min(cnt[j][i],Min);
			if(Min==0)break;
		}
		for(int j=0;j<Min;j++){
			cout << (char)('a'+i);
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
fn main()
{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim();
    
    let mut ans = true;
    for (i,c1) in buf.chars().enumerate() {
        for (j,c2) in buf.chars().enumerate() {
            if i!=15 && j!=15 && i!=j && c1==c2 { ans = false; }
        }
    }
    
    if ans {
        println!("yes");
    } else {
        println!("no");
    }
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 998244353;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

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

  if (ds[0] != 0) {
    cout << 0 << endl;
    return 0;
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

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

  vector<int> d_to_count(n);
  for (int d : ds) d_to_count[d]++;

  FiniteField solution = 1;
  for (int i = 1; i < n; i++) {
    if (ds[i] == 0) solution *= 0;
    else solution *= d_to_count[ds[i] - 1];
  }
  cout << solution.Value() << endl;
}

Measured memory_bytes: 1024
def gcd(a,b):
    if(a==0):
        return b
    return gcd(b%a,a)

n=int(input())
a=[int(i) for i in input().split()]

pre=[0,a[0]]
suf=[0]*(n+1)
suf[n-1]=a[-1]
for i in range(1,len(a)):
    pre.append(gcd(pre[-1],a[i]))
for i in range(len(a)-2,-1,-1):
    suf[i] = gcd(suf[i+1],a[i])
ans=1
for i in range(len(a)):
    ans = max(ans,gcd(pre[i],suf[i+1]))
print(ans)


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

int main() {
  int N, K;
  cin >> N;
  cin >> K;
  vector<int> A(N);
  vector<int> flash;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  rep(iterate, K) {
    flash = vector<int>(N, 0);
    rep(i, N) {
      int on = i - A[i];
      int off = i + A[i] + 1;
      if (on < 0) {
        flash[0] += 1;
      } else {
        flash[on] += 1;
      }
      if (off < N) {
        flash[off] -= 1;
      }
    }
    A[0] = flash[0];
    rep(i, N - 1) {
      A[i + 1] = A[i];
      A[i + 1] += flash[i + 1];
    }
    if (accumulate(A.begin(), A.end(), 0) == N * N) {
      break;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    cout << A.at(i) << " ";
  }
  cout << A.at(A.size() - 1) << endl;
}


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b; 
  cin >> a >> b;
  vector<int> A(2*b);
  for (int i=1;i<=a;i++) {
    int c=0;
    for(int j=0;j<2*b;j++) {
      cin >> A[j];
    if (A[j]==i)
      c++;
    }
    cout << c << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n,m; std::cin >> n >> m;
    std::vector<int> v(n,0), sc(n+1,-1);
    bool flag = true;
    for(int i=0; i<m; i++){
        int s,c; std::cin >> s >> c;
        if(s==1 && c==0 && n!=1){
            flag = false;
        }else if(sc[s]>=0 && sc[s]!=c){
            flag = false;
        }else{
            sc[s] = c;
        }
    }

    if(flag==false){
        std::cout << "-1" << "\n";
        return 0;
    }

    for(int i=0; i<n; i++){
        if(sc[i+1]>=0){
            v[i] = sc[i+1];
        }
    }

    if(v[0]==0 && n>1) v[0] = 1;
    for(int i=0; i<n; i++){
        std::cout << v[i];
    }
    std::cout << "\n";
    return 0;
}

Measured memory_bytes: 3576
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  f80 sum = 0;
  rep(i, n) sum += (f80) 1 / a[i];
  cout << ((f80) 1 / sum) << endl;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

struct Job {
  ll reward;
  ll day;
  bool used;
};

int main(int argc, char* argv[]) {
  ll n, m;
  cin >> n >> m;
  map<ll, vector<ll>> jobs;
  rep(i, 0, n) {
    ll d, c;
    cin >> d >> c;
    jobs[d].push_back(c);
  }

  priority_queue<ll> q;
  ll ans = 0;

  auto first = begin(jobs);
  auto last = end(jobs);
  rep(i, 1, m + 1) {
    if ((*first).first <= i && first != last) {
      for (ll val : (*first).second) q.push(val);
      first++;
    }

    if (q.empty()) continue;
    ans += q.top();
    q.pop();
  }

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

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 12928
import fractions

A, B = map(int, input().split())

x = fractions.gcd(A, B)

ans = 1

for i in range(2, int(x**0.5)+2):
    n = 0
    while x % i == 0:
        x //= i
        n += 1
    if n != 0:
        ans += 1
if x != 1:
    ans += 1
print(ans)


Measured memory_bytes: 5560
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a;  //動的配列aを宣言
	vector<int> b;
	a.resize(n);    //aのサイズをｎに変更
	b.resize(n);
	for (int i = 0;i < n;i++) cin >> a[i];

	int j,k,buff;

	j = n - 1;
	k = 0;

	for (int i = 0;i < n;i++)
	{
		b[i] = a[j];

		if (k == 0)
		{
			if (j > 1)
			{
				j -= 2;
			}
			else if(j == 1)
			{
				k = 1;
				j--;
			}
			else
			{
				k = 1;
				j++;
			}
		}
		else
		{
			j += 2;
		}
	}

	for (int i = 0;i < n;i++)
	{
		cout << b[i];
		cout << " ";
	}

	return 0;
}


Measured memory_bytes: 3712
open System

[<EntryPoint>]
let main argv =
    let n = Console.ReadLine() |> int64
    let mutable ans = 0
    let rec solve x d =
        if d > n then x
        else solve (x + n / d) (d * 5L)
    printf "%d" (if n % 2L = 0L then (solve 0L 10L) else 0L)
    0


Measured memory_bytes: 13916
// https://beta.atcoder.jp/contests/abc112

#define SUBMIT

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> c;
    for (int i = 0; i < N; ++i) {
        int ci, ti;
        cin >> ci >> ti;
        if (ti <= T) c.push_back(ci);
    }

    if (c.empty()) cout << "TLE" << endl;
    else cout << *min_element(c.begin(), c.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5],pp[ten52],mm[ten52];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k,r=0;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
            r++;
    }
    cout<<r;
    return 0;
}





Measured memory_bytes: 3900
# -*- coding: utf-8 -*-
"""
Walking in the Hospital
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0217

"""
import sys


def solve(n):
    result = sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: x[1]+x[2])
    return result[-1][0], sum(result[-1][1:])


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 7984
def main():
	N = int(input().strip())
	alist = list(map(int,input().strip().split()))

	countmin = 10000
	for i in range(len(alist)):
		ai = alist[i]
		count = 0
		while ai%2==0:
			ai = ai/2
			count = count+1

		if count<countmin:
			countmin = count

	print(countmin)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
double dp[303][303][303];
int n;
double dpsolve(int a, int b, int c)
{
    if(a==0 and b==0 and c==0)
        return 0;
    if(dp[a][b][c]>0)
        return dp[a][b][c];
    double sum = (a+b+c);
    if(a!=0)
        dp[a][b][c]+= (double)a/sum * dpsolve(a-1, b,c);
     if(b!=0)
        dp[a][b][c]+= (double)b/sum * dpsolve(a+1, b-1,c);
     if(c!=0)
        dp[a][b][c]+= (double)c/sum * dpsolve(a, b+1,c-1);
     dp[a][b][c]+= (1.0*n)/sum;

     return dp[a][b][c];
}
int main()
{
    int one=0, two=0, three=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int temp;
        cin>>temp;
        if(temp==1)
            one++;
        else if(temp==2)
            two++;
        else
            three++;
    }

    dpsolve(one, two, three);
    cout<<setprecision(16)<<fixed<<dp[one][two][three];

    return 0;
}


Measured memory_bytes: 217344
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, x;
    cin >> x >> n;
    set<pair<int, int> > st;
    for(int i = -200; i <= 200; i++){
        st.insert({abs(x - i), i});
    }
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        st.erase(st.find({abs(k - x), k}));
    }
    cout << (*st.begin()).second;


    return 0;

}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main() {
	double n,m,s;
	while(cin>>n>>m>>s,n){
		int ans=0;
		n+=100;
		m+=100;
		for(int i=1;i<=s/2;i++){
			for(int j=1,x,y;i+j<=s;j++){
				x=i*n/100;
				y=j*n/100;
				if(x+y==s){
					x=i*m/100;
					y=j*m/100;
					ans=max(ans,x+y);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i = 0;i < n;++i)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = INF;
    rep(i,n-k+1) {
        ans = min(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
        ans = min(ans,abs(x[i+k-1])+abs(x[i+k-1]-x[i]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

ll a[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,q,x,y;
    cin>>n;
    while (n--)
    {
        cin>>x;
        ++a[x];
    }
    ll ans=0;
    for (int i=1;i<=100000;++i)
        ans+=a[i]*i;
    cin>>q;
    while (q--)
    {
        cin>>x>>y;
        ans+=a[x]*(y-x);
        a[y]+=a[x];
        a[x]=0;
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4420
#!/usr/bin/env python3
import sys
import networkx as nx

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    G=nx.Graph()

    if M == 0 :
        print(1)
        return

    for a, b in zip(A,B):
        G.add_edge(a, b)

    Gc = max(nx.connected_components(G), key=len)
    print(len(Gc))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 258428
N,t0,x0,y0,ans=int(input()),0,0,0,0
for _ in range(N):
    t,x,y=map(int,input().split())
    timerest=(t-t0)-(x+y-x0-y0)
    if timerest<0 or timerest%2==1:ans=1
    t0,x0,y0=t,x,y
if ans==0:print("Yes")
else:print("No")

Measured memory_bytes: 3064
#include <map>
#include <stdio.h>

std::map<long long,std::pair<long, long>> mp;

int main(){
    long n;
    long m;
    long p;
    long long y;
    long cnt[100010] = {0};
    long long yy[100010];

    scanf("%ld %ld", &n, &m);

    for(long i = 0; i < m; i++){
        scanf("%ld %lld", &p, &y);
        mp[y] = std::make_pair(p, i + 1);
    }

    for (const auto& [key, value] : mp){
        cnt[value.first]++;
        yy[value.second] = value.first * 1000000ll + cnt[value.first];
    }

    for(long i = 1; i < m+1; i++){
        printf("%012lld\n", yy[i]);
    }

    return 0;
}

Measured memory_bytes: 11104
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
const int N = 100006;

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

    if(s == "RRR") cout << "3\n"; 
    else if(s == "RRS" || s == "SRR") cout << "2\n"; 
    else if(s == "SSS") cout << "0\n"; 
    else cout << "1\n";
    

    return 0;
}

// 


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>

using namespace std;

#define INF 1000000007
using vi = vector<int>;
using vvi = vector< vector<int> >;
using pii = pair<int, int>;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  long long ans = 1;
  vi v(2*n);
  vi r;
  v[0] = 1;
  int now = 0;
  for(int i = 1; i < s.length(); i++){
    if(s[i] == s[i-1]){
      now = !now;
    }
    if(now){
      v[i] = v[i-1];
      ans *= v[i] - r.size();
      ans %= INF;
      r.push_back(i);
    }
    else{
      v[i] = v[i-1] + 1;
    }
  }
  for(int i = 0; i < n ; i++){
    ans *= (i+1);
    ans %= INF;
  }
  if(r.size() != n || s[0] == 'W' || s[2*n-1] == 'W') ans = 0;
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;



class Osa_k {
private:
	int n;
	vector<int> factor;
public:

	//O(NloglogN)
	Osa_k(int _n):n(_n) {
		factor.assign(n, 0);
		iota(factor.begin(), factor.end(), 0);
		for(int i = 2; i*i < n; i++) {
			if(factor[i] < i)continue;
			for(int j = i * i; j < n; j += i) {
				if(factor[j] == j)factor[j] = i;
			}
		}
	}

	//O(logV)
	unordered_map<int, int> sieve(int v) {
		unordered_map<int, int> ret;
		while(v != factor[v]) {
			ret[factor[v]]++;
			v /= factor[v];
		}
		if(v != 1)ret[v]++;
		return ret;
	}


	//O(N)
	vector<int> get_list() {
		vector<int> prime;
		for(int i = 2; i < n; i++)if(factor[i] == i)prime.emplace_back(i);
		return prime;
	}

	//O(1)
	bool is_prime(int v) {
		if(v <= 1)return false;
		return (factor[v] == v);
	}

}fact(10000001);


int main()
{
	int n; cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++) {
		auto v = fact.sieve(i);
		ll ans = 1;
		for(auto j : v)ans *= j.second+1;
		sum += ans * i;
	}
	cout << sum << endl;
}

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

//42
typedef long long ll;

int main() {
	int n, k , q;
	cin >> n >> k >> q;
	vector<int> v(n);
	for (int i = 0; i < q; ++i) {
		int x;
		cin >> x;
		x--;
		v[x]++;
	}
	vector<int> ans(n);
	for (int i = 0; i < n; ++i) {
		ans[i] = -q + v[i] + k;
	//	cout << ans[i] << " ";
	}
	for (int i = 0; i < n; ++i) {
		if (ans[i] > 0) cout << "Yes\n";
		else cout << "No\n";
	}
}


Measured memory_bytes: 4040
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
#define int long long 
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
int N , W, w[maxn],v[maxn],dp[105][100005];
int32_t main()
{
    cin >> N >> W;
    for(int i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= N;i++){
        for(int j = 1; j <= W;j++){
            if(w[i] <= j){
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
                // printf("dp[i-1][j-w[i]]+v[i] === %d\n",dp[i-1][j-w[i]]+v[i]);
                // printf("p[%d][%d]==%d\n",i,j,dp[i][j]);
            }else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W];
}

Measured memory_bytes: 83456