akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
int N,M,S,T,u,v,D;
vector<pair<int,int>>G[1<<17];
long mod=1e9+7,a[1<<17],b[1<<17],c[1<<17],d[1<<17];
priority_queue<pair<long,int>>P;
void calc(int S,long*d,long*w)
{
	for(int i=w[S]=1;i<=N;)d[i++]=-1e18;
	P.push({d[S]=0,S});
	while(P.size())
	{
		long c=P.top().first,u=P.top().second;
		P.pop();
		if(d[u]==c)for(pair<int,int>p:G[u])
		{
			long v=p.first,nxt=c-p.second;
			if(d[v]<nxt)w[v]=w[u],P.push({d[v]=nxt,v});
			else if(d[v]==nxt)(w[v]+=w[u])%=mod;
		}
	}
}
main()
{
	cin>>N>>M>>S>>T;
	for(;cin>>u>>v>>D;G[v].push_back({u,D}))G[u].push_back({v,D});
	calc(S,a,b);calc(T,c,d);
	long ans=b[T]*b[T],t=a[T];
	for(u=0;u++<N;)
	{
		if(2*a[u]==t)ans-=b[u]*b[u]%mod*d[u]%mod*d[u]%mod;
		for(pair<int,int>p:G[u])if(2*a[u]>t&&2*a[v=p.first]<t&&a[u]+c[v]-p.second==t)ans-=b[u]*b[u]%mod*d[v]%mod*d[v]%mod;
	}
	cout<<(ans+mod)%mod;
}

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

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

    int dp[20][2] = {};
    dp[1][0] = (int)(N[0] - '0');
    dp[1][1] = (int)(N[0] - '1');

    for(int i=1; i<N.size(); ++i) {
        for(int j=0; j<2; ++j) {
            char x = (j == 1 ? '9' : N[i]);
            for(char a='0'; a <= x; ++a) {
                dp[i+1][j || a < x ] = max(dp[i+1][j || a < x], dp[i][j] + (int)(a - '0'));
            }
        }    
    }
    cout << max(dp[N.size()][0], dp[N.size()][1]) << endl;
}

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

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

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string s, t;
    cin >> s >> t;

    int ans = t.size();
    rep(i, s.size()) {
        if (s.size() < i + t.size()) break;
        int res = 0;
        rep(j, t.size()) {
            int idx = i + j;
            if (s[i+j] != t[j]) res++;
        }
        chmin(ans, res);
    }

    cout << ans << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

vector<vector<char>> s;
vector<vector<int>> g;
int h, w;

int bfs(int sy, int sx) {
    queue<pint> q;
    q.push(make_pair(sy,sx));

    pint u;
    int ux, uy;
    g.at(0).at(0) = 0;
    while(!q.empty()) {
        u = q.front(); q.pop();
        uy = u.first;
        ux = u.second;
        if(uy-1>=0) {
            if(s.at(uy-1).at(ux)=='.'&&g.at(uy-1).at(ux)==-1) { 
                q.push(make_pair(uy-1, ux));
                g.at(uy-1).at(ux) = g.at(uy).at(ux) + 1;
            }
        }
        if(uy+1<h) {
            if(s.at(uy+1).at(ux)=='.'&&g.at(uy+1).at(ux)==-1) { 
                q.push(make_pair(uy+1, ux));
                g.at(uy+1).at(ux) = g.at(uy).at(ux) + 1;
            }
        }
        if(ux-1>=0) {
            if(s.at(uy).at(ux-1)=='.'&&g.at(uy).at(ux-1)==-1) { 
                q.push(make_pair(uy, ux-1));
                g.at(uy).at(ux-1) = g.at(uy).at(ux) + 1;
            }
        }
        if(ux+1<w) {
            if(s.at(uy).at(ux+1)=='.'&&g.at(uy).at(ux+1)==-1) { 
                q.push(make_pair(uy, ux+1));
                g.at(uy).at(ux+1) = g.at(uy).at(ux) + 1;
            }
        }
        if(uy==h-1&&ux==w-1) { 
            return g.at(h-1).at(w-1);
        }
    }
    return -1;
}

