akhauriyash/Code-Regression huggingface dataset:
MAX_PRIME = 10**6
is_prime = [1] * MAX_PRIME
primes = []
is_prime[0] = 0
is_prime[1] = 0
for i in range(MAX_PRIME):
    if is_prime[i]:
        primes.append(i)
        for j in range(2, ((MAX_PRIME-1)//i) + 1):
            is_prime[i*j] = 0

def factorization(n):
    factor = {}
    for p in primes:
        if p ** 2 > n:
            break
        while n % p == 0:
            n //= p
            if p not in factor:
                factor[p] = 1
            else:
                factor[p] += 1
    if n > 1:
        factor[n] = 1
    return factor

a, b = map(int, input().split())
ans = 1
fa = factorization(a)
fb = factorization(b)
for p, _ in fa.items():
    if p in fb:
        ans += 1
print(ans)

Measured memory_bytes: 13996
from bisect import bisect_left

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

A.sort()

def calc(m) :
  c = 0
  for i in range(N) :
    c += N - bisect_left(A, m - A[i])
  return c

ng, ok = 0, A[-1] * 2 + 1
while ok - ng > 1 :
  m = (ok + ng) // 2

  if calc(m) <= M :
    ok = m
  else :
    ng = m
  
S = [A[0]]
for i in range(1, N) :
  S.append(S[-1] + A[i])
S.append(0)
S.append(0)

all = sum(A)
ret = 0
for i in range(N) :
  ret += all - S[bisect_left(A, ng - A[i])-1]
  ret += A[i] * (N - bisect_left(A, ng - A[i]))
ret -= (calc(ng) - M) * (ng)
print(ret)

Measured memory_bytes: 59852
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(int argc, char *argv[]) {
	int sr;
	char S[4], T[4];
	int i, j;

	sr=scanf("%s", S);
	sr=scanf("%s", T);

	j=0;
	for (i=0; i<3; i++) {
		if (S[i] == T[i]) j++;
	}

	printf("%d\n", j); fflush(stdout);


	return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

int main() {
    
    vector<int> X;
    vector<int> Y;
    
    int N,M;
    cin >> N >> M;
    
    X.resize(N);
    Y.resize(N);
    fill( X.begin(), X.end(), 0 );
    fill( Y.begin(), Y.end(), 0 );
    
    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if ( a == 0 || b == 0 ) {
            X[a] = X[b] = 1;
        }
        if ( a == N-1 || b == N-1 ) {
            Y[a] = Y[b] = 1;
        }
    }
    
    X[0] = Y[N-1] = 0;
    
    for ( int i = 0; i < N; i++ ) {
        if ( X[i] && Y[i] ) { cout << "POSSIBLE" << endl; return 0; }
    }
    
    cout << "IMPOSSIBLE" << endl;
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int M = scan.nextInt();

		TreeMap<Long, Long> tm = new TreeMap<>();
		long cost = 0;

		for (int i = 0; i < N; i++) {
			long key = scan.nextLong();
			long value = scan.nextLong();
			if (tm.containsKey(key)) {
				tm.put(key, tm.get(key) + value);
			} else {
				tm.put(key, value);
			}
		}

		for (long i : tm.keySet()) {
			if (M <= tm.get(i)) {
				cost += i * M;
				break;
			} else {
				M -= tm.get(i);
				cost += i * tm.get(i);
			}
		}
		System.out.println(cost);
		
	}
}

Measured memory_bytes: 99524
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
using namespace std;

#define INF 0x3f3f3f3f
#define eps 1e-8

typedef long long ll;
const int MAXN = 1010;

 int main() {
 	unsigned long long a, b;
 	char str[5];
 	cin >> a >> str;
 	b = 0;
 	bool flag = false;
 	int cnt = 0;
 	for (int i=0; str[i]; i++) {
 		if (str[i] == '.') {
 			flag = true;
 			continue;
		} 
 		b = b*10+str[i]-'0';
 		if (flag)
 			cnt++;
	}
	 
	unsigned long long c = 1;
	while (cnt--)
		c *= 10;
	cout << a*b/c << endl;
	return 0;
 }

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
using ll= long long int;

long long int replace(long long int x,long long int k){
    x=abs(x-k);
    return x;
}

int main(){
   ll n,k;
   cin>>n>>k;
   long long int a=n%k;
   long long int c;
   c=min(a,abs(k-a));

   cout<<fixed<<setprecision(20)<<c<<endl;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {

	int a;
	string s;

	cin >> a >> s;
	if (a < 3200) {
		s = "red";
	}
	cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    int a[4];
    rep(i, 0, 4) a[i] = s[i] - '0';
    rep(i, 0, 1<<4) {
        int sum = a[0];
        rep(j, 1, 4) {
            if (i >> j & 1) sum = sum + a[j];
            else sum = sum - a[j];
        }
        if (sum == 7) {
            cout << a[0];
            rep(j, 1, 4) {
                if (i >> j & 1) cout << '+';
                else cout << '-';
                cout << a[j];
                if (j == 3) {
                    cout << "=7" << endl;
                    break;
                }
            }
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
void initialize(int len, int array[len])
{
  int i;
  i = 0;
  while(i < len)
  {
    array[i] = 0;
    i++;
  }
}
 
int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  int d[k];
  int a[k][100];
  int b[n];
  int i,j;
  i = 0;
  initialize(n, b);
  i = 0;
  while (i < k)
  {
    scanf("%d",&d[i]);
    j = 0;
    while (j < d[i])
    {
      scanf("%d",&a[i][j]);
      b[a[i][j] - 1] += 1;
      j++;
    }
    i++;
  }
  
  i = 0;
  int sum;
  sum = 0;
  while (i < n)
  {
    if(b[i] == 0)
    {
      //printf("i:%d b[i]:%d\n",i,b[i]);
      sum += 1;
    }
    i++;
  }
  printf("%d",sum);
}

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

using namespace std;

int main() {
    int ans = 0;
    int N, H[20];
    cin >> N;
    int x = 0;
    for (int i = 0; i < N; i++) {
        cin >> H[i];
        if (x <= H[i]) {
            ans++;
        }
        x = max(x, H[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n,t;
  cin>>n;
  ll i=0,k=1,sum=0;
  while(sum<n)
  {
    i++;
    k*=26;
    sum+=k;
  }
  sum-=k;
  k/=26;
  n-=sum;
  string s;
  //deB(n,k)
  n--;
  while(i--)
  {
    s+='a'+n/k;
    n%=k;
    k/=26;
  }
  deb(s)
}


Measured memory_bytes: 3652
n_row, n_column = map(int, input().split())
A = [[int(i) for i in input().split()] for _ in range(n_row)]
b = [int(input()) for _ in range(n_column)]

# target: n*m * m*1 -> n*1
ans = [0 for _ in range(n_row)]

for i_A_row, A_row in enumerate(A):
    # print(f"i_A_row: {i_A_row}")
    # print(f"A_row: {A_row}")
    # print(f"b:     {b}\n")
    for i in range(n_column):
        ans[i_A_row] += A_row[i] * b[i]
        
for i in ans:
    print(i)


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



using ll = long long;
const ll INF = 1e18l+5;

int main(){
    string s,t;
    cin>>s>>t;
      
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1,0));
    string ans;
    for(int i=1; i<=s.size(); ++i){
        for(int j=1; j<=t.size(); ++j){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }

            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);    
        }
    }
    int i=s.size(), j=t.size();
    
    while(i>=1&&j>=1){
            if(dp[i][j]!=dp[i-1][j]&&dp[i][j]!=dp[i][j-1]){
                i--;
                j--;
                ans.push_back(s[i]);
            }

            else if(dp[i][j]==dp[i][j-1]) j--;
            else if(dp[i][j]==dp[i-1][j]) i--;

        
    }
    //cout<<dp[s.size()][t.size()];
    reverse(ans.begin(),ans.end());
        cout<<ans;
}

Measured memory_bytes: 38544
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayLong();
            var N = input[0];
            var T = input[1];
            var t = ReadArrayLong();
            var now = 0L;
            var total = 0L;
            for (int i = 1; i < N; i++)
            {
                if (t[i] - now >= T)
                {
                    total += T;
                    now = t[i];
                }
                else
                {
                    total += t[i] - now;
                    now = t[i];
                }
            }
            total += T;

            Console.WriteLine(total);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 30880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int k, n;
    ll p[300005] = {1};
    cin >> k >> n;
    for (int i = 1; i <= n; i++) p[i] = min(mod * 328ll, 1ll * p[i - 1] * k);
    for (int i = 1; i <= n; i++) p[i] = min(mod * 328ll, p[i - 1] + p[i]);
    if (k % 2 == 0) {
        cout << k / 2 << ' ';
        for (int i = 1; i < n; i++) cout << k << ' ';
    } else if (k == 1) {
        for (int i = 1; i <= (n + 1) / 2; i++) cout << 1 << ' ';
    } else {
        int m = 0;
        while (p[m] <= n) m++;
        for (int i = 1; i <= n - m; i++) cout << k / 2 + 1 << ' ';
        ll x = p[m] + 1;
        x -= n - m;
        if (n % 2) x++;
        x /= 2;
        for (int i = m; i; i--) {
            if (x == 1) break;
            int y = (int)((x - 2) / p[i - 1]);
            cout << y + 1 << ' ';
            x -= y * p[i - 1] + 1;
        }
    }
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A[3];
    cin >> N >> A[0] >> A[1] >> A[2];
    int l[8];
    rep(i, N) cin >> l[i];
    int ans = INF;
    int pattern = 1;
    rep(i, N) pattern *= 4;
    rep(bit, pattern) {
        int tmp = bit;
        vector<int> v[3];
        int sum[3] = {};
        rep(i, N) {
            if(tmp % 4 != 3) {
                v[tmp % 4].push_back(l[i]);
                sum[tmp % 4] += l[i];
            }
            tmp /= 4;
        }
        bool ok = true;
        rep(i, 3) if(v[i].size() == 0) ok = false;
        if(!ok) continue;
        int cost = 0;
        rep(i, 3) {
            cost += abs(sum[i] - A[i]);
            cost += (v[i].size() - 1) * 10;
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
using namespace std;


int main(){

    int a,b,c;
    cin >> a >> b >> c;

    if (a == b && b == c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAX(a,b) ((a>b)?a:b)
#define MIN(a,b) ((a>b)?b:a)
using namespace std;

int main()
{
	int N;
	string input;
	vector<char> S;

	cin >> input;
	N = static_cast<int>(input.size());
	copy(input.begin(), input.end(), back_inserter(S));

	int numOf0 = static_cast<int>(count(S.begin(), S.end(), '0'));
	int numOf1 = static_cast<int>(count(S.begin(), S.end(), '1'));

	cout << MIN(numOf0, numOf1) * 2;

	return 0;
}

Measured memory_bytes: 640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    rep(i,1,N+1){
        ll cnt = 0;
        ll m = i;
        while(m > 0){
            cnt++;
            m /= 10;
        }
        if(cnt % 2 == 1) ans++;
    }
    print(ans);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 5000 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
int main()
{
    int a,b,ans=0,max1=0;
    scanf("%d",&a);
    for(int i=1;i<=a;i++)
    {
        scanf("%d",&b);
        if(b>=max1)
        max1=b,ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define ld long double
#define ok puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define random ((1 << rand()) ^ rand())
#define whatis(x) cout << "#x = " << x << endl;

using namespace std;

inline ll min(ll a, ll b) {return (a > b) ? b : a;}
inline ll max(ll a, ll b) {return (a > b) ? a : b;}
inline void swap(ll &a, ll &b) {a ^= b; b ^= a; a ^= b;}

const int N = 1e7 + 7;;
const int inf = 1e9 + 7;
const ll linf = 1e18 + 9;
const double eps = 0.001;

int a[2002];

main() {
    int n, w, z; scanf ("%d %d %d", &n, &z, &w);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", a + i);
    }
    if (n == 1) {
        cout << abs(w - a[n]);
        return 0;
    }
    cout << max(abs(a[n] - a[n - 1]), abs(w - a[n]));
}



Measured memory_bytes: 256
n,m,rrr = map(int,input().split())
R = tuple(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in range(m)]
inf = 1000000000

edge = [[inf]*(n+1) for _ in range(n+1)]

for a,b,c in ABC:
    edge[a][b] = c
    edge[b][a] = c
    
def dijkstra(start,e,N):
    for _ in range(3):
        for v in range(1,N+1):#中間
            for g in range(1,N+1):#ゴール
                e[start][g] = min(e[start][g],e[start][v] + e[v][g])
                e[g][start] = e[start][g]
    return e[start]

dic = {}
for rr in R:
    dic[rr] = dijkstra(rr,edge,n)

from itertools import permutations as pm

temp = list(pm(R))

ans = 10000000000
for RR in temp:
    cost = 0
    for i in range(rrr-1):
        cost += dic[RR[i]][RR[i+1]]
    if cost < ans:
        ans = cost
print(ans)

Measured memory_bytes: 12648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int a,b,c;
	cin >> a >> b;
	if(a==1)
		c=1;
	else{
	c = a-1;
	if(a<=b)
		c++;
	}
	cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[200005];
vector<ll>beg[200005],ruib[200005];
vector<ll>en[200005],ruie[200005];
int main(){
	cin>>n;
	rep(i,n) cin>>a[i];
	for(int i=1;i<=n-1;i++){
		for(int j=0;j<n;j+=i){
			beg[i].pb(a[j]);
			if(ruib[i].empty()) ruib[i].pb(a[j]);
			else ruib[i].pb(ruib[i][ruib[i].size()-1]+a[j]);
		}
		for(int j=n-1;j>=0;j-=i){
			en[i].pb(a[j]);
			if(ruie[i].empty()) ruie[i].pb(a[j]);
			else ruie[i].pb(ruie[i][ruie[i].size()-1]+a[j]);
		}
	}
	
	ll ans = 0;
	for(ll p=2;p<n;p++){
		for(ll d=1;d<=(n-1)/(p-1);d++){
			ll A = n-1-d*(p-1);
			if(A<=d) continue;
			ll B = A-d;
			if(A%(A-B) == 0 && A/(A-B)<=p-1) continue;
			ans = max(ans,ruib[d][p-1]+ruie[d][p-1]);
			//cout<<A<<B<<p<<endl;
		}}
		cout<<ans<<endl;
	}

Measured memory_bytes: 75028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update> */

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
	
    ll n;
    ll c=0;
    bool flag=false;
    cin>>n;
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        ll d1,d2;
        cin>>d1>>d2;
        if(d1==d2)
            v.push_back(1);
        else
        {
            v.push_back(0);
        }
    }
    for(ll i=0;i<n;i++)
    {
        if(v[i]==1)
        {
            c=c+1;
        }
        else
        {
            c=0;
        }
        if(c==3)
        {
            flag=true;
            break;
        }
        
    }
    if(flag)
    cout<<"Yes\n";
    else
    {
        cout<<"No\n";
    }
    
    
    return 0;
}




Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 3e2+10;
const int mod = 1e9+7;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
vector< pair<int,int> > w[maxn];
int dp[maxn][maxn][maxn],a[5];
int main(){
	n=read();m=read();
	for(register int i=1;i<=m;i++){
		int l=read(),r=read(),x=read();
		w[r].push_back(make_pair(l,x));
	}
	dp[0][0][0]=1;
	int ans=0;
	for(register int i=0;i<=n;i++){
		for(register int j=0;j<=n;j++){
			if(i==j && i!=0)continue;
			for(register int k=0;k<=n;k++){
				if((i==k && i!=0)|| (j==k && j!=0))continue;
				a[1]=i;a[2]=j;a[3]=k;
				sort(a+1,a+4);
				int len=w[a[3]].size(),flag=0;
				for(register int u=0;u<len;u++){
					if(w[a[3]][u].second==1)
						if(a[1]>=w[a[3]][u].first || a[2]>=w[a[3]][u].first){flag=1;break;}	
					if(w[a[3]][u].second==2)
						if(a[1]>=w[a[3]][u].first || a[2]<w[a[3]][u].first){flag=1;break;}
					if(w[a[3]][u].second==3)
						if(a[1]<w[a[3]][u].first){flag=1;break;}
				}
				if(!flag){
					if(a[3]==n)(ans+=dp[i][j][k])%=mod;
					(dp[a[3]+1][j][k]+=dp[i][j][k])%=mod;
					(dp[i][a[3]+1][k]+=dp[i][j][k])%=mod;
					(dp[i][j][a[3]+1]+=dp[i][j][k])%=mod;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 114944
s = list(input())
if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            print(3)
        else:
            print(2)
    else:
        print(1)
elif s[1] == "R":
    if s[2] == "R":
        print(2)
    else:
        print(1)
else:
    if s[2] == "R":
        print(1)
    else:
        print(0)

Measured memory_bytes: 61672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int gcd(int a,int b){
	if(a<b) return gcd(b,a);
	int r;
	while(r=a%b){
		a=b;
		b=r;
	}
	return b;
}


int main(){
	int a,b,c;cin>>a>>b>>c;
	int d=a*b/gcd(a,b);

	for(int i=a;i<=d;i+=a){
		if(i%b==c){
			cout<<"YES"<<"\n";
			return 0;
		}
	}
	cout<<"NO"<<"\n";
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>

using namespace std;
int N, W;
const int MAX_N = 100, MAX_W = 10000;
int v[MAX_N], w[MAX_N];
int dp[MAX_N + 1][MAX_W + 1]; //dp????????????

void solve() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
}

int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 7008
#include<stdio.h>

int main (){
	int N,slimee,c;
	scanf("%d",&N);
	char slime[N+1];
	scanf("%s",slime);
	slimee = 1;
	slime[c]=slime[0];
	for (int i = 0;i<N;i++){
		if (slime[i]!=slime[c]){
			slime[c]=slime[i];
			slimee++;
		}
	}
     printf("%d\n",slimee);
     return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i)-1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

cnt = 0
before = -1
for i in a:
  cnt += b[i]
  if before == i-1 and i != 0:
    cnt += c[before]
  before = i
print(cnt)    

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string a, b;
	cin >> a >> b;
	if (a == b) cout << "H\n";
	else cout << "D\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
try(Scanner sc =new Scanner(System.in)){
    while(true){
        int n = sc.nextInt();
        if(n==0){break; }
        int[]scores=new int[n];
        for(int i =0;i<scores.length;i++){
            scores[i]=sc.nextInt();
        }
		double average =0.0, variance =0.00,suum=0.0;
        int sum=0;
        for(int i=0;i<scores.length;i++){
         sum = sum+scores[i];
        }
        average=(double)sum/n;
        for(int i=0;i<n;i++){
            double j = (double)scores[i]-average;
			suum = suum+j*j;
        }
        variance =(double)suum/scores.length;
        System.out.printf("%.8f\n",Math.sqrt(variance));
    }
    }
}
  }




Measured memory_bytes: 31424
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int n;
    scanf("%d", &n);

    int maxdata = 0;
    int mindata = 1000000000 + 1;

    for (int i = 0; i < n; i++) {

        int num;
        scanf("%d", &num);

        if (num < mindata) {
            mindata = num;
        }
        if (maxdata < num) {
            maxdata = num;
        }

    }

    printf("%d", maxdata - mindata);

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  int H,W;cin>>H>>W;
  vector<vint> a(H,vint(W));
  repeat(i,H){
    repeat(j,W){
      cin>>a[i][j];
    }
  }
  vector<pair<Pii,Pii>> ans;
  repeat(i,H){
    repeat(j,W){
      int x=i&1? W-1-j:j;
      if(!(a[i][x]&1)||(i==H-1&&j==W-1)) continue;
      int ny = j==W-1? i+1:i;
      int nx = j==W-1? x:(i&1? x-1:x+1);
      a[i][x]--;
      a[ny][nx]++;
      ans.push_back({{i+1,x+1},{ny+1,nx+1}});
    }
  }
  cout << ans.size() << endl;
  repeat(i,ans.size()){
    cout << ans[i].first.first << " " << ans[i].first.second << " "
          << ans[i].second.first << " " << ans[i].second.second << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
#define N 2 
int getMin(int x, int y) { return (x<y)? x: y; } 
int maximum(std::vector<int> &tree,int cur,int l,int r,int a,int b)
{
	//cout<<cur<<" "<<l<<" "<<r<<" "<<a<<" "<<b<<endl;
	if(l>r)
		return 0;
	if(l>b || r<a)
	{
		return 0;
	}
	if(l>=a && r<=b)
	{
		//cout<<tree[cur]<<endl;
		return tree[cur];
	}
	
	if(l==r)
		return tree[cur];

	int left=maximum(tree,2*cur,l,((l+r)/2),a,b);
	int right=maximum(tree,2*cur+1,((l+r)/2+1),r,a,b);
	return max(left,right);
} 
void update(vector<int> &tree,int cur,int l,int r,int x,int val)
{
	//cout<<"He";
	if(l>r)
		return;
	if(l==r)
	{
		tree[cur]=max(tree[cur],val);
		return;
	}
	int mid=((l+r)/2);
	if(mid>=x)
	{
		update(tree,cur*2,l,mid,x,val);

	}else{
		update(tree,cur*2+1,mid+1,r,x,val);
	}
	tree[cur]=max(tree[cur],max(tree[cur*2],tree[cur*2+1]));
} 
signed main() {
 
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	std::vector<int> h(n),a(n);
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans=0;			
	std::vector<int> dp(n+1,0);
	int sz=1;
	while(sz<=n)
	{
		sz=sz*2;
	}

	std::vector<int> tree((4*sz),0);
	int res=0;
	for(int i=0;i<n;i++)
	{
		// for(int j=0;j<h[i];j++)
		// {
		// 	dp[h[i]]=max(dp[h[i]],dp[j]+a[i]);
		// 	ans=max(ans,dp[h[i]]);
		// }

		int ans=maximum(tree,1,1,n,1,h[i]-1);
		//cout<<ans<<endl;
		update(tree,1,1,n,h[i],ans+a[i]);
		res=max(res,ans+a[i]);
		//cout<<res<<endl;
	}
	cout<<res;
	return 0;
 }


Measured memory_bytes: 13184
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  int N;
  cin>>N;
  ull ans=0;
  while(N--) {
    int l,r;
    cin>>l>>r;
    ans += r-l+1;
  }
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

char missing(char c1, char c2){
    if(c1 < c2)swap(c1, c2);
    if(c1 == 'R' && c2 == 'G'){
        return 'B';
    }
    else if(c1 == 'G' && c2 == 'B'){
        return 'R';
    }
    else{
        return 'G';
    }
}
int32_t main(){
    FAST
    int n; cin >> n;
    string s; cin >> s;
    vector<int> R;
    vector<int> B;
    vector<int> G;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R')R.pb(i);
        else if(s[i] == 'B')B.pb(i);
        else G.pb(i);
    }
    int ans = 0;
    vector<pair<char, int> > vec;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(s[i] != s[j]){
                if(missing(s[j], s[i]) == 'R'){
                    ans += R.size() - (lower_bound(R.begin(), R.end(), j) - R.begin());
                    if(j + j - i >= n)continue;
                    else if(s[j + j - i] == 'R')ans--;
                }
                else if(missing(s[j], s[i]) == 'B'){
                    ans += B.size() - (lower_bound(B.begin(), B.end(), j) - B.begin());
                    if(j + j - i >= n)continue;
                    else if(s[j + j - i] == 'B')ans--;
                }
                else{
                    ans += G.size() - (lower_bound(G.begin(), G.end(), j) - G.begin());
                    if(j + j - i >= n)continue;
                    else if(s[j + j - i] == 'G')ans--;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int N, M;
int P[100000], Y[100000];
vector<int> yd[100001];

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int n,a,b;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
    }else{
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    
}

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

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

int main(){
  int N;
  cin >> N;
  vector<int> P;
  rep(i,N){
    int p;
    cin >> p;
    P.push_back(p);
  }
  int mn = P.at(0);
  int count = 1;
  rep(i,N-1){
    if(P.at(i+1) <= mn) count++;
    mn = min(mn, P.at(i+1));
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>

using namespace std;

//long long __lcm (int (*A)[3001], int N){
//    long long lcm = (*A)[0];
//    for (int i = 0; i < N; i++)
//        lcm = (((*A)[i]*lcm) / __gcd((long long)(*A)[i], lcm));
//    return lcm;
//}

int main(){
    int N; cin >> N; int A, f = 0;
    for (int i = 0; i < N; i++) {cin >> A; f += A;}
    //long long m = __lcm(&A, N)-1;
    //for (int i = 0; i < N; i++) f += m % A[i];
    cout << f-N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int concat(int x, int y){
    char str1[20];
char str2[20];
    sprintf(str1,"%d",x);
    sprintf(str2,"%d",y);

    strcat(str1,str2);

    return atoi(str1);
}
int main()
{

    int x,y,z,i,j,c=0;
    cin>>x>>y;
    z=concat(x,y);
    for(i=1;i*i<=z;i++)
    {
        if(i*i==z)
            c=1;
    }
    if(c==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}





Measured memory_bytes: 3668
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;


int factorial(int N){
  int ans = 1;
  for (int i=N;i>0;i--) ans *=i;
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> chord(N,vector<int>(2));
  REP(n,N) cin >> chord[n][0] >> chord[n][1];
  vector<int> nums(N);
  REP(n,N) nums.at(n) = n;
  double ans = 0.0;

  do {
    REP(n,N-1){
      int current = nums.at(n);
      int next = nums.at(n+1);
      ans += pow((pow(((double)chord[current][0]-(double)chord[next][0]),2)
          +       pow(((double)chord[current][1]-(double)chord[next][1]),2)), 0.5 );
    }
  } while (next_permutation(nums.begin(), nums.end()));

  int factorialN = factorial(N);

  ans /= (double)factorialN;
  cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    vector<long long> num(1100000, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        auto pf = prime_factorize(A[i]);
        for (auto p : pf) num[p.first] = max(num[p.first], p.second);
    }

    mint LCM = 1;
    for (int v = 2; v < 1100000; ++v) {
        LCM *= modpow(mint(v), num[v]);
    }

    mint res = 0;
    for (auto a : A) {
        res += LCM / a;
    }
    cout << res << endl;
}

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

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

    string S;
    cin >> S;

    ll r, g, b;
    r = g = b = 0;
    rep(i,N) {
        if (S[i] == 'R') r++;
        else if (S[i] == 'G') g++;
        else if (S[i] == 'B') b++;
    }

    ll sum = r * g * b;
    for (int i = 1; i < N; i++) {
        for (int j = i; j + i < N; j++) {
            if (S[j] != S[j - i] && S[j] != S[j + i] && S[j - i] != S[j + i]) sum--;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3632
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto o(C *x)->decltype(os << *x, 0);
template<class C> static char o(...);
template<class C> typename enable_if<sizeof o<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof o<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 105;

int x, n, p[mxn], mn = inf, mni;
bitset<mxn> vstd;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> x >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i], vstd[p[i]] = 1;
    }
    for (int i = 0; i <= 101; i++) {
        if (vstd[i]) continue;
        int o = abs(x-i);
        if(o<mn) {
            mn = o, mni = i;
        }
    }
    cout << mni << '\n';
}

Measured memory_bytes: 3644
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
C = [[abs(a[i][j] - b[i][j]) for j in range(w)] for i in range(h)]#cを配列にしてfor文と干渉してた
dp = [[0]*w for i in range(h)]#dp = [[[0] for i in range(w)] for j in range(h)]にしてたので、各要素がリストになってた
ofs = 80*(h + w)#h*wにしてた

dp[0][0] = (1<<(ofs+C[0][0]) | 1<<(ofs-C[0][0]))#(1<<ofs+c[0][0] | 1<<ofs-c[0][0])にしてた
for r in range(h):
    for c in range(w):
        if c>0:
            dp[r][c] |= (dp[r][c-1]<<C[r][c] | dp[r][c-1]>>C[r][c])
        if r>0:
            dp[r][c] |= (dp[r-1][c] << C[r][c] | dp[r-1][c] >> C[r][c])

dp[h-1][w-1] >>= ofs#ofs-1にしてた
for i in range(ofs):
    if dp[h-1][w-1]>>i & 1:
        print(i)
        break

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

	
const int INF = 7+(1e+9);
typedef int Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る,prev:最短路木の親頂点が入る
//戻値 なし
void shortestPath(const Graph &g,int s,vector<Weight> &dist,vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  Q.push(Edge(-2, s, 0));
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();f++){
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
 


int main(){
  int v; cin >> v;
  Graph g(v);    //頂点数vの空隣接リストgを生成
  for(int i=0;i<v;i++){
        int u,k; cin >>u >>k;
        for(int j=0;j<k;j++){
            int vv,cc; cin >>vv >>cc;
            g[u].push_back(Edge(u,vv,cc));    //隣接リストgにsからtに向かう重さwの辺を追加
        }
  }
  vector<Weight> dist;
  vector<int> prev;
  shortestPath(g,0,dist,prev);
  for(int i=0;i<v;i++){
        cout<<i<<" "<<dist[i]<<endl;
  }
  
}


Measured memory_bytes: 3088
n = int(input())
t, a = map(int, input().split())
t = (a - t) * 1000
h = list(map(int, input().split()))
min_val = 10 ** 9
for i, x in enumerate(h):
    if min_val > abs(t + x * 6):
        min_val = abs(t + x * 6)
        ans = i
print(ans + 1)

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

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

    int n; cin >> n;
    vector<ll> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    ll sum = accumulate(arr.begin(), arr.end(), 0LL);
    ll pass = (ll)n * (n + 1) / 2;
    if (sum % pass) {
        cout << "NO" << endl;
        return 0;
    }
    ll k = sum / pass;
    ll res = 0;
    ll nk = (ll)(n-1) * k;
    for (int i = 0; i < n; i++){
        ll D = arr[(i+1)%n] - arr[i];
        D += nk;
        if (D % n) {
            cout << "NO" << endl;
            return 0;
        }
        ll x = D / n;
        if (x < 0 || x > k) {
            cout << "NO" << endl;
            return 0;
        }
        res += (k - x);
    }
    if (res == k) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main(){
    
    int N,M;
    cin>>N>>M;
    vector<long long int> S(N);
    vector<pair<long long int,long long int>> T(M);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(S.begin(),S.end());
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        T[i].first=b;
        T[i].second=a;
    }
    sort(T.begin(),T.end());
    reverse(T.begin(),T.end());
    int now=0;
    for(int i=0;i<M;i++){
        int ima=now;
        for(int j=ima;j<ima+T[i].second;j++){
            if(S[j]<T[i].first){
                S[j]=T[i].first;
                now++;
            }
            else break;
        }
    }
    long long int sum=0;
    for(int i=0;i<N;i++){
        sum+=S[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    ll n,m,k,ans=0;
    cin>>n>>m>>k;
    ll a[n+5]={0},b[m+5]={0};
    for(ll i=1;i<=n;i++)
    {
    	 cin>>a[i];
	a[i]+=a[i-1];
    }
    for(ll i=1;i<=m;i++)
    {
    	 cin>>b[i];
	b[i]+=b[i-1];
    }
    for(ll i=0;i<=n;i++) 
	 if(k>=a[i]) ans=max(ans,upper_bound(b+1,b+1+m,k-a[i])-b-1+i);
    
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

const ll MAX = 200100;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modpow(long long a, long long n, long long mod) {//a^n(mod)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;//次の準備
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}



signed main(){
    ll n,a,b,c,ans=0;cin>>n>>a>>b>>c;
    COMinit();

    ll an=modpow(a,n,mod),bn=modpow(b,n,mod);

    for(ll i=n;i < 2*n;i++)
    {
        ll ain=modpow(a,i-n,mod),bin=modpow(b,i-n,mod);

        ll res = ((an*bin)%mod)+((bn*ain)%mod);
        res%=mod;

        res*=i;res%=mod;

        res*=COM(i-1,i-n);res%=mod;
     
        res*=modinv(modpow(a+b,i,mod),mod);
        res%=mod;
        

        ans+=res;
        ans%=mod;
    }
    (ans*=100)%=mod;
    (ans*=inv[100-c])%=mod;


    cout<<ans<<endl;

}

Measured memory_bytes: 4992