akhauriyash/Code-Regression huggingface dataset:
fn main(){
  
  let pn = sieve(1000000);
  
  loop {
    let n: usize = read();
    if n == 0 { break; }

    let mut ans = 0;
    let mut i = 3;

    while 2 * i <= n {
      if pn[i] && pn[n-i] {
        ans += 1;
      }
      i += 2;
    }
    println!("{}", ans);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn sieve(n: usize) -> Vec<bool> {
  let mut v: Vec<bool> = vec![true; n+1];
  v[0] = false;
  v[1] = false;

  let mut i = 2;

  while i * i <= n {
    if v[i] {
      let mut j = i * i;
      while j <= n {
        v[j] = false;
        j += i;
      }
    }
    i += 1;
  }
  
  v
}



Measured memory_bytes: 5032
#include <iostream>

using namespace std;

int N, K;
int a[101];
bool dp[2][100010], vis[2][100010];

// true -> sente, false -> gote
bool rec(int cur, int k)
{
	if (vis[cur][k]) return dp[cur][k];
	if (k == K) {
		return cur % 2 == 1;
	}

	vis[cur][k] = true;

	if (cur % 2 == 0) {
		bool sente = false;
		for (int i = 0; i < N; ++i) {
			if (k + a[i] > K) break;
			sente |= rec((cur + 1) % 2, k + a[i]);
		}
		return dp[cur][k] = sente;
	} else {
		bool sente = true;
		for (int i = 0; i < N; ++i) {
			if (k + a[i] > K) break;
			sente &= rec((cur + 1) % 2, k + a[i]);
		}
		return dp[cur][k] = sente;
	}
}

signed main()
{
	cin >> N >> K;

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

	if (rec(0, 0)) {
		cout << "First" << endl;
	} else {
		cout << "Second" << endl;
	}
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],sum;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    sum=2*a[2]-a[0]-a[1];
    if(sum%2==0)cout<<sum/2;
    else cout<<sum/2+2;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n/100==7){
    cout<<"Yes"<<endl;
    return 0;
  }
  else{
    n=n%100;
  }
  if(n/10==7){
    cout<<"Yes"<<endl;
    return 0;
  }
  else{
    n=n%10;
  }
  if(n%10==7){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
typedef long long ll;
const int MN=104,MW=1e5+4;
int N,W;
ll dp[MW];
int main() {
    scanf("%d%d",&N,&W);
    for(int i=0,w,v;i<N;++i) {
        scanf("%d%d",&w,&v);
        for(int j=MW-1;j>=w;--j)
            dp[j]=std::max(dp[j],dp[j-w]+v);
    }
    printf("%lld\n",dp[W]);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 500010
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main(){
	ll n,m,x;
	cin>>n>>m>>x;
	vector<pair<ll,ll> > v;
	forn(i,x){
		ll p,q;
		cin>>p>>q;
		v.pb(mp(p,q));
	}
	map<ll,ll> row,col;
	forn(i,v.size()){
		row[v[i].ff]++;
		col[v[i].ss]++;
	}
	ll mrow=0,mcol=0;
	for(map<ll,ll>::iterator it=row.begin();it!=row.end();it++){
		mrow=max(mrow,it->ss);
	}
	for(map<ll,ll>::iterator it=col.begin();it!=col.end();it++){
		mcol=max(mcol,it->ss);
	}
	//cout<<mrow<<' '<<mcol<<endl;
	ll ans=mrow+mcol;
	vector<ll> r,c;
	for(map<ll,ll>::iterator it=row.begin();it!=row.end();it++){
		if(it->ss==mrow)	r.pb(it->ff);
	}
	for(map<ll,ll>::iterator it=col.begin();it!=col.end();it++){
		if(it->ss==mcol)	c.pb(it->ff);
	}
	/*forn(i,r.size())	cout<<r[i]<<' ';
	cout<<endl;
	forn(i,c.size())	cout<<c[i]<<' ';
	cout<<endl;			*/
	ll cnt=0,ref=r.size()*c.size();
	vector<ll>::iterator it1,it2;
	forn(i,x){
		ll a=v[i].ff,b=v[i].ss;
		it1=ub(r,a);it2=ub(c,b);
		if(it1==r.begin()||it2==c.begin())		continue;
		it1--;it2--;
		if(((*it1)==a)&&((*it2)==b))	ref--;
	}
	if(ref<=0)	ans--;
	cout<<ans;
}

Measured memory_bytes: 54196
#include<set> 
#include<map>
#include<cmath>    
#include<queue>    
#include<vector>    
#include<cstdio>    
#include<ctime>   
#include<cstring>    
#include<iostream>    
#include<algorithm>    
#define INF 0x3f3f3f3f
using namespace std;
long long read(){
    long long f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 50000
int main(){
	int d=read(),n=read();
	if(!d){printf("%d\n",n==100?101:n);return 0;}
	else if(d==1) printf("%d\n",(n==100?101:n)*100);
	else printf("%d\n",(n==100?101:n)*10000);
	return 0;
}  

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

main() {
  int N; cin >> N;
  int two = 0, four = 0, no = 0;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      four++;
    } else if (a % 2 == 0) {
      two++;
    } else {
      no++;
    }
  }
  no += (two > 0) ? 1 : 0;
  cout << ( (four + 1 >= no) ? "Yes" : "No" ) << endl;
}

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

int main() {
  int M, D;
  cin >> M >> D;
  
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= D; j++) {
      int product = (j % 10) * (j - j % 10) / 10;
    
      if (j % 10 < 2 || (j - j % 10) / 10 < 2) {
        continue;
      }
      
      if (product == i) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

///////////////////////////////////

int main(){
  lint x; cin>>x;
  if(x==1) cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 105;
struct Edges { int to, next; } e[MAXN * 2];
int head[MAXN], tot;
int dep[MAXN], Maxson[MAXN];

inline void addedge(int from, int to) {
  e[++tot] = (Edges){to, head[from]};
  head[from] = tot;
  e[++tot] = (Edges){from, head[to]};
  head[to] = tot;
}

void Dfs(int now, int fa, int d) {
  int cnt = 0;
  dep[now] = d;
  for (RI i = head[now]; i; i = e[i].next)
    if (e[i].to != fa)
      Dfs(e[i].to, now, d + 1), ++cnt;
  Maxson[dep[now]] = max(Maxson[dep[now]], cnt);
}

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n; read(n);
  for (RI i = 1, x, y; i < n; ++i)
    read(x), read(y), addedge(x, y);
  LL ans1 = 0x7f7f7f7f7f7f7f7f, ans2 = 0x7f7f7f7f7f7f7f7f;
  for (RI i = 1; i <= n; ++i) {
    memset(Maxson, 0, sizeof(Maxson));
    Dfs(i, 0, 1);
    LL Leaf = 1, Maxdep = 1;
    for (RI j = 1; j <= n; ++j)
      if (Maxson[j]) Leaf *= Maxson[j], Maxdep = j + 1;
      else break;
    if (Maxdep < ans1) ans1 = Maxdep, ans2 = Leaf;
    if (Maxdep == ans1) ans2 = min(ans2, Leaf);
  }
  for (RI i = 1; i <= n; ++i)
    for (RI j = head[i]; j; j = e[j].next) {
      memset(Maxson, 0, sizeof(Maxson));
      Dfs(i, e[j].to, 1), Dfs(e[j].to, i, 1);
      LL Leaf = 2, Maxdep = 1;
      for (RI k = 1; k <= n; ++k)
        if (Maxson[k]) Leaf *= Maxson[k], Maxdep = k + 1;
        else break;
      if (Maxdep < ans1) ans1 = Maxdep, ans2 = Leaf;
      if (Maxdep == ans1) ans2 = min(ans2, Leaf);
    }
  printf("%lld %lld\n", ans1, ans2);

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

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

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int x, y, b, p;
        cin >> x >> y >> b >> p;
        int ans;
        //pattern 1
        ans = x * b + y * p;
        //pattern 2
        if (b < 5) b = 5;
        if (p < 2) p = 2;
        x = x / 5 * 4;
        y = y / 5 * 4;
        ans = min(ans, x * b + y * p);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  int x; cin >> x;
  if(x>=30) cout<< "Yes" << endl;
  else cout << "No" << endl;

	return 0;
}



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

using namespace std;

const int N = 100 + 77 , Mod = 1000000007;
int n , T[N] , cur = 1;
bool M[N][N];
vector < pair < int , int > > A;
int main() {
   cin >> n;
   if(n & 1) {
      for(int i = 1;i <= n / 2;++ i)
         T[i] = T[n - i] = cur ++;
      T[n] = cur;
   } else {
      for(int i = 1;i <= n / 2;++ i)
         T[i] = T[n - i + 1] = cur ++;
   }
   for(int i = 1;i <= n;++ i)
      for(int j = i + 1;j <= n;++ j)
         if(T[i] ^ T[j])
            A.push_back(make_pair(i , j));
   cout << int(A.size()) << '\n';
   for(auto x : A)
      cout << x.first << ' ' << x.second << '\n';
   return 0;
}


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

int main(){
	int N,i,j,a[100],c,t;

	for(cin>>N,i=0;cin>>a[i],i<N;++i);
	
	for(i=0;i<N-1;++i)
		for(j=N-1;j>=i+1;--j)
			if(a[j]<a[j-1]){
				t=a[j];
				a[j]=a[j-1];
				a[j-1]=t;
				++c;
			}
			
	for(i=0;i<N;cout<<(i?" ":"")<<a[i],++i);
	cout<<endl<<c<<endl;
}

Measured memory_bytes: 1168
import java.util.*;

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

    int n = sc.nextInt();
    boolean[][] trump = new boolean[13][4];

    for(int i = 0; i < n; i++){
      String s = sc.next();
      int num = sc.nextInt();

      if(s.equals("S")){
        trump[num - 1][0] = true;
      } else if(s.equals("H")){
        trump[num - 1][1] = true;
      } else if(s.equals("C")){
        trump[num - 1][2] = true;
      } else {
        trump[num - 1][3] = true;
      }
    }

    for(int j = 0; j < 4; j++){
      for(int i = 0; i < 13; i++){
        if(trump[i][j] == false){
          if(j == 0){
            System.out.println("S " + (i + 1));
          } else if(j == 1){
            System.out.println("H " + (i + 1));
          } else if(j == 2){
            System.out.println("C " + (i + 1));
          } else {
            System.out.println("D " + (i + 1));
          }
        }
      }
    }
  }
}



Measured memory_bytes: 26500
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n, L;
int a[N], Right[20][N], Left[20][N];
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	cin >> L;

	/// calculating Rights
	int ptr = n;
	per(i, n, 1) {
		while (a[ptr] - a[i] > L) ptr--;
		Right[0][i] = ptr;
	}
	/// Calculating Lefts
	ptr = 1;
	rep(i, 1, n) {
		while (a[i] - a[ptr] > L) ptr++;
		Left[0][i] = ptr;
	}
	rep(dg, 1, 19) {
		rep(i, 1, n) {
			Right[dg][i] = Right[dg - 1][Right[dg - 1][i]];
			Left[dg][i] = Left[dg - 1][Left[dg - 1][i]];
		}
	}

	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		int ans = 0;
		if (l > r) swap(l, r);
		if (l < r) {
			per(i, 19, 0) {
				if (Right[i][l] < r) {
					l = Right[i][l];
					ans += (1 << i);
				}
			}
			++ans;
		}
		else {
			per(i, 19, 0) {
				if (Left[i][l] > r) {
					l = Left[i][l];
					ans += (1 << i);
				}
			}
			++ans;
		}
		cout << ans << nl;
	}
	ioi
}


