akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}
/*
double x[12];
string u[12];
*/
int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  double sum = 0.0;
  REP(i,n){
    double x;
    string u;
    cin >> x >> u;
    if(u == "BTC") sum += x*380000;
    else sum+=x;
  }

  cout << fixed << setprecision(10) << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<tuple<string,int,int>> sp;
    string s;
    int i,p;
    for(i=0;i<n;i++){
        cin >> s >> p;
        sp.push_back(make_tuple(s,-p,i));
    }
    sort(sp.begin(),sp.end());
    for(int i=0;i<sp.end()-sp.begin();i++){
        cout<<get<2>(sp[i])+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
    long long width, height, N;
    //int width_a = 0, height_a = 0;
 
    long long uplimit;
    long long lowlimit = 0;
    long long rightlimit;
    long long leftlimit = 0;
    long long S;
 
    long long x[101], y[101], a[101];
 
    cin >> width >> height >> N;
 
    uplimit = height;
    rightlimit = width;
 
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i] >> a[i];
    }
 
    for (int i = 0; i < N; i++)
    {
        if (a[i]==1 && leftlimit < x[i])
        {
            leftlimit = x[i];
        }
        else if (a[i] == 2 && rightlimit > x[i])
        {
            rightlimit = x[i];
        }
        else if (a[i] == 3 && lowlimit < y[i])
        {
            lowlimit = y[i];
        }
        else if (a[i] == 4 && uplimit > y[i])
        {
            uplimit = y[i];
        }
    }
 
    if ((uplimit - lowlimit) < 0 || (rightlimit - leftlimit) < 0)
    {
        S = 0;
    }
    else
    {
        S = (uplimit - lowlimit)*(rightlimit - leftlimit);
    }
 
    cout << S << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	// cout<<n<<endl;
	string aaa;
	getline(cin,aaa);
	rep(i,n){
		string s;
		getline(cin,s);
		// cout<<s<<endl;
		string s2=s;
		rep(j,s.size()){
			if(s2[j]==' '){
				s2[j]=-1;
			}
			else{
				s2[j]=s2[j]-'a';
			}
		}
		string ans;
		bool f=false;
		rep(j,1000){
			if(j%2==0||j%13==0){
				continue;
			}
			rep(k,26){
				string tmp=s2;
				rep(l,s2.size()){
					if(tmp[l]==-1){
						tmp[l]=' ';
					}
					else{
						tmp[l]=(j*tmp[l]+k)%26;
						tmp[l]+='a';
					}
				}
				if(tmp.find("this",0)!=string::npos||tmp.find("that",0)!=string::npos){
					ans=tmp;
					f=true;
					break;
				}
				
			}
			if(f) break;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    int N = S.size();
    vector<int> v(N+1);
    for(int i=0; i<N; i++) {
        v[i+1] = S[i] - '0';
    }

    partial_sum(v.begin(), v.end(), v.begin());

    int ans = 0;
    for(int K=0; K<=S.size(); K++) {
        if(v[K] - v[N-K] == 0 || v[K] - v[N-K] == 2*K-N) ans = K;
    }

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


Measured memory_bytes: 896
// AOJ 2758:  Sendame
// 2017.10.10 bal4u@uu

#include <stdio.h>

#define MAMORU 0
#define TAMERU 1
#define KOGEKI 2

char a[2][102];
char tr['z'];

int main()
{
	int k, i, j, p[2], ans;
	char buf[13], *s[] = { "Hikiwake-kun", "Isono-kun", "Nakajima-kun" };

	tr['m'] = MAMORU, tr['t'] = TAMERU, tr['k'] = KOGEKI;
	scanf("%d", &k);
	for (j = 0; j < 2; j++) for (i = 0; i < k; i++) {
		scanf("%s", buf);
		a[j][i] = tr[*buf];
	}
	ans = -1, p[0] = p[1] = 0;
	for (i = 0; i < k; i++) {
		for (j = 0; j < 2; j++) if (a[j][i] == KOGEKI) {
			if (p[j] == p[!j] && a[!j][i] == KOGEKI) continue;
			if (p[j] == 0) { ans = !j; goto FIN; }
			if (a[!j][i] == TAMERU || p[j] > p[!j] && a[!j][i] != MAMORU ||
				p[j] == 5 && a[!j][i] == MAMORU) { ans = j; goto FIN; }
		}
		for (j = 0; j < 2; j++) {
			if (a[j][i] == KOGEKI) p[j] = 0;
			else if (a[j][i] == TAMERU) { if (++p[j] > 5) p[j] = 5; }
		}
	}
FIN:puts(s[1+ans]);
	return 0;
}

Measured memory_bytes: 1716
n = int(input())
TXY = [list(map(int,input().split())) for _ in range(n)]
pret = 0
prex = 0
prey = 0
flag = True
for t,x,y in TXY:
    if t-pret < abs(x-prex)+abs(y-prey):
        flag = False
        break
    elif t-pret > abs(x-prex)+abs(y-prey)  and (abs(x-prex)+abs(y-prey))%2 != (t-pret)%2:
        flag = False
        break
    pret = t
    prex = x
    prey = y
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27380
//organize and stay in moment - Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
#define MAXN (int)2e5+5
#define pb push_back
int mod= 998244353;
int arr[MAXN];
void solve(){
  int n,k; cin>>n>>k;
  int t=n/k;
  cout<<min(n-t*k,k-(n-t*k))<<"\n"; 
}
int32_t main()
{
  int t; t=1; //cin>>t;
  while(t--) solve();
  return 0;
}


Measured memory_bytes: 256
a = [int(input()) for i in range(5)]
#10で割った余りが0でないもののうち、余りが一番小さい品を最後に注文するのが最も早くなる
last = -1
for i in range(5):
  if a[i] % 10 != 0:
    last = i
  break

if last == -1:
  last = 0
else:
  for i in range(5):
    if a[i] % 10 < a[last] % 10 and a[i] % 10 != 0:
      last = i


ans = 0
for i in range(5):
  if i == last:
    continue

  ans += a[i]
  if ans % 10 != 0:
    ans += 10 - (a[i] % 10)

ans += a[last]

print(ans)

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

int main(){
    int wtime[6], ans, trans[3] = {3600, 60, 1};

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 6; j++){
            cin >> wtime[j];
        }
        ans = 0;
        for(int j = 0; j < 3; j++){
            ans += (wtime[j + 3] - wtime[j]) * trans[j];
        }
        for(int j = 0; j < 3; j++){
            cout << ans / trans[j];
            ans -= ans / trans[j] * trans[j];
            if(j < 2){
                cout << " ";
            }else{
                cout << endl;
            }
        }

    }

}

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

