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

using namespace std;
typedef long long ll;

int main(){
	int n, tmp;
	ll sum = 0;
	cin >> n;
	map<int, int> a;
	for(int i = 0; i<n ;i++){
		cin >> tmp;
		sum+=tmp;
		a[tmp]++;
	} 
	int k, b, c;
	cin >> k;
	while(k){
		cin >> b >> c;
		sum += 1ll * (c - b)* a[b];
		cout << sum << endl;
		
		a[c] += a[b];
		a[b] = 0;
		k--;
	}
	return 0;
}


Measured memory_bytes: 8056
#include <iostream>
#include <vector>
#include <cstdlib>  // abs() for integer
using namespace std;

int main(){
  int N;
  vector<int> t, x1, x2;

  cin >> N;
  t = vector<int>(N, 0);
  x1 = vector<int>(N, 0);
  x2 = vector<int>(N, 0);

  for (int i = 0; i < N; i++){
    cin >> t[i] >> x1[i] >> x2[i];
  }

  if(t[0] < (abs(x1[0]) + abs(x2[0]))){
    cout << "No" << endl;
    return 0;
  }else if((t[0] % 2) != ((abs(x1[0]) + abs(x2[0])) % 2)){
    cout << "No" << endl;
    return 0;
  }

  for (int i = 1; i < N; i++){
    if((t[i] - t[i-1]) < (abs(x1[i] - x1[i-1]) + abs(x2[i] - x2[i-1]))){
      cout << "No" << endl;
      return 0;
    }else if(((t[i] - t[i-1]) % 2) != ((abs(x1[i] - x1[i-1]) + abs(x2[i] - x2[i-1])) % 2)){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

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

int main(){
  
  int n,i,j;
  cin>>n;
  cin>>i;
  cin>>j;
  int f=0;
  for(int k=i;k<=j;k++){
    if(k%n==0){
      f=1;
      break;
    }
  }
  if(f==1){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
//1-indexed
class BIT {
public:
    ll n;
    vector<ll> bit;
    BIT(ll n):n(n),bit(n+1,0){}

    void add(ll i,ll x){
        if(i==0) return;
        for(ll k=i;k<=n;k+=(k & -k)){
            bit[k]+=x;
        }
    }

    ll sum(ll i){
        ll s=0;
        if(i==0) return s;
        for(ll k=i;k>0;k-=(k & -k)){
            s+=bit[k];
        }
        return s;
    }

    ll lower_bound(ll x){
        if(x<=0){
            return 0;
        }else{
            ll i=0;ll r=1;
            while(r<n) r=r<<1;
            for(int len=r;len>0;len=len>>1) {
                if(i+len<n && bit[i+len]<x){
                    x-=bit[i+len];
                    i+=len;
                }
            }
            return i+1;
        }
    }
};

// 答えはv以下か
bool check(const vector<ll>& a, ll v) {
    ll n = a.size();

    // v以上のものが半数以上あるか
    // bの部分列で和が0以上になるなら半数以上
    vector<ll> b(a.size() + 1);
    rep(i, a.size()) b[i+1] = a[i] >= v ? 1 : -1;


    vector<ll> c(a.size() + 1);
    rep(i, a.size()) c[i+1] = c[i] + b[i+1];

    // c[i] <= c[j] となるような(i,j)の組み合わせ。BITで求められる
    BIT bit(2 * a.size() + 1);

    // 中央値がv以上になるi,jの組み合わせ
    ll sum = 0;
    rep(j, n + 1) {
        sum += bit.sum(n + c[j]); // 自分より左にいて、自分以下のものの数
        bit.add(n + c[j], 1);
    }

    bool ok = sum >= n * (n+1) / 4;
    return ok;
}

void Main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> s = a;
    sort(all(s));

    ll left = 0, right = a.size();

    while (right - left > 1) {
        ll k = (right + left) / 2;
        if (check(a, s[k])) {
            left = k;
        }
        else { 
            right = k;
        }
    }

    put(s[left]);
}
signed main(){ Main();return 0;}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,x = LI()
    a = sorted(LI(),reverse=True)
    d = collections.defaultdict(int)
    d[x] = 1
    for i in range(n):
        c = a[i]
        e = collections.defaultdict(int)
        for k,v in d.items():
            e[k] += v * (n-i-1)
            e[k] %= mod
            e[k%c] += v
            e[k%c] %= mod

        d = e

    r = 0
    for k,v in d.items():
        r += k * v
        r %= mod

    return r


print(main())




Measured memory_bytes: 7532
#include<bits/stdc++.h>
using namespace std;
const int maxn=200;
int n,Last[maxn],f[maxn];
char ch[maxn];
int idx(char c)
{
	return c-'a';
}
int main()
{
	cin>>ch;
	n=strlen(ch);
	memset(Last,-1,sizeof(Last));
	for (int i=0;i<n;i++)
	{
		int c=idx(ch[i]);
		f[c]=max(f[c],i-Last[c]-1);
		Last[c]=i;
	}
	for (int i=0;i<26;i++) f[i]=max(f[i],n-Last[i]-1);
	int ans=n;
	for (int i=0;i<26;i++) ans=min(ans,f[i]);
	cout<<ans;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
using ll = long long;

const int MOD = 1000000007;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
    int x = a.n + b.n;
    return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
    int x = a.n - b.n;
    return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
    for (int i = I_.size(); i <= n; i++) {
        I_.push_back(I_[MOD % i] * (MOD - MOD / i));
        F_.push_back(F_[i - 1] * i);
        R_.push_back(R_[i - 1] * I_[i]);
    }
}

mint I(int n) {
    check_fact(abs(n));
    return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
    check_fact(n);
    return n < 0 ? 0 : F_[n];
}
mint R(int n) {
    check_fact(n);
    return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        cout << H(i, K - i) * H(i + 1, N - K - (i - 1)) << '\n';
    }
}


Measured memory_bytes: 256
a, b, c, d = list(map(int, input().split()))
list = sorted([a, b, c, d])
if list[0] == a and list[1] == b or list[2] == c and list[3] == d:
    print(0)
elif list[0] == c and list[1] == d or list[2] == a and list[3] == b:
    print(0)
else:
    print(list[2] - list[1])

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MAXN = 200005;
int a[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  while (k--) {
    vector<int> cnt(n + 5, 0);
    for (int i = 1; i <= n; i++) {
      cnt[max(1, i - a[i])]++;
      cnt[min(n, i + a[i]) + 1]--;
    }
    bool diff = false;
    for (int i = 1; i <= n; i++) {
      cnt[i] += cnt[i - 1];
      a[i] = cnt[i];
      if (a[i] != n) diff = true;
    }
    if (!diff) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 5252
#include <stdio.h>

int main(){
  int A[1000];
  int N,i;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]%2==0){
      if(A[i]%3!=0 && A[i]%5!=0){
        printf("DENIED");
        return 0;
      }
    }
  }
  printf("APPROVED");
  return 0;
}

Measured memory_bytes: 128
from collections import defaultdict, deque

V, E = map(int, input().split())
G = defaultdict(list)

for i in range(E):
    s, t = map(int, input().split())
    G[s].append(t)

ans = deque([])
visited = defaultdict(bool)
def visit(v):
    if visited[v]: return
    visited[v] = True
    for k in G[v]:
        visit(k)
    ans.appendleft(v)

for v in range(V):
    visit(v)

print('\n'.join(map(str, ans)))

Measured memory_bytes: 12440
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

if len(a) % 2 != 0:
    a.append(0)

print(sum(a[0::2]) - sum(a[1::2]))


Measured memory_bytes: 61816
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second


signed main(){
	
	bool is_exist[1000001] = {false};
	ll s,i = 1;
	cin >> s;
	
	is_exist[s] = true;
	
	while(true){
		i++;
		if(s % 2){
			s = 3*s+1;
			if(is_exist[s]){
				cout << i << endl;
				return 0;
			}
			is_exist[s] = true;
		}
		else{
			s = s/2;
			if(is_exist[s]){
				cout << i << endl;
				return 0;
			}
			is_exist[s] = true;
		}
	}
	
	
	return 0;

}

Measured memory_bytes: 1280
#include<stdio.h>

void depthfs(void);

void visit(int);

#define MAX 109

#define WHITE 0
#define GRAY 1
#define BLACK 2

int graph[MAX][MAX];

int n;
int time;
int d[MAX],f[MAX];
int color[MAX];

int main(){
  int num,i;
  int u,j,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){    
      graph[i][j] = 0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&num);
    for(j=0;j<num;j++){
      scanf("%d",&v);
      graph[u][v] = 1;
    }
  }

  depthfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  
  return 0;

}