Measured memory_bytes: 16896
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()

print(math.ceil(n/2))


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    string s;
    cin >> s;
    
    map<string, string> mp;
    mp["ABC"] = "ARC", mp["ARC"] = "ABC";
    
    cout << mp[s] << '\n';
    return 0;
}


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

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

    int t[N];
    rep(i,N)cin >> t[i];

    int ans=0;
    
    rep(i,N){
        if(i==N-1)ans+=T;
        else {
            int tem = t[i+1] - t[i];
            if(tem<T){
                ans+=tem;
            }
            else {
                ans+=T;
            }

        }
    }

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

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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="776755555555555555555555555555555555555554555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1005;

int n,m,dcnt,ed;
bool vis[N];
int dep[N];
vector<int>ans;
vector<int>G[N];

bool Dfs(int u) {
	vector<int>k;
	int tmp=-1;
	for(int i=0;i<(int)G[u].size();i++) {
		int v=G[u][i];
		if(dep[v]!=-1) {
			if(tmp==-1)
				tmp=v;
			else if(dep[v]>dep[tmp])
				tmp=v;
		}
		if(!vis[v]) k.push_back(v);
		vis[v]=true;
	}
	if(tmp==-1) {
		for(int i=0;i<(int)k.size();i++) {
			int v=k[i];
			dep[v]=dep[u]+1;
			if(Dfs(v)) {
				if(dep[u]>=dep[ed])
					ans.push_back(u);
				return true;
			}
			dep[v]=-1;
		}
		for(int i=0;i<(int)k.size();i++)
			vis[k[i]]=false;
		return false;
	}
	else {
		ed=tmp;
		ans.push_back(u);
		return true;
	}
}
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1,u,v;i<=m;i++) {
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
	}
	memset(dep,-1,sizeof(dep));
	for(int i=1;i<=n;i++) {
		memset(vis,0,sizeof(vis));
		vis[i]=true;
		dep[i]=0;
		if(Dfs(i)) {
			printf("%d\n",(int)ans.size());
			for(int i=ans.size()-1;i>=0;i--)
				printf("%d\n",ans[i]);
			return 0;
		}
		dep[i]=-1;
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 384
N = gets.to_i
s = Hash[N.times.map { gets.chomp }.group_by { |v| v }.map { |k, v| [k, v.length] }]
M = gets.to_i
t = M.times.map { gets.chomp }
t.each { |v| s[v] = 0 unless s[v] }
t.each { |v| s[v] -= 1 }
puts [0, s.map { |_k, v| v }.max].max


Measured memory_bytes: 1788
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int money = 100000;
    int n, up;
    
    scanf("%d", &n);
    
    while(n > 0) {
        money += money * 0.05;
        up = money % 1000;
        if ( up > 0) {
            money = money - up + 1000;
        }
        n--;
    }
    
    printf("%d\n", money);
        
    return 0;
}

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

