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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n;
  ll k;
  cin >> n >> k;
  map<int, ll> mp;
  rep(i, n) {
    int a, b; cin >> a >> b;
    mp[a] += b;
  }
  ll sum = 0;
  for(auto x : mp) {
    sum += x.second;
    if(sum >= k) {
      cout << x.first << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 7480
#include <iostream>
#define MAX 250000
using namespace std;

bool TF[MAX];

int main(void){

  int n;
  int cnt;
  

  for( int i = 0 ; i < MAX ; i++ )TF[i] = true;
  TF[0] = TF[1] = false;

  for( int i = 2 ; i * i < MAX ; i++ ){
    if( TF[i] ){
      for( int j = i * 2 ; j <= MAX ; j += i )TF[j] =false;
    }
  }


  while(1){

    cnt = 0;

    cin >> n;
    if( n == 0 )break;

    for( int i = n + 1  ; i <= 2 * n ; i++ ){
      if( TF[i] == true ){
	cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                \
  ifstream in("atcoder-problems/code_festival_2017_qualc_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int N = S.size();
  int l = 0, r = N - 1;
  int ans = 0;
  while (l < r) {
    if (S[l] == S[r]) {
      l++;
      r--;
    } else if (S[l] == 'x') {
      l++;
      ans++;
    } else if (S[r] == 'x') {
      r--;
      ans++;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3696
from collections import deque

k = int(input())
count = 0
q = deque(range(1,10))

while count < k:
    l = q.popleft()
    resid = l % 10
    if resid != 0: q.append(l*10 + resid - 1)

    q.append(l*10 + resid)
    
    if resid != 9: q.append(l*10 + resid + 1)
    
    count += 1

print(l)

Measured memory_bytes: 11956
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,t;
  l=2*i;
  r=2*i+1;
  if(l<=size&&A[l]>A[i])largest=l;
  else largest=i;
  if(r<=size&&A[r]>A[largest])largest=r;
  if(largest!=i){
    t=A[i];A[i]=A[largest];A[largest]=t;
    maxHeapify(largest);
  }
}

main(){
  scanf("%d",&size);
  int i;
  for(i=1;i<=size;i++)scanf("%d",&A[i]);
  for(i=size/2;i>=1;i--)maxHeapify(i);
  for(i=1;i<=size;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3756
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//nの入力
		int n = sc.nextInt();
		int a[] = new int[n];
		//偶数の要素を数える
		int count = 0;
		//何回試行できるか数える
		int doing = 0;
		
		for(int i=0;i<n;i++) {
			//a[i]の要素入力
			a[i] = sc.nextInt();
		}
		
		while(true) {
			for(int i = 0;i < n;i++) {
				//もし要素が偶数なら
				if(a[i] % 2 == 0) {
					count++;
					//要素を２で割る
					a[i] = a[i]/2;
				}
			}
			if(count == n) {
				//カウント初期化
				count = 0;
				doing++;
			}else {
				break;
			}
		}
		System.out.println(doing);
	}
}

Measured memory_bytes: 21972
#define _GLIBCXX_DEBUG
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int gcd_3(int x, int y, int z){
  return gcd(gcd(x, y), z);
}

int main() {
  int K, ans = 0; scanf("%d", &K);
  for (int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        ans += gcd_3(i, j, k);
      }
    }
  }
  printf("%d", ans);
}

Measured memory_bytes: 3240
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxm=105;
int n,m,A[maxm],jc;
inline int read()
{
	int ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		A[i]=read();
		if(A[i]&1) jc++;
	}
	if(jc>2){printf("Impossible\n");return 0;}
	for(int i=2;i<m;i++)
	{
		if(A[i]&1)
		{
			if(A[1]&1) swap(A[i],A[m]);
			else swap(A[i],A[1]);
		}
	}
	for(int i=1;i<=m;i++)
		printf("%d%c",A[i],i==m?'\n':' ');
	if(m==1)
	{
		if(n!=1)
			printf("%d\n%d %d\n",2,1,n-1);
		else
			printf("%d\n%d\n",1,1);
	}
	else
	{
		printf("%d\n",m-(A[1]==1));
		for(int i=1;i<=m;i++)
		{
			if(i==1)
			{
				if(A[1]>1)
					printf("%d ",A[1]-1);
			}
			else if(i==m)
				printf("%d\n",A[m]+1);
			else printf("%d ",A[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int K, T;
    cin >> K >> T;
    vector<int> A(T);
    rep(i, T) cin >> A[i];

    int old = -1;
    while (true) {
        int mx = 0, mxi = -1;

        rep(i, T) {
            if (i != old && A[i] > mx) {
                mx = A[i];
                mxi = i;
            }
        }

        if (mxi == -1) {
            break;
        } else {
            A[mxi]--;
            old = mxi;
        }
    }

    int ans = 0;
    rep(i, T) {
        if (A[i] > 0) ans += A[i];
    }

    cout << ans << endl;
}



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

int main()
{
    int n;
    std::cin >> n;
    long long x, ans = 0;
    std::vector<long long> vec(n);
    std::cin >> x;
    for (int i = 0; i < n; ++i) { std::cin >> vec[i]; }
    std::sort(vec.begin(), vec.end());
    for (int i = 0; i < n; ++i)
    {
        if (x <= 0 || x < vec[i])
        {
            std::cout << ans << std::endl;
            return 0;
        }
        x -= vec[i];
        ++ans;
    }
    if (x > 0) { --ans; }
    std::cout << ans << std::endl;
    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 S = sc.nextLine();
        StringBuilder sb = new StringBuilder();

        for(int i=0; i<S.length(); i++){
            char a = S.charAt(i);
            if(Character.isUpperCase(a)) sb.append(Character.toLowerCase(a));
            else if(Character.isLowerCase(a)) sb.append(Character.toUpperCase(a));
            else sb.append(a);
        }

        System.out.println(sb);
    }
}


Measured memory_bytes: 26328
# -*- coding: utf-8 -*-

import sys

lines = sys.stdin.readlines()
for i in range(len(lines)/2):
    line1 = lines[2*i]
    line2 = lines[2*i+1]
    hit = blow = 0
    A = map(int, line1.split())
    B = map(int, line2.split())
    for i in range(4):
        if A[i] == B[i]:
            hit += 1
    for i in range(4):
        for j in range(4):
            if A[i] == B[j]:
                blow += 1
                break
    blow -= hit
    print "%d %d" %(hit, blow)

Measured memory_bytes: 6456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

ll divided_by_2(int x){
    if (x % 2) return 0;
    return 1 + divided_by_2(x / 2);
}

int main(){
    int n;
    cin >> n;
    ll cnt = 0;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        cnt += divided_by_2(a);
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_a
// https://atcoder.jp/contests/dp/tasks/dp_b
// https://atcoder.jp/contests/dp/tasks/dp_z
#include <bits/stdc++.h>
#define int             long long
#define ld              long double
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(int i=1;i<=n;i++)
#define fok(i,k,n)      for(int i=k;i<=n;i++)
#define rfo(i,n)        for(int i=n;i>=0;i--)
#define rfo1(i,n)       for(int i=n;i>0;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcount(x)
#define zerobits(x)     __builtin_ctz(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define endl            '\n'
#define mod             1000000007
#define M               (int)1e6+6
#define inf             1e18
using namespace std;

int n,m,k,x,y,z,a1,b,c,d,i,j,l,r;


void frog1(vi h)
{ int dp[n+1]={};
  dp[2]=abs(h[2]-h[1]);

  fok(i,3,n)dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  
  cout<<dp[n]<<endl;
}




void frog2(vi h,int k)
{
    int dp[n+1]={};
    dp[2]=abs(h[2]-h[1]);
    fok(i,3,n)
    {   dp[i]=inf;
        fo1(j,k)
        {   
            if(i-j>=1)
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n]<<endl;
}

void sol()
{   
    cin>>n; 
    //for frog2
    // cin>>k;
    in1(h,n);
    frog1(h);
    
    // frog2(h,k);
    
    
    // cout<<  <<endl;
}





int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // w(t)
    sol();
    return 0;
}



Measured memory_bytes: 2560
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
count=0
N=int(input())
for i in range(1,N+1):
	for j in range(1,N+1):
		for k in range(1,N+1):
			count+=(gcd_list([i,j,k]))
print(count)


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

typedef long long ll;
const ll InF = 1e15;
ll mod = 1000000007;
int a[100010];

int main() {
  ll n,m;
  cin>>n>>m;
  vector<ll> ans(n + 1, 0);
  for (int i = 0; i < m; i++) {
    int x;
    cin>>x;
    a[x] = 1;
  }
  ans[0] = 1, ans[1] = 1;
  if (a[1] == 1) ans[1] = 0;
  for (int i = 0; i <= n - 2; i++) {
    if (a[i + 2] == 1) ans[i + 2] = 0;
    else {
      ans[i + 2] = (ans[i + 1] + ans[i]) % mod;
    }
  }
  cout<<ans[n]<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n,m,ans=0;
	vector<int> x,l;
	cin >> n >> m;
	x.resize(m);
	l.resize(m-1);
	REP(i,m){
		cin >> x[i];
	}
	if(n >= m){
		cout << 0;
		return 0;
	}
	sort(x.begin(),x.end());
	REP(i,m-1){
		l[i] = x[i+1]-x[i];
	}
	sort(l.begin(),l.end());
	for(int i = 0; i<m-n; i++){
		ans += l[i];
	}
	cout << ans;
	return(0);
}

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


int main(){
  int x,y;
  cin >> x >> y;
  vector<int> a{1,3,5,7,8,10,12};
  vector<int> b{4,6,9,11};
  if( count(a.begin(),a.end(),x) == 1 &&
      count(a.begin(),a.end(),y) == 1   ){
    cout << "Yes" << endl;
    return 0;
  }
  if( count(b.begin(),b.end(),x) == 1 &&
      count(b.begin(),b.end(),y) == 1   ){
    cout << "Yes" << endl;
    return 0;
  }
  if( x == 2 && y == 2 ){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = -10000;

int main(){
  int MAX = 101010;
  vector<int> is_prime(MAX,1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i = 2;i<MAX;i++){
    if(!is_prime[i]) continue;//素数でないものは飛ばす
     for(int j = i*2;j<MAX;j+=i){//素数が見つかればふるいにかける
      is_prime[j] = 0;
    }
  }
    vector<int> a(MAX,0);
    for(int i = 0;i<MAX;i++){
      if(i%2 == 0) continue;
      if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    vector<int> s(MAX+1,0);
    for (int i = 0; i < MAX; ++i){
      s[i+1] = s[i] + a[i];
    }
    int Q;
    cin >> Q;
    for(int q = 0;q<Q;q++){
      int l,r;
      cin >> l >> r;
      cout << s[r+1]-s[l] << endl;
       }
    }


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    ll ar[n];
    int ok=0;
    for(ll i=0;i<n;++i)
    {
        cin>>ar[i];
        if(ar[i]==1){ok=1;}
    }
    if(!ok){cout<<"-1";return(0);}

    map<ll,ll> m;

    for(ll i=n-1;i>=0;--i)
    {
        ll x=ar[i];
        if(m.find(x+1)==m.end())
        {
            m[x]=1;
        }
        else
        {
            m[x]=max(m[x+1]+1,m[x]);
        }
    }
    ll ans=n-m[1];
    cout<<ans;

    return (0);
}


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

int main(){
    string S;
    int Q;
    bool change = false;
    cin>>S>>Q;
    deque<char> data(S.size());
    for(int i=0; i<S.size(); i++) data[i] = S[i];

    for(int i=0; i<Q; i++){
        int T,F;
        char C;
        cin>>T;
        if(T == 1){
            if(change)change = false;
            else change = true;
        }

        else{
            cin>>F>>C;
            F--;
            if(change)  F = 1-F;
            if(F == 0){
                data.push_front(C);
            }

            else data.push_back(C);

        }
    }

    if(change) reverse(data.begin(),data.end());
    for(int i=0; i<data.size(); i++) cout<<data[i];
    cout<<endl;
     
    return 0;
}

Measured memory_bytes: 896
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var N = Sarray()[0];
            var Ai = Slist();
            var ans = new long[N];
            for (var i = 0; i < N; ++i)
            {
                ans[Ai[i] - 1] = i + 1;
            }
            for (var i = 0; i < N; ++i)
                Write($"{ans[i]} ");

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 29144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

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

	ll N;
	cin >> N;

	ll a[N];
	rep(i,N) cin >> a[i];

	vector<P> ps;
	rep(i,N) ps.push_back(make_pair(a[i],-i));

	// a[i]が大きい順,iが小さい順(-iが大きい順)に並べる
	sort(ps.begin(),ps.end());
	reverse(ps.begin(),ps.end());

	ll ans[N] = {};
	ll mn = N;
	rep(i,N-1){
		P p0 = ps[i],p1 = ps[i+1];
		mn = min(mn,-p0.second);

		if(p1.first < p0.first){
			ans[mn] += (p0.first - p1.first) * (i+1);
		}
	}

	P pl = ps[N-1];
	mn = min(mn,-pl.second);
	ans[mn] += pl.first * N;

	rep(i,N){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4336
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include<string>
#include<queue>

using namespace std;

int dist[2003][2003];
int sum[2003][2003];
int H, W;

int vx[]{ 1,0,-1,0 };
int vy[]{ 0,1,0,-1 };

bool inside(int y, int x)
{
	return y >= 0 && x >= 0 && y < H && x < W;
}

vector<string> board;

int main() {
	int Q;
	cin >> H >> W >> Q;
	board = vector<string>(H);
	for (int i = 0; i < H; i++)
	{
		cin >> board[i];
	}
	int MAX = 99999999;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			dist[i][j] = MAX;
		}
	}


	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (board[i][j] == '1')
			{
				if (dist[i][j] != MAX) continue;
				sum[i + 1][j + 1]++;

				queue<pair<int, int>> q;
				dist[i][j] = 0;
				q.push(make_pair(i, j));
				while (!q.empty())
				{
					pair<int, int> now = q.front(); q.pop();
					int y = now.first;
					int x = now.second;
					for (int k = 0; k < 4; k++)
					{
						int ny = y + vy[k];
						int nx = x + vx[k];
						if (!inside(ny, nx)) continue;
						if (board[ny][nx] == '0') continue;
						if (dist[ny][nx] != MAX) continue;

						//ここに更新処理を挿入
						dist[ny][nx] = dist[y][x] + 1;

						q.push(make_pair(ny, nx));
					}
				}
			}
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
		}
	}

	for (int t = 0; t < Q; t++)
	{
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &y1, &x1, &y2, &x2);
		y1--; x1--;

		long ans = 0;
		ans += sum[y2][x2] - sum[y1][x2] - sum[y2][x1] + sum[y1][x1];

		if (x1 != 0)
		{
			for (int y = y1; y < y2; y++)
			{
				if (dist[y][x1] - 1 == dist[y][x1 - 1]) ans++;
			}
		}
		if (x2 != W)
		{
			for (int y = y1; y < y2; y++)
			{
				if (dist[y][x2 - 1] - 1 == dist[y][x2]) ans++;
			}
		}


		if (y1 != 0)
		{
			for (int x = x1; x < x2; x++)
			{
				if (dist[y1][x] - 1 == dist[y1 - 1][x]) ans++;
			}
		}
		if (y2 != H)
		{
			for (int x = x1; x < x2; x++)
			{
				if (dist[y2 - 1][x] - 1 == dist[y2][x]) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 37248
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;
int i,j,k;
int main(){
    int n;cin>>n;
    vector<int> v(n);for(i=0;i<n;i++){cin>>v[i];}
    vector<int> v1,v2;
 
    for(i=0;i<n;i++){
        if(i%2==0){v1.push_back(v[i]);}
        else{v2.push_back(v[i]);}
    }
 
    vector<int> v1num(1000000,0),v2num(1000000,0);
    for(i=0;i<n/2;i++){
        v1num[v1[i]]++;
        v2num[v2[i]]++;
    }
 
    int v1max=0,v2max=0,maxnumber1,maxnumber2;
    for(i=0;i<n/2;i++){
        if(v1max<v1num[v1[i]]){v1max=v1num[v1[i]];maxnumber1=v1[i];}
        if(v2max<v2num[v2[i]]){v2max=v2num[v2[i]];maxnumber2=v2[i];}
    }
 
    int v1max_second=0,v2max_second=0;
    for(i=0;i<n/2;i++){
        if(v1max_second<v1num[v1[i]] && !(v1[i]==maxnumber1 && v1num[v1[i]]==v1max)){//maxが同数になる場合も考慮してmax_secandを定める
            v1max_second=v1num[v1[i]];
        }
        if(v2max_second<v2num[v2[i]] && !(v2[i]==maxnumber2 && v2num[v2[i]]==v2max)){
            v2max_second=v2num[v2[i]];
        }
    }
 
    if(maxnumber1!=maxnumber2){cout<<(n-v1max-v2max)<<endl;}
    else{
        if(v1max>v2max){cout<<min(n-v1max-v1max_second,n-v1max-v2max_second)<<endl;}
        else{cout<<min(n-v2max-v1max_second,n-v2max-v2max_second)<<endl;}
    }
 
    return 0;
}

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

const int mod = 1e9 + 7;
const int N = 1e5 + 10;

vector<int> adj[N];
int k;
bool vis[N];

int ans = 1;

void dfs(int n,int level = 1)
{
    vis[n] = true;

    if(level == 1)
    {
        for(int i = 1; i <= adj[n].size(); ++i)
        {
            ans = (ans*(k-i))%mod;
        }
    }
    else
    {
        for(int i = 1; i < adj[n].size(); ++i)
        {
            ans = (ans*(k-i-1))%mod;
        }
    }
    
    for(int x : adj[n])
    {  
        if(!vis[x])
        {
            dfs(x,level + 1);
        }
    }
}

signed main()
{
    int n;
    cin >> n >> k;
    for(int i = 0; i < n - 1; ++i)
    {
        int u,v;
        cin >> u >> v;
        --u,--v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(0);

    cout << (k*ans)%mod;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(void) {
    int N;
    int a[100];
    cin >> N;

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

    sort(a, a + N, greater<int>());

    int score[2] = {0};

    for (int i = 0; i < N; i++) {
        score[i % 2] += a[i];
    }

    cout << (score[0] - score[1]);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
  int q,a,b;
  int i,j;
  char str[1001],strcp[1001],ins[8];
  scanf("%s",str);
  scanf("%d",&q);
  for(i=0;i<q;i++)
  {
    scanf("%s %d %d",ins,&a,&b);
    if(!strcmp(ins,"print"))
    {
      for(j=a;j<=b;j++)
      {
    printf("%c",str[j]);
    if(j==b)printf("\n");
      }
    }
    if(!strcmp(ins,"reverse"))
    {
      for(j=0;j<=(b-a)/2;j++)
      {
    char temp = str[a+j];
    str[a+j]=str[b-j];
    str[b-j]=temp;
      }
    }
    if(!strcmp(ins,"replace"))
    {
      char p;
      for(j=0;j<=b-a;j++)
      {
    scanf(" %c",&p);
    str[a+j]=p;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2108
n=int(input())
a=list(map(int,input().split()))
from fractions import gcd
L=[0]
R=[]
l=a[0]
r=a[-1]
for i in range(n-1):
    l=gcd(a[i], l)
    L.append(l)
    r=gcd(a[-i-1], r)
    R.append(r)
R=R[::-1]
R.append(0)
M=[]
#print(L,R)
for i in range(n):
    m=gcd(L[i],R[i])
    M.append(m)
print(max(M))

Measured memory_bytes: 98280
#include<stdio.h>

int main(void){

    char S[4];
    int ans = 0;

    scanf("%s",S);

    if(S[0] == 'S' && S[1] == 'U'){
        ans += 7;
    }else if(S[0] == 'M'){
        ans += 6;
    }else if(S[0] == 'T' && S[1] == 'U'){
        ans += 5;
    }else if(S[0] == 'W'){
        ans += 4;
    }else if(S[0] == 'T' && S[1] == 'H'){
        ans += 3;
    }else if(S[0] == 'F'){
        ans += 2;
    }else if(S[0] == 'S' && S[1] == 'A'){
        ans += 1;
    }

    printf("%d\n",ans);
    return 0;
}

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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int S, W;
  cin >> S >> W;
  if (W>=S) {
    cout << "un";
  }
  cout << "safe\n";
}


Measured memory_bytes: 3580
n = gets.to_i
first = -1
second = -1

A = Array.new(n) do
  gets.to_i.tap do |i|
    if first < i
      second = first
      first = i
    elsif second < i
      second = i
    end
  end
end

A.each do |a|
  if a == first
    puts second
  else
    puts first
  end
end


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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 vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    const i64 mod = 1'000'000'007;
    
    i64 N;
    cin >> N;
    
    vector<i64> C(N);
    rep(i,0,N){
        cin >> C[i];
        --C[i];
    }
    
    const i64 maxc=200000;
    vector<i64> last(maxc,-1),next(maxc,-1);
    for(i64 i=N-1; i>=0; --i){
        if(last[C[i]]!=-1){
            next[i]=last[C[i]];
            last[C[i]]=i;
        }else{
            last[C[i]]=i;
        }
    }
    
    vector<i64> memo(N+1);
    vector<bool> done(N+1);
    function<i64(i64)> rec=[&](i64 i){
        auto& res=memo[i];
        if(done[i]) return res;
        done[i]=true;
        
        if(i==N-1) return res=1;
        
        if(C[i]==C[i+1]){
            return res=rec(i+1);
        }
        
        res=rec(i+1);
        if(next[i]!=-1){
            res+=rec(next[i]);
            res%=mod;
        }
        
        return res;
    };
    
    cout << rec(0) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
namespace ProjectSedge
{
	struct edge
	{
		int to,w;
		edge(int x2=0,int x3=0){to=x2,w=x3;}
	};
	vector<edge>e[1000001];
	int seg[1000001*4];
	int mx,add;
	void build(int node,int l,int r)
	{
		if(l==r)
		{
			seg[l]=node;
			e[node].push_back(node+add);
			return;
		}
		int mid=(l+r)/2;
		e[node].push_back(edge(node*2,0));
		e[node].push_back(edge(node*2+1,0));
		e[node*2+add].push_back(edge(node+add,0));
		e[node*2+1+add].push_back(edge(node+add,0));
		build(node*2,l,mid);
		build(node*2+1,mid+1,r);
	}
	void init(int x)
	{
		for(int i=1;i<=add*2;i++)
			e[i].clear();
		mx=x;
		add=mx*4;
		build(1,1,mx);
	}
	void connect(int node,int st,int ed,int l,int r,int x,int ind)
	{
		if(st>r||ed<l) return;
		if(st>=l&&ed<=r)
		{
			e[seg[x]+add].push_back(edge(node,ind));
			return;
		}
		int mid=(st+ed)/2;
		connect(node*2,st,mid,l,r,x,ind);
		connect(node*2+1,mid+1,ed,l,r,x,ind);
	}
}
using namespace ProjectSedge;
int tot,cnt;
int dfn[1000001],low[1000001],vis[1000001],col[1000001];
stack<int>s;
void tarjan(int u)
{
	low[u]=dfn[u]=++cnt;
	s.push(u);
	vis[u]=1;
	for(int i=0;i<e[u].size();i++)
	{
		int to=e[u][i].to;
		if(!dfn[to])
		{
			tarjan(to);
			low[u]=min(low[u],low[to]);
		}
		else if(vis[to])
			low[u]=min(low[u],dfn[to]);
	}
	if(dfn[u]==low[u])
	{
		tot++;
		while(s.top()!=u)
		{
			col[s.top()]=tot;
			vis[s.top()]=0;
			s.pop();
		}
		col[u]=tot;
		vis[u]=0;
		s.pop();
	}
}
int n;
struct node
{
	int v,id;
}p[1000001];
bool cmp(node a,node b){return a.v<b.v;}
pair<int,int> get(int x,int d)
{
	int l=0,r=2*n+1,ansl,ansr;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(p[mid].v<x-d+1) l=mid;
		else r=mid;
	}
	ansl=r;
	l=0,r=2*n+1;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(p[mid].v<=x+d-1) l=mid;
		else r=mid;
	}
	ansr=l;
	return make_pair(ansl,ansr);
}
int rev[1000001];
int oth[1000001];
bool check(int d)
{
	init(n*2);
	tot=0,cnt=0;
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(col,0,sizeof(col));
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=2*n;i++)
	{
		pair<int,int> pr=get(p[i].v,d);
		connect(1,1,mx,pr.first,i-1,rev[oth[p[i].id]],0);
		connect(1,1,mx,i+1,pr.second,rev[oth[p[i].id]],0);			
	}
	for(int i=1;i<=add*2;i++)
		if(!col[i])
			tarjan(i);
	for(int i=1;i<=n;i++)
		if(col[seg[rev[i]]]==col[seg[rev[i+n]]])
			return false;
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&p[i].v,&p[i+n].v);
		p[i].id=i,p[i+n].id=i+n,oth[i]=i+n,oth[i+n]=i;
	}
	sort(p+1,p+2*n+1,cmp);
	for(int i=1;i<=2*n;i++)
		rev[p[i].id]=i;
	int l=-1,r=1000000001;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(check(mid))
			l=mid;
		else
			r=mid;
	}
	printf("%d",l);
	return 0;
}
/*
2
1 2
1 4
*/


Measured memory_bytes: 63568
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

maxmax=max(a)
maxmax_ind=a.index(maxmax)
a[maxmax_ind]=0
maxmax2=max(a)
a[maxmax_ind]=maxmax

if maxmax==maxmax2:
    for i in range(n):
        print(maxmax)

else:
    for i in range(n):
        if i==maxmax_ind:
            print(maxmax2)
        else:
            print(maxmax)

Measured memory_bytes: 12532
#include <stdio.h>
int main(int argc, char const *argv[])
{
  int h,n;
  int sum=0;
  scanf("%d%d",&h,&n);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[n]);
    sum+=a[n];
  }
  if(sum<h){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end()			// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
typedef long long ll;

int main() {
	string S, T; cin >> S >> T;
	vector<int> start(26, -1);
	vector<int> goal(26, -1);

	for (int  i = 0; i < S.size(); i++)
	{
		int a = S[i] - 'a';
		int b = T[i] - 'a';

		if (start[a] != -1 || goal[b] != -1)
		{
			if (start[a] != b || goal[b] != a)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			start[a] = b;
			goal[b] = a;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
 int n; cin >> n;
 vector<double> a(n);
 vector<double> b(n);
 double sum=0;
 for(int i=0;i<n;i++){
   cin >> a[i];
   b[i]=1/a[i];
   sum+=b[i];
 }
 cout << 1/sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, ll> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

ll ds(ll x){
	return ((x<10)?x:x%10+ds(x/10));
}

bool comp(P a, P b){
	return (a.first == b.first)?(a.second < b.second):(a.first < b.first);
}

vector<P> v;

int main(void){
	ll k,i,t=1ll,b=0ll,j,x,y,p=0ll;
	for(i=1ll; i<1000; ++i){
		x = i;
		y = ds(i);
		for(j=0; j<15; ++j){
			v.push_back(P((double)(x)/y,x));
			x *= 10;
			x += 9;
			y += 9;
		}
	}
	sort(v.begin(),v.end(),comp);
	cin >> k; i=0;
	while(k){
		if(v[i].second > p){
			p = v[i].second;
			cout << p << endl;
			--k;
		}
		++i;
	}
	return 0;
}


Measured memory_bytes: 640
n = int(input())
a = sorted(int(input()) for _ in range(n))
m = n // 2
if n % 2 == 0:
    ans = (sum(a[m:]) - sum(a[:m])) * 2 - a[m] + a[m-1]
    print(ans)
else:
    ans1 = (sum(a[m+1:]) - sum(a[:m])) * 2 - a[m] + a[m-1]
    ans2 = (sum(a[m+1:]) - sum(a[:m])) * 2 - a[m+1] + a[m]
    print(max(ans1, ans2))

Measured memory_bytes: 7524
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_4-C: Dictionary

#include <cstdio>
#include <cstring>
#include <cassert>

template <unsigned int N>
class dictionary {
  char** data_;
  unsigned int size_ = 0; // for assert
public:
  dictionary() {
    data_ = new char*[N];
    for (auto i = 0U; i < N; ++i) {
      data_[i] = nullptr;
    }
  }
  ~dictionary() {
    for (auto i = 0U; i < N; ++i) {
      delete data_[i]; // delete nullptr is ok!
    }
    delete[] data_;
  }
  void insert(const char* cp) {
    assert(size_ < N-1); // at least one vacancy entry needed for not found
    auto i = find_index(cp);
    if (data_[i]) return; // cp was already inserted
    auto buf = new char[std::strlen(cp)+1];
    std::strcpy(buf, cp);
    data_[i] = buf;
    ++size_;
  }
  bool find(const char* cp) const {
    auto i = find_index(cp);
    return data_[i] ? true : false;
  }
private:
  unsigned int find_index(const char* cp) const {
    auto h1 = hash1(cp), h2 = hash2(h1);
    auto h = h1%N;
    for (auto i = 0U; ; ++i) {
      if (data_[h] == nullptr || std::strcmp(data_[h], cp) == 0) {
        return h;
      }
      h = (h+h2)%N; // (h + i*h2(h)) % N;
    }
  }
  unsigned int hash1(const char* cp) const {
    auto h = 0U;
    for (; *cp; ++cp) {
      h = 31*h + *cp;
    }
    return h % N;
  }
  unsigned int hash2(int h1) const {
    return h1 ? (N-h1) : 1;
  }
};


int main(void) {
  const unsigned int M = 1250437; // prime number * 0.8 > 1000000
  dictionary<M> dict;

  int n;
  std::scanf("%d", &n);
  
  for (auto i = 0; i < n; ++i) {
    char buf1[6+1]; // "insert".size() + 1('\0')
    char buf2[12+1]; // 12(max)+1('\0')
    std::scanf("%6s %12s", buf1, buf2);
    if (buf1[0] == 'i') { // insert ...
      dict.insert(buf2);
    } else { // find ...
      auto found = dict.find(buf2);
      puts(found ? "yes" : "no");
    }
  }

  return 0;
}
// end

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

using namespace std;

const int MAX_N = 200000, MAX_Q = 200000, INDEX = 1;
const long long INF = (long long)(MAX_N) * (long long)(MAX_Q) + 1;

long long min(long long a, long long b) {
    if (a < b) {
        return a;
    } else {
        return b;
    }
}

template <typename T>
class SegmentTree {
private:

    int n;
    vector<T> st;
    T e;
    T (*f)(T a, T b);

public:

    SegmentTree() {
        ;
    }

    SegmentTree(int n, T e, T (*f)(T a, T b)) {
        this->n = n;
        this->st.reserve(4 * n);
        this->e = e;
        this->f = f;

        build(0, 1, this->n);
    }

private:

    void build(int v, int l, int r) {
        if (l == r) {
            st[v] = e;

            return ;
        }

        int m = (l + r) / 2;

        build(2 * v + 1, l, m);
        build(2 * v + 2, m + 1, r);

        st[v] = f(st[2 * v + 1], st[2 * v + 2]);
    }

    T getst(int v, int l, int r, int lb, int rb) {
        if (lb > rb) {
            return e;
        }

        if (l == lb && r == rb) {
            return st[v];
        }

        int m = (l + r) / 2;

        return f(getst(2 * v + 1, l, m, lb, min(rb, m)), getst(2 * v + 2, m + 1, r, max(lb, m + 1), rb));
    }

    void changest(int v, int l, int r, int ind, T val) {
        if (ind < l || ind > r) {
            return ;
        }

        if (l == r) {
            st[v] = val;

            return ;
        }

        int m = (l + r) / 2;

        changest(2 * v + 1, l, m, ind, val);
        changest(2 * v + 2, m + 1, r, ind, val);

        st[v] = f(st[2 * v + 1], st[2 * v + 2]);
    }

public:

    T get(int l, int r) {
        return getst(0, 1, n, l, r);
    }

    void change(int ind, T val) {
        changest(0, 1, n, ind, val);
    }
};

int n, q, a, b, x[MAX_Q + INDEX];
long long dp[MAX_N + INDEX];
SegmentTree<long long> stl, str;

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

    cin >> n >> q >> a >> b;

    for (int i = 1; i <= q; i++) {
        cin >> x[i];
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = INF;
    }

    stl = SegmentTree<long long>(n, INF, min);
    str = SegmentTree<long long>(n, INF, min);

    dp[a] = abs(x[1] - b);
    dp[b] = abs(x[1] - a);

    stl.change(a, dp[a] - a);
    stl.change(b, dp[b] - b);
    str.change(a, dp[a] + a);
    str.change(b, dp[b] + b);

    for (int i = 2; i <= q; i++) {
        dp[x[i - 1]] = min(dp[x[i - 1]], min(dp[x[i]], min(stl.get(1, x[i] - 1) + x[i], str.get(x[i] + 1, n) - x[i])) - abs(x[i] - x[i - 1]));

        stl.change(x[i - 1], dp[x[i - 1]] - x[i - 1]);
        str.change(x[i - 1], dp[x[i - 1]] + x[i - 1]);
    }

    long long ans = INF;
    for (int i = 1; i <= n; i++) {
        ans = min(ans, dp[i]);
    }

    for (int i = 2; i <= q; i++) {
        ans += abs(x[i] - x[i - 1]);
    }

    cout << ans << endl;

    return 0;
}


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

bool isPrime(int n)
{
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main()
{
    int n, a, count = 0;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (isPrime(a))
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define y2 cyktxdy
typedef long long ll;
typedef vector<int> poly;
typedef vector<ll> Poly;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline ll readl() {
  ll ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline int Read(char*s) {
  int top=0;
  char ch=gc();
  while(!isalpha(ch)&&!isdigit(ch)) ch=gc();
  while(isalpha(ch)||isdigit(ch)) s[++top]=ch,ch=gc();
  return top;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
}
using namespace modular;
template<typename T>inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T>inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T>inline T gcd(T a,T b) { T t;while(b) t=a,a=b,b=t-t/a*a;return a; }
const int N=1005;
int n,K,f[2][N],cur=0,fac[N],ifac[N];
inline void init_fac() {
  fac[0]=fac[1]=ifac[0]=ifac[1]=1;
  for(ri i=2;i<=n;++i) {
    fac[i]=mul(fac[i-1],i);
    ifac[i]=mul(ifac[mod-mod/i*i],mod-mod/i);
  }
  for(ri i=2;i<=n;++i) Mul(ifac[i],ifac[i-1]);
}
inline int C(int n,int m) { return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m])); }
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read(),K=read();
  init_fac();
  f[cur][0]=1;
  for(ri x;K;--K) {
    x=read();
    cur^=1;
    for(ri i=0;i<=n;++i) {
      f[cur][i]=0;
      for(ri j=max(0,i-x);j<=i;++j) Add(f[cur][i],mul(f[cur^1][j],mul(C(n-j,i-j),C(n-(i-j),x-(i-j)))));
    }
  }
  cout<<f[cur][n];
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define N 3

int main() {
	
	int a,b,c;
	
	cin >> a >> b >> c;
	
	int sum1 = a+b;
	int sum2 = b+c;
	int sum3 = c+a;
	
	if(sum1 < sum2 && sum1 < sum3) cout << sum1 << endl;
	if(sum2 < sum1 && sum2 < sum3) cout << sum2 << endl;
	if(sum3 < sum2 && sum3 < sum1) cout << sum3 << endl;
	if(sum1 == sum2 && sum1 == sum3) cout << sum1 << endl;
		
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
void solve(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    pair<ll,short int> apples[a+b+c];
    for(int i=0;i<a;i++){
        int z;
        cin>>z;
        apples[i]=mp(z,0);
    } 
    for(int i=0;i<b;i++){
        int z;
        cin>>z;
        apples[i+a]=mp(z,1);
    }
    for(int i=0;i<c;i++){
        int z;
        cin>>z;
        apples[i+a+b]=mp(z,2);
    }
    sort(apples,apples+a+b+c,greater<pair<ll,short int>>());
    int applesused=0;
    int redused=0,greenused=0;
    ll score=0;
    for(int i=0;i<a+b+c;i++){
        if(applesused==x+y){
            break;
        }
        if(apples[i].second==2){
            score+=apples[i].first;
            applesused++;
            continue;
        }
        if(apples[i].second==1 && greenused<y){
            score+=apples[i].first;
            greenused++;
            applesused++;
            continue;
        }
        if(apples[i].second==0 && redused<x){
            score+=apples[i].first;
            redused++;
            applesused++;
            continue;
        }
    }
    cout<<score;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <string>
#include <list>

using namespace std;

int main(void) {

    string s;
    bool f = false;
    cin >> s;

    for (int i = 0; i < 3; i++)
    {
        if ( s[i] == '7') {
            f = true;
            break;
        }
    }

    if (f == true) {
        cout << "Yes";
    }    else {
        cout << "No";
    }

}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long

int main(){
    ll n;
    char s[5];
    scanf("%s",s);
    if(s[0]==s[1]&&s[1]==s[2]){
        printf("No");
        return 0;
    }else{
        printf("Yes");
        return 0;
    }
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

b = min(a)
li = [x%b for x in a]
c = max(li)

if c == 0:
    ans = b
else:
    while c != 0:
        d = c # 一時記憶
        c = b%c
        if c == 0:
            ans = d
        else:
            b = d # 戻す
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
#include <iostream>
using namespace std;

int A,B;
int main (){
	cin >>A>>B;
	if (A==B){
		cout<<"Draw";
	}else if (A==1){
		cout<<"Alice";
	}else if (B==1){
		cout<<"Bob";
	}else if (A<B){
		cout<<"Bob";
	}else if (A>B){
		cout<<"Alice";
	}
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int H, W;
int cnt = 0;
vector<string> grid;

bool is_symmetric(int x1, int x2, const vector<int> &perm)
{
    for (int y=0; y<H; y++) {
        assert(perm[y]>=0);
        if (grid[perm[y]][x1] != grid[perm[H-y-1]][x2]) return false;
    }
    return true;
}

bool match(const vector<int> &perm)
{
#ifdef DEBUG
    rep(i, H) cerr << perm[i] << " ";
    cerr << endl;
#endif

    int used = 0;
    bool allow_alone = W%2;
    for (int x1=0; x1<W; x1++) {
        if ((used>>x1) & 1) continue;
        bool matched = false;
        for (int x2=0; x2<W; x2++) {
            if (x1 == x2) continue;
            if ((used>>x2) & 1) continue;

            if (is_symmetric(x1, x2, perm)) {
                used |= (1<<x1), used |= (1<<x2);
                matched = true;
                break;
            }
        }

        if (!matched && allow_alone) {
            if (is_symmetric(x1, x1, perm)) {
                used |= (1<<x1);
                allow_alone = false;
                matched = true;
            }
        }

        if (!matched) {
            return false;
        }
    }
    return __builtin_popcount(used) == W;

    // return match_dfs(0, 0, W%2, perm);
}

bool dfs(int y1, int used, bool allow_alone, int y1_pos, int y2_pos, vector<int> &perm)
{
    if (used == (1<<H) - 1) {
        cnt++;
        return match(perm);
    }

    if ((used>>y1) & 1) {
        return dfs(y1+1, used, allow_alone, y1_pos, y2_pos, perm);
    }

    used |= (1<<y1);

    bool res = false;
    if (allow_alone) {
        perm[H/2] = y1;
        res = dfs(y1+1, used, false, y1_pos, y2_pos, perm);
        perm[H/2] = -1;
    }

    perm[y1_pos] = y1;

    for (int y2=y1+1; y2<H; y2++) {
        if ((used>>y2) & 1) continue; 
        used |= (1<<y2);
        perm[y2_pos] = y2;
        res  |= dfs(y1+1, used, allow_alone, y1_pos+1, y2_pos-1, perm);
        perm[y2_pos] = -1;
        used &= ~(1<<y2);
    }

    perm[y1_pos] = -1;
    used &= ~(1<<y1);

    return res;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> H >> W;

    rep(i, H) {
        string S; cin >> S;
        grid.push_back(S);
    }

    vector<int> perm(H, -1);
    cout << (dfs(0, 0, H%2, 0, H-1, perm) ? "YES" : "NO") << endl;
    return 0;
}



Measured memory_bytes: 256