void depthfs(void){
  int i;
  //for each vertex u in V
  for(i=1;i<=n;i++){
  color[i] = WHITE;
  d[i] = 0;
  f[i] = 0;
  }

  time= 0;

  //for each vertex u in V
  for(i=1;i<=n;i++){
  if(color[i] == WHITE) visit(i);
  }

}

void visit(int x){
  int i;

  color[x] = GRAY;//white vertex u has just been discovered

  d[x] = ++time;

  //for each v in adj[u] //explore edge(u,v)

  for(i=1;i<=n;i++){
    if(graph[x][i] == 1){
      if(color[i] == WHITE) visit(i);
    }
  }

  color[x] = BLACK; //blacken u; it is finished

  f[x] = ++time;
  
}



Measured memory_bytes: 2740
N=int(input())
t1=0
x1=0
y1=0
out='Yes'
for i in range(N):
  t2, x2, y2=map(int, input().split())
  if (t2-t1)%2!=(abs(x2-x1)+abs(y2-y1))%2 or (t2-t1)<abs(x2-x1)+abs(y2-y1):
    out='No'
  t1=t2
  x1=x2
  y1=y2
print(out)

Measured memory_bytes: 47064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main (){
    int A,B,C,D,E,max;
    cin >> A >>B;
    C=A+B;
    D=A-B;
    E=A*B;
    if(C>=D&&C>=E){
        max=C;
    }
    else if(D>=E&&D>=C){
        max=D;
    }
    else{
        max=E;
    }
    cout << max << endl;
    return 0;

}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI h(n);
	rep(i, n) cin >>h[i];
	int ans =0;
	rep2(i, 1, 101){
		bool csw=false;
		rep(j, n){
			if(h[j] >= i && !csw){ans++; csw=true;}
			if(h[j] < i && csw){ csw = false;}
		}
	}
	cout <<ans <<"\n";
	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);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();
		boolean one = B.substring(0, 1).equals(A.substring(A.length() - 1, A.length()));
		boolean two = C.substring(0, 1).equals(B.substring(B.length() - 1, B.length()));
		if(one && two) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22996