int main(void) {
    cin >> h >> w;

    int white = 0;
    string stmp;
    s.resize(h, vector<char>(w));
    g.resize(h, vector<int>(w,-1));
    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            cin >> s.at(ih).at(iw);
            if(s.at(ih).at(iw)=='.') white++;
        }
    }

    int ans, res;
    res = bfs(0, 0);
    if(res==-1) {
        cout << -1 << endl;
        return 0;
    }
    else {
        ans = white-res-1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  cout << (C % gcd(A, B) == 0 ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int i,j=0,k,N,K,Q;
  scanf("%d %d %d",&N,&K,&Q);
  int A[N];
  for(i=0;i<N;i++)
    A[i]=0;
  for(i=0;i<Q;i++){
    scanf("%d ",&k);
    A[k-1]++;
  }
  
  for(i=0;i<N;i++){
    if(A[i]-Q+K > 0){
      puts("Yes");
    }
    else
      puts("No");
  }
  return 0;
}



Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    ll n;
    map<ll,int>kimap,gumap;
    P kip={0,0},gup={0,0};
    ll gumax=0,kimax=0;
    cin>>n;
    rep(i,n/2)
    {
        ll gu,ki;
        cin>>ki;
        cin>>gu;
        kimap[ki]++;
        gumap[gu]++;

    }

    int even_1=0,even_2=0,odd_1=0,odd_2=0;
    int e1,e2,o1,o2;
    int cnt=0;
    for(auto itr=kimap.begin();itr!=kimap.end();itr++)
    {
        if(itr->second>cnt)
        {
            cnt=itr->second;
            odd_1=itr->first;
        }
    }

    o1=cnt;
    cnt=0;
    for(auto itr=kimap.begin();itr!=kimap.end();itr++)
    {
        if(itr->second>cnt&& itr->first !=odd_1 )
        {
            cnt=itr->second;
            odd_2=itr->first;
        }
    }
    o2=cnt;
    cnt=0;

    for(auto itr=gumap.begin();itr!=gumap.end();itr++)
    {
        if(itr->second>cnt)
        {
            cnt=itr->second;
            even_1=itr->first;
        }
    }
    e1=cnt;
    cnt=0;

    for(auto itr=gumap.begin();itr!=gumap.end();itr++)
    {
        if(itr->second>cnt && itr->first!=even_1)
        {
            cnt=itr->second;
            even_2=itr->first;
        }
    }
    e2=cnt;

    if(odd_1==even_1)
    {
        cout<<min(n-o1-e2,n-o2-e1)<<endl;
    }
    else
    {
        cout<<n-e1-o1<<endl;
    }
    
    
    

}

Measured memory_bytes: 6528
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
for k in range(N):
    B = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == B:
                A[i][j] = 0

ok = False
for i in range(3):
    if A[i][0] == A[i][1] and A[i][1] == A[i][2]:
        ok = True
    if A[0][i] == A[1][i] and A[1][i] == A[2][i]:
        ok = True
if A[0][0] == A[1][1] and A[1][1] == A[2][2]:
    ok = True
if A[2][0] == A[1][1] and A[1][1] == A[0][2]:
    ok = True
print('Yes' if ok else 'No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD %1000000007
#define md %998244353
#define INF 2e9
#define INFI 1e9 + 7
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}