using namespace std;

int main() 
{
    int N,K,Q;
    cin>>N>>K>>Q;

    vector<int> P(N,K);//参加者0-Nごとの得点
    vector<int> A;
    for(int i=0;i<Q;++i)
    {
        int a;
        cin>>a;
        A.push_back(a);
    }

    for(const auto&a:A)
    {
        ++P[a-1];
    }

    for(auto&p:P)
    {
        p-=Q;
    }

    //yes or no
    for(const auto&p:P)
    {
        if(p>0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int score[6],sum=0;
    for(int i=0;i<5;++i){
        scanf("%d",&score[i]);
    }
    for(int i=0;i<5;++i){
        if(score[i] < 40){
            score[i]=40;
            sum+=score[i];
        }else{
            sum+=score[i];
        }
    }
    printf("%d\n",sum/=5);
    return 0;
}

Measured memory_bytes: 3224
#解説見た
n = int(input())
p = list(map(int, input().split()))
p.append(0)
ans = 0
for i in range(n):
    if p[i] == (i+1):
        p[i],p[i+1] = p[i+1], p[i]
        ans += 1

print(ans)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int H, W;
string B[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) cin >> B[y];

    rep(y, 0, H)rep(x, 0, W) if(B[y][x] == '.') {
        int c = 0;
        rep(dx, -1, 2) rep(dy, -1, 2) {
            if (dx == 0 and dy == 0) continue;
            int xx = x + dx;
            int yy = y + dy;
            if (0 <= xx and xx < W and 0 <= yy and yy < H) {
                if (B[yy][xx] == '#') c++;
            }
        }
        B[y][x] = char('0' + c);
    }

    rep(y, 0, H)cout << B[y] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var S = cin.next;
        int cnt = 0;
        for (int i = 1; i < S.Length; i++)
        {
            if (2 <= i && i < S.Length - 1 && S[i] == 'C')
            {
                cnt++;
            }
            else if ('A' <= S[i] && S[i] <= 'Z')
            {
                WriteLine("WA");
                return;
            }
        }
        if (cnt == 1 && S[0] == 'A')
        {
            WriteLine("AC");
        }
        else
        {
            WriteLine("WA");
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n;
    int t[100001] = {0};
    scanf("%d", &n);
    rep(i, 0, n){
        int a;
        scanf("%d", &a);
        t[a]++;
    }
    int ans = 0;
    rep(i, 0, 100000-2){
        int buf = t[i] + t[i+1] + t[i+2];
        if(buf > ans){
            ans = buf;
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let mut a = vec![0u64; n];
    let big_int: u64 = 1000_000_000 + 7;
    for i in 0..n {
        a[i] = read();
    }

    let mut each_num_pos_dict = HashMap::new();
    for (i, &num) in a.iter().enumerate() {
        each_num_pos_dict.entry(num).or_insert(Vec::new()).push(i);
    }

    let mut dp = vec![0; n + 1];
    dp[n] = 1;

    for i in (0..n).rev() {
        dp[i] = dp[i + 1];
        let pos = each_num_pos_dict[&a[i]].lower_bound(&(i + 2));
        if i != n - 1 && a[i + 1] != a[i] && pos != each_num_pos_dict[&a[i]].len() {
            let next_ai_pos = each_num_pos_dict[&a[i]][pos];
            dp[i] += dp[next_ai_pos];
            dp[i] %= big_int;
        }
    }
    println!("{}", dp[0]);
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);
  sort(L.begin(), L.end());
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = 0; k < j; k++) {
        if (L.at(i) == L.at(j)) continue;
        if (L.at(j) == L.at(k)) continue;
        if (L.at(k) == L.at(i)) continue;
        if (L.at(i) < L.at(j) + L.at(k)) ans++;
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3628
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
r = min(A)+min(B)
for i in range(m):
    x, y, c = map(int, input().split())
    r = min(r, A[x-1]+B[y-1]-c)
print(r)

Measured memory_bytes: 18684
#include <bits/stdc++.h>
using namespace std;
int n, m;
char mp[1010][1010];
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i){
        scanf("%s", mp[i] + 1);
    }
    bool flag = true;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j)if(mp[i][j] == '#'){
            if(mp[i][j - 1] == '#' || mp[i][j + 1] == '#' || mp[i - 1][j] == '#' || mp[i + 1][j] == '#')
                continue;
            else
                flag = false;
        }
    }
    cout << (flag ? "Yes": "No") << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;

ll dp[101][100001];
int a[102];

inline ll get(int i, int l, int r) {
    ll res = dp[i][r];
    if (l > 0)
        res -= dp[i][l - 1];
    while (res >= mod)
        res -= mod;
    while (res < 0)
        res += mod;
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i <= k; ++i) {
        dp[0][i] = 1;
    }

    for (int i = 1; i <= n; ++i) {
        for (int e = 0; e <= k; ++e) {
            dp[i][e] = get(i-1,e - a[i], e);

            dout << i <<" - "<<e <<" : "<<dp[i][e]<<endl;
        }
        if(i < n)
        for(int e=1;e<=k;++e){
            dp[i][e]+=dp[i][e-1];
            if(dp[i][e]>=mod)
                dp[i][e]-=mod;
        }


    }
    cout << dp[n][k]<<"\n";
}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 79232
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};



