akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

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

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int s = 0;int e = pow(10,9)+1;
    while(s+1<e){
        int m = (s+e)/2;
        auto f = [&]{
            ll now =0;
            rep(i,n){
                now+= (a[i]-1)/m;
            }
            return now <= k;
        };
        if(f()){
            e=m;
            
        }else{
            s=m;
        }
    }
    cout << e << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = b / a;
    if(ans > c) ans = c;
    cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 764
use proconio::input;

fn main(){
  input!{
    N:usize,
    As:[i32; N-1],
  }
  let mut tree = vec![0; N];
  for var in As.iter() {
    tree[(*var as usize)-1] += 1;
  }
  for var in tree.iter() {
    println!("{}", var);
  }
}

Measured memory_bytes: 4712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

int main() {
    int k; cin >> k;
    vll a(k);
    rep(i,k) cin >> a[i];
    reverse(all(a));
    ll l = 2;
    ll r = 2;
    rep(i,k) {
        l = ((l+a[i]-1)/a[i]) * a[i];
        r = (r/a[i]) * a[i] + a[i] - 1;
        if (l > r) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << " " << r << endl;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int c[330000];
bool ex[330000] = {};

int main(){
	
	int N, Q;
	cin >> N >> Q;
	
	for(int i = 0; i < N; i++){
		cin >> c[i];
		ex[c[i]] = true;
	}
	
	for(int loop = 0; loop < Q; loop++){
		int q;
		cin >> q;
		int ans = 0;
		if(N < 1000){
			for(int i = 0; i < N; i++){
				ans = max(ans, c[i] % q);
			}
		}else{
			for(int rem = q - 1; rem > 0; rem--){
				for(int i = rem; i <= 310000; i += q){
					if(ex[i]){
						ans = rem;
						break;
					}
				}
				if(ans != 0){
					break;
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}



Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
int main() {
  int N,K;
  cin >> N >> K;
  int a[N];
  vector<vector<mint>> dp(N+1,vector<mint>(K+1));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= N; i++) {
    mint sum = 0;
    for (int j = 0; j <= a[i-1]; j++) {
      sum += dp[i-1][j];
      dp[i][j] = sum;
    }
    for (int j = a[i-1]+1; j <= K; j++) {
      sum += dp[i-1][j]-dp[i-1][j-a[i-1]-1];
      dp[i][j] = sum;
    }
  }
  cout << dp[N][K].x;
}

Measured memory_bytes: 83012
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[]
for i in range(M):
  xyc.append(list(map(int,input().split())))
price=[]
for i in range(M):
  price.append(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
price.sort()
a.sort()
b.sort()
min=a[0]+b[0]
if min<=price[0]:
  print(min)
else:
  print(price[0])

Measured memory_bytes: 42792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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


int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> ab(n);
    rep(i,n){
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(b, a);
    }
    sort(all(ab));
    int sum = 0;
    rep(i,n){
        sum += ab[i].second;
        if (sum > ab[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;

int main()
{
    int N;
    vector<vector<int>> bingo(3, vector<int>(3));
    vector<vector<int>> check(3, vector<int>(3, 0));
    map<int, pair<int, int>> bin;

    for(int i =0; i<3;i++){
        for(int j = 0; j<3; j++){
            int buf;
            // cin >>bingo.at(i).at(j);
            cin >> buf;
            bin[buf] = make_pair(i, j);
        }
    }
    cin >> N;
    int buf;
    for(int i = 0; i<N; i++){
        cin >> buf;
        if(bin.find(buf) != bin.end()){
            auto s = bin[buf];
            check.at(s.first).at(s.second) = 1;
        }
    }

    bool ch = false;
    for(int i = 0; i<3; i++){
        if(check.at(i).at(0) + check.at(i).at(1) + check.at(i).at(2) == 3){
            ch = true;
        }
    }

    for(int i = 0; i<3; i++){
        if(check.at(0).at(i) + check.at(1).at(i) + check.at(2).at(i) == 3){
            ch = true;
        }
    }

    if(check.at(0).at(0) + check.at(1).at(1) + check.at(2).at(2) == 3){
        ch = true;
    }

    if(check.at(2).at(0) + check.at(1).at(1) + check.at(0).at(2) == 3){
        ch = true;
    }

    if(ch){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{

  string S;
  cin >> S;

  if(S == "SUN") cout << 7 << endl;
  else if(S == "MON") cout << 6 << endl;
  else if(S == "TUE") cout << 5 << endl;
  else if(S == "WED") cout << 4 << endl;
  else if(S == "THU") cout << 3 << endl;
  else if(S == "FRI") cout << 2 << endl;
  else if(S == "SAT") cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "C"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=200010;

int n,it,mx;
int f[N];
vector<int> ad[N];

void dfs(int u,int p=-1,int c=0)
{
    if(mx<=c) it=u,mx=c;
    forv(v,ad[u]) if(v!=p) dfs(v,u,c+1);
}
main()
{
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    f[1]=1;
    forinc(i,2,200000) f[i]=1-min(f[i-1],(i>2 ? f[i-2] : 1));

    n=in;
    forinc(i,2,n)
    {
        int u=in,v=in;
        ad[u].pb(v);
        ad[v].pb(u);
    }
    it=1;
    dfs(it);
    dfs(it);
    cout<<(f[mx+1] ? "First" : "Second");
}


Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
 int main(){
    long long int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
   
    long long int n1=x%d;
    if(n1==0){
        long long int use=abs(x/d);
        if(use>k){
            d=d*k;
            x=x-d;
            cout<<x;  
        }
        else{
        k=k-use;
        if(k%2==0)
            cout<<"0";
        else
            cout<<d;}
    }
    
    else{
        
        long long int use=abs(x/d);
        if(use>k){
            d=d*k;
            x=x-d;
            cout<<x; 
        }
        else{
       	k=k-use;
        if(k%2==0){
            cout<<n1;
            
        }
        else{
           long long int use2=abs(n1+d);
           long long int use1=abs(n1-d);
           cout<<min(use1,use2);
        }
        }
        
        
    }
    
    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
  ll n,t1;
  cin >> n >> t1;
  vector<ll> t(n);
  for(int i=0;i<n;i++){
    cin >> t[i];
  }
  ll ans = 0;
  for(int i=0;i<n-1;i++){
    ans += t1;
    ans += min(0ll,t[i+1]-(t[i]+t1));
  }
  ans += t1;
  cout << ans <<endl;
  return 0;
}

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

int main() {
    using vi = vector<long long>;
    
    int n;
    cin >> n;
    switch(n%10){
        case 3:cout << "bon" << endl;break;
        case 0:
        case 1:
        case 6:
        case 8:cout << "pon" << endl;break;
        default:cout<< "hon" << endl;
    }
}

Measured memory_bytes: 3592
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int D = in.nextInt();
        int[] c = new int[26];
        for (int i = 0; i < 26; i++)
            c[i] = in.nextInt();
        int[][] s = new int[D][26];
        for (int d = 0; d < D; d++) for (int i = 0; i < 26; i++)
            s[d][i] = in.nextInt();

        int[] last = new int[26];
        long S = 0;
        for (int d = 0; d < D; d++) {
            int ans = 0;
            int max = Integer.MIN_VALUE;
            int sum = 0;
            for (int i = 0; i < 26; i++) {
                sum += c[i] * (d + 1 - last[i]);
            }
            for (int i = 0; i < 26; i++) {
                int dS = s[d][i] - sum + c[i] * (d + 1 - last[i]);
                if (max < dS) {
                    ans = i;
                    max = dS;
                }
            }
            last[ans] = d + 1;
            S += max;
            out.println(ans + 1);
        }

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 35656
from collections import deque

def solve(s, start):
    if s[start[0]][start[1]] == "#":
        return -1 
    q = deque([start])
    distance = [[-1] * w for _ in range(h)]
    distance[start[0]][start[1]] = 0

    while q:
        y, x = q.popleft()
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + i, x + j
            if not(0 <= new_y < h and 0 <= new_x < w): continue
            if s[new_y][new_x] == "#": continue
            if distance[new_y][new_x] == -1:
                distance[new_y][new_x] = distance[y][x] + 1
                q.append([new_y, new_x])

    return max(map(max, distance))


h, w = map(int, input().split())
s = [input() for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, solve(s, [i, j]))

print(ans)


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int f(string s)
{
    if(s=="AC")
        return 1;
    if(s=="WA")
        return 2;
    if(s=="TLE")
        return 3;
    else
        return 4;
}
int main()
{
    int n;
    cin>>n;
    int ac=0,wa=0,tle=0,re=0;
    string s;
    while(n--)
    {
        cin>>s;
        int temp = f(s);
        switch(temp)
        {
        case(1):
            ac++;
            break;
        case(2):
            wa++;
            break;
        case(3):
            tle++;
            break;
        case(4):
            re++;
            break;
        }
    }
    cout<<"AC x "<<ac;
    cout<<"\nWA x "<<wa;
    cout<<"\nTLE x "<<tle;
    cout<<"\nRE x "<<re<<endl;
}


Measured memory_bytes: 3600
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = s.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = s.nextInt();
        }

        int max = 0, count = 0;

        for (int i = 1; i < N; i++) {
            if (H[i-1] >= H[i]) {
                count++;
            }
            else {
                if(max < count) max = count;
                count = 0;
            }
        }
        if(max < count) max = count;

        System.out.println(max);
        s.close();
    }
}

Measured memory_bytes: 51716
package main

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

func main() {
	N := nextInt()
	if N == 1 {
		fmt.Printf("%f", float32(1))
	} else {
		if N%2 == 0 {
			fmt.Printf("%f", float32(0.5))
		} else {
			ans := float32(N/2+1) / float32(N)
			fmt.Printf("%f", ans)
		}
	}
	return
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool flag=true;
    while(true)
    {
        if(flag)
        {
            flag=false;
            c-=b;
            if(c<=0)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        else
        {
            flag=true;
            a-=d;
            if(a<=0)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3620
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N = II()
res = 0
for i in range(1, N+1):
    n = N//i
    res += i*n*(n+1) >> 1

print(res)


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}
template<typename T>T power(T a,T b){
  T tmp = 1;
  rep(i,b){
    tmp *= a;
  }
  return tmp;
}
int main(){
  ll x,y;cin>>x>>y;
  if(x % y == 0)print(-1)
    else print(x)
  return 0;
}


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

P calc(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  double A=imag(a/c),B=A-imag(b/c);
  return d+a+(b-a)*A/B;
}

int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
    P ans=calc(P(ax,ay),P(bx,by),P(cx,cy),P(dx,dy));
    printf("%.8f %.8f\n",ans.real(),ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1260
from collections import defaultdict


def main():
    x = int(input())
    ans = (x // 11) * 2
    now = (x // 11) * 11
    a = 0
    while now < x:
        if a % 2 == 0:
            now += 6
        else:
            now += 5
        a += 1
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
N=int(input())
H=list(map(int,input().split()))
cnt=0
max=0
for i in range(N-1):
    if H[i]>=H[i+1]:
        cnt=cnt+1
    else:
        if cnt>max:
            max=cnt
        cnt=0
if cnt>max:
    max=cnt
print(max)


Measured memory_bytes: 63984
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m, d[212345], t[212345];
    M mp;

    cin >> n;
    REP(i, n)
    {
        cin >> d[i];
        mp[d[i]]++;
    }
    cin >> m;

    bool res = true;
    REP(i, m)
    {
        cin >> t[i];

        if (mp[t[i]] < 1)
            res = false;

        mp[t[i]]--;
    }

    cout << (res ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll h, w;
char a[1010][1010];
ll res[1010][1010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	double n, m, d;
	cin >> n >> m >> d;
	double ans;
	if (d == 0) {
		ans = (m - 1) / n;
	}
	else {
		ans = (m - 1) * (n - d) * 2 / (n * n);
	}
	exout(ans);
	return 0;
}


Measured memory_bytes: 3768
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List


solve2 :: [Int] -> Int -> Int
solve2 [] total = 0
solve2 (x:xs) total
    | total `mod` 10 > 0 = total
    | x `mod` 10 > 0 = total - x
    | otherwise = solve2 xs total

solve :: [Int] -> Int
solve arr = solve2 sorted total
    where
        total = sum arr
        sorted = List.sort arr

main :: IO()
main = do
    n <- (fst . fromJust . BS.readInt) <$> BS.getLine
    arr <- replicateM n ((fst . fromJust . BS.readInt) <$> BS.getLine)
    print $ solve arr


Measured memory_bytes: 508
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    cin >> N;
    double ans=0;
    
    for(ll i=0; i<N; i++) {
        double x;
        string u;
        cin >> x >> u;
        
        if(u=="BTC") {
            ans+=380000*x;
        }else {
            ans+=x;
        }
    }
    
    printf("%.8f\n", ans);
    
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll psum[300005];
const int INF=1e9+7;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        int t=s[i]-'A'+n;
        if(t>25) t-=26;
        cout<<(char)('A'+t);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main (){
    ll N, M; cin >> N >> M;
    vector<PLL> D(N);
    for(int i=0; i<N; i++){
        ll A, B; cin >> A >> B;
        D[i] = PLL(A, B);
    }
    
    sort(D.begin(), D.end());
    
    ll sum = 0;
    for(int i=0; i<N; i++){
        ll buy = 0;
        if(D[i].second > M){
            sum += M * D[i].first;
            break;
        }else{
            buy = D[i].second;
            sum += D[i].second * D[i].first;
            M -= buy;
        }

    }
    
    cout << sum << endl;
    return 0;
}



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

int main(){
	int h,w;
	cin >> h >> w;
	string s;
	int G[h][w];
	rep(i,h){
		cin >> s;
		rep(j,w){
			if(s[j] == '.') G[i][j] = 0;
			else G[i][j] = 1;
		}
	}
	int L[h][w],R[h][w],U[h][w],D[h][w];
	rep(i,h){
		rep(j,w){
			if(j == 0){
				if(G[i][j] == 0) L[i][j] = 1;
				else L[i][j] = 0;
			}else{
				if(G[i][j] == 0) L[i][j] = L[i][j-1] + 1;
				else L[i][j] = 0;
			}
		}
	}
	rep(i,h){
		for(int j(w-1);j>=0;--j){
			if(j == w-1){
				if(G[i][j] == 0) R[i][j] = 1;
				else R[i][j] = 0;
			}else{
				if(G[i][j] == 0) R[i][j] = R[i][j+1] + 1;
				else R[i][j] = 0;
			}
		}
	}
	rep(i,h){
		rep(j,w){
			if(i == 0){
				if(G[i][j] == 0) U[i][j] = 1;
				else U[i][j] = 0;
			}else{
				if(G[i][j] == 0) U[i][j] = U[i-1][j] + 1;
				else U[i][j] = 0;
			}
		}
	}
	for(int i(h-1);i>=0;--i){
		rep(j,w){
			if(i == h-1){
				if(G[i][j] == 0) D[i][j] = 1;
				else D[i][j] = 0;
			}else{
				if(G[i][j] == 0) D[i][j] = D[i+1][j] + 1;
				else D[i][j] = 0;
			}
		}
	}
	int ans(0);
	rep(i,h){
		rep(j,w){
			ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j] - 3);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	string str;
	int n;
	cin >> str;
	cin >> n;
	for(int z=0;z<n;z++){
		string ope;
		cin >> ope;
		if(ope=="print"){
			int s,g;
			cin >> s >> g;
			for(int i=s;i<=g;i++){
				cout << str[i];
			}
			cout << endl;
		}
		else if(ope=="reverse"){
			string temp;
			int s,g;
			cin >> s >> g;
			for(int i=s;i<=g;i++){
				temp.push_back(str[i]);
			}
			for(int i=0;i<temp.length();i++){
				str[s+i]=temp[temp.length()-1-i];
			}
		}
		else if(ope=="replace"){
			int s,g;
			string temp;
			cin >> s >> g >> temp;
			for(int i=s;i<=g;i++){
				str[i]=temp[i-s];
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3148
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define INF               1e18
#define ff                first
#define ss                second
#define vi                vector<int>
#define pii               pair<int,int>
#define mii               map<int,int>
#define endl              "\n"
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define debug(x)          cout<<#x<<" is "<<(x)<<endl
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(long long i=a;i<b;i++)
#define sp(ans,p)         fixed <<setprecision(p)<<ans;
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;



constexpr int N = 3005;

int r, c, k;
int arr[N][N];
int dp[N][N][4];




int recur(int r, int c, int pick)
{
    if (r < 0 || c < 0 || pick <= 0)
    {
        return 0;
    }
    if (dp[r][c][pick] != -1) return dp[r][c][pick];


    int a = recur(r - 1, c, 3) + arr[r][c];
    int b = recur(r, c - 1, pick - 1) + arr[r][c];
    int cc = recur(r, c - 1, pick);
    int z = max(a, max(b, cc));


    return dp[r][c][pick] = z;
}



void solve()
{
    mem(dp, -1);
    cin >> r >> c >> k;
    rep(i, 0, k)
    {
        int a, b, v;
        cin >> a >> b >> v;
        a--, b--;
        arr[a][b] = v;
    }
    cout << recur(r - 1, c - 1, 3) << endl;
    return;
}

signed main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // sieve();
    int t = 1;
    // cin >> t;
    while (t--)   solve();
    return 0;
}


Measured memory_bytes: 356648
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,k,mx;
int a[maxn];

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

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	REP(i,n)cin>>a[i],mx=max(mx,a[i]);
	int GCD=a[1];
	for(int i=2;i<=n;i++)GCD=gcd(GCD,a[i]);
	if(k%GCD==0&&k<=mx)cout<<"POSSIBLE";
	else cout<<"IMPOSSIBLE";
	return 0; 
}


Measured memory_bytes: 640
def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 0
    current_min = 2 * 10 ** 5 + 1

    for i in range(N):
        current_min = min(current_min, P[i])
        if P[i] <= current_min:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24744
from datetime import datetime as dt


if __name__ == '__main__':
    S = str(input())

    last_day = dt.strptime('2019/04/30', '%Y/%m/%d')
    S_datetime = dt.strptime(S, '%Y/%m/%d')


    if S_datetime <= last_day:
        print('Heisei')
    else:
        print('TBD')


Measured memory_bytes: 4464
def get_color_type_num(a_list):

    c_list = [0 for i in range(9)]

    for a in a_list:
        if 1 <= a <= 399:
            c_list[0] += 1
        elif 400 <= a <= 799:
            c_list[1] += 1
        elif 800 <= a <= 1199:
            c_list[2] += 1
        elif 1200 <= a <= 1599:
            c_list[3] += 1
        elif 1600 <= a <= 1999:
            c_list[4] += 1
        elif 2000 <= a <= 2399:
            c_list[5] += 1
        elif 2400 <= a <= 2799:
            c_list[6] += 1
        elif 2800 <= a <= 3199:
            c_list[7] += 1
        else:
            c_list[8] += 1

    c_num = 0
    c_free = c_list[8]
    for i, c in enumerate(c_list):
        if i == 8:
            c_free = c
        elif c:
            c_num += 1

    min_c = c_num
    max_c = min_c + c_free
    # if max_c > 8:
    #     max_c = 8
    if min_c == 0:
        min_c = 1

    return min_c, max_c


if __name__ == '__main__':
    N = input()
    a_list = [int(i) for i in input().split()]

    min_c, max_c = get_color_type_num(a_list)
    print(min_c, max_c)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  for(int i=0;i<=100;i++){
    if(4*x-y==2*i && 0<=x-i && x-i<=100){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3580
import std.stdio, std.string, std.range, std.algorithm, std.math, std.typecons, std.conv;

void main() {
  auto inp = readln.split.to!(long[]);
  auto N = inp[0], T = inp[1];
  auto t = readln.split.to!(long[]);
  long res = 0;
  foreach (i; 0..N-1) {
    res += min(T, t[i+1] - t[i]);
  }
  res += T;
  writeln(res);
}


Measured memory_bytes: 11480
import std.stdio, std.string, std.array, std.conv;

void main() {
    int[] a;
    int q = readln.chomp.to!int;
    foreach (i; 0 .. q) {
        int[] tmp = readln.chomp.split.to!(int[]);
        if (tmp[0] == 0) {
            a ~= tmp[1];
        } else if (tmp[0] == 1) {
            a[tmp[1]].writeln;
        } else {
            a = a[0..$-1];
        }
    }
}


Measured memory_bytes: 6988
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> n >> m;
	vector<ll> k(m);
	vector<vector<ll>> ss(m);
	vector<ll> p(m);
	ll res = 0;
	rep(i, m) {
		cin >> k[i];
		ss[i].resize(k[i]);
		rep(j, k[i]) {
			cin >> ss[i][j];
		}
	}
	rep(i, m) {
		cin >> p[i];
	}
	for (int bit = 0; bit < (1 << n); bit++) {
		ll flg2 = 1;
		rep(i, m) {
			ll cnt = 0;
			rep(j, k[i]) {
				if (bit & (1 << (ss[i][j]-1))) {
					++cnt;
				}
			}
			if (cnt % 2 != p[i]) {
				flg2 = 0;
				break;
			}
		}
		if (flg2 == 1) {
			++res;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vector<pair<int, int> > adj[100001];
ll d[100001];

void dfs(int x, int p)
{
    for (auto q : adj[x])
    {
        int y = q.first;
        int l = q.second;
        if (y != p)
        {
            d[y] = d[x] + l;
            dfs(y, x);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].emplace_back(b, c);
        adj[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    dfs(k, -1);
    for (int i = 0; i < q; ++i)
    {
        int x, y;
        cin >> x >> y;
        cout << d[x] + d[y] << '\n';
    }
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, m;
    cin >> n >> m;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll sum[n];
    sum[0] = a[0] % m;
    repd(i, 1, n) {
        sum[i] = sum[i - 1] + a[i];
        sum[i] %= m;
    }

    map<ll, ll> memo;
    memo[0] = 1;
    rep(i, n) {
        ll x = sum[i];
        if (memo[x] == 0) {
            memo[x] = 1;
        } else {
            memo[x]++;
        }
    }
    ll ans = 0;
    for (auto iter = memo.begin(); iter != memo.end(); iter++) {
        ll num = iter->second;
        if (num >= 2) {
            ans += num * (num - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5760
n = int(input())
a = [int(i) for i in input().split()]
a = list(reversed(sorted(a)))
# 2番目を最大にするとは
# 大きいものを各組に2つずつ割り振るべき
# a > b > c > dなら[[a,b][c,d]]か[[a,c][b,d]]なので
# つまり出力は大きい順に並べたうちで、上から奇数番目のNつの和
sum = 0
for i in range(2*n):
    if i % 2 == 1:
        sum += a[i]
        # print(a[i])
print(sum)


Measured memory_bytes: 37084
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct mypair{
    LL a,b;
    mypair(){}
    mypair(LL i,LL j):a(i),b(j){

    }

    bool operator <(const mypair &right)const{
        if(a != right.a){
            return a < right.a;
        }else{
            return b < right.b;
        }
    }
};

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

    LL n,m;
    cin >> n >> m;

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

    vector<LL> total(n+1,0);
    vector<LL> tmptotal(n+1,0);
    for(int i = 1; i < n+1; i++){
        total[i] = total[i-1] + a[i];
        tmptotal[i] = total[i];
        tmptotal[i] %= m;
    }

    LL ans = 0;

    vector<mypair> vec(n+1);

    for(int i = 1; i < n+1; i++){
        vec[i] = mypair(tmptotal[i],i);
    }

    sort(vec.begin()+1,vec.end());

    for(int i = n; i > 0; i--){
        auto itr1 = lower_bound(vec.begin()+1,vec.end(),mypair(tmptotal[i-1],i));
        auto itr2 = upper_bound(vec.begin()+1,vec.end(),mypair(tmptotal[i-1],n));
        ans += itr2 - itr1;
    }

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

Measured memory_bytes: 4352
#include<stdio.h>

int main(void){
  int x,y;
  scanf("%d%d",&x,&y);
  while(1){
  if(x<y) y=y%x;
    else x=x%y;
  if(x==0||y==0) break;
  }
  if(x==0) printf("%d\n",y);
  else if(y==0) printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};

int d[105][105];
vector<string> s;

int main(){
    int w, h;
    while(cin >> w >> h, w){
        s.resize(h);
        int si, sj;
        for(int i=0;i<h;i++){
            cin >> s[i];
            for(int j=0;j<w;j++){
                if(s[i][j] == '&'){
                    si = i;
                    sj = j;
                }
            }
        }
        for(int i=0;i<h;i++){
            fill(d[i], d[i]+w, IINF);
        }
        d[si][sj] = 0;
        deque<P> que;
        que.push_back(P(si,sj));
        while(!que.empty()){
            P p = que.front();
            que.pop_front();
            int i = p.first, j = p.second;
            for(int k=0;k<4;k++){
                int ni = i+di[k], nj = j+dj[k];
                if(ni < 0 || ni >= h) continue;
                if(nj < 0 || nj >= w) continue;
                if(s[i][j] != '#' && s[ni][nj] == '#'){
                    if(d[ni][nj] > d[i][j] + 1){
                        d[ni][nj] = d[i][j] + 1;
                        que.push_back(P(ni,nj));
                    }
                }else{
                    if(d[ni][nj] > d[i][j]){
                        d[ni][nj] = d[i][j];
                        que.push_front(P(ni,nj));
                    }
                }
            }
        }
        int ans = IINF;
        for(int i=0;i<h;i++){
            ans = min(ans, min(d[i][0], d[i][w-1]));
        }
        for(int j=0;j<w;j++){
            ans = min(ans, min(d[0][j], d[h-1][j]));
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  long long int N,sum=0,an=0;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    if(i==0){
      sum+=abs(A.at(i));
    }else{
      sum+=abs(A.at(i)-A.at(i-1));
    }
  }
  sum+=abs(A.at(N-1));
  for(int i=0;i<N;i++){
    an=0;
    if(i==0){
      an=sum-abs(A.at(i))-abs(A.at(i)-A.at(i+1))+abs(A.at(i+1));
    }else if(i==N-1){
      an=sum-abs(A.at(i)-A.at(i-1))-abs(A.at(i))+abs(A.at(i-1));
    }else{
      an=sum-abs(A.at(i)-A.at(i-1))-abs(A.at(i)-A.at(i+1))+abs(A.at(i-1)-A.at(i+1));
    }
    cout<<an<<endl;
  }
  
    
  
  
  
  
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  vector<int> A(N);
  bool f = true;
  map<int, int> all;
  int o;  
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
    all[A[i]]++;    
    if ( A[i] > 0 ) f = false;
    if ( A[i] > 0 ) o = A[i];
  }

  if ( f ) {
    cout << "Yes" << endl;
    return 0;
  }

  

  if ( all.size() == 2 && all[0]*2 == all[o] ) {
    cout << "Yes" << endl;
    return 0;
  }  
  if ( N > 3 ) {    
    int c = 0;
    set<int> cnt;    
    for ( auto i : all ) {
      A[c++] = i.first;
      cnt.insert(i.second);      
    }
    if ( cnt.size() != 1 || all.size() != 3 ) {
      cout << "No" << endl;
      return 0;
    }
  }
  if ( A[0] == (A[2]^A[1]) && A[1] == (A[2]^A[0]) && A[2] == (A[1]^A[0]) ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }  
  
  return 0;
}


Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ll K;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> K;
    int N = 50;
    ll A = K / N;
    vll a(N);
    iota(all(a), A);
    rep(i, K%N) {
        ll mi = *min_element(all(a));
        rep(j, N) {
            if (a[j] == mi)a[j] += N;
            else a[j]--;
        }
    }
    cout << N << endl;
    rep(i, N)cout << a[i] << (i != N - 1 ? ' ' : '\n');
}


Measured memory_bytes: 256
H,W=map(int,input().split())
S=[0]*H
for i in range(H):
  S[i]=list(str(input()))

dx=[-1,0,1,0]
dy=[0,-1,0,1]

for i in range(H):
  for j in range(W):
    ok=0
    if S[i][j]=='#':
      for k in range(4):
        x=j+dx[k]
        y=i+dy[k]
        if 0<=x<W and 0<=y<H and S[y][x]=='#':
          ok=1
          break
      if ok==0:
        print('No')
        exit()
print('Yes') 



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int a,b,ans=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    string s,t;
    s=to_string(i);
    t=s;
    reverse(all(s));
    if(t==s)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3692
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a > b){
		printf("a > b\n");
	}
	else if(a < b){
		printf("a < b\n");
	}
	else if(a == b){
		printf("a == b\n");
	}
	
	return(0);
}

Measured memory_bytes: 2616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL n,a[110],x;
int main()
{
	 scanf("%lld %lld",&n,&x);
	 for(LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	 sort(a+1,a+n+1);
	 for(LL i=2;i<=n;i++) a[i]+=a[i-1];
	 if(a[n]<x) {printf("%lld",n-1);return 0;}
	 LL k=0;
	 for(LL i=1;i<=n;i++) if(a[i]<=x) k=i;
	 printf("%lld",k);
}

Measured memory_bytes: 256