int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 
   
  ll n,i,j,k,flag=0,m,ans=0,x,c=0,sum=0;
  

 cin>>n>>k;
 
      
  if (n%k==0)
  cout<<"0";  
 else if(n<k)
 {
 	cout<<min(abs(k-n),n);
 }
 else if(n>k)
 {
   ll kk = n%k;
   ll tt = abs(kk-k);
   if(kk<tt)
     cout<<kk;
    else
     cout<<tt;
 }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q);
    vector<int> r(Q);
    rep(i, Q) cin >> l[i] >> r[i];
    vector<int> roll(N);
    roll[0] = 0;
    for(int i=1;i<N;i++){
        bool isA = S[i - 1] == 'A';
        bool isC = S[i] == 'C';
        if(isA&&isC){
          roll[i] = roll[i-1]+1;
        }else {
          roll[i] = roll[i-1];
        }
    }

    rep(i,Q){
        int li = l[i] - 1;
        int ri = r[i] - 1;
        cout << roll[ri] - roll[li] << endl;
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
//ofstream outputfile("test.txt");
//outputfile<<ans[i]<<endl;
  int main(){      
      lint n;
      cin>>n;
      lint f[n][10];
      rep(i,n){
          rep(j,10){
              cin>>f[i][j];
          }
      }
      lint p[n][11];
      rep(i,n){
          rep(j,11){
              cin>>p[i][j];
          }
      }
      lint ans=-INF;
      repp(bit,1,1<<10){
          bool x[10];
          fill(x,x+10,false);
          rep(j,10){
              if(bit&(1<<j))x[j]=true;
          }
          lint a=0;
          rep(i,n){
              lint c=0;
              rep(j,10){
            if(x[j]&&f[i][j])c++;
              }
              a+=p[i][c];
          }
          ans=max(ans,a);
      }
      cout<<ans<<endl;
    }
      
      
    

  
          
  

Measured memory_bytes: 256
t = gets.chomp.split('')

PD = []
D = []

t.each do |i|
  if i == "?"
    PD << "P"
  elsif i != "?"
    PD << i
  end
end

t.each do |k|
  if k == "?"
    D << "D"
  elsif k != "?"
    D << k
  end
end

PD_count1 = PD.join.scan("PD").length
PD_count2 = PD.join.scan("D").length

D_count1 = D.join.scan("D").length
D_count2 = D.join.scan("PD").length

print (PD_count1 + PD_count2) >= (D_count1 + D_count2) ? PD.join : D.join

Measured memory_bytes: 58444
n,k,q = map(int,input().split())
a = []
for _ in range(q):
    a.append(int(input()))

#番号iの参加者が何回正解したかを格納する配列
b = [0]*n

#番号iの参加者が何回正解したかをカウントしていく
for i in a:
    #↑参加者は1〜N番なのに対して、配列は0〜N-1なので、
    #b[i-1] += 1というようにしている。
    b[i-1] += 1


for i in range(n):
    #i番目の参加者が何点引かれるか計算
    minus_point = q - b[i]
    #それが持ち点（K点）を超えてなければ勝ち
    if k - minus_point > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb emplace_back
#define pi pair<int,int>
using namespace std;
const int maxn = 1e3 + 4;
const int mod = 1e9 + 7;

int h, w;
string a[maxn];
int dp[maxn][maxn];

int main(){
	cin>>h>>w;
	for (int i = 0; i < h; ++i){
		cin>>a[i];
	}
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			if (a[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}
			if (i == 0 and j == 0){
				dp[i][j] = 1;
			}
			else if (i == 0){
				dp[i][j] = dp[i][j-1]%mod;
			}
			else if (j == 0)
				dp[i][j] = dp[i-1][j]%mod;
			else
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
		}
	}
	cout<<dp[h-1][w-1]<<'\n';
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const ll infll = (1ll<<60);
const int mod = 1000000007;
using namespace std;

struct edge{
	int from;
	int to;
	ll cost;
};

vector<edge> graph;

int main(){
	int n, m; cin >> n >> m;
	const int s = 0, g = n-1;
	for( int i = 0; i < m; ++i ){
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		graph.push_back( (edge){a, b, -c} );
	}
	vector<ll> d(n);
	fill_n( d.begin(), n, infll );
	// スタート地点を 0 にしておく
	d[s] = 0;
	int k = n-1;
	while( k-- ){
		for( auto e : graph ){
			d[e.to] = min(d[e.to], d[e.from]+e.cost);
		}
	}
	bool negativ[n];
	fill_n( negativ, n, false );
	k = n;
	while( k-- ){
		for( auto e : graph ){
			if( d[e.to] > d[e.from]+e.cost ){
				d[e.to] = d[e.from]+e.cost;
				negativ[e.to] = true;
			}
			if( negativ[e.from] ) negativ[e.to] = true;
		}
	}
	if( negativ[g] ) cout << "inf" << endl;
	else cout << -d[g] << endl;
	return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        tmp = 0
        for k in range(D):
            tmp += (items[i][k] - items[j][k]) ** 2
        if pow(tmp, 0.5) % 1 == 0:
            ans += 1
print(ans)


Measured memory_bytes: 3188
use proconio::input;
use std::collections::HashMap;
 
fn main() {
  input! {
    n: usize,
    a: [(usize, usize);n-1],
  }
  
  let mut vertex = 0;
  for i in 1..=n {
    vertex += i * (n - i + 1);
  }
  
  let mut edges = 0;
  for (u, v) in a {
    edges += if u > v {
       v * (n - u + 1) 
    } else {
       u * (n - v + 1)
    };
  }
  
  println!("{}", vertex - edges);  
}

Measured memory_bytes: 7600
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Main {
  public static void main (String[] args) throws IOException {
    StringBuilder sb  = new StringBuilder();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt( br.readLine());
    int x = 0;
for(int i = 1; i <= n; i++){
    if(i % 3 == 0) {
      sb.append(" ");
      sb.append(i);
    } else {
      x = i;
     while(x != 0){
      if(x % 10 == 3) {
        sb.append(" ");
        sb.append(i);
        break;
    } else {
      x /= 10;
    }
     }
    }
   }
   sb.append("\n");
   System.out.print(sb);
  }
}


Measured memory_bytes: 25588
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int A, B, Q;
  cin >> A >> B >> Q;
  
  vector<long long> S(A,0);
  vector<long long> T(B,0);
  
  for(int i=0; i<A; i++) {
    cin >> S[i];
  }  
  
  for(int i=0; i<B; i++) {
    cin >> T[i];
  }
  
  for(int i=0; i<Q; i++) {
    long long p;
    cin >> p;
    
    long long x, y, w, z;
  
    auto p_s_u = upper_bound(S.begin(), S.end(), p);
    if(p_s_u==S.end()) {
      x = S[S.size()-1];
      y = S[S.size()-1];
    } else {
      x = *p_s_u;
      if(x!=S[0]) {
        y = *(p_s_u-1);
      } else {
        y = x;
      }
    }
  
    auto p_t_u = upper_bound(T.begin(), T.end(), p);
    if(p_t_u==T.end()) {
      w = T[T.size()-1];
      z = T[T.size()-1];
    } else {
      w = *p_t_u;
      if(w!=T[0]) {
        z = *(p_t_u-1);
      } else {
        z = w;
      }
    }
    long long a = abs(p-x) + abs(x-w);
    long long b = abs(p-x) + abs(x-z);
    long long c = abs(p-y) + abs(y-w);
    long long d = abs(p-y) + abs(y-z);
    long long e = abs(p-w) + abs(w-x);
    long long f = abs(p-w) + abs(w-y);
    long long g = abs(p-z) + abs(z-x);
    long long h = abs(p-z) + abs(z-y);
    
    cout << min({a,b,c,d,e,f,g,h}) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, q;
    string S;
    int count[100000];
    cin >> n >> q;
    cin >> S;
    char old = '_';
    int cnt = 0;
    for (int i=0;i<S.size();i++){
        if (old=='A' and S[i]=='C'){
            cnt++;
        }
        count[i] = cnt;
        old = S[i];
    }
    int l,r;
    for (int i=0;i<q;i++){
        cin >> l >>r;
        cout << count[r-1]-count[l-1]<< endl;
    }

}

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

#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

static constexpr auto MOD = static_cast <int64_t> (1e9+7);

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t h, w;
  cin >> h >> w;

  vector <vector <char>> a (h, vector <char> (w, '\0'));
  rep (y, h)
  {
    rep (x, w)
    {
      cin >> a[y][x];
    }
  }

  vector <vector <int>> dp (h, vector <int> (w, 0));
  dp[0][0] = 1;

  rep (y, h)
  {
    rep (x, w)
    {
      if (x == 0 && y == 0) continue;
      if (a[y][x] == '.')
      {
        if (x == 0)
        {
          dp[y][x] = dp[y - 1][x];
        }
        else if (y == 0)
        {
          dp[y][x] = dp[y][x - 1];
        }
        else
        {
          dp[y][x] = dp[y - 1][x] + dp[y][x - 1];
          dp[y][x] %= MOD;
        }
      }
    }
  }

#ifdef LOCAL
  rep (y, h)
  {
    rep (x, w) cout << dp[y][x];
    cout << endl;
  }
#endif

  cout << dp[h - 1][w - 1] << endl;

}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	long long n,k,sum=0;
	cin>>n>>k;
	for(int i=k;i<=n+1;i++){
	    sum+=(n-i+1)*i+1;
	    sum%=1000000007;
	}
	cout<<sum;
	return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

const int MAX_H = 11;
int a[MAX_H][5];
int H;
int ans;

void init() {
    ans = 0;
    rep(i, H) {
        rep(j, 5) {
            cin >> a[i][j];
        }
    }
}

bool erase() {
    bool erased = false;
    rep(i, H) {
        rep(l, 5) {
            if (a[i][l] == 0) continue;
            int r = l;
            while (r < 5 && a[i][r] == a[i][l]) {
                r++;
            }
            if (r - l >= 3) {
                // erase
                rep2(j, l, r) {
                    ans += a[i][j];
                    a[i][j] = 0;
                }
                erased = true;
            }
        }
    }

    return erased;
}

void drop() {
    for (int i = H - 1; i >= 1; i--) {
        rep(j, 5) {
            if (a[i][j] == 0) {
                for (int i2 = i - 1; i2 >= 0; i2--) {
                    if (a[i2][j] != 0) {
                        a[i][j] = a[i2][j];
                        a[i2][j] = 0;
                        break;
                    }
                }
            }
        }
    }
}

bool step() {
    if (!erase()) return false;
    drop();
    return true;
}


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

    while (cin >> H, H) {
        init();
        while (step());
        cout << ans << endl;
    }
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int  X,Y;
	cin>>X>>Y;
	if(X%Y==0) print(-1);
	else print(X);
	return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K == 0:
        print(sum(A))
        return
    
    bitK = bin(K)[2:]
    l = len(bitK)
    tight = True
    X = 0
    for n in range(l):
        one_num = 0
        for a in A:
            if a & (1 << (l - 1 - n)): one_num += 1
        if one_num > N - one_num: # Xの(n-1-i)ビット目は0推奨
            if bitK[n] == "1":
                tight = False
                X = X * 2
            else:
                X = X * 2
        elif one_num < N - one_num: # Xの(n-1-i)ビット目は1推奨
            if bitK[n] == "1":
                X = X * 2 + 1
            elif tight:
                X = X * 2
            else:
                X = X * 2 + 1
        else: # Xの(n-1-i)ビット目はどちらでもよい
            if bitK[n] == "1":
                tight = False
                X = X * 2
            else:
                X = X * 2
    ans = 0
    for a in A: ans += X ^ a
    #print(X)
    print(ans)



if __name__ == "__main__":
    main()


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

bool check(string s)
{
    string tmp;
    tmp = s;
    reverse(tmp.begin(), tmp.end());
    if (s.compare(tmp) != 0)
        return false;
    else
        return true;
}

int main()
{
    int n;
    string s, tmp1, tmp2;
    cin >> s;

    if (check(s) && check(s.substr(0, (s.length() - 1) / 2)) 
        && check(s.substr((s.length() + 1) / 2, (s.length() - 1) / 2)))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
        
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 3e5+ 2, mod = 1e9 + 7;

long long binpow(long long a, long long b, long long m = mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}


void solve() {
     int n;
     cin >> n;
     ll ans = (binpow(10, n) - (2*binpow(9, n))%mod + mod)%mod;
     cout << (ans + binpow(8, n))%mod << '\n';
}    


int main() {
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		// cout << "Case #:" << tc << " ";
		solve();
	}
}

Measured memory_bytes: 3560
/*
    coder:xxjAc
    name:
    time:2017/9/2 
*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
const int INF=1000000007;
int n,x;
int main(){
	scanf("%d",&n);
	int ans=0;
	bool f=false;
	for (int i=0;i<n;i++){
		scanf("%d",&x);
		if (f){
			f=false;
			continue;
		}
		if (x==i+1){
			ans++;
			f=true;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s, t;
  cin >> s >> t;

  map<char, char> st, ts;

  rep(i, s.size()) {
    if (!st[s[i]]) {
      st[s[i]] = t[i];
    } else if (st[s[i]] != t[i]) {
      cout << "No" << endl;
      return 0;
    }

    if (!ts[t[i]]) {
      ts[t[i]] = s[i];
    } else if (ts[t[i]] != s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int b[n];
  int f[n];
  int r[n];
  int w[n];
  for(int i=0;i<n;i++)
  {
    cin>>b[i]>>f[i]>>r[i]>>w[i];
  }
  int A[5][11]={0};
  int B[5][11]={0};
  int C[5][11]={0};
  int D[5][11]={0};
  for(int i=0;i<n;i++)
  {
    if(b[i]==1)
    {
      A[f[i]][r[i]]=A[f[i]][r[i]]+w[i];
    }
    if(b[i]==2)
    {
      B[f[i]][r[i]]=  B[f[i]][r[i]]+w[i];
    }
    if(b[i]==3)
    {
      C[f[i]][r[i]]=C[f[i]][r[i]]+w[i];
    }
    if(b[i]==4)
    {
      D[f[i]][r[i]]=  D[f[i]][r[i]]+w[i];
    }
  }
//for(int i=0;i<;i++)
//{
  for(int f=1;f<=3;f++)
  {
    for(int r=1;r<=10;r++)
    {
     cout<<" "<<A[f][r];
    }
    cout<<endl;
  }
  cout<<"####################"<<endl;

  for(int f=1;f<=3;f++)
  {
    for(int r=1;r<=10;r++)
    {
     cout<<" "<< B[f][r];
    }
  cout<<endl;
  }
    cout<<"####################"<<endl;
  for(int f=1;f<=3;f++)
  {
    for(int r=1;r<=10;r++)
    {
     cout<<" "<<C[f][r];
    }
    cout<<endl;
  }
    cout<<"####################"<<endl;
  for(int f=1;f<=3;f++)
  {
    for(int r=1;r<=10;r++)
    {
     cout<<" "<<D[f][r];
    }
    cout<<endl;
  }
return 0;
}



Measured memory_bytes: 3104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func gcd(a, b int) int {
	var rem int
	if a < b {
		a, b = b, a
	}
	for {
		rem = a % b
		if rem == 0 {
			break
		}
		a = b
		b = rem
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	k := nextInt()
	sum := 0
	for l := 1; l <= k; l++ {
		for m := 1; m <= k; m++ {
			for n := 1; n <= k; n++ {
				sum += gcd(gcd(l, m), n)
			}
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1776
h, w = map(int, input().split())
s = []
s.append(['-'] * (w + 2))
s += [['-'] + list(input()) + ['-'] for i in range(h)]
s.append(['-'] * (w + 2))

def count_bombs(y,x):
  y_c = y - 1
  x_c = x - 1
  r = 0
  for i in range(y_c, y_c + 3):
    for j in range(x_c, x_c + 3):
      if s[i][j] == '#':
        r += 1  
  return r

for i in range(1, h + 1):
  for j in range(1, w + 1):    
    if s[i][j] == '.':
      s[i][j] = count_bombs(i,j)
    print(s[i][j], end='')
  print('')

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>

using namespace std;
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

int main(){
    int a,b,n;
    cin >> n;
    int flag = 1;
    _for(i,1,10) 
    {if(flag)
        _for(j,1,10) 
    if(i*j == n) {cout <<"Yes\n", flag = 0;break;}}
    if(flag) cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    int xv[n]={},yv[n]={};
    for (int i=0; i<2*n; i++){
        if (i<n){
            int x;
            cin >> x;
            xv[i] = x;
        }
        else {
            int y;
            cin >> y;
            yv[i-n] = y;
        }
    }
    //p=1
    double d1=0;
    for (int j=0; j<n; j++){
        d1 += (double)(fabs(xv[j]-yv[j]));
    }
    cout << fixed << setprecision(15) << d1 << "\n";
    
    //p=2
    double d2=0;
    for (int k=0; k<n; k++){
        d2 += (double)(pow(fabs(xv[k]-yv[k]),2));
    }
    d2 = sqrt(d2);
    cout << fixed << setprecision(15) << d2 << "\n";
    
    //p=3
    double d3=0;
    for (int m=0; m<n; m++){
        d3 += (double)(pow(fabs(xv[m]-yv[m]),3));
    }
    d3 = cbrt(d3);
    cout << fixed << setprecision(15) << d3 << "\n";
    
    //p=∞
    double di=0;
    for (int l=0; l<n; l++){
        double d = fabs(xv[l]-yv[l]);
        if (d>=di) di = d;
    }
    cout << fixed << setprecision(15) << di << "\n";
    
    
    return 0;
}


Measured memory_bytes: 3532
#include <cstdio>
#include <iostream>

using namespace std;

int N;
int arr[55];

bool isAsd(){
  for(int i=0;i<N-1;i++){
    if(arr[i]>arr[i+1]) return false;
  }
  return true;
}

int main(void){
  int tmp;
  bool ans=false;
  scanf("%d",&N);
  for(int i=0;i<N;i++) scanf("%d",&arr[i]);
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      tmp=arr[j];
      arr[j]=arr[i];
      arr[i]=tmp;
      if(isAsd()){
        ans=true;
        break;
      }
      tmp=arr[j];
      arr[j]=arr[i];
      arr[i]=tmp;
    }
  }
  if(ans) printf("YES");
  else printf("NO");
  return 0;
}

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

struct Dice 
{
	int s[6];
	void roll(char c)
	{
        int b;
        if (c == 'E') {
            b = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = s[2];
            s[2] = b;
        }
        if (c == 'W') {
            b = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = s[3];
            s[3] = b;
        }
        if (c == 'N') {
            b = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = s[4];
            s[4] = b;
        }
        if (c == 'S') {
            b = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = s[1];
            s[1] = b;
        }
        if (c == 'R') {
            b = s[1];
            s[1] = s[2];
            s[2] = s[4];
            s[4] = s[3];
            s[3] = b;
        }

	}
    int top() 
    {
        return s[0];
    }
    int right() 
    {
        return s[2];
    }
    int left() 
    {
        return s[3];
    }
    int front() 
    {
        return s[1];
    }
};
bool same(Dice a, Dice b) {
    for (int i = 0; i < 6; i++)
        if (a.s[i] != b.s[i])
            return false;
    return true;
}
int main() {
    Dice d[2];
    int i;
    int j;
    for (j = 0; j < 2; j++)
        for (i = 0; i < 6; i++)
            cin >> d[j].s[i];
    bool f = false;

    for (i = 0; i < 4; i++) {
        d[1].roll('R');
        for (int j = 0; j < 4; j++) {
            d[1].roll('N');
            if (same(d[0], d[1])) f = true;
        }
    }
    d[1].roll('E');
    for (int j = 0; j < 4; j++) {
        d[1].roll('N');
        if (same(d[0], d[1])) f = true;
    }

    d[1].roll('W');
    d[1].roll('W');
    for (int j = 0; j < 4; j++) {
        d[1].roll('N');
        if (same(d[0], d[1])) f = true;
    }

    cout << (f ? "Yes" : "No") << endl;
    return 0;
}


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

int main()
{
	string s, s1, s2, s3;
	cin >> s;

	s1 = s.substr(0, 5);
	s2 = s.substr(6, 7);
	s3 = s.substr(14, 5);

	/*
	cout << s1 << endl;
	cout << s2 << endl;
	cout << s3 << endl;
	*/

	cout << s1 << " " << s2 << " " << s3 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int A, B;
    cin >> A >> B;
    OUT(A*B)

    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(){
int a,b,i,yj=0,x;
char s[12];
scanf("%d %d",&a,&b);
scanf("%s",s);
for(i=0;i<a;i++){
x=s[i]-'0';
if(x<0||9<x)yj++;
}
if(s[a]!='-')yj++;
for(i=a+1;i<a+b+1;i++){
x=s[i]-'0';
if(x<0||9<x)yj++;
}
if(yj==0)printf("Yes");
else printf("No");
return 0;
}

Measured memory_bytes: 128
S = input()
if S == 'SUN':
  print(7)
elif S == 'MON':
  print(6)
elif S == 'TUE':
  print(5)
elif S == 'WED':
  print(4)
elif S == 'THU':
  print(3)
elif S == 'FRI':
  print(2)
elif S == 'SAT':
  print(1)
else:
  print('ERROR')


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

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

    int a, b;
    vector<pair<int, int>> p;
    for(int i=0; i<M; i++){
        cin >> a >> b;
        p.push_back(make_pair(b, a));
    }

    sort(p.begin(), p.end());
    int ans = 0;
    int rt = 0;
    int lf = 0;
    for(int i=0; i<M; i++){
        if(p.at(i).second <= lf && rt <= p.at(i).first) continue;
        lf = p.at(i).first -1;
        rt = p.at(i).first;
        ans++;
    }    

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


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int k,x;
  cin >> k>>x;

  if(500*k>=x) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{

    int n, m;
    cin >> n >> m;
    set<int> a;
    rep(i, m)
    {
        int temp;
        cin >> temp;
        a.insert(temp);
    }
    vector<long long int> b(n + 1, 0);
    b[0] = 1;
    if (a.count(1) == 0)
        b[1] = 1;
    REP(i, 2, b.size())
    {
        if (a.count(i) == 0)
        {
            b[i] = (((b[i - 1]) % MOD) + ((b[i - 2]) % MOD)) % MOD;
        }
    }
    //rep(i, b.size()) cout << b[i] << endl;
    cout << b[b.size() - 1] << endl;
    return 0;
}


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

'''
2 1
'''

# n1 偶数
n1, n2 = map(int, input().split())

# 奇数＋奇数 /  偶数+偶数
print(int(n1 * (n1-1) / 2 + (n2 * (n2-1))/2))



Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <queue>

using namespace std;

priority_queue <long long> res;

struct student{
    long long  x;
    long long  y;
};

bool cmp(student a,student b ){
    if (a.x!=b.x){
        return a.x<b.x;
    }
    return a.y>b.y;
}

student ans[100005];

int main(){
    int n,m;
    cin>>n>>m;
    for (int i = 0;i < n; i++){
        cin>>ans[i].x>>ans[i].y;
    }
    int k = 1;
    long long result = 0;
    sort(ans,ans+n,cmp);
    for (int  i = 1;i <= m;i++){
        while(k<=n&&ans[k-1].x<=i){
            res.push(ans[k-1].y);
            k++;
        }
        if(!res.empty()){
            long long p = res.top();
            result += p;
            res.pop();
        }
    }
    cout<<result<<endl;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,l;
    cin>>n>>m>>l;
    ll a,b,c;
    ll dist[n+1][n+1];
    ll ans[n+1][n+1];
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(i==j)
            {
                dist[i][j]=0;
                ans[i][j]=0;
            }
            else
            {
                dist[i][j]=1e18;
                ans[i][j]=1e18;
            }
        }
    }
    for(ll i=1;i<=m;i++)
    {
        cin>>a>>b>>c;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    for(ll k=1;k<=n;k++)
    {
        for(ll i=1;i<=n;i++)
        {
            for(ll j=1;j<=n;j++)
            {
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(dist[i][j]<=l)
                ans[i][j]=1;
        }
    }
    for(ll k=1;k<=n;k++)
    {
        for(ll i=1;i<=n;i++)
        {
            for(ll j=1;j<=n;j++)
            {
                ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]);
            }
        }
    }
    ll q;
    cin>>q;
    ll s,t;
    for(ll i=1;i<=q;i++)
    {
        cin>>s>>t;
        if(ans[s][t]==1e18)
        {
            cout<<"-1\n";
        }
        else{
            cout<<ans[s][t]-1<<endl;
        }
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */
ll dp[51][51][50*50 + 1] = {0};

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> sum(N+1, 0);
  map<ll, ll> cnt;
  REP(i, N){
    ll a; cin >> a;
    sum[i+1] = (sum[i] + a)%M;
  }

  REP(i, N+1){
    cnt[sum[i]]++;
  }

  ll ans = 0;
  FOREACH(x, cnt){
    ans += x.second * (x.second-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                String N = scan.next();
                
                if(Character.isUpperCase(N.charAt(0))){
                 System.out.println("A");       
                }else{
                    System.out.println("a");
                }
        }
}

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

int char_to_num (char c)
{
    return (int)c - 65;
}
char num_to_char (int i)
{
    return (char)(i+65);
}
int main()
{
    int n;
    string s;
    cin >> n >> s;

    int len = s.length();
    for(int i = 0; i < len; ++i) {
        s[i] = num_to_char(( char_to_num(s[i]) + n ) % 26);
    }
    cout << s;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9;
const llong LINF = 2e18;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Improoving ATC rating. I want to leave this green trash

// Code below

int x;

void inp() {
    cin >> x;
}

llong luc[100];

void solve() {
    luc[0] = 2;
    luc[1] = 1;
    for (int i = 2; i < 100; ++i) {
        luc[i] = luc[i - 1] + luc[i - 2];
    }
    cout << luc[x];
}

void stress() {

}

void naive() {

}
void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif  
    
    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

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

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	string s; cin >> s;
	int k; cin >> k; int n = s.length();
	Rep(i, n){
		if(s[i] == 'a') continue;

		int a = ('z' - s[i]) + 1;
		if(k >= a){
			s[i] = 'a';
			k -= a;
		}
	}
	if(k > 0){
		int a = s[n - 1] - 'a';
		a = (a + k % 26) % 26 + 'a';
		s[n - 1] = a;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
n4 = int(n / 4) + 1
n7 = int(n / 7) + 1
hit = False
for f in range(n4):
    for s in range(n7):
        if (n - f * 4 - s * 7 == 0):
            hit = True
if (hit):
    print ("Yes")
else:
    print ("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
int n=s1.size();
int m=s2.size();
int dp[n+1][m+1];
for(int i=0;i<=n;i++)
{
    for(int j=0;j<=m;j++)
    {
        if(i==0||j==0)
            dp[i][j]=0;
        else if(s1[i-1]==s2[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
        else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
}
int i=n;
int j=m;
string s="";
while(i>=1&&j>=1)
{
    if(s1[i-1]==s2[j-1])
    {
        s+=s1[i-1];
        i--;
        j--;
    }
    else{
        if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
    }
}
reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    long long n, d, a; cin >> n >> d >> a;
    vector<pair<long long, long long>> xhs(n);
    for(int i=0; i<n; ++i){
        cin >> xhs[i].first >> xhs[i].second;
    }
    sort(xhs.begin(), xhs.end());
    vector<long long> xs(n), hs(n);
    for(int i=0; i<n; ++i){
        xs[i]=xhs[i].first;
        hs[i]=xhs[i].second;
    }
    vector<long long> decs(n+1);
    long long cnt=0;
    long long ans=0;
    for(int i=0; i<n; ++i){
        cnt-=decs[i];
        hs[i]-=a*cnt;
        if(hs[i]<=0) continue;
        long long inc=(hs[i]+a-1)/a;
        int j=upper_bound(xs.begin(), xs.end(), xs[i]+2*d)-xs.begin();
        decs[j]+=inc;
        cnt+=inc;
        ans+=inc;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>

int N, M;
std::vector<int> adj[100001];
int dp[100001];

int f(int u) {
  if (adj[u].size() == 0) return 0;
  if (dp[u] != -1) return dp[u];
  int best = 0;
  for (int v : adj[u]) {
    best = std::max(best, 1 + f(v));
  }
  return dp[u] = best;
}

int main() {
  std::memset(dp, -1, sizeof(dp));
  std::cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int u, v; std::cin >> u >> v;
    --u; --v;
    adj[u].push_back(v);
  }
  int best = 0;
  for (int i = 0; i < N; ++i) {
    best = std::max(best, f(i));
  }
  std::cout << best << '\n';
}


Measured memory_bytes: 8192
W, H, N = map(int, input().split())
x = []
y = []
a = []
X = [1]*W
Y = [1]*H
ans = 0
for _ in range(N):
    i, j, k = map(int, input().split())
    x.append(i)
    y.append(j)
    a.append(k)
for i in range(N):
    if a[i] == 1:
        for j in range(x[i]):
            X[j] = 0
    elif a[i] == 2:
        for j in range(x[i], W):
            X[j] = 0
    elif a[i] == 3:
        for j in range(y[i]):
            Y[j] = 0
    else:
        for j in range(y[i], H):
            Y[j] = 0
for i in range(H):
    for j in range(W):
        if X[j] and Y[i]:
            ans += 1
print(ans)

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

int main(){
  int N; cin >> N;
  pair<int,int> m1(0,0), m2(0,0);
  for(int i=0; i<N; i++){
    int tmp; cin >> tmp;
    if(tmp>=m1.first){
      m2=m1;
      m1=make_pair(tmp,i);
    }else if(tmp>=m2.first){
      m2=make_pair(tmp,i);
    }
  }
  for(int i=0; i<N; i++){
    if(i==m1.second) cout << m2.first << endl;
    else cout << m1.first << endl;
  }
}

Measured memory_bytes: 1664
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int a[200000];

int main(){
    int n;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",&a[i]);
    }
    a[n] = INT_MAX;

    sort(a,a+n);

    if(a[n - 1] - a[0] > 1){
        printf("No\n");
        return 0;
    }
    int cou = 0;

    if(a[n - 1] - a[0] == 1){

        cou = 1;
        FOR(i,1,n - 1){
            if(a[i - 1] < a[i])
                break;
            cou++;
        }
    }
    FOR(i,cou,n )
        a[i] -= cou;

    int m = n - cou;

    if((a[n - 1] == a[0] && n == a[0] + 1) || (a[n - 1] > 0 && 2 * a[n - 1] <= m))
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 640