int main(){
    int x,y,s;
    while(cin>>x>>y>>s,x||y||s){
        int ma=0;
        for(int i=1;i<1000;i++){
            for(int j=1;j<1000;j++){
                int v1=1.0*i*(100+x)/100;
                int v2=1.0*j*(100+x)/100;
                if(v1+v2!=s)continue;
                v1=1.0*i*(100+y)/100;
                v2=1.0*j*(100+y)/100;
                ma=max(ma,v1+v2);
            }
        }
        cout<<ma<<endl;
    }
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    VL a(n),sub(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n; i++) {
        sub[i] = a[i] - a[i-1];
    }
    LL ans = 1;
    bool inclease = false;
    bool declease = false;
    for (int i = 1; i < n; i++) {
        if (sub[i] > 0) {
            if (declease) {
                ans++;
                declease = false;
                continue;
            }
            inclease = true;
        }
        else if (sub[i] < 0) {
            if (inclease) {
                ans++;
                inclease = false;
                continue;
            }
            declease = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll x,y;
int c[200001];
ll w[200001];
ll fact[200001];
vector<ll> col[200001];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

int main(void){
	scanf("%d%lld%lld",&n,&x,&y);
	if(n==1){
		printf("1\n");
		return 0;
	}
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=(ll)fact[i-1]*i%MOD;
	}
	for(int i=0;i<n;i++){
		scanf("%d%lld",&c[i],&w[i]);
		c[i]--;
		col[c[i]].push_back(w[i]);
	}
	for(int i=0;i<n;i++){
		sort(col[i].begin(),col[i].end());
	}
	ll mini=min(w[0],w[1]);
	ll mini2=max(w[0],w[1]);
	for(int i=0;i<n;i++){
		if(w[i]<mini){
			mini2=mini;
			mini=w[i];
		}else if(w[i]<mini2){
			mini2=w[i];
		}
	}
	ll res=1;
	ll all=0;
	for(int i=0;i<n;i++){
		if(col[i].size()>0){
			if(mini+col[i][0]<=y){
				int r=upper_bound(col[i].begin(),col[i].end(),x-col[i][0])-col[i].begin();
				int r2=upper_bound(col[i].begin(),col[i].end(),y-mini)-col[i].begin();
				if(mini==col[i][0]){
					r2=upper_bound(col[i].begin(),col[i].end(),y-mini2)-col[i].begin();
				}
				r=max(r,r2);
				if(r<=1){
					all+=1;
				}else{
					all+=r;
					res=res*mod_inverse(fact[r],MOD)%MOD;
				}
			}
		}
	}
	res=res*fact[all]%MOD;
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 13440
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

 
int main(){
    ll k,s; cin >> k >> s;
    ll cnt = 0;
    rep(i,k+1){
        rep(j,k+1){
            if(0 <= s-i-j && s-i-j <= k) cnt++;
        }
    }
    cout << cnt << endl;
}

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














int N, A[101010];
//---------------------------------------------------------------------------------------------------
ll solve() {
	if (N == 0) {
		if (A[0] == 1) return 1;
		else return -1;
	}

	if (A[0] != 0) return -1;

	ll tot = 0;
	rep(i, 0, N + 1) tot += A[i];

	ll cur = 1;
	ll ans = 1;
	rep(i, 1, N + 1) {
		cur *= 2;

		if (cur < A[i]) return -1;

		ans += min(cur, tot);
		cur = min(cur, tot) - A[i];
		tot -= A[i];
	}
	return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N + 1) cin >> A[i];
	cout << solve() << endl;
}







Measured memory_bytes: 4004
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int main ()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int d;
	d = a;
	if (b > d)
		d = b;
		if (c > d)
			d = c;
			printf("%d",a+b+c-d);
	}

Measured memory_bytes: 128
import java.util.*;
class Main{
	
    public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
    	int n=sc.nextInt();
    	  int t=sc.nextInt();
    	  int a=sc.nextInt();
    	  int h[]=new int[n];
    	  int ans=0;
    	  double b[]=new double[n];
    	  for (int i=0;i<n;i++){
    	   h[i]=sc.nextInt(); 
    	   b[i]=Math.abs(t-h[i]*0.006-a);
    	   	   if(b[i]<b[ans]) {
    	   		   ans=i;
    	   	   }	
    	  }
         System.out.println(ans+1); 
    }
}