int const N = 200000;
ll const inf = 1e18;
int x[N + 1];
ll dp[N + 1][5];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n + 1)scanf("%d", x + i);
	f(i, 0, n + 1)f(j, 0, 5)dp[i][j] = inf;
	dp[0][0] = 0;
	f(i, 1, n + 1)f(j, 0, 5)if (dp[i - 1][j] < inf)f(k, j, 5){
		ll nc = dp[i - 1][j];
		if (k == 0 || k == 4)nc += x[i];
		else if (k == 1 || k == 3){
			if (x[i] == 0)nc += 2;
			else if (x[i] & 1)++nc;
		}else if (!(x[i] & 1))++nc;
		dp[i][k] = min(dp[i][k], nc);
	}
	ll an = inf;
	f(i, 0, 5)an = min(an, dp[n][i]);
	printf("%lld\n", an);
}

Measured memory_bytes: 8832
fun main(args:Array<String>):Unit{
    val (t,d,l) = readLine()!!.split(' ').map(String::toInt)
    f(t, d, l)
}
tailrec fun f(t:Int, d:Int, l:Int):Unit{
    if (t != 0 && d != 0 && l != 0){
        var prev = 1 - d
        var timeSum = - d
        for (time in 1 .. t){
            val x = readLine()!!.toInt()
            if (x >= l){
                if (time - prev > d){
                    timeSum += d
                    prev = time
                }else{
                    timeSum += time - prev
                    prev = time
                }
            }
        }
        if (t - prev > d){
            timeSum += d
        }else{
            timeSum += t - prev
        }
        println(timeSum)
        val (tt, dd, ll) = readLine()!!.split(' ').map(String::toInt)
        f(tt, dd, ll)
    }
}


Measured memory_bytes: 67000
s = gets.to_s.chomp.bytes
q = gets.to_s.to_i

reverse_state = false

l = []
r = []
q.times do
  
  query = gets.to_s.split
  # p query
  if query[0] == "1"
    reverse_state = !reverse_state
    # s.reverse!
  else
    if query[1] == "1"
      reverse_state ? (r << query[2].ord)  : (l << query[2].ord)
    else
      reverse_state ? (l << query[2].ord) : (r << query[2].ord)
    end
  end
  p 
end

if reverse_state
  puts (r.reverse + s.reverse + l ).pack("U*")
else
  puts (l.reverse + s + r ).pack("U*")
end

