akhauriyash/Code-Regression huggingface dataset:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A = LS2()
N = len(A)

# 答えは、(Ai != Aj たる 1 <= i < j <= N の個数) +1

from collections import defaultdict

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

ans = 0
for key in d.keys():
    ans += d[key]*(N-d[key])

ans //= 2
ans += 1
print(ans)


Measured memory_bytes: 82108
def main():
    N, M = map(int, input().split())
    cnt = [1] * N
    red = [False] * N
    red[0] = True
    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        cnt[x] -= 1
        cnt[y] += 1
        if red[x] == True:
            red[y] = True
            if cnt[x] == 0:
                red[x] = False
    ans = 0
    for i in red:
        if i:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 47448
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String a = sc.next();
            String b = sc.next();
            char ach = a.charAt(0);
            char bch = b.charAt(0);
            if ( ach > bch ) {
                System.out.println(">");
            } else if ( ach < bch ) {
                System.out.println("<");
            } else {
                System.out.println("=");
            }
        }
    }
}


Measured memory_bytes: 25172
import sys

def chmin(a,i,b):
  if a[i] > b:
    a[i] = b
    #print(a)
    return True
  else:
    return False

n = int(input())
abc = [[0 for i in range(3)] for j in range(n)]
dp = [[0 for i in range(3)] for j in range(n+1)]

for i in range(n):
  a,b,c = map(int, input().split() ) 
  abc[i][0] = a
  abc[i][1] = b
  abc[i][2] = c

for i in range(1,n+1):
  for j in range(3):
    for k in range(3):
      if j == k:
        continue
      
      dp[i][j] = max(dp[i][j], abc[i-1][j]+dp[i-1][k])

  
  
#print(abc)
#print(dp)
ret = 0
for i in range(3):
  ret = max(ret, dp[n][i])
 