Measured memory_bytes: 23656
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var taro = 0
    var hana = 0
    (0 until n).forEach {
        val (t, h) = readLine()!!.toString().split(" ")
        when {
            t == h -> {
                taro++
                hana++
            }
            t > h -> {
                taro += 3
            }
            else -> {
                hana += 3
            }
        }
    }

    println("$taro $hana")
}


Measured memory_bytes: 27548
#include<stdio.h>

int main(void){
int i,j,h,w;
while(1){
scanf("%d %d",&h,&w);
if(h==0&&w==0)break;
else for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(i%2==j%2)printf("#");
else printf(".");
}
printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int a, b; cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    long long int n, m, x, i, j;
    vector<long long int>u, v;
    
    cin >> n >> m;
    
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    
    for(i = 0; i < m; i++){
        cin >> x;
        u.push_back(x);
    }
    sort(u.begin(), u.end());
    
    for(j = 1; j < m; j++){
        v.push_back(u[j]-u[j-1]);
    }
    sort(v.begin(), v.end());
    
    long long int sum = 0;
    long long int ans;
    for(i = 0; i < n-1; i++){
        sum += v[m-2-i];
    }
    ans = (u[m-1]-u[0]) - sum;
    
    cout << ans << endl;
}


Measured memory_bytes: 2548
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (x, a) = get!(usize, usize);
    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i += 1)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX_N 100000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    ll N,M;
    cin >> N >> M;
    ll A[N];
    vector<ll> Sum(N);
    Rep(i,N){
        cin >> A[i];
        if(i != 0)Sum[i] = Sum[i-1] + A[i];
        else Sum[i] = A[i];
        Sum[i] %= M;
        //cout << Sum[i] << endl;
    }
    sort(All(Sum));
    ll cnt = 1;
    ll ans = 0;
    Rep(i,N){
        if(Sum[i] == 0)ans++;
    }
    Rep(i,N-1){
        if(Sum[i] == Sum[i+1]){
            cnt++;
        }else{
            ans += (cnt*(cnt-1))/2;
            cnt = 1;
        }
    }
    ans += (cnt*(cnt-1))/2;
    cout << ans;
    //cin >> N;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=6e5+5;