Measured memory_bytes: 10748
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;

  char at[N];
  rep(i,N) at[i] = ' ';
  ll ans = 0;
  rep(i,N) {
    char now = T[i];
    char prev = ' ';
    char next = ' ';
    if (i >= K) prev = at[i-K];
    if (i+K < N) next = T[i+K];
    if (now == 'r') {
      if (prev == 'p') {
       if (next == 'p') {
          at[i] = 'r';
        } else {
          at[i] = next;
        }
      } else {
        at[i] = 'p';
        ans += P;
      }
    } else if (now == 's') {
      if (prev == 'r') {
       if (next == 'r') {
          at[i] = 's';
        } else {
          at[i] = next;
        }
      } else {
        at[i] = 'r';
        ans += R;
      }
    } else if (now == 'p') {
      if (prev == 's') {
       if (next == 's') {
          at[i] = 'p';
        } else {
          at[i] = next;
        }
      } else {
        at[i] = 's';
        ans += S;
      }
    }
  }

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


Measured memory_bytes: 512
import java.io.*;
import java.util.Scanner;
 
public class Main {
    public static int divide(int a, int b) {
        return a / b;
    }

    public static int remainder(int a, int b) {
        return a % b;
    }

    public static double dividef(int a, int b) {
        return 1.0 * a / b;
    }
 
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.printf("%d %d %f", divide(a,b), remainder(a,b),dividef(a,b));
    }
}


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

int cntChar(bool cntX[], bool cntY[]){
	int sum = 0;
	for(int i=0;i<26;i++){
		sum = (cntX[i] && cntY[i]) ? sum+1 : sum;
	}
	return sum;
}

void count(bool cnt[], string s){
	int i=0;
	while(s[i]){
		cnt[s[i]- 'a'] = 1;
		i++;
	}
}

int cutAndCount(string s, int n){
	string x, y;
	bool cntX[26], cntY[26];
	int max = 0;
	for(int i = 0; i < (n-1); i++){
		for(int j=0;j<26;j++){
			cntX[j] = 0; cntY[j] = 0;
		}
		x = s.substr(0, i+1);
		y = s.substr(i+1, n-i-1);
		count(cntX, x);
		count(cntY, y);
		int tmp = cntChar(cntX, cntY);
		max = (tmp > max) ? tmp : max;
	}
	return max;
}


int main(){
	int n;
	string s;
	cin >> n;
	cin.ignore();
	getline(cin, s,'\n');
	cout << cutAndCount(s, n);
}

Measured memory_bytes: 3608
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a,b,c=0,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> a >> b >> c;
    ans = a / (b+c);
    if(a-ans*(b+c)==c)
        cout << ans <<endl; 
    else cout << ans-1 <<endl; 
    return 0;
}


Measured memory_bytes: 256
function main()

  A, B, H, M = map(x -> parse(Int, x), split(readline()))
  
  times = 60H + M
  
  A_deg = 0.5*times
  B_deg = 6*M
  
  degree = min(abs(A_deg - B_deg), 360 - abs(A_deg - B_deg))
  
  ans = sqrt(A^2 + B^2 - 2*A*B*cosd(degree))
  
  println(ans)
  
end

main()

Measured memory_bytes: 200244
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int K = in.nextInt();
        int A = in.nextInt();
        int B = in.nextInt();
        boolean flag = false;
        for (int i = A; i <=B  ; i++) {
            if(i%K == 0){
                flag = true;
                break;
            }
        }

        if (flag){
            System.out.println("OK");
        }else System.out.println("NG");
    }

    public static int MaxTwo(int x, int y){
        return ((x > y)?x:y);
    }
    public static int MaxThree(int x, int y, int z){
        return MaxTwo(MaxTwo(x,y),z);
    }
    public static int MinTwo(int x, int y){
        return ((x < y)?x:y);
    }
    public static int MinThree(int x, int y, int z){
        return MinTwo(MinTwo(x,y),z);
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int size){
            int arr[] =new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = Integer.parseInt(next());
//                sum = sum + in.nextInt();
            }
            return arr;
        }

    }
}




Measured memory_bytes: 32780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		//long n = sc.nextLong();
		//long m = sc.nextLong();
		//long k = sc.nextLong();

		if(s.substring(0, 1).equals(t.substring(2,3))&&s.substring(1, 2).equals(t.substring(1,2))&&s.substring(2, 3).equals(t.substring(0,1))) {
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
		//System.out.println(2*m-n);
	}
}