print(ret)


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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream& os, const set<T>& v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const map<T,S>& v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "TRACE ON! (Line: " << __LINE__ << ")\n"; auto _stream = istringstream{string{#args}}; d_f(_stream, args); } while(0)
	void d_f(__attribute__((unused)) istringstream& _stream) {}
	template<typename Head, typename... Tails> void d_f(istringstream& _stream, Head H, Tails... T) { string _name; _stream >> _name; if(_name.back() == ',') _name.pop_back(); cerr << "\t" << _name << " <=> [" << H << "]\n"; d_f(_stream, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

void solve(){
	int n;
	cin >> n;

	vector<int> arr(n);
	for(auto& i: arr) cin >> i;

	int tot = 0;
	for(auto i: arr) tot ^= i;

	for(auto i: arr) cout << (i ^ tot) << " ";
}

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

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3984
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int x[n];
    int y[n];
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        cin >> y[i];
        cin >> h[i];
    }   
    int ansx = 101;
    int ansy = 101;
    int ansh;
    int ht; 
    bool flag = true;
    for (int i = 0; i <= 100; i++) {
        if (ansx < 101) {
            break;
        }
        for (int j = 0; j <= 100; j++) {
            flag = true;
            for (int k = 0; k < n; k++) {
                if (h[k] != 0) {
                    ht = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    break;
                    //
                    cout << "ht" << endl;
                }
            }
            for (int k = 0; k < n; k++) {
                if ((h[k] != 0 && h[k] != ht - abs(x[k] - i) - abs(y[k] - j)) || (h[k] == 0 && ht - abs(x[k] - i) - abs(y[k] - j) > 0)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ansx = i; 
                ansy = j;
                ansh = ht; 
                break;
            }
        }
    }
    cout << ansx << " " << ansy << " " << ansh << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

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

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

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define oo 100005
using namespace std;
long long stk[oo], f[oo], sum[oo];
int top, n, m;
void solve (long long len, long long p)
{
    if(!len) return;
    int t = upper_bound(stk + 1, stk + top + 1, len) - stk - 1;
    if(!t) sum[1] += p, sum[len + 1] -= p;
    else f[t] += len / stk[t] * p, solve(len % stk[t], p);
}
int main ()
{
    scanf("%d%d", &n, &m);
    stk[top = 1] = n;
    for(int i = 1; i <= m; ++ i)
    {
        long long tmp;
        scanf("%lld", &tmp);
        while(tmp <= stk[top]) -- top;
        stk[++ top] = tmp;
    }
    f[top] = 1;
    for(int i = top; i > 1; -- i)
    {
        f[i - 1] += stk[i] / stk[i - 1] * f[i];
        solve(stk[i] % stk[i - 1], f[i]);
    }
    sum[1] += f[1]; sum[stk[1] + 1] -= f[1];
    for(int i = 1; i <= n; ++ i)
    printf("%lld\n", sum[i] += sum[i - 1]);
    return 0;
}

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

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

inline void Main() {
  int n; cin >> n;
  int x = (n + 999) / 1000;
  cout << x * 1000 - n << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void){
	int i,n,j,k;
	int cards[4][13];
	char smark[2];
	int mark,num;

	for(j=0;j<4;j++){
		for(k=0;k<13;k++){
			cards[j][k]=0;
		}
	}

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",&smark,&num);

		if(smark[0] =='S') {
			mark=0;
		}
		if(smark[0] =='H') {
			mark=1;
		}
		if(smark[0] =='C') {
			mark=2;
		}
		if(smark[0] =='D') {
			mark=3;
		}
		for(j=0;j<4;j++){
			for(k=0;k<13;k++){
				if((j==mark) && (k==num-1) ){
					cards[j][k]=1;
				}
			}
		}
	}

	for(j=0;j<4;j++){
		for(k=0;k<13;k++){
			if(cards[j][k]==0){
				if(j==0) {
					smark[0] ='S';
				}
				if(j==1) {
					smark[0] ='H';
				}
				if(j==2) {
					smark[0] ='C';
				}
				if(j==3) {
					smark[0] ='D';
				}
				printf("%s %d\n",smark, k+1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 596
from collections import deque
dxdy = ((-1,0), (1,0), (0,-1), (0,1)) # タプルやリストで持っておくと便利

H, W, K = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
mp = [input() for _ in range(H)]
INF = 10**10
dist = [[INF]*W for _ in range(H)]
dist[x1-1][y1-1] = 0
q = deque()
q.append((x1-1,y1-1)) # スタート地点をenqueue
while(q):
    x, y = q.popleft()
    if x==x2-1 and y==y2-1:
        print (dist[x2-1][y2-1])
        exit()
    else:
        for dx, dy in  dxdy:
            for i in range(1,K+1):
                nx = x + dx*i
                ny = y + dy*i
                if not (0<=nx<H and 0<=ny<W) or mp[nx][ny]=='@':
                    break
                #print(nx,ny,x,y)
                #print (dist[nx][ny] , dist[x][y])
                if dist[nx][ny] <= dist[x][y]:
                    break 
                #print(nx,ny,x,y)
                if dist[nx][ny] == INF:
                    q.append((nx,ny))
                dist[nx][ny] = dist[x][y] + 1
print(-1)




Measured memory_bytes: 36708
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,k;
    cin>>a>>b;
    int chart[a][b];
    int chart2[a][b];
    char ch[a][b];
    for(i=0;i<a;i++){
        for(j=0;j<b;j++){
            char s;
            chart[i][j]=0;
            chart2[i][j]=0;
            cin>>s;
            ch[i][j]=s;
            if(j==0&&s=='.')
            chart[i][j]=1;
            else if(s=='.')
            chart[i][j]=chart[i][j-1]+1;
            else
            chart[i][j]=0;
            if(i==0&&s=='.')
            chart2[i][j]=1;
            else if(s=='.')
            chart2[i][j]=chart2[i-1][j]+1;
            else
            chart2[i][j]=0;
        }
    }
    
    int mx=0;
    for(i=0;i<a;i++){
        for(j=0;j<b;j++){
            if(j!=0&&ch[a-i-1][b-j-1]=='.'){
                if(ch[a-1-i][b-j]=='.')
                chart[a-1-i][b-j-1]=chart[a-1-i][b-j];
            }
            if(i!=0&&ch[a-1-i][b-1-j]=='.'){
                if(ch[a-i][b-1-j]=='.')
                chart2[a-1-i][b-j-1]=chart2[a-i][b-1-j];
            }
            if(ch[a-1-i][b-1-j]=='.'){
                int tmp=chart[a-1-i][b-j-1]+chart2[a-1-i][b-1-j];
                if(tmp>mx)
                mx=tmp;
            }
        }
    }
    cout<<mx-1<<endl;
    
    
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n;
    cin >> n;
    ll ans(0);
    for (ll i = 1; i <= n; i++) {
        ll w = n / i;
        ans += (i + w * i) * w / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
# 解説を見て解きました。

n = int(input())
a = sorted(list(map(int,input().split())))
# aの最大値+1(0を含むので)
m_a = a[-1]+1
# dp[i](aの最小値<=i<=aの最大値)が1の個数の合計が答え
dp = [0]*m_a

for i in a:
    # dp[i]の初期値は0なので1を足す
    dp[i] += 1
    # dp[i]が2以上の時は列挙する必要がないのでパス
    if dp[i] == 1:
        # aの最大値までのiの倍数を列挙
        for j in range(i*2, m_a, i):
            # 倍数をはじくためにdp[j]を2以上にする
            dp[j] += 2

print(dp.count(1))

Measured memory_bytes: 32228
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int x;
    cin >> x;
    cout << (x+1)%2;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

int main(void) {
	int num, i, a;
	ll ans = 0, k = 1;
	cin >> num;
	for (i = num - 1; i >= 0; i--) {
		cin >> a;
		if (a & 1)
			ans += k * (Pow(3, i) << 1);
		else {
			ans += k * Pow(3, i);
			k <<= 1;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
par = [-1 for i in range(n + 1)]
par[0] = 0
def find(x):
    if (par[x] < 0):
        return x
    else:
        x = par[x]
        return find(x)
def unit(x, y):
    if (find(x) == find(y)):
        pass
    else:
        x = find(x)
        y = find(y)
        if (x > y):
            x, y = y, x
        s = par[y]
        par[y] = x
        par[x] = par[x] + s

for i in range(m):
    a, b = map(int,input().split())
    unit(a, b)

par.sort()
print(-par[0])


Measured memory_bytes: 16824
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};
vector<vector<ll> > vec(100001);
priority_queue<ll> que;

int main(){

	int n,m;
	cin>>n>>m;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		vec[a].push_back(b);
	}

	ll ans=0;
	for(int i=1; i<m+1; i++){
		rep(j,vec[i].size()){
			que.push(vec[i][j]);
		}
		if(que.empty())continue;
		ans+=que.top();
		que.pop();
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 8608
import collections
 
N = int(input())
D = list(map(int, input().split()))
 
c = collections.Counter(D)
 
if c[0] != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    ans = 1
    buf = 1
    for i in range(max(D) + 1):
        if c[i] == 0:
            print(0)
            break
        ans *= buf ** c[i]
        buf = c[i]
    else:
        print(ans % 998244353)

Measured memory_bytes: 19936
#include<stdio.h>
#include<math.h>

int main(void)
{
  int a,b;

  scanf("%d %d", &a,&b);

  if(a>b)
    printf("a > b\n");
  else if(a<b)
    printf("a < b\n");
  else
    printf("a == b\n");

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  int N;
  cin >> N;
  vector<int > A(N);
  REP(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  int ans;  
  if(N%2 == 0){
    ans = 1;
    REP(i, N/2){
      if(A[2*i] != A[2*i + 1]||A[2*i] != 2*i + 1){
	// cout << A[2*i] << " " << A[2*i + 1] << " " << 2*i + 1 << endl;
	cout << 0 << endl;
	return 0;
      }else{
	ans = (ans*2)%MOD;
      }
    }
  }else{
    if(A[0] != 0 ){
      cout << 0 << endl;
      return 0;
    }else{
      ans = 2;
      for (int i = 1; i < N/2 ; i ++){
	if(A[2*i - 1] != A[2*i]||A[2*i - 1] != 2*i){
	  cout << 0 << endl;
	  return 0;
	}else{
	  ans = (ans*2)%MOD;
	}
      }
    }
  }
  if(N == 1){
    cout << 1 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main(){

    int N;
    int K;
    scanf("%d",&N);
    scanf("%d",&K);
    
   	int arr[N];
   	for(int i=0; i<N; i++){
   	    arr[i]=0;
   	}
    for(int i=0; i<K; i++){
        int count;

        scanf("%d", &count);
        //printf("count: %d\n",count);
        for(int i=0; i<count; i++){
            int who;
            scanf("%d", &who);
            arr[who-1] += 1;
            //printf("who: %d\n",who);
        }
    }

    printf("\n");
    int cnt=0;
    for(int i=0; i<N; i++){
        if(arr[i]==0){
            cnt++;
        }
    }

    printf("%d\n",cnt);

    return 0;

}

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

typedef long long ll;

const ll INF=1e12;
ll dp[1005][1005];


int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(i==j)continue;
            dp[i][j]=INF;
        }

    for(int i=0;i<m;i++){
       int a,b,cost;
       cin>>a>>b>>cost;
       dp[a-1][b-1]=-cost;

    }
    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    if(dp[0][0]==0)cout<<-dp[0][n-1];
    else cout<<"inf";

}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    rep(i, 2) {
        rep(j, 2) {
            rep(k, 2) {
                ll tmp = 0;
                rep(x, 4) {
                    ll d = S[x] - '0';
                    if (x == 0) tmp += d;
                    if (x == 1) {
                        if (i == 0) tmp += d;
                        else tmp -= d;
                    }
                    if (x == 2) {
                        if (j == 0) tmp += d;
                        else tmp -= d;
                    }
                    if (x == 3) {
                        if (k == 0) tmp += d;
                        else tmp -= d;
                    }
                }
                if (tmp == 7) {
                    char f = (i == 0) ? '+' : '-';
                    char s = (j == 0) ? '+' : '-';
                    char t = (k == 0) ? '+' : '-';
                    cout << S[0] << f << S[1] << s << S[2] << t << S[3] << "=7" << '\n';
                    return;
                }
            }
        }
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(void)
{
  string s,t;
  cin >> s;
  cin >> t;
  bool flag = true;
  for(int i =0 ; i < s.size(); i++)
  {
    if(s[i] != t[i])
    {
      flag = false;
    }
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var c string
	fmt.Scan(&c)
	var cards []int
	for i := 0; i < len(c); i++ {
		si, _ := strconv.Atoi(c[i : i+1])

		cards = append(cards, si)
	}

	flipped := 0
	for i := 1; i < len(cards); i++ {
		if cards[i-1] == cards[i] {
			if cards[i] == 1 {
				cards[i] = 0
			} else {
				cards[i] = 1
			}
			flipped++
		}
	}

	fmt.Println(flipped)
}


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

int main() {
    string a,b;
    cin>>a>>b;
    
    int n=a.size(),m=b.size();
    int m2=INT_MAX;
    for(int i=0;i<n-m+1;i++)
    {
        int p=0;
        for(int j=0;j<m;j++)
        {
            if(b[j]!=a[i+j])
            p++;
        }
        m2=min(p,m2);
    }
    if(m2==INT_MAX)
    cout<<0;
    else
    cout<<m2;
    
    
    return 0;
}

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

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

  int sa = 0;
  int sb = 0;
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    (i & 1) ? sb += a[i] : sa += a[i];
  }

  cout << sa - sb << endl;
  return 0;
}

Measured memory_bytes: 256
fn is_ok(a: &Vec<char>, b: &Vec<char>) -> Vec<bool> {
    let mut ret = vec![true; a.len()];
    for i in 0..a.len() {
        if (0..b.len())
            .any(|j| i + j < a.len() && b[j] != '?' && a[i + j] != '?' && b[j] != a[i + j])
        {
            ret[i] = false;
        }
    }
    ret
}

fn main() {
    let a = read::<String>().chars().collect::<Vec<_>>();
    let b = read::<String>().chars().collect::<Vec<_>>();
    let c = read::<String>().chars().collect::<Vec<_>>();
    // [0]a->b, [1]b->a, [2]b->c, [3]c->b, [4]a->c, [5]c->a
    let mut ok = vec![vec![]; 6];
    for (i, &(ref a, ref b)) in [(&a, &b), (&b, &a), (&b, &c), (&c, &b), (&a, &c), (&c, &a)]
        .iter()
        .enumerate()
    {
        ok[i] = is_ok(&a, &b);
    }

    let mut ans = a.len() + b.len() + c.len();
    let criterion = |ok: &Vec<bool>, i| i >= ok.len() || ok[i];
    for &(ref ok0, ref ok1, ref ok2, l1, l2, l3) in &[
        (&ok[0], &ok[2], &ok[4], a.len(), b.len(), c.len()), // a -> b -> c
        (&ok[4], &ok[3], &ok[0], a.len(), c.len(), b.len()), // a -> c -> b
        (&ok[1], &ok[4], &ok[2], b.len(), a.len(), c.len()), // b -> a -> c
        (&ok[2], &ok[5], &ok[1], b.len(), c.len(), a.len()), // b -> c -> a
        (&ok[5], &ok[0], &ok[3], c.len(), a.len(), b.len()), // c -> a -> b
        (&ok[3], &ok[1], &ok[5], c.len(), b.len(), a.len()), // c -> b -> a
    ] {
        for i in 0..ok0.len() {
            if !criterion(ok0, i) {
                continue;
            }
            let j = (i..ok0.len() + ok1.len())
                .find(|&j| criterion(ok1, j - i) && criterion(ok2, j))
                .unwrap();
            let cur_length = *[l1, i + l2, j + l3].iter().max().unwrap();
            ans = std::cmp::min(ans, cur_length);
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
  x[i], y[i], c[i] =map(int, input().split())

disc = [0] * M
for i in range(M):
  disc[i] = a[x[i]-1] + b[y[i]-1] - c[i]

D = min(a) + min(b)

print(min(min(disc), D))

Measured memory_bytes: 27308
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf  1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
//*//signed main(){
//    int n,s;cin>>n>>s;
//    for(int i=2;i*i<=n;i++){
//        int count=0;
//        int t=n;
//        while(t){
//            count+=t%i;
//            t/=i;
//        }
//        if(count==s){
//            cout<<i<<endl;
//            return 0;
//        }
//    }
//    for(int i=1;i*i<=n;i++){
//        int h=(n-s)/i+1;
//        int count=0;
//        int t=h;
//        while(t){
//            count+=t%h;
//            t/=h;
//        }
//        if(count==s){
//            cout<<h<<endl;
//            return 0;
//        }
//    }
//    cout<<-1<<endl;
//    return 0;
//            }
//signed main(){
//    int n,d;cin>>d>>n;
//    if(n!=100)rep(i,0,d)n*=100;
//    else if(d==0)n=101;
//    else if(d==1)n=10001;
//    else n=1000000;
//    cout<<n<<endl;
//    return 0;
//}
signed main(){
    int n;cin>>n;
    int ans=0;
    rep(i,0,n){
        int a;cin>>a;
        while(a%2==0){
            ans++;a/=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, cnt;
  cin >> a;
  if (a >= 100) {
    cnt++;
    a -= 100;
  }
  if (a >= 10) {
    cnt++;
    a -= 10;
  }
  if (a >= 1) {
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class UnionFindTree{
private:
  int _size;
  int* _parent;
  int* _rank;
public:
  UnionFindTree(int n){
    _size = n;
    _parent = new int[_size]();
    _rank = new int[_size]();
    for(int i = 0; i < _size; i++){
      _parent[i] = i;
      _rank[i] = 0;
    }
  }

  ~UnionFindTree(){
    delete[] _parent;
    delete[] _rank;
  }

  int find(int child){
    int next = _parent[child];
    if(next == child) return child;
    else return find(next);
  }

  bool same(int lhs,int rhs){
    lhs = find(lhs);
    rhs = find(rhs);
    return (lhs == rhs);
  }
  
  bool unite(int lhs,int rhs){
    lhs = find(lhs);
    rhs = find(rhs);
    if(same(lhs,rhs)) return false;
    
    if(_rank[lhs] < _rank[rhs]){
      _parent[rhs] = lhs;
      _rank[lhs] += _rank[rhs];
    }
    else {
      _parent[lhs] = rhs;
      _rank[rhs] += _rank[lhs];
    }
    return true;
  }

};

class State {
public:
  int _from,_to;
  double _distance;
  State(int from,int to,double distance)
    : _from(from),_to(to),_distance(distance) {}
  bool operator<(const State& s) const {
    return _distance < s._distance;
  }
  bool operator>(const State& s) const {
    return _distance > s._distance;
  }
};

int main(){
  int num_of_magical_piles;
  int num_of_magical_fences;
  while(~scanf("%d %d",
               &num_of_magical_piles,
               &num_of_magical_fences)){
    
    vector<P> piles;
    for(int pile_i = 0; pile_i < num_of_magical_piles; pile_i++){
      int x,y;
      scanf("%d %d",&x,&y);
      piles.push_back(P(x,y));
    }

    double sum = 0;
    priority_queue<State,vector<State>,less<State> > que;

    for(int fence_i = 0; fence_i < num_of_magical_fences; fence_i++){
      int from,to;
      scanf("%d %d",&from,&to);
      from--; to--;
      int from_x = piles[from].first;
      int from_y = piles[from].second;

      int to_x = piles[to].first;
      int to_y = piles[to].second;

      double distance = sqrt((double)((from_x - to_x) * (from_x - to_x)
                                      + (from_y - to_y) * (from_y - to_y)));
      sum += distance;
      que.push(State(from,to,distance));
    }

    UnionFindTree uft(num_of_magical_piles);
    double after_ruined = 0;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      if(uft.same(s._from ,s._to)){
        continue;
      }
      uft.unite(s._from,s._to);
      after_ruined += s._distance;
    }
    printf("%lf\n",sum - after_ruined);
  }
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, m; cin >> n >> m;
    vector<bool> red(n, false);
    vector<int> cnt(n, 1);
    red[0] = true;

    for (int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        --x; --y;

        if (red[x] && cnt[x] == 1) {
            red[x] = false;
            red[y] = true;
        } else if (red[x] && cnt[x] > 1) {
            red[y] = true;
        }

        cnt[x]--;
        cnt[y]++;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (red[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3708
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb(a) push_back(a)
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;



using namespace std;
lint x,y;
lint ans;

int main(){
  cin >> x >> y;
  while(y>=x){
    y /=2;
    ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 100009
#define mod 1000000007
#define ll long long
#define pb push_back
using namespace std;
#ifdef _WIN32
#define WINPAUSE system("pause")
#endif


int main()
{

         ll  L ,R,d;
         cin >> L >> R >> d;
       
         int cnt{ 0 };
         while (L <= R)
         {
             if (L % d == 0)
                 ++cnt;

             ++L;
         }
         cout << cnt << '\n';
        
    
     //cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

//グラフの隣接リスト
VI g[100010];
VI gi[100010];
//頂点の入次数を管理
int h[100010];
signed main(void)
{
  //頂点数v、辺の数e
  int v, e;
  cin >> v >> e;
    e=v-1+e;
  REP(i, e) {
    int s, t;
    cin >> s >> t;
    s--;t--;
    //頂点sから頂点tへの有向辺
    g[s].push_back(t);
    gi[t].push_back(s);
    h[t]++;
  }

  //入次数が0の頂点の集合
  stack<int> st;

  //入次数が0の頂点であればstに追加
  REP(i, v) if(h[i] == 0) st.push(i);

  //ソートされた後のグラフ
  VI ans;
  //stがなくなるまでループ
  while(st.size()) {
    //stの集合のから一つ取り出す
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(auto& j: g[i]) {
      //隣接する頂点の入次数をマイナス1
      h[j]--;
      //これによって入次数が0になればstに追加
      if(h[j] == 0) st.push(j);
    }
  }

  VI ts(v);
  {
      int cnt=0;
      for(auto i:ans){
        ts[i]=cnt++;
      }
  }
  VI tr(v,-1);
  for(auto i:ans){
      int x=-1;
      int ax=-1;
      REP(j,gi[i].size()){
          if(ts[gi[i][j]]>x){
              x=ts[gi[i][j]];
              ax=gi[i][j];
          }
      }
      tr[i]=ax+1;
  }
    REP(i,v){
      cout<<tr[i]<<endl;
    }
  return 0;
}

Measured memory_bytes: 13436
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

fn comb(n: usize, r: usize) -> usize {
   let mut x = 1;
   for i in 0..r {
      x *= n - i;
      x /= i + 1;
   }
   x
}

#[fastout]
fn main() {
   input! {
      n: usize,
      a: usize,
      b: usize,
      v: [usize; n]
   }
   let mut map = std::collections::BTreeMap::new();
   for v in v {
      map.entry(v).and_modify(|x| *x += 1).or_insert(1_usize);
   }
   if let Some((&k, &n)) = map.iter().rev().next() {
      if n >= a {
         println!("{}", k);
         let mut count = 0;
         for r in a..=std::cmp::min(b, n) {
            count += comb(n, r);
         }
         println!("{}", count);
         return;
      }
   }

   let mut sum = 0;
   let mut an = a;
   let mut count = 0;
   for (&k, &n) in map.iter().rev() {
      if n >= an {
         sum += k * an;
         count = comb(n, an);
         break;
      }
      sum += k * n;
      an -= n;
   }
   println!("{0:.7}", (sum as f64) / (a as f64));
   println!("{}", count);
}


Measured memory_bytes: 2200
def parse(s, left, target_stack):
  if s[left] == "[":
    target_stack.append("]")
  if s[left] == "(":
    target_stack.append(")")
  
  if s[left] == "]":
    if target_stack and target_stack[-1] == "]":
      target_stack.pop()
    else:
      return False

  if s[left] == ")":
    if target_stack and target_stack[-1] == ")":
      target_stack.pop()
    else:
      return False

  left += 1
  if left == len(s):
    if target_stack:
      return False
    else:
      return True

  else:
    return parse(s, left, target_stack)

while True:
  s = input()
  if s == ".":
    break

  if parse(s, 0, []):
    print("yes")
  else:
    print("no")


Measured memory_bytes: 5596
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_c"
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) IntSlice2(l, n int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := 0; i < n; i++ {
		sl[i] = s.Int()
	}
	return sl
}

func solve(n int, u [][]int) int {
	t := make([][]int, n+1, n+1)
	for i := range t {
		t[i] = make([]int, 3, 3)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				if v := t[i][j] + u[i][k]; t[i+1][k] < v {
					t[i+1][k] = v
				}
			}
		}
	}
	max := math.MinInt64
	for _, v := range t[n] {
		if max < v {
			max = v
		}
	}
	return max
}

func main() {
	scan := newScanner(os.Stdin)
	n := scan.Int()
	u := make([][]int, n+1, n+1)
	for i := 0; i <= n; i++ {
		u[i] = []int{scan.Int(), scan.Int(), scan.Int()}
	}
	fmt.Println(solve(n, u))
}


Measured memory_bytes: 13728
n, m = map(int, input().split(' '))
num = input().split(' ')
for i in range(len(num)):
    num[i] = int(num[i])
s = sum(num)
ans = s/(4*m)
temp = 0
for i in num:
    if i>=ans:
        temp += 1
if temp>=m:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <vector>
#include <functional>
#include <deque>
#include <stdexcept>

template<typename T, typename Container = ::std::vector<T>, typename Compare = ::std::greater<typename Container::value_type>>
class sliding_window {
    using iterator_type = typename Container::const_iterator;
    using value_compare = Compare;
    using value_type = T;
    using const_reference = const value_type &;

    iterator_type right_bound, left_bound, end;
    value_compare comp;
    size_t length;
    ::std::deque<value_type> val;

public:
    void push() {
        if (left_bound == end) {
            throw ::std::runtime_error("already reached to the end");
        }
        const auto &tmp = *left_bound;
        while (!val.empty() && comp(val.back(), tmp))val.pop_back();
        val.push_back(tmp);
        ++left_bound;
        ++length;
    }

    void pop() {
        if (right_bound == left_bound) {
            throw ::std::runtime_error("interval is empty");
        }
        const auto &tmp = *right_bound;
        if (tmp == val.front())val.pop_front();
        ++right_bound;
        --length;
    }

    sliding_window(iterator_type _begin, iterator_type _end, const Compare &_comp = Compare()) : length(0),
                                                                                                 right_bound(_begin),
                                                                                                 left_bound(_begin),
                                                                                                 end(_end), comp(_comp),
                                                                                                 val({}) {}

    const size_t size() const {
        return length;
    }

    const_reference top() const {
        return val.front();
    }

    void resize(size_t n) {
        if (n < length) {
            while (n < length) {
                pop();
            }
        } else {
            while (n > length) {
                push();
            }
        }
    }

    void forward() {
        if (left_bound != end)push();
        pop();
    }

};

#include <iostream>
#include <algorithm>

int main() {
    unsigned long long N, M, K;
    scanf("%llu%llu%llu", &N, &M, &K);

    std::vector<unsigned long long> A(N), dp1(N), dp2(N);
    for (auto &i : A)scanf("%llu", &i);

    std::copy(A.begin(), A.end(), dp1.begin());

    for (unsigned long long i = 1; i < K; ++i) {
        sliding_window<unsigned long long, std::vector<unsigned long long>, std::less<>> slidingWindow(
                dp1.begin() + i - 1, dp1.end());
        std::transform(A.begin() + i, A.end(), dp2.begin() + i, [&i](auto a) { return a * (i + 1); });

        slidingWindow.push();

        for (unsigned long long j = i; j < N; ++j) {
            dp2[j] += slidingWindow.top();
            slidingWindow.push();
            if (slidingWindow.size() > M)slidingWindow.pop();
        }

        std::swap(dp1, dp2);
    }

    std::cout << *std::max_element(dp1.begin(), dp1.end()) << std::endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()

const int MOD = 1000000007;
const int N = 100005;
const double PI =4*atan(1);

ll dp[2][N];
ll w[105];
ll v[105];
ll n,W,ans;

int main(){
    ios::sync_with_stdio(0);
    //freopen("baklava.in","r",stdin);
    cin.tie(0);
    cout.tie(0);
    //start
    cin >> n >> W;
    for(int i=0;i<n;i++){
    	cin >> w[i] >> v[i];
    }
    for(int i=0;i<=W;i++){
    	dp[0][i]=0;
    }
    ans=0;
    for(int i=1;i<=n;i++){
    	ll pos=i&1;
		for(int j=0;j<=W;j++){
			dp[pos][j]=dp[pos^1][j];
			if(j>=w[i-1])
			dp[pos][j]=max(dp[pos][j],dp[pos^1][j-w[i-1]]+v[i-1]);
			ans=max(ans,dp[pos][j]);
		}
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
import math


def solve(L: int):
    # if L % 3 == 0:
    #     print(math.pow(L/3,3))
    #     return
    # if L % 3 == 1:
    #     print(math.pow(L//3,2) * (1+L//3))
    #     return
    # if L % 3 == 2:
    #     print(math.pow(1+L//3,2) * (L//3))
    #     return
    #L_3 = L / 3
    #print(L_3*L_3*(L-L_3*2))
    print(pow(L,3)/27.0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    solve(L)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	int N;
	cin >> N;
	int T,A;
	cin >> T >> A;
	vector<int> H(N);
	map<double,int> mapped;
	for(size_t i = 0; i < N; i++)
	{
		double x;
		cin >> x;
		double average = T - x*0.006;
		mapped[pow(A-average,2)] = i;
	}
	cout << mapped.begin()->second + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
  N = int(input())
  s = input()
  s += s[0]

  # S: 1, W: 0
  for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)):
    l = [a0, a1]

    for c in s[1:]:
      if c == 'o':
        a0, a1 = a1, not (a0 ^ a1)
      else:
        a0, a1 = a1, (a0 ^ a1)
      l.append(a1)

    if (l[0] == l[-2]) and (l[1] == l[-1]):
      print(''.join('S' if i == 1 else 'W' for i in l[:-2]))
      exit()

  print(-1)

if __name__ == '__main__':
  main()

Measured memory_bytes: 5636
#include <iostream>
using namespace std;
int main() {
  bool f;
  int n, i, a, b, c;
  cin >> n;
  while (n--) {
    for (i = b = c = f = 0; i < 10; i++) {
      cin >> a;
      if (a > b) {
        b = a;
      } else if (a > c) {
        c = a;
      } else {
        f = 1;
      }
    }
    if (f)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

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

int main() {
  int N;   cin >> N;
  string s; cin >>s;
  int ans =1;
  for(int i = 0; i<N-1; i++){
    if(s[i]==s[i+1]){
      continue;
    }
    else{
      ans++;
    }
  }
  cout << ans << endl;
 
      

  
  }

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct edge{
	int v,pass,time;
	ll cost;
	bool operator<(const edge &rhs) const {
		return cost < rhs.cost;
	}
	bool operator>(const edge &rhs) const {
		return cost > rhs.cost;
	}
};

ll d[101][1<<8][25];
P v[1<<8];
vector<edge> g[101];
priority_queue<edge, vector<edge>, greater<edge> > pq;

int main(void){
	int n,m,h,k,a,b,r,i,j,s,t,p;
	ll c,ans;
	edge e,x,y;
	while(true){
		ans = INFLL;
		fill(d[0][0],d[101][0],INFLL);
		scanf("%d%d%d%d",&n,&m,&h,&k);
		if(!n){
			break;
		}
		for(i=0; i<m; ++i){
			scanf("%d%d%lld%d%d",&a,&b,&c,&t,&r); --a; --b; --r;
			e.v = b; e.cost = c; e.time = t; e.pass=(1<<r); g[a].push_back(e);
			e.v = a; g[b].push_back(e);
		}
		scanf("%d%d%d",&s,&t,&p); --s; --t;
		d[s][0][0] = 0ll; x.v = s; x.cost = 0ll; x.pass = 0; x.time = 0; pq.push(x);
		for(i=0; i<p; ++i){
			scanf("%d%lld",&a,&c); b = 0;
			for(j=0; j<a; ++j){
				scanf("%d",&r); --r;
				b += (1<<r);
			}
			v[i].first = b; v[i].second = c;
		}
		while(!pq.empty()){
			x = pq.top();
			pq.pop();
			if(d[x.v][x.pass][x.time] < x.cost){
				continue;
			}
			if(x.v == s){
				for(i=0; i<p; ++i){
					y.v = s;
					y.cost = x.cost + v[i].second;
					y.pass = (x.pass|v[i].first);
					y.time = 0;
					if(d[y.v][y.pass][y.time] > y.cost){
						d[y.v][y.pass][y.time] = y.cost;
						pq.push(y);
					}
				}
			}
			for(i=(g[x.v].l_ength()-1); i>=0; --i){
				e = g[x.v][i];
				y.v = e.v;
				y.cost = x.cost + ((x.pass&e.pass)?0ll:e.cost);
				y.pass = x.pass;
				y.time = x.time + e.time;
				if(y.time > h){
					continue;
				}
				if(d[y.v][y.pass][y.time] > y.cost){
					d[y.v][y.pass][y.time] = y.cost;
					pq.push(y);
				}
			}
		}
		for(i=0; i<n; ++i){
			g[i].clear();
		}
		for(i=0; i<(1<<k); ++i){
			for(j=0; j<=h; ++j){
				ans = min(ans,d[t][i][j]);
			}
		}
		if(ans==INFLL){
			printf("-1\n");
		}else{
			printf("%lld\n",ans);
		}
	}
	return 0;
}



Measured memory_bytes: 11132
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;
int A, B, C;
int D[110];

int main() {
  cin >> N >> A >> B >> C;
  for (int i=0; i<N; i++) cin >> D[i];
  sort(D, D+N, greater<int>());
  int ans = 0, t = C;
  for (int i=0; i<N; i++) {
    t += D[i];
    ans = max(ans, t / (A + (i+1)*B));
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 3e5 + 7, MAXM = 1e5 + 7;
int bit[MAXM];

void upd(int i, int x)
{
    for (; i < MAXM; i += i & (-i)) bit[i] += x;
}

int get(int i)
{
    int ans = 0;
    for (; i > 0; i -= i & (-i)) ans += bit[i];
    return ans;
}

int N, M;
vector<int> add[MAXM], rem[MAXM];
int ans[MAXM];
vector<int> factors[MAXM];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;

    for (int d = 1; d <= M; ++d) {
        for (int i = d; i <= M; i += d) {
            factors[i].push_back(d);
        }
    }

    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        add[l].push_back(l);
        rem[r].push_back(l);
    }

    for (int i = 1; i <= M; ++i) {
        for (int x : add[i]) upd(x, 1);
        for (int x : factors[i]) {
            ans[x] += get(i) - get(i - x);
        }
        for (int x : rem[i]) upd(x, -1);
    }

    for (int i = 1; i <= M; ++i) cout << ans[i] << '\n';
}


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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){

    vector<string> s = {
        "mon",
        "tue",
        "wed",
        "thu",
        "fri",
        "sat",
        "sun",
    };

    int x;
    cin >> x;
    cout << s[(x + 3) % 7] << endl;

}



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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int n;
const int MAXS = 5e5;
int c[MAXS + 3];
vii queries[MAXS + 3];
int ans[MAXS+3];
int lastvis[MAXS + 3];

int fen[MAXS + 3];
void update(int pos, int delta){
    while(pos <= n){
        fen[pos] += delta;
        pos += pos & (-pos);
    }
}

int query(int pos){
    int answer = 0;
    while(pos){
        answer += fen[pos];
        pos -= pos & (-pos);
    }
    return answer;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n;
    int q; cin>>q;
    for (int i=1; i<=n; i++)
        cin>>c[i];
    
    for (int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        queries[r].pb(ii(l, i));
    }
    for (int r=1; r<=n; r++){
        if (lastvis[c[r]]) update(lastvis[c[r]], -1);
        lastvis[c[r]] = r;
        update(r, 1);
        for (int i=0; i<queries[r].size(); i++){
            ans[queries[r][i].second] = query(r) - query(queries[r][i].first - 1);
        }
    }
    for (int i=0; i<q; i++) cout<<ans[i]<<'\n';
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 33236
import java.util.*;
import java.util.Arrays;

public class Main {// Main
    public static void main(String[] args){

        Scanner sc =   new Scanner(System.in);
        int[]  N ;
         N = new int[4];
         N[0] = sc.nextInt();
         N[1] = sc.nextInt();
         N[2] = sc.nextInt();
         N[3] = sc.nextInt();

        Arrays.sort(N);

        if(N[0]==1){
            if(N[1]==4){
                if(N[2]==7){
                    if(N[3]==9){
                        System.out.println("YES");
                    }else{
            System.out.println("NO");
            }
                }else{
            System.out.println("NO");
            }
            }else{
            System.out.println("NO");
            }
        }else{
            System.out.println("NO");
            }


    }

}

Measured memory_bytes: 21332
N = int(input())
a = list(map(int, input().split()))
count = 0

#インデックスを1から始める

step = 2
for i, name in enumerate(a, 1):
    if i%2 == 1:
        if name%2 ==1:
            count += 1
        else:
            pass
    else:
        pass

print(count)



Measured memory_bytes: 9108
function main(input) {
    var x = parseInt(input.trim().split(" "), 10);

    var num_500 = Math.floor(x/500);
    var num_5 = Math.floor((x-(num_500*500)) / 5);

    console.log(1000*num_500 + 5 * num_5);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500