N = int(input())
ans = 'No'
count =0
for i in range(N):
    d1,d2 = list(map(int,input().split()))
    if d1!=d2:
        count =0
    else:
        count +=1
    if count ==3:
        ans = 'Yes'
        break #count3達したら終了させる
print(ans)

Measured memory_bytes: 9044
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K;
string s;
int main() {
	cin >> N >> s >> K; K--;
	REP(i, N) {
		if (s[i] != s[K]) s[i] = '*';
	}
	cout << s << endl;
}


Measured memory_bytes: 3596
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------


n,m = mapi()
h = list(mapi())
g = defaultdict(list)
for i in range(m):
    x,y= mapi()
    g[x].append(y)
    g[y].append(x)
res = 0
for i in range(1,n+1):
    tmp = h[i-1]
    f = 1
    for j in g[i]:
        if tmp<=h[j-1]:
            f =0
            break
    if f:res+=1
print(res)


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

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

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main()
{
  int n,i,ans=1,ans1=0;
  cin>>n;
  for(i=1;i<=n;i++)
    cin>>a[i];
  sort(a+1,a+n+1);
  for(i=2;i<=n;i++)
    {
      if(a[i]==a[i-1])
	    ans=(ans+1)%2;
      else
	  {
	    ans1+=ans;
		ans=1;	
	  }
    }
  if(ans%2!=0)
    ans1++;
  cout<<ans1<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;
typedef bitset<1024> bs;

ll n, m, ans, dp[2][10000000], k2[500];
char s[500][501];
bitset<1024> k[500], d, zero;
const ll INF = 100000000000LL;

void dfs(ll num, ll sum) {
  if (n == num) {
    if (d == 0) ans = max(ans, sum);
    return;
  }
  dfs(num+1, sum);
  d = d xor k[num];
  dfs(num+1, sum + 1);
  d = d xor k[num];
}

int main() {
  while (scanf("%lld%lld", &n, &m), n) {
    for (ll i = 0; i < n; i++) scanf("%s", s[i]);
    if (n <= 25) {
      for (ll i = 0; i < n; i++) k[i] = bs(s[i]);
      ans = 0;
      dfs(0, 0);
      printf("%lld\n", ans);
    } else {
      for (ll i = 0; i < n; i++) {
        k2[i] = 0;
        for (ll j = 0; j < m; j++) {
          k2[i] <<= 1;
          if (s[i][j] == '1') k2[i]++;
        }
      }
      for (ll i = 0; i < 1<<m; i++) dp[0][i] = dp[1][i] = -INF;
      dp[0][0] = 0;
      for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < 1<<m; j++) {
          dp[(i+1)&1][j] = max(dp[i&1][j], dp[i&1][j xor k2[i]] + 1);
        }
      }
      printf("%lld\n", dp[n&1][0]);
    }
  }
}



Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