Measured memory_bytes: 21844
#include<iostream>
#include<queue>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
bool used[101];
int cost[101][101];
int n,m;
int prim(){
  for(int i=0;i<n;i++){
    used[i]=false;
  }
  priority_queue<P,vector<P>,greater<P> > q;
  int res=0;
  q.push(P(0,0));
  while(!q.empty()){
    P p=q.top();
    q.pop();
    if(used[p.second]==true){
      continue;
    }
    used[p.second]=true;
    res+=p.first;
    for(int i=0;i<n;i++){
      if(cost[p.second][i]!=INF){
	q.push(P(cost[p.second][i],i));
      }
    }
    
  }
  return res;
}
main(){
  int a,b,k;
  while(1){  
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cost[i][j]=INF;
      }
    }
    cin>>m;
    for(int i=0;i<m;i++){
      scanf("%d,%d,%d",&a,&b,&k);
      cost[a][b]=k/100-1;
      cost[b][a]=k/100-1;
    }
    cout<<prim()<<endl;
  }
}

Measured memory_bytes: 1416
#include <stdio.h>
int main(void)
{
  int n;
  int i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)
      break;
    int f=0;
    for(i=1;i<=n/2;i++){
      int sum=0;
      for(j=i;sum<n;j++){
	sum+=j;
      }
      if(sum==n)
	f++;
      
    }
    printf("%d\n",f);
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 1;
    for (int i = 0; i < k; i++) {
        ans *= (n * m - i);
        ans %= 1000000007;
        ans *= modinv(i + 1, 1000000007);
        ans %= 1000000007;
    }
    ll b = (k * (k - 1) + k * (k - 1) % 1000000007 * modinv((n * m - 1) % 1000000007, 1000000007) % 1000000007) % 1000000007;
    ans *= b;
    ans %= 1000000007;
    ll t = 0;
    ll y = 0;
    for (int i = 0; i < n; i++) {
        t += i * (n - i) * 2 %1000000007;
        t %= 1000000007;
    }
    for (int i = 0; i < m; i++) {
        y += i * (m - i) * 2 %1000000007;
        y %= 1000000007;
    }
    ll p = n * n % 1000000007;
    ll q = m * m % 1000000007;
    t *= modinv(p, 1000000007);
    y *= modinv(q, 1000000007);

    ans *= (t + y) % 1000000007;
    ans %= 1000000007;
    ans *= modinv(2, 1000000007);
    ans %= 1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		try (Scanner sc = new Scanner(System.in)) {
			int x = sc.nextInt();
			int a = sc.nextInt();
			
			if (x < a) {
				System.out.println(0);
			} else {
				System.out.println(10);
			}
		}

	}

}

Measured memory_bytes: 21716
import java.io.IOException;
import java.util.Scanner;

/**
 * <pre>
 * NumberOfIsland
 *
 * ??¶?????°???????????????
 * </pre>
 *
 * @author ?????????????????§???
 *
 */
public class Main{

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {

			boolean map[][] = new boolean[12][12];
			for (int cnt1 = 0; cnt1 < map.length; cnt1++) {
				// ????????????????????????
				char[] tmp_row = sc.next().toCharArray();
				for (int cnt2 = 0; cnt2 < map[0].length; cnt2++) {
					// true ?????? false???????´?
					map[cnt1][cnt2] = (tmp_row[cnt2] == '1')/*
															 * (tmp_row[cnt2] ==
															 * '1'? true:false)
															 */;
				}
			}
			// ??¶?????°
			int ans = 0;
			for (int cnt1 = 0; cnt1 < map.length; cnt1++) {
				for (int cnt2 = 0; cnt2 < map[0].length; cnt2++) {
					// ?????°??????
					if (map[cnt1][cnt2]/* == true */) {
						// ?????°???????????¬???
						land_survey(cnt1, cnt2, map);
						// ??¬??????????????£????????¶?????°?????????
						ans++;
					}
				}
			}
			// ???????????????
			System.out.println(ans);
		} // ?????????????????????
			// ????????????????????????
		sc.close();
	}// ?????????????????????????????????

	/**
	 *
	 * ?????°??¬??????????????????
	 *
	 * @param mh
	 *            ??????
	 * @param mw
	 *            ??????
	 * @param map
	 */
	private static void land_survey(int mh, int mw, boolean[][] map) {

		map[mh][mw] = false;
		// ?§??????????????????????
		int move_list1[] = { 1, 0, -1, 0 };
		int move_list2[] = { 0, 1, 0, -1 };
		for (int cnt = 0; cnt < move_list1.length; cnt++) {
			// ??????????????????????§??????????
			int addr_h = mh + move_list1[cnt];
			// ??????????????????????§??????????
			int addr_w = mw + move_list2[cnt];

			// ??°???????????????????????°
			if (0 <= addr_h && 0 <= addr_w && addr_h < map.length && addr_w < map[0].length
					&& map[addr_h][addr_w]/* ==true */)
				// ?????°??????????????°????¶?????????¬???
				land_survey(addr_h, addr_w, map);
		}
	}// land_survey????????????????????????

}// ??????????????????????????????