int n,m,x,k,a[N],tree[N<<2],ans=0;
void pushup(int i)
{
    tree[i]=max(tree[i<<1],tree[i<<1|1]);
}

void update(int i,int l,int r,int x,int k)
{
    if(l==r)
    {
        tree[i]=max(tree[i],k);
        return ;
    }
    int mid=l+(r-l)/2;
    if(x<=mid) update(i<<1,l,mid,x,k);
    else update(i<<1|1,mid+1,r,x,k);
    pushup(i);
}

int query(int i,int l,int r,int m,int n)
{
    if(m<=l && r<=n) return tree[i];
    int ans=0,mid=l+(r-l)/2;
    if(m<=mid) ans=max(ans,query(i<<1,l,mid,m,n));
    if(n>mid) ans=max(ans,query(i<<1|1,mid+1,r,m,n));
    return ans;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]++;
    for(int i=1;i<=n;i++){
        x=query(1,1,300001,max(a[i]-k,1),min(a[i]+k,300001))+1;
        ans=max(ans,x);
        update(1,1,300001,a[i],x);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 9084
#include <iostream>

#define ll long long int

using namespace std;

ll w[4001];
ll sum[4001];
ll dp[4001][4001];
int at[4001][4001];

int main(int argc, char const* argv[])
{
	int n; cin >> n;
	for(int i = 0; i < n; i++){
			cin >> w[i];
			if(i == 0)sum[i] = w[i];
			else sum[i] = sum[i-1] + w[i];
			at[i][i] = i;
	}
	for(int k = 1; k < n; k++){
			for(int i = 0; i < n - k; i++){
					// dp[i][i + k]
					ll mini = 1e18;
					for(int j = at[i][i+k-1]; j <= at[i+1][i+k]; j++){
							if(j < i || j > i + k - 1)continue;
							ll tmp = dp[i][j] + dp[j+1][i+k];
							if(tmp <= mini){
									mini = tmp;
									at[i][i+k] = j;
							}
					}
					if(i != 0)dp[i][i+k] = mini + sum[i+k] - sum[i - 1];
					else dp[i][i+k] = mini + sum[k];
			}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}



Measured memory_bytes: 125816
a,b,k = gets.split.map(&:to_i)
k.times do |i|
    if i.even?
        a -= 1 if a.odd?
        a /= 2
        b += a
    else
        b -= 1 if b.odd?
        b /= 2
        a += b
    end
end
puts [a,b].join(" ")

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

class Shape {
public:
    int H;
    int W;
    Shape(int H, int W) {
        this->H = H;
        this->W = W;
    }
};

int main(void) {
    int H, W;
    vector<Shape> shapeList;
    while(true) {
        cin >> H >> W;
        if(H == 0 && W == 0) break;

        shapeList.push_back(Shape(H, W));
    }

    for(int i=0; i < shapeList.size(); i++) {
        for(int j=0; j < shapeList[i].H; j++) {
            for(int k=0; k < shapeList[i].W; k++) {
                if(j == 0 || j == shapeList[i].H - 1) {
                    cout << "#";
                } else {
                    if(k == 0 || k == shapeList[i].W - 1) {
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

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

int main()
{
	int k, n;
	cin >> k >> n;
	int a[n];
	int res = 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		if (i < n-1){
			res = max(res, abs(a[i]-a[i+1]));
		} else res = max(res, abs(a[0]+k-a[n-1]));
	}

	cout << k - res << endl;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K;
  cin >> N >> K;
  VI xs(N);
  cin >> xs;
  SORT(xs);

  int ans = 1e9+100;
  REP(i,N-K+1) mini(ans, xs[i+K-1] - xs[i]);
  cout << ans << endl;

  return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int k=1;
  while (a>0 and c>0) {
    if (k) {
      c -= b;
    } else {
      a -= d;
    }
    k = !k;
  }

  if (a<=0) {
    cout << "No\n";
  } else cout << "Yes\n";
}

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

signed main() {
  int h,w,a,b;cin>>h>>w>>a>>b;

  vector<string> s(h,string(w,'1'));

  for(int hi=0;hi<h;++hi){
    for(int wi=0;wi<w;++wi){
      if(wi<a && hi<b) {
        s[hi][wi] = '0';
      }
      if(wi>=a && hi>=b){
        s[hi][wi] = '0';
      }
    }
  }

  for(int hi=0;hi<h;++hi)
    cout<<s[hi]<<endl;

  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long

#define rep(i, a, b) for (int i = a; i < b; i++)
#define For(i, a, b) for (int i = a; i <= b; i++)

using namespace std;

const int mod = 1000000000 + 7;

int main(){
    char in;
    cin >> in;
    if (in == 'A')
        printf("T");
    else if (in == 'T')
        printf("A");
    else if (in == 'G')
        printf("C");
    else
        printf("G");
}

Measured memory_bytes: 256