struct edge{
    int from,to,dist;
    edge(){}
    edge(int f,int t,int d) : from(f),to(t),dist(d){}
};

int main(){
    int N,M;cin >> N >> M;
    vi L(M),R(M),D(M);
    vector<vector<edge>> G(N);
    rep(i,M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
        G[L[i]].emplace_back(edge(L[i],R[i],D[i]));
        G[R[i]].emplace_back(edge(R[i],L[i],-D[i]));
    }

    vector<bool> visited(N,false);
    vector<ll> x(N,0);

    queue<int> que;
    for(int i=0;i<N;i++){
        if(!visited[i]){
            visited[i] = true;
            x[i] = 0;
            que.push(i);
        }
        while(!que.empty()){
            int i = que.front();
            que.pop();

            for(const auto& e :  G[i]){
                int j = e.to;
                int d = e.dist;
                if(visited[j]){
                    if(x[j] != x[i] + d){
                        cout << "No" << endl;
                        return 0;
                    }
                }else{
                    x[j] = x[i] + d;
                    visited[j] = true;
                    que.push(j);
                }
            }
        }
    }

    ll min = (1ll << 60);
    rep(i,N){
        min = std::min(min,x[i]);
    }
    rep(i,N){
        x[i] += min;
    }
    rep(i,N){
        if(x[i] > 1e9){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll N, W; cin >> N >> W;
	vector<ll> w(N), v(N);
	for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
	for(int i = 0; i <= N; i++) for(int j = 0; j <= W; j++) dp[i][j] = -INF;
	for(int i = 0; i <= N; i++) dp[i][0] = 0;
	for(int i = 0; i <= W; i++) dp[0][i] = 0;
	for(int s = 1; s <= N; s++) {
		for(int t = 1; t <= W; t++) {
			dp[s][t] = dp[s - 1][t];
			if(t - w[s - 1] >= 0) {
				dp[s][t] = max(max(dp[s][t], dp[s - 1][t - w[s - 1]] + v[s - 1]), dp[s - 1][t]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 83172
#define LL long long
#include<iostream>
using namespace std;

int main(){
	LL x,a,b;
	cin>>x>>a>>b;
	auto n=[&x,&a,&b](){
		if(a-b>=0){
			cout<<"delicious"<<endl;
		}else if(b-a>0 && x>=b-a){
			cout<<"safe"<<endl;
		}else{
			cout<<"dangerous"<<endl;
		}
	};
	n();
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define INF 1000001

int main(void){
	int i, j, n ,c, small1, small2;
	int dp1[1000000],dp2[1000000];
	scanf("%d",&n);
	while(n != 0){
		for(i = 0;i <= n;i++)
			dp1[i] = dp2[i] = INF;
		dp1[0] = dp2[0] = 0;
		for(i = 0;i < n;i++){
			small1 = dp1[n];
			if(small1 > dp1[i] + 1 && dp1[i] != INF){
				for(j = 1,c = j * (j + 1) * (j + 2);c / 6 + i <= n;j++,c = j * (j + 1) * (j + 2)){
					if(dp1[c / 6 + i] > dp1[i] + 1 && dp1[i] != INF){
						dp1[c / 6 + i] = dp1[i] + 1;
					}
				}
			}
		}
		for(i = 0;i < n;i++){
			small2 = dp2[n];
			if(small2 > dp2[i] + 1 && dp2[i] != INF){
				for(j = 1,c = j * (j + 1) * (j + 2);c / 6 + i <= n;j++,c = j * (j + 1) * (j + 2)){
					if(dp2[c / 6 + i] > dp2[i] + 1 && (c / 6) % 2 == 1 && dp2[i] != INF)
						dp2[c / 6 + i] = dp2[i] + 1;
				}
			}
		}
		printf("%d %d\n",dp1[n],dp2[n]);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 8720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n=sz(s);
  string t="";
  if(sz(s)%2==1){
    cout << "No" << endl;
    return 0;
  }
  rep(i,n){
    if(i%2==0) t+="h";
    else t+="i";
  }
  //cout << t << endl;
  rep(i,n){
    if(s[i]!=t[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
        int input_sec;
        int hour, minute, second;
        scanf("%d", &input_sec);

        hour = input_sec / 3600;
        minute = (input_sec % 3600) / 60;
        second = input_sec % 60;

        printf("%d:%d:%d\n", hour, minute, second);

        return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin>>N;
    vector<ll> x(N),y(N);
    
    rep(i,N){
        cin>>x[i]>>y[i];
    }
    int res=N;
    rep(i,N){
        rep(j,N){
            if(i==j)continue;
            ll p = x[i]-x[j];
            ll q = y[i]-y[j];
            int cnt=0;
            rep(k,N){
                rep(l,N){
                    if(k==l)continue;
                    if(x[l]-x[k]==p&&y[l]-y[k]==q){
                        cnt++;
                    }
                }
            }
            res = min(res,N-cnt);
        }
    }
    if(N==1){
        cout<<"1";
    }else{
        cout<<res;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vector<bool> dp(MOD, false);
  ll count = 0;
  rep(i,n){
    ll a;
    cin >> a;
    if(dp[a]){
      dp[a] = false;
      count--;
    }
    else{
      dp[a] = true;
      count++;
    }
  }
  print(count);
}

Measured memory_bytes: 125200
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007  

int main(){
    int W, H;
    cin >> W >> H;
    vector<ll> P(W), Q(H);
    for(int i = 0; i < W; i++) cin >> P[i];
    for(int i = 0; i < H; i++) cin >> Q[i];
    sort(P.begin(), P.end());
    vector<ll> P_acc(W);
    P_acc[0] = P[0];
    for(int i = 1; i < W; i++){
        P_acc[i] = P_acc[i - 1] + P[i];
    }
    ll ans = P_acc[W - 1];
    for(int i = 0; i < H; i++){
        if(Q[i] < P[0]) ans += Q[i] * (W + 1);
        else{
            auto iter = upper_bound(P.begin(), P.end(), Q[i]);
            ll idx = iter - P.begin();
            idx--;
            ans += P_acc[idx];
            ans += Q[i] * (W - idx);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
map<int,set<int> > brd[200010];
int fad[200010],fal[200010];
int get(int *a,int i){
	return (a[i]==i)?i:a[i]=get(a,a[i]);
}
bool sameset(int *a,int i,int j){
	return (get(a,i)==get(a,j));
}
void unite(int *a,int i,int j){
	a[get(a,i)]=get(a,j);
}
int main(void){
	for (int i=1;i<=200000;i++){
		fad[i]=fal[i]=i;
	}
	int n,k,l;
	scanf("%d%d%d",&n,&k,&l);
	for (int i=1;i<=k;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		unite(fad,a,b);
	}
	for (int i=1;i<=l;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		unite(fal,a,b);
	}
	for (int i=1;i<=n;i++){
		brd[get(fad,i)][get(fal,i)].insert(i);
	}
	for (int i=1;i<=n;i++){
		printf("%d ",brd[get(fad,i)][get(fal,i)].size());
	}
	return 0;
}

Measured memory_bytes: 37760
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=3e3, M=998244353;
int n, s, a[mxN];
ll dp[mxN+1][mxN+1], ans;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n >> s;
	for(int i=0; i<n; ++i) {
		cin >> a[i];
		memcpy(dp[i+1], dp[i], sizeof(dp[0]));
		//start a new sequence
		dp[i+1][a[i]]=(dp[i+1][a[i]]+i+1)%M;
		for(int j=0; j+a[i]<=s; ++j)
			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%M;
		ans=(dp[i+1][s]+ans)%M;
	}
	cout << ans;
}

Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		int[] inp = Input().ToInt();
		int n = inp[0];
		int k = inp[1];
		int[] bh = Input().ToInt();
		int[] h = new int[n+k+1];
		Array.Copy(bh, 0, h, 0, n);
		int[] c = new int[n+k+1];
		for(int i = 1; i < n; i++)
			c[i]=999999999;
		for(int i = 0; i < n; i++)
		{
			for(int j = 1; j <= k; j++)
				c[i+j] = Math.Min(c[i+j], Math.Abs(h[i]-h[i+j]) + c[i]);
		}
		Console.WriteLine(c[n-1]);
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 19296
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    //unordered_map<long long, int, custom_hash>
    //gp_hash_table<long long, int, custom_hash>
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	
	long long a, b, n; cin>>a>>b>>n;
	long long x = min(b-1, n);
	long long ans = (a * x) / b;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

// dp[i][j]:= i 回コインを投げて表が j 回出る確率 

const int MAX_N = 3000;

double dp[MAX_N][MAX_N];

int main()
{
	rep (i, MAX_N) rep (j, MAX_N) dp[i][j] = 0.0;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<double> p(N+1, 0);
	rep (i, N){
		cin >> p[i+1];
	} // end rep

	dp[0][0] = 1.0;
	for (int i = 1; i <= N; ++i){
		for (int j = 0; j <= i; ++j){
			if (j == 0){
				dp[i][j] = dp[i-1][j] * (1.0 - p[i]);
				continue;
			}else
			if (j == i){
				dp[i][j] = dp[i-1][j-1] * p[i];
				continue;
			} // end if
			dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1.0 - p[i]);
		} // end for
	} // end for

	double res = 0.0;
	for (int i = N; i > N / 2; --i){
		res += dp[N][i];
	} // end for

	printf("%.12lf\n", res);

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

bool cmp(string a, string b){
    if(a=="x") return true;
    if(b=="x") return false;
    if(a.size() < b.size()) return true;
    if(a.size() > b.size()) return false;
    for(int i=0;i<a.size();i++){
        if(a[i] != b[i]) return a[i]<b[i];
    }
    return false;
}

string cmax(string a, string b){
    if(cmp(a,b)) return b;
    else return a;
}

int main(){
    int N, M;
    int A[10];
    const int req[10] = {INT32_MAX, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

    string dp[10001];
    dp[0] = "";
    for(int i=1;i<=N;i++){
        dp[i] = "x";
        for(int m=0;m<M;m++){
            if(req[A[m]] <= i && dp[i-req[A[m]]] != "x"){
                dp[i] = cmax(dp[i], dp[i-req[A[m]]] + to_string(A[m]));
            }
        }
    }

    cout << dp[N] << endl;
    
    return 0;
}

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

vector<int> factorial = {1, 1, 2, 6, 24, 120, 720, 4320, 30240, 241920};

int N;
vector<int> x(10), y(10);

double dist(int i, int j){
  return sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
}

int main(){
  

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

  double ans = 0;
  for (int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      ans += dist(i,j) * 2;
    }
  }
  ans /= N;

  cout << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;



template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}



int n,m,r;
vector<int> v;
ll ans = INF;
vector<ll> w[10000];

void g(int b[]){
  ll res=0;
  FOR(i,1,r){
    res+=w[b[i-1]][b[i]];
  }
  ans = min(ans,res);
}

void f(int b[],int s){
  if(s==r){
    g(b);
    return;
  }
  rep(i,r){
    bool bc=false;
    rep(j,s)
      if(b[j]==v[i])
        bc = true;
    if(!bc){
      b[s]=v[i];
      f(b,s+1);
    }
  }
}

int main(){
  cin>>n>>m>>r;
  rep(i,r){
    int a;
    cin>>a;
    v.PB(a);
  }

  WG<ll> es(n+1);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    es[a].PB(edge<ll>(b,c));
    es[b].PB(edge<ll>(a,c));
  }

  FOR(i,1,n+1){
    w[i]=dijkstra(es,i);
  }


  int b[1000];
  f(b,0);

  cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MAXN = 200005;
const ll MOD = 998244353;
char str[MAXN];
int y[MAXN];
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x <= MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint pow(Mint a, ll p) {
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= pow(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
Mint g[MAXN * 2], p2[MAXN * 2];
int main() {
	p2[0] = 1;
	for (int i = 1; i < MAXN * 2; ++i) p2[i] = p2[i - 1] * 2;
	int n;
	scanf("%d%s", &n, str);
	for (int d = 1; d < 2 * n; ++d) {
		if (2 * n % d || n % d == 0) {
			g[d] = 0;
			continue;
		}	
		assert(d % 2 == 0);
		// y[i] = y[i + d]
		for (int i = 0; i < d / 2; ++i) {
			if (str[i] == '1') {
				g[d] += p2[d / 2 - i - 1];
			}
			y[i] = str[i] - '0';
		}
		bool same = true;
		for (int i = d / 2; i < n; ++i) {
			y[i] = 1 - y[i - d / 2];
			if (y[i] < str[i] - '0') {
				break;
			}
			if (y[i] > str[i] - '0') {
				same = false;
				break;
			}
		}
		if (same) ++g[d];
		for (int e = d + d; e <= 2 * n; e += d) {
			g[e] -= g[d];
		}
	}
	++g[2 * n];
	for (int i = 0; i < n; ++i) {
		if (str[i] == '1') {
			g[2 * n] += p2[n - i - 1];
		}
	}
	Mint ans = 0;
	for (int d = 1; d <= 2 * n; ++d) {
		ans += g[d] * d;
	}
	printf("%lld\n", ans.val);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    for(int i = n-1; i >= 0; i--){
        if(i >= 5 && s[i]=='r' && s[i-1]=='e' && s[i-2]=='s' && s[i-3]=='a' && s[i-4]=='r' && s[i-5]=='e') i -= 5;
        else if(i >= 4 && s[i]=='e' && s[i-1]=='s' && s[i-2]=='a' && s[i-3]=='r' && s[i-4]=='e') i -= 4;
        else if(i >= 6 && s[i]=='r' && s[i-1]=='e' && s[i-2]=='m' && s[i-3]=='a' && s[i-4]=='e' && s[i-5]=='r' && s[i-6]=='d') i -= 6;
        else if(i >= 4 && s[i]=='m' && s[i-1]=='a' && s[i-2]=='e' && s[i-3]=='r' && s[i-4]=='d') i -= 4;
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X, Y, A, B, C;
    long long sum;
    cin >> X >> Y >> A >> B >> C;
    sum = 0;
    vector<int> p;
    vector<int> q;
    vector<int> r;
    vector<int> v;
    for (int i = 0; i < A; i++) {
        int a;
        cin >> a;
        p.push_back(a);
    }
    for (int i = 0; i < B; i++) {
        int a;
        cin >> a;
        q.push_back(a);
    }
    for (int i = 0; i < C; i++) {
        int a;
        cin >> a;
        r.push_back(a);
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());    
    for (int i = 0; i < X; i++) {
        v.push_back(p[i]);
    }
    for (int i = 0; i < Y; i++) {
        v.push_back(q[i]);
    }
    for (int i = 0; i < C; i++) {
        v.push_back(r[i]);
    }
    sort(v.begin(), v.end(), greater<int>()); 
    for (int i = 0; i < X + Y; i ++) {
        sum += v[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    if(n%2!=0)
        cout<<2*n<<endl;
    else
        cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=705;
struct edge{int x,y,next;}a[MAXN*MAXN*2];int len,last[MAXN];
void ins(int x,int y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}
int col[MAXN],cal[3];
void dfs(int x,int c)
{
	if(col[x]==3-c){puts("-1");exit(0);}
	if(col[x]==c)return ;
	col[x]=c;cal[c]++;
	for(int k=last[x];k;k=a[k].next)dfs(a[k].y,3-c);
}
int n,m,mp[MAXN][MAXN],f[MAXN][MAXN];
int A[MAXN],B[MAXN],ln;
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		mp[x][y]=mp[y][x]=1;
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!mp[i][j]&&i!=j)ins(i,j);
	for(int i=1;i<=n;i++)if(!col[i])
	{
		cal[1]=cal[2]=0;
		dfs(i,1);
		A[++ln]=cal[1];B[ln]=cal[2];
	}
	f[0][0]=1;
	for(int i=1;i<=ln;i++)
	{
		for(int j=n;j>=0;j--)for(int k=n;k>=0;k--)
		{
			if(j>=A[i]&&k>=B[i])f[j][k]|=f[j-A[i]][k-B[i]];
			if(j>=B[i]&&k>=A[i])f[j][k]|=f[j-B[i]][k-A[i]];
		}
	}
	int ans=(1<<31-1);
	for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)if(f[i][j]&&i+j==n)
		ans=min(ans,i*(i-1)/2+j*(j-1)/2);
	pr2(ans);
	return 0;
}



Measured memory_bytes: 8320
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int A, B, X;
	scanf("%d %d", &A ,&B);
	if (A == B) {
		X = A + B;
	}
	else {
		if (A < B) {
			X = B * 2 - 1;
		}
		else {
			X = A * 2 - 1;
		}
	}
	printf("%d", X);
}



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

using namespace std ;

const long long mod = 1e9 + 7ll ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] , cnt[n+1];
	memset(cnt , 0 , sizeof(cnt)) ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	cnt[1] = 1 ;
	int last = 1;
	for(int j = 1 ; j < n ; ++j)
	{
		int prv = j-last+1 ;
		cnt[last]++ ;
		if((prv+1)*2-1 > arr[j])
		{
			last++ ;
			cnt[last] = cnt[last-1] - 1 ;
		}
	}
	while(last <= n)
	{
		++last ;
		cnt[last] = cnt[last-1] - 1 ;
	}
	long long ans = cnt[1] ;
	for(int i = 2 ; i <= n ; ++i)
		ans = (ans * 1ll * cnt[i]) % mod ;
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    vector< mp > a(n);
    for(ll i=0;i<n;i++){
	ll x,l;
	cin>>x>>l;
	a[i] = mp( x-l , x + l );
    }
    sort( a.begin() , a.end() );
    ll res = -inf;
    ll cnt = 0;
    for(ll i=0;i<n;i++){
	if( a[i].first >= res ){
	    cnt++;
	    res = a[i].second;
	}else{
	    res = min( res , a[i].second );
	}
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int score = sc.nextInt();

        if(score < 1200)
            System.out.println("ABC");
        else if(score < 2800)
            System.out.println("ARC");
        else
            System.out.println("AGC");
    }
}

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

void print( int* a );
void reverse( int* a );
void shiftL( int* a );
void shiftR( int* a );

int main()
{
    long long x;                    //整数の範囲を間違えない
    int bit[32];

    for( int i = 0; i < 32; i++ )
        bit[i] = 0;

    cin >> x;

    int j = 0;
    while( x > 1 )
    {
        bit[j] = x % 2;
        j++;
        x = x / 2;
    }

    bit[j] = x;                     //最後のbitを入れる(1)

    print( bit );
    reverse( bit );
    shiftL( bit );
    shiftR( bit );

    return 0;
}

void print( int* a )
{
    for( int i = 0; i < 32; i++ )
        cout << a[31-i];
    cout << endl;
}

void reverse( int* a )
{
    int x[32];
    for( int i = 0; i < 32; i++ )
    {
        if( a[i] == 1 )
            x[i] = 0;
        else
            x[i] = 1;
    }
    print( x );
}

void shiftL( int* a )
{
    int x[32];
    x[0] = 0;
    for( int i = 0; i < 31; i++ )
        x[i+1] = a[i];
    print( x );
}

void shiftR( int* a )
{
    int x[32];
    x[31] = 0;
    for( int i = 0; i < 31; i++ )
        x[i] = a[i+1];
    print( x );
}


Measured memory_bytes: 3112
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String str  = sc.nextLine();
        String[] astr = str.split(" "); //状況に合わせて
        int[] in_data = Stream.of(astr).mapToInt(x->{
            try{
                return Integer.parseInt(x);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();
        int ans =0;

        for(int i=0;i<in_data.length;i++){
            for(int j =i+1;j<in_data.length;j++){
                ans += in_data[i] * in_data[j];
            }
        }
        System.out.println(ans);
    }
}

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

int main() {
	int N;
	cin >> N; 
	double dans;
	if (1== N%2) {
		dans = ((N + 1) / 2) / (double)N;
	}
	else{
		dans = 1 / 2.0;
	}

	printf("%.10f\n", dans);
	return 0;
}

Measured memory_bytes: 3732