Measured memory_bytes: 26084
#include <bits/stdc++.h>
const int INF = 1e9;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;

#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string str;cin >> str;
    LL ans = 0;

        ans += str.at(0)-'0'-1;
        string ins;
        ins += str.at(0);
        for(int a = 0;a < str.size()-1;a++){
            ins += '9';
        }
        if(str == ins){
            LL w = 0;
            for(int a = 0;a < str.size();a++){
                w += str.at(a)-'0';
            }
            cout<<w<<endl;
            return 0;
        }
        for(int a = 0;a < str.size()-1;a++){
            ans += 9;
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, c, x[100009], v[100009], ans, acc[2][100009], dat[2][100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> c;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> v[i];
	}
	long long tmp = v[0];
	acc[0][0] = tmp - x[0];
	dat[0][0] = acc[0][0];
	for (int i = 1; i < n; i++) {
		tmp += v[i];
		acc[0][i] = tmp - x[i];
		dat[0][i] = max(dat[0][i - 1], acc[0][i]);
	}
	tmp = v[n - 1];
	acc[1][n - 1] = tmp - (c - x[n - 1]);
	dat[1][n - 1] = acc[1][n - 1];
	for (int i = n - 2; i >= 0; i--) {
		tmp += v[i];
		acc[1][i] = tmp - (c - x[i]);
		dat[1][i] = max(dat[1][i + 1], acc[1][i]);
	}
	ans = max(ans, dat[0][n - 1]);
	for (int i = n - 1; i > 0; i--) {
		ans = max(ans, acc[1][i] - (c - x[i]) + dat[0][i - 1]);
	}
	ans = max(ans, dat[1][0]);
	for (int i = 0; i < n - 1; i++) {
		ans = max(ans, acc[0][i] - x[i] + dat[1][i + 1]);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

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

int powmod(int a, int n, int mod) {
	if (a >= mod) a %= mod;
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int p10[19];
int L, a, b, m;

//r^0 + … + r^(n - 1)
int tohi(int r, int n) {
	int s[61];
	int i;
	
	s[0] = 1;
	for (i = 0; i < 60; i++) {
		s[i + 1] = s[i] + powmod(r, (1LL << i), m) * s[i];
		s[i + 1] %= m;
	}
	
	int cnt = 0;
	int ret = 0;
	for (i = 59; i >= 0; i--) {
		if ((n >> i) % 2 == 1) {
			ret += powmod(r, cnt, m) * s[i];
			ret %= m;
			cnt += (1LL << i);
		}
	}
	
	//cout << "tohi(" << r << ", " << n << ") = " << ret << endl;
	return ret;
}

//0 * r^0 + … + (n - 1) * r^(n - 1)
int tohi2(int r, int n) {
	int s[61];
	int t[61];
	int i;
	
	s[0] = 1;
	for (i = 0; i < 60; i++) {
		s[i + 1] = s[i] + powmod(r, (1LL << i), m) * s[i];
		s[i + 1] %= m;
	}
	
	t[0] = 0;
	for (i = 0; i < 60; i++) {
		t[i + 1] = t[i] + powmod(r, (1LL << i), m) * ((1LL << i) % m * s[i] % m + t[i]) % m;
		t[i + 1] %= m;
	}
	
	int cnt = 0;
	int ret = 0;
	for (i = 59; i >= 0; i--) {
		if ((n >> i) % 2 == 1) {
			int res1 = powmod(r, cnt, m);
			int res2 = cnt % m * s[i] + t[i]; res2 %= m;
			ret += res1 * res2;
			ret %= m;
			cnt += (1LL << i);
		}
	}
	
	//cout << "tohi2(" << r << ", " << n << ") = " << ret << endl;
	return ret;
}

//a, a + d, …, a + (n - 1)d, x桁
int calc(int a, int d, int n, int x) {
	int syu = (a % m + (n - 1) % m * d % m) % m;
	int res1 = syu * tohi(p10[x], n) % m;
	int res2 = d % m * tohi2(p10[x], n) % m;
	return (res1 + m - res2) % m;
}

signed main() {
	int i, j;
	
	p10[0] = 1;
	for (i = 1; i < 19; i++) p10[i] = p10[i - 1] * 10;
	
	cin >> L >> a >> b >> m;
	
	int ans = 0;
	vector<int> cnts;
	for (i = 17; i >= 0; i--) {
		if (a >= p10[i + 1]) continue;
		
		int l, r;	//[l, r]項目はi+1桁
		if (a >= p10[i]) { l = 0; }
		else { l = (p10[i] - a + b - 1) / b; }
		r = (p10[i + 1] - a + b - 1) / b - 1;
		if (r >= L) r = L - 1;
		if (l > r) continue;
		//cout << i << ", " << "[l, r] = " << l << ", " << r << endl;
		
		int syo = a + l * b;
		int n = r - l + 1;
		int res1 = 1;
		
		rep(j, cnts.size()) {
			res1 *= powmod(10, cnts[j], m);
			res1 %= m;
		}
			
		ans += res1 * calc(syo, b, n, i + 1) % m;
		ans %= m;
		
		//cnt += n * (i + 1); <- オーバーフローするのでちょっとズルします。
		rep(j, i + 1) cnts.push_back(n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  string S;
  cin >> S;
  if (S.length() % 2 == 1) {
    out("No");
    return 0;
  }
  rep(i, S.length()) {
    if ((i % 2 == 0 && S[i] != 'h') || (i % 2 == 1 && S[i] != 'i')) {
      out("No");
      return 0;
    }
  }
  out("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  using namespace std;

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (auto &e : A) cin >> e;
  
  auto sum_A = accumulate(A.begin(), A.end(), 0);
  auto remaining_days = N - sum_A;
  
  if (remaining_days < 0) {
  	cout << "-1\n";
    return 0;
  }
  
  cout << remaining_days << endl;
  
  return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

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

	int ans = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i]!=t[i]) ans++;
	}

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


Measured memory_bytes: 3856
#include <iostream>
using namespace std;
int main(){
		int a,b;
		cin >> a >> b;
		if(a<b)      cout << "a < b"  << endl;
		else if(a>b) cout << "a > b"  << endl;
		else         cout << "a == b" << endl;
		return 0;
}

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

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

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

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

    int i = 0;
    while(a > 0 && c > 0){
        if(i % 2 == 1){
            a -= d;
        }else{
            c -= b;
        }
        i++;
    }

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


    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int n;
  cin >> n;
  vector<ll> l(n);
  rep (i,n) cin >> l[i];

  ll count = 0;
  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      for (int k = j+1; k < n; k++) {
        ll a = l[i];
        ll b = l[j];
        ll c = l[k];
        if (a == b || a == c || b == c) continue;
        if (a+b > c && b+c > a && c+a > b) count++;
      }
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

char a[1000010];
int main()
{
	scanf("%s",a);
	int ans=0;
	int len=strlen(a);
	for(int i=1;i<len;i++){
		if(a[i]!=a[i-1])ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 384
using System;
class c
{
    static void Main()
    {
        var nq = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int n = nq[0], q = nq[1];
        var s = Console.ReadLine();
        var ac = new int[s.Length];
        for (int i = 1; i < s.Length; i++)
        {
            if (s[i - 1] == 'A' && s[i] == 'C') ac[i] = ac[i - 1] + 1;
            else ac[i] = ac[i - 1];
        }
        for (int i = 0; i < q; i++)
        {
            var lr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine(ac[lr[1] - 1] - ac[lr[0] - 1]);
        }
    }
}

Measured memory_bytes: 17816
from collections import defaultdict
N, M = map(int, input().split())
L = []
A = []
for _ in range(M):
    p, y = map(int, input().split())
    L.append([p, y])
    A.append([p, y])

L.sort(key=lambda x: x[1])

ans_d = defaultdict()
dp = [0] * (N + 1)
for i, v in enumerate(L):
    # k = 6 - len(str(v[0]))
    s = ''
    if (dp[v[0]] != 0):
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'

        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    else:
        l_dp = 6 - len(str(dp[v[0]] + 1))
        for j in range(l_dp):
            s += '0'
        s += str(dp[v[0]] + 1)
        dp[v[0]] += 1
    k = str(v[0]) + ' ' + str(v[1])
    ans_d[k] = s

for i in A:
    m = str(i[0]) + ' ' + str(i[1])
    k = 6 - len(str(i[0]))
    s = ''
    for j in range(k):
        s += '0'
    s += str(i[0])
    print(s + ans_d[m])


Measured memory_bytes: 54612
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    int a = 0, b = 0, ab = 0, ans = 0;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i];
        for(int j = 0; j < S[i].size() - 1; j++) {
            if(S[i].substr(j, 2) == "AB") {
                ans++;
            }
        }
        if (S[i].front() == 'B' && S[i].back() == 'A') {
            ab++;
        } else if (S[i].back() == 'A') {
            a++;
        } else if (S[i].front() == 'B') {
            b++;
        }
    }
    if(a > 0 || b > 0) {
        if(a > 0 && b > 0) {
            ans += min(a, b) + ab;
        } else {
            ans += ab;
        }
    } else {
        ans += max(ab - 1, 0);
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
  int n;
  std::cin >> n;

  std::vector<int> t(n), buf(n);
  for (int i = 0; i < n; i++) {
    std::cin >> t[i];
  }

  buf = t;

  int m;
  std::cin >> m;

  for (int i = 0; i < m; i++) {
    int p, x;
    std::cin >> p >> x;
    
    std::swap(t[--p], x);

    int ans = 0;
    for (int j : t) {
      ans += j;
    }
    std::cout << ans << std::endl;

    t = buf;
  }

  return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
int gcd(int i, int j) {
    return j == 0 ? i : gcd(j, i % j);
}
int main() {
    int a, b, c, k, ans = 0;
    scanf("%d", &k);
    for(a = 1; a <= k; ++a)
    for(b = 1; b <= k; ++b)
    for(c = 1; c <= k; ++c) 
    ans += gcd(gcd(a, b), c);
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  string s, t;
  int a, b;
  string u;
  cin >> s >> t >> a >> b >> u;
  if (u == s) {
    a--;
  }
  else {
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AtTest
{
    class Program
    {
        static void Main(string[] args)
        {            
            int k = int.Parse(Console.ReadLine());
            
            long max = 1000000000000000;
            long now = 19;
            long delta = 10;
            for (int i = 1; i <= k&&now<=max; i++)
            {
                if (i < 10)
                {
                    Console.WriteLine(i);
                }
                else
                {
                    for (; now < max; now += delta)
                    {
                        if (Snk(now) <= Snk(now + delta))
                        {
                            Console.WriteLine(now);
                            now += delta;
                            break;
                        }
                        else
                        {
                            now -= delta;
                            delta *= 10;
                        }
                    }
                }
            }
        }

        public static double Snk(long val)
        {
            long sk = 0;
            long subN = val;
            while (subN > 9)
            {
                sk += subN % 10;
                subN /= 10;
            }
            sk += subN;
            return (double)val / sk;
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] odd = new long[n - n/2];
        long[] even = new long[n/2];
        Long[] nums = new Long[n];
        for(int i = 0; i < n; i++) {
            nums[i] = sc.nextLong();
        }
        Arrays.sort(nums);
        int oddIndex = 0;
        int evenIndex = 0;
        for(int i = 0; i < n; i++) {
            if(i % 2 == 0) {
                odd[oddIndex] = nums[i];
                oddIndex++;
            } else {
                even[evenIndex] = nums[i];
                evenIndex++;
            }
        }
        long[] newNums = new long[n];
        int middle = n - n/2;
        long count = 0;
        int evenStart = 0;
        int evenEnd = even.length-1;
        for(int i = middle; i < n; i++) {
            if(count % 2 == 0) {
                newNums[i] = even[evenEnd];
                evenEnd--;
            } else {
                newNums[i] = even[evenStart];
                evenStart++;
            }
            count++;
        }
        count = 0;
        int oddStart = 0;
        int oddEnd = odd.length-1;
        for(int i = middle-1; i >= 0; i--) {
            if(count % 2 == 0) {
                newNums[i] = odd[oddStart];
                oddStart++;
            } else {
                newNums[i] = odd[oddEnd];
                oddEnd--;
            }
            count++;
        }
        long sum1 = 0;
        long prev = newNums[0];
        for(int i = 1; i < n; i++) {
            long current = newNums[i];
            sum1 += Math.abs(prev - current);
            prev = current;
        }


        Arrays.sort(nums, Collections.reverseOrder());
        oddIndex = 0;
        evenIndex = 0;
        for(int i = 0; i < n; i++) {
            if(i % 2 == 0) {
                odd[oddIndex] = nums[i];
                oddIndex++;
            } else {
                even[evenIndex] = nums[i];
                evenIndex++;
            }
        }
        middle = n - n/2;
        count = 0;
        evenStart = 0;
        evenEnd = even.length-1;
        for(int i = middle; i < n; i++) {
            if(count % 2 == 0) {
                newNums[i] = even[evenEnd];
                evenEnd--;
            } else {
                newNums[i] = even[evenStart];
                evenStart++;
            }
            count++;
        }
        count = 0;
        oddStart = 0;
        oddEnd = odd.length-1;
        for(int i = middle-1; i >= 0; i--) {
            if(count % 2 == 0) {
                newNums[i] = odd[oddStart];
                oddStart++;
            } else {
                newNums[i] = odd[oddEnd];
                oddEnd--;
            }
            count++;
        }
        long sum2 = 0;
        prev = newNums[0];
        for(int i = 1; i < n; i++) {
            long current = newNums[i];
            sum2 += Math.abs(prev - current);
            prev = current;
        }

        System.out.println(Math.max(sum1, sum2));
    }
}



Measured memory_bytes: 64780
#!/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,m = LI()
a = LI()
a = list(accumulate(a))
lst = [0] + [i % m for i in a]
lst = list(Counter(lst).items())
ans = 0
for i,j in lst:
    if j >= 2:
        ans += j*(j-1)//2
print(ans)

Measured memory_bytes: 60836
A=list(input())
B=list(input())
C=list(input())

next=A[0]
while True:
  if next=='a':
    if len(A)==0:
      print('A')
      break
    next=A[0]
    A=A[1:]
  elif next=='b':
    if len(B)==0:
      print('B')
      break
    next=B[0]
    B=B[1:]
  elif next=='c':
    if len(C)==0:
      print('C')
      break
    next=C[0]
    C=C[1:]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int N;
  cin >> N;
  
  if(N % 10 == 3){
cout << "bon" << endl;
  }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8 ){
cout << "pon" << endl;
  }else{
cout << "hon" << endl;
  }
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
  int h, m, s, t;
  scanf("%d", &t);
  s = t % 60;
  t /= 60;
  m = t % 60;
  t /= 60;
  h = t;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        print(B);
    } else if ((6 <= A) && (A <= 12)) {
        print(B/2);
    } else {
        print(0);
    }
}

int main()
{
    solve();

    return 0;
}


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

int main(void)
{
    long long int a,b,c,d,i,j,k,n;
    string s;
    char C[5];

    cin >> a  >> b;


    cout << (a+b)/2+(a+b)%2;

    return 0;
}

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

int main() {
    int n, result = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        if (2 * sum < a[i]) {
            result = i;
        }
        sum += a[i];
    }
    cout << n - result;
    return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

menu=[INT() for i in range(5)]

last=INF
idx=0
for i in range(5):
    if menu[i]%10!=0:
        if menu[i]%10<last:
            last=menu[i]%10
            idx=i

ans=0
for i in range(5):
    if i!=idx:
        ans+=menu[i]//10*10
        if menu[i]%10!=0:
            ans+=10
ans+=menu[idx]
print(ans)


Measured memory_bytes: 3064
use std::cmp;

const MOD: u32 = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let red: Vec<usize> = sc.chars().iter().map(|&c| c as usize - '0' as usize).collect();
    let n = red.len();

    let mut dp: Vec<u32> = vec![0; 2 * n + 1];
    dp[red[0]] = 1;
    for turn in 0..(2 * n) {
        let mut next = vec![0; 2 * n + 1];

        let cur_balls = 2 * cmp::min(turn + 1, n) - turn;
        let supplied_red = if turn + 1 < n { red[turn + 1] } else { 0 };

        for cur_red in 0..(cur_balls + 1) {
            if cur_red > 0 {
                // pop red
                next[cur_red + supplied_red - 1] += dp[cur_red];
                next[cur_red + supplied_red - 1] %= MOD;
            }
            if cur_balls - cur_red > 0 {
                // pop blue
                next[cur_red + supplied_red] += dp[cur_red];
                next[cur_red + supplied_red] %= MOD;
            }
        }

        dp = next;
    }

    println!("{}", dp[0]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10000];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1744
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define nl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define trav(x) for(auto& i: x)

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

	int n;
	cin >> n;
	bool ans = false;
	for(int i = 1; i <= 9; i++) {
		if(n % i == 0) {
			if(n / i <= 9 && n / i >= 1) {
				ans = true;
				break;
			}
		}
	}
	if(ans) {
		cout << "Yes" << nl;
	} else {
		cout << "No" << nl;
	}
}

Measured memory_bytes: 256
io = STDIN
a,b,c=io.gets.split.map(&:to_i)
k=io.gets.to_i

max=[a,b,c].max
if max == a
  puts b+c+max*(2**k)
elsif max == b
  puts a+c+max*(2**k)
else
  puts a+b+max*(2**k)
end


Measured memory_bytes: 1788